1import{m as U,n as F,r as o,x as W,e as m,j as e,B as u,a4 as q}from"./index-C_Y-hnZk.js";import{B as v}from"./badge-CDdCoe7J.js";import{S as _}from"./skeleton-C_rvVPcJ.js";import{s as R}from"./stealthPreview-Dyyov0zm.js";import{T as V}from"./TeamDesignWorkspace-B4FSVuSp.js";import{g as K,m as H}from"./internalTeamOrders-CAkS8l7c.js";import{s as J}from"./internalTeamRemix-iMb1Ep12.js";import{f as Q}from"./phonePolicy-BQZIAjjn.js";import{d as X,c as C,b as Y,a as Z}from"./internalCustomerLinks-BJuElHWd.js";import{A as b}from"./arrow-left-D1Ues1kB.js";import{f as I}from"./format-CaiECi-v.js";import{W as ee}from"./wand-sparkles-KY110KSA.js";import{L as S}from"./loader-circle-BFYvasFl.js";import{L as ae}from"./link-2-ClePXXgL.js";import{S as se}from"./shopping-cart-BtNRgGiJ.js";import"./useFabricExport-BAxsGW2S.js";import"./logoDebug-B7cNoPBt.js";import"./customizer-CAc3FQyO.js";import"./arrangePrintSheets-B-d0wF9V.js";import"./resolveLogoUrls-DdvqfLfI.js";import"./printer-B9A8zKVz.js";import"./download-CyKOhC0s.js";import"./untypedSupabase-CDjka2eY.js";import"./inlinePreviews-vKvna3tk.js";import"./orderArtwork-BZGGDKDm.js";function Se(){var y,N;const{orderId:l}=U(),x=F(),[a,g]=o.useState(null),[L,T]=o.useState(null),[D,z]=o.useState(!0),[d,p]=o.useState(null),[B,O]=o.useState(null),[E,M]=o.useState(null);o.useEffect(()=>{l&&P(l)},[l]);const P=async t=>{try{const s=await K(t);if(g(s),s!=null&&s.created_by){const{data:n}=await W.from("profiles").select("display_name, email").eq("user_id",s.created_by).maybeSingle();T((n==null?void 0:n.display_name)||(n==null?void 0:n.email)||null)}}catch(s){console.error(s),m.error("Failed to load internal team order")}finally{z(!1)}},G=async()=>{if(!l)return;const t=await H(l);g(s=>s&&{...s,designs_generated_at:t})},$=()=>{if(a)try{J({designData:a.design_data??{},orderId:a.id,suggestedName:a.name??void 0}),x("/admin/internal-team-customizer")}catch(t){console.error("Failed to open team order for editing:",t),m.error("Could not open this team order for editing")}},f=async t=>{var n,w,k;if(!a||d)return;const s=Array.isArray((n=a.design_data)==null?void 0:n.roster)?a.design_data.roster:[];if(s.length===0){m.error("This team order has no saved roster.");return}p(t);try{let i=B;if(i||(i=await X({name:a.name||a.team_name||"Internal team customer design",designData:a.design_data,previewImageUrl:a.preview_image_url}),O(i)),t==="customizer"){await C(Y(window.location.origin,i,{team:!0})),m.success("Team customizer link copied",{description:"The saved roster will open directly at the purchase summary."});return}let h=E;if(!h){const A=await q(s.length);h=await Z({designId:i,variantId:A,quantity:s.length,brand:((k=(w=a.design_data)==null?void 0:w.skateInfo)==null?void 0:k.brand)||"CCM",size:`Team Order (${s.length} pairs)`,model:"Team Order"}),M(h)}await C(h),m.success("Team checkout link copied")}catch(i){console.error(`Could not create team ${t} link:`,i),m.error(`Could not create the team ${t} link`,{description:i instanceof Error?i.message:void 0})}finally{p(null)}};if(D)return e.jsxs("div",{className:"space-y-6",children:[e.jsx(_,{className:"h-8 w-48"}),e.jsx(_,{className:"h-64"})]});if(!a)return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(u,{variant:"ghost",onClick:()=>x("/admin/internal-team-orders"),children:[e.jsx(b,{className:"w-4 h-4 mr-2"})," Back"]}),e.jsx("p",{className:"text-muted-foreground",children:"Internal team order not found."})]});const j=((y=a.design_data)==null?void 0:y.roster)??[],c=!!a.designs_generated_at,r=(N=a.design_data)==null?void 0:N.contact;return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsxs(u,{variant:"ghost",className:"-ml-2 mb-4",onClick:()=>x("/admin/internal-team-orders"),children:[e.jsx(b,{className:"w-4 h-4 mr-2"})," Back to Internal Team Orders"]}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-6 items-start",children:[e.jsx("div",{className:"w-full md:w-56 h-32 rounded-lg border bg-muted/30 flex items-center justify-center overflow-hidden flex-shrink-0",children:a.preview_image_url?e.jsx("img",{src:a.preview_image_url,alt:"master design",className:"w-full h-full object-contain p-2",style:R(a.design_data)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"No preview"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap mb-1",children:[e.jsx("h1",{className:"text-2xl font-bold",children:a.name||"Untitled team order"}),e.jsx(v,{variant:"outline",children:"Internal"}),e.jsx(v,{variant:c?"default":"secondary",children:c?"â Designs Generated":"Pending Generation"})]}),e.jsxs("p",{className:"text-muted-foreground text-sm",children:[L||"Unknown","  · ",I(new Date(a.created_at),"MMM d, yyyy"),c&&e.jsxs(e.Fragment,{children:[" · generated ",I(new Date(a.designs_generated_at),"MMM d, yyyy")]})]}),e.jsxs("p",{className:"text-sm mt-1",children:[e.jsx("span",{className:"font-semibold",children:j.length})," players in roster"]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-3",children:[e.jsxs(u,{size:"sm",variant:"outline",onClick:$,children:[e.jsx(ee,{className:"w-4 h-4 mr-2"}),"Edit design & roster"]}),e.jsxs(u,{size:"sm",variant:"outline",onClick:()=>f("customizer"),disabled:!!d,children:[d==="customizer"?e.jsx(S,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(ae,{className:"w-4 h-4 mr-2"}),"Copy Customizer Link"]}),e.jsxs(u,{size:"sm",variant:"outline",onClick:()=>f("checkout"),disabled:!!d,children:[d==="checkout"?e.jsx(S,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(se,{className:"w-4 h-4 mr-2"}),"Copy Checkout Link"]}),c&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Saving an edit clears the generated designs â you'll regenerate them."})]}
1),r&&(r.teamName||r.name||r.email||r.phone)&&e.jsxs("div",{className:"mt-3 rounded-lg border bg-muted/30 p-3 text-sm grid gap-x-6 gap-y-1 sm:grid-cols-2 max-w-xl",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Team:"})," ",e.jsx("span",{className:"font-medium",children:r.teamName||"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Contact:"})," ",e.jsx("span",{className:"font-medium",children:r.name||"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Email:"})," ",r.email?e.jsx("a",{href:`mailto:${r.email}`,className:"font-medium text-primary hover:underline",children:r.email}):"â"]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Phone:"})," ",r.phone?e.jsx("a",{href:`tel:${r.phone}`,className:"font-medium text-primary hover:underline",children:Q(r.phone)}):"â"]})]})]})]})]}),e.jsx(V,{roster:j,masterDesignData:a.design_data,linkKey:"internal_team_order_id",linkValue:a.id,filePrefix:`internal-team-${(a.name||a.id).replace(/[^\w.-]+/g,"_")}`,isGenerated:c,onGenerated:G})]})}export{Se as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.