1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3058],{21782:function(e,l,t){t.d(l,{Z:function(){return r}});var n=t(57437),i=t(2069);function r(e){let{hex:l,size:t=10,shape:r="square",borderRadius:o,sx:a={}}=e,d=!l;return(0,n.jsx)(i.Z,{sx:{width:t,height:t,borderRadius:null!=o?o:"circle"===r?"50%":"3px",flexShrink:0,...d?{border:"1.5px dashed var(--lv-border-strong)"}:{bgcolor:l,border:"0.75px solid var(--lv-border-default)"},...a}})}},52180:function(e,l,t){t.d(l,{Z:function(){return n.f},v:function(){return n.f}});var n=t(66848)},41175:function(e,l,t){var n=t(57437);t(2265);var i=t(91723),r=t(43792),o=t(77543);l.Z=e=>{let{label:l,tooltip:t,showIcon:a=!0,iconOnly:d=!1,className:s=""}=e;if(!l)return null;let u=(0,n.jsxs)("span",{className:"".concat("inline-flex items-center gap-1 rounded-md px-1.5 py-[2px] w-fit"," ").concat(s).trim(),style:{color:o.oR.warningStrong,backgroundColor:o.oR.warningBg},"aria-label":d?l:void 0,children:[(a||d)&&(0,n.jsx)(i.Z,{size:11,strokeWidth:2.25,"aria-hidden":"true"}),!d&&(0,n.jsx)("span",{className:"text-[10px] font-semibold font-Inter leading-[12px]",children:l})]});return t?(0,n.jsx)(r.Z,{title:t,children:(0,n.jsx)("span",{style:{display:"inline-flex"},children:u})}):u}},88890:function(e,l,t){t.d(l,{Z:function(){return y}});var n=t(57437),i=t(2265),r=t(2069),o=t(46387),a=t(24156),d=t(13213),s=t(13807),u=t(43792);function c(e){let{text:l="",tailLength:t=14,title:i,className:r="",style:o}=e,a=String(null!=l?l:""),d=null!=i?i:a;if(a.length<=t+1)return(0,n.jsx)("span",{className:"block truncate ".concat(r).trim(),style:o,title:d,children:a});let s=a.slice(0,a.length-t),u=a.slice(a.length-t);return(0,n.jsxs)("span",{className:"flex min-w-0 max-w-full ".concat(r).trim(),style:o,title:d,children:[(0,n.jsx)("span",{className:"min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:s}),(0,n.jsx)("span",{className:"flex-shrink-0 whitespace-nowrap",children:u})]})}var p=t(77543),v=t(11512);let h={fontSize:v.np,lineHeight:v.D7},f=e=>(0,n.jsx)("span",{style:h,children:e}),x=e=>e?"string"==typeof e?e:e.label||e.name||e.value||"":"",g=(e,l)=>e===l||!!e&&!!l&&(null!=e.id&&null!=l.id?e.id===l.id:null!=e.value&&null!=l.value?e.value===l.value:x(e)===x(l)),m=(e,l)=>{var t,n,i,r,o,a;return e?"string"==typeof e?e:null!==(a=null!==(o=null!==(r=null!==(i=null!==(n=null!==(t=e.id)&&void 0!==t?t:e.value)&&void 0!==n?n:e.shipping_profile_id)&&void 0!==i?i:e.section_id)&&void 0!==r?r:e.taxonomy_id)&&void 0!==o?o:x(e))&&void 0!==a?a:l:l};function y(e){var l;let t,{options:h=[],value:y=null,onChange:b,placeholder:j="Select an option",searchPlaceholder:_="Search...",noOptionsText:w="No results found",clearable:S=!1,clearLabel:k="Clear",disabled:I=!1,fullWidth:C=!0,size:Z="sm",compact:P=!1,cozy:R=!1,middleTruncate:A=!1,minWidth:E=220,maxHeight:M=v.lM.maxHeight,ariaLabel:z,sx:D={},menuProps:L={},getOptionLabel:O=x,isOptionEqual:F=g,filterOption:T}=e,N=(0,i.useRef)(null),[W,U]=(0,i.useState)(null),[H,B]=(0,i.useState)(""),[V,K]=(0,i.useState)(!1),q=!0===P,G=q?v.EC:v.jG,Y="".concat(v.KI,"px"),Q=!!W;(0,i.useEffect)(()=>{Q||B("")},[Q]);let $=h.find(e=>F(e,y))||y||null,X=H.trim().toLowerCase(),J=T||((e,l)=>O(e).toLowerCase().includes(l)),ee=e=>(null==e?void 0:e.type)==="group-header";if(X){t=[];let e=null;for(let l of h){if(ee(l)){e=l;continue}J(l,X)&&(e&&(t.push(e),e=null),t.push(l))}}else t=h;let el=t.length?t.map((e,l)=>ee(e)?{key:m(e,l),render:()=>(0,n.jsx)(r.Z,{sx:{px:1.5,pt:0===l?.75:1.25,pb:.25,fontSize:10,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:p.oR.textTertiary,...l>0&&{borderTop:"1px solid ".concat(p.oR.borderDividerSubtle),mt:.5}},children:O(e)})}:{key:m(e,l),label:f(A?(0,n.jsx)(c,{text:O(e)}):O(e)),active:!!($&&F(e,$)),onClick:()=>{null==b||b(e)}}):[{key:"empty",render:()=>(0,n.jsx)(r.Z,{sx:{px:1.5,py:1,fontSize:v.np,color:p.oR.textSecondary},children:w})}],et=[...S?[{key:"clear-selection",label:f(k),active:!$,onClick:()=>{null==b||b(null)}},{key:"clear-selection-divider",divider:!0}]:[],...el],en=Math.max((null===(l=N.current)||void 0===l?void 0:l.offsetWidth)||0,E),{paperProps:ei={},...er}=L,eo={...ei,sx:{borderRadius:v.lM.borderRadius,border:v.lM.border,background:v.lM.background,boxSh
1adow:"".concat(v.lM.boxShadow," !important"),...ei.sx||{}}},ea=A&&!!$,ed=(0,n.jsxs)(r.Z,{ref:N,component:"button",type:"button","aria-label":z,disabled:I,onClick:e=>{I||U(e.currentTarget)},onMouseEnter:()=>K(!0),onMouseLeave:()=>K(!1),sx:{width:C?"100%":"auto",minWidth:C?void 0:E,display:"flex",alignItems:"center",justifyContent:"space-between",gap:"".concat(v.FN,"px"),textAlign:"left",bgcolor:p.oR.bgInput,borderRadius:p.PY.md,boxShadow:v.f1,px:"".concat(v.CR.px,"px"),py:"".concat(v.CR.py,"px"),minHeight:v.CR.height,color:$?v.Mp:v.iL,cursor:I?"not-allowed":"pointer",opacity:I?v.Nr:1,transition:v.DZ,"&:hover":{bgcolor:I?p.oR.bgInput:p.oR.bgHover},"&:focus":{outline:"none",boxShadow:v.aP},...Q&&{boxShadow:v.aP},...D},children:[A&&$?(0,n.jsx)(c,{text:O($),title:"",style:{flex:1,minWidth:0,fontSize:G,color:"inherit",lineHeight:Y}}):(0,n.jsx)(o.Z,{sx:{flex:1,minWidth:0,fontSize:G,color:"inherit",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:Y},children:$?O($):j}),(0,n.jsx)(a.Z,{size:q?v.b2:v.sO,color:v.To})]});return(0,n.jsxs)(n.Fragment,{children:[ea?(0,n.jsx)(u.Z,{title:O($),placement:"top",maxWidth:320,open:V&&!Q,children:ed}):ed,(0,n.jsx)(d.Z,{anchorEl:W,open:Q,onClose:()=>U(null),items:et,minWidth:en,maxHeight:M,paperProps:eo,header:(0,n.jsx)(s.Z,{value:H,onChange:B,placeholder:_,fullWidth:!0,size:"sm"}),...er})]})}},2595:function(e,l,t){t.d(l,{Z:function(){return o},x:function(){return r}});var n=t(57437);t(2265);var i=t(67136);function r(e){let l=null==e?void 0:e.possible_values;return!Array.isArray(l)||0===l.length}function o(e){var l;let{property:t,value:r,onChange:o,placeholder:a="Type a value"}=e,d=Array.isArray(null==r?void 0:r.values)&&null!==(l=r.values[0])&&void 0!==l?l:"";return(0,n.jsx)(i.Z,{fullWidth:!0,value:d,placeholder:a,inputProps:{"aria-label":(null==t?void 0:t.display_name)||(null==t?void 0:t.name)},onChange:e=>{let l=String(null!=e?e:"").replace(/[()]/g,""),n=l.trim();o(t.property_id,[],n?[l]:[])}})}},72336:function(e,l,t){t.d(l,{Z:function(){return u}});var n=t(57437),i=t(2265),r=t(65838),o=t(67944),a=t(98624),d=t(2069),s=t(72585);function u(e){var l,t,u,c,p,v,h,f,x,g,m,y,b,j,_,w,S,k;let{formState:I,ai:C,derived:Z,mode:P,surface:R,caps:A,listingContext:E={},beforeEditors:M,afterEditors:z,afterTitleSlot:D,rightRailTopSlot:L,conflictFields:O,validation:F,enableMockupSlotConfig:T=!1,fileAssignments:N,onRefreshFileAssignments:W,hostOwnsContainer:U=!1,tagScores:H}=e,B=null==E?void 0:E.scoring,V=null!==(g=function(){for(var e=arguments.length,l=Array(e),t=0;t<e;t++)l[t]=arguments[t];return l.find(e=>Array.isArray(e)&&e.length>0)}(N,null==E?void 0:E.livePresetAssignments,null==E?void 0:E.initialFileAssignments,I.presetDigitalDesignFiles))&&void 0!==g?g:[],K=e=>{var l,t;return null!==(t=null==F?void 0:null===(l=F.getFieldProps)||void 0===l?void 0:l.call(F,e))&&void 0!==t?t:{error:!1,warning:!1,helperText:""}},q=(0,a.lB)({caps:A,formState:I,mode:P}),G="download"===I.typeOption,Y=e=>void 0===A?!G:e===o._P?!G:!!e,Q=Y(null==A?void 0:A.shipping),$=Y(null==A?void 0:A.returnPolicy),X=Y(null==A?void 0:A.physicalAttrs
1),J=null!==(m=null==E?void 0:E.initialPodProducts)&&void 0!==m?m:null==E?void 0:null===(l=E.selectedListing)||void 0===l?void 0:l.podProducts,ee=(null==A?void 0:A.showPodPrintAreaPreview)===!0&&"pod"===I.typeOption&&!!(null==E?void 0:E.listingId),[el,et]=(0,i.useState)(null),en=(0,i.useCallback)(e=>{et(null!=e?e:null)},[]);return(0,n.jsxs)("div",{className:U?void 0:"px-4",children:[M,(0,n.jsx)(d.Z,{sx:{containerType:"inline-size"},children:(0,n.jsxs)(d.Z,{sx:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) ".concat(320,"px"),columnGap:3,alignItems:"start",["@container (max-width: ".concat(880,"px)")]:{gridTemplateColumns:"1fr"}},children:[(0,n.jsxs)(d.Z,{sx:{minWidth:0},children:[(0,n.jsx)(r.s$,{title:I.title,setTitle:I.setTitle,description:I.description,setDescription:I.setDescription,aiLoading:C.aiLoading,aiPendingFields:C.aiPendingFields,onAcceptAI:C.handleAcceptAI,onRejectAI:C.handleRejectAI,onRegenerateAI:C.handleRegenerateAI,score:B,conflictFields:O,titleValidation:K("title"),descriptionValidation:K("description"),tagsValidation:K("tags"),afterTitleSlot:D,children:(0,n.jsx)(r.o$,{bare:!0,tags:I.tags,setTags:I.setTags,aiLoading:C.aiLoading,aiPendingFields:C.aiPendingFields,onAcceptAI:C.handleAcceptAI,onRejectAI:C.handleRejectAI,onRegenerateAI:C.handleRegenerateAI,score:B,tagScores:H,rawApiTags:null!==(y=null==E?void 0:E.rawApiTags)&&void 0!==y?y:[],conflictField:null==O?void 0:O.has("tags"),validation:K("tags"),grounding:null==C?void 0:C.grounding,surface:R})}),(0,n.jsx)(r.JA,{images:I.images,setImages:I.setImages,video:I.video,setVideo:I.setVideo,score:B,conflictField:null==O?void 0:O.has("images"),validation:K("photos"),queuedImages:null==E?void 0:E.queuedImages,mode:P,typeOption:I.typeOption,enableMockupSlotConfig:T,fileAssignments:N,onRefreshFileAssignments:W,designFileAssignments:V,showPodPrintAreaPreview:ee,listingId:null==E?void 0:E.listingId,surfaceKey:null!==(j=null!==(b=null==E?void 0:E.presetId)&&void 0!==b?b:null==E?void 0:E.listingId)&&void 0!==j?j:null,podProducts:J}),(0,n.jsx)(r.MX,{listingId:E.listingId,isPreset:"preset"===P,title:(null===(t=E.selectedListing)||void 0===t?void 0:t.title)||I.title,imageUrl:(null===(c=E.selectedListing)||void 0===c?void 0:null===(u=c.primaryImage)||void 0===u?void 0:u.srcFull)||(null===(p=E.selectedListing)||void 0===p?void 0:p.primaryImage)||(null===(f=E.selectedListing)||void 0===f?void 0:null===(h=f.images)||void 0===h?void 0:null===(v=h[0])||void 0===v?void 0:v.url_fullxfull)||(null===(x=I.images.find(e=>null==e?void 0:e.src))||void 0===x?void 0:x.src),typeOption:I.typeOption,setTypeOption:I.setTypeOption,restoreSnapshot:I.restoreSnapshot,setRestoreSnapshot:I.setRestoreSnapshot,setPreviousType:I.setPreviousType,restoreSnapshotInfo:I.restoreSnapshotInfo,setRestoreSnapshotInfo:I.setRestoreSnapshotInfo,rawInventory:I.rawInventory,setShippingProfile:I.setShippingProfile,setReturnPolicy:I.setReturnPolicy,productsVaryByVariants:I.productsVaryByVariants,setProductsVaryByVariants:I.setProductsVaryByVariants,variants:I.variants,setVariants:I.setVariants,variantInventory:I.variantInventory,setVariantInventory:I.setVariantInventory,onInventoryChange:I.setInventory,aiInventoryPriceWrites:I.aiInventoryPriceWrites,onAiInventoryPriceWritesApplied:I.onAiInventoryPriceWritesApplied,aiPodPriceWrites:I.aiPodPriceWrites,onAiPodPriceWritesApplied:I.onAiPodPriceWritesApplied,aiVariantPricePreview:I.aiVariantPricePreview,onPayloadGetterReady:null==E?void 0:E.onDigitalFilesPayloadGetterReady,onResetReady:null==E?void 0:E.onDigitalFilesResetReady,onReplaceReady:null==E?void 0:E.onDigitalFilesReplaceReady,onPresetSnapshotReady:null==E?void 0:E.onPresetSnapshotReady,initialParentFolder:null==E?void 0:E.initialParentFolder,initialDeliverables:null==E?void 0:E.initialDeliverables,preserveDigitalMount:!!(null==A?void 0:A.preserveDigitalMount),onDigitalUploadingChange:null==E?void 0:E.onDigitalUploadingChange,onPdfSettingsChange:null==E?void 0:E.onPdfSettingsChange,initialPdfOverrides:null==E?void 0:E.initialPdfOverrides,onRawInventoryLoaded:I.setRawInventory,initialPodProducts:J,initialFileAssignments:null==E?void 0:E.initialFileAssignments,presetInstanceKey:null==E?void 0:E.presetInstanceKey,presetApplyGeneration:null==E?void 0:E.presetApplyGeneration,onPodSnapshotGetterReady:null==E?void 0:E.onPodSnapshotGetterReady,onPresetDesignsChanged:null==E?void 0:E.onPresetDesignsChanged,initialDigitalDesignFiles:I.presetDigitalDesignFiles,onDigitalDesignFilesChanged:I.setPresetDigitalDesignFiles,onPodProductsChange:I.setPodProducts,onPodEditorHydrated:I.markPodEditorHydrated,globalPrice:I.price,globalQuantity:I.quantity,globalSku:I.sku,pdfPreviewRefreshKey:null!==(_=null==E?void 0:E.pdfPreviewRefreshKey)&&void 0!==_?_:0,variationsRefreshKey:null!==(w=null==E?void 0:E.variationsRefreshKey)&&void 0!==w?w:0,podDesignsRefreshKey:null!==(S=null==E?void 0:E.podDesignsRefreshKey)&&void 0!==S?S:0,onOverridesFlushReady:null==E?void 0:E.onOverridesFlushReady,onRegisterTypeSwitch:en}),q&&(0,n.jsx)(r.n0,{price:I.price,setPrice:I.setPrice,quantity:I.quantity,setQuantity:I.setQuantity,sku:I.sku,setSku:I.setSku,score:B,conflictField:null==O?void 0:O.has("price"),validation:K("priceQuantitySku"),aiPendingFields:C.aiPendingFields,aiLoading:C.aiLoading,onAcceptAI:C.handleAcceptAI,onRejectAI:C.handleRejectAI,onRegenerateAI:C.handleRegenerateAI}),(0,n.jsx)(r.Ib,{questions:I.personalizationQuestions,onChange:I.setPersonalizationQuestions,score:B,surface:"preset"===P?s.Qb.PRESETS:s.Qb.SINGLE,listingId:null!==(k=E.listingId)&&void 0!==k?k:null})]}),(0,n.jsxs)(d.Z,{component:"aside",sx:{minWidth:0}
1,children:[L,(0,n.jsx)(r.Cd,{whoMadeThis:I.whoMadeThis,setWhoMadeThis:I.setWhoMadeThis,whatIsIt:I.whatIsIt,setWhatIsIt:I.setWhatIsIt,whenMade:I.whenMade,setWhenMade:I.setWhenMade,typeOption:I.typeOption,typeSwitch:el,validation:K("coreDetails"),productionPartnerIds:I.productionPartnerIds,setProductionPartnerIds:I.setProductionPartnerIds,availablePartners:I.availablePartners,productionPartnersLoading:I.productionPartnersLoading,productionPartnersError:I.productionPartnersError,productionPartnersFetched:I.productionPartnersFetched,onRetryProductionPartners:I.refetchProductionPartners}),(0,n.jsx)(r.QA,{etsyCategory:I.etsyCategory,setEtsyCategory:I.setEtsyCategory,taxonomies:I.taxonomies,categoryProperties:I.categoryProperties,setCategoryProperties:I.setCategoryProperties,selectedPropertyValues:I.selectedPropertyValues,setSelectedPropertyValues:I.setSelectedPropertyValues,validation:K("category")}),Q&&(0,n.jsx)(r.WT,{shippingProfile:I.shippingProfile,setShippingProfile:I.setShippingProfile,shippingProfiles:I.shippingProfiles,validation:K("shippingProfile")}),$&&(0,n.jsx)(r.qt,{returnPolicy:I.returnPolicy,setReturnPolicy:I.setReturnPolicy,returnPolicies:I.returnPolicies,validation:K("returnPolicy")}),(0,n.jsx)(r.WE,{shopSection:I.shopSection,setShopSection:I.setShopSection,shopSections:I.shopSections}),(0,n.jsx)(r.lb,{showPhysicalAttributes:X,renewalOption:I.renewalOption,setRenewalOption:I.setRenewalOption,itemWeight:I.itemWeight,setItemWeight:I.setItemWeight,itemLength:I.itemLength,setItemLength:I.setItemLength,itemWidth:I.itemWidth,setItemWidth:I.setItemWidth,itemHeight:I.itemHeight,setItemHeight:I.setItemHeight,weightUnit:I.weightUnit,setWeightUnit:I.setWeightUnit,dimensionsUnit:I.dimensionsUnit,setDimensionsUnit:I.setDimensionsUnit,requireItemDimensions:X&&(I.shippingProfiles||[]).some(e=>(null==e?void 0:e.shipping_profile_id)===I.shippingProfile&&(null==e?void 0:e.profile_type)==="calculated")}),(0,n.jsx)(r.RU,{materials:I.materials,setMaterials:I.setMaterials,conflictField:null==O?void 0:O.has("materials"),validation:K("materials")})]})]})}),z]})}},82950:function(e,l,t){t.d(l,{Z:function(){return s}});var n=t(57437);t(2265);var i=t(41905),r=t(22135),o=t(40875),a=t(32372);let d=e=>{let{children:l,onClick:t}=e;return(0,n.jsx)("button",{type:"button",onClick:t,className:"rounded-full border border-lv-border bg-lv-elevated px-2 py-0.5 text-[11px] text-lv-text-primary hover:bg-lv-hover",children:l})};function s(e){let{name:l,options:t=[],links:s={},images:u=[],isOpen:c=!1,onToggle:p,onDone:v,onDelete:h,onChange:f,draggable:x=!1,dragProps:g={},isDragging:m=!1,isDropTarget:y=!1,renderOptionChip:b}=e;return(0,n.jsxs)("div",{onDragOver:g.onDragOver,onDrop:g.onDrop,className:["".concat(a.tc," p-3"),"transition-[border-color,box-shadow,opacity]",m?"opacity-45":"opacity-100",c||y?"border-lv-border-strong shadow-md":"hover:border-lv-border-strong"].join(" "),title:x?"Click to edit or drag to swap":"Click to edit",children:[(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[x&&(0,n.jsx)("button",{type:"button",draggable:!0,onDragStart:g.onDragStart,onDragEnd:g.onDragEnd,onClick:e=>e.stopPropagation(),className:"mt-0.5 rounded-lg p-2 text-lv-text-tertiary cursor-grab active:cursor-grabbing","aria-label":"Drag ".concat(l),title:"Drag to reorder",children:(0,n.jsx)(i.Z,{className:"h-4 w-4"})}),(0,n.jsxs)("button",{type:"button",onClick:p,className:"flex min-w-0 flex-1 items-start justify-between gap-3 rounded-lg text-left",children:[(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"truncate text-sm font-medium text-lv-text-primary",children:l||"Untitled variant"}),(0,n.jsxs)("div",{className:"mt-0.5 text-[11px] text-lv-text-secondary",children:[t.length," Options"]})]}),(0,n.jsx)("span",{className:"mt-0.5 inline-flex h-6 w-6 items-center justify-center rounded-full border border-lv-border bg-lv-elevated text-lv-text-secondary",children:c?(0,n.jsx)(r.Z,{className:"h-3.5 w-3.5"}):(0,n.jsx)(o.Z,{className:"h-3.5 w-3.5"})})]})]}),c?(0,n.jsx)(a.ZP,{images:u,initialName:l,initialOptions:t,initialLinks:s,embedded:!0,onDone:v,onDelete:h,onChange:f}):t.length?(0,n.jsx)("div",{className:"mt-2 flex flex-wrap gap-1.5",children:t.map((e,l)=>b?b(e,l):(0,n.jsx)(d,{onClick:e=>e.stopPropagation(),children:e},"".concat(e,"_").concat(l)))}):null]})}},75674:function(e,l,t){t.d(l,{Z:function(){return o}});var n=t(57437);t(2265);var i=t(76865),r=t(73560);
1function o(e){let{count:l,limit:t,className:o=""}=e;return Number.isFinite(l)&&Number.isFinite(t)&&!(l<=t)?(0,n.jsxs)("div",{role:"alert","data-testid":"variant-combination-cap-banner",className:"flex items-start gap-2 rounded-lv-md border border-lv-error-border bg-lv-error-surface px-4 py-3 ".concat(o),children:[(0,n.jsx)(i.Z,{size:16,className:"mt-0.5 shrink-0 text-lv-error","aria-hidden":"true"}),(0,n.jsx)("p",{className:"flex-1 text-lv-body text-lv-text-primary",children:(0,r.MT)(l,t)})]}):null}},23004:function(e,l,t){t.d(l,{Td:function(){return p},ZP:function(){return v},j4:function(){return c},wD:function(){return s}});var n=t(57437),i=t(2069),r=t(46387),o=t(33245),a=t(43792),d=t(77543);let s={FULL:"full",MODEL:"model"},u=e=>e?String(e).trim():"";function c(e){return u(null==e?void 0:e.name)}function p(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s.FULL,t=u(null==e?void 0:e.name),n=[u(null==e?void 0:e.brand),u(null==e?void 0:e.model)].filter(Boolean).join(" ");return l===s.MODEL?n||t:[n,t].filter(Boolean).join(" â ")}function v(e){let{product:l,tooltipContent:t=null,metaLabel:u=null,metaIcon:v=null,thumbSize:h,nameMode:f=s.FULL,sx:x}=e;if(!l)return null;let g=p(l,f),m=c(l),y=f===s.MODEL&&!t&&m&&m!==g?m:void 0,b=null!=h,j=b?Math.max(12,Math.round(.45*h)):40,_=(0,n.jsx)(i.Z,{sx:{...b?{width:h,height:h,flexShrink:0}:{width:"100%",aspectRatio:"1 / 1",mb:1},borderRadius:d.PY.md,bgcolor:d.oR.bgElevated,border:"1px solid ".concat(d.oR.borderDefault),overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"center"},children:l.image_url?(0,n.jsx)(i.Z,{component:"img",src:l.image_url,alt:g,sx:{width:"100%",height:"100%",objectFit:"cover"}}):(0,n.jsx)("svg",{width:j,height:j,viewBox:"0 0 24 24",fill:"none",children:(0,n.jsx)("path",{d:"M3 6l3-3 2 2a4 4 0 0 0 8 0l2-2 3 3-3 3v10H6V9L3 6z",fill:d.oR.borderStrong})})}),w=(0,n.jsxs)(i.Z,{sx:{display:"flex",flexDirection:"column",minWidth:0,flex:b?1:void 0},children:[(0,n.jsx)(a.Z,{title:t,placement:"top",disableInteractive:!0,maxWidth:240,children:(0,n.jsxs)(i.Z,{sx:{display:"flex",alignItems:"flex-start",gap:.5,...b?{}:{height:"2.8em"},mb:.25,cursor:t?"help":"default"},children:[(0,n.jsx)(r.Z,{className:"title-text",title:y,sx:{minWidth:0,fontSize:12,fontWeight:500,color:d.oR.textPrimary,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",textOverflow:"ellipsis",wordBreak:"break-word",lineHeight:1.4},children:g}),t&&(0,n.jsx)(i.Z,{className:"title-info-icon",sx:{flexShrink:0,mt:"2px",color:d.oR.textTertiary,opacity:0,transition:"opacity 0.15s"},children:(0,n.jsx)(o.Z,{size:12})})]})}),(v||u)&&(0,n.jsxs)(i.Z,{sx:{display:"flex",alignItems:"center",gap:.5,mb:.25,minWidth:0},children:[v,u&&(0,n.jsx)(r.Z,{sx:{fontFamily:d._$.metadata,fontSize:12,fontWeight:600,color:d.oR.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:u})]})]});return(0,n.jsxs)(i.Z,{sx:{display:"flex",flexDirection:b?"row":"column",alignItems:b?"flex-start":"stretch",gap:b?1.25:0,minWidth:0,...x},children:[_,w]})}},65838:function(e,l,t){t.d(l,{QA:function(){return lv},Cd:function(){return e9},lb:function(){return tf},RU:function(){return tx},Ib:function(){return ta.ZP},JA:function(){return e$},f:function(){return o},n0:function(){return l_},MX:function(){return iX},qt:function(){return tp},WT:function(){return tc},WE:function(){return tv},o$:function(){return M},s$:function(){return m}});var n=t(57437),i=t(67136),r=t(90884);function o(e){let{presetName:l,setPresetName:t}=e;return(0,n.jsx)(r.Z,{id:"preset-name",title:"Preset Name",children:(0,n.jsx)(i.Z,{fullWidth:!0,placeholder:"Enter Preset Name",value:l,onChange:t})})}var a=t(2265),d=t(99583),s=t(75226),u=t(27647),c=t(26420),p=t(25238),v=t(70745),h=t(53632),f=t(11217),x=t(75986),g=t(59497);function m(e){var l,t,o,m,y,b;let{title:j,setTitle:_,description:w,setDescription:S,aiLoading:k={},aiPendingFields:I={},onAcceptAI:C,onRejectAI:Z,onRegenerateAI:P,score:R,conflictFields:A,titleValidation:E={},descriptionValidation:M={},tagsValidation:z={},afterTitleSlot:D,children:L}=e,{rules:O}=(0,x.RK)(),F=null!==(y=null===(l=O.title)||void 0===l?void 0:l.maxLength)&&void 0!==y?y:150,T=null!==(b=null===(t=O.description)||void 0===t?void 0:t.maxLength)&&void 0!==b?b:5e3,N=(0,v.bw)(E),W=(0,v.bw)(M),U=[N,W,(0,v.bw)(z)].filter(
1Boolean),H=j.length>=.9*F?(0,n.jsx)(c.Z,{state:j.length>F?"error":"warning",label:"".concat(j.length," of ").concat(F," characters")}):null,B=w.length>=.9*T?(0,n.jsx)(c.Z,{state:w.length>T?"error":"warning",label:"".concat(w.length," of ").concat(T," characters")}):null,V=null==R?void 0:R.score,K=null==V?void 0:V.observed,q=(0,a.useMemo)(()=>(0,f.ZM)(R,"title"),[R]),G=(0,a.useMemo)(()=>(0,f.ZM)(R,"description"),[R]),Y=V?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(d.Z,{label:f.HE.badgeLabels.title,showLabelPrefix:!0,score:V.title,total:g.SCORE_RUBRIC.max.title,factor:"title",observed:K,rows:q}),(0,n.jsx)(d.Z,{label:f.HE.badgeLabels.description,labelPrefix:"Desc.",showLabelPrefix:!0,score:V.description,total:g.SCORE_RUBRIC.max.description,factor:"description",observed:K,rows:G})]}):null,Q=!!I.title,$=!!I.description;return(0,n.jsxs)(r.Z,{id:"title-description",title:"Title & Description",headerAction:Y,issues:U,pillsInHeader:!1,children:[(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)(p.FQ,{label:"Title",issue:N,meta:H}),(0,n.jsx)(s.Z,{active:Q,fieldLabel:"title",detail:null===(o=I.title)||void 0===o?void 0:o.model,loading:!!k.title,onAccept:()=>null==C?void 0:C("title"),onRegenerate:()=>null==P?void 0:P("title"),onDiscard:()=>null==Z?void 0:Z("title"),children:(0,n.jsx)(i.Z,{fullWidth:!0,value:j,onChange:e=>{_(e),Q&&(null==C||C("title"))},error:E.error||j.length>F,inputProps:{maxLength:F},sx:Q?h.g:void 0})})]}),D,(0,n.jsxs)("div",{children:[(0,n.jsx)(p.FQ,{label:"Description",issue:W,meta:B}),(0,n.jsx)(s.Z,{active:$,fieldLabel:"description",detail:null===(m=I.description)||void 0===m?void 0:m.model,loading:!!k.description,onAccept:()=>null==C?void 0:C("description"),onRegenerate:()=>null==P?void 0:P("description"),onDiscard:()=>null==Z?void 0:Z("description"),children:(0,n.jsx)(u.Z,{fullWidth:!0,value:w,onChange:e=>{S(e),$&&(null==C||C("description"))},rows:6,maxRows:20,maxLength:T,hideCount:!0,error:M.error,sx:$?h.g:void 0})})]}),L]})}var y=t(2069),b=t(82431),j=t(10093),_=t(43792),w=t(66848),S=t(66280),k=t(7768),I=t(16273),C=t(48840),Z=t(15127);let P=(e,l)=>e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,l)?e[l]:void 0,R=(e,l)=>!!e&&"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,l),A=e=>!!e&&"function"==typeof e.ensureTagScores&&"function"==typeof e.seedTagScores&&!!e.tagScoreCache&&"object"==typeof e.tagScoreCache&&e.fetchingTags instanceof Set,E=e=>{let{tags:l,tagScoreCache:t,payloadTagDemand:n}=e,i=Object.create(null);for(let e of l){let l=(0,C.Qb)(e);if(!l)continue;let r=P(t,l),o=r&&Number.isFinite(r.demandScore)?r.demandScore:null;null!==o?i[e]=o:R(n,l)?i[e]=n[l]:R(t,l)&&(i[e]=null)}return i};function M(e){var l,t,o,u,h,m,M,z,D,L;let{tags:O,setTags:F,aiLoading:T={},aiPendingFields:N={},onAcceptAI:W,onRejectAI:U,onRegenerateAI:H,score:B,rawApiTags:V=[],conflictField:K=!1,validation:q={},bare:G=!1,grounding:Y=null,surface:Q=null,tagScores:$=null}=e,{rules:X}=(0,x.RK)(),J=null!==(m=null===(l=X.tags)||void 0===l?void 0:l.maxCount)&&void 0!==m?m:13,ee=(0,v.bw)(q),[el,et]=(0,a.useState)(""),[en,ei]=(0,a.useState)(""),er=(0,C.ZP)(),{tagScoreCache:eo,fetchingTags:ea,ensureTagScores:ed,seedTagScores:es,tagScoreEpoch:eu}=A($)?$:er,ec=Array.isArray(O)?O:O?O.split(",").map(e=>e.trim()).filter(Boolean):[],ep=e=>{var l;let t=(0,C.Qb)(e);return null!==(l=V.find(e=>{var l;return(null===(l=e.keyword)||void 0===l?void 0:l.toLowerCase())===t}))&&void 0!==l?l:null},ev=(0,a.useMemo)(()=>ec.map(e=>{let l=e.toLowerCase(),t=Object.prototype.hasOwnProperty.call(eo,l)?eo[l]:void 0;if(t)return{tag:e,...t};let n=V.find(e=>{var t;return(null===(t=e.keyword)||void 0===t?void 0:t.toLowerCase())===l});if(!n||n.message){var i;return{tag:e,opportunityScore:null,competitionScore:null,demandScore:null,velocityScore:null,message:null!==(i=null==n?void 0:n.message)&&void 0!==i?i:null}}return{tag:e,opportunityScore:parseFloat(n.opportunityScore),competitionScore:parseFloat(n.competitionScore),demandScore:parseFloat(n.demandScore),velocityScore:null!=n.velocityScore?parseFloat(n.velocityScore):null}}),[ec,V,eo]),eh=null==B?void 0:B.score,ef=null==B?void 0:B.scoreInputs,ex=ec.filter(e=>ea.has((0,C.Qb)(e))).length,eg=(0,a.useMemo)(()=>E({tags:ec,tagScoreCache:eo,payloadTagDemand:null==ef?void 0:ef.tagDemand}),[ec,eo,ef]),em=(0,a.useMemo)(()=>(0,f.ZM)(B,"tags",{tagDemand:eg,checkingCount:ex,degraded:null==ef?void 0:ef.degraded}
1),[B,eg,ex,ef]),ey=eh?(0,n.jsx)(d.Z,{label:f.HE.badgeLabels.tags,score:eh.tags,total:g.SCORE_RUBRIC.max.tags,factor:"tags",observed:eh.observed,rows:em}):null,eb=!!N.tags,ej=null!==(M=null==Y?void 0:Y.provenance)&&void 0!==M?M:null,e_=null!==(z=null==Y?void 0:Y.refillCandidates)&&void 0!==z?z:[],ew=eb&&"function"==typeof(null==Y?void 0:Y.toggleTagDiscard)&&(e_.length>0||!!ej),eS=ew&&null!==(D=Y.discardedTags)&&void 0!==D?D:[],ek=ew?ec.filter(e=>(0,k.y8)(eS,e)).length:0,eI=ew&&(0,k.pN)(e_,ec),eC=ew&&ek>0&&!eI,eZ=null===(t=N.tags)||void 0===t?void 0:t.generated,eP=(0,a.useMemo)(()=>Array.isArray(eZ)&&0!==eZ.length?eZ.filter(e=>!R(eo,(0,C.Qb)(e))).join("\0"):"",[eZ,eo]);(0,a.useEffect)(()=>{var e;if(!Array.isArray(eZ)||0===eZ.length)return;let l=new Set(eZ.map(C.Qb)),t=Object.create(null);(null!==(e=null==Y?void 0:Y.refillCandidates)&&void 0!==e?e:[]).forEach(e=>{let n=(0,k.wg)(e);if(!n||!l.has((0,C.Qb)(n))||R(eo,(0,C.Qb)(n)))return;let i=(0,k.Qh)(e);i&&(t[n]=i)}),es(t),ed(eZ.filter(e=>!ep(e)))},[eZ,eP,eu]);let eR=(e,l)=>{let{discardedCount:t,refillUsed:n=0}=l;(0,Z.L)("tag_curation",{action:e,discardedCount:t,refillUsed:n,...Q?{surface:Q}:{}})},eA=e=>{let l=!(0,k.y8)(eS,e);Y.toggleTagDiscard(e),eR(l?"discard":"undiscard",{discardedCount:ek+(l?1:-1)})},eE=e=>{let l=String(e).split(",").map(e=>e.trim()).filter(Boolean);if(0===l.length)return;let t=[...ec],n=[],i="";for(let e of l){if(t.length>=J)break;let l=(0,I.aQ)(e,X);if(!l.valid){i||(i=l.error);continue}t.some(e=>e.toLowerCase()===l.tag.toLowerCase())||(t.push(l.tag),n.push(l.tag))}n.length>0?(F(t),et(""),ei(""),eb&&(null==W||W("tags")),ed(n)):i&&ei(i)},eM=e=>{F(ec.filter(l=>l.toLowerCase()!==e.toLowerCase())),eb&&(null==W||W("tags"))},ez=en?(0,n.jsx)(c.Z,{state:"error",label:en}):(0,n.jsx)(c.Z,{state:"neutral",label:"".concat(ec.length," of ").concat(J," tags")}
1),eD=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(i.Z,{fullWidth:!0,value:el,onChange:e=>{et(e),en&&ei("")},onBlur:()=>{el.trim()&&eE(el)},inputProps:{onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),eE(el))},onPaste:e=>{var l,t;let n=null!==(t=null===(l=e.clipboardData)||void 0===l?void 0:l.getData("text"))&&void 0!==t?t:"";n.includes(",")&&(e.preventDefault(),eE("".concat(el).concat(n)))}},placeholder:"Type a tag and press Enter",disabled:ec.length>=J}),(ec.length>0||eb)&&(0,n.jsx)(s.Z,{active:eb,fieldLabel:"tags",detail:(null===(u=N.tags)||void 0===u?void 0:null===(o=u.generated)||void 0===o?void 0:o.length)?"".concat(N.tags.generated.length," tags"):null!==(L=null===(h=N.tags)||void 0===h?void 0:h.model)&&void 0!==L?L:null,loading:!!T.tags,onAccept:()=>null==W?void 0:W("tags"),onRegenerate:()=>null==H?void 0:H("tags"),onDiscard:()=>null==U?void 0:U("tags"),children:(0,n.jsxs)(y.Z,{sx:{display:"flex",flexWrap:"wrap",gap:.75,mt:2,...eb?{p:1,borderRadius:"8px",bgcolor:"var(--lv-bg-input)"}:{}},children:[0===ec.length&&(0,n.jsx)("span",{className:"text-lv-caption text-lv-text-tertiary",children:"This generation returned no tags."}),ev.map((e,l)=>{var t;return(0,n.jsx)(j.Z,{tagObj:e,onRemove:()=>eM(e.tag),isLoading:ea.has(e.tag.toLowerCase()),provenance:ew&&null!==(t=P(ej,e.tag))&&void 0!==t?t:null,discarded:ew&&(0,k.y8)(eS,e.tag),onToggleDiscard:ew?()=>eA(e.tag):null},"".concat(e.tag.toLowerCase(),"-").concat(l))}),ew&&(0,n.jsxs)(y.Z,{sx:{flexBasis:"100%",display:"flex",alignItems:"center",flexWrap:"wrap",gap:1,mt:.5},children:[(0,n.jsx)(_.Z,{title:eI?S.QZ.refillExhausted:ek>0?S.QZ.refillTooltip:S.QZ.refillNoDiscards,maxWidth:260,children:(0,n.jsx)("span",{className:"inline-flex",children:(0,n.jsx)(w.f,{text:S.QZ.refillLabel,onClick:()=>{let e=(0,k.Xk)({tags:ec,discardedTags:eS,refillCandidates:e_});if(!e.changed)return;F(e.tags),Y.applyTagRefill({discardedTags:e.discardedTags,provenance:e.provenance});let l=Object.create(null);e.placed.forEach(e=>{let{tag:t,scores:n}=e;n&&(l[t]=n)}),es(l),eR("refill",{discardedCount:e.discardedTags.length,refillUsed:e.filled})},disabled:!eC,width:"auto",icon:(0,n.jsx)(b.Z,{size:12,"aria-hidden":"true"}),iconPosition:"before"})})}),eI&&ek>0&&(0,n.jsx)("span",{role:"status",className:"text-[12px] leading-4 text-lv-text-secondary",children:S.QZ.refillExhausted})]})]})})]});return G?(0,n.jsxs)(y.Z,{id:"tags",sx:{mt:3,pt:3,borderTop:"1px solid var(--lv-border)"},children:[(0,n.jsx)(p.FQ,{label:"Tags",issue:ee,meta:ez,trailing:ey}),eD]}):(0,n.jsx)(r.Z,{id:"tags",title:"Tags",headerAction:ey,issues:[(0,v.bw)(q)].filter(Boolean),children:eD})}var z=t(30166),D=t(67571),L=t(46387),O=t(7261),F=t(1974),T=t(73540),N=t(63822),W=t(7485),U=t(9396),H=t(76865),B=t(17162),V=t(21988),K=t(15735),q=t(9871),G=t(22135),Y=t(40875),Q=t(30401),$=t(37930),X=t(74276),J=t(13807),ee=t(19998),el=t(74431),et=t(75067),en=t(71399),ei=t(77543),er=t(98527),eo=t(65370),ea=t(68380);let ed="ABCDEFGHIJ",es=[{value:"",label:"All collections"},{value:"none",label:"No collection"}];function eu(e,l,t){return Number.isFinite(l)?50*e<l:t>=50}let ec="This mockup has no print region yet, so a design can't be placed on it. Open it in the Asset Library and define a print region, then come back.";function ep(e,l){var t;return String(null!==(t=null==e?void 0:e.id)&&void 0!==t?t:l)}function ev(e){let{maxDesignLabels:l,designFiles:t=null}=e,[i,r]=(0,a.useState)(!1),o={A:"Your listing's first design file",B:"Your listing's second design file",C:"Your listing's third design file",D:"Your listing's fourth design file",E:"Your listing's fifth design file",F:"Your listing's sixth design file",G:"Your listing's seventh design file",H:"Your listing's eighth design file",I:"Your listing's ninth design file",J:"Your listing's tenth design file"},d=(e,l)=>{var n,i;return null!==(i=null==t?void 0:null===(n=t[l])||void 0===n?void 0:n.name)&&void 0!==i?i:o[e]};return(0,n.jsxs)(y.Z,{children:[(0,n.jsxs)(y.Z,{component:"button",type:"button",onClick:()=>r(e=>!e),sx:{display:"inline-flex",alignItems:"center",gap:.4,background:"none",border:"none",padding:0,cursor:"pointer",color:ei.oR.textTertiary,fontSize:"0.7rem","&:hover":{color:ei.oR.textSecondary}},children:["What do A/B/C mean?",i?(0,n.jsx)(G.Z,{size:12}):(0,n.jsx)(Y.Z,{size:12})]}),(0,n.jsx)(B.Z,{in:i,children:(0,n.jsx)(y.Z,{sx:{mt:.75,borderRadius:ei.PY.sm,border:"1px solid ".concat(ei.oR.borderSubtle),overflow:"hidden"},children:ed.slice(0,Math.min(l,10)).split("").map((e,l)=>(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1,px:1.25,py:.6,borderTop:l>0?"1px solid ".concat(ei.oR.borderSubtle):"none",bgcolor:l%2==0?ei.oR.bgPage:"transparent"},children:[(0,n.jsx)(L.Z,{component:"span",sx:{fontSize:"0.68rem",fontWeight:700,color:ei.oR.textPrimary,minWidth:16,userSelect:"none"},children:e}),(0,n.jsx)(L.Z,{component:"span",sx:{fontSize:"0.68rem",color:ei.oR.textSecondary,minWidth:16},children:"â"}),(0,n.jsx)(L.Z,{component:"span",sx:{fontSize:"0.68rem",color:ei.oR.textSecondary},children:d(e,l)})]},e))})})]})}function eh(e){let{file:l,name:t}=e,i=(0,a.useRef)(null),[r,o]=(0,a.useState)({width:0,height:0}),d=(0,a.useCallback)(()=>{let e=i.current;if(!e)return;let{width:l,height:t}=e.getBoundingClientRect();o(e=>l&&t&&(l!==e.width||t!==e.height)?{width:l,height:t}:e)},[]);(0,a.useEffect)(()=>{d();let e=i.current;if(!e||"undefined"==typeof ResizeObserver)return;let l=new ResizeObserver(()=>d());return l.observe(e),()=>l.disconnect()},[d]);
1let s=l.thumbnailUrl||l.s3Url||null,u=Array.isArray(l.regions)&&l.regions.length>0||!!(l.mockupRegion&&Array.isArray(l.mockupRegion.points)&&l.mockupRegion.points.length>0);return(0,n.jsx)(y.Z,{ref:i,sx:{position:"relative",width:"100%",aspectRatio:"1 / 1",bgcolor:"var(--lv-bg-page)",overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"center"},children:s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(y.Z,{component:"img",src:s,alt:t,onLoad:d,sx:{width:"100%",height:"100%",objectFit:"cover"}}),u&&r.width>0&&(0,n.jsx)(en.Z,{regions:l.regions,region:l.mockupRegion,containerWidth:r.width,containerHeight:r.height,fit:"cover"})]}):(0,n.jsx)(L.Z,{sx:{color:"var(--lv-text-tertiary)",fontSize:10},children:"No preview"})})}function ef(e){var l,t,i,r,o,d,s,u;let{open:c,onClose:p,slotIndex:v,initialValue:h=null,onSave:f,maxDesignLabels:x=10,designFiles:g=null,requireResolvableDesign:m=!1,unresolvedDesignMessage:b=null}=e,j=null!=h,_=Array.isArray(g),S=_?new Map(g.filter(e=>null==e?void 0:e.name).map(e=>[e.label,e.name])):null,k=ed.slice(0,Math.min(x,10)).split("").map(e=>({value:e,label:e})).map(e=>{let l=null==S?void 0:S.get(e.value);return l?{value:e.value,label:"".concat(e.value," â ").concat(l)}:_?{value:e.value,label:"".concat(e.value," â ").concat("resolves at apply time")}:e}),[I,C]=(0,a.useState)(null!==(l=null==h?void 0:h.mockupTemplateId)&&void 0!==l?l:null),[P,R]=(0,a.useState)(null!==(t=null==h?void 0:h.designLabel)&&void 0!==t?t:"A"),[A,E]=(0,a.useState)(null!==(i=null==h?void 0:h.designLabelsByRegion)&&void 0!==i?i:{}),[M,z]=(0,a.useState)(null!==(r=null==h?void 0:h._templateThumbUrl)&&void 0!==r?r:null),[D,F]=(0,a.useState)(null!==(o=null==h?void 0:h._templateFilename)&&void 0!==o?o:null),[T,N]=(0,a.useState)(null!==(d=null==h?void 0:h._templateRegions)&&void 0!==d?d:null),[W,U]=(0,a.useState)(null!==(s=null==h?void 0:h._templateRegion)&&void 0!==s?s:null),[H,G]=(0,a.useState)(null!==(u=null==h?void 0:h.mockupPlacement)&&void 0!==u?u:null),[Y,en]=(0,a.useState)([]),[ef,ex]=(0,a.useState)("idle"),[eg,em]=(0,a.useState)(null),[ey,eb]=(0,a.useState)(1),[ej,e_]=(0,a.useState)(!1),[ew,eS]=(0,a.useState)(!1),[ek,eI]=(0,a.useState)(0),[eC,eZ]=(0,a.useState)(""),[eP,eR]=(0,a.useState)(""),[eA,eE]=(0,a.useState)(!1),eM=!j||eA,{collections:ez}=(0,el.Z)(c&&eM),eD=(0,a.useMemo)(()=>[...es,...(ez||[]).map(e=>({value:e.id,label:e.name}))],[ez]),eL=(0,a.useMemo)(()=>{let e={assetCategory:"mockup_templates",uploadStatus:"ready",limit:50};return eC.trim()&&(e.search=eC.trim()),eP&&(e.collectionId=eP),e},[eC,eP]),eO=!!eC.trim()||!!eP,eF=(0,a.useRef)(0);(0,a.useEffect)(()=>{var e,l,t,n,i,r,o,a;c&&(C(null!==(e=null==h?void 0:h.mockupTemplateId)&&void 0!==e?e:null),R(null!==(l=null==h?void 0:h.designLabel)&&void 0!==l?l:"A"),E(null!==(t=null==h?void 0:h.designLabelsByRegion)&&void 0!==t?t:{}),z(null!==(n=null==h?void 0:h._templateThumbUrl)&&void 0!==n?n:null),F(null!==(i=null==h?void 0:h._templateFilename)&&void 0!==i?i:null),N(null!==(r=null==h?void 0:h._templateRegions)&&void 0!==r?r:null),U(null!==(o=null==h?void 0:h._templateRegion)&&void 0!==o?o:null),G(null!==(a=null==h?void 0:h.mockupPlacement)&&void 0!==a?a:null),eZ(""),eR(""),eE(!1))},[c]),(0,a.useEffect)(()=>{if(!c){eF.current+=1,eS(!1);return}let e=!1;return eM||(null==h?void 0:h.mockupTemplateId)==null?(ex("loading"),em(null),eb(1),e_(!1),eS(!1),eF.current+=1,(0,er.bE)({...eL,page:1}).then(l=>{var t,n,i;if(e)return;let r=null!==(i=null==l?void 0:null===(t=l.data)||void 0===t?void 0:t.files)&&void 0!==i?i:[];en(r),e_(eu(1,null==l?void 0:null===(n=l.data)||void 0===n?void 0:n.total,r.length)),ex("ready")}).catch(l=>{e||(em((null==l?void 0:l.message)||"Failed to load mockup templates. Please try again."),ex("error"))})):null!=h._templateRegions||null!=h._templateRegion||null!=h._templateThumbUrl?ex("ready"):(ex("loading"),em(null),(0,er.hn)(h.mockupTemplateId).then(l=>{var t,n,i,r,o,a,d,s,u;if(e)return;let c=null!==(i=null!==(n=null==l?void 0:null===(t=l.data)||void 0===t?void 0:t.data)&&void 0!==n?n:null==l?void 0:l.data)&&void 0!==i?i:null;c&&(z(null!==(o=null!==(r=c.thumbnailUrl)&&void 0!==r?r:c.s3Url)&&void 0!==o?o:null),F(null!==(d=null!==(a=c.sanitizedFilename)&&void 0!==a?a:c.originalFilename)&&void 0!==d?d:null),N(null!==(s=c.regions)&&void 0!==s?s:null),U(null!==(u=c.mockupRegion)&&void 0!==u?u:null)),ex("ready")}
1).catch(l=>{e||(em((null==l?void 0:l.message)||"Failed to load this mockup. Please try again."),ex("error"))})),()=>{e=!0}},[c,ek,eM,eL]);let eT=(0,a.useCallback)(()=>{if(!ej||ew)return;let e=ey+1,l=eF.current;eS(!0),(0,er.bE)({...eL,page:e}).then(t=>{var n,i,r;if(eF.current!==l)return;let o=null!==(r=null==t?void 0:null===(n=t.data)||void 0===n?void 0:n.files)&&void 0!==r?r:[];en(e=>{let l=new Set(e.map(e=>e.id));return[...e,...o.filter(e=>!l.has(e.id))]}),eb(e),e_(eu(e,null==t?void 0:null===(i=t.data)||void 0===i?void 0:i.total,o.length))}).catch(e=>{eF.current===l&&O.Am.error((null==e?void 0:e.message)||"Failed to load more mockup templates. Try again.")}).finally(()=>{eF.current===l&&eS(!1)})},[ej,ew,ey,eL]),eN=(0,eo.F6)({regions:T,mockupRegion:W}),eW=!m||Array.isArray(g)&&g.some(e=>(null==e?void 0:e.label)===P),eU=null!=I&&null!=P&&eN&&eW,eH=Array.isArray(T)&&T.length>1,eB=(0,et.AI)(T,W),eV=null!=H?H:eB,eK=(0,a.useCallback)(e=>{var l,t,n,i;(0,eo.F6)(e)&&(C(e.id),z(null!==(t=null!==(l=e.thumbnailUrl)&&void 0!==l?l:e.s3Url)&&void 0!==t?t:null),F(e.sanitizedFilename||e.originalFilename||null),N(null!==(n=e.regions)&&void 0!==n?n:null),U(null!==(i=e.mockupRegion)&&void 0!==i?i:null),G((0,et.AI)(e.regions,e.mockupRegion)),E({}))},[]),eq=(0,a.useCallback)(e=>{R(e.target.value)},[]),eG=(0,a.useCallback)((e,l)=>{E(t=>({...t,[e]:l}))},[]),eY=(0,a.useCallback)(()=>eI(e=>e+1),[]),eQ=(0,a.useCallback)(()=>{var e;if(!eU)return;let l=null!=H&&JSON.stringify(H)!==JSON.stringify(eB),t={},n=0;eH&&T.forEach((e,l)=>{var i;let r=ep(e,l),o=null!==(i=A[r])&&void 0!==i?i:P;t[r]=o,o!==P&&(n+=1)}),f({mockupTemplateId:I,designLabel:P,_templateThumbUrl:null!=M?M:null,_templateFilename:null!=D?D:null,_templateName:null!=D?D:null,_templateRegions:null!=T?T:null,_templateRegion:null!=W?W:null,mockupPlacement:l?H:null,...Object.keys(t).length>0?{designLabelsByRegion:t}:{}}),(0,Z.L)("preset.mockup_slot.saved",{region_count:null!==(e=null==T?void 0:T.length)&&void 0!==e?e:null!=W?1:0,per_region_assigned_count:n})},[eU,I,P,A,eH,M,D,T,W,H,eB,f]);return(0,n.jsxs)($.Z,{open:c,onClose:p,title:j?v?"Edit mockup slot â slot ".concat(v):"Edit mockup slot":v?"Use mockup slot â slot ".concat(v):"Use mockup slot",size:"sm",fullWidth:!0,actions:(0,n.jsxs)(y.Z,{sx:{display:"flex",gap:1},children:[(0,n.jsx)(w.f,{text:"Cancel",color:"white",width:"auto",className:"whitespace-nowrap",onClick:p}),(0,n.jsx)(w.f,{text:j?"Save changes":"Save slot",color:"blue",width:"auto",className:"whitespace-nowrap",disabled:!eU,onClick:eQ})]}),children:[eM?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:1.5,mb:2},children:[(0,n.jsx)(y.Z,{sx:{flex:"1 1 200px",minWidth:0},children:(0,n.jsx)(J.Z,{placeholder:"Search mockupsâ¦",size:"sm",fullWidth:!0,value:eC,debounceMs:300,onChange:eZ,onClear:()=>eZ("")})}),(0,n.jsx)(ee.Kl,{label:"Collection",value:eP,options:eD,onChange:eR})]}),"loading"===ef?(0,n.jsx)(y.Z,{sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(100px, 1fr))",gap:1,maxHeight:300,overflowY:"auto",border:"1px solid var(--lv-border-default)",borderRadius:2,p:1},children:Array.from({length:8}).map((e,l)=>(0,n.jsx)(V.Z,{variant:"rectangular",sx:{borderRadius:"8px",aspectRatio:"1 / 1"}},l))}):"error"===ef?(0,n.jsx)(K.Z,{severity:"error",action:(0,n.jsx)(w.f,{text:"Retry",color:"white",width:"auto",className:"whitespace-nowrap",onClick:eY}),sx:{borderRadius:"8px"},children:eg}):0===Y.length?(0,n.jsx)(y.Z,{sx:{py:4,textAlign:"center"},children:(0,n.jsx)(L.Z,{sx:{color:"var(--lv-text-tertiary)",fontSize:13},children:eO?eC.trim()?'No mockups match "'.concat(eC.trim(),'".'):"No mockups in this collection.":"No mockup templates yet. Create some in the Mockup Generator first."})}):(0,n.jsx)(y.Z,{sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(100px, 1fr))",gap:1,maxHeight:300,overflowY:"auto",border:"1px solid var(--lv-border-default)",borderRadius:2,p:1},children:Y.map(e=>{let l=e.sanitizedFilename||e.originalFilename||"mockup",t=e.id===I,i=!(0,eo.F6)(e);return(0,n.jsxs)(y.Z,{onClick:()=>eK(e),"aria-disabled":i||void 0,title:i?ec:void 0,sx:{borderRadius:2,overflow:"hidden",cursor:i?"not-allowed":"pointer",position:"relative",opacity:i?.5:1,border:t?"2px solid var(--lv-selected)":"0.5px solid var(--lv-border-default)",boxShadow:"0px 1px 4px -2px rgba(0, 0, 0, 0.25)",bgcolor:"var(--lv-bg-elevated)",...i?{}:{"&:hover":{borderColor:"var(--lv-selected)",boxShadow:"0px 1px 4px -2px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--lv-selected)"}},transition:"border-color 150ms, box-shadow 150ms"},children:[t&&(0,n.jsx)(y.Z,{sx:{position:"absolute",top:4,right:4,zIndex:2,width:20,height:20,borderRadius:"50%",bgcolor:"var(--lv-selected)",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,n.jsx)(Q.Z,{size:12,color:"#fff"})}),(0,n.jsx)(eh,{file:e,name:l}),(0,n.jsxs)(y.Z,{sx:{px:.75,py:.5}
1,children:[(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l}),i?(0,n.jsx)(L.Z,{sx:{fontSize:9,fontWeight:600,color:"var(--lv-warning)"},children:"Define print regions first"}):e.fileSize&&(0,n.jsx)(L.Z,{sx:{fontSize:9,color:"var(--lv-text-tertiary)"},children:(0,ea.td)(e.fileSize)})]})]},e.id)})}),"ready"===ef&&ej&&(0,n.jsx)(y.Z,{sx:{display:"flex",justifyContent:"center",mt:1},children:(0,n.jsx)(w.f,{text:ew?"Loadingâ¦":"Load more",color:"white",width:"auto",className:"whitespace-nowrap",disabled:ew,onClick:eT,icon:ew?(0,n.jsx)(q.D8,{size:12,sx:{color:"inherit"}}):void 0})})]}):(0,n.jsx)(n.Fragment,{children:"loading"===ef?(0,n.jsx)(V.Z,{variant:"rectangular",sx:{borderRadius:"8px",width:96,aspectRatio:"1 / 1"}}):"error"===ef?(0,n.jsx)(K.Z,{severity:"error",action:(0,n.jsx)(w.f,{text:"Retry",color:"white",width:"auto",className:"whitespace-nowrap",onClick:eY}),sx:{borderRadius:"8px"},children:eg}):null!=I?(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1.5},children:[(0,n.jsx)(y.Z,{sx:{width:96,flexShrink:0,borderRadius:2,overflow:"hidden",border:"1px solid var(--lv-border-default)",bgcolor:"var(--lv-bg-elevated)"},children:(0,n.jsx)(eh,{file:{id:I,thumbnailUrl:M,s3Url:M,regions:T,mockupRegion:W},name:D||"mockup"})}),(0,n.jsxs)(y.Z,{sx:{minWidth:0},children:[D&&(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:D}),(0,n.jsx)(w.f,{text:"Change mockup",color:"no-background",width:"auto",className:"whitespace-nowrap",onClick:()=>eE(!0)})]})]}):null}),null!=I&&!eN&&(0,n.jsx)(K.Z,{severity:"warning",sx:{borderRadius:"8px",mt:2},action:(0,n.jsx)(w.f,{text:"Define regions",color:"white",width:"auto",className:"whitespace-nowrap",onClick:()=>window.open("/dashboard/asset-library?tab=mockup-templates","_blank","noopener,noreferrer")}),children:ec}),m&&!eW&&(0,n.jsx)(K.Z,{severity:"warning",sx:{borderRadius:"8px",mt:2},children:b||"Attach a design file first."}),(0,n.jsxs)(B.Z,{in:null!=I,unmountOnExit:!0,children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.75,mt:2},children:[!eH&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(L.Z,{variant:"caption",sx:{fontWeight:600,color:ei.oR.textSecondary},children:"Design slot"}),(0,n.jsx)(X.Z,{cozy:!0,value:P,onChange:eq,options:k,fullWidth:!1,formControlSx:{maxWidth:240}})]}),(0,n.jsx)(ev,{maxDesignLabels:x,designFiles:g})]}),eH&&(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.75,mt:2,pt:2,borderTop:"1px solid ".concat(ei.oR.borderSubtle)},children:[(0,n.jsx)(L.Z,{variant:"caption",sx:{fontWeight:600,color:ei.oR.textSecondary},children:"Per-region designs"}),(0,n.jsxs)(L.Z,{variant:"caption",sx:{color:ei.oR.textTertiary,fontSize:"0.68rem",lineHeight:1.5},children:["This template has ",T.length," print regions â set a design for each below."]}),T.map((e,l)=>{var t,i;let r=ep(e,l),o=(null==e?void 0:null===(i=e.label)||void 0===i?void 0:i.trim())||"Region ".concat(l+1);return(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1},children:[(0,n.jsx)(L.Z,{variant:"caption",title:o,sx:{color:ei.oR.textSecondary,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o}),(0,n.jsx)(X.Z,{value:null!==(t=A[r])&&void 0!==t?t:P,onChange:e=>eG(r,e.target.value),options:k,fullWidth:!1,formControlSx:{width:200,flexShrink:0},SelectDisplayProps:{"aria-label":"Design for ".concat(o)}})]},r)})]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1,mt:2,pt:2,borderTop:"1px solid ".concat(ei.oR.borderSubtle)},children:[(0,n.jsx)(L.Z,{variant:"caption",sx:{fontWeight:600,color:ei.oR.textSecondary},children:"Mockup controls"}),(0,n.jsx)(L.Z,{variant:"caption",sx:{color:ei.oR.textTertiary,fontSize:"0.68rem",lineHeight:1.5},children:"How the design sits on this mockup. Applied when the mockup renders."}),(0,n.jsx)(et.ZP,{value:eV,onChange:G})]})]})]})}var ex=t(16904),eg=t(78942),em=t(86804);let ey=e=>e<5e3?1e3:e<15e3?2e3:e<45e3?3e3:5e3,eb="mockup-render-quota",ej=new Set(["psd_daily_quota_exceeded","inhouse_daily_quota_exceeded"]),e_=e=>{var l,t,n;let i=null==e?void 0:null===(l=e.response)||void 0===l?void 0:l.data;return null!==(n=null!==(t=null==i?void 0:i.data)&&void 0!==t?t:i)&&void 0!==n?n:{}},ew=e=>{var l;return(null==e?void 0:null===(l=e.response)||void 0===l?void 0:l.status)===429&&ej.has(e_(e).code)},eS=e=>{let l=e_(e),t=(null==l?void 0:l.resets_at)?new Date(l.resets_at):null,n=Number.isFinite(null==l?void 0:l.limit)&&Number.isFinite(null==l?void 0:l.remaining)?" (".concat(l.limit-l.remaining,"/").concat(l.limit," used)"):Number.isFinite(null==l?void 0:l.limit)?" (".concat(l.limit,"/day)"):"";if(!t||Number.isNaN(t.getTime()))return"Daily mockup limit reached".concat(n," â resets automatically, try again later.");let i=Math.max(1,Math.round((t.getTime()-Date.now())/36e5));return"Daily mockup limit reached".concat(n," â resets in about ").concat(i," hour").concat(1===i?"":"s",".")}
1,ek=e=>{var l,t,n;return null!==(n=null!==(t=null==e?void 0:null===(l=e.data)||void 0===l?void 0:l.data)&&void 0!==t?t:null==e?void 0:e.data)&&void 0!==n?n:{}};var eI=t(4465),eC=t(3397),eZ=t(15111),eP=t(52056),eR=t(30075);let eA=e=>null==e?null:String(e),eE="lv-pod-file-links-changed",eM="lv-pod-open-canvas";function ez(e,l){window.dispatchEvent(new CustomEvent(e,{detail:l}))}function eD(e,l){return null!=e&&null!=l&&String(e)===String(l)}function eL(e){let l=new Map,t=e=>{var t,n,i,r,o,a,d,s,u,c,p,v,h;let f=eA(null!==(r=null!==(i=null==e?void 0:e.id)&&void 0!==i?i:null==e?void 0:e.assetFileId)&&void 0!==r?r:null);if(null==f||l.has(f))return;let x=!!(0,eC.Bp)(e)||"psd"===String(null!==(v=null==e?void 0:e.fileExtension)&&void 0!==v?v:"").toLowerCase().replace(/^\./,"")||"image/vnd.adobe.photoshop"===String(null!==(h=null==e?void 0:e.mimeType)&&void 0!==h?h:"").toLowerCase();l.set(f,{assetFileId:f,name:null!==(a=null!==(o=e.originalFilename)&&void 0!==o?o:e.fileName)&&void 0!==a?a:"Design",thumbnail:x?null!==(d=e.thumbnailUrl)&&void 0!==d?d:null:null!==(u=null!==(s=e.s3Url)&&void 0!==s?s:e.thumbnailUrl)&&void 0!==u?u:null,width:null!==(c=null===(t=e.metadata)||void 0===t?void 0:t.width)&&void 0!==c?c:null,height:null!==(p=null===(n=e.metadata)||void 0===n?void 0:n.height)&&void 0!==p?p:null})};for(let l of null!=e?e:[]){var n;(null==l?void 0:l.type)==="file"&&l.file?t(l.file):(null==l?void 0:l.type)==="collection"&&Array.isArray(null===(n=l.collection)||void 0===n?void 0:n.files)&&l.collection.files.forEach(t)}return l}function eO(e){let{key:l,file:t,product:n,printArea:i,printAreaName:r,link:o}=e;return{key:l,file:t,product:n,printArea:i,link:o,productName:[null==n?void 0:n.brand,null==n?void 0:n.model].filter(e=>"string"==typeof e&&e.trim().length>0).join(" ").trim()||(null==n?void 0:n.name)||"Product",printAreaName:(0,eP.tw)(r)}}function eF(e){let{preview:l,onOpen:t}=e,{file:i,product:r,link:o,printArea:d,productName:s,printAreaName:u}=l,[c,p]=(0,a.useState)(!1),v=(0,a.useMemo)(()=>{let e=(0,eP.ED)(o,r,i,d),l=(0,eP.DL)(o,e),{w:t,h:n}=(0,eP.QV)(l,e),{xOffsetPct:a,yOffsetPct:s}=(0,eP.Iv)(l),u=(0,eP.xK)({link:l,printAreaWidthIn:e.printAreaWidthIn,printAreaHeightIn:e.printAreaHeightIn,widthPct:t,heightPct:n}),c=(0,eP.O4)({link:l,printAreaWidthIn:e.printAreaWidthIn,printAreaHeightIn:e.printAreaHeightIn,rotatedWidthPct:u.rotatedWidthPct,rotatedHeightPct:u.rotatedHeightPct,xOffsetPct:a,yOffsetPct:s});return{...u,...c,ctx:e}}
1,[o,r,i,d]),{printAreaWidthIn:h,printAreaHeightIn:f}=v.ctx,{width:x,height:g}=function(e,l){let t=e/l;if(!Number.isFinite(t)||t<=0)return{width:96,height:96};let n=96*t;if(n<=220)return{width:n,height:96};let i=220/n;return{width:n*i,height:96*i}}(h,f);return(0,a.useEffect)(()=>{p(!1)},[i.thumbnail]),(0,n.jsx)("button",{type:"button",onClick:t,"aria-label":"Edit ".concat(s," â ").concat(u," print area in the canvas editor"),"data-testid":"pod-print-area-preview-open",className:"flex-shrink-0 block p-0 bg-transparent border-0 text-left cursor-pointer rounded-lv-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lv-focus",style:{width:x},children:(0,n.jsxs)("div",{"aria-hidden":"true",children:[(0,n.jsx)("div",{"data-testid":"pod-print-area-preview-card",style:{position:"relative",width:x,height:g,overflow:"hidden",...eR.$P,border:"1px solid ".concat(ei.oR.borderMedia),borderRadius:ei.PY.sm},children:!c&&(0,n.jsx)("div",{"data-testid":"pod-print-area-preview-design-box",style:{position:"absolute",left:"".concat(v.designLeftPct,"%"),top:"".concat(v.designTopPct,"%"),width:"".concat(v.rotatedWidthPct,"%"),height:"".concat(v.rotatedHeightPct,"%"),pointerEvents:"none",userSelect:"none",overflow:"visible"},children:(0,n.jsx)("div",{style:{position:"absolute",left:"".concat(v.innerLeftPctOfOuter,"%"),top:"".concat(v.innerTopPctOfOuter,"%"),width:"".concat(v.innerWidthPctOfOuter,"%"),height:"".concat(v.innerHeightPctOfOuter,"%"),transform:"rotate(".concat(v.angle,"deg)"),transformOrigin:"center center"},children:(0,n.jsx)("img",{src:i.thumbnail,alt:"","aria-hidden":"true",draggable:!1,"data-testid":"pod-print-area-preview-design",onError:()=>p(!0),style:{width:"100%",height:"100%",objectFit:"contain",display:"block",pointerEvents:"none"}})})})}),(0,n.jsx)("div",{title:s,className:"mt-1 text-lv-caption text-lv-text-primary truncate",children:s}),(0,n.jsx)("div",{className:"text-lv-caption text-lv-text-secondary truncate",children:u}),!v.ctx.dimsKnown&&(0,n.jsx)("div",{"data-testid":"pod-print-area-preview-size-unknown",className:"text-lv-caption text-lv-warning-strong truncate",title:"Print-area size unknown â re-pick the print provider",children:"Size unknown"})]})})}function eT(e){let{listingId:l,podProducts:t,refreshKey:i}=e,[r,o]=(0,a.useState)({assignments:[],deliverables:[]}),[d,s]=(0,a.useState)(null),u=(0,a.useRef)(0),c=(0,a.useMemo)(()=>Array.isArray(t)?t.map(e=>(0,eZ.ZV)(e)?e:(0,eZ.c9)(e)):[],[t]),p=(0,a.useMemo)(()=>c.map(e=>{var l,t,n;return"".concat(null!==(t=null==e?void 0:e.podProductId)&&void 0!==t?t:"",":").concat(null!==(n=null==e?void 0:null===(l=e.product)||void 0===l?void 0:l.id)&&void 0!==n?n:"")}).join(","),[c]);(0,a.useEffect)(()=>{if(!l||0===c.length){o({assignments:[],deliverables:[]});return}let e=!1,t=u.current,n="undefined"!=typeof AbortController?new AbortController:null,i=n?{signal:n.signal}:void 0;return Promise.all([(0,eI.vv)(l,i),(0,eI.f_)(l,i)]).then(l=>{var n,i,r,a,d,c;let[p,v]=l;if(e)return;let h=null!==(a=null!==(r=null==p?void 0:null===(n=p.data)||void 0===n?void 0:n.data)&&void 0!==r?r:null==p?void 0:p.data)&&void 0!==a?a:[],f=null!==(c=null!==(d=null==v?void 0:null===(i=v.data)||void 0===i?void 0:i.data)&&void 0!==d?d:null==v?void 0:v.data)&&void 0!==c?c:{};o({assignments:Array.isArray(h)?h:[],deliverables:Array.isArray(null==f?void 0:f.deliverables)?f.deliverables:[]}),u.current===t&&s(null)}).catch(()=>{e||o({assignments:[],deliverables:[]})}),()=>{e=!0,null==n||n.abort()}},[l,p,i]),(0,a.useEffect)(()=>{if(!l)return;let e=e=>{let t=null==e?void 0:e.detail;if(!eD(null==t?void 0:t.listingId,l))return;u.current+=1;let n=Array.isArray(t.links)?t.links:[];s({links:n,managedFileIds:Array.isArray(t.managedFileIds)?t.managedFileIds:n.map(e=>null==e?void 0:e.assetFileId).filter(e=>null!=e)})};return window.addEventListener(eE,e),()=>window.removeEventListener(eE,e)},[l]);let v=(0,a.useMemo)(()=>{var e;let l=function(e){let{assignments:l,deliverables:t,podProducts:n}=e;if(!Array.isArray(l)||!Array.isArray(n)||0===n.length)return[];let i=eL(t),r=[],o=new Set;
1return l.forEach(e=>{var l,t,a,d,s;if((null==e?void 0:e.is_enabled)===!1)return;let u=eA(null!==(t=null!==(l=null==e?void 0:e.asset_file_id)&&void 0!==l?l:null==e?void 0:e.assetFileId)&&void 0!==t?t:null),c=null!==(a=i.get(u))&&void 0!==a?a:null;if(!(null==c?void 0:c.thumbnail))return;let p=null!==(s=null!==(d=e.targets)&&void 0!==d?d:e.assigned_to)&&void 0!==s?s:[];(Array.isArray(p)?p:[]).forEach((l,t)=>{var i,a,d;let s=(0,eZ.UE)(n,null==l?void 0:l.pod_product_id),p=null==s?void 0:s.product;if(!p)return;let v=(0,eP.z_)(p.print_areas,null==l?void 0:l.print_area_id),h=(null==v?void 0:v.name)||(null==v?void 0:v.position)||null;if(!v||!h)return;let f="".concat(u,"::").concat(p.id,"::").concat(h);o.has(f)||(o.add(f),r.push(eO({key:"".concat(null!==(i=e.id)&&void 0!==i?i:u,"-").concat(t),file:c,product:p,printArea:v,printAreaName:h,link:(0,eP.lP)(l,{linkId:"preview-".concat(null!==(a=e.id)&&void 0!==a?a:u,"-").concat(t),productId:p.id,printAreaName:h,printAreaId:null!==(d=v.id)&&void 0!==d?d:null,geometry:(0,eP.QZ)(v,c)})})))})}),r}({assignments:r.assignments,deliverables:r.deliverables,podProducts:c});if(!d)return l;let t=new Set((null!==(e=d.managedFileIds)&&void 0!==e?e:[]).map(eA));return[...l.filter(e=>!t.has(eA(e.file.assetFileId))),...function(e){let{liveLinks:l,deliverables:t,podProducts:n}=e;if(!Array.isArray(l)||!Array.isArray(n)||0===n.length)return[];let i=eL(t),r=[],o=new Set;return l.forEach((e,l)=>{var t,a,d,s,u,c;let{assetFileId:p,link:v}=null!=e?e:{};if(!v)return;let h=null!==(a=i.get(eA(p)))&&void 0!==a?a:null;if(!(null==h?void 0:h.thumbnail))return;let f=null===(t=n.find(e=>{var l;return(null==e?void 0:null===(l=e.product)||void 0===l?void 0:l.id)!=null&&eA(e.product.id)===eA(v.productId)}))||void 0===t?void 0:t.product;if(!f)return;let x=null!==(u=null!==(s=(0,eP.z_)(f.print_areas,v.printAreaId))&&void 0!==s?s:(null!==(d=f.print_areas)&&void 0!==d?d:[]).find(e=>{var l;return(null!==(l=null==e?void 0:e.name)&&void 0!==l?l:null==e?void 0:e.position)===v.printArea}))&&void 0!==u?u:null,g=(null==x?void 0:x.name)||(null==x?void 0:x.position)||null;if(!x||!g)return;let m="".concat(p,"::").concat(f.id,"::").concat(g);o.has(m)||(o.add(m),r.push(eO({key:"live-".concat(null!==(c=v.id)&&void 0!==c?c:"".concat(p,"-").concat(l)),file:h,product:f,printArea:x,printAreaName:g,link:v})))}),r}({liveLinks:d.links,deliverables:r.deliverables,podProducts:c})]},[d,r,c]),h=e=>{var t,n,i,r,o,a,d,s;ez(eM,{listingId:l,assetFileId:eA(e.file.assetFileId),linkId:eA(null===(t=e.link)||void 0===t?void 0:t.id),productId:eA(null===(n=e.product)||void 0===n?void 0:n.id),printAreaId:eA(null===(i=e.printArea)||void 0===i?void 0:i.id),printArea:null!==(s=null!==(d=null===(r=e.printArea)||void 0===r?void 0:r.name)&&void 0!==d?d:null===(o=e.printArea)||void 0===o?void 0:o.position)&&void 0!==s?s:null}),null===(a=document.getElementById("product"))||void 0===a||a.scrollIntoView({behavior:"smooth",block:"start"})};return 0===v.length?null:(0,n.jsxs)(y.Z,{sx:{mt:2},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:1,mb:1},children:[(0,n.jsx)("span",{className:"text-lv-btn text-lv-text-primary",children:"Print area previews"}),(0,n.jsx)("span",{className:"text-lv-caption text-lv-text-secondary",children:"Click a preview to edit its placement"})]}),(0,n.jsx)(y.Z,{sx:{display:"flex",alignItems:"flex-start",gap:1.5,overflowX:"auto",pb:.5},children:v.map(e=>(0,n.jsx)(eF,{preview:e,onOpen:()=>h(e)},e.key))})]})}var eN=t(32615),eW=t(41175),eU=t(74315);let eH=(0,z.default)(()=>Promise.all([t.e(3407),t.e(4085),t.e(6569),t.e(405),t.e(5607),t.e(9784)]).then(t.bind(t,33329)),{loadableGenerated:{webpack:()=>[33329]},ssr:!1}),eB="Attach a design file to this listing first, then save the mockup slot.";function eV(e){let{bg:l,text:t}=eU.fx[(0,g.VY)(e)];return{fontWeight:700,background:l,color:t}}let eK="var(--lv-chart-tooltip-text)",eq="color-mix(in srgb, var(--lv-chart-tooltip-text) 75%, transparent)",eG=e=>Number.isFinite(e)?{scored:!0,text:"".concat(e,"%")}:{scored:!1,text:"â"},eY=Object.freeze({fontWeight:700,background:"transparent",color:eK});function eQ(e){var l,t,i,r,o,a,d,s,u,c;let{score:p}=e,v=null===(t=p.score)||void 0===t?void 0:null===(l=t.percentages)||void 0===l?void 0:l.numberOfPhotos,h=null===(r=p.score)||void 0===r?void 0:null===(i=r.percentages)||void 0===i?void 0:i.photoQuality,f=eG(v),x=eG(h),g=null!==(s=null===(o=p.recommendations)||void 0===o?void 0:o.imageCount)&&void 0!==s?s:0,m=null!==(u=null===(d=p.recommendations)||void 0===d?void 0:null===(a=d.lowQualityImages)||void 0===a?void 0:a.length)&&void 0!==u?u:0,y=null!==(c=p.allImages)&&void 0!==c?c:[],b=Array.from({length:U.j$},(e,l)=>y[l]||null);return(0,n.jsxs)("div",{style:{width:"340px"},children:[(0,n.jsx)("div",{style:{fontWeight:700,fontSize:13,color:eK,marginBottom:"14px"},children:"Photo Score"}),(0,n.jsxs)("div",{style:{marginBottom:"14px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"4px"},children:[(0,n.jsx)("span",{style:{...ei.cp.subHeader,color:eK},children:"Number of photos"}),(0,n.jsx)(D.Z,{label:f.text,size:"small",sx:f.scored?eV(v):eY})]}),(0,n.jsxs)("p",{style:{fontSize:12,color:eq,margin:"0 0 2px 0"},children:[(0,n.jsx)("b",{children:"Etsy Recommends:"})," At least 5 high-quality images to maximize the score (4 points per image)."]}),(0,n.jsxs)("p",{style:{fontSize:12,color:eq,margin:0},children:[(0,n.jsx)("b",{children:"Your listing:"})," Has ",g," ",1===g?"image":"images","."]})]}),(0,n.jsxs)("div",{style:{marginBottom:"12px"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"4px"},children:[(0,n.jsx)("span",{style:{...ei.cp.subHeader,color:eK},children:"Photo quality"}
1),(0,n.jsx)(D.Z,{label:x.text,size:"small",sx:x.scored?eV(h):eY})]}),(0,n.jsxs)("p",{style:{fontSize:12,color:eq,margin:"0 0 2px 0"},children:[(0,n.jsx)("b",{children:"Etsy Recommends:"})," Images with at least 2,000px on the shortest side of the image and a resolution of 72 PPI. Low quality images deduct from your score."]}),(0,n.jsxs)("p",{style:{fontSize:12,color:eq,margin:"0 0 10px 0"},children:[(0,n.jsx)("b",{children:"Your listing:"})," Has ",m," low quality images."]}),b.some(Boolean)&&(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:b.map((e,l)=>e?(0,n.jsx)("div",{style:{width:52,height:52,borderRadius:"8px",border:e.isLowQuality?"2px solid red":"1px solid var(--lv-border-default)",background:"url(".concat(e.srcFull,") center/cover no-repeat"),flexShrink:0}},l):null)})]})]})}function e$(e){var l;let{images:t,setImages:i,video:o,setVideo:s,score:u,conflictField:c=!1,validation:p={},queuedImages:h=null,mode:x="listing",typeOption:m,enableMockupSlotConfig:b=!1,fileAssignments:j,onRefreshFileAssignments:_,designFileAssignments:w,showPodPrintAreaPreview:S=!1,listingId:k,surfaceKey:I=null,podProducts:C}=e,Z=(0,a.useMemo)(()=>{if(Array.isArray(t)&&t.length===U.j$)return t;let e=Array(U.j$).fill(null).map(()=>({src:null}));if(Array.isArray(t))for(let l=0;l<Math.min(t.length,U.j$);l++)t[l]&&(e[l]=t[l]);return e},[t]),{pendingSlots:P,hasUnmatchedPending:R}=(0,a.useMemo)(()=>(0,U.nU)(Z,h),[Z,h]),[A]=(0,a.useState)(!1),[E,M]=(0,a.useState)(!1),z=(0,a.useRef)(null),{available:D}=(0,T.Z)(),[B,V]=(0,a.useState)(null),[K,q]=(0,a.useState)(null),G=function(e,l){var t,n;let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if((null==l?void 0:l.id)==null)return;let o=Z.map(e=>null!=e?e:{src:null});if(!(e<0)&&!(e>=U.j$)){if(null!=r){let l=Z[e];if((0,U.kt)(l)||String(null!==(t=null==l?void 0:l.assetFileId)&&void 0!==t?t:"")!==String(r)){O.Am.error("That photo slot changed while you were editing. The edited copy is in your library â add it from there.");return}}o[e]={type:"file",src:null!==(n=l.s3Url)&&void 0!==n?n:null,assetFileId:l.id,slotIndex:e},i(o)}},[Y,Q]=(0,a.useState)(null),$=(0,a.useMemo)(()=>Array.isArray(w)?w.filter(e=>(null==e?void 0:e.is_enabled)!==!1).slice(0,10).map((e,l)=>{var t,n;return{label:String.fromCharCode(65+l),name:null!==(n=null!==(t=null==e?void 0:e.file_name)&&void 0!==t?t:null==e?void 0:e.fileName)&&void 0!==n?n:null}}):null,[w]),X=(0,a.useMemo)(()=>b?(0,U.x3)((0,U.PM)(Z,w)):"",[b,Z,w]),J=b&&"listing"===x&&null!=k,ee=(0,a.useRef)(i);ee.current=i;let el=(0,a.useCallback)((e,l)=>{let t=":slot-",n=e.lastIndexOf(t);if(n<0)return;let i=Number(e.slice(n+t.length));!Number.isInteger(i)||i<0||i>=U.j$||ee.current(e=>{let t=Array.isArray(e)?e:[],n=Array(U.j$).fill(null).map((e,l)=>{var n;return null!==(n=t[l])&&void 0!==n?n:{src:null}});return(0,U.kt)(n[i])?(n[i]={...n[i],...l},(0,U.J3)(n,t)):e})},[]),{requestRender:et,forget:en}=function(e){let{renderFn:l,patchSlot:t,enabled:n=!0}=e,i=(0,a.useRef)(new Map),r=(0,a.useRef)(0),o=(0,a.useRef)(new Map),d=(0,a.useRef)(new Map),s=(0,a.useRef)(l);s.current=l;let u=(0,a.useRef)(t);u.current=t;let c=(0,a.useCallback)(e=>{let l=o.current.get(e);l&&(clearTimeout(l),o.current.delete(e)),d.current.delete(e)},[]),p=(0,a.useCallback)((e,l,t,n)=>{var r,o,a,s,c,p,v,h,f,x,g,m;let y=i.current.get(e);y&&y.signature===l&&y.requestToken===t&&(d.current.delete(e),i.current.set(e,{...y,jobId:null,status:"ready",renderInputHash:null!==(o=null!==(r=n.renderInputHash)&&void 0!==r?r:y.renderInputHash)&&void 0!==o?o:null}),u.current(e,{_renderStatus:"ready",_renderInputSignature:l,_renderThumbUrl:null!==(a=n.thumbUrl)&&void 0!==a?a:null,_renderedUrl:null!==(c=null!==(s=n.thumbUrl)&&void 0!==s?s:n.fullUrl)&&void 0!==c?c:null,_renderFullUrl:null!==(v=null!==(p=n.fullUrl)&&void 0!==p?p:n.thumbUrl)&&void 0!==v?v:null,_renderOutputFileId:null!==(h=n.outputFileId)&&void 0!==h?h:null,_renderDesignAssetFileId:null!==(f=y.designAssetFileId)&&void 0!==f?f:null,_renderDesignsByRegion:null!==(x=y.designsByRegion)&&void 0!==x?x:null,_renderInputHash:null!==(m=null!==(g=n.renderInputHash)&&void 0!==g?g:y.renderInputHash)&&void 0!==m?m:null,_renderIsWatermarked:!!n.isWatermarked,_renderError:null,_renderQuotaBlocked:!1,_renderJobId:null}))},[]),v=(0,a.useCallback)(async(e,l,t,n)=>{let r=()=>{let n=i.current.get(e);return!!n&&n.signature===l&&n.requestToken===t};if(!r())return;let o=n;if(null!=n.outputFileId)try{var a,d,s;let e=ek(await (0,er.hn)(n.outputFileId)),l=null!==(d=null!==(a=e.activeUrl)&&void 0!==a?a:e.s3Url)&&void 0!==d?d:null;l&&(o={...n,fullUrl:l,thumbUrl:null!==(s=e.thumbnailUrl)&&void 0!==s?s:l})}catch(e){}r()&&p(e,l,t,o)},[p]),h=(0,a.useCallback)(function(e,l,t,n){let{quotaBlocked:r=!1}=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{},o=i.current.get(e);o&&o.signature===l&&o.requestToken===t&&(d.current.delete(e),i.current.set(e,{...o,jobId:null,status:"failed"}),u.current(e,{_renderStatus:"failed",_renderInputSignature:l,_renderError:n||"Render failed",_renderQuotaBlocked:!0===r,_renderJobId:null}))},[]),f=(0,a.useCallback)((e,l,t,n,r)=>{c(e);let a=Date.now(),s=()=>{let r=i.current.get(e);return!!r&&r.jobId===l&&r.signature===t&&r.requestToken===n},p=()=>{let r=i.current.get(e);r&&r.jobId===l&&r.signature===t&&r.requestToken===n&&"background"!==r.status&&(i.current.set(e,{...r,status:"background"}),u.current(e,{_renderStatus:"background",_renderInputSignature:t,_renderError:null}))},f=()=>{let l=Date.now()-a,t=l>=36e4?3e4:ey(l);o.current.set(e,setTimeout(x,t))};async function x(){var i,d,u,c,x,g,m,y,b;if(o.current.delete(e),s())try{let o=ek(await (0,em.jW)(l));if(!s())return;let m=o.status;if("completed"===m||"partial_failure"===m){let l=Array.isArray(o.results)?o.results[0]:null,a=null!==(d=null!==(i=null==l?void 0:l.outputFileId)&&void 0!==i?i:null==l?void 0:l.output_file_id)&&void 0!==d?d:null,s=null!==(c=null!==(u=null==l?void 0:l.thumbnailUrl)&&void 0!==u?u:null==l?void 0:l.imageUrl)&&void 0!==c?c:null;l&&(null!=a||s)?await v(e,t,n,{thumbUrl:s,fullUrl:null!==(x=l.imageUrl)&&void 0!==x?x:null,outputFileId:a,renderInputHash:r,isWatermarked:null!==(g=o.isWatermarked)&&void 0!==g?g:o.is_watermarked}):h(e,t,n,(null==l?void 0:l.error)||"Render produced no image");return}if("failed"===m){h(e,t,n,o.error||"Render failed");return}let y=Date.now()-a;if(y>=18e5){p();return}y>=3e4&&p(),f()}catch(i){if(!s())return;let l=null==i?void 0:null===(m=i.response)||void 0===m?void 0:m.status;if(null==l||l>=500){let e=Date.now()-a;if(e>=18e5){p();return}e>=3e4&&p(),f();return}h(e,t,n,(null==i?void 0:null===(b=i.response)||void 0===b?void 0:null===(y=b.data)||void 0===y?void 0:y.message)||(null==i?void 0:i.message)||"Render poll failed")}}d.current.set(e,()=>{s()&&(clearTimeout(o.current.get(e)),o.current.delete(e),x())}),f()},[h,v,c]),x=(0,a.useCallback)(async(e,l,t,n)=>{var r,a,d,p,g,m,y,b,j,_,w,S,k,I,C,Z,P;c(e);let R=()=>{let l=i.current.get(e);return!!l&&l.signature===t&&l.requestToken===n};try{let c=ek(await s.current({slotKey:e,mockupTemplateId:l.mockupTemplateId,designAssetFileId:l.designAssetFileId,designsByRegion:null!==(r=l.designsByRegion)&&void 0!==r?r:null,placement:null!==(a=l.placement)&&void 0!==a?a:null}));if(!R())return;if("ready"===c.status||"done"===c.cache){await v(e,t,n,{thumbUrl:null!==(p=null!==(d=c.s3Url)&&void 0!==d?d:c.thumbnailUrl)&&void 0!==p?p:null,fullUrl:null!==(g=c.s3Url)&&void 0!==g?g:null,outputFileId:null!==(y=null!==(m=c.outputFileId)&&void 0!==m?m:c.output_file_id)&&void 0!==y?y:null,renderInputHash:null!==(b=c.renderInputHash)&&void 0!==b?b:c.render_input_hash,isWatermarked:null!==(j=c.isWatermarked)&&void 0!==j?j:c.is_watermarked});return}if("locked"===c.cache&&null==c.jobId){let r=Number(c.retryAfterMs)||1e3;if(!i.current.get(e)||!R())return;o.current.set(e,setTimeout(()=>{o.current.delete(e),R()&&x(e,l,t,n)},r));return}let I=null!==(w=null!==(_=c.jobId)&&void 0!==_?_:c.job_id)&&void 0!==w?w:null;if(null!=I){let l=null!==(k=null!==(S=c.renderInputHash)&&void 0!==S?S:c.render_input_hash)&&void 0!==k?k:null,r=i.current.get(e);if(!r||!R())return;i.current.set(e,{...r,jobId:I,status:"rendering",renderInputHash:l}),u.current(e,{_renderJobId:I,_renderInputHash:l}),f(e,I,t,n,l);return}h(e,t,n,"Unexpected render response")}catch(o){if(!R())return;let l=null==o?void 0:null===(I=o.response)||void 0===I?void 0:I.status,i=null==o?void 0:null===(C=o.response)||void 0===C?void 0:C.data,r=null!==(P=null==i?void 0:null===(Z=i.data)||void 0===Z?void 0:Z.code)&&void 0!==P?P:null==i?void 0:i.code;
1if(ew(o)){let l=eS(o);O.Am.error(l,{toastId:eb}),h(e,t,n,l,{quotaBlocked:!0});return}429===l&&O.Am.error(eS(o),{toastId:eb}),h(e,t,n,"region_asset_not_owned"===r?"A per-region design isn't in your library â re-pick it and retry.":"unresolvable_region_designs"===r?"This template's regions changed â re-pick the per-region designs and retry.":"listing_not_found"===r?"This listing is no longer available â reload the page and try again.":"flag_off"===r?"Mockup rendering is temporarily unavailable â the mockup will be generated when you publish.":(null==i?void 0:i.message)||(null==o?void 0:o.message)||"Render failed")}},[h,v,c,f]),g=(0,a.useCallback)(function(e,l){var t,o,a;let{force:d=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!n)return"disabled";if(!e)return"invalid";let s=null!==(t=null==l?void 0:l.mockupTemplateId)&&void 0!==t?t:null,c=null!==(o=null==l?void 0:l.designAssetFileId)&&void 0!==o?o:null;if(null==s||null==c)return"invalid";let p=null!==(a=l.designsByRegion)&&void 0!==a?a:null,v=(0,ex.zy)(s,c,p),h=i.current.get(e);if(!d&&h&&h.signature===v&&"failed"!==h.status)return"noop";let f=++r.current;return i.current.set(e,{requestToken:f,signature:v,jobId:null,status:"rendering",renderInputHash:null,mockupTemplateId:s,designAssetFileId:c,designsByRegion:p}),u.current(e,{_renderStatus:"rendering",_renderInputSignature:v,_renderDesignAssetFileId:c,_renderDesignsByRegion:p,_renderError:null,_renderQuotaBlocked:!1}),x(e,{...l,designsByRegion:p},v,f),"fired"},[n,x]),m=(0,a.useCallback)(e=>{i.current.delete(e),c(e)},[c]);return(0,a.useEffect)(()=>{let e=o.current,l=d.current;return()=>{e.forEach(e=>clearTimeout(e)),e.clear(),l.clear()}},[]),(0,a.useEffect)(()=>{if(!n)return;let e=()=>{d.current.forEach(e=>e())};return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[n]),{requestRender:g,forget:m}}({renderFn:(0,a.useCallback)(e=>(0,em.je)({listingId:k,...e}),[k]),patchSlot:el,enabled:J}),ei=(0,a.useRef)(new Map),eo=(0,a.useCallback)((e,l)=>{let t=(0,U.wu)(null!=e?e:"A",j),n=null;if(l&&"object"==typeof l&&!Array.isArray(l)){let e=Object.entries(l).map(e=>{let[l,t]=e;return[l,(0,U.wu)(t,j)]}).filter(e=>{let[,l]=e;return null!==l});e.length>0&&(n=Object.fromEntries(e))}return{base:t,regionIds:n}},[j]),ea=(0,a.useCallback)(function(e,l){var t,n;let{force:i=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!J||!(0,U.kt)(l)||null==l.mockupTemplateId)return!1;let{base:r,regionIds:o}=eo(l.designLabel,l.designLabelsByRegion);if(null==r)return!1;let a=(0,ex.At)(k,e),d=null!==(t=(0,eg.iX)(l.mockupPlacement))&&void 0!==t?t:null,s=JSON.stringify(d),u=null!==(n=ei.current.get(a))&&void 0!==n?n:null;return ei.current.set(a,s),et(a,{mockupTemplateId:l.mockupTemplateId,designAssetFileId:r,designsByRegion:(0,ex.GX)(o,r),placement:d},{force:i||null!==u&&u!==s}),!0},[J,k,et,eo]),ed=(0,a.useCallback)(e=>{ea(e,Z[e],{force:!0})||O.Am.info(eB)},[ea,Z]),es=(()=>{var e,l,t,n,i,r,o,a,d;if(!Y)return null;let s=Z[Y.slotIndex-1];return(0,U.kt)(s)?{mockupTemplateId:null!==(l=s.mockupTemplateId)&&void 0!==l?l:null,designLabel:null!==(t=s.designLabel)&&void 0!==t?t:"A",designLabelsByRegion:null!==(n=s.designLabelsByRegion)&&void 0!==n?n:null,_templateThumbUrl:null!==(i=s._templateThumbUrl)&&void 0!==i?i:null,_templateFilename:null!==(r=s._templateFilename)&&void 0!==r?r:null,_templateRegions:null!==(o=s._templateRegions)&&void 0!==o?o:null,_templateRegion:null!==(a=s._templateRegion)&&void 0!==a?a:null,mockupPlacement:null!==(d=s.mockupPlacement)&&void 0!==d?d:null}:(null==s?void 0:s._lvMockupRender)===!0&&(null==s?void 0:s._mockupTemplateId)!=null?{mockupTemplateId:s._mockupTemplateId,designLabel:null!==(e=s._designLabel)&&void 0!==e?e:"A",designLabelsByRegion:null,_templateThumbUrl:null,_templateFilename:null,_templateRegions:null,_templateRegion:null,mockupPlacement:null}:null})(),eu=(null==u?void 0:u.score)?(0,n.jsx)(d.Z,{label:f.HE.badgeLabels.images,score:u.score.images,total:g.SCORE_RUBRIC.max.images,factor:"images",observed:u.score.observed,tooltipContent:(0,n.jsx)(eQ,{score:u})}):null,ec=(0,a.useMemo)(()=>Z.map(e=>null==e?void 0:e.assetFileId).filter(e=>null!=e),[Z]),ep=async e=>{var l;let t=Z[e];if(!(0,U.kt)(t))return;let n=j;if("function"==typeof _)try{n=await _()}catch(e){n=j}if(!Array.isArray(n))return;let r=(0,U.wu)(null!==(l=t.designLabel)&&void 0!==l?l:"A",n),o=t.designLabelsByRegion,a=null;if(o&&"object"==typeof o&&!Array.isArray(o)){let e=Object.entries(o).map(e=>{let[l,t]=e;return[l,(0,U.wu)(t,n)]}).filter(e=>{let[,l]=e;return null!==l});e.length>0&&(a=Object.fromEntries(e))}if(null!==r){let{designAssetFileIdsByRegion:l,...n}=t,o=[...Z];o[e]={...n,designAssetFileId:r,...a&&{designAssetFileIdsByRegion:a}},i((0,U.J3)(o,Z)),O.Am.success("Design file attached to slot ".concat(e+1,"."))}
1else O.Am.info("No enabled design files yet â upload a design file to this listing first.")};return(0,n.jsxs)(r.Z,{id:"photos-video",title:"Photos & Videos",headerAction:eu,issues:[(0,v.bw)(p)].filter(Boolean),children:[(0,n.jsx)(L.Z,{className:"text-xs text-lv-text-secondary mb-3",children:"Drag and drop images to the slots or click to upload. Drag a filled slot onto another to reorder. First image will be the primary photo."}),(P.size>0||R)&&(0,n.jsx)(y.Z,{sx:{mb:1.5},children:(0,n.jsx)(eW.Z,{label:0===P.size?"An image is pending re-sync to Etsy":R?"Highlighted images (and 1 more) are pending re-sync to Etsy":"Highlighted images are pending re-sync to Etsy",tooltip:"These image changes will publish to Etsy on your next save or sync."})}),(0,n.jsx)(W.Z,{slots:Z,onChange:e=>{if(J)for(let l=0;l<U.j$;l+=1)(0,U.kt)(Z[l])&&!(0,U.kt)(e[l])&&(en((0,ex.At)(k,l)),ei.current.delete((0,ex.At)(k,l)));i((0,U.J3)(e,Z))},maxSlots:U.j$,onBrowseAssetLibrary:e=>{z.current=e,M(!0)},allowPsd:"preset"===x,surfaceKey:null!==(l=null!=I?I:k)&&void 0!==l?l:null,onEditSlotDesign:D?e=>{var l,t,n,i,r;let o=Z[e],a=null!==(l=null==o?void 0:o.assetFileId)&&void 0!==l?l:null;null==a||(0,U.kt)(o)||V({slotIndex:e,assetFile:{id:a,s3Url:null!==(t=null==o?void 0:o.src)&&void 0!==t?t:null,originalFilename:null!==(n=null==o?void 0:o.originalFilename)&&void 0!==n?n:null,metadata:{width:null!==(i=null==o?void 0:o.width)&&void 0!==i?i:null,height:null!==(r=null==o?void 0:o.height)&&void 0!==r?r:null}}})}:void 0,pendingSlots:P,ariaLabel:"Listing photos",editorMode:x,enableMockupSlotConfig:b,typeOption:m,onConfigureMockupSlot:e=>{b&&Q({slotIndex:e+1})},fileAssignments:j,onRefreshMockupSlot:void 0!==j?ep:void 0,liveRenderMode:J,onRetryMockupRender:J?ed:void 0,trailingSlot:(0,n.jsx)(N.ZP,{label:"Video",isVideo:!0,image:o,isLoading:A,onUploadComplete:e=>{s({src:e.src})},onRemove:()=>{s({src:null})}})}),X&&(0,n.jsxs)("div",{role:"status","data-testid":"orphaned-design-warning",className:"mt-3 flex items-start gap-2 rounded-lv-md border border-lv-warning-border bg-lv-warning-surface px-4 py-3",children:[(0,n.jsx)(H.Z,{size:16,className:"mt-0.5 shrink-0 text-lv-warning","aria-hidden":"true"}),(0,n.jsx)("p",{className:"flex-1 text-lv-body text-lv-text-primary",children:X})]}),S&&(0,n.jsx)(eT,{listingId:k,podProducts:C,refreshKey:j}),(0,n.jsx)(ef,{open:b&&null!==Y,onClose:()=>Q(null),slotIndex:null==Y?void 0:Y.slotIndex,initialValue:es,designFiles:$,requireResolvableDesign:J,unresolvedDesignMessage:eB,onSave:e=>{let{mockupTemplateId:l,designLabel:t,designLabelsByRegion:n,_templateThumbUrl:r,_templateFilename:o,_templateName:a,_templateRegions:d,_templateRegion:s,mockupPlacement:u}=e;if(!Y)return;let c=Y.slotIndex-1,p=[...Z];p[c]={type:"mockup_slot",slotIndex:c,mockupTemplateId:l,designLabel:t,...n&&Object.keys(n).length>0&&{designLabelsByRegion:n},_previewState:"idle",...r&&{_templateThumbUrl:r},...o&&{_templateFilename:o},...a&&{_templateName:a},...d&&{_templateRegions:d},...s&&{_templateRegion:s},...u&&{mockupPlacement:u}};let v=null;if(J){let{base:e,regionIds:l}=eo(t,n);v=e,null!=e&&(p[c].designAssetFileId=e,l&&(p[c].designAssetFileIdsByRegion=l))}if(J&&null==v){O.Am.info(eB);return}i((0,U.J3)(p,Z)),Q(null),J&&ea(c,p[c])}}),(0,n.jsx)(eN.default,{open:E,onClose:()=>{M(!1),z.current=null},onSelect:e=>{var l,t,n,r;let o=Array.isArray(e)?e:[e];if(0===o.length)return;let a=Z.map(e=>null!=e?e:{src:null}),d=null!==(l=z.current)&&void 0!==l?l:0;d<U.j$&&(a[d]={type:"file",src:o[0].url,assetFileId:null!==(t=o[0].fileId)&&void 0!==t?t:null,slotIndex:d});let s=d+1;for(let e=1;e<o.length;e++){for(;s<U.j$&&(null===(n=a[s])||void 0===n?void 0:n.src);)s++;if(s>=U.j$)break;a[s]={type:"file",src:o[e].url,assetFileId:null!==(r=o[e].fileId)&&void 0!==r?r:null,slotIndex:s},s++}i(a)},pool:"listingPhotos",excludeIds:ec,multiSelect:!0,title:"Add listing photos"}),B&&(0,n.jsx)(eH,{open:!0,assetFile:B.assetFile,onClose:()=>V(null),onSaved:e=>{var l,t;(null==e?void 0:e.id)!=null&&q({slotIndex:B.slotIndex,sourceAssetFileId:null!==(t=null===(l=B.assetFile)||void 0===l?void 0:l.id)&&void 0!==t?t:null,asset:e})}}),(0,n.jsx)(F.Z,{open:null!==K,title:"Use the edited copy in this photo slot?",message:"Your edited copy was saved to your library. You can put it in this photo slot now â nothing is sent to Etsy until you save the listing.",confirmText:"Ap
1ply",cancelText:"Just keep in library",onClose:()=>q(null),onConfirm:()=>{G(K.slotIndex,K.asset,K.sourceAssetFileId),q(null)}})]})}var eX=t(2323),eJ=t(42187),e0=t(86720),e1=t(98104),e5=t(41414),e2=t(13213);let e3=e=>{var l,t;return null!==(t=null!==(l=null==e?void 0:e.production_partner_id)&&void 0!==l?l:null==e?void 0:e.id)&&void 0!==t?t:null},e4=e=>(null==e?void 0:e.partner_name)||(null==e?void 0:e.name)||"Partner ".concat(e3(e));function e7(e){var l;let{partners:t=[],value:i=[],onChange:r,loading:o=!1,loadError:d=!1,onRetry:s,required:u=!1,error:c=!1,disabled:p=!1}=e,v=(0,a.useRef)(null),[h,f]=(0,a.useState)(null),[x,g]=(0,a.useState)(""),[m,b]=(0,a.useState)(!1),j=!!h,w=p||o,S=ei.W1.md,k=(0,a.useMemo)(()=>new Set(Array.isArray(i)?i:[]),[i]),I=x.trim().toLowerCase(),C=I?t.filter(e=>e4(e).toLowerCase().includes(I)):t,Z=e=>{r&&r(k.has(e)?Array.from(k).filter(l=>l!==e):[...Array.from(k),e])},P=C.length>0?C.map(e=>{let l=e3(e),t=k.has(l);return{key:null!=l?l:e4(e),label:e4(e),description:(null==e?void 0:e.location)||void 0,active:t,icon:t?(0,n.jsx)(Q.Z,{size:14}):null,keepOpen:!0,onClick:()=>Z(l)}}):[{key:"empty",render:()=>(0,n.jsx)(y.Z,{sx:{px:1.5,py:1,fontSize:12,color:ei.oR.textSecondary},children:I?"No partners match your search.":"No production partners found for this shop."})}],R=t.filter(e=>k.has(e3(e))),A=o?"Loading production partnersâ¦":0===R.length?u?"Select production partner(s) â required":"Select production partner(s)":R.length<=2?R.map(e4).join(", "):"".concat(R.length," partners selected"),E=R.map(e4).join(", "),M=R.length>2&&!!E,z=Math.max((null===(l=v.current)||void 0===l?void 0:l.offsetWidth)||0,260),D=(0,n.jsxs)(y.Z,{ref:v,component:"button",type:"button",disabled:w,onClick:e=>{w||f(e.currentTarget)},onMouseEnter:()=>b(!0),onMouseLeave:()=>b(!1),sx:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:1,textAlign:"left",bgcolor:ei.oR.bgInput,border:"1px solid ".concat(c?ei.oR.errorBorder:ei.oR.borderDefault),borderRadius:ei.PY.md,px:"".concat(S.px,"px"),py:"".concat(S.py,"px"),minHeight:S.height,color:w?ei.oR.textTertiary:ei.oR.textPrimary,cursor:w?"not-allowed":"pointer",opacity:w?.6:1,transition:"border-color 150ms ease-in-out","&:hover":{borderColor:w?c?ei.oR.errorBorder:ei.oR.borderDefault:c?ei.oR.errorBorder:ei.oR.borderStrong},"&:focus-visible":{outline:"none",borderColor:c?ei.oR.errorBorder:ei.oR.borderStrong}},children:[(0,n.jsx)(L.Z,{sx:{flex:1,minWidth:0,fontSize:S.fontSize,color:R.length>0?ei.oR.textPrimary:ei.oR.textSecondary,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",lineHeight:1.4},children:A}),(0,n.jsx)(Y.Z,{size:14,color:w?ei.oR.textTertiary:ei.oR.textSecondary})]});return(0,n.jsxs)(y.Z,{children:[M?(0,n.jsx)(_.Z,{title:E,placement:"top",maxWidth:320,open:m&&!j,children:D}):D,(0,n.jsx)(e2.Z,{anchorEl:h,open:j,onClose:()=>{f(null),g("")},items:P,minWidth:z,maxHeight:320,header:t.length>5?(0,n.jsx)(J.Z,{value:x,onChange:g,placeholder:"Search partnersâ¦",fullWidth:!0,size:"sm"}):void 0}),d&&(0,n.jsxs)(y.Z,{role:"alert",sx:{mt:.75,display:"flex",alignItems:"center",gap:.75,fontSize:12,color:ei.oR.errorStrong},children:[(0,n.jsx)("span",{children:"Couldn't load production partners."}),s&&(0,n.jsxs)(y.Z,{component:"button",type:"button",onClick:s,sx:{display:"inline-flex",alignItems:"center",gap:"4px",fontSize:12,fontWeight:600,color:ei.oR.errorStrong,textDecoration:"underline",background:"none",border:"none",cursor:"pointer",p:0},children:[(0,n.jsx)(e5.Z,{size:12})," Retry"]})]})]})}var e6=t(65876);let e8="Product type";function e9(e){var l;let{whoMadeThis:t,setWhoMadeThis:i,whatIsIt:o,setWhatIsIt:d,whenMade:s,setWhenMade:u,typeOption:c,typeSwitch:h=null,validation:f={},productionPartnerIds:x=[],setProductionPartnerIds:g,availablePartners:m=[],productionPartnersLoading:b=!1,productionPartnersError:j=!1,productionPartnersFetched:_=!1,onRetryProductionPartners:w}=e,S=(0,v.bw)(f),k=e=>S&&!e?{severity:S.severity,message:"Required"}:null,C=k(t),Z=k(o),P=k(s),R=(0,e1.$i)({whoMade:t,whenMade:s,isSupply:"supply_tool"===o}),A=(null!==(l=null==x?void 0:x.length)&&void 0!==l?l:0)>0,E=!(0,e1.hH)({whoMade:t,whenMade:s,isSupply:"supply_tool"===o,hasProductionPartner:A}),M=E?{severity:"error",message:"Invalid for Etsy"}
1:null,z=[C,Z,P,M].filter(Boolean),D=(0,a.useRef)(!1);(0,a.useEffect)(()=>{var e,l,t,n;if(!R){D.current=!1;return}if(!D.current&&_){if(1===m.length&&(null!==(e=null==x?void 0:x.length)&&void 0!==e?e:0)===0&&"function"==typeof g){let e=null!==(n=null===(l=m[0])||void 0===l?void 0:l.production_partner_id)&&void 0!==n?n:null===(t=m[0])||void 0===t?void 0:t.id;null!=e&&g([e])}D.current=!0}},[R,m,_,x,g]);let L="download"===c,[O,T]=(0,a.useState)(!1);return(0,n.jsxs)(r.Z,{id:"core-details",title:"Core Details",issues:z,pillsInHeader:!1,children:[h?(0,n.jsxs)(y.Z,{sx:{mb:2},children:[(0,n.jsx)(p.m7,{label:e8}),(0,n.jsx)(e0.Z,{options:h.options,value:h.value,onChange:h.onSelect,disabled:h.disabled,fullWidth:!0,activeColor:"var(--lv-text-primary)",ariaLabel:e8})]}):null,(0,n.jsx)(y.Z,{sx:{containerType:"inline-size"},children:(0,n.jsxs)(y.Z,{sx:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:2,["@container (max-width: ".concat(480,"px)")]:{gridTemplateColumns:"1fr"}},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(p.m7,{label:"Who made this",issue:C||M}),(0,n.jsx)(X.Z,{cozy:!0,error:E,value:t,onChange:e=>i(e.target.value),placeholder:"Select an option",options:I.oR})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(p.m7,{label:"What is it",issue:Z||M}),(0,n.jsx)(X.Z,{cozy:!0,error:E,value:o,onChange:e=>d(e.target.value),placeholder:"Select an option",options:I.t1})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(p.m7,{label:"When did you make it",issue:P||M}),(0,n.jsx)(X.Z,{cozy:!0,error:E,value:s,onChange:e=>{let l=e.target.value;if("made_to_order"===l&&L){T(!0);return}u(l)},placeholder:"Select an option",children:I.Jc.map(e=>[(0,n.jsx)(eX.Z,{sx:{fontSize:"0.7rem",lineHeight:"1.5rem",color:"var(--lv-text-secondary)"},children:e.label},e.label),...e.items.map(e=>(0,n.jsx)(eJ.Z,{value:e.value,children:e.label},e.value))])})]})]})}),E&&(0,n.jsx)(y.Z,{role:"alert",sx:{mt:1.5,borderRadius:"8px",border:"1px solid ".concat(ei.oR.errorBorder),backgroundColor:ei.oR.errorSurface,color:ei.oR.errorStrong,fontSize:12,lineHeight:"18px",padding:"8px 10px"},children:e6.y6}),R&&(0,n.jsxs)(y.Z,{sx:{mt:1.5},children:[(0,n.jsx)(p.m7,{label:"Production partners for this listing",issue:A?null:{severity:"error",message:"Required"}}),(0,n.jsx)(e7,{partners:m,value:x,onChange:g,loading:b,loadError:j,onRetry:w,required:!0,error:E})]}),(0,n.jsx)(F.Z,{open:O,onClose:()=>T(!1),onConfirm:()=>T(!1),hideCancel:!0,title:"Not available for digital listings",message:'"Made to order" canât be used with a digital (download) listing â digital files are delivered instantly. Please choose a different "When did you make it" option.',confirmText:"Got it"})]})}var le=t(95576),ll=t(8350),lt=t(42147),ln=t(53410),li=t(12713),lr=t(32489),lo=t(4385),la=t(2595),ld=t(88890);let ls=e=>((null==e?void 0:e.path)||(null==e?void 0:e.name)||"").replace(/\s-\s/g," -> "),lu=(e,l)=>{if(!l)return!0;let t=((null==e?void 0:e.path)||(null==e?void 0:e.name)||"").toLowerCase(),n=((null==e?void 0:e.name)||"").toLowerCase();return t.includes(l)||n.includes(l)},lc=e=>{let{label:l,onRemove:t}=e;return(0,n.jsxs)(y.Z,{component:"span",sx:{display:"inline-flex",alignItems:"center",border:"1px solid var(--lv-border-default)",borderRadius:"8px",bgcolor:"var(--lv-bg-card)",px:1.25,py:.3,boxShadow:"0 1px 2px rgba(15,23,42,0.05)",fontSize:"0.75rem",fontWeight:500,color:"var(--lv-text-primary)",gap:.25},children:[(0,n.jsx)(le.Z,{size:"small",onClick:t,sx:{p:0,minWidth:"auto",width:16,height:16,borderRadius:"50%",color:"var(--lv-text-primary)"},children:(0,n.jsx)(lr.Z,{size:12})}),(0,n.jsx)(ll.Z,{orientation:"vertical",flexItem:!0,sx:{mx:.25}}),(0,n.jsx)(y.Z,{component:"span",sx:{pl:.5},children:l})]})};async function lp(e){return(await lo.default.get("".concat("https://backend.listingview.io","/api/integration/etsy-bulk/seller-taxonomy/").concat(e,"/properties"))).data}function lv(e){let{etsyCategory:l,setEtsyCategory:t,taxonomies:i,categoryProperties:o,setCategoryProperties:d,selectedPropertyValues:s,setSelectedPropertyValues:u,validation:c={}}=e,[h,f]=(0,a.useState)(!1),[x,g]=(0,a.useState)(!1),m=async e=>{if(t(e),u({}),null==e?void 0:e.id){f(!0);try{var l;let t=await lp(e.id),n=(null==t?void 0:null===(l=t.data)||void 0===l?void 0:l.results)||[];d(n)}catch(e){console.error("Failed to fetch taxonomy properties:",e),d([])}finally{f(!1)}}else d([])},b=(e,l,t)=>{u(n=>({...n,[e]:{value_ids:l,values:t}}))},j=e=>{let l=s[e];return l?{value_ids:l.value_ids||[],values:l.values||[]}:{value_ids:[],values:[]}};return(0,n.jsxs)(r.Z,{id:"category",title:"Category & Attributes",issues:[(0,v.bw)(c)].filter(
1Boolean),children:[(0,n.jsx)(p.ZP,{children:"Etsy category"}),(0,n.jsx)(ld.Z,{cozy:!0,middleTruncate:!0,options:i||[],value:l,onChange:m,placeholder:"Type to search categories...",searchPlaceholder:"Type to search categories...",noOptionsText:"No categories found",getOptionLabel:ls,filterOption:lu,fullWidth:!0}),h?(0,n.jsx)(y.Z,{sx:{display:"flex",justifyContent:"center",alignItems:"center",py:3},children:(0,n.jsx)(q.D8,{size:24,sx:{color:"var(--lv-text-primary)"}})}):o.length>0?(0,n.jsxs)(y.Z,{sx:{mt:2},children:[(0,n.jsxs)(y.Z,{component:"button",type:"button",onClick:()=>g(e=>!e),"aria-expanded":x,sx:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",px:1.25,py:1,border:"1px solid var(--lv-border)",borderRadius:"10px",bgcolor:"transparent",cursor:"pointer",color:"var(--lv-text-primary)"},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:13,fontWeight:600},children:["Attributes (",o.length,")"]}),(0,n.jsx)(Y.Z,{size:16,style:{transition:"transform 150ms ease",transform:x?"rotate(180deg)":"none"}})]}),x&&(0,n.jsx)(y.Z,{sx:{mt:1.5,display:"flex",flexDirection:"column",gap:2},children:o.map(e=>{let l=j(e.property_id),t=e.is_multivalued||!1,i=e.possible_values||[],r=(0,la.x)(e);return(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(p.ZP,{children:e.display_name||e.name}),r?(0,n.jsx)(la.Z,{property:e,value:l,onChange:b}):t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(lt.Z,{multiple:!0,options:i,getOptionLabel:e=>e.name||String(e),value:i.filter(e=>l.value_ids.includes(e.value_id)),onChange:(l,t)=>{let n=t.map(e=>e.value_id),i=t.map(e=>e.name);b(e.property_id,n,i)},ListboxProps:{sx:{"& .MuiAutocomplete-option":{fontSize:"0.8125rem"}}},PaperComponent:e=>{let{children:l,...t}=e;return(0,n.jsx)(ln.Z,{...t,elevation:0,sx:{border:"1px solid var(--lv-border-default)",borderRadius:"0.5rem",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)"},children:l})},renderInput:e=>(0,n.jsx)(li.Z,{...e,placeholder:"Select options",size:"small",sx:{"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem",backgroundColor:"var(--lv-bg-input)","& .MuiOutlinedInput-notchedOutline":{borderColor:"var(--lv-border-default)"},"&:hover .MuiOutlinedInput-notchedOutline":{borderColor:"var(--lv-border-strong)"},"&.Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"var(--lv-border-strong)",borderWidth:"1px"}},"& .MuiOutlinedInput-input":{fontSize:"0.8125rem"},"& .MuiOutlinedInput-input::placeholder":{color:"var(--lv-text-secondary)",opacity:1}}}),renderTags:()=>null}),(0,n.jsx)(y.Z,{sx:{mt:1,display:"flex",flexWrap:"wrap",gap:.5},children:i.filter(e=>l.value_ids.includes(e.value_id)).map(t=>(0,n.jsx)(lc,{label:t.name,onRemove:()=>{let n=l.value_ids.filter(e=>e!==t.value_id),i=l.values.filter(e=>e!==t.name);b(e.property_id,n,i)}},t.value_id))})]}):(0,n.jsx)(X.Z,{cozy:!0,value:l.value_ids[0]||"",onChange:l=>{let t=l.target.value,n=i.find(e=>e.value_id===t);b(e.property_id,t?[t]:[],n?[n.name]:[])},placeholder:"Select option",options:i.map(e=>({value:e.value_id,label:e.name}))})]},e.property_id)})})]}):null]})}var lh=t(68575),lf=t(82091),lx=t(77440);let lg=Object.freeze({price:lf.Z,personalization:lx.Z}),lm=(e,l)=>Object.prototype.hasOwnProperty.call(e,l)?e[l]:void 0;function ly(e){let{kind:l,message:t,actionLabel:i,onAction:r,readOnly:o=!1,surface:d,impressionKey:s}=e,u=lm(lg,l),c="string"==typeof t?t.trim():"",p=!!u&&""!==c,v=(0,a.useRef)(null);return((0,a.useEffect)(()=>{if(!p)return;let e=String(null!=s?s:"");null===v.current&&(v.current=new Set),v.current.has(e)||(v.current.add(e),(0,Z.L)("score_nudge_shown",{kind:l,...d?{surface:d}:{}}))},[p,l,d,s]),p)?(0,n.jsxs)("div",{role:"note","data-testid":"score-nudge","data-kind":l,className:"flex w-full items-start gap-2 rounded-lv-md bg-lv-info-bg px-3 py-2 text-lv-caption text-lv-text-secondary",children:[(0,n.jsx)(u,{size:ei.j1.md,"aria-hidden":"true",className:"mt-0.5 shrink-0 text-lv-text-secondary"}),(0,n.jsxs)("span",{className:"min-w-0",children:[c,!o&&!!i&&"function"==typeof r&&(0,n.jsx)("button",{type:"button",onClick:()=>{(0,Z.L)("score_nudge_clicked",{kind:l,...d?{surface:d}:{}}),r()},className:"ml-2 inline-flex min-h-[44px] min-w-[44px] items-center justify-center rounded-lv-md px-2 text-lv-btn text-lv-selected-strong underline-offset-2 outline-none hover:underline focus-visible:ring-2 focus-visible:ring-lv-focus",children:i})]})]}):null}var lb=t(76164),lj=t(58501);function l_(e){var l,t;let{price:o,setPrice:u,quantity:c,setQuantity:h,sku:x,setSku:m,score:y,conflictField:b=!1,validation:j={},aiPendingFields:_={},aiLoading:w={},onAcceptAI:S,onRejectAI:k,onRegenerateAI:I}=e,C=(0,lh.v9)(e=>e.user.shopCurrencyCode||"USD"),Z=(0,lb.j)(C),P=(0,v.bw)(j),R=null===(l=_.price)||void 0===l?void 0:l.generated,A=null==y?void 0:y.score,E=null==A?void 0:A.observed,M=null==y?void 0:y.scoreInputs,z=(0,a.useMemo)(()=>({breakpoints:null==M?void 0:M.priceBreakpoints,currency:null==M?void 0:M.listingCurrency,degraded:null==M?void 0:M.degraded,price:o}),[M,o]),D=(0,a.useMemo)(()=>(0,f.ZM)(y,"price",z),[y,z]),L=(null==A?void 0:A.price)===0&&(null==E?void 0:E.priceBand)==="above"?(0,f.Jv)(z.breakpoints,o):"";return(0,n.jsxs)(r.Z,{id:"price-quantity-sku",title:"Price, Quantity & SKU",headerAction:A?(0,n.jsx)(d.Z,{label:f.HE.badgeLabels.price,score:A.price,total:g.SCORE_RUBRIC.max.price,factor:"price",observed:E,rows:D}
1):null,issues:[P].filter(Boolean),pillsInHeader:!1,children:[(0,n.jsxs)("div",{className:"grid grid-cols-3 gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(p.m7,{label:"Price",issue:P}),(0,n.jsx)(s.Z,{active:null!=R,compact:!0,fieldLabel:"price",label:"AI suggests ".concat(Z).concat(R),detail:null===(t=_.price)||void 0===t?void 0:t.model,loading:!!w.price,onAccept:()=>null==S?void 0:S("price"),onRegenerate:()=>null==I?void 0:I("price"),onDiscard:()=>null==k?void 0:k("price"),children:(0,n.jsx)(i.Z,{fullWidth:!0,value:o,onChange:u,startAdornment:(0,n.jsx)("span",{className:"text-xs",children:Z}),endAdornment:(0,n.jsx)("span",{className:"text-xs",children:C}),error:j.error})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(p.m7,{label:"Quantity"}),(0,n.jsx)(i.Z,{fullWidth:!0,value:c,onChange:h})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(p.m7,{label:"SKU"}),(0,n.jsx)(i.Z,{fullWidth:!0,value:x,onChange:m})]})]}),(0,n.jsx)("div",{className:L?"mt-3":void 0,children:(0,n.jsx)(ly,{kind:"price",message:L,surface:"edit",impressionKey:(0,lj.G0)(y)})})]})}var lw=t(54301),lS=t(61201),lk=t(33245),lI=t(7778),lC=t(98462),lZ=t(82950);let lP="min-w-[48px]",lR=(0,a.forwardRef)(function(e,l){let{value:t="",onCommit:i,label:r,ariaLabel:o,type:d="text",step:s,prefix:u=null,placeholder:c,disabled:p=!1,error:v=!1}=e,[h,f]=(0,a.useState)(!1),[x,g]=(0,a.useState)(t),m=(0,a.useRef)(null),y=(0,a.useRef)(!1),b=(0,a.useRef)(!1);(0,a.useEffect)(()=>{g(t)},[t]),(0,a.useEffect)(()=>{var e;!h&&b.current&&(b.current=!1,null===(e=m.current)||void 0===e||e.focus())},[h]);let j=(0,a.useCallback)(()=>x===t?null:(null==i||i(x),x),[x,t,i]);(0,a.useImperativeHandle)(l,()=>({flush:()=>h?(y.current=!0,f(!1),j()):null,isEditing:()=>h}),[h,j]);let _=()=>{p||(y.current=!1,g(t),f(!0))},w=""!==t&&null!=t,S=null!=o?o:r?"".concat(r,", ").concat(w?t:"empty"):void 0,k=S&&v?"".concat(S,", ").concat("invalid value"):S;return p?(0,n.jsxs)("div",{className:[lP,"px-2 py-1 text-lv-caption text-lv-text-disabled"].join(" "),children:[u,w?t:"â"]}):h?(0,n.jsx)("input",{type:d,step:"number"===d?s:void 0,value:x,placeholder:c,"aria-label":null!=o?o:r,"aria-invalid":v||void 0,autoFocus:!0,onChange:e=>g(e.target.value),onBlur:()=>{if(y.current){y.current=!1;return}f(!1),j()},onKeyDown:e=>{if("Enter"===e.key){e.preventDefault(),y.current=!0,b.current=!0,f(!1),j();return}"Escape"===e.key&&(e.preventDefault(),y.current=!0,b.current=!0,g(t),f(!1))},className:["w-full",lP,"rounded-lv-sm border-[1.5px] px-1.5 py-1 text-lv-caption text-lv-text-primary","[font-family:inherit] outline-none [&::-webkit-inner-spin-button]:hidden",v?"border-lv-error-border bg-lv-error-surface":"border-lv-selected bg-lv-card"].join(" ")}):(0,n.jsxs)("div",{ref:m,role:"button",tabIndex:0,"aria-label":k,onClick:_,onKeyDown:e=>{("Enter"===e.key||" "===e.key||"Spacebar"===e.key)&&(e.preventDefault(),_())},className:["w-full",lP,"cursor-text truncate rounded-lv-sm border px-1.5 py-1 text-left text-lv-caption text-lv-text-primary","transition-colors duration-lv ease-lv","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lv-focus",v?"border-lv-error-border bg-lv-error-surface":"border-lv-border bg-lv-card hover:border-lv-border-strong"].join(" "),children:[u,w?t:(0,n.jsx)("span",{"aria-hidden":"true",className:"text-lv-text-disabled",children:"â"})]})});var lA=t(14865);let lE={"& .MuiSwitch-switchBase.Mui-checked":{color:"var(--lv-selected)"},"& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track":{bgcolor:"var(--lv-selected)"}};function lM(e){let{checked:l=!1,disabled:t=!1,tooltip:i=null,tooltipPlacement:r="top",label:o,onChange:d}=e;"string"==typeof o&&o.trim(),(0,a.useRef)(!1),(0,a.useEffect)(()=>{},[]);let s=(0,n.jsx)(lA.Z,{size:"small",checked:l,disabled:t,onChange:e=>null==d?void 0:d(e.target.checked,e),inputProps:{"aria-label":o},sx:lE});return i?(0,n.jsx)(_.Z,{title:i,placement:r,children:s}):s}var lz=t(22095),lD=t(70208),lL=t(32281),lO=t(59469);let lF={fontSize:11,fontWeight:600,color:"var(--lv-text-secondary)",bgcolor:"var(--lv-bg-elevated)",py:.875,px:1,borderBottom:"1px solid var(--lv-border-default)",whiteSpace:"nowrap"},lT={fontSize:12,color:"var(--lv-text-primary)",py:.625,px:1,borderBottom:"1px solid var(--lv-border-default)"},lN="2px solid ".concat("var(--lv-focus-ring)"),lW="data-variant-row-blurred",lU={width:"calc(100% - 2px)",mx:"1px",py:1,fontSize:12,color:"var(--lv-text-secondary)",cursor:"pointer",border:"1px solid var(--lv-border-default)",borderTop:"none",borderRadius:"0 0 8px 8px",bgcolor:"var(--lv-bg-card)","&:hover":{bgcolor:"var(--lv-bg-elevated)",color:"var(--lv-text-primary)"},"&:focus-visible":{outline:lN,outlineOffset:1},fontFamily:"inherit",transition:"all 0.15s"},lH="& > tr[".concat(lW,"='true'] > td");
1function lB(e){let{columns:l,rows:t,totalCount:i,expanded:r=!1,onExpandChange:o,canCollapse:d=!1,isTruncated:s=!1,emptyState:u,renderRow:c}=e,p=l.filter(e=>!e.hidden),v=null!=i?i:t.length;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(lz.Z,{sx:{border:"1px solid var(--lv-border-default)",borderRadius:s?"8px 8px 0 0":2,overflow:"auto",p:0},children:(0,n.jsxs)(lD.Z,{size:"small",stickyHeader:!0,children:[(0,n.jsx)(lL.Z,{children:(0,n.jsx)(lw.Z,{children:p.map(e=>(0,n.jsx)(lS.Z,{align:e.align,sx:lF,children:e.label},e.key))})}),(0,n.jsx)(lO.Z,{sx:{...r?null:{"& > tr:last-of-type > td":{borderBottom:"none"}},[lH]:{filter:"blur(2px)",pointerEvents:"none"}},children:0===t.length?(0,n.jsx)(lw.Z,{children:(0,n.jsx)(lS.Z,{colSpan:p.length,sx:{py:1,px:1,borderBottom:"none"},children:u})}):(()=>{let e=t.map((e,l)=>c(e,l));if(!s)return e;let l=-1;for(let t=e.length-1;t>=0;t--)if((0,a.isValidElement)(e[t])){l=t;break}return -1===l?e:e.map((e,t)=>t===l?(0,a.cloneElement)(e,{[lW]:"true"}):e)})()})]})}),"function"==typeof o&&(s||r&&d)&&(0,n.jsx)(y.Z,{component:"button",type:"button",onClick:()=>o(!r),sx:lU,children:r?"Show less â":"Show all ".concat(v," variants â")})]})}function lV(e){let{id:l="variations",expanded:t,onExpandedChange:i,children:r,sx:o}=e,a="".concat(l,"-trigger"),d="".concat(l,"-panel");return(0,n.jsxs)(y.Z,{sx:o,children:[(0,n.jsxs)(y.Z,{component:"button",type:"button",id:a,"aria-expanded":t,"aria-controls":d,onClick:()=>null==i?void 0:i(!t),sx:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",cursor:"pointer",userSelect:"none",py:1,px:1.5,border:"1px solid var(--lv-border-default)",borderRadius:t?"12px 12px 0 0":3,bgcolor:"var(--lv-bg-elevated)",borderBottom:t?"none":"1px solid var(--lv-border-default)",fontFamily:"inherit",textAlign:"left","&:focus-visible":{outline:lN,outlineOffset:2}},children:[(0,n.jsx)(L.Z,{component:"span",sx:{fontSize:13,fontWeight:600,color:"var(--lv-text-primary)"},children:"Variations"}),(0,n.jsx)(y.Z,{component:"span","aria-hidden":"true",sx:{fontSize:12,color:"var(--lv-text-secondary)",transform:t?"rotate(180deg)":"none",transition:"transform 0.2s",display:"flex",alignItems:"center"},children:(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:(0,n.jsx)("path",{d:"M3 5l4 4 4-4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),(0,n.jsx)(y.Z,{id:d,role:"region","aria-labelledby":a,hidden:!t,sx:{border:"1px solid var(--lv-border-default)",borderTop:"none",borderRadius:"0 0 12px 12px",overflow:"hidden",px:2,py:2,"&[hidden]":{display:"none"}},children:r})]})}function lK(e,l){return"".concat(e," of ").concat(l," variant").concat(1!==l?"s":""," shown")}function lq(e){let{summary:l,actions:t=[],sx:i}=e,r=t.filter(Boolean);return(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1.5,flexWrap:"wrap",gap:1,...i},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)"},children:l}),(0,n.jsx)(y.Z,{sx:{display:"flex",gap:.75,flexWrap:"wrap"},children:r.map(e=>{let l={text:e.label,color:"white",width:"auto",className:"whitespace-nowrap",disabled:e.disabled,onClick:e.onClick};return e.tooltip?(0,n.jsx)(_.Z,{placement:"top",title:e.tooltip,children:(0,n.jsx)("span",{className:"inline-flex",children:(0,n.jsx)(w.f,{...l})})},e.key):(0,n.jsx)(w.f,{...l},e.key)})})]})}var lG=t(23909),lY=t(59808),lQ=t(38869);let l$="price",lX=[{id:l$,label:"Price"},{id:"qty",label:"Quantity"},{id:"sku",label:"SKU"}],lJ={[l$]:"Enter a price value before updating.",qty:"Enter a quantity before updating.",sku:"Enter a SKU value before updating."},l0={[l$]:"Enter a numeric price value before updating.",qty:"Enter a numeric quantity before updating."},l1=e=>""===String(null!=e?e:"").trim();function l5(e){var l;let{targetCount:t=0,onApply:i,lockedProperties:r=null,lockedReason:o=null}=e,[d,s]=(0,a.useState)(l$),u=(0,lQ.ZP)({modes:lQ.c5,defaultMode:lQ.DZ.OVERWRITE.id}),c=(0,lQ.ZP)({modes:lQ.Qe,defaultMode:lQ.DZ.OVERWRITE.id}),p=(0,lQ.ZP)({modes:lQ.$P,defaultMode:lQ.DZ.OVERWRITE.id}),v=d===l$?u:"qty"===d?c:p,h=Array.isArray(r)?r.includes(d):!!(null==r?void 0:null===(l=r.has)||void 0===l?void 0:l.call(r,d));return(0,n.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[(0,n.jsx)(X.Z,{value:d,onChange:e=>s(e.target.value),fullWidth:!1,formControlSx:{minWidth:132},inputProps:{"aria-label":"Property to bulk edit"},children:lX.map(e=>(0,n.jsx)(eJ.Z,{value:e.id,children:e.label},e.id))}),(0,n.jsx)("div",{className:"min-w-[240px] flex-1",children:(0,n.jsx)(lG.Z,{...v,size:"sm",modeAriaLabel:"How to apply the value",inputType:"sku"===d?"text":"number"})}),(0,n.jsx)(w.f,{text:"Update",color:"white",width:"auto",className:"whitespace-nowrap",disabled:0===t||h,onClick:()=>
1{if(h)return;let e=function(e,l){let{mode:t,input:n,findText:i}=l;if(t===lQ.DZ.FIND_REPLACE.id)return l1(i)?"Enter the text to find before updating.":null;if("sku"===e)return l1(n)?lJ.sku:null;if(l1(n))return lJ[e];if(e===l$&&!(0,lY.pt)(n))return l0[l$];let r=Number(String(n).trim());return Number.isFinite(r)?"qty"===e&&(!Number.isInteger(r)||r<0)?"Enter a whole, non-negative quantity to update by.":null:l0[e]}(d,v);if(e){O.Am.error(e);return}let l=null==i?void 0:i(d,e=>{let l=String(null!=e?e:""),t=d===l$&&v.mode===lQ.DZ.FIND_REPLACE.id?(0,lY.U$)(l):l;return function(e,l,t,n){if("sku"===e)return n;let i=String(null!=t?t:"");if(l1(i)&&l!==lQ.DZ.OVERWRITE.id)return null;if(e===l$){let e=(0,lY.ef)(n,i);return null===e?null:e.toFixed(2)}let r=Number(n);return Number.isFinite(r)?String(Math.max(0,Math.trunc(r))):null}(d,v.mode,l,v.transform(t))});if(!l){O.Am.info("No variants were updated.");return}v.reset(),O.Am.success("Updated ".concat(l," variant").concat(1!==l?"s":"","."))}}),h&&o?(0,n.jsx)("p",{className:"m-0 basis-full text-lv-caption text-lv-text-secondary","data-testid":"variant-bulk-locked-reason",children:o}):null]})}var l2=t(92649);function l3(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return l.every((l,t)=>{if(!l||0===l.size)return!0;let n=e[t];return null!=n&&l.has(n)})}function l4(e){let{axes:l=[],active:t=!1,onClear:i}=e,r=l.filter(e=>{var l,t;return(null!==(t=null==e?void 0:null===(l=e.options)||void 0===l?void 0:l.length)&&void 0!==t?t:0)>=2});return 0!==r.length||t?(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:1,mb:1.5},children:[r.map(e=>{let l=e.options.map(e=>e.label);return(0,n.jsx)(l2.Z,{variant:e.name,options:l,selectedOptions:l.filter(l=>{var t,n;return null!==(n=null===(t=e.selected)||void 0===t?void 0:t.has(l))&&void 0!==n&&n}),onToggleOption:(l,t)=>{var n;return null===(n=e.onToggle)||void 0===n?void 0:n.call(e,t)}},e.key)}),t&&(0,n.jsx)(w.f,{text:"Clear filters",color:"white",width:"auto",className:"whitespace-nowrap",onClick:i})]}):null}function l7(){return(0,n.jsx)("div",{className:"py-2 text-center text-lv-caption text-lv-text-secondary",children:"No variants match the selected filters."})}var l6=t(37990),l8=t(75674),l9=t(73560),te=t(28808);function tl(e){let{sku:l,propertyValues:t,quantity:n,isEnabled:i,priceCents:r,readinessStateId:o}=e;return{sku:String(null!=l?l:""),property_values:Array.isArray(t)?t:[],offerings:[{quantity:Number.isFinite(Number(n))?Number(n):0,is_enabled:null==i||i,price:{amount:r,divisor:100,currency_code:"USD"},readiness_state_id:null!=o?o:1402579160544}]}}let tt={Sizes:513,Colors:514};function tn(e){let l=Number(e);return isFinite(l)?Math.round(100*l):0}function ti(e,l){if(!e)return null;let{axes:t,rows:n}=e,i=t.map((e,t)=>{let i=l[e];return(null==i?void 0:i.deleted)?[]:(null==i?void 0:i.options)?i.options:[...new Set(n.map(e=>0===t?e.v1:e.v2).filter(Boolean))]}),r=t.map(e=>{var t,n;return null!==(n=null===(t=l[e])||void 0===t?void 0:t.name)&&void 0!==n?n:e}),o=Object.fromEntries(n.map(e=>[e.key,e])),a=1===t.length?i[0].map(e=>{var l;let t=null!==(l=o[e])&&void 0!==l?l:n.find(l=>l.v1===e);return null!=t?t:{key:e,v1:e,v2:"",sku:"",price:"",quantity:"",visible:!0}}):i[0].flatMap(e=>{var l;return(null!==(l=i[1])&&void 0!==l?l:[]).map(l=>{var t;let i="".concat(e,"|||").concat(l),r=null!==(t=o[i])&&void 0!==t?t:n.find(t=>t.v1===e&&t.v2===l);return null!=r?r:{key:i,v1:e,v2:l,sku:"",price:"",quantity:"",visible:!0}})});return{axisOpts:i,axisNames:r,rows:a,rowKeys:new Set(a.map(e=>e.key))}}let tr=()=>"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"id_".concat(Date.now(),"_").concat(Math.random().toString(36).slice(2,8));function to(e){var l,t,i,r,o;let{productsVaryByVariants:d,setProductsVaryByVariants:s,variants:u,setVariants:c,variantInventory:p,setVariantInventory:v,listingId:h,onInventoryChange:f,onRawInventoryLoaded:g,globalPrice:m,globalQuantity:y,globalSku:b,aiInventoryPriceWrites:j,onAiInventoryPriceWritesApplied:_,aiVariantPricePreview:w}=e,{rules:S}=(0,x.RK)(),k=null!==(i=S.variants)&&void 0!==i?i:{maxTypes:2,nameLengthMin:1,nameLengthMax:20,optionValueLengthMin:1,optionValueLengthMax:20,maxOptionsProduct:l9.jh},{maxProductsVaryByAll:I,policyEffectiveDate:C}=(0,te.G)(),Z=null!==(r=null!=I?I:k.maxOptionsProduct)&&void 0!==r?r:l9.jh,[P,R]=(0,a.useState)(!1),[A,E]=(0,a.useState)(""),[M,z]=(0,a.useState)([]),[D,L]=(0,a.useState)(null),[F,T]=(0,a.useState)(null),[N,W]=(0,a.useState)(!1),[U,H]=(0,a.useState)(null),[B,V]=(0,a.useState)(null),[K,G]=(0,a.useState)({});(0,a.useEffect)(()=>
1{if(!h)return;let e=!1;return W(!0),lo.default.post("".concat("https://backend.listingview.io","/api/integration/etsy-bulk/getInventoryByListingIds"),{listingIds:[h]}).then(l=>{var t,n;if(e)return;let i=Array.isArray(null===(t=l.data)||void 0===t?void 0:t.data)?l.data.data:[null===(n=l.data)||void 0===n?void 0:n.data],r=i.find(e=>Number((null==e?void 0:e.listingId)||(null==e?void 0:e.listing_id)||(null==e?void 0:e.id))===Number(h))||i[0],o=function(e){var l;let t=(null==e?void 0:null===(l=e.inventory)||void 0===l?void 0:l.products)||[];if(!t.length)return null;let n=[];if(t.forEach(e=>{(e.property_values||[]).forEach(e=>{var l;let t=null==e?void 0:null===(l=e.property_name)||void 0===l?void 0:l.trim();t&&!n.includes(t)&&n.push(t)})}),0===n.length)return null;let i=n[0],r=n[1]||null,o=t.map(e=>{var l,t;let n=(e.offerings||[])[0]||{},o=l=>(e.property_values||[]).find(e=>(e.property_name||"").toLowerCase()===(l||"").toLowerCase()),a=o(i),d=r?o(r):null,s=((null==a?void 0:a.values)||[])[0]||"",u=r&&((null==d?void 0:d.values)||[])[0]||"";return{key:(0,l6.Pp)({propertyValues:[a,d],productId:e.product_id,axisValues:r?[s,u]:[s]}),v1:s,v2:u,sku:e.sku||"",price:function(e){let l=null==e?void 0:e.price;return l?"object"==typeof l&&null!=l.amount&&l.divisor?(l.amount/l.divisor).toFixed(2):"number"==typeof l?l.toFixed(2):String(l||""):""}(n),quantity:null!==(l=n.quantity)&&void 0!==l?l:"",visible:null===(t=n.is_enabled)||void 0===t||t}});return{axes:[i,r].filter(Boolean),rows:o}}(r);V(r),H(o),(null==r?void 0:r.inventory)&&g&&g(r.inventory),o&&s&&s(!0)}).catch(()=>{e||H(null)}).finally(()=>{e||W(!1)}),()=>{e=!0}},[h]);let[Y,Q]=(0,a.useState)(!1),[$,X]=(0,a.useState)(()=>[new Set,new Set]),J=(0,a.useCallback)((e,l)=>{X(t=>{let n=t.map(e=>new Set(e)),i=n[e];return i?(i.has(l)?i.delete(l):i.add(l),n):t})},[]),ee=(0,a.useCallback)(()=>{X([new Set,new Set])},[]),el=$.some(e=>e.size>0),[et,en]=(0,a.useState)(null),[er,eo]=(0,a.useState)({}),ea=(0,a.useRef)(K),ed=(0,a.useRef)(er),es=(0,a.useMemo)(()=>ti(U,er),[U,er]),eu=(0,a.useRef)(),ec=(0,a.useCallback)(e=>{let l=JSON.stringify(e);l!==eu.current&&(eu.current=l,f(e))},[f]),ep=(0,a.useCallback)((e,l,t)=>{if(!f||!B)return;let n=((null==B?void 0:B.inventory)||{}).products||[];if(!d){if(0===n.length){ec(null);return}let e=n.filter(e=>(e.property_values||[]).every(e=>{var t;let n=l[e.property_name];return!n||!n.deleted&&(!n.options||n.options.includes(null===(t=e.values)||void 0===t?void 0:t[0]))}));if(0===e.length){ec({products:[{sku:String(null!=b?b:""),property_values:[],offerings:[{quantity:parseInt(y||0,10),is_enabled:!0,price:{amount:tn(m||0),divisor:100,currency_code:"USD"}}]}],price_on_property:[],quantity_on_property:[],sku_on_property:[],readiness_state_on_property:[]});return}ec({products:e.map(e=>{var l,t;let n=(null==e?void 0:null===(l=e.offerings)||void 0===l?void 0:l[0])||{};return tl({sku:b,propertyValues:(e.property_values||[]).map(e=>({property_id:e.property_id,property_name:e.property_name,value_ids:[],values:e.values||[]})),quantity:parseInt(y||0,10),isEnabled:null===(t=n.is_enabled)||void 0===t||t,priceCents:tn(m||0),readinessStateId:n.readiness_state_id})}),price_on_property:[],quantity_on_property:[],sku_on_property:[],readiness_state_on_property:[]});return}let i=ti(t,l);if(!t||!i){ec(null);return}let r=Object.keys(e).length>0,o=Object.keys(l).length>0;if(!r&&!o){ec(null);return}let{axes:a,rows:s}=t,u={};n.length>0&&(n[0].property_values||[]).forEach(e=>{u[e.property_name]={property_id:e.property_id,property_name:e.property_name}});let c=(e,l)=>{var t,n,i,r;return null!==(r=null!==(i=null!==(n=null===(t=u[e])||void 0===t?void 0:t.property_id)&&void 0!==n?n:tt[e])&&void 0!==i?i:l)&&void 0!==r?r:513},{axisOpts:p,axisNames:v}=i,h=Object.fromEntries(s.map(e=>[e.key,e])),x={};n.forEach(e=>{var l,t;let n=(e.property_values||[]).find(e=>e.property_name===a[0]),i=(null==n?void 0:null===(l=n.values)||void 0===l?void 0:l[0])||"",r=a[1]?(e.property_values||[]).find(e=>e.property_name===a[1]):null,o=(null==r?void 0:null===(t=r.values)||void 0===t?void 0:t[0])||"";x[a[1]?"".concat(i,"|||").concat(o):i]=e});
1let g=1===a.length?p[0].map(l=>{var t,n,i,r,o,d,u,p,f,g,m;let y=null!==(n=h[l])&&void 0!==n?n:s.find(e=>e.v1===l),b=e[null!==(i=null==y?void 0:y.key)&&void 0!==i?i:l]||{},j=x[l]||{},_=(null==j?void 0:null===(t=j.offerings)||void 0===t?void 0:t[0])||{};return tl({sku:null!==(o=null!==(r=b.sku)&&void 0!==r?r:null==y?void 0:y.sku)&&void 0!==o?o:"",propertyValues:[{property_id:c(a[0],513),property_name:v[0],value_ids:[],values:[l]}],quantity:parseInt(null!==(u=null!==(d=b.quantity)&&void 0!==d?d:null==y?void 0:y.quantity)&&void 0!==u?u:0,10),isEnabled:null===(f=null!==(p=b.visible)&&void 0!==p?p:null==y?void 0:y.visible)||void 0===f||f,priceCents:tn(null!==(m=null!==(g=b.price)&&void 0!==g?g:null==y?void 0:y.price)&&void 0!==m?m:0),readinessStateId:_.readiness_state_id})}):p[0].flatMap(l=>{var t;return(null!==(t=p[1])&&void 0!==t?t:[]).map(t=>{var n,i,r,o,d,u,p,f,g,m,y;let b="".concat(l,"|||").concat(t),j=null!==(i=h[b])&&void 0!==i?i:s.find(e=>e.v1===l&&e.v2===t),_=e[null!==(r=null==j?void 0:j.key)&&void 0!==r?r:b]||{},w=x[b]||{},S=(null==w?void 0:null===(n=w.offerings)||void 0===n?void 0:n[0])||{};return tl({sku:null!==(d=null!==(o=_.sku)&&void 0!==o?o:null==j?void 0:j.sku)&&void 0!==d?d:"",propertyValues:[{property_id:c(a[0],513),property_name:v[0],value_ids:[],values:[l]},{property_id:c(a[1],514),property_name:v[1],value_ids:[],values:[t]}],quantity:parseInt(null!==(p=null!==(u=_.quantity)&&void 0!==u?u:null==j?void 0:j.quantity)&&void 0!==p?p:0,10),isEnabled:null===(g=null!==(f=_.visible)&&void 0!==f?f:null==j?void 0:j.visible)||void 0===g||g,priceCents:tn(null!==(y=null!==(m=_.price)&&void 0!==m?m:null==j?void 0:j.price)&&void 0!==y?y:0),readinessStateId:S.readiness_state_id})})}),j=c(a[0],513),_=a[1]?c(a[1],514):null,w=_?[j,_]:[j];if(0===g.length){ec({products:[{sku:String(null!=b?b:""),property_values:[],offerings:[{quantity:parseInt(y||0,10),is_enabled:!0,price:{amount:tn(m||0),divisor:100,currency_code:"USD"}}]}],price_on_property:[],quantity_on_property:[],sku_on_property:[],readiness_state_on_property:[]});return}ec({products:g,price_on_property:w,quantity_on_property:w,sku_on_property:w,readiness_state_on_property:[]})},[d,B,f,ec,m,y,b]),ev=(e,l)=>{let t=ea.current,n={...t,[e]:{...t[e]||{},...l}};ea.current=n,G(n),ep(n,ed.current,U)},eh=function(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:U,t=ed.current,n="function"==typeof e?e(t):e;ed.current=n,eo(n),ep(ea.current,n,l)},ef=(0,a.useCallback)(e=>{if(!e.length)return;let l={...ea.current};e.forEach(e=>{let[t,n]=e;l[t]={...l[t]||{},...n}}),ea.current=l,G(l),ep(l,ed.current,U)},[ep,U]),ex=(0,a.useRef)(0);(0,a.useEffect)(()=>{let e=null==j?void 0:j.revision;if(!e||e===ex.current||!es)return;ex.current=e;let l=j.prices||{},t=Object.entries(l).filter(e=>{let[l]=e;return es.rowKeys.has(l)});ef(t.map(e=>{let[l,t]=e;return[l,{price:t}]})),null==_||_(e,{applied:t.length,dropped:Object.keys(l).length-t.length})},[j,es,_,ef]),(0,a.useEffect)(()=>{ep(K,er,U)},[ep,K,er,U]),(0,a.useMemo)(()=>{let{nameLengthMin:e,nameLengthMax:l,optionValueLengthMin:t,optionValueLengthMax:n}=k,i=A.trim(),r=i.length>=e&&i.length<=l,o=M.length>0&&M.every(e=>{let l=e.value.trim();return l.length>=t&&l.length<=n});return r&&o},[A,M,k]);let eg=e=>{c(l=>l.filter(l=>l.id!==e)),v(l=>{let t={...l};return delete t[e],t})},em=(e,l,t)=>{v(n=>{var i;return{...n,[e]:{...n[e]||{},[l]:{...(null===(i=n[e])||void 0===i?void 0:i[l])||{},...t}}}})},ey=e=>{e.length&&v(l=>{let t={...l};return e.forEach(e=>{var l;let{bucketKey:n,optionKey:i,changes:r}=e;t[n]={...t[n]||{},[i]:{...(null===(l=t[n])||void 0===l?void 0:l[i])||{},...r}}}),t})},eb=e=>e.slice(0,$.length).map((e,l)=>{var t;return{key:"axis-".concat(l),name:e.name,options:(null!==(t=e.options)&&void 0!==t?t:[]).map(e=>({label:e})),selected:$[l],onToggle:e=>J(l,e)}}),ej=e=>{let{axes:l,shownCount:t,totalCount:i,onApplyBulk:r}=e;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l5,{targetCount:t,onApply:r}),(0,n.jsx)(l4,{axes:l,active:el,onClear:ee}),(0,n.jsx)(lq,{summary:el?lK(t,i):"".concat(i," variant").concat(1!==i?"s":"")})]})};if(N)return(0,n.jsx)("div",{className:"flex items-center justify-center py-10",children:(0,n.jsx)(q.D8,{size:24,sx:{color:"var(--lv-brand)"}})});if(U&&es){let{axes:e}=U,{axisOpts:l,axisNames:t,rows:i}=es,r=eb(e.map((e,n)=>{var i;return{name:t[n],options:null!==(i=l[n])&&void 0!==i?i:[]}})),a=i.filter(e=>l3([e.v1||null,e.v2||null],$)),u=a.length>10,c=Y?a:a.slice(0,10),p=[...t.map((e,l)=>
1({key:"axis-".concat(l),label:e})),{key:"sku",label:"SKU"},{key:"price",label:"Price"},{key:"quantity",label:"Qty"},{key:"visible",label:"On",align:"right"}],v=Object.keys(er).filter(l=>{var t,n;return!e.includes(l)&&!(null===(t=er[l])||void 0===t?void 0:t.deleted)&&(null===(n=er[l])||void 0===n?void 0:n.options)}),h=[...e,...v],f=[...l,...v.map(e=>er[e].options)],x=h.map((e,l)=>({name:e,options:f[l]})),g=(0,l9.MB)(f.map(e=>({options:e})));return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l8.Z,{count:g,limit:Z,className:"mb-4"}),(0,n.jsx)("div",{className:"mb-4 grid gap-3 ".concat(e.length>1?"md:grid-cols-2":"grid-cols-1"),children:x.map(e=>{var l,t;let{name:i,options:r}=e,o=er[i];if((null==o?void 0:o.deleted)===!0)return null;let a=null!==(l=null==o?void 0:o.name)&&void 0!==l?l:i,d=null!==(t=null==o?void 0:o.options)&&void 0!==t?t:r;return(0,n.jsx)(lZ.Z,{name:a,options:d,isOpen:et===i,onToggle:()=>en(e=>e===i?null:i),onDone:e=>{let{name:l,options:t}=e;eh(e=>({...e,[i]:{name:l,options:t}})),en(null)},onDelete:()=>{eh(e=>({...e,[i]:{deleted:!0}})),en(null)}},i)})}),x.filter(e=>{var l;let{name:t}=e;return!(null===(l=er[t])||void 0===l?void 0:l.deleted)}).length>=(null!==(o=k.maxTypes)&&void 0!==o?o:2)?null:(0,n.jsx)("div",{className:"mb-4",children:P?(0,n.jsx)(lZ.Z,{name:"",options:[],isOpen:!0,onToggle:()=>R(!1),onDone:e=>{let{name:l,options:t}=e;if(!l.trim()||!t.length)return;let n=Math.max(1,g)*t.length;if(n>Z){O.Am.error((0,l9.MT)(n,Z,C));return}let i=l.trim(),r=U?{...U,axes:[...U.axes,i]}:U;H(r),eh(e=>({...e,[i]:{name:i,options:t}}),r),R(!1)},onDelete:()=>R(!1)}):(0,n.jsx)("button",{type:"button",onClick:()=>R(!0),className:"rounded-md bg-black px-3.5 py-2 text-sm font-medium text-white shadow-sm hover:bg-neutral-800",children:"Add a variant"})}),(0,n.jsxs)("div",{className:"mb-4 flex items-center gap-2",children:[(0,n.jsx)(lC.Z,{checked:d,onChange:e=>s(e),label:"Products vary by variants"}),(0,n.jsx)("span",{className:"text-xs text-lv-text-secondary",children:"(e.g. different prices for different sizes)"})]}),d&&w&&(0,n.jsx)("p",{className:"mb-2 text-lv-caption",style:{color:ei.oR.accent},children:"AI suggests prices for ".concat(w.coveredRows," of ").concat(w.sentRows," variations â accept in the AI panel to apply")}),d&&(0,n.jsxs)(n.Fragment,{children:[ej({axes:r,shownCount:a.length,totalCount:i.length,onApplyBulk:(e,l)=>{let t=ea.current,n=e===l$?"price":"qty"===e?"quantity":"sku",i=[];return(a.forEach(e=>{var r,o;let a=l(String(null!==(o=null!==(r=(t[e.key]||{})[n])&&void 0!==r?r:e[n])&&void 0!==o?o:""));null!=a&&i.push([e.key,{[n]:"quantity"===n?Number(a):a}])}),i.length)?(ef(i),i.length):0}}),(0,n.jsx)(lB,{columns:p,rows:c,totalCount:a.length,expanded:Y,onExpandChange:Q,canCollapse:u,isTruncated:u&&!Y,emptyState:el?(0,n.jsx)(l7,{}):(0,n.jsx)(lI.Z,{size:"sm",icon:(0,n.jsx)(lk.Z,{}),title:"No variants left to price",description:"Every option was removed from this variation. Add an option back above, or delete the variation to sell this listing as a single product."}),renderRow:l=>{var t,i,r,o,a,d;let s=K[l.key]||{},u=null!==(i=s.sku)&&void 0!==i?i:l.sku,c=null!==(r=s.price)&&void 0!==r?r:l.price,p=null!==(o=s.quantity)&&void 0!==o?o:l.quantity,v=null!==(a=s.visible)&&void 0!==a?a:l.visible,h=null!==(d=null==w?void 0:null===(t=w.byRowKey)||void 0===t?void 0:t[l.key])&&void 0!==d?d:null;return(0,n.jsxs)(lw.Z,{children:[(0,n.jsx)(lS.Z,{sx:lT,children:l.v1}),e.length>1&&(0,n.jsx)(lS.Z,{sx:lT,children:l.v2}),(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsx)(lR,{value:u,label:"SKU",placeholder:"SKU",onCommit:e=>ev(l.key,{sku:e})})}),(0,n.jsxs)(lS.Z,{sx:lT,children:[(0,n.jsx)("div",{children:(0,n.jsx)(lR,{value:c,label:"Price",type:"number",step:"0.01",prefix:"$",placeholder:"0.00",onCommit:e=>ev(l.key,{price:e})})}),null!=h&&(0,n.jsx)("p",{className:"mt-1 text-lv-caption",style:{color:ei.oR.accent},children:"AI: $".concat(h)})]}),(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsx)(lR,{value:p,label:"Quantity",type:"number",placeholder:"0",onCommit:e=>ev(l.key,{quantity:Number(e)})})}),(0,n.jsx)(lS.Z,{sx:{...lT,textAlign:"right"}
1,children:(0,n.jsx)(lM,{checked:v,label:"Visible",onChange:e=>ev(l.key,{visible:e})})})]},l.key)}})]})]})}let e_=[{key:"axis-1",label:(null===(l=u[0])||void 0===l?void 0:l.name)||"OPTION"},{key:"axis-2",label:null===(t=u[1])||void 0===t?void 0:t.name,hidden:u.length<2},{key:"sku",label:"SKU"},{key:"price",label:"Price"},{key:"quantity",label:"Qty"},{key:"visible",label:"On",align:"right"}],ew=1===u.length?(u[0].options||[]).map(e=>({key:"".concat(u[0].id,"_").concat(e),option1:e,bucketKey:u[0].id,optionKey:e,inventory:(p[u[0].id]||{})[e]||{}})):u.length>=2?(u[0].options||[]).flatMap(e=>(u[1].options||[]).map(l=>{let t="".concat(e,"|||").concat(l),n="".concat(u[0].id,"__").concat(u[1].id);return{key:t,option1:e,option2:l,bucketKey:n,optionKey:t,inventory:(p[n]||{})[t]||{}}})):[],eS=eb(u.map(e=>{var l;return{name:e.name||"OPTION",options:null!==(l=e.options)&&void 0!==l?l:[]}})),ek=ew.filter(e=>{var l,t;return l3([null!==(l=e.option1)&&void 0!==l?l:null,null!==(t=e.option2)&&void 0!==t?t:null],$)});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l8.Z,{count:(0,l9.MB)(u),limit:Z,className:"mb-4"}),u.length>0&&(0,n.jsx)("div",{className:"mb-4 grid gap-3 md:grid-cols-2",children:u.map(e=>(0,n.jsx)(lZ.Z,{name:e.name,options:e.options,isOpen:F===e.id,onToggle:()=>T(l=>l===e.id?null:e.id),onDone:l=>{let{name:t,options:n}=l;c(l=>l.map(l=>l.id===e.id?{...l,name:t,options:n}:l)),v(l=>{let t=l[e.id]||{},i={};return n.forEach(e=>{i[e]=t[e]||{sku:"",price:"",quantity:""}}),{...l,[e.id]:i}}),T(null)},onDelete:()=>eg(e.id)},e.id))}),0===u.length&&!P&&(0,n.jsx)("p",{className:"mb-3 text-sm text-lv-text-secondary",children:"No variants created yet."}),u.length<k.maxTypes&&(0,n.jsx)("div",{className:"mb-4",children:P?(0,n.jsx)(lZ.Z,{name:"",options:[],isOpen:!0,onToggle:()=>R(!1),onDone:e=>{let{name:l,options:t}=e;if(!l.trim()||!t.length)return;let n=Math.max(1,(0,l9.MB)(u))*t.length;if(n>Z){O.Am.error((0,l9.MT)(n,Z,C));return}let i={id:tr(),name:l.trim(),options:t};c(e=>[...e,i]),v(e=>{let l={};return t.forEach(e=>{l[e]={sku:"",price:"",quantity:""}}),{...e,[i.id]:l}}),s&&s(!0),R(!1)},onDelete:()=>R(!1)}):(0,n.jsx)("button",{type:"button",onClick:()=>R(!0),className:"rounded-md bg-black px-3.5 py-2 text-sm font-medium text-white shadow-sm hover:bg-neutral-800",children:"Add a variant"})}),(0,n.jsxs)("div",{className:"mb-4 flex items-center gap-2",children:[(0,n.jsx)(lC.Z,{checked:d,onChange:e=>s(e),label:"Products vary by variants"}),(0,n.jsx)("span",{className:"text-xs text-lv-text-secondary",children:"(e.g. different prices for different sizes)"})]}),d&&(0,n.jsx)(n.Fragment,{children:0===u.length?(0,n.jsx)(lI.Z,{size:"sm",icon:(0,n.jsx)(lk.Z,{}),title:"No inventory to configure yet",description:"Add at least one variant above to configure inventory."}):(0,n.jsxs)(n.Fragment,{children:[ej({axes:eS,shownCount:ek.length,totalCount:ew.length,onApplyBulk:(e,l)=>{let t=e===l$?"price":"qty"===e?"quantity":"sku",n=[];return(ek.forEach(e=>{var i;let{bucketKey:r,optionKey:o,inventory:a}=e,d=l(String(null!==(i=null==a?void 0:a[t])&&void 0!==i?i:""));null!=d&&n.push({bucketKey:r,optionKey:o,changes:{[t]:d}})}),n.length)?(ey(n),n.length):0}}),(0,n.jsx)(lB,{columns:e_,rows:ek,totalCount:ek.length,emptyState:el?(0,n.jsx)(l7,{}):(0,n.jsx)(lI.Z,{size:"sm",icon:(0,n.jsx)(lk.Z,{}),title:"No options to price",description:"This variation has no options yet. Add at least one option above to configure its inventory."}),renderRow:e=>{let l=e.inventory;return(0,n.jsxs)(lw.Z,{children:[(0,n.jsx)(lS.Z,{sx:lT,children:e.option1}),void 0!==e.option2&&(0,n.jsx)(lS.Z,{sx:lT,children:e.option2}),(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsx)(lR,{value:l.sku||"",label:"SKU",placeholder:"SKU",onCommit:l=>em(e.bucketKey,e.optionKey,{sku:l})})}),(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsx)(lR,{value:l.price||"",label:"Price",type:"number",step:"0.01",prefix:"$",placeholder:"0.00",onCommit:l=>em(e.bucketKey,e.optionKey,{price:l})})}),(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsx)(lR,{value:l.quantity||"",label:"Quantity",type:"number",placeholder:"0",onCommit:l=>em(e.bucketKey,e.optionKey,{quantity:l})})}),(0,n.jsx)(lS.Z,{sx:lT,align:"right",children:(0,n.jsx)(lM,{checked:!1!==l.visible,label:"Visible",onCh
1ange:l=>em(e.bucketKey,e.optionKey,{visible:l})})})]},e.key)}})]})})]})}var ta=t(72585);let td=e=>(null==e?void 0:e.title)?"calculated"===e.profile_type?"".concat(e.title," (calculated)"):e.title:"",ts=(e,l)=>!l||td(e).toLowerCase().includes(l),tu=(e,l)=>(null==e?void 0:e.shipping_profile_id)===(null==l?void 0:l.shipping_profile_id);function tc(e){let{shippingProfile:l,setShippingProfile:t,shippingProfiles:i=[],validation:o={}}=e,a=i.find(e=>e.shipping_profile_id===l)||null;return(0,n.jsx)(r.Z,{id:"shipping-profile",title:"Shipping Profile",issues:[(0,v.bw)(o)].filter(Boolean),children:(0,n.jsx)(ld.Z,{cozy:!0,options:i,value:a,onChange:e=>{var l;return t(null!==(l=null==e?void 0:e.shipping_profile_id)&&void 0!==l?l:"")},placeholder:"Select a shipping profile",searchPlaceholder:"Search shipping profiles...",noOptionsText:"No shipping profiles found",getOptionLabel:td,isOptionEqual:tu,filterOption:ts,fullWidth:!0})})}function tp(e){let{returnPolicy:l,setReturnPolicy:t,returnPolicies:i=[],validation:o={}}=e;return(0,n.jsx)(r.Z,{id:"return-policy",title:"Return Policy",issues:[(0,v.bw)(o)].filter(Boolean),children:(0,n.jsx)(X.Z,{cozy:!0,value:l,onChange:e=>t(e.target.value),placeholder:"Select a return policy",options:i.map(e=>({value:e.return_policy_id,label:(0,I.PX)(e)}))})})}function tv(e){let{shopSection:l,setShopSection:t,shopSections:i=[]}=e;return(0,n.jsx)(r.Z,{id:"shop-section",title:"Shop Section",children:(0,n.jsx)(X.Z,{cozy:!0,value:null==l||""===l?"":String(l),onChange:e=>t(e.target.value),placeholder:"Select a section",options:i.map(e=>({value:String(e.shop_section_id),label:e.title}))})})}function th(e){let{title:l,description:t,selected:i,onClick:r}=e;return(0,n.jsxs)("div",{className:"flex-1 p-4 border rounded-xl cursor-pointer transition-colors ".concat(i?"border-lv-brand bg-lv-brand-light":"border-lv-border hover:border-lv-border-strong"),onClick:r,children:[(0,n.jsx)(L.Z,{className:"text-xs font-medium text-lv-text-primary",children:l}),(0,n.jsx)(L.Z,{className:"text-xs text-lv-text-secondary mt-1",children:t})]})}function tf(e){let{renewalOption:l,setRenewalOption:t,itemWeight:o,setItemWeight:d,itemLength:s,setItemLength:u,itemWidth:c,setItemWidth:p,itemHeight:v,setItemHeight:h,weightUnit:f,setWeightUnit:x,dimensionsUnit:g,setDimensionsUnit:m,showPhysicalAttributes:b=!0,requireItemDimensions:j=!1}=e,_=!o||!s||!c||!v||!f||!g,[w,S]=(0,a.useState)(j&&_);return(0,n.jsx)(r.Z,{id:"listing-details",title:"Listing Details",children:(0,n.jsxs)(y.Z,{sx:{containerType:"inline-size"},children:[(0,n.jsxs)("div",{className:"mb-6",children:[(0,n.jsx)(L.Z,{className:"text-xs font-medium text-lv-text-primary mb-3",children:"Renewal options"}),(0,n.jsxs)(y.Z,{sx:{display:"flex",gap:2,["@container (max-width: ".concat(480,"px)")]:{flexDirection:"column"}},children:[(0,n.jsx)(th,{title:"Automatic",description:"This listing will renew as it expires for $0.20 USD each time (recommended).",selected:"automatic"===l,onClick:()=>t("automatic")}),(0,n.jsx)(th,{title:"Manual",description:"I'll renew expired listings myself.",selected:"manual"===l,onClick:()=>t("manual")})]})]}),b&&(0,n.jsxs)("div",{children:[(0,n.jsxs)(y.Z,{component:"button",type:"button",onClick:()=>S(e=>!e),"aria-expanded":w,sx:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",px:1.25,py:1,border:"1px solid var(--lv-border)",borderRadius:"10px",bgcolor:"transparent",cursor:"pointer",color:"var(--lv-text-primary)"},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:13,fontWeight:600},children:["Item Details",j&&(0,n.jsx)(L.Z,{component:"span",sx:{ml:.75,fontSize:12,fontWeight:500,color:_?"var(--lv-danger, #d32f2f)":"var(--lv-text-secondary)"},children:_?"⢠Required for calculated shipping":"⢠Complete"})]}),(0,n.jsx)(Y.Z,{size:16,style:{transition:"transform 150ms ease",transform:w?"rotate(180deg)":"none"}})]}),w&&(0,n.jsxs)(y.Z,{sx:{mt:1.5},children:[j&&_&&(0,n.jsx)(L.Z,{sx:{mb:1.5,fontSize:12,lineHeight:1.5,color:"var(--lv-text-secondary)"},children:"Your shipping profile uses calculated shipping, so Etsy needs the package weight and size to work out delivery cost. Listings can't be created until all six are filled
1in."}),(0,n.jsxs)(y.Z,{sx:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:2,mb:2,["@container (max-width: ".concat(480,"px)")]:{gridTemplateColumns:"1fr"}},children:[(0,n.jsx)(i.Z,{label:"Item weight",fullWidth:!0,value:o,onChange:e=>d(e)}),(0,n.jsx)(i.Z,{label:"Item length",fullWidth:!0,value:s,onChange:e=>u(e)}),(0,n.jsx)(i.Z,{label:"Item width",fullWidth:!0,value:c,onChange:e=>p(e)})]}),(0,n.jsxs)(y.Z,{sx:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:2,["@container (max-width: ".concat(480,"px)")]:{gridTemplateColumns:"1fr"}},children:[(0,n.jsx)(i.Z,{label:"Item height",fullWidth:!0,value:v,onChange:e=>h(e)}),(0,n.jsxs)("div",{children:[(0,n.jsx)(L.Z,{component:"label",sx:{display:"block",fontSize:12,fontWeight:500,color:"var(--lv-text-primary)",mb:.5},children:"Item weight unit"}),(0,n.jsx)(X.Z,{cozy:!0,value:f,onChange:e=>x(e.target.value),placeholder:"Select unit",options:I.dN})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(L.Z,{component:"label",sx:{display:"block",fontSize:12,fontWeight:500,color:"var(--lv-text-primary)",mb:.5},children:"Item dimensions unit"}),(0,n.jsx)(X.Z,{cozy:!0,value:g,onChange:e=>m(e.target.value),placeholder:"Select unit",options:I.E0})]})]})]})]})]})})}function tx(e){var l,t,o,d;let{materials:s,setMaterials:u,conflictField:p=!1,validation:h={}}=e,{rules:f}=(0,x.RK)(),g=null!==(o=null===(l=f.materials)||void 0===l?void 0:l.maxCount)&&void 0!==o?o:13,m=null!==(d=null===(t=f.materials)||void 0===t?void 0:t.maxLengthPerMaterial)&&void 0!==d?d:45,[b,j]=(0,a.useState)(""),[_,w]=(0,a.useState)(""),S=Array.isArray(s)?s:s?s.split(",").map(e=>e.trim()).filter(Boolean):[],k=e=>{let l=String(e).split(",").map(e=>e.trim()).filter(Boolean);if(0===l.length)return;let t=[...S],n=[],i="";for(let e of l){if(t.length>=g)break;let l=(0,I.eo)(e,f);if(!l.valid){i||(i=l.error);continue}t.some(e=>e.toLowerCase()===l.material.toLowerCase())||(t.push(l.material),n.push(l.material))}n.length>0?(u(t),j(""),w("")):i&&w(i)},C=e=>{u(S.filter(l=>l.toLowerCase()!==e.toLowerCase()))};return(0,n.jsxs)(r.Z,{id:"materials",title:"Materials",issues:[(0,v.bw)(h)].filter(Boolean),children:[(0,n.jsx)(i.Z,{fullWidth:!0,value:b,onChange:e=>{j(e),_&&w("")},onBlur:()=>{b.trim()&&k(b)},inputProps:{onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),k(b))},onPaste:e=>{var l,t;let n=null!==(t=null===(l=e.clipboardData)||void 0===l?void 0:l.getData("text"))&&void 0!==t?t:"";n.includes(",")&&(e.preventDefault(),k("".concat(b).concat(n)))}},placeholder:"Type a material and press Enter",helperText:"Max ".concat(m," characters per material ⢠Press Enter to add"),metaBadge:_?(0,n.jsx)(c.Z,{state:"error",label:_}):(0,n.jsx)(c.Z,{state:"neutral",label:"".concat(S.length," of ").concat(g," materials")}),disabled:S.length>=g,sx:void 0}),S.length>0&&(0,n.jsx)(y.Z,{sx:{display:"flex",flexWrap:"wrap",gap:.75,mt:2},children:S.map((e,l)=>(0,n.jsxs)(y.Z,{component:"span",sx:{display:"inline-flex",alignItems:"center",gap:.5,border:"1px solid var(--lv-border-default)",borderRadius:"10px",bgcolor:"var(--lv-bg-card)",px:1,py:.5,boxShadow:"0 1px 2px rgba(15,23,42,0.05)",fontSize:"0.75rem",fontWeight:500,color:"var(--lv-text-primary)"},children:[(0,n.jsx)(le.Z,{size:"small",onClick:()=>C(e),sx:{p:0,minWidth:"auto",borderRadius:"10%",color:"var(--lv-text-primary)"},children:(0,n.jsx)(lr.Z,{size:12})}),(0,n.jsx)(ll.Z,{orientation:"vertical",flexItem:!0}),(0,n.jsx)(y.Z,{component:"span",children:e})]},"".concat(e.toLowerCase(),"-").concat(l)))})]})}var tg=t(67563),tm=t(37723),ty=t(45319),tb=t(87789);function tj(e){var l,t;let{supplier:i,providerName:r}=e,o=null!==(l=null==i?void 0:i.slug)&&void 0!==l?l:i,a=null!==(t=null==i?void 0:i.name)&&void 0!==t?t:"printify"===o?"Printify":"printful"===o?"Printful":o,d=r?"Supplier: ".concat(r," (via ").concat(a,")"):"Supplier: ".concat(a);return"printify"===o?(0,n.jsx)(_.Z,{title:d,placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{component:"span",sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:13.5,height:13.5,borderRadius:"3px",bgcolor:ei.V9.printify.primary,flexShrink:0},children:(0,n.jsx)(tb.j4,{size:8.6,color:ei.V9.printify.onPrimary,className:"block"})})}):(0,n.jsx)(_.Z,{title:d,placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{component:"span",sx:{dis
1play:"inline-flex",alignItems:"center",width:14,height:14,px:.4,borderRadius:"3px",bgcolor:ei.V9.printful.primary,flexShrink:0},children:(0,n.jsx)(L.Z,{sx:{fontSize:8,color:ei.V9.printful.onPrimary,fontWeight:700,lineHeight:1},children:"PF"})})})}var t_=t(42148),tw=t(46257),tS=t(23004),tk=t(59253),tI=t(83688),tC=t(36943),tZ=t(45675),tP=t(49322),tR=t(66337),tA=t(21782),tE=t(17339),tM=t(32090),tz=t(92741),tD=t(64165),tL=t(39095),tO=t(9017);let tF=Object.freeze({lv_orders_in_flight:"ListingView has orders in flight for this routing product.",printify_orders_in_flight:"Printify has orders in flight for this routing product.",printify_order_probe_unavailable:"Printify order status could not be checked safely. Try again shortly.",printify_links_span_multiple_shops:"This listing's Printify routing spans more than one Printify shop, so order status cannot be verified for this change."});function tT(e){var l;let{open:t,kind:i,assessment:r,proposedKeys:o=[],droppedCombinations:a=[],splitUnsupported:d=!1,loading:s=!1,error:u=null,onClose:c,onConfirm:p}=e,v=(0,tO.Mk)(r,o),h=function(e){let{kind:l,assessment:t,proposedKeys:n=[],splitUnsupported:i=!1}
1=e;return!!i||("provider"===l?(null==t?void 0:t.blocking_provider_change)===!0:(0,tO.Mk)(t,n).length>0)}({kind:i,assessment:r,proposedKeys:o,splitUnsupported:d}),f=Array.isArray(null==r?void 0:r.reasons)?r.reasons:[],x=f.includes("printify_links_span_multiple_shops"),g=x?f.filter(e=>"printify_order_probe_unavailable"!==e):f,m="provider"===i;return(0,n.jsx)(F.Z,{open:t,onClose:c,onConfirm:p,title:m?"Replace routing product?":"Update routing product?",confirmText:m?"Replace product":"Update product",confirmDisabled:h,loading:s,maxWidth:"sm",fullWidth:!0,disableBackdropClose:s,disableEscapeKeyDown:s,children:(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:[(0,n.jsx)(L.Z,{sx:{fontSize:14,color:"var(--lv-text-primary)"},children:"ListingView will update your Printify routing product first, then Etsy."}),d&&(0,n.jsx)(L.Z,{role:"alert",sx:{fontSize:13,color:"var(--lv-error-strong)"},children:tO.cF}),m&&(0,n.jsx)(L.Z,{sx:{fontSize:13,color:"var(--lv-text-secondary)"},children:"ListingView will create and verify a replacement Printify product before adopting it. The current routing product stays active until verification succeeds."}),m&&a.length>0&&(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:13,fontWeight:600,color:"var(--lv-text-primary)"},children:"The new provider does not carry these combinations:"}),(0,n.jsx)(y.Z,{component:"ul",sx:{m:0,mt:.5,pl:2.5},children:a.map(e=>(0,n.jsx)(L.Z,{component:"li",sx:{fontSize:13,color:"var(--lv-text-secondary)"},children:e},e))})]}),r&&(0,n.jsxs)(y.Z,{sx:{border:"1px solid var(--lv-border-default)",borderRadius:1,p:1.25},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)"},children:["ListingView orders in flight:"," ",null!==(l=r.in_flight_lv_orders)&&void 0!==l?l:0]}),(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)"},children:["Printify orders in flight:"," ",null==r.in_flight_printify_orders?"unavailable":r.in_flight_printify_orders]})]}),g.length>0&&(0,n.jsx)(y.Z,{component:"ul",sx:{m:0,pl:2.5},children:g.map(e=>{var l;return(0,n.jsx)(L.Z,{component:"li",sx:{fontSize:13,color:"var(--lv-warning)"},children:null!==(l=tF[e])&&void 0!==l?l:e},e)})}),v.length>0&&(0,n.jsx)(L.Z,{role:"alert",sx:{fontSize:13,color:"var(--lv-error-strong)"},children:x?(0,n.jsxs)(n.Fragment,{children:["Order status cannot be verified for these combinations:"," ",v.join(", "),"."]}):(0,n.jsxs)(n.Fragment,{children:["This change affects combinations with orders in flight:"," ",v.join(", "),"."]})}),u&&(0,n.jsx)(L.Z,{role:"alert",sx:{fontSize:13,color:"var(--lv-error-strong)"},children:u})]})})}var tN=t(36362),tW=t(46746),tU=t(43173),tH=t(98597);let tB=[{value:"awaiting_approval",label:"Awaiting Approval (default â newly captured)"},{value:"held",label:"Held (auto-hold rule triggered)"},{value:"approved",label:"Approved (passed the gate)"},{value:"submitted",label:"Submitted (sent to Printify)"},{value:"in_production",label:"In Production"},{value:"shipped",label:"Shipped"},{value:"relay_failed",label:"Relay Failed (test the retry banner)"},{value:"delivered",label:"Delivered (terminal â for badge visual)"}],tV=[{value:"webhook_sim",label:"Backend webhook sim (real BE order)",helper:"Builds an Etsy transaction.created webhook and posts it to the BE. The order lands in the real D9 list â approve/reject/hold all hit real endpoints."},{value:"local_mock",label:"Local mock (offline, localStorage)",helper:"Persists the order to this browser's localStorage. No BE call. Useful when the BE is unreachable, or when you need to seed a non-awaiting state to test mid-pipeline UI."}],tK={first_name:"Jane",last_name:"Doe",address1:"123 Main Street",address2:"Apt 4B",city:"Austin",region:"TX",zip:"78701",country:"US",email:"[email protected]",phone:"+1-512-555-0100"};function tq(e){var l,t;let{open:r,onClose:o,variant:d=null,podProducts:s=[],listingId:u,listingTitle:c,onCreated:p}=e,v=(0,a.useMemo)(()=>d?[]:function(e){let l=[];for(let r of e||[]){var t,n,i;let e=r.colors||r.colorOptions||[],o=r.sizes||r.sizeOptions||[],a=r.variant_matrix||r.variantMatrix||{};if(e.length&&o.length)for(let i of e)for(let e of o){let o="".concat(i.id||i.option_id||i.value,"+").concat(e.id||e.option_id||e.value),d=a[o];if((null==d?void 0:d.is_enabled)===!1)continue;let s=i.name||i.label||i.value||"â",u=e.name||e.label||e.value||"â",c=null!==(n=null!==(t=null==d?void 0:d.price_cents)&&void 0!==t?t:r.basePriceCents)&&void 0!==n?n:2500;
1l.push({id:"".concat(r.id||r.podProductId,"__").concat(o),label:"".concat(r.title||r.name||"POD"," â ").concat(s," / ").concat(u),productImage:r.previewImage||r.image||null,podProductId:r.id||r.podProductId,colorOptionId:i.id||i.option_id||i.value,sizeOptionId:e.id||e.option_id||e.value,priceCents:c,provider:r.provider||"printify",variations:[{name:"Color",value:s},{name:"Size",value:u}]})}else l.push({id:"".concat(r.id||r.podProductId,"__default"),label:r.title||r.name||"Default variant",productImage:r.previewImage||r.image||null,podProductId:r.id||r.podProductId,priceCents:null!==(i=r.basePriceCents)&&void 0!==i?i:2500,provider:r.provider||"printify",variations:[]})}return l}(s),[d,s]),[h,f]=(0,a.useState)((null===(l=v[0])||void 0===l?void 0:l.id)||""),[x,g]=(0,a.useState)(1),[m,b]=(0,a.useState)(""),[j,_]=(0,a.useState)("awaiting_approval"),[S,k]=(0,a.useState)(tK),[I,C]=(0,a.useState)("webhook_sim"),[Z,P]=(0,a.useState)(!1),[R,A]=(0,a.useState)({}),[E,M]=(0,a.useState)(null),z=(0,lh.v9)(e=>{var l,t;return null===(t=e.user)||void 0===t?void 0:null===(l=t.myInfo)||void 0===l?void 0:l.etsyShopId}),D=()=>{var e;f((null===(e=v[0])||void 0===e?void 0:e.id)||""),g(1),b(""),_("awaiting_approval"),k(tK),C("webhook_sim"),A({}),M(null)},F=()=>{Z||(D(),null==o||o())},T=(e,l)=>{k(t=>({...t,[e]:l})),R[e]&&A(l=>({...l,[e]:void 0}))},N=()=>{let e={};return d||h||(e.variantId="Pick a variant"),S.first_name.trim()||(e.first_name="Required"),S.last_name.trim()||(e.last_name="Required"),S.address1.trim()||(e.address1="Required"),S.city.trim()||(e.city="Required"),S.zip.trim()||(e.zip="Required"),S.country.trim()||(e.country="Required"),A(e),0===Object.keys(e).length},W=()=>({first_name:S.first_name.trim(),last_name:S.last_name.trim(),address1:S.address1.trim(),address2:S.address2.trim()||void 0,city:S.city.trim(),region:S.region.trim()||void 0,zip:S.zip.trim(),country:S.country.trim().toUpperCase(),email:S.email.trim()||void 0,phone:S.phone.trim()||void 0}),U=async()=>{var e,l,t,n,i,r,a;if(!N())return;M(null),P(!0);let s=null!=d?d:v.find(e=>e.id===h),f={...s,listingId:null!==(e=null==s?void 0:s.listingId)&&void 0!==e?e:u,listingTitle:null!==(t=null!==(l=null==s?void 0:s.listingTitle)&&void 0!==l?l:c)&&void 0!==t?t:null==s?void 0:s.label},g=W();try{if("webhook_sim"===I){if(!z)throw Error("No active Etsy shop in Redux. Switch to a shop with POD enabled before using the webhook simulator.");if(!f.listingId)throw Error("Couldn't find a listingId for the selected variant. The webhook simulator needs a real Etsy listing to link against.");let e=(0,tH.sm)({etsyShopId:z,variant:f,address:g,quantity:x,personalization:m}),l=await (0,tH.Gc)(e);O.Am.success("Webhook accepted by backend. The new order should appear in /dashboard/orders."),null==p||p({via:"webhook_sim",result:l})}else{let e=(0,tU.xA)({shippingAddress:g,variant:f,quantity:x,personalization:m,initialStatus:j});O.Am.success("Local mock order created (".concat(j,"). Open /dashboard/orders to view.")),null==p||p({via:"local_mock",order:e})}D(),null==o||o()}catch(l){let e=(null==l?void 0:null===(i=l.response)||void 0===i?void 0:null===(n=i.data)||void 0===n?void 0:n.message)||(null==l?void 0:null===(a=l.response)||void 0===a?void 0:null===(r=a.data)||void 0===r?void 0:r.error)||(null==l?void 0:l.message)||"Couldn't create test order.";M(e),O.Am.error(e)}finally{P(!1)}};return(0,n.jsx)($.Z,{open:r,onClose:F,title:"Create a test POD order",size:"md",fullWidth:!0,actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w.f,{text:"Cancel",color:"no-background",onClick:F,disabled:Z,padding:"px-3 py-1.5",fontSize:"text-xs",width:"auto"}),(0,n.jsx)(w.f,{text:Z?"webhook_sim"===I?"Sending webhookâ¦":"Creatingâ¦":"webhook_sim"===I?"Send to backend":"Create local mock",color:"purple",onClick:U,disabled:Z||"webhook_sim"===I&&!z,padding:"px-4 py-1.5",borderRadius:"rounded-lg",fontSize:"text-xs",width:"auto",className:"whitespace-nowrap"})]}),children:(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:2},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:"12px",color:"var(--lv-text-secondary)",lineHeight:1.5},children:["Engineering-only. Pick how the order should be created â either a real backend pod_order (via the Etsy webhook simulator) or a local mock in this browser's storage. Both flow through ",(0,n.jsx)("strong",{children:"/dashboard/orders"}),"."]}),(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:"12px",fontWeight:600,color:"var(--lv-text-primary)",mb:.5},children:"Create via"}),(0,n.jsx)(tW.Z,{fullWidth:!0,size:"small",value:I,onChange:e=>{C(e.target.value),M(null)},sx:{fontSize:"13px"},"data-testid":"submit-mode-select",children:tV.map(e=>(0,n.jsx)(eJ.Z,{value:e.value,sx:{fontSize:"13px"},children:e.label},e.value))}),(0,n.jsx)(L.Z,{sx:{fontSize:"11px",color:"var(--lv-text-tertiary)",mt:.5,lineHeight:1.4},children:null===(t=tV.find(e=>e.value===I))||void 0===t?void 0:t.helper}),"webhook_sim"===I&&!z&&(0,n.jsx)(L.Z,{sx:{fontSize:"11px",color:"var(--lv-error)",mt:.5},children:"No active Etsy shop selected â switch to a shop with POD enabled before submitting."})]}),(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:"12px",fontWeight:600,color:"var(--lv-text-primary)",mb:.5},children:"Variant"}),d?(0,n.jsxs)(y.Z,{sx:{px:1.5,py:1,borderRadius:"8px",backgroundColor:"var(--lv-bg-elevated)",border:"1px solid var(--lv-border-default)",display:"flex",alignItems:"center",gap:1.25},children:[d.productImage&&(0,n.jsx)("img",{src:d.productImage,alt:"",style:{width:32,height:32,borderRadius:4,objectFit:"cover"}}),(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,n.jsx)(L.Z,{sx:{fontSize:"13px",fontWeight:500,color:"var(--lv-text-primary)"},children:d.label}),Number.isFinite(d.priceCents)&&(0,n.jsxs)(L.Z,{sx:{fontSize:"11px",color:"var(--lv-text-tertiary)"},children:["$",(d.priceCents/100).toFixed(2)," \xb7"," ",d.provider||"printify"]})]})]}):0===v.length?(0,n.jsx)(L.Z,{sx:{fontSize:"12px",color:"var(--lv-error)"},children:"No variants found in this listing's POD products. Add a POD product first."}):(0,n.jsx)(tW.Z,{fullWidth:!0,size:"small",value:h,onChange:e=>f(e.target.value),sx:{fontSize:"13px"},children:v.map(e=>(0,n.jsx)(eJ.Z,{value:e.id,sx:{fontSize:"13px"},children:e.label},e.id))}),R.variantId&&(0,n.jsx)(L.Z,{sx:{fontSize:"11px",color:"var(--lv-error)",mt:.5},children:R.variantId})]}),(0,n.jsxs)(y.Z,{children:[(0,n.jsxs)(L.Z,{sx:{fontSize:"12px",fontWeight:600,color:"var(--lv-text-primary)",mb:.5},children:["Starting state"," ","webhook_sim"===I&&(0,n.jsx)(L.Z,{component:"span",sx:{fontSize:"11px",fontWeight:400,color:"var(--lv-text-tertiary)"},children:"(ignored â BE assigns)"})]}),(0,n.jsx)(tW.Z,{fullWidth:!0,size:"small",value:j,onChange:e=>_(e.target.value),sx:{fontSize:"13px"},disabled:"webhook_sim"===I,children:tB.map(e=>(0,n.jsx)(eJ.Z,{value:e.value,sx:{fontSize:"13px"},children:e.label},e.value))})]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",gap:1.5},children:[(0,n.jsxs)(y.Z,{sx:{flex:"0 0 110px"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:"12px",fontWeight:600,color:"var(--lv-text-primary)",mb:.5},children:"Quantity"}),(0,n.jsx)(i.Z,{type:"number",value:String(x),onChange:e=>g(Math.max(1,parseInt(e,10)||1)),fullWidth:!0,size:"sm"})]}),(0,n.jsxs)(y.Z,{sx:{flex:1},children:[(0,n.jsx)(L.Z,{sx:{fontSize:"12px",fontWeight:600,color:"var(--lv-text-primary)",mb:.5},children:"Personalization (optional)"}),(0,n.jsx)(i.Z,{value:m,onChange:e=>b(e),placeholder:'Triggers "has personalization" flag',fullWidth:!0,size:"sm"})]})]}),(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:"13px",fontWeight:600,color:"var(--lv-text-primary)",mb:1},children:"Shipping address"}),(0,n.jsxs)(y.Z,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1.5},children:[(0,n.jsx)(tG,{label:"First name *",error:R.first_name,children:(0,n.jsx)(i.Z,{value:S.first_name,onChange:e=>T("first_name",e),fullWidth:!0,size:"sm"})}),(0,n.jsx)(tG,{label:"Last name *",error:R.last_name,children:(0,n.jsx)(i.Z,{value:S.last_name,onChange:e=>T("last_name",e),fullWidth:!0,size:"sm"})}),(0,n.jsx)(tG,{label:"Address line 1 *",error:R.address1,fullWidth:!0,children:(0,n.jsx)(i.Z,{value:S.address1,onChange:e=>T("address1",e),fullWidth:!0,size:"sm"})}),(0,n.jsx)(tG,{label:"Address line 2",fullWidth:!0,children:(0,n.jsx)(i.Z,{value:S.address2,onChange:e=>T("address2",e),fullWidth:!0,size:"sm"})}),(0,n.jsx)(tG,{label:"City *",error:R.city,children:(0,n.jsx)(i.Z,{value:S.city,onChange:e=>T("city",e),fullWidth:!0,size:"sm"})}),(0,n.jsx)(tG,{label:"State / Region",children:(0,n.jsx)(i.Z,{value:S.region,onChange:e=>T("region",e),fullWidth:!0,size:"sm"})}),(0,n.jsx)(tG,{label:"ZIP / Postal code *",error:R.zip,children:(0,n.jsx)(i.Z,{value:S.zip,onChange:e=>T("zip",e),fullWidth:!0,size:"sm"})}),(0,n.jsx)(tG,{label:"Country (ISO 2-letter) *",error:R.country,children:(0,n.jsx)(i.Z,{value:S.country,onChange:e=>T("country",e.toUpperCase().slice(0,2)),placeholder:"US, GB, DEâ¦",fullWidth:!0,size:"sm"})}),(0,n.jsx)(tG,{label:"Email",children:(0,n.jsx)(i.Z,{value:S.email,onChange:e=>T("email",e),fullWidth:!0,size:"sm"})}),(0,n.jsx)(tG,{label:"Phone",children:(0,n.jsx)(i.Z,{value:S.phone,onChange:e=>T("phone",e),fullWidth:!0,size:"sm"})})]})]}
1),E&&(0,n.jsxs)(y.Z,{role:"alert",sx:{display:"flex",alignItems:"flex-start",gap:1,p:1.25,borderRadius:"8px",backgroundColor:"var(--lv-error-bg, #fff1f2)",border:"1px solid var(--lv-error)"},children:[(0,n.jsx)(tP.Z,{size:16,"aria-hidden":"true",style:{color:"var(--lv-error)",marginTop:2}}),(0,n.jsxs)(y.Z,{sx:{flex:1,minWidth:0},children:[(0,n.jsx)(L.Z,{sx:{fontSize:"12px",fontWeight:600,color:"var(--lv-error)",mb:.25},children:"webhook_sim"===I?"Backend webhook sim failed":"Couldn't save local mock order"}),(0,n.jsx)(L.Z,{sx:{fontSize:"12px",color:"var(--lv-text-primary)"},children:E}),"webhook_sim"===I&&(0,n.jsxs)(L.Z,{sx:{fontSize:"11px",color:"var(--lv-text-secondary)",mt:.5},children:["Tip: switch ",(0,n.jsx)("strong",{children:"Create via"}),' to "Local mock" above to keep testing the UI while the backend issue is being investigated.']})]})]})]})})}function tG(e){let{label:l,error:t,fullWidth:i=!1,children:r}=e;return(0,n.jsxs)(y.Z,{sx:{gridColumn:i?"1 / -1":"auto"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:"11px",fontWeight:500,color:"var(--lv-text-secondary)",mb:.5},children:l}),r,t&&(0,n.jsx)(L.Z,{sx:{fontSize:"10px",color:"var(--lv-error)",mt:.5},children:t})]})}var tY=t(17794),tQ=t(81314);let t$=e=>{let l=(null!=e?e:"").toLowerCase();return l.endsWith("s")?l:"".concat(l,"s")},tX=e=>{let l=parseFloat(e);return isNaN(l)?"â":"$".concat(l.toFixed(2))}
1,tJ="Your Printify provider no longer offers this size/color. Pick a different combination or change the print provider.",t0=e=>{var l,t;return(null==e?void 0:null===(l=e.product)||void 0===l?void 0:l.title)||(null==e?void 0:null===(t=e.product)||void 0===t?void 0:t.name)||(null==e?void 0:e.title)||(null==e?void 0:e.name)||"POD Product"},t1=Object.freeze(["sku"]),t5={[l$]:"price",qty:"qty"};function t2(e){let{condition:l,v1Name:t,v2Name:i}=e,r=1===l,o=1===l?"Standard matrix â ".concat([t,i].filter(Boolean).join(" \xd7 ")):2===l?"V2 renamed to 'Option' â Etsy size chart will not attach":"No shared variations â both axes renamed. Size chart will not attach.";return(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1,px:1.5,py:.875,borderRadius:1.5,mb:1.5,bgcolor:r?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",border:"1px solid ".concat(r?"rgba(34,197,94,0.25)":"rgba(245,158,11,0.3)")},children:[(0,n.jsx)(y.Z,{sx:{width:6,height:6,borderRadius:"50%",bgcolor:r?"#22c55e":"#f59e0b",flexShrink:0}}),(0,n.jsx)(L.Z,{sx:{fontSize:12,color:r?"#16a34a":"#b45309"},children:o})]})}function t3(e){let{podProducts:l=[],listingId:t,isPreset:i=!1,listingTitle:r,onVariantMatrixChange:o,onCatalogRefreshed:d,aiPodPriceWrites:s,onAiPodPriceWritesApplied:u,aiVariantPricePreview:c,publishBlocked:p=!1,publishBlockedReason:v="Upload a design for the reserved slot(s) to publish"}=e,[h,f]=(0,a.useState)({}),x=(0,a.useRef)(h);x.current=h;let[g,m]=(0,a.useState)({}),[j,w]=(0,a.useState)(null),[S,k]=(0,a.useState)(""),[I,C]=(0,a.useState)(!1),Z=(0,a.useRef)({}),{linked:P,markLinked:R,refreshStatus:A}=(0,tD.Z)(t,{enabled:!i}),[E,M]=(0,a.useState)(null),{emitBlocked:z,handleLockedInteraction:D,handleLockedKeyDown:T}=(0,tL.Z)(tE.yK.MATRIX),N=(0,a.useCallback)(e=>{let l=(0,tE.EO)(e);l&&(O.Am.error(l.message,{toastId:l.code}),l.code===tE.hr.LOCKED_ROUTED_LISTING&&(R(),z(tE.vk)))},[R,z]),W=(0,a.useCallback)(e=>{let{cellKey:l,field:t,previous:n,podProductId:i,matKey:r}=e;if(null!=l&&null!=t&&(f(e=>({...e,[l]:{...e[l],[t]:n}})),i&&null!=r)){let e={};if("price"===t){let l=Math.round(100*parseFloat(n));isNaN(l)||(e.price_cents=l)}else if("qty"===t){let l=parseInt(n,10);isNaN(l)||(e.quantity=l)}else"sku"===t&&(e.sku=null!=n?n:"");Object.keys(e).length&&(null==o||o(i,{[r]:e}))}},[o]),U=(0,a.useCallback)((e,l)=>{var t;let n=null==e?void 0:null===(t=e.data)||void 0===t?void 0:t.data,i=(Array.isArray(null==n?void 0:n.skipped)?n.skipped:[]).some(e=>(null==e?void 0:e.key)===l.matKey||(null==e?void 0:e.matrixKey)===l.matKey),r="number"==typeof(null==n?void 0:n.applied_count)&&0===n.applied_count;return(i||r)&&(W(l),O.Am.error("That change didn't save â this variant is no longer in the product's catalog. Reload the listing and try again.",{toastId:"pod-matrix-write-skipped"})),e},[W]),H=(0,a.useCallback)((e,l)=>{if(W(l),(0,tE.EO)(e)){N(e);return}O.Am.error("That change didn't save â reopen the listing and try again.",{toastId:"pod-matrix-write-failed"})},[W,N]),B=(0,a.useRef)(null),V=(0,a.useCallback)(e=>{let l;if(B.current)l=B.current.then(e,e);else try{l=Promise.resolve(e())}catch(e){l=Promise.reject(e)}let t=l.then(()=>{},()=>{});return B.current=t,t.then(()=>{B.current===t&&(B.current=null)}),l},[]),K=(0,a.useCallback)(e=>{let{cellKey:l,podProductId:t,matKey:n,enabled:i}=e;f(e=>({...e,[l]:{...e[l],userEnabled:i}})),null==o||o(t,{[n]:{is_enabled:i}})},[o]),q=(0,a.useCallback)(async e=>{let l={...e,kind:"variant",proposedKeys:e.enabled?[]:[e.matKey]};M(e=>e?{...e,loading:!0,error:null}:e);try{let l=await V(()=>(0,eI.Y$)(t,e.podProductId,{[e.matKey]:{is_enabled:e.enabled}})),n=(0,tO.Uy)(l);n?(0,tO.Cq)(n,t):K(e),M(null)}catch(a){var n,i,r;let o=(0,tO.vx)(a);if(o.code===tO.LB.ORDERS_IN_FLIGHT||o.code===tO.LB.MULTI_SHOP){M(e=>({...null!=e?e:l,assessment:o.assessment,loading:!1,error:o.message}));return}if(o.code===tO.LB.SPLIT_UNSUPPORTED){M(e=>({...null!=e?e:l,splitUnsupported:!0,loading:!1,error:tO.cF}));return}if(o.code===tO.LB.IN_PROGRESS){let l=await A();(0,tO.Cq)({status:null!==(n=null==l?void 0:l.edit_in_flight)&&void 0!==n?n:"updating",operationId:null,podProductId:e.podProductId},t),M(null);return}if(o.code===tO.LB.RETRY_REQUIRED){await A(),M(null),O.Am.info("Retry the Printify routing product from the status banner before editing again.");return}if(o.code===tO.LB.UNCOVERED_VARIANTS){null===(r=document.getElementById("pod-design-coverage"))||void 0===r||null===(i=r.scrollIntoView)||void 0===i||i.call(r,{behavior:"smooth",block:"start"}),M(e=>({...null!=e?e:l,loading:!1,error:"Add design coverage for this combination, then retry."}));return}e.kind?M(l=>({...null!=l?l:e,loading:!1,error:o.message||"Could not update this combination. Try again."})):O.Am.error(o.message||"Could not update this combination. Try again.")}},[K,V,t,A]),G=(0,a.useCallback)(async e=>{if(!t||!e.podProductId||null==e.matKey){K(e);return}if(P){let l=await A();if(void 0===l){O.Am.error("Could not check linked orders. Try again shortly.");return}if((0,tO.kF)(l,e.podProductId)){M({...e,kind:"variant",assessment:(0,tO.nn)(l),proposedKeys:e.enabled?[]:[e.matKey],splitUnsupported:(0,tO.y_)(l,e.podProductId),loading:!1,error:null});return}}await q(e)},[K,P,q,t,A]),[Y,Q]=(0,a.useState)(()=>new Set),[$,X]=(0,a.useState)(()=>new Set),J=(0,a.useCallback)(e=>{Q(l=>{let t=new Set(l);return t.has(e)?t.delete(e):t.add(e),t})},[]),ee=(0,a.useCallback)(e=>{X(l=>{let t=new Set(l);return t.has(e)?t.delete(e):t.add(e),t})},[]),el=(0,a.useCallback)(()=>{Q(new Set),X(new Set)},[]),[et,en]=(0,a.useState)({}),[ei,er]=(0,a.useState)(null),[eo,ea]=(0,a.useState)(null),[ed,es]=(0,a.useState)(!1),[eu,ec]=(0,a.useState)(null),[ep,ev]=(0,a.useState)(null),eh=(0,a.useRef)(null),ef=(0,a.useRef)(null),ex=(0,a.useRef)(null),eg=(0,a.useCallback)(()=>{eh.current&&(clearInterval(eh.current),eh.current=null),ef.current&&(clearTimeout(ef.current),ef.current=null)},[]),em=(0,a.useCallback)(async e=>{var l,t,n;try{let{data:n}=await lo.default.get("/api/catalog/refresh/".concat(e)),i=null==n?void 0:n.data;if(!i)return;if(ev(e=>e?{...e,status:i.status,progress:"number"==typeof i.progress?i.progress:e.progress}:e),"done"===i.status){eg(),ev(null);try{null==d||d()}catch(e){}}else if("failed"===i.status){eg(),ev(null);let e=(null===(l=i.error)||void 0===l?void 0:l.classification)||"
1UNKNOWN",n=null===(t=i.error)||void 0===t?void 0:t.retry_after_seconds;"RATE_LIMITED"===e?O.Am.warning("Couldn't refresh now â try again in ".concat(null!=n?n:60,"s.")):"TOKEN_REVOKED"===e||"TOKEN_INVALID"===e?O.Am.warning("Your Printify connection has expired. Reconnect in Settings to refresh availability."):O.Am.warning("Couldn't refresh â using last-known data.")}}catch(e){if((null==e?void 0:null===(n=e.response)||void 0===n?void 0:n.status)===404){eg(),ev(null);try{null==d||d()}catch(e){}}}},[d,eg]);(0,a.useEffect)(()=>{if(!Array.isArray(l)||0===l.length)return;let e=null;for(let t of l){let l=null==t?void 0:t.refreshMeta;if(l&&l.refresh_supported&&l.is_stale&&null!=l.blueprint_id&&null!=l.print_provider_id){e=l;break}}if(!e)return;let t="printify",n="".concat(t,":").concat(e.blueprint_id,":").concat(e.print_provider_id);if(ex.current===n)return;ex.current=n;let i=!1;return(async()=>{try{let{data:l}=await lo.default.post("/api/catalog/refresh",{supplier:t,blueprint_id:e.blueprint_id,print_provider_id:e.print_provider_id});if(i)return;let n=null==l?void 0:l.data;if(!n||"already_fresh"===n.status)return;let r=n.jobId;if(!r)return;ev({status:n.status||"queued",progress:0,jobId:r,supplier:t,blueprintId:e.blueprint_id,printProviderId:e.print_provider_id}),eh.current=setInterval(()=>em(r),2e3),ef.current=setTimeout(()=>{eg(),ev(null),O.Am.warning("Refresh taking longer than expected â using last-known data.")},3e4)}catch(t){var l,n,r,o;let e=null==t?void 0:null===(r=t.response)||void 0===r?void 0:null===(n=r.data)||void 0===n?void 0:null===(l=n.data)||void 0===l?void 0:l.code;if((null==t?void 0:null===(o=t.response)||void 0===o?void 0:o.status)===503&&"POD_REFRESH_DISABLED"===e)return}})(),()=>{i=!0,eg()}},[l.map(e=>{var l,t,n;return"".concat(null==e?void 0:null===(l=e.refreshMeta)||void 0===l?void 0:l.blueprint_id,":").concat(null==e?void 0:null===(t=e.refreshMeta)||void 0===t?void 0:t.print_provider_id,":").concat(null==e?void 0:null===(n=e.refreshMeta)||void 0===n?void 0:n.is_stale)}).join(",")]);let ey=(0,a.useMemo)(()=>(0,tY.aI)(l),[l]),{v1Options:eb,v2Options:ej,v1Name:e_,v2Name:ew,v1Role:eS,v2Role:ek,axes:eC,axisCount:eZ,costMap:eP,productColorSets:eR,productAxes:eA,productRefs:eE}=(0,a.useMemo)(()=>(0,tQ.Aq)(l,ey),[l,ey]),eM=l.length>1,ez=(0,a.useMemo)(()=>(0,tQ.ng)({v1Options:eb,v2Options:ej,axisCount:eZ,condition:ey,costMap:eP,productColorSets:eR,productAxes:eA,productRefs:eE}),[eb,ej,eZ,ey,eP,eR,eA,eE]),eD=(0,a.useRef)(new Set);(0,a.useEffect)(()=>{ez.forEach(e=>{var l,t,n,i;if(!(0,tQ.Kh)(e,eZ))return;let r=String(null!==(l=e.podProductId)&&void 0!==l?l:"unknown");if(!eD.current.has(r)){eD.current.add(r);try{tI.n({category:"pod-variant-matrix",level:"warning",message:"POD product has options the variant matrix cannot model",data:{podProductId:null!==(t=e.podProductId)&&void 0!==t?t:null,axisCount:null!==(n=e.productAxisCount)&&void 0!==n?n:eZ,attemptedKey:null!==(i=e.reconstructedKey)&&void 0!==i?i:null}})}catch(e){}}})},[ez,eZ]);let eL=Y.size>0||$.size>0,eO=(0,a.useCallback)(e=>{var l,t,n,i;return l3([null!==(n=null===(l=e.v1)||void 0===l?void 0:l.label)&&void 0!==n?n:null,null!==(i=null===(t=e.v2)||void 0===t?void 0:t.label)&&void 0!==i?i:null],[Y,$])},[Y,$]),eF=(0,a.useMemo)(()=>ez.filter(e=>e.productEnabled&&e.hasMatrixEntry&&eO(e)),[ez,eO]);(0,a.useEffect)(()=>{f(e=>{let n={};return ez.forEach(r=>{var o,a,d,s,u,c,p,v,h,f,x,g,m;let{cellKey:y,v1:b,v2:j,cost_cents:_,price_cents:w,saved_qty:S,is_enabled:k,productEnabled:I,stored_sku:C,matrixKey:Z,podProductId:P}=r;if(!I)return;let R=null!=_?_/100:null,A=null===(o=null!=j?j:b)||void 0===o?void 0:o.source_refs,E=null!==(v=l.find(e=>null==A?void 0:A.some(l=>l.podProductId===e.podProductId)))&&void 0!==v?v:l.find(e=>e.podProductId===P),M=E&&null!==(f=Object.values(null!==(h=E.prefixes)&&void 0!==h?h:{})[0])&&void 0!==f?f:"",z=null!==(x=eA[P])&&void 0!==x?x:eC,{colorRaw:D,sizeRaw:L}=(0,tQ.c8)({v1:b,v2:j,v1Role:null!==(g=null===(a=z[0])||void 0===a?void 0:a.role)&&void 0!==g?g:null,v2Role:null!==(m=null===(d=z[1])||void 0===d?void 0:d.role)&&void 0!==m?m:null,axisCount:eZ}),O=(0,tQ.RN)(t,M,D,L),F=i?Z?null==E?void 0:null===(u=E.rawVariants)||void 0===u?void 0:null===(s=u.find(e=>e.matrixKey===Z))||void 0===s?void 0:s.sku:null==E?void 0:null===(p=E.rawVariants)||void 0===p?void 0:null===(c=p.find(e=>e.color===D&&e.size===L))||void 0===c?void 0:c.sku:null,T="string"==typeof F&&""!==F.trim(),N=i?T?F:"":null!=C&&""!==String(C)?String(C):O;if(e[y])n[y]={...e[y],sku:e[y].skuOverridden?e[y].sku:N};else{let e=null!=w?(w/100).toFixed(2):null;n[y]={price:null!=e?e:null!==R&&R>0?(1.5*R).toFixed(2):"",qty:null!=S?String(S):"999",sku:N,skuOverridden:!!i&&T,userEnabled:k}}}),n})},[ez,t,i]);let eT=(0,a.useMemo)(()=>{let e=new Map;for(let t of ez){var l;if(!t.productEnabled||!t.hasMatrixEntry)continue;let n=h[t.cellKey];if(!n||!1===n.userEnabled)continue;let i=(0,tE.Z0)(n.sku);""!==i&&e.set(i,(null!==(l=e.get(i))&&void 0!==l?l:0)+1)}let t=new Set;for(let[l,n]of e)n>1&&t.add(l);return t},[ez,h]),eN=(0,a.useCallback)((e,l,n,i)=>{var r,a,d;let s="sku"===l?(0,tE.Z0)(n):n,u=null===(a=x.current)||void 0===a?void 0:null===(r=a[e])||void 0===r?void 0:r[l];if(f(t=>({...t,[e]:{...t[e],[l]:s,..."sku"===l?{skuOverridden:!0}:{}}}
1)),!(null==i?void 0:i.podProductId)||(null==i?void 0:i.matrixKey)==null)return;let c=i.matrixKey,p={};if("price"===l){let e=Math.round(100*parseFloat(n));isNaN(e)||(p.price_cents=e)}else if("qty"===l){let e=parseInt(n,10);isNaN(e)||(p.quantity=e)}else"sku"===l&&(p.sku=s);if(!Object.keys(p).length||(null==o||o(i.podProductId,{[c]:p}),!t))return;let v="".concat(i.podProductId,"|").concat(c),h=Z.current[v];h&&clearTimeout(h.timer);let g={...null!==(d=null==h?void 0:h.update)&&void 0!==d?d:{},...p};Z.current[v]={update:g,timer:setTimeout(()=>{delete Z.current[v];let n={cellKey:e,field:l,previous:u,podProductId:i.podProductId,matKey:c};V(()=>(0,eI.Y$)(t,i.podProductId,{[c]:g})).then(e=>U(e,n)).catch(e=>H(e,n))},800)}},[t,o,V,U,H]),eW=(0,a.useCallback)(e=>{let l={};e.forEach(e=>{var t;let{podProductId:n,matKey:i,patch:r}=e;n&&((null!==(t=l[n])&&void 0!==t?t:l[n]={})[i]=r)}),Object.entries(l).forEach(e=>{let[l,t]=e;Object.keys(t).forEach(e=>{let n="".concat(l,"|").concat(e),i=Z.current[n];i&&(clearTimeout(i.timer),delete Z.current[n],t[e]={...i.update,...t[e]})})});let n=[];return Object.entries(l).forEach(e=>{let[l,i]=e;t&&n.push(V(()=>(0,eI.Y$)(t,l,i)).then(e=>{var l,t;let n=null==e?void 0:null===(t=e.data)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.skipped;return Array.isArray(n)&&n.length>0&&O.Am.info("".concat(n.length," variant(s) skipped â not in the current catalog for this product. The rest were updated successfully.")),!0}).catch(e=>{var t,n;return N(e),{podProductId:l,skuCode:null!==(n=null===(t=(0,tE.EO)(e))||void 0===t?void 0:t.code)&&void 0!==n?n:null}})),null==o||o(l,i)}),Promise.all(n).then(e=>({attempted:e.length,failed:e.filter(e=>
1!0!==e).length,skuRejections:e.filter(e=>!0!==e&&(null==e?void 0:e.skuCode)!=null)}))},[t,o,V,N]),eU=(0,a.useMemo)(()=>{let e=new Map;for(let l of ez)l.productEnabled&&l.hasMatrixEntry&&l.podProductId&&null!=l.matrixKey&&e.set((0,l6.W5)(l.podProductId,l.matrixKey),l);return e},[ez]),eH=(0,a.useRef)(0);(0,a.useEffect)(()=>{let e=null==s?void 0:s.revision;if(!e||e===eH.current||0===eU.size||0===Object.keys(h).length)return;let l=s.prices||{};if(Object.keys(l).some(e=>{let l=eU.get(e);return null!=l&&!h[l.cellKey]}))return;eH.current=e;let t=[];for(let[e,n]of Object.entries(l)){let l=eU.get(e);if(!l)continue;let i=Math.round(100*parseFloat(n));Number.isFinite(i)&&!(i<=0)&&t.push({row:l,price:n,cents:i})}t.length>0&&(f(e=>{let l={...e};for(let{row:e,price:n}of t)l[e.cellKey]={...l[e.cellKey],price:n};return l}),eW(t.map(e=>{let{row:l,cents:t}=e;return{podProductId:l.podProductId,matKey:l.matrixKey,patch:{price_cents:t}}})).then(e=>{let{failed:l}=e;l>0&&O.Am.error("Couldn't save the AI variation prices to the server. They're shown in the grid, but a reload will bring back the old prices â re-enter them in the matrix to save them.")})),null==u||u(e,{applied:t.length,dropped:Object.keys(l).length-t.length})},[s,eU,h,eW,u]);let eB=(0,a.useCallback)(async()=>{var e,l,n,i,r,o,a,d,s,u,c,p,v;if(ei&&t){es(!0);try{let{podProductId:u,matKey:c,cellKey:p}=ei,v=await (0,eI.MM)(t,u,[c]),h=null!==(o=null==v?void 0:null===(l=v.data)||void 0===l?void 0:null===(e=l.data)||void 0===e?void 0:e.variant_matrix)&&void 0!==o?o:{},f=null!==(a=null==v?void 0:null===(i=v.data)||void 0===i?void 0:null===(n=i.data)||void 0===n?void 0:n.skipped)&&void 0!==a?a:[],x=null===(r=h[c])||void 0===r?void 0:r.cost_cents;if(null!=x)en(e=>({...e,[p]:x})),O.Am.success("Cost updated to $".concat((x/100).toFixed(2),". Margin recalculated."));else if(f.length>0){let e=null!==(s=null===(d=f[0])||void 0===d?void 0:d.reason)&&void 0!==s?s:"unknown";O.Am.error("catalog_cost_unavailable"===e?"Catalog cost not available yet â publish first to discover the cost.":"Could not refresh cost (".concat(e,")."))}else O.Am.info("No cost change to apply.")}catch(l){let e=null!==(v=null!==(p=null==l?void 0:null===(c=l.response)||void 0===c?void 0:null===(u=c.data)||void 0===u?void 0:u.message)&&void 0!==p?p:null==l?void 0:l.message)&&void 0!==v?v:"Failed to refresh cost";O.Am.error(e)}finally{es(!1),er(null)}}},[ei,t]);(0,a.useCallback)(async e=>{var n,i,r,a,d,s,u,c,p,v,h,f,x,g,m,y,b,j,_,w,S,k;let I=null==e?void 0:e.podProductId;if(!I||!t)return;let C=l.find(e=>e.podProductId===I);if(!C)return;let Z=e.matrixKey;if(!Z)return;let R={};for(let e of null!==(n=C.rawVariants)&&void 0!==n?n:[]){let l=null!==(i=null==e?void 0:e.matrixKey)&&void 0!==i?i:(null==e?void 0:e.color)||(null==e?void 0:e.size)?(0,eI.wr)(null==e?void 0:e.color,null==e?void 0:e.size):null;l&&(R[l]=!1!==e.is_enabled)}let A={};for(let e of Object.keys(R))A[e]={is_enabled:e===Z};A[Z]={is_enabled:!0};let E={};for(let e of Object.keys(R))E[e]={is_enabled:R[e]};let M=(0,tQ.j$)(e)||t0(C);ec(I);let z=!1;try{Object.keys(A).length>0&&(await (0,eI.Y$)(t,I,A),null==o||o(I,A));let e=await (0,eI.Kp)(t,I);z=!0,(0,tM.NK)(t);let l=null!==(u=null!==(s=null==e?void 0:null===(r=e.data)||void 0===r?void 0:r.data)&&void 0!==s?s:null==e?void 0:e.data)&&void 0!==u?u:{},n=null==l?void 0:l.updated_variant_matrix;if(n&&"object"==typeof n){let e={};for(let[l,t]of Object.entries(n)){if(!t||"object"!=typeof t)continue;let n={};null!=t.cost_cents&&(n.base_cost_cents=t.cost_cents),"boolean"==typeof t.is_available&&(n.is_available=t.is_available),Object.keys(n).length>0&&(e[l]=n)}Object.keys(e).length>0&&(null==o||o(I,e));let l=Object.values(n).filter(e=>e&&!1===e.is_available).length;l>0&&O.Am.warning("".concat(l," variant(s) are currently out of stock on Printify."),{autoClose:8e3})}let i=null==e?void 0:null===(d=e.data)||void 0===d?void 0:null===(a=d.data)||void 0===a?void 0:a.auto_disabled_variants;Array.isArray(i)&&i.length>0?O.Am.success("Published ".concat(M," to Printify â (auto-disabled by provider â try a different size/color or print provider)."),{autoClose:8e3}):O.Am.success("Published ".concat(M," to Printify successfully"))}catch(i){let e=null==i?void 0:null===(c=i.response)||void 0===c?void 0:c.data,l=null==e?void 0:null===(p=e.data)||void 0===p?void 0:p.code,t=(null==e?void 0:null===(f=e.data)||void 0===f?void 0:null===(h=f.printify_error)||void 0===h?void 0:null===(v=h.errors)||void 0===v?void 0:v.reason)||(null==e?void 0:null===(g=e.data)||void 0===g?void 0:null===(x=g.printify_error)||void 0===x?void 0:x.message),n=t||(null==e?void 0:e.message)||(null==i?void 0:i.message)||"Failed to publish to Printify";if(O.Am.error(n),"UNCOVERED_VARIANTS"===l){let l=null==e?void 0:null===(y=e.data)||void 0===y?void 0:null===(m=y.details)||void 0===m?void 0:m.uncovered_color_labels;Array.isArray(l)&&l.length&&O.Am.info("Add a design for: ".concat(l.join(", "),' â click the gear icon on a design file and enable those colors, or set "Apply to â All colors".'))}else if("PRINTIFY_NOT_CONNECTED"===l)O.Am.info("Connect Printify in Settings and select a shop, then try again.");else if("NO_ENABLED_VARIANTS"===l){let l=null==e?void 0:null===(j=e.data)||void 0===j?void 0:null===(b=j.details)||void 0===b?void 0:b.auto_disabled_variants;if(Array.isArray(l)&&l.length>0){let e={};for(let t of l)(null==t?void 0:t.variant_key)&&(e[t.variant_key]={is_available:!1});Object.keys(e).length>0&&(null==o||o(I,e));let t=l.map(e=>[null==e?void 0:e.color_label,null==e?void 0:e.size_label].filter(
1Boolean).join(" / ")).filter(Boolean);if(t.length>0){let e=t.slice(0,3).join(", "),l=t.length>3?" (+".concat(t.length-3," more)"):"";O.Am.info("Printify no longer offers: ".concat(e).concat(l,". Pick a different size/color or change the print provider."),{autoClose:8e3})}else O.Am.info("Printify no longer offers ".concat(M," for this product â pick a different size/color or change the print provider."),{autoClose:1e4})}else O.Am.info("Printify no longer offers ".concat(M," for this product â pick a different size/color or change the print provider."),{autoClose:1e4})}else if("NO_FILE_ASSIGNMENTS"===l)O.Am.info("Attach at least one design file to this product before publishing.");else if("ALREADY_PUBLISHED"===l){let l=null==e?void 0:null===(_=e.data)||void 0===_?void 0:_.printify_product_id;l&&O.Am.info("Already published (Printify id: ".concat(l,")"))}else if("ASSET_FILE_MISSING_URL"===l)O.Am.info("Design file is still processing â try again in a moment.");else if("MISSING_PROVIDER_REFS"===l||"POD_PRODUCT_MISSING_PRINT_AREAS"===l)O.Am.info("This product is missing Printify metadata â re-add it from the product catalog.");else if("TOO_MANY_VARIANTS"===l){let l=function(){let{details:e,hasServerMessage:l,draftLinked:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return(null==e?void 0:e.split_count_exceeded)===!0?l?null:(0,tz.YS)(e):(null==e?void 0:e.enabled_count)!=null&&(null==e?void 0:e.max_allowed)!=null?"Currently ".concat(e.enabled_count," variants enabled, Printify allows up to ").concat(e.max_allowed,". Disable ").concat(e.excess," more in the variant matrix or in the publish dialog before retrying.").concat(t?" Note: automatic Printify routing (drafts) can split large listings; this cap applies only to publishing into My Products.":""):null}({details:null==e?void 0:null===(w=e.data)||void 0===w?void 0:w.details,hasServerMessage:!!(t||(null==e?void 0:e.message)),draftLinked:P});l&&O.Am.info(l)}else if("INVALID_VARIANT_EXTERNAL_IDS"===l){let l=null==e?void 0:null===(k=e.data)||void 0===k?void 0:null===(S=k.details)||void 0===S?void 0:S.invalid_variants;if(Array.isArray(l)&&l.length){let e=new Map;for(let t of l)e.has(t.color_label)||e.set(t.color_label,[]),t.size_label&&e.get(t.color_label).push(t.size_label);let t=[...e.entries()].map(e=>{let[l,t]=e;return t.length?"".concat(l," (").concat(t.join(", "),")"):l}).join("; ");O.Am.info("Disable these in the variant matrix: ".concat(t,". They aren't offered by the current print provider."))}}console.error("[publishPodProductToPrintify]",{code:l,body:e,err:i})}finally{try{Object.keys(E).length>0&&(await (0,eI.Y$)(t,I,E),null==o||o(I,E))}catch(e){z&&O.Am.info("Couldn't restore previous toggle state. Re-toggle variants if needed.")}ec(null)}},[t,l,o,P]);let eV=eb.length,eK=ej.length,eq=(0,a.useMemo)(()=>{let e=new Map;return eb.forEach(l=>{e.has(l.label)||e.set(l.label,{label:l.label})}),[...e.values()]},[eb]),eG=(0,a.useMemo)(()=>{let e=new Map;return ej.forEach(l=>{e.has(l.label)||e.set(l.label,{label:l.label})}),[...e.values()]},[ej]),eY=eZ>=1&&eq.length>1,eQ=eZ>=2&&eG.length>1,e$=(0,a.useMemo)(()=>ez.filter(e=>e.productEnabled),[ez]),eX=(0,a.useMemo)(()=>e$.filter(eO),[e$,eO]),eJ=e$.length,e0=eX.length,e1=eF.length,e5=eX.length>10,e2=I?eX:eX.slice(0,10),e3=e5&&!I,e4=(0,a.useMemo)(()=>e$.reduce((e,l)=>{var t,n;let i=null!==(t=h[l.cellKey])&&void 0!==t?t:{},r=null===(n=i.userEnabled)||void 0===n||n,o=!l.hasMatrixEntry,a=l.hasMatrixEntry&&!1===l.is_available,d=parseFloat(i.price);return o||a||!r||d>0?e:e+1},0),[e$,h]),e7=[0===eZ?{key:"product",label:"Product"}:{key:"axis-1",label:e_},{key:"axis-2",label:ew,hidden:eZ<2},{key:"sku",label:"SKU"},{key:"price",label:"Price"},{key:"cost",label:"Cost"},{key:"margin",label:"Margin"},{key:"qty",label:"Qty"},{key:"on",label:"On",align:"center"},{key:"create",label:"Create",align:"center",hidden:!0}];if(0===l.length)return null;let e6=eZ>=1&&0===eb.length?{title:"Every option is switched off",description:"No ".concat(t$(null!=e_?e_:"option")," are selected for this product. Turn at least one back on in the product card above to price it.")}:eZ>=2&&0===ej.length?{title:"No option pairs to price",description:"This product's second option has no values to pair with, so no variants could be built. Re-
1add it from the product catalog."}:ez.length>0?{title:"No variants are linked to this product",description:"These options don't belong to any product in this listing. Re-add the product from the catalog to price them."}:{title:"No variants to show",description:"This product's options couldn't be matched to any Printify variants. Re-add it from the product catalog, or pick a different print provider."};if(0===ez.length)return(0,n.jsx)(y.Z,{children:(0,n.jsx)(lI.Z,{size:"sm",icon:(0,n.jsx)(lk.Z,{}),title:e6.title,description:e6.description})});let e8=(e,l,t)=>(null==e?void 0:e.truncated)&&!t?j===e.label?(0,n.jsx)(y.Z,{component:"input",value:S,maxLength:20,autoFocus:!0,onChange:e=>k(e.target.value),onBlur:()=>{S.trim()&&m(l=>({...l,[e.label]:S.trim()})),w(null)},onKeyDown:l=>{"Enter"===l.key&&(S.trim()&&m(l=>({...l,[e.label]:S.trim()})),w(null)),"Escape"===l.key&&w(null)},sx:{width:90,fontSize:11,px:.5,py:.25,border:"1.5px solid var(--lv-brand)",borderRadius:"4px",bgcolor:"var(--lv-bg-card)",color:"var(--lv-text-primary)",outline:"none",fontFamily:"inherit"}}):(0,n.jsx)(y.Z,{onClick:()=>{w(e.label),k(l)},title:"Label truncated â click to override",sx:{cursor:"pointer",color:"var(--lv-text-secondary)",display:"flex",alignItems:"center","&:hover":{color:"var(--lv-brand)"}},children:(0,n.jsx)(tZ.Z,{size:11})}):null;return(0,n.jsxs)(y.Z,{children:[eM&&(0,n.jsx)(t2,{condition:ey,v1Name:e_,v2Name:ew}),ep&&(0,n.jsxs)(y.Z,{sx:{mb:1,p:1,borderRadius:1,bgcolor:"var(--lv-bg-elevated)",border:"1px solid var(--lv-border-default)"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)",mb:.5},children:"queued"===ep.status?"Refreshing variant availability from Printifyâ¦":"Refreshing variant availability â ".concat(ep.progress,"%")}),"running"===ep.status&&ep.progress>0?(0,n.jsx)(tC.Z,{progress:ep.progress/100,thickness:2,showPercent:!1,ariaLabel:"Refreshing variant availability"}):(0,n.jsx)(tk.Z,{variant:"indeterminate",sx:{height:4,borderRadius:2}})]}),(0,n.jsx)(l5,{targetCount:e1,onApply:(e,l)=>{var t;let n=null!==(t=t5[e])&&void 0!==t?t:"sku",i="sku"===n;if(i&&P)return 0;let r=[];if(eF.forEach(e=>{var t;let o=h[e.cellKey];if(!o)return;let a=l(String(null!==(t=o[n])&&void 0!==t?t:""));if(null==a)return;let d=i?(0,tE.Z0)(a):a;i&&""===d||r.push({row:e,value:d,previous:o})}),!r.length)return 0;f(e=>{let l={...e};return r.forEach(e=>{let{row:t,value:i}=e;l[t.cellKey]&&(l[t.cellKey]={...l[t.cellKey],[n]:i,..."sku"===n?{skuOverridden:!0}:{}})}),l});let a=eW(r.map(e=>{let{row:l,value:t}=e;if(!l.podProductId||null==l.matrixKey)return null;let i=function(e,l){if("price"===e){let e=Math.round(100*parseFloat(l));return isNaN(e)?null:{price_cents:e}}if("qty"===e){let e=parseInt(l,10);return isNaN(e)?null:{quantity:e}}return{sku:l}}(n,t);return i?{podProductId:l.podProductId,matKey:l.matrixKey,patch:i}:null}).filter(Boolean));return i&&a.then(e=>{let{skuRejections:l}=e;if(!(null==l?void 0:l.length))return;let t=new Set(l.map(e=>String(e.podProductId))),n=r.filter(e=>{let{row:l}=e;return t.has(String(l.podProductId))});if(0===n.length)return;f(e=>{let l={...e};return n.forEach(e=>{let{row:t,previous:n}=e;l[t.cellKey]&&null!=n&&(l[t.cellKey]={...l[t.cellKey],sku:n.sku,skuOverridden:n.skuOverridden})}),l});let i={};n.forEach(e=>{var l,t;let{row:n,previous:r}=e;n.podProductId&&null!=n.matrixKey&&null!=r&&((null!==(t=i[l=n.podProductId])&&void 0!==t?t:i[l]={})[n.matrixKey]={sku:r.sku})}),Object.entries(i).forEach(e=>{let[l,t]=e;return null==o?void 0:o(l,t)})}),r.length},lockedProperties:P?t1:void 0,lockedReason:P?tE._1:void 0}),(0,n.jsx)(l4,{axes:[eY&&{key:"v1",name:e_,options:eq,selected:Y,onToggle:J},eQ&&{key:"v2",name:ew,options:eG,selected:$,onToggle:ee}].filter(Boolean),active:eL,onClear:el}),(0,n.jsx)(lq,{summary:eL?lK(e0,eJ):eM?"".concat(eJ," variant").concat(1!==eJ?"s":""," across ").concat(l.length," products"):eZ>=2?"".concat(eV," ").concat(t$(e_)," \xd7 ").concat(eK," ").concat(t$(ew)," = ").concat(eJ," variant").concat(1!==eJ?"s":""):1===eZ?"".concat(eV," ").concat(t$(e_)," = ").concat(eJ," variant").concat(1!==eJ?"s":""):"".concat(eJ," variant").concat(1!==eJ?"s":""),actions:[{key:"reset",label:eL?"Reset filtered prices":"Reset prices",onClick:()=>{let e=eF.map(e=>{let l=null!=e.cost_cents?e.cost_cents/100:null,t=null!==l&&l>0?(1.5*l).toFixed(2):"";return{...e,price:t}});f(l=>{let t={...l};
1return e.forEach(e=>{let{cellKey:l,price:n}=e;t[l]&&(t[l]={...t[l],price:n})}),t}),eW(e.filter(e=>e.podProductId&&null!=e.matrixKey&&""!==e.price).map(e=>({podProductId:e.podProductId,matKey:e.matrixKey,patch:{price_cents:Math.round(100*parseFloat(e.price))}})))}}]}),c&&(0,n.jsx)(L.Z,{sx:{mb:1,fontSize:12,color:"var(--lv-accent)"},children:"AI suggests prices for ".concat(c.coveredRows," of ").concat(c.sentRows," variations â accept in the AI panel to apply")}),i&&(0,n.jsxs)("div",{className:"flex items-start gap-1.5 mb-2 text-xs text-lv-text-tertiary",children:[(0,n.jsx)(lk.Z,{size:13,className:"mt-[1px] shrink-0"}),(0,n.jsx)("span",{children:"SKUs are auto-generated uniquely per listing for Bulk Create. Entering a custom SKU makes this preset single-listing only (not eligible for Bulk Create)."})]}),e4>0&&(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.75,mb:1.25,px:1.25,py:.875,borderRadius:"8px",border:"1px solid var(--lv-error-border)",bgcolor:"var(--lv-error-surface)"},children:[(0,n.jsx)(tP.Z,{size:14,style:{color:"var(--lv-error-strong)",flexShrink:0},"aria-hidden":!0}),(0,n.jsxs)(L.Z,{sx:{fontSize:12,fontWeight:500,color:"var(--lv-error-strong)"},children:[e4," variant",1!==e4?"s":""," need",1===e4?"s":""," a price",e5&&!I?" â some may be hidden; click âShow allâ to see them.":"."]})]}),(0,n.jsx)(lB,{columns:e7,rows:e2,totalCount:eX.length,expanded:I,onExpandChange:C,canCollapse:e5,isTruncated:e3,emptyState:eL?(0,n.jsx)(l7,{}):(0,n.jsx)(lI.Z,{size:"sm",icon:(0,n.jsx)(lk.Z,{}),title:e6.title,description:e6.description}),renderRow:(e,t)=>{var r,o,a,d,s,u,p,v,f,x,m,j,w;let{cellKey:S,v1:k,v2:I,productEnabled:C,hasMatrixEntry:Z,cost_cents:R,catalog_cost_cents:A,podProductId:E}=e,M=null!==(o=h[S])&&void 0!==o?o:{},z=E&&null!=e.matrixKey&&null!==(a=null==c?void 0:null===(r=c.byCellId)||void 0===r?void 0:r[(0,l6.W5)(E,e.matrixKey)])&&void 0!==a?a:null,O=null===(d=M.userEnabled)||void 0===d||d,F=!C,N=e3&&t===e2.length-1,W=C&&!Z,U=(0,tQ.Kh)(e,eZ),H=W&&!U,B=C&&Z&&!1===e.is_available,V=F||W||B,K=null!==(s=et[S])&&void 0!==s?s:R,q=null!=K?K/100:null,Y=parseFloat(M.price),Q=!V&&O&&!(Y>0),$=!P&&!V&&O,X=null!=h[S],J=(0,tE.Z0)(M.sku),ee=$&&X?(0,tE.dd)(M.sku,{requireNonEmpty:!i,duplicate:""!==J&&eT.has(J)}):null,el=isNaN(Y)||null===q?null:Y-q,en=null!==el&&Y>0?(el/Y*100).toFixed(0):null,ei=k?null!==(u=g[k.label])&&void 0!==u?u:k.label:null,eo=I?null!==(p=g[I.label])&&void 0!==p?p:I.label:null,ea=l.find(e=>e.podProductId===E);return(0,n.jsxs)(lw.Z,{sx:{opacity:F?.35:W||B?.5:O?1:.55,pointerEvents:F?"none":"auto","&:hover td":F||W||B?{}:{bgcolor:"var(--lv-bg-elevated)"}},children:[0===eZ?(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-primary)",whiteSpace:"nowrap"},children:t0(ea)})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.75},children:[(eZ>=2||eS===tQ.O4)&&(0,n.jsx)(tA.Z,{hex:k.hex,size:10,shape:"circle"}),(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-primary)",whiteSpace:"nowrap"},children:1===eZ?ei:k.label}),1===eZ&&e8(k,ei,F||N)]})}),eZ>=2&&(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-primary)",whiteSpace:"nowrap"},children:eo}),e8(I,eo,F||N)]})})]}),(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsx)(y.Z,{sx:{minWidth:90,maxWidth:220},children:H?(0,n.jsx)(L.Z,{sx:{fontSize:11,fontStyle:"italic",color:"var(--lv-text-disabled)",whiteSpace:"nowrap"},children:tQ.Ji}):U?(0,n.jsx)(_.Z,{title:tQ.Tm,placement:"top",children:(0,n.jsx)(L.Z,{sx:{fontSize:11,fontStyle:"italic",color:"var(--lv-text-disabled)",whiteSpace:"normal",cursor:"help"},children:tQ.yL})}):B?(0,n.jsx)(_.Z,{title:tJ,placement:"top",children:(0,n.jsx)(L.Z,{sx:{fontSize:11,fontStyle:"italic",color:"var(--lv-text-disabled)",whiteSpace:"nowrap",cursor:"help"},children:"Provider dropped this variant"})}):P?(0,n.jsx)(_.Z,{title:tE._1,placement:"top",children:(0,n.jsxs)(y.Z,{"aria-label":(0,tE.ZQ)(M.sku),className:"rounded-lv-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lv-focus","data-testid":tE.eD,onClick:()=>D(S),onKeyDown:e=>T(e,S),tabIndex:0,sx:{display:"flex",alignItems:"center",gap:.5,cursor:"not-allowed"},children:[(0,n.jsx)(lR,{value:null!==(v=M.sku)&&void 0!==v?v:"",label:"SKU",disabled:!0}),(0,n.jsx)(tR.Z,{size:14,role:"img","aria-label":tE.Cw,style:{color:"var(--lv-text-tertiary)",flexShrink:0}})]})}):i||""===String(null!==(f=e.stored_sku)&&void 0!==f?f:"")?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(lR,{value:null!==(m=M.sku)&&void 0!==m?m:"",label:"SKU",disabled:F||!O,error:!!ee,onCommit:l=>eN(S,"sku",l,e)}),ee&&(0,n.jsx)(L.Z,{sx:{mt:.5,fontSize:11,color:"var(--lv-error-strong)",whiteSpace:"normal"},children:ee})]}):(0,n.jsx)(_.Z,{title:tE.wy,placement:"top",children:(0,n.jsx)(y.Z,{"aria-label":tE.wy,className:"rounded-lv-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lv-focus","data-testid":tE.ll,tabIndex:0,sx:{display:"flex",alignItems:"center",cursor:"not-allowed"},children:(0,n.jsx)(lR,{value:null!==(x=M.sku)&&void 0!==x?x:"",label:"SKU",disabled:!0})})})})}),(0,n.jsx)(lS.Z,{sx:{...lT},children:(0,n.jsxs)(y.Z,{sx:{minWidth:64},children:[(0,n.jsx)(lR,{value:null!==(j=M.price)&&void 0!==j?j:"",label:"Price",type:"number",prefix:"$",disabled:V,error:Q,onCommit:l=>eN(S,"price",l,e)}),null!=z&&(0,n.jsx)(L.Z,{sx:{mt:.5,fontSize:11,color:"var(--lv-accent)"},children:"AI: $".concat(z)})]})}),(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5,whiteSpace:"nowrap"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)"},children:null!==q?tX(q):"â"}),null!=A&&null!=K&&A!==K&&!F&&!B&&(0,n.jsx)(_.Z,{title:"Provider's cost changed from ".concat(tX(K/100)," to ").concat(tX(A/100),". Click to accept â your margin will recalculate."),placement:"top",children:(0,n.jsxs)(y.Z,{component:"button",type:"button",onClick:()=>er({type:"one",cellKey:S,podProductId:E,matKey:e.matrixKey,oldCost:K,newCost:A,label:(0,tQ.j$)(e)||t0(ea)}),sx:{display:"inline-flex",alignItems:"center",gap:.25,fontSize:11,fontWeight:500,color:"var(--lv-warning, #c97a18)",bgcolor:"transparent",border:"1px solid var(--lv-warning, #c97a18)",borderRadius:"4px",px:.5,py:.125,cursor:"pointer",fontFamily:"inherit","&:hover":{bgcolor:"rgba(201,122,24,0.08)"}},children:[(0,n.jsx)(b.Z,{size:10}),tX(A/100)]})})]})}),(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsx)(L.Z,{sx:{fontSize:12,whiteSpace:"nowrap",color:null===el?"var(--lv-text-disabled)":el<0?"#ef4444":"var(--lv-text-primary)"},children:null!==el?"".concat(tX(el)).concat(null!==en?" (".concat(en,"%)"):""):"â"})}),(0,n.jsx)(lS.Z,{sx:lT,children:(0,n.jsx)(y.Z,{sx:{minWidth:52},children:(0,n.jsx)(lR,{value:null!==(w=M.qty)&&void 0!==w?w:"999",label:"Quantity",type:"number",disabled:V,onCommit:l=>eN(S,"qty",l,e)})})}),(0,n.jsx)(lS.Z,{sx:{...lT,textAlign:"center"},children:B?(0,n.jsx)(lM,{checked:!1,disabled:!0,label:"On",tooltip:tJ}):(0,n.jsx)(lM,{checked:!V&&O,disabled:V,label:"On",onChange:l=>{G({cellKey:S,podProductId:e.podProductId,matKey:e.matrixKey,enabled:l})}})}),!1]},S)}}),(0,n.jsx)(tT,{open:null!=E,kind:"variant",assessment:null==E?void 0:E.assessment,proposedKeys:null==E?void 0:E.proposedKeys,splitUnsupported:null==E?void 0:E.splitUnsupported,loading:null==E?void 0:E.loading,error:null==E?void 0:E.error,onClose:()=>{(null==E?void 0:E.loading)||M(null)},onConfirm:()=>q(E)}),(0,n.jsx)(F.Z,{open:!!ei,onClose:()=>!ed&&er(null),onConfirm:eB,title:"Update cost",confirmText:"Update cost",loading:ed,children:ei&&(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:13,color:"var(--lv-text-secondary)"},children:["The provider's cost for"," ",(0,n.jsx)(y.Z,{component:"span",sx:{color:"var(--lv-text-primary)",fontWeight:500},children:ei.label})," ","has changed. Your margin will recalculate at the current price."]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",gap:2,fontSize:13},children:[(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)"},children:"Current cost"}),(0,n.jsx)(L.Z,{sx:{fontSize:13,color:"var(--lv-text-primary)",fontWeight:500},children:tX(ei.oldCost/100)})]}),(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)"},children:"New cost"}),(0,n.jsx)(L.Z,{sx:{fontSize:13,color:"var(--lv-warning, #c97a18)",fontWeight:500},children:tX(ei.newCost/100)})]})]})]})}),tN.gp&&(0,n.jsx)(tq,{open:null!=eo,onClose:()=>ea(null),variant:eo,listingId:t})]})}let t4="Printify Choice",t7=[{value:"popular",label:"Popular"},{value:"price_asc",label:"Price: Low â High"},{value:"price_desc",label:"Price: High â Low"},{value:"name_az",label:"Name A â Z"}],t6=[{value:"all",label:"All prices"},{value:"0-1500",label:"Under $15"},{value:"1500-3000",label:"$15 â $30"},{value:"3000+",label:"$30+"}];function t8(e){var l;let t=function(e){let l=Array.isArray(null==e?void 0:e.shipping_summary)?e.shipping_summary:[],t=l.map(e=>e.estimated_days_min).filter(e=>null!=e),n=l.map(e=>e.estimated_days_max).filter(e=>null!=e);if(t.length||n.length){let e=t.length?Math.min(...t):null,l=n.length?Math.max(...n):null;return{min:null!=e?e:l,max:null!=l?l:e}}return(null==e?void 0:e.avg_production_days)!=null?{min:e.avg_production_days,max:e.avg_production_days}:null}(e);if(!t)return null;if(null!=t.min&&null!=t.max&&t.min!==t.max)return"~".concat(t.min,"â").concat(t.max," days");let n=null!==(l=t.min)&&void 0!==l?l:t.max;return"~".concat(n," ").concat(1===n?"day":"days")}function t9(e){var l,t,i,r,o,a;let d=[];(null===(l=e.supplier)||void 0===l?void 0:l.name)&&d.push(["Supplier",e.supplier.name]);let s=null!==(a=null!==(o=null===(t=e.provider)||void 0===t?void 0:t.name)&&void 0!==o?o:null===(i=e.print_provider)||void 0===i?void 0:i.name)&&void 0!==a?a:null;s&&d.push(["Print provider",s]),(null===(r=e.category)||void 0===r?void 0:r.name)&&d.push(["Category",e.category.name]),e.available_colors_count>0&&d.push(["Colors","".concat(e.available_colors_count)]),e.size_range&&d.push(["Sizes",e.size_range]);let u=t8(e);if(u&&d.push(["Delivery",u]),e.variant_count&&d.push(["Variants","".concat(e.variant_count)]),Array.isArray(e.print_areas)&&e.print_areas.length>0){let l=e.print_areas.map(e=>
1"string"==typeof e?e:null==e?void 0:e.name).filter(Boolean);l.length>0&&d.push(["Print areas",l.join(", ")])}return 0===d.length?null:(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.5,p:.25,minWidth:180},children:d.map(e=>{let[l,t]=e;return(0,n.jsxs)(y.Z,{sx:{display:"flex",justifyContent:"space-between",gap:2},children:[(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-chart-tooltip-label)"},children:l}),(0,n.jsx)(L.Z,{sx:{fontFamily:ei._$.metadata,fontSize:11,fontWeight:500,color:"var(--lv-chart-tooltip-text)",textAlign:"right"},children:t})]},l)})})}function ne(e){var l,t;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=null==e?void 0:e.print_areas;if(!Array.isArray(i)||0===i.length)return null;let r=(e,l)=>Number.isFinite(Number(e))&&Number(e)>0?parseFloat((Number(e)/l).toFixed(2)):null,o=null!==(t=null!==(l=null==e?void 0:e.external_id)&&void 0!==l?l:null==e?void 0:e.id)&&void 0!==t?t:null,a=i.map((e,l)=>{let t=Number(null==e?void 0:e.dpi)>0?Number(e.dpi):300,n=(null==e?void 0:e.width_in)!=null?e.width_in:r(null==e?void 0:e.width_px,t),i=(null==e?void 0:e.height_in)!=null?e.height_in:r(null==e?void 0:e.height_px,t);return{...e,id:"pa_".concat(l+1),name:(null==e?void 0:e.name)||(null==e?void 0:e.position)||"area_".concat(l+1),width_in:n,height_in:i,dpi:t,geometry_source:"provider",...null!=o&&{provider_external_id:o}}});if(!Array.isArray(n)||0===n.length)return a;let d=new Map;a.forEach(e=>{let l=(0,eP.U2)(e.name);l&&!d.has(l)&&d.set(l,e)});let s=n.map((e,l)=>{var t,n,i,r;let a=null!==(t=d.get((0,eP.U2)(null==e?void 0:e.name)))&&void 0!==t?t:d.get((0,eP.U2)(null==e?void 0:e.position));return a?(d.delete((0,eP.U2)(a.name)),{...e,id:null!==(n=null==e?void 0:e.id)&&void 0!==n?n:"pa_".concat(l+1),width_in:a.width_in,height_in:a.height_in,width_px:null!==(i=a.width_px)&&void 0!==i?i:null==e?void 0:e.width_px,height_px:null!==(r=a.height_px)&&void 0!==r?r:null==e?void 0:e.height_px,dpi:a.dpi,geometry_source:"provider",...null!=o&&{provider_external_id:o}}):e}),u=a.filter(e=>d.get((0,eP.U2)(e.name))===e).map((e,l)=>({...e,id:"pa_".concat(s.length+l+1)}));return[...s,...u]}function nl(e){return"string"==typeof(null==e?void 0:e.name)&&e.name.trim().toLowerCase()===t4.toLowerCase()}let nt=e=>null==e?"":String(e).trim().toLowerCase();function nn(e){var l,t,i,r,o,d;let{product:s,onConfirm:u,initialSelection:c=null,initialVariationId:p=null,existingPodProducts:v=[],editContext:h=null}=e,f=null!==(t=s.variations)&&void 0!==t?t:[],[x,g]=(0,a.useState)(()=>{if(c){let e={};return f.forEach(l=>{e[l.id]={},l.options.forEach(t=>{var n,i;e[l.id][t.id]=null!==(i=null===(n=c[l.id])||void 0===n?void 0:n[t.id])&&void 0!==i?i:!l.is_design_variable})}),e}let e={};return f.forEach(l=>{e[l.id]={},l.options.forEach(t=>{e[l.id][t.id]=!l.is_design_variable})}),e}),[m,b]=(0,a.useState)(p&&f.some(e=>e.id===p)?p:null!==(i=null===(l=f[0])||void 0===l?void 0:l.id)&&void 0!==i?i:""),[j,S]=(0,a.useState)({}),k=f.find(e=>e.id===m),I=null!==(r=j[m])&&void 0!==r?r:"",C=(0,a.useMemo)(()=>k?k.options.filter(e=>e.label.toLowerCase().includes(I.toLowerCase())):[],[k,I]),Z=(e,l,t)=>g(n=>({...n,[e]:{...n[e],[l]:t}})),P=(e,l)=>g(t=>{let n={...t[e]};return Object.keys(n).forEach(e=>{n[e]=l}),{...t,[e]:n}}),R=(0,a.useMemo)(()=>{let e={};return f.forEach(l=>{var t;e[l.id]=Object.values(null!==(t=x[l.id])&&void 0!==t?t:{}).filter(Boolean).length}),e},[x,f]),A=!!k&&C.every(e=>{var l;return null===(l=x[m])||void 0===l?void 0:l[e.id]}),E=(0,a.useMemo)(()=>f.reduce((e,l)=>{var t;return e*(Object.values(null!==(t=x[l.id])&&void 0!==t?t:{}).filter(Boolean).length||1)},1),[x,f]),M=(0,a.useMemo)(()=>f.filter(e=>{var l;return(null!==(l=R[e.id])&&void 0!==l?l:0)>0}).map(e=>"".concat(R[e.id]," ").concat(e.label.toLowerCase())).join(" \xd7 "),[f,R]),z=(0,a.useMemo)(()=>{let e=new Set;return v.forEach(l=>{var t;let{product:n}=l;(null!==(t=n.variations)&&void 0!==t?t:[]).forEach(l=>{l.id.startsWith("_product_")||e.add(l.id)})}),e},[v]),D=(0,a.useMemo)(()=>f.filter(e=>!z.has(e.id)).map(e=>e.label),[f,z]),O=(0,a.useMemo)(()=>{let e=new Set(z);return f.forEach(l=>e.add(l.id)),e.size},[f,z]),F=v.length>0&&O>2,{projectedAxisCounts:T,mergedAxisCounts:N,projectedAxisNames:W,pendingAxisOffset:U}=(0,a.useMemo)(()=>{var e,l,t,n,i,r,o;let a=null!==(t=null==h?void 0:h.podProductId)&&void 0!==t?t:"_pending",d=(null!==(n=s.variations)&&void 0!==n?n:[]).length,u={product:s,selection:x,rawVariants:null!==(i=s.rawVariants)&&void 0!==i?i:[],podProductId:a,prefixes:null!==(r=null==h?void 0:h.prefixes)&&void 0!==r?r:{},naturalVariationCount:d},c=h?[...v,u]:(0,eZ.yo)(v,u),p=c[c.length-1],f=Math.max(0,(null!==(o=null==p?void 0:null===(l=p.product)||void 0===l?void 0:null===(e=l.variations)||void 0===e?void 0:e.length)&&void 0!==o?o:0)-d),g=(0,tY.aI)(c),{v1Options:m,v2Options:y,v1Name:b,v2Name:j}=(0,tQ.Aq)(c,g),_=[m,y].map(e=>{let l=new Set,t=new Set;
1return e.forEach(e=>{var n;return((null===(n=e.source_refs)||void 0===n?void 0:n.some(e=>e.podProductId===a))?l:t).add(e.label)}),{all:new Set([...l,...t]),pending:l,prior:t}});return{projectedAxisCounts:_.map(e=>e.all.size),mergedAxisCounts:_.map(e=>[...e.pending].filter(l=>e.prior.has(l)).length),projectedAxisNames:[b,j],pendingAxisOffset:f}},[v,s,x,h]),{mergeParts:H,mergeVerb:B}=(0,a.useMemo)(()=>{let e=W.map((e,l)=>{var t;return{name:e,count:null!==(t=N[l])&&void 0!==t?t:0}}).filter(e=>{let{name:l,count:t}=e;return l&&t>0});return{mergeParts:e.map(e=>{let{name:l,count:t}=e,n=l.toLowerCase(),i=n.endsWith("s")?n.slice(0,-1):n;return"".concat(t," ").concat(1===t?i:"".concat(i,"s"))}),mergeVerb:1===e.length&&1===e[0].count?"matches":"match"}},[W,N]),V=Math.max(T[0],1)*Math.max(T[1],1),K=T.some(e=>e>70),{maxProductsVaryByAll:q}=(0,te.G)(),G=null!=q?q:400,Y=V>G,Q=(0,a.useMemo)(()=>{let e=[];return K&&e.push("A variation exceeds the ".concat(70,"-option limit")),Y&&e.push("Listing total exceeds the ".concat(G,"-option limit")),e},[K,Y]),$=(0,a.useMemo)(()=>{var e;return k&&null!==(e=T[f.findIndex(e=>e.id===m)+U])&&void 0!==e?e:0},[k,m,f,T,U]),X=f.every(e=>{var l;return(null!==(l=R[e.id])&&void 0!==l?l:0)>=1})&&!F&&!K&&!Y;return 0===f.length?(0,n.jsxs)(y.Z,{sx:{textAlign:"center",py:3},children:[(0,n.jsx)(L.Z,{sx:{fontSize:13,color:ei.oR.textSecondary,mb:2},children:"No variation options available for this product."}),(0,n.jsx)(y.Z,{sx:{display:"flex",justifyContent:"flex-end"},children:(0,n.jsx)(w.f,{text:"Add Product to Listing",color:"purple",width:"auto",onClick:()=>u(s,{})})})]}):(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(y.Z,{sx:{mb:1.5},children:(0,n.jsx)(t_.Z,{options:f.map(e=>({value:e.id,label:e.label})),value:m,onChange:b,activeColor:ei.oR.textPrimary})}),(0,n.jsx)(y.Z,{sx:{mb:1.5}
1,children:(0,n.jsx)(J.Z,{value:I,onChange:e=>S(l=>({...l,[m]:e})),placeholder:"Search options",size:"sm",fullWidth:!0})}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:.5},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:ei.oR.textSecondary},children:[null!==(o=R[m])&&void 0!==o?o:0," of ",null!==(d=null==k?void 0:k.options.length)&&void 0!==d?d:0," selected"]}),(0,n.jsx)(L.Z,{onClick:()=>P(m,!A),sx:{fontSize:12,fontWeight:500,color:ei.oR.selected,cursor:"pointer",userSelect:"none","&:hover":{opacity:.8}},children:A?"Deselect all":"Select all"})]}),k&&(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:$>70?ei.oR.warning:ei.oR.textTertiary,mb:1},children:["Using ",$," of ",70," allowed ",k.label.toLowerCase()," options"]}),(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.25,maxHeight:260,overflowY:"auto",p:.75,border:"1px solid ".concat(ei.oR.borderDefault),borderRadius:ei.PY.lg,bgcolor:ei.oR.bgCard,scrollbarWidth:"thin",scrollbarColor:"".concat(ei.oR.borderStrong," transparent"),"&::-webkit-scrollbar":{width:6},"&::-webkit-scrollbar-track":{background:"transparent"},"&::-webkit-scrollbar-thumb":{borderRadius:ei.PY.sm,backgroundColor:ei.oR.borderStrong}},children:C.map(e=>{var l,t;let i=null!==(t=null===(l=x[m])||void 0===l?void 0:l[e.id])&&void 0!==t&&t,r=$>=70&&!i,o=V>=G&&!i,a=r||o,d=r?"Etsy limit reached (".concat(70," options per variation)"):o?"Etsy limit reached (".concat(G," total options)"):"";return(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1.5,py:.75,px:1,borderRadius:ei.PY.md,"&:hover":{bgcolor:ei.oR.bgHover}},children:[(null==k?void 0:k.is_design_variable)&&e.hex&&(0,n.jsx)(y.Z,{sx:{width:16,height:16,borderRadius:"50%",bgcolor:e.hex,border:"1px solid ".concat(ei.oR.borderDefault),flexShrink:0}}),(0,n.jsx)(L.Z,{sx:{flex:1,fontSize:13,color:ei.oR.textPrimary,opacity:i?1:.55},children:e.label}),(0,n.jsx)(_.Z,{title:a?d:"",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{sx:{opacity:a?.4:1,pointerEvents:a?"none":"auto"},children:(0,n.jsx)(lC.Z,{checked:i,onChange:l=>Z(m,e.id,l)})})})]},e.id)})}),F&&(0,n.jsx)(y.Z,{sx:{mt:1.5,p:1.25,borderRadius:ei.PY.md,bgcolor:ei.oR.warningBg,border:"1px solid ".concat(ei.oR.warningBg)},children:(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:ei.oR.warning},children:["This product adds a â",D.join(", "),"â variation. Etsy only supports 2 variations per listing."]})}),Q.length>0&&(0,n.jsx)(y.Z,{sx:{mt:1.5,p:1.25,borderRadius:ei.PY.md,bgcolor:ei.oR.warningBg,border:"1px solid ".concat(ei.oR.warningBg)},children:Q.map((e,l)=>(0,n.jsx)(L.Z,{sx:{fontSize:12,color:ei.oR.warning},children:e},l))}),(0,n.jsxs)(y.Z,{sx:{mt:1.5,p:1.25,borderRadius:ei.PY.md,bgcolor:ei.oR.bgElevated},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,color:ei.oR.textSecondary},children:M?"This will create ".concat(E," variant").concat(1!==E?"s":""," (").concat(M,")"):"Select at least 1 option per variation"}),M&&v.length>0&&H.length>0&&(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:ei.oR.textTertiary,mt:.5},children:[H.join(" and ")," ",B," options already in this listing and will merge."]}),(v.length>0||E>0)&&(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:Y?ei.oR.warning:ei.oR.textTertiary,mt:.5,fontWeight:Y?600:400},children:["Listing total: ",V," / ",G," options",v.length>0&&E>0?" across ".concat(v.length+1," products"):""]})]}),!X&&(0,n.jsx)(y.Z,{sx:{mt:1},children:f.map(e=>{var l;return(null!==(l=R[e.id])&&void 0!==l?l:0)===0?(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:ei.oR.textSecondary},children:["Select at least 1 ",e.label.toLowerCase()]},e.id):null})}),(0,n.jsx)(y.Z,{sx:{mt:2,display:"flex",justifyContent:"flex-end"},children:(0,n.jsx)(w.f,{text:"Add Product to Listing",color:"purple",width:"auto",className:"whitespace-nowrap",disabled:!X,onClick:()=>u(s,x)})})]})}function ni(e){var l,t;let{onSelectProduct:i,existingPodProducts:r=[]}=e,[o,d]=(0,a.useState)(""),[s,u]=(0,a.useState)("all"),[c,p]=(0,a.useState)("all"),[v,h]=(0,a.useState)("all"),[f,x]=(0,a.useState)("popular"),[g,m]=(0,a.useState)([]),[b,j]=(0,a.useState)({page:1,total:0,total_pages:1}),[S,k]=(0,a.useState)({suppliers:[],categories:[]}),[I,C]=(0,a.useState)(!1),[Z,P]=(0,a.useState)(!1),R=(0,a.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,l={page:e,limit:24,sort:f,search:o};if("all"!==s&&(l.supplier=s),"all"!==c&&(l.category=c),"all"!==v){let[e,t]=v.split("-");e&&(l.price_min=parseInt(e)),t&&!v.endsWith("+")&&(l.price_max=parseInt(t))}return l},[s,c,v,f,o]),A=(0,a.useCallback)(async()=>{C(!0);try{var e,l,t,n;let i=await (0,tw.mk)(R(1));m(null!==(t=i.data)&&void 0!==t?t:[]),j(null!==(n=i.pagination)&&void 0!==n?n:{page:1,total:0,total_pages:1}),(null===(l=i.filters)||void 0===l?void 0:null===(e=l.suppliers)||void 0===e?void 0:e.length)&&k(i.filters)}finally{C(!1)}},[R]);(0,a.useEffect)(()=>{A()},[A]);let E=async()=>{let e=b.page+1;P(!0);try{var l;let t=await (0,tw.mk)(R(e));m(e=>{var l;return[...e,...null!==(l=t.data)&&void 0!==l?l:[]]}),j(null!==(l=t.pagination)&&void 0!==l?l:b)}finally{P(!1)}},M=b.page<b.total_pages,z=[{value:"all",label:"All suppliers"},...(null!==(l=S.suppliers)&&void 0!==l?l:[]).map(e=>({value:e.slug,label:e.name}))],D=[{value:"all",label:"All categories"},...(null!==(t=S.categories)&&void 0!==t?t:[]).map(e=>({value:e.slug,label:e.name}))],O=e=>{var l,t;let n=null===(l=e.price_range)||void 0===l?void 0:l.min_cents,i=null===(t=e.price_range)||void 0===t?void 0:t.max_cents;if(null==n&&null==i)return null;let r=e=>"$".concat((e/100).toFixed(2));return null!=n&&null!=i&&i!==n?"".concat(r(n)," â ").concat(r(i)):null!=n?"From ".concat(r(n)):"Up to ".concat(r(i))},F=e=>Array.isArray(e)&&0!==e.length?e.map(e=>e.toUpperCase()).join(" ⢠"):null;return(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(y.Z,{sx:{mb:1.5},children:(0,n.jsx)(J.Z,{value:o,onChange:e=>d(e),placeholder:"Search products...",size:"sm",fullWidth:!0,debounceMs:300})}),(0,n.jsxs)(y.Z,{sx:{display:"flex",gap:1,mb:2,flexWrap:"wrap",alignItems:"center"},children:[(0,n.jsx)(y.Z,{sx:{minWidth:120},children:(0,n.jsx)(X.Z,{value:s,onChange:e=>u(e.target.value),options:z})}),(0,n.jsx)(y.Z,{sx:{minWidth:140},children:(0,n.jsx)(X.Z,{value:c,onChange:e=>p(e.target.value),options:D})}),(0,n.jsx)(y.Z,{sx:{minWidth:120}
1,children:(0,n.jsx)(X.Z,{value:v,onChange:e=>h(e.target.value),options:t6})}),(0,n.jsx)(y.Z,{sx:{ml:"auto",minWidth:155},children:(0,n.jsx)(X.Z,{value:f,onChange:e=>x(e.target.value),options:t7})})]}),I?(0,n.jsx)(y.Z,{sx:{py:6,display:"flex",justifyContent:"center"},children:(0,n.jsx)(q.D8,{size:28,sx:{color:ei.oR.selected}})}):0===g.length?(0,n.jsx)(y.Z,{sx:{py:6,textAlign:"center"},children:(0,n.jsx)(L.Z,{sx:{fontSize:13,color:ei.oR.textSecondary},children:"No products match your filters."})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(y.Z,{sx:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:1.25},children:g.map(e=>{var l;let t=O(e),o=F(e.delivery_regions),a=t9(e),d=function(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"USD";if(!Array.isArray(e)||0===e.length)return null;let t=e=>null==e?null:"$".concat((e/100).toFixed(2)),i=(e,l)=>null==e&&null==l?null:null!=e&&null!=l&&e!==l?"".concat(e,"â").concat(l," days"):"".concat(null!=e?e:l," days");return(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.75,p:.25,minWidth:200},children:[e.map(e=>{var l;let r=t(e.first_item_cost_cents),o=t(e.additional_item_cost_cents),a=i(e.estimated_days_min,e.estimated_days_max),d=r&&o?"".concat(r," first \xb7 ").concat(o," each"):r||o||null;return(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.25},children:[(0,n.jsx)(L.Z,{sx:{fontSize:11,fontWeight:600,color:"var(--lv-chart-tooltip-text)"},children:null===(l=e.region)||void 0===l?void 0:l.toUpperCase()}),d&&(0,n.jsx)(L.Z,{sx:{fontFamily:ei._$.metadata,fontSize:11,color:"var(--lv-chart-tooltip-text)",opacity:.85},children:d}),a&&(0,n.jsx)(L.Z,{sx:{fontFamily:ei._$.metadata,fontSize:11,color:"var(--lv-chart-tooltip-label)"},children:a})]},e.region)}),e.some(e=>e.currency&&e.currency!==l)&&(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-chart-tooltip-label)",opacity:.8,mt:.25},children:"Costs shown in provider currency."})]})}(e.shipping_summary,null===(l=e.price_range)||void 0===l?void 0:l.currency),s=r.some(l=>{var t,n;return(null===(t=l.product)||void 0===t?void 0:t.id)===e.id||(null===(n=l.product)||void 0===n?void 0:n.slug)===e.slug});return(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",p:1,borderRadius:ei.PY.lg,border:"1px solid ".concat(ei.oR.borderDefault),bgcolor:ei.oR.bgCard,transition:"border-color 0.15s","&:hover":{borderColor:ei.oR.borderStrong},"&:hover .title-info-icon":{opacity:.65},"&:hover .title-text":{textDecoration:"underline",textDecorationStyle:"dotted",textDecorationColor:ei.oR.textTertiary,textUnderlineOffset:"3px"},"&:hover .ships-line":{textDecoration:"underline",textDecorationStyle:"dotted",textDecorationColor:ei.oR.textTertiary,textUnderlineOffset:"3px"}},children:[(0,n.jsx)(tS.ZP,{product:e,tooltipContent:a,metaLabel:t}),o?(0,n.jsx)(_.Z,{title:d,placement:"top",disableInteractive:!0,maxWidth:260,children:(0,n.jsxs)(L.Z,{className:d?"ships-line":void 0,sx:{fontFamily:ei._$.metadata,fontSize:10,color:ei.oR.textTertiary,mb:1,lineHeight:1.4,width:"fit-content",cursor:d?"help":"default"},children:["Ships from ",o]})}):(0,n.jsx)(y.Z,{sx:{mb:1}}),(0,n.jsx)(w.f,{text:s?"Selected":"Select",color:s?"no-background":"white",width:"auto",className:"whitespace-nowrap",disabled:s,onClick:()=>!s&&i(e)})]},e.id)})}),M&&(0,n.jsx)(y.Z,{sx:{mt:2,display:"flex",justifyContent:"center"},children:Z?(0,n.jsx)(q.D8,{size:22,sx:{color:ei.oR.selected}}):(0,n.jsx)(w.f,{text:"Load More (".concat(b.total-g.length," remaining)"),color:"white",width:"auto",className:"whitespace-nowrap",onClick:E})})]})]})}function nr(e){let{providers:l,selectedProvider:t,onSelect:i,onConfirm:r,confirmText:o="Continue",helperText:a="Choose the print provider that will fulfil orders for this product."}=e;return(0,n.jsxs)(y.Z,{sx:{p:2},children:[(0,n.jsx)(L.Z,{sx:{fontSize:13,color:ei.oR.textSecondary,mb:2},children:a}),(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1.5,mb:3},children:l.map(e=>{var l,r,o,a;let d=(null==t?void 0:t.id)===e.id,s=!1===e.is_active,u=function(e){let l=e.min_cost_cents,t=e.max_cost_cents;if(null==l&&null==t)return null;let n=e=>"$".concat((e/100).toFixed(2));return null!=l&&null!=t&&t!==l?"".concat(n(l)," â ").concat(n(t)):n(null!=l&&null!=t?l:null!=l?l:t)}(e);return(0,n.jsxs)(y.Z,{onClick:()=>!s&&i(e),sx:{border:"1.5px solid ".concat(d?ei.oR.selected:ei.oR.borderDefault),borderRadius:2,p:2,cursor:s?"not-allowed":"pointer",opacity:s?.5:1,backgroundColor:d?ei.oR.selectedLight:"transparent",transition:"border-color 0.15s, background-color 0.15s","&:hover":s?void 0:{borderColor:ei.oR.selected},display:"flex",alignItems:"center",gap:1.5},children:[(0,n.jsx)(tj,{supplier:"printify"}),(0,n.jsxs)(y.Z,{sx:{flex:1,minWidth:0},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1,flexWrap:"wrap"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:14,fontWeight:600,color:ei.oR.textPrimary},children:e.name}),e.is_default&&(0,n.jsx)(L.Z,{component:"span",sx:{fontSize:10,fontWeight:600,px:.75,py:.25,borderRadius:1,backgroundColor:ei.oR.selectedLight,color:ei.oR.selected,lineHeight:1.6},children:"Recommended"}),s&&(0,n.jsx)(_.Z,{title:"This provider's last catalog sync didn't return any variants â temporarily unavailable. Try again after the next sync.",placement:"top",disableInteractive:!0,children:(0,n.jsx)(L.Z,{component:"span",sx:{fontSize:10,fontWeight:600,px:.75,py:.25,borderRadius:1,backgroundColor:ei.oR.warningBg,color:ei.oR.warning,lineHeight:1.6,cursor:"help"},children:"Unavailable"})})]}),u&&(0,n.jsxs)(y.Z,{sx:{mt:.5},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:500,color:ei.oR.textPrimary,fontFamily:ei._$.metadata},children:u}),e.cost_note&&(0,n.jsx)(_.Z,{title:e.cost_note,placement:"top",disableInteractive:!0,maxWidth:320,children:(0,n.jsx)(L.Z,{sx:{fontSize:10,
1color:ei.oR.textTertiary,mt:.25,lineHeight:1.3,cursor:"help",textDecoration:"underline",textDecorationStyle:"dotted",textDecorationColor:ei.oR.textTertiary,textUnderlineOffset:"3px",width:"fit-content"},children:"catalog"===e.cost_source?"Catalog cost \xb7 why?":"Cost note"})})]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",gap:1.5,mt:.5,flexWrap:"wrap"},children:[(null===(l=e.location)||void 0===l?void 0:l.city)&&(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:ei.oR.textSecondary},children:["\uD83D\uDCCD ",e.location.city,", ",e.location.country]}),e.avg_production_days&&(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:ei.oR.textSecondary},children:["â± ",e.avg_production_days,"d production"]}),(()=>{let l=t8(e);return l?(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:ei.oR.textSecondary},children:["\uD83D\uDE9A Ships in ",l]}):null})(),(null===(r=e.colors)||void 0===r?void 0:r.length)>0&&(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:ei.oR.textSecondary},children:["\uD83C\uDFA8 ",e.colors.length," colors"]}),(null===(o=e.sizes)||void 0===o?void 0:o.length)>0&&(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:ei.oR.textSecondary},children:["\uD83D\uDCD0 ",e.sizes.length," sizes"]})]})]}),d&&(0,n.jsx)(y.Z,{sx:{width:18,height:18,borderRadius:"50%",backgroundColor:ei.oR.selected,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,n.jsx)("svg",{width:"10",height:"8",viewBox:"0 0 10 8",fill:"none",children:(0,n.jsx)("path",{d:"M1 4L3.5 6.5L9 1",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]},null!==(a=e.slug)&&void 0!==a?a:e.id)})}),(0,n.jsx)(w.f,{text:o,color:"purple",width:"100%",disabled:!t||!1===t.is_active,onClick:r})]})}function no(e){var l,t,i,r;let{onAddProduct:o,hasProducts:d=!1,disabled:s=!1,disabledReason:u=null,existingPodProducts:c=[],editTarget:p=null,onEditConfirm:v=null,mode:h=null,onChangeProvider:f=null,initialVariationId:x=null,open:g,onClose:m}=e,[b,j]=(0,a.useState)(!1),S=void 0!==g?g:b,k=()=>j(!1),[I,C]=(0,a.useState)("browse"),[Z,P]=(0,a.useState)(null),[R,A]=(0,a.useState)(null),[E,M]=(0,a.useState)([]),[z,D]=(0,a.useState)(null),[O,F]=(0,a.useState)(!1),T=(0,a.useCallback)(async(e,l)=>{var t,n,i,r;let o=[];try{let l=null!==(n=null!==(t=e.slug)&&void 0!==t?t:e.catalogProductId)&&void 0!==n?n:e.id;o=await (0,tw.O3)(l,{withVariants:!0})}catch(e){}M(o=function(e){if(!e||0===e.length)return[{id:"printify_choice",name:t4,is_default:!0}];let l=e.find(nl),t=e.filter(e=>!nl(e)).map(e=>({...e,is_default:!1}));return l?[{...l,is_default:!0},...t]:t}(o)),D(null!==(r=null!==(i=function(e,l){var t;if(null==l||""===l)return null;let n=String(l);return null!==(t=(null!=e?e:[]).find(e=>(null==e?void 0:e.external_id)!=null&&String(e.external_id)===n||(null==e?void 0:e.id)!=null&&String(e.id)===n))&&void 0!==t?t:null}(o,l))&&void 0!==i?i:o.find(nl))&&void 0!==r?r:o[0])},[]);(0,a.useEffect)(()=>{if(S){if("change-provider"===h&&(null==p?void 0:p.product)){var e,l,t,n,i,r,o,a,d,s;P(p.product),A(null),C("loading");let u=null!==(s=null!==(d=null!==(a=null!==(o=null!==(r=null==(e=p.product)?void 0:null===(l=e.provider)||void 0===l?void 0:l.external_id)&&void 0!==r?r:null==e?void 0:null===(t=e.provider)||void 0===t?void 0:t.id)&&void 0!==o?o:null==e?void 0:null===(n=e.print_provider)||void 0===n?void 0:n.id)&&void 0!==a?a:null==e?void 0:e.print_provider_id)&&void 0!==d?d:null==e?void 0:null===(i=e.provider_refs)||void 0===i?void 0:i.print_provider_id)&&void 0!==s?s:null;T(p.product,u).then(()=>{C("providers")});return}p?(P(p.product),A(p.selection),C("options")):(C("browse"),P(null),A(null))}},[S,p,h,T]);let N=()=>{m?m():k(),C("browse"),P(null),A(null),M([]),D(null),F(!1)},W="change-provider"===h?N:p?N:"options"===I?()=>C("providers"):"providers"===I?()=>{C("browse"),P(null)}:()=>C("browse"),U=async e=>{C("loading"),P(e),await T(e,null),C("providers")},H=async()=>{var e,l,t,n,i;if("change-provider"===h&&f){F(!0);try{let e=await f(z);!1!==e&&N()}finally{F(!1)}return}let r=(0,tw.gd)(z),o=null!==(e=z.colors)&&void 0!==e?e:[],a=null!==(l=z.sizes)&&void 0!==l?l:[],d=[];if(o.length>0&&a.length>0)for(let e of o)for(let l of a)d.push({color:e.name,color_hex:null!==(t=e.hex)&&void 0!==t?t:null,size:l});else if(o.length>0)for(let e of o)d.push({color:e.name,color_hex:null!==(n=e.hex)&&void 0!==n?n:null,
1size:""});else if(a.length>0)for(let e of a)d.push({color:"",color_hex:null,size:e});let s=function(e,l){let t=Array.isArray(e)?e:[],n=Array.isArray(l)?l:[];if(!n.length)return t;let i=new Map;for(let e of n){if(!e||"object"!=typeof e)continue;let l="".concat(nt(e.color),"|").concat(nt(e.size));i.has(l)||i.set(l,e)}return t.map(e=>{var l,t;let n=i.get("".concat(nt(e.color),"|").concat(nt(e.size)));if(!n)return e;let r=n.base_cost_cents,o=null!=r&&""!==r&&Number.isFinite(Number(r))?Number(r):null;return{...e,base_cost_cents:null!==(l=e.base_cost_cents)&&void 0!==l?l:o,catalog_cost_cents:null!==(t=e.catalog_cost_cents)&&void 0!==t?t:o,...null!=n.is_available&&null==e.is_available?{is_available:!1!==n.is_available}:{}}})}(d,z.variants),u=ne(z,null!==(i=null==Z?void 0:Z.print_areas)&&void 0!==i?i:null);P(e=>({...e,variations:r,rawVariants:s,provider:z,...u?{print_areas:u}:{}})),A(null),C("options")},B=async(e,l)=>{var t;let n=null!==(t=e.rawVariants)&&void 0!==t?t:[];if(p&&v){if(!1===await v(e,l,n))return}else null==o||o({product:e,selection:l,rawVariants:n});N()},V=(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1,minWidth:0,flex:1},children:[(0,n.jsx)(y.Z,{onClick:W,sx:{display:"flex",alignItems:"center",cursor:"pointer",color:ei.oR.textTertiary,"&:hover":{color:ei.oR.textPrimary},transition:"color 0.15s"},children:(0,n.jsx)(ty.Z,{sx:{fontSize:18}})}),(0,n.jsx)(L.Z,{component:"span",sx:{fontSize:16,fontWeight:600,color:ei.oR.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:null!==(l=null==Z?void 0:Z.name)&&void 0!==l?l:"Select Provider"})]}),K=(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1,minWidth:0,flex:1},children:[(0,n.jsx)(y.Z,{onClick:W,sx:{display:"flex",alignItems:"center",cursor:"pointer",color:ei.oR.textTertiary,"&:hover":{color:ei.oR.textPrimary},transition:"color 0.15s"},children:(0,n.jsx)(ty.Z,{sx:{fontSize:18}})}),(0,n.jsx)(L.Z,{component:"span",sx:{fontSize:16,fontWeight:600,color:ei.oR.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:null!==(t=null==Z?void 0:Z.name)&&void 0!==t?t:"Select Options"})]}),G=void 0===g&&!p&&"change-provider"!==h;return(0,n.jsxs)(n.Fragment,{children:[G&&(0,n.jsx)(_.Z,{title:null!=u?u:"",placement:"top",disableInteractive:!0,children:(0,n.jsx)("span",{children:(0,n.jsx)(w.f,{text:d?"+ Add Another Product":"+ Add Product",color:"white",width:"auto",className:"whitespace-nowrap",disabled:s,onClick:()=>!s&&j(!0)})})}),(0,n.jsxs)($.Z,{open:S,onClose:N,title:"options"===I?K:"providers"===I?V:"Select a Product",size:"sm",fullWidth:!0,children:["browse"===I&&(0,n.jsx)(ni,{onSelectProduct:U,existingPodProducts:c}),"providers"===I&&(0,n.jsx)(nr,{providers:E,selectedProvider:z,onSelect:D,onConfirm:H,confirmText:"change-provider"===h?O?"Switching...":"Switch provider":"Continue",helperText:"change-provider"===h?"Pick a new print provider for this product. Variants the new provider doesn't carry will be removed; variants both providers share keep their prices.":"Choose the print provider that will fulfil orders for this product."}),"loading"===I&&(0,n.jsxs)(y.Z,{sx:{py:6,display:"flex",flexDirection:"column",alignItems:"center",gap:2},children:[(0,n.jsx)(q.D8,{size:32,sx:{color:ei.oR.selected}}),(0,n.jsx)(L.Z,{sx:{fontSize:13,color:ei.oR.textSecondary},children:"Loading product options..."})]}),"options"===I&&Z&&(0,n.jsx)(nn,{product:Z,onConfirm:B,initialSelection:R,initialVariationId:x,existingPodProducts:c,editContext:p?{prefixes:null!==(i=p.prefixes)&&void 0!==i?i:{},podProductId:null!==(r=p.podProductId)&&void 0!==r?r:null}:null})]})]})}var na=t(95829),nd=t(29886),ns=t(93312);let nu={XS:1,S:2,M:3,L:4,XL:5,"2XL":6,XXL:6,"3XL":7,XXXL:7,"4XL":8,"5XL":9};function nc(e,l,t){return l.options.filter(e=>{var n;return null==t?void 0:null===(n=t[l.id])||void 0===n?void 0:n[e.id]}).map(l=>{var t;let n=String(null!==(t=null==l?void 0:l.label)&&void 0!==t?t:"");return e?"".concat(e).concat(" - ").concat(n):n})}function np(e){let{value:l,originalLabel:t,maxLen:i,displayStyle:r,onChange:o,onReset:d,hint:s="Click to rename"}=e,[u,c]=(0,a.useState)(!1),p=void 0!==t&&t!==l;if(u){var v;return(0,n.jsx)(y.Z,{component:"input",autoFocus:!0,value:null!=l?l:"",maxLength:i>0?i:0,onChange:e=>null==o?void 0:o(e.target.value.slice(0,i)),onBlur:()=>c(!1),onKeyDown:e=>{("Enter"===e.key||"Escape"===e.key)&&e.currentTarget.blur()},sx:{border:"1px solid var(--lv-selected)",outline:"none",background:"transparent",borderRadius:"6px",px:.5,py:"1px",fontFamily:"inherit",width:"".concat(Math.max((null!==(v=null==l?void 0:l.length)&&void 0!==v?v:0)+1,4),"ch"),...r}})}return(0,n.jsx)(_.Z,{title:p?"Original: ".concat(t):s,placement:"top",disableInteractive:!0,children:(0,n.jsxs)(y.Z,{onClick:()=>c(!0),sx:{display:"inline-flex",alignItems:"center",gap:"3px",border:"1px dashed transparent",borderRadius:"6px",px:.5,py:"1px",cursor:"pointer","&:hover":{borderColor:"var(--lv-border-default)"}},children:[(0,n.jsx)(L.Z,{sx:r,children:l}),p&&d&&(0,n.jsx)(y.Z,{component:"span",onClick:e=>{e.stopPropagation(),d()}
1,sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:11,lineHeight:1,color:"var(--lv-text-secondary)",cursor:"pointer",userSelect:"none","&:hover":{color:"var(--lv-text-primary)"}},children:"âº"})]})})}function nv(e){let{count:l,label:t}=e;return(0,n.jsx)(_.Z,{title:"".concat(l," ").concat(t," option").concat(1===l?"":"s"," selected"),placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",px:.75,py:.25,height:18,bgcolor:"var(--lv-bg-hover)",borderRadius:"7px",ml:.75},children:(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)",fontWeight:500,lineHeight:1},children:l})})})}function nh(e){let{children:l,truncate:t,maxWidth:i,color:r}=e;return(0,n.jsx)(y.Z,{sx:{bgcolor:"var(--lv-bg-elevated)",borderRadius:"10px",px:1.5,py:.75,...i&&{maxWidth:i,overflow:"hidden"}},children:(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:500,color:r||"var(--lv-text-primary)",...t&&{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},children:l})})}function nf(e){var l,t;let{variation:i,selection:r,prefix:o,onPrefixChange:d,onAutoGenerate:s,variationIndex:u,showPrefix:c,otherNames:p,onEditVariation:v,onOptionLabelChange:h,onResetOptionLabel:f,onVariationLabelChange:x,onResetVariationLabel:g,draftLinked:m=!1,linkedEditUnsupported:b=!1,linkedEditUnsupportedCopy:j=tO.cF}=e,[w,S]=(0,a.useState)(!1),[k,I]=(0,a.useState)(!1),C="colors"===i.id,Z=[...i.options.filter(e=>{var l;return null==r?void 0:null===(l=r[i.id])||void 0===l?void 0:l[e.id]})].sort((e,l)=>{var t,n;let i=String(null!==(t=null==e?void 0:e.label)&&void 0!==t?t:"").trim().toUpperCase(),r=String(null!==(n=null==l?void 0:l.label)&&void 0!==n?n:"").trim().toUpperCase(),o=nu[i],a=nu[r];if(null!=o&&null!=a)return a-o;if(null!=o)return -1;if(null!=a)return 1;let d=parseFloat(i),s=parseFloat(r);return isNaN(d)||isNaN(s)?r.localeCompare(i):s-d}),P=Z.length,R=null!==(l=i.label)&&void 0!==l?l:"colors"===i.id?"Color":"sizes"===i.id?"Size":i.id,A=(0,a.useMemo)(()=>nc(null!=o?o:"",i,r),[o,i,r]),E=A.filter(e=>e.length>20),M=p?A.filter(e=>p.includes(e)):[],z=17-(0,a.useMemo)(()=>Z.reduce((e,l)=>{var t;return Math.max(e,String(null!==(t=null==l?void 0:l.label)&&void 0!==t?t:"").length)},0),[Z]),D=20-(o?o.length+3:0),O=!!o;return(0,n.jsxs)(y.Z,{sx:{flex:1,minWidth:0},children:[(0,n.jsxs)(y.Z,{sx:{mb:1.25},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5},children:[(0,n.jsx)(np,{value:R,originalLabel:i._original_label,maxLen:20,displayStyle:{fontSize:16,fontWeight:500,color:"var(--lv-text-primary)",lineHeight:1},onChange:e=>null==x?void 0:x(i.id,e),onReset:void 0!==i._original_label?()=>null==g?void 0:g(i.id):void 0,hint:"Click to rename â applies to all linked products"}),(0,n.jsx)(nv,{count:P,label:R.toLowerCase()})]}),(0,n.jsxs)(y.Z,{onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),sx:{display:"flex",alignItems:"center",gap:.5,mt:.5},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:12,fontWeight:500,color:"var(--lv-text-secondary)"},children:["Variation ",u+1]}),b?(0,n.jsx)(_.Z,{title:j,placement:"top",children:(0,n.jsx)(y.Z,{"aria-label":j,"aria-disabled":"true",tabIndex:0,className:"rounded-lv-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lv-focus",sx:{dis
1play:"inline-flex",cursor:"not-allowed"},children:(0,n.jsx)(na.Z,{sx:{fontSize:13,color:"var(--lv-text-tertiary)"}})})}):(0,n.jsx)(na.Z,{onClick:()=>null==v?void 0:v(i.id),sx:{fontSize:13,color:"var(--lv-text-secondary)",cursor:"pointer",opacity:w?1:0,transition:"opacity 0.15s","&:hover":{color:"var(--lv-text-primary)"}}})]})]}),(0,n.jsxs)(y.Z,{sx:{border:"1px solid var(--lv-border-default)",borderRadius:4,p:1.25,bgcolor:"var(--lv-bg-card)"},children:[c&&(0,n.jsx)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",minHeight:27,px:.5,mb:.5},children:k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:500,color:"var(--lv-selected)",mr:1,flexShrink:0},children:"Prefix"}),(0,n.jsx)(_.Z,{title:z>0?"".concat(null!==(t=null==o?void 0:o.length)&&void 0!==t?t:0,"/").concat(z," characters"):"No room for prefix",placement:"top",open:k,children:(0,n.jsx)(y.Z,{component:"input",autoFocus:!0,value:null!=o?o:"",maxLength:z>0?z:0,onChange:e=>{let l=z>0?e.target.value.slice(0,z):"";null==d||d(l)},onBlur:()=>I(!1),onKeyDown:e=>{"Enter"===e.key&&I(!1)},sx:{flex:1,minWidth:0,border:"none",outline:"none",background:"var(--lv-bg-elevated)",fontSize:12,fontWeight:500,color:"var(--lv-text-primary)",fontFamily:"inherit",borderRadius:"10px",px:1.5,py:.75}})})]}):O?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:500,color:"var(--lv-selected)",flexShrink:0},children:"Prefix"}),(0,n.jsxs)(y.Z,{onClick:()=>I(!0),sx:{display:"flex",alignItems:"center",cursor:"pointer"},children:[(0,n.jsx)(nh,{truncate:!0,maxWidth:115,children:o}),(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)",mx:.25},children:"+"}),(0,n.jsx)(nh,{color:"var(--lv-text-secondary)",children:R})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:500,color:"var(--lv-text-primary)"},children:"Prefix"}),(0,n.jsx)(_.Z,{title:"Auto-generate prefix from product name",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:()=>{null==s||s(),I(!0)},sx:{display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",color:"var(--lv-text-secondary)","&:hover":{color:"var(--lv-text-primary)"}},children:(0,n.jsx)(nd.Z,{sx:{fontSize:16}})})})]})}),E.length>0&&(0,n.jsxs)(L.Z,{sx:{fontSize:10,color:"var(--lv-error)",mb:.5},children:[E.length," name",E.length>1?"s":""," exceed 20 chars."]}),M.length>0&&(0,n.jsxs)(L.Z,{sx:{fontSize:10,color:"var(--lv-error)",mb:.5},children:[M.length," name collision",M.length>1?"s":"","."]}),(0,n.jsx)(y.Z,{sx:{display:"flex",flexWrap:"wrap",gap:0},children:Z.map(e=>{var l,t;return(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:"5px",px:"5px",py:"3.75px",borderRadius:"7px"},children:[C?(0,n.jsx)(tA.Z,{hex:e.hex,size:10,sx:{boxShadow:"inset 0 0 0 0.25px #fff"}}):(0,n.jsx)(tA.Z,{size:10,borderRadius:"2px"}),i._synthetic?(0,n.jsx)(_.Z,{title:"Rename this option",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{component:"input",value:e.label,maxLength:20,onChange:l=>null==h?void 0:h(i.id,e.id,l.target.value.slice(0,20)),sx:{border:"1px dashed var(--lv-border-default)",outline:"none",background:"transparent",borderRadius:"6px",px:.5,py:"1px",fontSize:12,fontWeight:500,color:"var(--lv-text-primary)",fontFamily:"inherit",lineHeight:1.2,width:"".concat(Math.max((null!==(t=null===(l=e.label)||void 0===l?void 0:l.length)&&void 0!==t?t:0)+1,4),"ch"),"&:focus":{borderColor:"var(--lv-selected)",borderStyle:"solid"}}})}):(0,n.jsx)(np,{value:e.label,originalLabel:e._original_label,maxLen:D,displayStyle:{fontSize:12,fontWeight:500,color:"var(--lv-text-primary)",lineHeight:1},onChange:l=>null==h?void 0:h(i.id,e.id,l),onReset:void 0!==e._original_label?()=>null==f?void 0:f(i.id,e.id):void 0})]},e.id)})}),0===P&&(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-disabled)"},children:"No options selected"})]})]})}function nx(e){var l,t,i,r,o,d,s;let{product:u,selection:c,prefixes:p,onPrefixChange:v,onOptionLabelChange:h,onResetOptionLabel:f,onVariationLabelChange:x,onResetVariationLabel:g,onEditOptions:m,onChangeProvider:b,onRemove:j,showPrefix:S,otherResolvedNames:k,label:I,hasDesign:C=!0,draftLinked:Z=!1,linkedEditUnsupported:P=!1,linkedEditUnsupportedCopy:R=tO.cF,providerChangeUnavailable:A=!1,providerChangeUnavailableCopy:E}=e,[M,z]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),F=null!==(r=u.variations)&&void 0!==r?r:[],T=(0,a.useMemo)(()=>{var e,l,t,i,r,o,a,d,s;let c=null===(e=u.supplier)||void 0===e?void 0:e.slug,p=null!==(o=null===(l=u.supplier)||void 0===l?void 0:l.name)&&void 0!==o?o:c?c.charAt(0).toUpperCase()+c.slice(1):null,v=null!==(s=null!==(d=null!==(a=null===(t=u.provider)||void 0===t?void 0:t.name)&&void 0!==a?a:null===(i=u.print_provider)||void 0===i?void 0:i.name)&&void 0!==d?d:null===(r=u.provider_refs)||void 0===r?void 0:r.print_provider_name)&&void 0!==s?s:null,h=[];p&&h.push((0,n.jsx)("span",{children:p},"supplier")),v&&h.push((0,n.jsx)(_.Z,{title:"Print provider: ".concat(v),placement:"top",disableInteractive:!0,children:(0,n.jsx)("span",{style:{cursor:"help"},children:v})},"provider"));let f=t8(u);return(f&&h.push((0,n.jsx)("span",{children:"Ships in ".concat(f)},"ships")),0===h.length)?null:h.flatMap((e,l)=>0===l?[e]:[(0,n.jsx)("span",{children:" ⢠"},"sep-".concat(l)),e])},[u]),N=(0,a.useMemo)(()=>t9(u),[u]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(y.Z,{sx:{border:"1px solid var(--lv-border-default)",borderRadius:5,p:2.5,display:"flex",flexDirection:"column",gap:3,bgcolor:"var(--lv-bg-elevated)","&:hover .title-info-icon":{opacity:.65}},children:[I&&(C?(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:600,color:"var(--lv-text-tertiary)",lineHeight:1},children:I}):(0,n.jsx)(_.Z,{title:"No design file linked â assign a design in the panel on the left",placement:"top",disableInteractive:!0,children:(0,n.jsxs)(y.Z,{sx:{alignSelf:"flex-start",display:"inline-flex",alignItems:"center",gap:.5,px:1,py:.5,bgcolor:"var(--lv-bg-elevated)",borderRadius:2,cursor:"help"},children:[(0,n.jsx)(ns.Z,{sx:{fontSize:13,color:"var(--lv-text-secondary)"}}),(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:600,color:"var(--lv-text-secondary)",lineHeight:1},children:I})]})})),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:1.25},children:[(0,n.jsx)(tS.ZP,{product:u,tooltipContent:N,metaLabel:T,metaIcon:u.supplier?(0,n.jsx)(tj,{supplier:u.supplier,providerName:null!==(s=null!==(d=null!==(o=null===(l=u.provider)||void 0===l?void 0:l.name)&&void 0!==o?o:null===(t=u.print_provider)||void 0===t?void 0:t.name)&&void 0!==d?d:null===(i=u.provider_refs)||void 0===i?void 0:i.print_provider_name)&&void 0!==s?s:void 0}):null,thumbSize:48,sx:{flex:1}}),(0,n.jsx)(y.Z,{onClick:e=>O(D?null:e.currentTarget),sx:{width:27,height:27,borderRadius:"10px",flexShrink:0,border:"0.5px solid var(--lv-border-default)",bgcolor:D?"var(--lv-bg-elevated)":"var(--lv-bg-card)",boxShadow:"var(--lv-shadow-sm)",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer","&:hover":{bgcolor:"var(--lv-bg-elevated)"},transition:"background 0.15s"},children:(0,n.jsx)(na.Z,{sx:{fontSize:14,color:"var(--lv-text-secondary)"}})}
1),(0,n.jsx)(e2.Z,{anchorEl:D,open:!!D,onClose:()=>O(null),items:[{label:"Edit Options",onClick:()=>null==m?void 0:m(),disabled:P,description:P?R:void 0,descriptionLines:P?2:void 0},...b?[{label:"Change Provider",onClick:()=>null==b?void 0:b(),disabled:P||A,description:P?R:A?E:void 0,descriptionLines:P||A?2:void 0}]:[],{divider:!0},{label:"Remove",danger:!0,onClick:()=>z(!0)}]})]}),F.length>0&&(0,n.jsx)(y.Z,{sx:{display:"flex",gap:3},children:F.map((e,l)=>{var t,i;let r=nc(null!==(t=null==p?void 0:p[e.id])&&void 0!==t?t:"",e,c),o=(null!=k?k:[]).filter(e=>!r.includes(e));return(0,n.jsx)(nf,{variation:e,selection:c,prefix:null!==(i=null==p?void 0:p[e.id])&&void 0!==i?i:"",onPrefixChange:l=>null==v?void 0:v(e.id,l),onAutoGenerate:()=>{var l;let t=(null!==(l=u.name)&&void 0!==l?l:"").trim().split(/\s+/).filter(Boolean).map(e=>e[0].toUpperCase()).join(""),n=17-e.options.filter(l=>{var t;return null==c?void 0:null===(t=c[e.id])||void 0===t?void 0:t[l.id]}).reduce((e,l)=>{var t;return Math.max(e,String(null!==(t=null==l?void 0:l.label)&&void 0!==t?t:"").length)},0);null==v||v(e.id,n>0?t.slice(0,n):"")},variationIndex:l,showPrefix:S,otherNames:o,draftLinked:Z,linkedEditUnsupported:P,linkedEditUnsupportedCopy:R,onEditVariation:e=>null==m?void 0:m(e),onOptionLabelChange:h,onResetOptionLabel:f,onVariationLabelChange:x,onResetVariationLabel:g},e.id)})})]}),(0,n.jsx)($.Z,{open:M,onClose:()=>z(!1),title:"Remove ".concat(u.name,"?"),PaperProps:{sx:{maxWidth:400}},actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w.f,{text:"Cancel",color:"white",width:"auto",className:"whitespace-nowrap",onClick:()=>z(!1)}),(0,n.jsx)(w.f,{text:"Remove",color:"purple",width:"auto",className:"whitespace-nowrap",onClick:()=>{z(!1),null==j||j()}})]}),children:(0,n.jsx)(L.Z,{sx:{fontSize:13,color:"var(--lv-text-secondary)",lineHeight:1.6},children:"This will delete all variant pricing and design file mappings for this product."})})]})}var ng=t(60332),nm=t(18930),ny=t(84121),nb=t(35341),nj=t(14064),n_=t(18477),nw=t(69076),nS=t(99397),nk=t(41473),nI=t(90372),nC=t(39149),nZ=t(65778),nP=t(70657),nR=t(45641);let nA=[25,50,75,100],nE="undefined"!=typeof navigator&&/Mac/i.test(navigator.userAgent)?"â":"Ctrl+",nM="var(--lv-selected)",nz="var(--lv-text-secondary)",nD="#009CFF",nL="rgba(0, 156, 255,0.40)",nO="#f59e0b",nF=[{value:"contain",tooltip:"Fit â scale design to fit within the print area",icon:e=>{let l=e?nM:nz;return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 12 12",fill:"none",children:[(0,n.jsx)("path",{d:"M7.36 6.03H10.01M10.01 6.03L8.95 4.97M10.01 6.03L8.95 7.09M3.12 7.09L2.06 6.03M2.06 6.03L3.12 4.97M2.06 6.03H4.71",stroke:l,strokeWidth:"0.62",strokeLinecap:"round",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M1 3.22V2.11C1 1.5 1.5 1 2.11 1H3.22M8.78 1H9.89C10.5 1 11 1.5 11 2.11V3.22M11 8.78V9.89C11 10.5 10.5 11 9.89 11H8.78M3.22 11H2.11C1.5 11 1 10.5 1 9.89V8.78",stroke:l,strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round"})]})}},{value:"cover",tooltip:"Cover â scale design to fill the entire print area (may crop edges)",icon:e=>{let l=e?nM:nz;return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 12 12",fill:"none",children:[(0,n.jsx)("path",{d:"M6.97 5.1L8.85 3.22M8.85 3.22H7.35M8.85 3.22V4.72M5.1 5.1L3.22 3.22M3.22 3.22H4.72M3.22 3.22V4.72M7.35 8.85H8.85M8.85 8.85V7.35M8.85 8.85L6.97 6.97M4.72 8.85H3.22M3.22 8.85V7.35M3.22 8.85L5.1 6.97",stroke:l,strokeWidth:"0.62",strokeLinecap:"round",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M1 3.22V2.11C1 1.5 1.5 1 2.11 1H3.22M8.78 1H9.89C10.5 1 11 1.5 11 2.11V3.22M11 8.78V9.89C11 10.5 10.5 11 9.89 11H8.78M3.22 11H2.11C1.5 11 1 10.5 1 9.89V8.78",stroke:l,strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round"})]})}}],nT=[{value:"left",tooltip:"Align left",icon:e=>{let l=e?nM:nz;return(0,n.jsx)("svg",{width:"13",height:"11",viewBox:"0 0 10 8",fill:"none",children:(0,n.jsx)("path",{d:"M0.5 7.5V0.5M5.5 1L2.5 4M2.5 4L5.5 7M2.5 4H9.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}},{value:"center",tooltip:"Center",icon:e=>{let l=e?nM:nz;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 11 11",fill:"none",children:(0,n.jsx)("path",{d:"M5.5 0.5V10.5M3.5 4.5H1.5C1.23 4.5 1 4.27 1 4V2.5C1 1.95 1.45 1.5 2 1.5H3.5M7.5 4.5H9.5C9.77 4.5 10 4.27 10 4V2.5C10 1.95 9.55 1.5 9 1.5H7.5M3.5 9.5H3C2.45 9.5 2 9.05 2 8.5V7.5C2 6.95 2.45 6.5 3 6.5H3.5M7.5 6.5H8C8.55 6.5 9 6.95 9 7.5V8.5C9 9.05 8.55 9.5 8 9.5H7.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}},{value:"right",tooltip:"Align right",icon:e=>{let l=e?nM:nz;return(0,n.jsx)("svg",{width:"13",height:"11",viewBox:"0 0 10 8",fill:"none",children:(0,n.jsx)("path",{d:"M7.5 4H0.5M7.5 4L4.5 7M7.5 4L4.5 1M9.5 0.5V7.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}}],nN=[{value:"top",tooltip:"Align top",icon:e=>{let l=e?nM:nz;return(0,n.jsx)("svg",{width:"11",height:"13",viewBox:"0 0 8 10",fill:"none",children:(0,n.jsx)("path",{d:"M0.5 0.5H7.5M7 5.5L4 2.5M4 2.5L1 5.5M4 2.5V9.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}}
1,{value:"center",tooltip:"Center vertical",icon:e=>{let l=e?nM:nz;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 11 11",fill:"none",children:(0,n.jsx)("path",{d:"M0.5 5.5H10.5M4.5 7.5V9.5C4.5 9.77 4.27 10 4 10H2.5C1.95 10 1.5 9.55 1.5 9V7.5M4.5 3.5V1.5C4.5 1.23 4.27 1 4 1H2.5C1.95 1 1.5 1.45 1.5 2V3.5M9.5 7.5V8C9.5 8.55 9.05 9 8.5 9H7.5C6.95 9 6.5 8.55 6.5 8V7.5M6.5 3.5V3C6.5 2.45 6.95 2 7.5 2H8.5C9.05 2 9.5 2.45 9.5 3V3.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}},{value:"bottom",tooltip:"Align bottom",icon:e=>{let l=e?nM:nz;return(0,n.jsx)("svg",{width:"11",height:"13",viewBox:"0 0 8 10",fill:"none",children:(0,n.jsx)("path",{d:"M4 7.5V0.5M4 7.5L1 4.5M4 7.5L7 4.5M7.5 9.5H0.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}}],nW=[{dim:"width",label:"Width",minField:"minWidth",maxField:"maxWidth"},{dim:"height",label:"Height",minField:"minHeight",maxField:"maxHeight"}];function nU(e){var l,t,i;let{label:r,value:o,options:d=[],onChange:s,disabled:u}=e,[c,p]=(0,a.useState)(null),v=null!==(l=d.find(e=>e.value===o))&&void 0!==l?l:d[0];return(0,n.jsxs)(y.Z,{sx:{display:"inline-flex",alignItems:"stretch",border:"1px solid var(--lv-border-default)",borderRadius:"9px",backgroundColor:"var(--lv-bg-card)",overflow:"hidden",height:"32px",width:"fit-content",opacity:u?.6:1},children:[(0,n.jsx)(y.Z,{sx:{backgroundColor:"var(--lv-bg-elevated)",display:"flex",alignItems:"center",justifyContent:"center",px:"10px",flexShrink:0},children:(0,n.jsx)(L.Z,{sx:{fontSize:"12px",color:"var(--lv-text-primary)",fontWeight:500,whiteSpace:"nowrap"},children:r})}),(0,n.jsxs)(y.Z,{onClick:u?void 0:e=>p(e.currentTarget),sx:{borderLeft:"1px solid var(--lv-border-default)",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",px:"10px",flexShrink:0,cursor:u?"default":"pointer","&:hover":u?{}:{backgroundColor:"var(--lv-bg-elevated)"}},children:[(0,n.jsx)(L.Z,{sx:{fontSize:"12px",color:"var(--lv-text-primary)",fontWeight:500,whiteSpace:"nowrap"},children:null!==(i=null!==(t=null==v?void 0:v.label)&&void 0!==t?t:null==v?void 0:v.value)&&void 0!==i?i:"â"}),(0,n.jsx)(Y.Z,{size:14,strokeWidth:2.25,color:"var(--lv-text-primary)"})]}),(0,n.jsx)(e2.Z,{anchorEl:c,open:!!c,onClose:()=>p(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},minWidth:160,items:d.map(e=>{var l;return{label:null!==(l=e.label)&&void 0!==l?l:e.value,active:e.value===o,onClick:()=>s(e.value)}})})]})}function nH(e){let{label:l,minValue:t,maxValue:i,onMinChange:r,onMaxChange:o,minInvalid:d,maxInvalid:s,unit:u,unitOptions:c,onUnitChange:p,onRemove:v}=e,[h,f]=(0,a.useState)(null),x=Array.isArray(c)&&"function"==typeof p,g=x||"function"==typeof v,m={display:"flex",alignItems:"center",width:68,flexShrink:0,borderLeft:"1px solid var(--lv-border-default)"},b={width:"100%","& .MuiOutlinedInput-root":{borderRadius:0,backgroundColor:"transparent",padding:"0 10px","& fieldset":{border:"none"}},"& input":{fontSize:"12px",padding:"0px",textAlign:"left","&::placeholder":{color:"var(--lv-text-secondary)",opacity:1,fontSize:"12px"}},"& input[type=number]::-webkit-inner-spin-button":{display:"none"},"& input[type=number]::-webkit-outer-spin-button":{display:"none"},"& input[type=number]":{MozAppearance:"textfield"}},j=[];return x&&c.forEach(e=>{var l;j.push({label:null!==(l=e.label)&&void 0!==l?l:e.value,active:e.value===u,onClick:()=>p(e.value)})}),"function"==typeof v&&(j.length>0&&j.push({divider:!0}),j.push({label:"Remove ".concat(l.toLowerCase()," constraint"),icon:(0,n.jsx)(nm.Z,{size:14}),danger:!0,onClick:v})),(0,n.jsxs)(y.Z,{sx:{display:"inline-flex",alignItems:"stretch",border:"1px solid var(--lv-border-default)",borderRadius:"9px",backgroundColor:"var(--lv-bg-card)",overflow:"hidden",height:"32px",width:"fit-content"},children:[(0,n.jsx)(y.Z,{sx:{backgroundColor:"var(--lv-bg-elevated)",display:"flex",alignItems:"center",justifyContent:"center",px:"10px",flexShrink:0},children:(0,n.jsx)(L.Z,{sx:{fontSize:"12px",color:"var(--lv-text-primary)",fontWeight:500,whiteSpace:"nowrap"},children:l})}),(0,n.jsx)(y.Z,{sx:{...m,...d?{boxShadow:"inset 0 0 0 1px #ef4444"}:{}},children:(0,n.jsx)(li.Z,{size:"small",placeholder:"min",type:"number",value:null!=t?t:"",onChange:e=>r(e.target.value),sx:b,fullWidth:!0})}
1),(0,n.jsxs)(y.Z,{sx:{...m,...s?{boxShadow:"inset 0 0 0 1px #ef4444"}:{}},children:[(0,n.jsx)(li.Z,{size:"small",placeholder:"max",type:"number",value:null!=i?i:"",onChange:e=>o(e.target.value),sx:b,fullWidth:!0}),u&&!x&&(0,n.jsx)(L.Z,{sx:{fontSize:"10px",color:"var(--lv-text-disabled)",pr:"10px",flexShrink:0},children:u})]}),g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(y.Z,{onClick:e=>f(e.currentTarget),sx:{borderLeft:"1px solid var(--lv-border-default)",backgroundColor:"var(--lv-bg-elevated)",display:"flex",alignItems:"center",justifyContent:"center",gap:"4px",px:"10px",flexShrink:0,cursor:"pointer","&:hover":{backgroundColor:"var(--lv-bg-card)"}},children:[x&&(0,n.jsx)(L.Z,{sx:{fontSize:"12px",color:"var(--lv-text-primary)",fontWeight:500,whiteSpace:"nowrap"},children:u}),(0,n.jsx)(Y.Z,{size:14,strokeWidth:2.25,color:"var(--lv-text-primary)"})]}),(0,n.jsx)(e2.Z,{anchorEl:h,open:!!h,onClose:()=>f(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},minWidth:160,items:j})]})]})}function nB(e){var l,t;let{localLink:i,update:r,unit:o,violations:d,hasViolation:s,deriveConstraint:u,margins:c,effectiveWidthIn:p,effectiveHeightIn:v,printAreaWidthIn:h,printAreaHeightIn:f,areaNameLabel:x,dimLabel:g,dimsKnown:m=!0,fileW:b,fileH:j,dpiStatus:w,calcDpi:S,DPI_META:k,isFill:I,fileAspectRatio:C,printAR:Z,history:P,handleReset:R}=e,[A,E]=(0,a.useState)(null),M=e=>{let{minField:l,maxField:t}=e;return null!=i[l]||null!=i[t]},z=nW.some(M),D=(0,eP.J_)(i),O=(0,eP.$O)(i),F=(0,eP.L2)(i),T={fontSize:11,fontWeight:600,color:"var(--lv-text-secondary)",textTransform:"uppercase",letterSpacing:"0.07em"},N={borderTop:"1px solid var(--lv-border-default)",my:1.25},W={width:26,height:26,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"6px",cursor:"pointer",border:"1px solid var(--lv-border-default)",bgcolor:"var(--lv-bg-elevated)",color:"var(--lv-text-secondary)","&:hover":{borderColor:"var(--lv-border-strong)",color:"var(--lv-text-primary)"}},U={...W,opacity:.4,cursor:"not-allowed","&:hover":{}};return(0,n.jsxs)(y.Z,{sx:{width:380,flexShrink:0,borderLeft:"1px solid var(--lv-border-default)",bgcolor:"var(--lv-bg-card)",p:2,display:"flex",flexDirection:"column",gap:0,overflowY:"auto"},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:1,mb:1.25},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.25,minWidth:0},children:[(0,n.jsx)(L.Z,{sx:{fontSize:13,fontWeight:600,color:"var(--lv-text-primary)"},children:x}),g?(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-secondary)"},children:g}):m?null:(0,n.jsx)(L.Z,{"data-testid":"pod-canvas-print-area-size-unknown",sx:{fontSize:10,color:"var(--lv-warning-strong)"},children:"Print-area size unknown â re-pick the print provider"})]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5,flexShrink:0},children:[(0,n.jsx)(_.Z,{title:"Undo (".concat(nE,"Z)"),placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:()=>P.canUndo&&P.undo(),sx:P.canUndo?W:U,children:(0,n.jsx)(nj.Z,{size:14})})}),(0,n.jsx)(_.Z,{title:"Redo (".concat(nE,"â§Z)"),placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:()=>P.canRedo&&P.redo(),sx:P.canRedo?W:U,children:(0,n.jsx)(n_.Z,{size:14})})}),(0,n.jsx)(_.Z,{title:"Reset all placement settings to defaults (R)",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:R,sx:W,children:(0,n.jsx)(nw.Z,{size:14})})})]})]}),(0,n.jsx)(y.Z,{sx:N}),(0,n.jsxs)(y.Z,{sx:{display:"flex",gap:1.5,mb:1.25},children:[(0,n.jsxs)(y.Z,{sx:{flexShrink:0},children:[(0,n.jsx)(L.Z,{sx:{...T,mb:.75},children:"Fit Mode"}),(0,n.jsx)(t_.Z,{options:nF,value:F,onChange:e=>r((0,eP.sO)(e,{fileAspectRatio:C,printAR:Z})),size:"compact"})]}),(0,n.jsxs)(y.Z,{sx:{flex:1,minWidth:0},children:[(0,n.jsx)(L.Z,{sx:{...T,mb:.75},children:"Rotation"}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5},children:[(0,n.jsx)(_.Z,{title:"Rotate -90\xb0",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:()=>{var e;return r({angle:(((null!==(e=i.angle)&&void 0!==e?e:0)-90)%360+360)%360})},sx:W,children:(0,n.jsx)(nw.Z,{size:14})})}),(0,n.jsx)(nI.Z,{value:null!==(l=i.angle)&&void 0!==l?l:0,onChange:e=>{r({angle:(Math.round(parseFloat(e)||0)%360+360)%360})},width:56}),(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)"},children:"\xb0"}),(0,n.jsx)(_.Z,{title:"Rotate +90\xb0",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:()=>{var e;return r({angle:((null!==(e=i.angle)&&void 0!==e?e:0)+90)%360})},sx:W,children:(0,n.jsx)(e5.Z,{size:14})})}),(null!==(t=i.angle)&&void 0!==t?t:0)!==0&&(0,n.jsx)(_.Z,{title:"Reset rotation",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:()=>r({angle:0}),sx:{fontSize:12,color:"var(--lv-text-secondary)",cursor:"pointer","&:hover":{color:"var(--lv-text-primary)"}},children:"â"})})]})]})]}),(0,n.jsx)(y.Z,{sx:N}),(0,n.jsx)(L.Z,{sx:{...T,mb:.75},children:"Alignment"}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:1.25},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5}
1,children:[(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-secondary)",flexShrink:0},children:"H:"}),(0,n.jsx)(t_.Z,{options:nT,value:D,onChange:e=>r((0,eP.Jb)(e)),size:"compact"})]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5},children:[(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-secondary)",flexShrink:0},children:"V:"}),(0,n.jsx)(t_.Z,{options:nN,value:O,onChange:e=>r((0,eP.Ht)(e)),size:"compact"})]})]}),(0,n.jsx)(y.Z,{sx:N}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:1,gap:.75},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1,minWidth:0},children:[(0,n.jsx)(L.Z,{sx:T,children:"Size Constraints"}),z&&(0,n.jsx)(L.Z,{component:"button",onClick:()=>r({minWidth:null,maxWidth:null,minHeight:null,maxHeight:null}),sx:{fontSize:10,color:"var(--lv-selected)",background:"none",border:"none",padding:0,cursor:"pointer",textTransform:"none",fontWeight:500,"&:hover":{textDecoration:"underline"}},children:"Clear"})]}),(0,n.jsx)(_.Z,{title:"Add a size constraint",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:e=>E(e.currentTarget),sx:{width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"8px",cursor:"pointer",border:"0.5px solid #e5e7eb",bgcolor:"white",color:"var(--lv-text-secondary)","&:hover":{color:"var(--lv-text-primary)"}},children:(0,n.jsx)(nS.Z,{size:14})})}),(0,n.jsx)(e2.Z,{anchorEl:A,open:!!A,onClose:()=>E(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},minWidth:120,items:nW.map(e=>({label:e.label,disabled:M(e),onClick:()=>r({[e.minField]:"",[e.maxField]:""})}))})]}),z?(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.75,mb:1.25},children:nW.map(e=>M(e)?(0,n.jsx)(nH,{label:e.label,minValue:i[e.minField],maxValue:i[e.maxField],onMinChange:l=>r(u(e.minField,l)),onMaxChange:l=>
1r(u(e.maxField,l)),minInvalid:d[e.minField],maxInvalid:d[e.maxField],unit:o,unitOptions:["inches","cm","mm","px"].map(e=>({value:e,label:e})),onUnitChange:e=>r({unit:e}),onRemove:()=>r({[e.minField]:null,[e.maxField]:null})},e.dim):null)}):(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-disabled)",fontStyle:"italic",mb:1.25},children:"No constraints. Click + to add one."}),s&&(0,n.jsx)(y.Z,{sx:{mb:1.25,px:1,py:.75,borderRadius:1.5,bgcolor:"rgba(239,68,68,0.07)",border:"1px solid rgba(239,68,68,0.25)"},children:(0,n.jsxs)(L.Z,{sx:{fontSize:10,color:"#ef4444",lineHeight:1.5},children:["Current placement violates"," ",[d.minWidth&&"min width",d.maxWidth&&"max width",d.minHeight&&"min height",d.maxHeight&&"max height"].filter(Boolean).join(", ")]})}),(0,n.jsx)(y.Z,{sx:N}),(0,n.jsxs)(L.Z,{sx:{...T,mb:.75},children:["Margins ",(0,n.jsx)(y.Z,{component:"span",sx:{fontSize:9,color:"var(--lv-text-disabled)",textTransform:"none",letterSpacing:0,fontWeight:400},children:"(inches)"})]}),(0,n.jsx)(y.Z,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1,mb:1.25},children:[["top","Top"],["right","Right"],["bottom","Bottom"],["left","Left"]].map(e=>{var l;let[t,i]=e,o="left"===t||"right"===t,a="left"===t?"right":"right"===t?"left":"top"===t?"bottom":"top",d=Math.max(0,(o?h:f)-(Number.isFinite(c[a])?c[a]:0)-.1);return(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5},children:[(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-secondary)",width:36,flexShrink:0},children:i}),(0,n.jsx)(nI.Z,{fullWidth:!0,value:null!==(l=c[t])&&void 0!==l?l:0,onChange:e=>{let l=parseFloat(e),n=Number.isFinite(l)?Math.max(0,Math.min(d,l)):0;r({margins:{...c,[t]:n}})},min:0,max:d,size:"sm"})]},t)})}),(0,n.jsx)(y.Z,{sx:N}),(0,n.jsx)(L.Z,{sx:{...T,mb:.75},children:"Current Size"}),(0,n.jsx)(y.Z,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1,mb:1.25},children:[["W",p],["H",v]].map(e=>{let[l,t]=e,i=(0,eP.bg)(t,o);return(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.25},children:[(0,n.jsx)(L.Z,{sx:{fontSize:9,color:"var(--lv-text-secondary)"},children:l}),(0,n.jsx)(y.Z,{sx:{px:1,py:.5,borderRadius:"6px",bgcolor:"var(--lv-bg-elevated)",border:"1px solid var(--lv-border-default)"},children:(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-primary)",fontWeight:500},children:[i.toFixed(2)," ",(0,n.jsx)(y.Z,{component:"span",sx:{fontSize:9,color:"var(--lv-text-disabled)"},children:o})]})})]},l)})}),(()=>{if(!m||"cover"===F||!Number.isFinite(h)||!Number.isFinite(f))return null;let e=p-h>.01?p-h:0,l=v-f>.01?v-f:0;if(!e&&!l)return null;let t=[];return l&&t.push("".concat(l.toFixed(2)," in taller")),e&&t.push("".concat(e.toFixed(2)," in wider")),(0,n.jsx)(y.Z,{"data-testid":"pod-canvas-overflow-notice",sx:{mt:-.5,mb:1.25,px:1,py:.75,borderRadius:"6px",bgcolor:"var(--lv-warning-surface)",border:"1px solid var(--lv-warning-border)"},children:(0,n.jsxs)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-primary)",lineHeight:1.5},children:["Design is ",t.join(" and ")," than the print area â the overflow will be cut off. Choose ",(0,n.jsx)("b",{children:"Fit"})," to fit it inside, or resize it smaller."]})})})(),(0,n.jsx)(y.Z,{sx:N}),(0,n.jsx)(L.Z,{sx:{...T,mb:.75},children:"Print Quality"}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"baseline",flexWrap:"wrap",columnGap:.75,rowGap:.25},children:[b&&j&&(0,n.jsxs)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-secondary)",lineHeight:1.4},children:[b.toLocaleString()," \xd7 ",j.toLocaleString()," px"]}),b&&j&&w&&(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-disabled)",lineHeight:1.4},children:"\xb7"}),w&&(0,n.jsxs)(L.Z,{sx:{fontSize:10,color:k[w].color,fontWeight:500,lineHeight:1.4},children:[S?"".concat(S," DPI"):""," ",k[w].label]})]})]})}function nV(e){let{canvasW:l,canvasH:t,effectiveWidthPct:i,effectiveHeightPct:r,effectiveX:o,effectiveY:a,marginL_px:d=0,marginT_px:s=0,usableW_px:u,usableH_px:c,dragging:p,moveDragging:v,ghostRect:h,dragDimLabel:f,snapGuides:x,constraintActive:g,onResizeStart:m,onMoveStart:y}=e,b=null!=u?u:l,j=null!=c?c:t,_=i/100*l,w=null!=r?r/100*t:_,S=d+o/100*(b-_),k=s+a/100*(j-w),I=[{id:"TC",x:S+_/2,y:k,cursor:"n-resize",axis:"y",edge:"top"},{id:"BC",x:S+_/2,y:k+w,cursor:"s-resize",axis:"y",edge:"bottom"},{id:"ML",x:S,y:k+w/2,cursor:"w-resize",axis:"x",edge:"left"},{id:"MR",x:S+_,y:k+w/2,cursor:"e-resize",axis:"x",edge:"right"}
1,{id:"TL",x:S,y:k,cursor:"nw-resize",axis:"xy",edge:"top-left"},{id:"TR",x:S+_,y:k,cursor:"ne-resize",axis:"xy",edge:"top-right"},{id:"BL",x:S,y:k+w,cursor:"sw-resize",axis:"xy",edge:"bottom-left"},{id:"BR",x:S+_,y:k+w,cursor:"se-resize",axis:"xy",edge:"bottom-right"}],C=e=>["TL","TR","BL","BR"].includes(e),Z=p||v,P=g?nO:nD,R=g?nO:Z?nD:nL;return(0,n.jsxs)("svg",{width:l,height:t,viewBox:"0 0 ".concat(l," ").concat(t),style:{position:"absolute",top:0,left:0,overflow:"visible",pointerEvents:"none"},children:[h&&(0,n.jsx)("rect",{x:h.x,y:h.y,width:h.w,height:h.h,fill:"none",stroke:nL,strokeWidth:"1",strokeDasharray:"5 4",opacity:"0.3"}),(null==x?void 0:x.x)!=null&&(0,n.jsx)("line",{x1:x.x/100*l,y1:-20,x2:x.x/100*l,y2:t+20,stroke:nD,strokeWidth:"1",strokeDasharray:"3 3",opacity:"0.7"}),(null==x?void 0:x.y)!=null&&(0,n.jsx)("line",{x1:-20,y1:x.y/100*t,x2:l+20,y2:x.y/100*t,stroke:nD,strokeWidth:"1",strokeDasharray:"3 3",opacity:"0.7"}),(0,n.jsx)("rect",{x:S,y:k,width:_,height:w,fill:g?"rgba(245,158,11,0.10)":"rgba(0, 156, 255,0.08)",stroke:"none",style:{pointerEvents:"none"}}),(0,n.jsx)("rect",{x:S,y:k,width:_,height:w,fill:"none",stroke:R,strokeWidth:Z||g?2:1.5,strokeDasharray:Z||g?"none":"5 4",style:{pointerEvents:"none"}}),(0,n.jsx)("rect",{x:S,y:k,width:_,height:w,fill:"transparent",style:{pointerEvents:"all",cursor:v?"grabbing":"grab"},onMouseDown:y}),I.map(e=>(0,n.jsxs)("g",{children:[C(e.id)?(0,n.jsx)("circle",{cx:e.x,cy:e.y,r:18,fill:"transparent",style:{pointerEvents:"all",cursor:e.cursor},onMouseDown:l=>m(l,e)}):(0,n.jsx)("rect",{x:e.x-12,y:e.y-12,width:24,height:24,fill:"transparent",style:{pointerEvents:"all",cursor:e.cursor},onMouseDown:l=>m(l,e)}),C(e.id)?(0,n.jsx)("circle",{cx:e.x,cy:e.y,r:8,fill:"white",stroke:P,strokeWidth:"2",style:{pointerEvents:"none"}}):(0,n.jsx)("rect",{x:e.x-5,y:e.y-5,width:10,height:10,fill:"white",stroke:P,strokeWidth:"1.5",style:{pointerEvents:"none"}})]},e.id)),f&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("text",{x:S+_/2,y:k+w+18,textAnchor:"middle",fill:P,fontSize:"10",fontWeight:"600",fontFamily:"Inter, sans-serif",style:{pointerEvents:"none"},children:f.width}),(0,n.jsx)("text",{x:S+_+8,y:k+w/2,textAnchor:"start",dominantBaseline:"central",fill:P,fontSize:"10",fontWeight:"600",fontFamily:"Inter, sans-serif",style:{pointerEvents:"none"},children:f.height})]})]})}function nK(e){var l,t,i,r,o,d,s,u,c,p,v,h,f,x,g,m,b,j,S,k,I,C,Z,P,R;let{open:A,onClose:E,file:M,product:z,link:D={},onChange:O}=e,T=(0,nC.XY)(D),N=T.state,[W,U]=(0,a.useState)(!1),[H,B]=(0,a.useState)(!1);(0,a.useEffect)(()=>{if(A){let e=(0,eP.ED)(D,z,M),l=(0,eP.uX)(D),t=(0,eP.DL)(l,e);T.reset(t),U(t!==l),B(!1);let n=setTimeout(()=>{var e;return null===(e=e$.current)||void 0===e?void 0:e.focus({preventScroll:!0})},50);return()=>clearTimeout(n)}},[A]);let V=(0,a.useCallback)(e=>{T.commit(l=>({...l,...e})),U(!0)},[T]),K=(0,a.useCallback)(()=>V({rule:eP.aP.rule,fitMode:eP.aP.fitMode,hAlign:eP.aP.hAlign,vAlign:eP.aP.vAlign,xOffset:50,yOffset:50,designWidthPct:null,designHeightPct:null,maxWidth:null,maxHeight:null,minWidth:null,minHeight:null,lockAspectRatio:!0,minDpi:null,margins:{top:0,bottom:0,left:0,right:0}}),[V]),q=(0,a.useRef)(null),G=(0,a.useRef)(null);(0,nP.N)({enabled:A,scope:"window",shortcuts:{"mod+z":e=>{e.preventDefault(),T.canUndo&&T.undo()},"mod+shift+z":e=>{e.preventDefault(),T.canRedo&&T.redo()},r:e=>{e.preventDefault(),K()},arrowup:e=>{var l;e.preventDefault(),null===(l=q.current)||void 0===l||l.call(q,0,-1,1)},arrowdown:e=>{var l;e.preventDefault(),null===(l=q.current)||void 0===l||l.call(q,0,1,1)},arrowleft:e=>{var l;e.preventDefault(),null===(l=q.current)||void 0===l||l.call(q,-1,0,1)},arrowright:e=>{var l;e.preventDefault(),null===(l=q.current)||void 0===l||l.call(q,1,0,1)},"shift+arrowup":e=>{var l;e.preventDefault(),null===(l=q.current)||void 0===l||l.call(q,0,-1,5)},"shift+arrowdown":e=>{var l;e.preventDefault(),null===(l=q.current)||void 0===l||l.call(q,0,1,5)},"shift+arrowleft":e=>{var l;e.preventDefault(),null===(l=q.current)||void 0===l||l.call(q,-1,0,5)},"shift+arrowright":e=>{var l;e.preventDefault(),null===(l=q.current)||void 0===l||l.call(q,1,0,5)},"mod+arrowup":e=>{var l;e.preventDefault(),null===(l=G.current)||void 0===l||l.call(G,0,-1,1)},"mod+arrowdown":e=>{var l;e.preventDefault(),null===(l=G.current)||void 0===l||l.call(G,0,1,1)},"mod+arrowleft":e=>{var l;e.preventDefault(),null===(l=G.current)||void 0===l||l.call(G,-1,0,1)},"mod+arrowright":e=>{var l;e.preventDefault(),null===(l=G.current)||void 0===l||l.call(G,1,0,1)},"mod+shift+arrowup":e=>{var l;e.preventDefault(),null===(l=G.current)||void 0===l||l.call(G,0,-1,5)},"mod+shift+arrowdown":e=>{var l;e.preventDefault(),null===(l=G.current)||void 0===l||l.call(G,0,1,5)},"mod+shift+arrowleft":e=>{var l;e.preventDefault(),null===(l=G.current)||void 0===l||l.call(G,-1,0,5)},"mod+shift+arrowright":e=>{var l;e.preventDefault(),null===(l=G.current)||void 0===l||l.call(G,1,0,5)}}});let Y=()=>{W?B(!0):E()},Q=null!==(l=N.rule)&&void 0!==l?l:"cover"===N.fitMode?"fill_to_print_area":"max_width",J=null!==(t=N.unit)&&void 0!==t?t:"inches",ee=null!==(i=N.margins)&&void 0!==i?i:{top:0,bottom:0,left:0,right:0},el=null===(r=N.snapEnabled)||void 0===r||r,[et,en]=(0,a.useState)({x:null,y:null,w:null,h:null}),ei=(0,eP.Cf)(N,z),er=(0,eP.Eo)(ei),eo=er.widthIn,ea=er.heightIn,ed=er.known,es=(null!=(R=null!==(d=null!==(o=null==ei?void 0:ei.name)&&void 0!==o?o:N.printArea)&&void 0!==d?d:"Front")?R:"").replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase()),eu=function(e){let l=(0,eP.Eo)(e);return l.known?"".concat(parseFloat(l.widthIn.toFixed(2))," \xd7 ").concat(parseFloat(l.heightIn.toFixed(2))," in"):null}(ei),ec=(0,eP.hO)(z,ei,N.printArea),ep="string"==typeof ec&&ec.length>0,[ev,eh]=(0,a.useState)(!1);(0,a.useEffect)(()=>{eh(!1)},[ec]);let ef=null!==(s=null==M?void 0:M.width)&&void 0!==s?s:null,ex=null!==(u=null==M?void 0:M.height)&&void 0!==u?u:null,eg=ef&&ex?ef/ex:eo/ea,em=ea/eo*eg,ey=eo/ea,eb=640,ej=640/ey;ej>640&&(ej=640,eb=640*ey),eb=Math.round(eb),ej=Math.round(ej);let e_=e=>{let l=parseFloat(null!=e?e:eo);return"cm"===J?l/2.54:"mm"===J?l/25.4:"px"===J?l/300:l},ew=e=>"cm"===J?2.54*e:"mm"===J?25.4*e:"px"===J?300*e:e,eS=eo/ea,{w:ek,h:eI}=(0,eP.QV)(N,{printAreaWidthIn:eo,printAreaHeightIn:ea,fileAspectRatio:eg}),{zoom:eC,setZoom:eZ,pan:eA,spaceHeld:eE,isPanning:eM,reset:ez,wheelRef:eD,panRef:eL}=(0,nZ.M)({min:.1,max:4,initial:.7}),eO=[{value:"default",label:"Default",hex:"#EFEFEF"},{value:"white",label:"White",hex:"#FFFFFF"},{value:"black",label:"Black",hex:"#333333"},...ep?[{value:"garment",label:"Garment",hex:null}]:[]],[eF,eT]=(0,a.useState)("default"),eN=null!==(c=eO.find(e=>e.value===eF))&&void 0!==c?c:eO[0],[eW,eU]=(0,a.useState)(null),[eH,eB]=(0,a.useState)(null),[eV,eK]=(0,a.useState)(!1),[eq,eG]=(0,a.useState)(null),[eY,eQ]=(0,a.useState)(null),e$=(0,a.useRef)(null),eX=(0,a.useRef)(null),eJ=(0,a.useRef)(ek),e0=(0,a.useRef)(eI);(0,a.useEffect)(()=>{eJ.current=null!=eW?eW:ek},[eW,ek]),(0,a.useEffect)(()=>{e0.current=null!=eH?eH:eI},[eH,eI]),(0,a.useEffect)(()=>{eU(null),eB(null)},[N.printArea,N.designWidthPct,N.designHeightPct,N.maxWidth,N.maxHeight,N.unit,N.rule]);let e1=null!=eW?eW:ek,e5=null!=eH?eH:eI,e2=(0,eP.QB)(N,eo,ea),e3=e2.marginL_pct/100*eb,e4=e2.marginR_pct/100*eb,e7=e2.marginT_pct/100*ej,e6=e2.marginB_pct/100*ej,e8=eb-e3-e4,e9=ej-e7-e6,{rotatedWidthPct:le,rotatedHeightPct:ll,innerWidthPctOfOuter:lt,innerHe
1ightPctOfOuter:ln,innerLeftPctOfOuter:li,innerTopPctOfOuter:lr}=(0,eP.xK)({link:N,printAreaWidthIn:eo,printAreaHeightIn:ea,widthPct:e1,heightPct:e5}),[lo,la]=(0,a.useState)(!1),[ld,ls]=(0,a.useState)(null),[lu,lc]=(0,a.useState)(null),lp=(0,a.useRef)(null),lv=(0,a.useRef)(null),lh=null!==(p=N.xOffset)&&void 0!==p?p:"left"===N.hAlign?0:"right"===N.hAlign?100:50,lf=null!==(v=N.yOffset)&&void 0!==v?v:"top"===N.vAlign?0:"bottom"===N.vAlign?100:50,lx=Math.max(0,Math.min(100,lh)),lg=Math.max(0,Math.min(100,lf)),lm=null!=ld?ld:lx,ly=null!=lu?lu:lg;(0,a.useEffect)(()=>{lp.current=null!=ld?ld:lx},[ld,lx]),(0,a.useEffect)(()=>{lv.current=null!=lu?lu:lg},[lu,lg]),(0,a.useEffect)(()=>{ls(null),lc(null)},[N.xOffset,N.yOffset,N.hAlign,N.vAlign]);let lb=null!==(h=null==M?void 0:M.dpi)&&void 0!==h?h:null,lj=e1/100*eo,l_=e5/100*ea,lw=ef&&lj>0?Math.round(ef/lj):lb,lS=null!=lw?lw>=300?"high":lw>=150?"medium":"low":(null==M?void 0:M.highResolution)!=null?M.highResolution?"high":"medium":null,lk={minWidth:N.minWidth&&lj<e_(N.minWidth),maxWidth:N.maxWidth&&lj>e_(N.maxWidth),minHeight:N.minHeight&&l_<e_(N.minHeight),maxHeight:N.maxHeight&&l_>e_(N.maxHeight),minDpi:N.minDpi&&null!=lw&&lw<N.minDpi},lI=Object.values(lk).some(Boolean),lC=(0,a.useCallback)(e=>(0,eP.Re)(e,eo,ea),[eo,ea])(N),{minW:lZ,minH:lP,maxW:lR,maxH:lA,userMaxW:lE,userMaxH:lM}=lC,lz=lZ>eP.m5&&e1<=lZ+.05||lP>eP.m5&&e5<=lP+.05||lE<1/0&&e1>=lE-.05||lM<1/0&&e5>=lM-.05,lD=((null!==(f=ee.top)&&void 0!==f?f:0)/ea*100).toFixed(1),lL=((null!==(x=ee.bottom)&&void 0!==x?x:0)/ea*100).toFixed(1),lO=((null!==(g=ee.left)&&void 0!==g?g:0)/eo*100).toFixed(1),lF=((null!==(m=ee.right)&&void 0!==m?m:0)/eo*100).toFixed(1),lT=Object.values(ee).some(e=>(null!=e?e:0)>0),{designLeftPct:lN,designTopPct:lW}=(0,eP.O4)({link:N,printAreaWidthIn:eo,printAreaHeightIn:ea,rotatedWidthPct:le,rotatedHeightPct:ll,xOffsetPct:lm,yOffsetPct:ly});return q.current=(e,l,t)=>{let n={};0!==e&&(n.xOffset=parseFloat(Math.max(0,Math.min(100,lx+e*t)).toFixed(1))),0!==l&&(n.yOffset=parseFloat(Math.max(0,Math.min(100,lg+l*t)).toFixed(1))),V(n)},G.current=(e,l,t)=>{let n=e1,i=e5;0!==e&&(n=Math.max(2,e1+e*t)),0!==l&&(i=Math.max(2,e5+l*t)),0!==e&&0===l?i=n/em:0!==l&&0===e&&(n=i*em),V({designWidthPct:parseFloat(n.toFixed(2)),designHeightPct:parseFloat(i.toFixed(2)),rule:"fill_to_print_area"===Q?"max_width":Q})},(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($.Z,{open:A,onClose:Y,title:(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1.5,flex:1},children:[(0,n.jsx)("span",{children:"Design Placement Editor"}),(null==M?void 0:M.name)&&(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontWeight:400},children:M.name})]}),size:"xl",fullWidth:!0,noPadding:!0,PaperProps:{sx:{overflow:"hidden",boxShadow:"0 24px 64px rgba(0,0,0,0.35)",width:"min(1500px, 96vw)",maxWidth:"96vw",maxHeight:"92vh",display:"flex",flexDirection:"column"}},actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.25},children:[(0,n.jsx)(y.Z,{onClick:()=>eZ(e=>parseFloat((e-.1).toFixed(2))),sx:{cursor:"pointer",color:"var(--lv-text-secondary)",fontSize:16,lineHeight:1,px:.5,"&:hover":{color:"var(--lv-text-primary)"}},children:"â"}),(0,n.jsxs)(L.Z,{sx:{fontSize:10,fontWeight:600,color:"var(--lv-text-secondary)",minWidth:36,textAlign:"center"},children:[Math.round(100*eC),"%"]}),(0,n.jsx)(y.Z,{onClick:()=>eZ(e=>parseFloat((e+.1).toFixed(2))),sx:{cursor:"pointer",color:"var(--lv-text-secondary)",fontSize:16,lineHeight:1,px:.5,"&:hover":{color:"var(--lv-text-primary)"}},children:"+"})]}),(.7!==eC||0!==eA.x||0!==eA.y)&&(0,n.jsx)(_.Z,{title:"Reset zoom and pan",placement:"top",disableInteractive:!0,children:(0,n.jsx)("span",{children:(0,n.jsx)(w.f,{text:"Fit",color:"white-outline",width:"auto",padding:"px-2.5 py-1",textSize:"text-xs",noShadow:!0,onClick:ez})})}),(0,n.jsx)(_.Z,{title:el?"Snap enabled â click to disable (hold Shift while dragging to override)":"Enable snap-to-guides",placement:"top",disableInteractive:!0,children:(0,n.jsx)("span",{children:(0,n.jsx)(w.f,{text:el?"Snap":"Snap Off",color:el?"black":"white-outline",width:"auto",padding:"px-2.5 py-1",textSize:"text-xs",noShadow:!0,icon:(0,n.jsx)(nk.Z,{size:12}),onClick:()=>V({snapEnabled:!el})})})}),(0,n.jsx)(y.Z,{sx:{flexGrow:1}}),W&&(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)"},children:"Unsaved changes"}),(0,n.jsx)(w.f,{text:"Cancel",color:"white",width:"auto",className:"whitespace-nowrap",onClick:Y}),(0,n.jsx)(w.f,{text:"Save",color:"purple",width:"auto",className:"whitespace-nowrap",onClick:()=>{var e,l,t,n,i,r,o,a,d,s,u,c,p,v,h,f,x,g,m,y;let b=null!==(e=N.rule)&&void 0!==e?e:"cover"===N.fitMode?"fill_to_print_area":"max_width",j=e=>"number"==typeof e&&isFinite(e)?parseFloat(e.toFixed(2)):null,_=null!==(l=N.designWidthPct)&&void 0!==l?l:j(e1),w=null!==(t=N.designHeightPct)&&void 0!==t?t:j(e5),S=(0,eP.L2)({...N,rule:b,designWidthPct:_,designHeightPct:w});null==O||O({...N,printArea:null!==(i=null!==(n=N.printArea)&&void 0!==n?n:null==ei?void 0:ei.name)&&void 0!==i?i:"Front",rule:b,fitMode:S,angle:null!==(r=N.angle)&&void 0!==r?r:0,snapEnabled:null===(o=N.snapEnabled)||void 0===o||o,lockA
1spectRatio:!0,hAlign:null!==(a=N.hAlign)&&void 0!==a?a:"center",vAlign:null!==(d=N.vAlign)&&void 0!==d?d:"center",xOffset:null!==(s=N.xOffset)&&void 0!==s?s:lx,yOffset:null!==(u=N.yOffset)&&void 0!==u?u:lg,margins:null!==(c=N.margins)&&void 0!==c?c:{top:0,bottom:0,left:0,right:0},minDpi:null!==(p=N.minDpi)&&void 0!==p?p:null,unit:null!==(v=N.unit)&&void 0!==v?v:"inches",designWidthPct:null!==(h=N.designWidthPct)&&void 0!==h?h:j(e1),designHeightPct:null!==(f=N.designHeightPct)&&void 0!==f?f:j(e5),widthIn:j(lj),heightIn:j(l_),minWidth:null!==(x=N.minWidth)&&void 0!==x?x:null,maxWidth:null!==(g=N.maxWidth)&&void 0!==g?g:null,minHeight:null!==(m=N.minHeight)&&void 0!==m?m:null,maxHeight:null!==(y=N.maxHeight)&&void 0!==y?y:null}),E()}})]}),children:(0,n.jsxs)(y.Z,{sx:{display:"flex",flex:1,overflow:"hidden",minHeight:400},children:[(0,n.jsxs)(y.Z,{ref:eL,sx:{flex:1,minWidth:0,minHeight:0,bgcolor:"var(--lv-bg-elevated)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",position:"relative",p:3,overflow:"hidden",cursor:eM?"grabbing":eE?"grab":"default"},children:[(0,n.jsx)(y.Z,{ref:eD,sx:{display:"flex",flexDirection:"column",alignItems:"center",transform:"translate(".concat(eA.x,"px, ").concat(eA.y,"px) scale(").concat(eC,")"),transformOrigin:"center center",transition:eM?"none":"transform 0.1s",flexShrink:0},children:(0,n.jsxs)(y.Z,{ref:e$,tabIndex:0,sx:{width:eb,height:ej,position:"relative",overflow:"visible",bgcolor:eN.hex,backgroundImage:eR.Cw,backgroundSize:eR.w,border:"1px solid var(--lv-border-default)",borderRadius:"3px",boxShadow:"0 2px 12px rgba(0,0,0,0.10)",outline:"none","&:focus-visible":{boxShadow:"0 2px 12px rgba(0,0,0,0.10), 0 0 0 2px rgba(0, 156, 255,0.45)"}},children:["garment"===eF&&ep&&!ev&&(0,n.jsx)(y.Z,{component:"img",src:ec,alt:"","aria-hidden":"true",draggable:!1,onError:()=>eh(!0),sx:{position:"absolute",inset:0,width:"100%",height:"100%",objectFit:"contain",opacity:.9,pointerEvents:"none",userSelect:"none",zIndex:0}}),lT&&(0,n.jsxs)(n.Fragment,{children:[(null!==(b=ee.top)&&void 0!==b?b:0)>0&&(0,n.jsx)(y.Z,{sx:{position:"absolute",top:"".concat(lD,"%"),left:0,right:0,height:"1px",bgcolor:"rgba(99,102,241,0.4)",pointerEvents:"none"}}),(null!==(j=ee.bottom)&&void 0!==j?j:0)>0&&(0,n.jsx)(y.Z,{sx:{position:"absolute",bottom:"".concat(lL,"%"),left:0,right:0,height:"1px",bgcolor:"rgba(99,102,241,0.4)",pointerEvents:"none"}}),(null!==(S=ee.left)&&void 0!==S?S:0)>0&&(0,n.jsx)(y.Z,{sx:{position:"absolute",left:"".concat(lO,"%"),top:0,bottom:0,width:"1px",bgcolor:"rgba(99,102,241,0.4)",pointerEvents:"none"}}),(null!==(k=ee.right)&&void 0!==k?k:0)>0&&(0,n.jsx)(y.Z,{sx:{position:"absolute",right:"".concat(lF,"%"),top:0,bottom:0,width:"1px",bgcolor:"rgba(99,102,241,0.4)",pointerEvents:"none"}})]}),(0,n.jsx)(y.Z,{sx:{position:"absolute",left:"".concat(lN,"%"),top:"".concat(lW,"%"),width:"".concat(le,"%"),height:"".concat(ll,"%"),pointerEvents:"none",userSelect:"none",opacity:.3,overflow:"visible"},children:(0,n.jsx)(y.Z,{sx:{position:"absolute",left:"".concat(li,"%"),top:"".concat(lr,"%"),width:"".concat(lt,"%"),height:"".concat(ln,"%"),transform:"rotate(".concat(null!==(I=N.angle)&&void 0!==I?I:0,"deg)"),transformOrigin:"center center"},children:(null==M?void 0:M.thumbnail)?(0,n.jsx)(y.Z,{component:"img",src:M.thumbnail,alt:null!==(C=null==M?void 0:M.name)&&void 0!==C?C:"Design",draggable:!1,sx:{width:"100%",height:"100%",objectFit:"contain",display:"block",pointerEvents:"none"}}):(0,n.jsx)(L.Z,{sx:{fontSize:18,fontWeight:300,color:"#93b4d4",textAlign:"center",userSelect:"none",p:1},children:"Design"})})}),(0,n.jsx)(y.Z,{sx:{position:"absolute",inset:0,overflow:"hidden",pointerEvents:"none"},children:(0,n.jsx)(y.Z,{sx:{position:"absolute",left:"".concat(lN,"%"),top:"".concat(lW,"%"),width:"".concat(le,"%"),height:"".concat(ll,"%"),pointerEvents:"none",userSelect:"none",overflow:"visible"},children:(0,n.jsx)(y.Z,{sx:{position:"absolute",left:"".concat(li,"%"),top:"".concat(lr,"%"),width:"".concat(lt,"%"),height:"".concat(ln,"%"),transform:"rotate(".concat(null!==(Z=N.angle)&&void 0!==Z?Z:0,"deg)"),transformOrigin:"center center"},children:(null==M?void 0:M.thumbnail)?(0,n.jsx)(y.Z,{component:"img",src:M.thumbnail,alt:null!==(P=null==M?void 0:M.name)&&void 0!==P?P:"Design",draggable:!1,sx:{width:"100%",height:"100%",objectFit:"contain",display:"block",pointerEvents:"none"}}):(0,n.jsx)(L.Z,{sx:{fontSize:18,fontWeight:300,color:"#93b4d4",textAlign:"center",userSelect:"none",p:1},children:"Design"})})})}),(0,n.jsx)(nV,{canvasW:eb,canvasH:ej,effectiveWidthPct:le,effectiveHeightPct:ll,effectiveX:lm,effectiveY:ly,marginL_px:e3,marginT_px:e7,usableW_px:e8,usableH_px:e9,dragging:eV,moveDragging:lo,ghostRect:eq,dragDimLabel:eY,snapGuides:et,constraintActive:lz,onResizeStart:(e,l)=>{var t;e.preventDefault(),e.stopPropagation();let n=e.clientX,i=e.clientY,r=e1/100*eb,o=e5/100*ej,a=e3+lm/100*(e8-r),d=e7+ly/100*(e9-o),s=null!==(t=({top:{fx:null,fy:1},bottom:{fx:null,fy:0}
1,left:{fx:1,fy:null},right:{fx:0,fy:null},"top-left":{fx:1,fy:1},"top-right":{fx:0,fy:1},"bottom-left":{fx:1,fy:0},"bottom-right":{fx:0,fy:0}})[l.edge])&&void 0!==t?t:{fx:null,fy:null},u=null!=s.fx?a+s.fx*r:null,c=null!=s.fy?d+s.fy*o:null;eG({x:a,y:d,w:r,h:o}),eX.current={startX:n,startY:i,startWPct:e1,startHPct:e5,handle:l},eK(!0);let p=e=>{if(!eX.current||!e$.current)return;let t=e$.current.getBoundingClientRect(),r=e.clientX-n,o=e.clientY-i,a=r/t.width*100,d=o/t.height*100,p=e1,v=e5;("x"===l.axis||"xy"===l.axis)&&(p=Math.max(2,e1+a*(l.edge.includes("left")?-1:1))),("y"===l.axis||"xy"===l.axis)&&(v=Math.max(2,e5+d*(l.edge.includes("top")?-1:1))),"x"===l.axis?v=p/em:"y"===l.axis?p=v*em:v=p/em,p<2&&(v=(p=2)/em),v<2&&(p=(v=2)*em);let h=null,f=null;if(el){let e=nA.filter(e=>e>=lC.minW&&e<=lC.maxW),t=nA.filter(e=>e>=lC.minH&&e<=lC.maxH);if("x"===l.axis||"xy"===l.axis){let l=(0,nR.n)(p,e,1.5);l.snapped&&(p=l.value,h=l.target)}if("y"===l.axis||"xy"===l.axis){let e=(0,nR.n)(v,t,1.5);e.snapped&&(v=e.value,f=e.target)}(null!=h||null!=f)&&(null!=h&&null==f?v=p/em:null!=f&&null==h&&(p=v*em))}en(e=>({...e,w:h,h:f}));let x=e1/e5,g=(0,eP.oW)(p,v,!0,x,lC);p=g.w,v=g.h,eJ.current=p,e0.current=v,eU(p),eB(v);let m=p/100*eb,y=v/100*ej;if(null!=u){let e=e8-m;if(Math.abs(e)>.5){let l=Math.max(0,Math.min(100,(u-e3-s.fx*m)*100/e));lp.current=l,ls(l)}}if(null!=c){let e=e9-y;if(Math.abs(e)>.5){let l=Math.max(0,Math.min(100,(c-e7-s.fy*y)*100/e));lv.current=l,lc(l)}}let b=p/100*eo,j=v/100*ea;eQ({width:"".concat(ew(b).toFixed(1)," ").concat(J),height:"".concat(ew(j).toFixed(1)," ").concat(J)})},v=()=>{var e;let l={designWidthPct:parseFloat(eJ.current.toFixed(2)),designHeightPct:parseFloat((null!==(e=e0.current)&&void 0!==e?e:e5).toFixed(2))};null!=lp.current&&(l.xOffset=parseFloat(lp.current.toFixed(1))),null!=lv.current&&(l.yOffset=parseFloat(lv.current.toFixed(1))),"fill_to_print_area"===Q&&(l.rule="max_width"),V(l),en({x:null,y:null,w:null,h:null}),eX.current=null,eK(!1),eG(null),eQ(null),ls(null),lc(null),window.removeEventListener("mousemove",p),window.removeEventListener("mouseup",v)};window.addEventListener("mousemove",p),window.addEventListener("mouseup",v)},onMoveStart:e=>{var l,t;if(0!==e.button)return;e.preventDefault(),e.stopPropagation();let n=null!==(l=lp.current)&&void 0!==l?l:lx,i=null!==(t=lv.current)&&void 0!==t?t:lg,r=e.clientX,o=e.clientY,a=e1/100*eb,d=e5/100*ej,s=e3+n/100*(e8-a),u=e7+i/100*(e9-d),c=e8-a,p=e9-d;la(!0);let v=e=>{if(!e$.current)return;let l=e$.current.getBoundingClientRect(),t=(e.clientX-r)*eb/l.width,a=(e.clientY-o)*ej/l.height,d=Math.abs(c)>.5?Math.max(0,Math.min(100,(s+t-e3)/c*100)):n,v=Math.abs(p)>.5?Math.max(0,Math.min(100,(u+a-e7)/p*100)):i,h=null,f=null;if(el&&!e.shiftKey){var x,g,m,y;let e=[];(null!==(x=ee.left)&&void 0!==x?x:0)>0&&e.push(ee.left/eo*100),(null!==(g=ee.right)&&void 0!==g?g:0)>0&&e.push(100-ee.right/eo*100);let l=[];(null!==(m=ee.top)&&void 0!==m?m:0)>0&&l.push(ee.top/ea*100),(null!==(y=ee.bottom)&&void 0!==y?y:0)>0&&l.push(100-ee.bottom/ea*100);let t=[0,33.33,50,66.67,100,...e],n=[0,33.33,50,66.67,100,...l],i=(0,nR.n)(d,t,1.5),r=(0,nR.n)(v,n,1.5);i.snapped&&(d=i.value,h=i.target),r.snapped&&(v=r.value,f=r.target)}en(e=>({...e,x:h,y:f})),lp.current=d,lv.current=v,ls(d),lc(v)},h=()=>{var e,l;V({xOffset:parseFloat((null!==(e=lp.current)&&void 0!==e?e:lx).toFixed(1)),yOffset:parseFloat((null!==(l=lv.current)&&void 0!==l?l:lg).toFixed(1))}),ls(null),lc(null),la(!1),en({x:null,y:null,w:null,h:null}),window.removeEventListener("mousemove",v),window.removeEventListener("mouseup",h)};window.addEventListener("mousemove",v),window.addEventListener("mouseup",h)}})]})}),(0,n.jsxs)(y.Z,{sx:{position:"absolute",bottom:12,left:14,display:"flex",alignItems:"center",gap:.75},children:[(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-secondary)"},children:"Preview:"}),(0,n.jsx)(X.Z,{cozy:!0,value:eF,onChange:e=>eT(e.target.value),options:eO.map(e=>({value:e.value,label:e.label})),fullWidth:!1})]})]}),(0,n.jsx)(nB,{localLink:N,update:V,unit:J,violations:lk,hasViolation:lI,deriveConstraint:(e,l)=>(0,eP.$0)(N,e,l,{printAreaWidthIn:eo,printAreaHeightIn:ea,fileAspectRatio:eg}),margins:ee,effectiveWidthIn:lj,effectiveHeightIn:l_,printAreaWidthIn:eo,printAreaHeightIn:ea,areaNameLabel:es,dimLabel:eu,dimsKnown:ed,fileW:ef,fileH:ex,dpiStatus:lS,calcDpi:lw,DPI_META:{high:{label:"High Res",color:"#3ebf8f"},medium:{label:"Medium Res",color:"#ffa000"},low:{label:"Low Res",color:"#ef4444"}},isFill:"fill_to_print_area"===Q,fileAspectRatio:eg,printAR:eS,history:T,handleReset:K})]})}),(0,n.jsx)(F.Z,{open:H,onClose:()=>B(!1),onConfirm:()=>{B(!1),E()},title:"Discard changes?",message:"You have unsaved changes to the design placement. Are you sure you want to close?",confirmText:"Discard",variant:"danger"})]})}nW.flatMap(e=>{let{label:l,minField:t,maxField:n}=e;return[{field:t,label:"Min ".concat(l)},{field:n,label:"Max ".concat(l)}]});var nq=t(69579);function nG(e){var l,t,n,i;let r=(null!=e?e:[]).filter(e=>!e._synthetic);return null!==(i=null!==(n=null!==(t=null!==(l=r.find(e=>e._original_design_variable))&&void 0!==l?l:r.find(e=>e.is_design_variable))&&void 0!==t?t:r.find(e=>"colors"===e.id))&&void 0!==n?n:r[0])&&void 0!==i?i:null}function nY(e,l){var t,n;let i=null!==(t=null==e?void 0:e.print_areas)&&void 0!==t?t:[];if(!i.length)return null;let r=e=>String(null!=e?e:"").toLowerCase().trim().replace(/\s+/g,"_"),o=r(l),a=i.findIndex(e=>r(e.name)===o||r(e.position)===o),d=a>=0?a:1===i.length?0:-1;return d<0?null:null!==(n=i[d].id)&&void 0!==n?n:"pa_".concat(d+1)}let nQ=e=>String(e),n$=e=>new Set((null!=e?e:[]).map(nQ)),nX={PROCESSING:"processing",NOT_POD_READY:"not_pod_ready"};var nJ=t(70740),n0=t(4604),n1=t(18660),n5=t(13435),n2=t(67326);let n3="Attach at least one design file to this product before publishing.";function n4(e,l,t){var n,i,r;let o=(0,nq.Ht)(e);return o?o.message:"".concat(l," ").concat(null!==(r=null==e?void 0:null===(i=e.response)||void 0===i?void 0:null===(n=i.data)||void 0===n?void 0:n.message)&&void 0!==r?r:t)}let n7=(0,z.default)(()=>Promise.all([t.e(3407),t.e(4085),t.e(6569),t.e(405),t.e(5607),t.e(9784)]).then(t.bind(t,33329)),{loadableGenerated:{webpack:()=>[33329]},ssr:!1}),n6=(e,l)=>{var t;let n=(null==e?void 0:null===(t=e.file)||void 0===t?void 0:t.id)!=null?"asset:".concat(e.file.id):"item:".concat(null==e?void 0:e.id);return"".concat(null!=l?l:"preset",":").concat(n)},n8=e=>{let l=String(null!=e?e:"");return/s$/i.test(l)?l:"".concat(l,"s")};function n9(e,l,t,n,i,r){if(""===t||null==t){r({...e,[l]:t});return}let o=(0,eP.ED)(e,n,i),a=(0,eP.$0)(e,l,t,o);r({...e,...a})}function ie(e){var l;let{link:t,dim:i,product:r,file:o,onChange:a}=e;return(0,n.jsx)(nH,{label:i.label,minValue:t[i.minField],maxValue:t[i.maxField],onMinChange:e=>n9(t,i.minField,e,r,o,a),onMaxChange:e=>n9(t,i.maxField,e,r,o,a),unit:null!==(l=t.unit)&&void 0!==l?l:"inches",unitOptions:["inches","cm","mm","px"].map(e=>({value:e,label:e})),onUnitChange:e=>a({...t,unit:e}),onRemove:()=>
1a({...t,[i.minField]:null,[i.maxField]:null})})}function il(e){return"Design ".concat(e<26?String.fromCharCode(65+e):String(e+1))}function it(e){if(null==e)return null;let l=String(e).match(/^colou?r[-_](.*)$/i);if(!l)return null;let t=l[1].toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_|_$/g,"");return t?"color_".concat(t):null}function ii(e,l){if(!e)return e;let t=function(e,l){var t;if(!e||"all"===e)return e;let n=e.option_ids;if(!Array.isArray(n)||0===n.length)return e;let i=nG(null==l?void 0:l.variations),r=null!==(t=null==i?void 0:i.options)&&void 0!==t?t:[];if(!r.length)return e;let o=new Set(r.map(e=>String(e.id))),a=new Map;r.forEach(e=>{let l=it(e.id);l&&!a.has(l)&&a.set(l,e.id)});let d=!1,s=n.map(e=>{if(o.has(String(e)))return e;let l=it(e);return l&&a.has(l)?(d=!0,a.get(l)):e});return d?{...e,option_ids:s}:e}(e.colorMapping,l);return t===e.colorMapping?e:{...e,colorMapping:t}}function ir(e){let{printAreas:l,productId:t,fileId:n,allFileLinks:i}=e,r=null!=l?l:[],o=e=>!!t&&Object.entries(null!=i?i:{}).some(l=>{let[i,r]=l;return eA(i)!==eA(n)&&(null!=r?r:[]).some(l=>l.productId===t&&l.printArea===e&&("all"===l.colorMapping||l.colorMapping&&"object"==typeof l.colorMapping&&"specific"!==l.colorMapping.type))}),a=(0,nJ.q)(r),d=(null==a?void 0:a.name)||(null==a?void 0:a.position)||"front",s=r.length>0;for(let e of r)if(!o(e.name||e.position||"front")){s=!1;break}return{chosenAreaObj:a,areaName:d,allClaimed:s,colorMapping:t&&Object.entries(null!=i?i:{}).some(e=>{let[l,i]=e;return eA(l)!==eA(n)&&(null!=i?i:[]).some(e=>e.productId===t)})?{type:"specific",option_ids:[]}:"all"}}let io=["front","back","left_sleeve","right_sleeve"];function ia(e){if("string"!=typeof e)return null;let l=e.replace("#","");if(3!==l.length&&6!==l.length)return null;let t=parseInt(3===l.length?l.split("").map(e=>e+e).join(""):l,16);return Number.isNaN(t)?null:.299*(t>>16&255)+.587*(t>>8&255)+.114*(255&t)>140}let id={width:27,height:27,borderRadius:"10px",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",bgcolor:"var(--lv-bg-card)",border:"0.5px solid var(--lv-border-default)",boxShadow:"var(--lv-shadow-sm)",color:"var(--lv-text-secondary)","&:hover":{color:"var(--lv-text-primary)"}};function is(e){let{variant:l}=e;return"placeholder"===l?(0,n.jsx)(y.Z,{sx:{width:60,height:60,borderRadius:"11px",flexShrink:0,bgcolor:"var(--lv-bg-card)",border:"1.5px dashed var(--lv-border-default)",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",color:"var(--lv-selected)"},children:(0,n.jsx)(ng.Z,{size:22,"aria-hidden":"true"})}):(0,n.jsx)(y.Z,{sx:{width:60,height:60,borderRadius:"11px",flexShrink:0,bgcolor:"var(--lv-text-primary)",border:"1px solid var(--lv-border-default)",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden"},children:(0,n.jsxs)(L.Z,{sx:{fontSize:8,color:"var(--lv-bg-card)",fontWeight:700,textAlign:"center",lineHeight:1.2,px:.5},children:["MOMENT","\n","FACTORY"]})})}let iu="var(--lv-selected)",ic="var(--lv-text-secondary)",ip=[{value:"contain",tooltip:"Fit",icon:e=>{let l=e?iu:ic;return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 12 12",fill:"none",children:[(0,n.jsx)("path",{d:"M7.36 6.03H10.01M10.01 6.03L8.95 4.97M10.01 6.03L8.95 7.09M3.12 7.09L2.06 6.03M2.06 6.03L3.12 4.97M2.06 6.03H4.71",stroke:l,strokeWidth:"0.62",strokeLinecap:"round",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M1 3.22V2.11C1 1.5 1.5 1 2.11 1H3.22M8.78 1H9.89C10.5 1 11 1.5 11 2.11V3.22M11 8.78V9.89C11 10.5 10.5 11 9.89 11H8.78M3.22 11H2.11C1.5 11 1 10.5 1 9.89V8.78",stroke:l,strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round"})]})}},{value:"cover",tooltip:"Cover",icon:e=>{let l=e?iu:ic;return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 12 12",fill:"none",children:[(0,n.jsx)("path",{d:"M6.97 5.1L8.85 3.22M8.85 3.22H7.35M8.85 3.22V4.72M5.1 5.1L3.22 3.22M3.22 3.22H4.72M3.22 3.22V4.72M7.35 8.85H8.85M8.85 8.85V7.35M8.85 8.85L6.97 6.97M4.72 8.85H3.22M3.22 8.85V7.35M3.22 8.85L5.1 6.97",stroke:l,strokeWidth:"0.62",strokeLinecap:"round",strokeLinejoin:"round"}),(0,n.jsx)("path",{d:"M1 3.22V2.11C1 1.5 1.5 1 2.11 1H3.22M8.78 1H9.89C10.5 1 11 1.5 11 2.11V3.22M11 8.78V9.89C11 10.5 10.5 11 9.89 11H8.78M3.22 11H2.11C1.5 11 1 10.5 1 9.89V8.78",stroke:l,strokeWidth:"1.1",strokeLinecap:"round",strokeLinejoin:"round"})]})}}],iv=[{value:"left",tooltip:"Align left",icon:e=>{let l=e?iu:ic;return(0,n.jsx)("svg",{width:"12",height:"10",viewBox:"0 0 10 8",fill:"none",children:(0,n.jsx)("path",{d:"M0.5 7.5V0.5M5.5 1L2.5 4M2.5 4L5.5 7M2.5 4H9.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}}
1,{value:"center",tooltip:"Center",icon:e=>{let l=e?iu:ic;return(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 11 11",fill:"none",children:(0,n.jsx)("path",{d:"M5.5 0.5V10.5M3.5 4.5H1.5C1.23 4.5 1 4.27 1 4V2.5C1 1.95 1.45 1.5 2 1.5H3.5M7.5 4.5H9.5C9.77 4.5 10 4.27 10 4V2.5C10 1.95 9.55 1.5 9 1.5H7.5M3.5 9.5H3C2.45 9.5 2 9.05 2 8.5V7.5C2 6.95 2.45 6.5 3 6.5H3.5M7.5 6.5H8C8.55 6.5 9 6.95 9 7.5V8.5C9 9.05 8.55 9.5 8 9.5H7.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}},{value:"right",tooltip:"Align right",icon:e=>{let l=e?iu:ic;return(0,n.jsx)("svg",{width:"12",height:"10",viewBox:"0 0 10 8",fill:"none",children:(0,n.jsx)("path",{d:"M7.5 4H0.5M7.5 4L4.5 7M7.5 4L4.5 1M9.5 0.5V7.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}}],ih=[{value:"top",tooltip:"Align top",icon:e=>{let l=e?iu:ic;return(0,n.jsx)("svg",{width:"10",height:"12",viewBox:"0 0 8 10",fill:"none",children:(0,n.jsx)("path",{d:"M0.5 0.5H7.5M7 5.5L4 2.5M4 2.5L1 5.5M4 2.5V9.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}},{value:"center",tooltip:"Center vertical",icon:e=>{let l=e?iu:ic;return(0,n.jsx)("svg",{width:"13",height:"13",viewBox:"0 0 11 11",fill:"none",children:(0,n.jsx)("path",{d:"M0.5 5.5H10.5M4.5 7.5V9.5C4.5 9.77 4.27 10 4 10H2.5C1.95 10 1.5 9.55 1.5 9V7.5M4.5 3.5V1.5C4.5 1.23 4.27 1 4 1H2.5C1.95 1 1.5 1.45 1.5 2V3.5M9.5 7.5V8C9.5 8.55 9.05 9 8.5 9H7.5C6.95 9 6.5 8.55 6.5 8V7.5M6.5 3.5V3C6.5 2.45 6.95 2 7.5 2H8.5C9.05 2 9.5 2.45 9.5 3V3.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}},{value:"bottom",tooltip:"Align bottom",icon:e=>{let l=e?iu:ic;return(0,n.jsx)("svg",{width:"10",height:"12",viewBox:"0 0 8 10",fill:"none",children:(0,n.jsx)("path",{d:"M4 7.5V0.5M4 7.5L1 4.5M4 7.5L7 4.5M7.5 9.5H0.5",stroke:l,strokeLinecap:"round",strokeLinejoin:"round"})})}}];function ix(){return(0,n.jsx)(y.Z,{sx:{borderTop:"1px solid var(--lv-border-default)",mx:-2,my:1}})}function ig(e){var l,t,i,r,o,d,s,u;let{podProducts:c,link:p,onChange:v,onRemove:h,conflictColorIds:f,claimedByOther:x,hasOtherLinkAtSameArea:g,onTransferOption:m,onSetColorMapping:b,file:j,listingId:w,openCanvasSignal:S=!1,onCanvasOpenConsumed:k}=e,[I,C]=(0,a.useState)(!1);(0,a.useEffect)(()=>{S&&(C(!0),null==k||k())},[S]);let[Z,P]=(0,a.useState)(!1),[R,A]=(0,a.useState)(null),[E,M]=(0,a.useState)(null),[z,D]=(0,a.useState)(!1),O=null!==(l=c.find(e=>e.product.id===p.productId))&&void 0!==l?l:null,F=(0,a.useRef)(null),T=(0,a.useRef)(null),N=()=>{clearTimeout(F.current)},W=()=>{D(!1),M(null)};(0,a.useEffect)(()=>{if(!E||z)return;let e=null,l=e=>e?e.getBoundingClientRect():null,t=(e,l,t)=>e&&l>=e.left&&l<=e.right&&t>=e.top&&t<=e.bottom,n=n=>{let i=document.querySelector('[data-lv-settings-menu="true"]'),r=l(E),o=l(i),a=null;r&&o&&o.top>=r.bottom&&(a={left:Math.min(r.left,o.left)-6,right:Math.max(r.right,o.right)+6,top:r.bottom,bottom:o.top}),t(r,n.clientX,n.clientY)||t(o,n.clientX,n.clientY)||t(a,n.clientX,n.clientY)?e&&(clearTimeout(e),e=null):e||(e=setTimeout(()=>M(null),180))};return document.addEventListener("mousemove",n),()=>{document.removeEventListener("mousemove",n),e&&clearTimeout(e)}},[E,z]);let U=null!==(t=null==O?void 0:O.product)&&void 0!==t?t:null,H=nG(null==U?void 0:U.variations),B=null!==(i=null==H?void 0:H.id)&&void 0!==i?i:"colors",V=(null==H?void 0:H.label)||("colors"===B?"Color":"sizes"===B?"Size":B),K="colors"===B,q=(null!==(r=null==H?void 0:H.options)&&void 0!==r?r:[]).filter(e=>{var l,t;return null==O?void 0:null===(t=O.selection)||void 0===t?void 0:null===(l=t[B])||void 0===l?void 0:l[e.id]}),G=(0,a.useMemo)(()=>U?t9(U):null,[U]),Y=(0,a.useMemo)(()=>{var e,l,t,n;if(!U)return null;let i=null===(e=U.supplier)||void 0===e?void 0:e.slug,r=null!==(n=null===(l=U.supplier)||void 0===l?void 0:l.name)&&void 0!==n?n:i?i.charAt(0).toUpperCase()+i.slice(1):null,o=[];r&&o.push(r);let a=null===(t=U.provider)||void 0===t?void 0:t.name;a&&o.push(a);let d=t8(U);return d&&o.push("Ships in ".concat(d)),o.length?o.join(" ⢠"):null},[U]);return(0,n.jsxs)(y.Z,{sx:{border:"1px solid var(--lv-border-default)",borderRadius:"22px",p:2,bgcolor:"var(--lv-bg-card)",display:"flex",flexDirection:"column",gap:"10px"},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:500,color:"var(--lv-text-primary)"},children:"Linked Product"}),(0,n.jsx)(_.Z,{title:"Remove link",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:h,sx:{fontSize:12,color:"var(--lv-text-secondary)",cursor:"pointer",lineHeight:1,"&:hover":{color:"var(--lv-error)"}},children:"â"})})]}),U&&(0,n.jsx)(y.Z,{sx:{"&:hover .title-info-icon":{opacity:.65}},children:(0,n.jsx)(tS.ZP,{product:U,tooltipContent:G,metaLabel:Y,metaIcon:U.supplier?(0,n.jsx)(tj,{supplier:U.supplier}):null,thumbSize:48,nameMode:tS.wD.MODEL})}),(0,n.jsx)(ix,{}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.75},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:500,color:"var(--lv-text-primary)"},children:V}),q.length>0&&(()=>{var e,l;let t=null!==(e=p.colorMapping)&&void 0!==e?e:"all",i=new Set("all"!==t&&t?(null!==(l=t.option_ids)&&void 0!==l?l:[]).map(String):[]),r="all"!==t&&t?q.filter(e=>i.has(String(e.id))).length:q.length;return(0,n.jsxs)(L.Z,{sx:{fontSize:11,fontWeight:500,lineHeight:1,px:.75,py:"2px",borderRadius:"6px",bgcolor:"var(--lv-bg-elevated)",color:"var(--lv-text-secondary)"},children:[r," / ",q.length]})})(),(null==f?void 0:f.size)>0&&(0,n.jsx)(_.Z,{title:"".concat(V," conflict â open settings to fix"),placement:"top",disableInteractive:!0,children:(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-error)",lineHeight:1,cursor:"default"},children:"â "})})]}),(0,n.jsx)(y.Z,{ref:T,onClick:()=>{N(),D(!0),T.current&&M(T.current)},onMouseEnter:()=>{clearTimeout(F.current),F.current=setTimeout(()=>{T.current&&M(T.current)},120)},sx:{...id,color:(null==f?void 0:f.size)>0?"var(--lv-error)":p.colorMapping&&"all"!==p.colorMapping?"var(--lv-brand)":"var(--lv-text-secondary)"},children:(0,n.jsx)(na.Z,{sx:{fontSize:14}})}),(()=>{var e,l;let t=null!==(e=p.colorMapping)&&void 0!==e?e:"all",i="all"===t||!t,r=i?q.map(e=>e.id):null!==(l=t.option_ids)&&void 0!==l?l:[],o=new Set(r.map(String)),a=e=>{let l=[...r];
1e.forEach(e=>{o.has(String(e))||l.push(e)});let t=new Set(l.map(String)),n=q.map(e=>e.id),i=n.length>0&&n.every(e=>t.has(String(e)));null==b||b(i?"all":{type:"specific",option_ids:l})},d=K?q.filter(e=>!1===ia(e.hex)).map(e=>e.id):[],s=K?q.filter(e=>!0===ia(e.hex)).map(e=>e.id):[],u=i||0===d.length||d.every(e=>o.has(String(e))),c=i||0===s.length||s.every(e=>o.has(String(e))),v=[{label:"Select all ".concat(n8(V.toLowerCase())),disabled:i,onClick:()=>null==b?void 0:b("all"),keepOpen:!0},...K?[{divider:!0},{label:"Add dark colors",disabled:u,onClick:()=>a(d),keepOpen:!0},{label:"Add light colors",disabled:c,onClick:()=>a(s),keepOpen:!0}]:[],{divider:!0},{label:"Clear selection",disabled:!i&&0===o.size||!g,onClick:()=>null==b?void 0:b({type:"specific",option_ids:[]}),keepOpen:!0},{divider:!0},{label:"More settingsâ¦",onClick:()=>P(!0)}];return(0,n.jsx)(e2.Z,{anchorEl:E,open:!!E,onClose:(e,l)=>{if("backdropClick"===l){let l=T.current,t=!1;if(l&&(null==e?void 0:e.clientX)!=null){let n=l.getBoundingClientRect();t=e.clientX>=n.left&&e.clientX<=n.right&&e.clientY>=n.top&&e.clientY<=n.bottom}if(t){z?W():D(!0);return}}W()},anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},minWidth:180,items:v,paperProps:{"data-lv-settings-menu":"true"}})})()]}),(0,n.jsx)(y.Z,{sx:{display:"flex",flexWrap:"wrap",gap:0},children:q.length>0?q.map(e=>{var l,t,i,r;let o=null!==(l=p.colorMapping)&&void 0!==l?l:"all",a="all"===o||(null!==(t=null==o?void 0:o.option_ids)&&void 0!==t?t:[]).some(l=>String(l)===String(e.id)),d=a&&null!==(i=null==f?void 0:f.has(String(e.id)))&&void 0!==i&&i,s=null==x?void 0:x[e.id],u=!a&&!!s;return(0,n.jsx)(_.Z,{title:d?"".concat(e.label," â also claimed by another design on this print area"):u?"Claimed by ".concat(s.fileLabel,". Click to move here."):"",placement:"top",disableInteractive:!0,children:(0,n.jsxs)(y.Z,{onClick:u?()=>null==m?void 0:m(s.fileId,s.linkIdx,e.id):void 0,sx:{display:"flex",alignItems:"center",gap:"7px",px:"8px",py:"6px",borderRadius:"9px",opacity:a?1:u?.3:.4,filter:u?"grayscale(1)":void 0,cursor:u?"pointer":"default",transition:"opacity 0.15s, background-color 0.15s","&:hover":u?{opacity:1,bgcolor:"var(--lv-bg-hover)"}:void 0},children:[(0,n.jsx)(tA.Z,{hex:K?null!==(r=e.hex)&&void 0!==r?r:"var(--lv-text-tertiary)":void 0,size:13,borderRadius:K?void 0:"3px",sx:d?{border:"1.5px solid var(--lv-error)",outline:"1px solid var(--lv-error-bg)",outlineOffset:"1px"}:K?{boxShadow:"inset 0 0 0 0.25px #fff"}:void 0}),(0,n.jsx)(L.Z,{sx:{fontSize:13,fontWeight:500,color:"var(--lv-text-primary)",lineHeight:1},children:e.label})]})},e.id)}):(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-disabled)"},children:"No options available"})}),(null==f?void 0:f.size)>0&&(0,n.jsxs)(L.Z,{sx:{fontSize:10,color:"var(--lv-error)",mt:.5},children:[f.size," option",1!==f.size?"s":""," also assigned to another design â open â to fix"]}),(0,n.jsx)(im,{open:Z,onClose:()=>P(!1),link:p,product:U,listingId:w,onApply:e=>null==b?void 0:b(e)}),(0,n.jsx)(ix,{}),(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:500,color:"var(--lv-text-primary)"},children:"Size & Position"}),(()=>{var e,l;let t=((null==U?void 0:null===(e=U.print_areas)||void 0===e?void 0:e.length)?U.print_areas.map(e=>({...e,name:e.name||e.position||e.title||e.id||"front",id:e.id||e.name||"pa_1"})):io.map(e=>({id:e,name:e}))).filter(e=>e.name),i=t.length?t.map(e=>e.name):io,r=Object.fromEntries(i.map(e=>[e,(0,eP.tw)(e)])),o=(0,eP.Cf)(p,U),a=(null==o?void 0:o.name)||(null==o?void 0:o.position)||null,d=p.printArea&&i.includes(p.printArea)?p.printArea:a&&i.includes(a)?a:null!==(l=i[0])&&void 0!==l?l:"front",s=function(e){var l;let t=(0,eP.Eo)(e);if(!t.known)return"Print-area size unknown â re-pick the print provider";let n=null!==(l=null==e?void 0:e.dpi)&&void 0!==l?l:300,i=Math.round(t.widthIn*n).toLocaleString(),r=Math.round(t.heightIn*n).toLocaleString(),o="".concat(parseFloat(t.widthIn.toFixed(2))," \xd7 ").concat(parseFloat(t.heightIn.toFixed(2))," in");return"".concat(o," (").concat(i,"\xd7").concat(r,"px)")}(t.find(e=>e.name===d));return(0,n.jsx)(_.Z,{title:null!=s?s:"",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{sx:{display:"inline-flex",alignSelf:"flex-start",width:"fit-content"},children:(0,n.jsx)(nU,{label:"Print area",value:d,options:i.map(e=>{var l;return{value:e,label:null!==(l=null==r?void 0:r[e])&&void 0!==l?l:e}}),onChange:e=>v({...p,printArea:e})})})})})(),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.625},children:[(0,n.jsx)(t_.Z,{options:ip,value:(0,eP.L2)(p),onChange:e=>{let l=(0,eP.ED)(p,U,j);v({...p,...(0,eP.sO)(e,l)})},size:"compact"}),(0,n.jsx)(t_.Z,{options:iv,value:null!==(d=null!==(o=(0,eP.J_)(p))&&void 0!==o?o:p.hAlign)&&void 0!==d?d:"center",onChange:e=>v({...p,...(0,eP.Jb)(e)}),size:"compact"}),(0,n.jsx)(t_.Z,{options:ih,value:null!==(u=null!==(s=(0,eP.$O)(p))&&void 0!==s?s:p.vAlign)&&void 0!==u?u:"center",onChange:e=>v({...p,...(0,eP.Ht)(e)}),size:"compact"}),(()=>{let e=function(e,l,t){if(!e||null==e.designWidthPct||null==e.designHeightPct||"cover"===(0,eP.L2)(e))return null;let n=(0,eP.ED)(e,l,t);if(!n||!1===n.dimsKnown)return null;let i=Number(n.printAreaWidthIn),r=Number(n.printAreaHeightIn);if(!Number.isFinite(i)||!Number.isFinite(r)||i<=0||r<=0)return null;let o=Number(e.designWidthPct)/100*i,a=Number(e.designHeightPct)/100*r,d=o-i>.01?o-i:0,s=a-r>.01?a-r:0;if(!d&&!s)return null;let u=[];return s&&u.push("".concat(s.toFixed(2)," in taller")),d&&u.push("".concat(d.toFixed(2)," in wider")),{overW:d,overH:s,label:"Exceeds print area",tooltip:"Design is ".concat(u.join(" and ")," than the ").concat(i.toFixed(2)," \xd7 ").concat(r.toFixed(2)," in print area â the overflow will be cut off. Choose Fit, or resize it smaller.")}}(p,U,j);return e?(0,n.jsx)(_.Z,{title:e.tooltip,placement:"top",disableInteractive:!0,children:(0,n.jsx)(L.Z,{component:"span","data-testid":"pod-design-overflow-badge",sx:{fontSize:10,
1color:"var(--lv-warning)",fontWeight:500,whiteSpace:"nowrap",ml:.25},children:e.label})}):null})()]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",gap:.625},children:[(0,n.jsx)(_.Z,{title:"Add width constraint",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:e=>A(e.currentTarget),sx:id,children:(0,n.jsx)(nd.Z,{sx:{fontSize:14}})})}),(0,n.jsx)(e2.Z,{anchorEl:R,open:!!R,onClose:()=>A(null),anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},minWidth:140,items:nW.map(e=>({label:e.label,disabled:null!=p[e.minField]||null!=p[e.maxField],onClick:()=>v({...p,[e.minField]:"",[e.maxField]:""})}))}),(0,n.jsx)(_.Z,{title:"Open canvas editor",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:()=>C(!0),sx:id,children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"}),(0,n.jsx)("path",{d:"m15 5 4 4"})]})})})]})]}),nW.some(e=>null!=p[e.minField]||null!=p[e.maxField])&&(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.75},children:nW.map(e=>null!=p[e.minField]||null!=p[e.maxField]?(0,n.jsx)(ie,{link:p,dim:e,product:U,file:j,onChange:v},e.dim):null)})]}),(0,n.jsx)(nK,{open:I,onClose:()=>C(!1),file:j,product:U,link:p,onChange:v})]})}function im(e){var l,t;let{open:i,onClose:r,link:o,product:d,listingId:s,onApply:u}=e,[c,p]=(0,a.useState)("all"),[v,h]=(0,a.useState)(new Set),[f,x]=(0,a.useState)(null),[g,m]=(0,a.useState)(!1),[b,j]=(0,a.useState)(null),_=nG(null==d?void 0:d.variations),S=null!==(l=null==_?void 0:_.id)&&void 0!==l?l:"colors",k=(null==_?void 0:_.label)||("colors"===S?"Color":"sizes"===S?"Size":S),I="colors"===S,C=null!==(t=null==_?void 0:_.options)&&void 0!==t?t:[];(0,a.useEffect)(()=>{var e,l;if(!i)return;let t=null!==(e=o.colorMapping)&&void 0!==e?e:"all";"all"===t||void 0===t?(p("all"),h(new Set(C.map(e=>String(e.id))))):(p("specific"),h(new Set((null!==(l=t.option_ids)&&void 0!==l?l:[]).map(String))))},[i]);let Z=(0,a.useMemo)(()=>{let e=new Map;return(null!=f?f:[]).forEach(l=>{var t,n,i,r;e.set(null!==(t=l.option_id)&&void 0!==t?t:l.id,{status:null!==(n=l.status)&&void 0!==n?n:"available",claimedBy:null!==(r=null!==(i=l.claimed_by_file_name)&&void 0!==i?i:l.claimed_by)&&void 0!==r?r:null})}),e},[f]),P=C.filter(e=>{let l=Z.get(e.id);return!l||"available"===l.status||"claimed_by_self"===l.status}).map(e=>String(e.id)),R=C.filter(e=>{let l=Z.get(e.id);return(!l||"available"===l.status)&&!v.has(String(e.id))}),A=e=>{if("all"===e){let e=(null!=f?f:[]).find(e=>"claimed"===e.status);if(e){var l,t;j(null!==(t=null!==(l=e.claimed_by_file_name)&&void 0!==l?l:e.claimed_by)&&void 0!==t?t:"another file")}else j(null)}else j(null);p(e),"specific"===e&&0===v.size&&h(new Set(P))},E=e=>{let l=String(e);h(e=>{let t=new Set(e);return t.has(l)?t.delete(l):t.add(l),t})};return(0,n.jsxs)($.Z,{open:i,onClose:r,title:"".concat(k," Settings"),size:"xs",PaperProps:{sx:{width:380,maxWidth:"95vw"}},actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w.f,{text:"Cancel",color:"white",width:"auto",className:"whitespace-nowrap",onClick:r}),(0,n.jsx)(w.f,{text:"Apply",color:"purple",width:"auto",className:"whitespace-nowrap",onClick:()=>{let e=new Map;if(o.colorMapping&&"all"!==o.colorMapping){var l;
1(null!==(l=o.colorMapping.option_ids)&&void 0!==l?l:[]).forEach(l=>e.set(String(l),l))}C.forEach(l=>e.set(String(l.id),l.id)),u("all"===c?"all":{type:"specific",option_ids:[...v].map(l=>{var t;return null!==(t=e.get(l))&&void 0!==t?t:l})}),r()}})]}),children:[(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)",mb:.75},children:"Apply design to:"}),(0,n.jsx)(y.Z,{sx:{display:"flex",gap:1,mb:1.75},children:[{value:"all",label:"All ".concat(n8(k.toLowerCase()))},{value:"specific",label:"Specific ".concat(n8(k.toLowerCase()))}].map(e=>{let{value:l,label:t}=e;return(0,n.jsxs)(y.Z,{onClick:()=>A(l),sx:{flex:1,display:"flex",alignItems:"center",gap:.75,cursor:"pointer",px:1.25,py:.75,borderRadius:2,border:"1px solid ".concat(c===l?"var(--lv-brand)":"var(--lv-border-default)"),bgcolor:c===l?"var(--lv-brand-light)":"transparent",transition:"all 0.15s"},children:[(0,n.jsx)(y.Z,{sx:{width:14,height:14,borderRadius:"50%",flexShrink:0,border:"1.5px solid ".concat(c===l?"var(--lv-brand)":"var(--lv-border-default)"),display:"flex",alignItems:"center",justifyContent:"center"},children:c===l&&(0,n.jsx)(y.Z,{sx:{width:6,height:6,borderRadius:"50%",bgcolor:"var(--lv-brand)"}})}),(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-primary)",fontWeight:c===l?500:400},children:t})]},l)})}),"all"===c&&b&&(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"flex-start",gap:.75,mb:1.5,px:1.25,py:.75,borderRadius:2,bgcolor:"var(--lv-warning-bg)",border:"1px solid var(--lv-warning)"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12},children:"â ï¸"}),(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:"var(--lv-warning)",lineHeight:1.4},children:['Switching to "all ',n8(k.toLowerCase()),'" may conflict with ',(0,n.jsx)("strong",{children:b}),", which has specific ",n8(k.toLowerCase())," assigned to this print area."]})]}),"specific"===c&&(0,n.jsxs)(y.Z,{sx:{border:"1px solid var(--lv-border-default)",borderRadius:2,p:1.25,mb:1.5},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:10,fontWeight:600,color:"var(--lv-text-secondary)",mb:1,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Select ",n8(k)]}),g?(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-disabled)",py:1},children:"Loading..."}):(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.75,maxHeight:220,overflowY:"auto"},children:C.map(e=>{var l,t;let i=Z.get(e.id),r=(null==i?void 0:i.status)==="claimed",o=v.has(String(e.id))&&!r;return(0,n.jsxs)(y.Z,{onClick:()=>!r&&E(e.id),sx:{display:"flex",alignItems:"center",gap:1,cursor:r?"not-allowed":"pointer",opacity:r?.5:1},children:[(0,n.jsx)(y.Z,{sx:{width:15,height:15,borderRadius:"4px",flexShrink:0,border:"1.5px solid ".concat(o?"var(--lv-brand)":"var(--lv-border-default)"),bgcolor:o?"var(--lv-brand)":"transparent",display:"flex",alignItems:"center",justifyContent:"center",transition:"all 0.15s"},children:o&&(0,n.jsx)("svg",{width:"9",height:"9",viewBox:"0 0 9 9",fill:"none",children:(0,n.jsx)("path",{d:"M1.5 4.5L3.5 6.5L7.5 2.5",stroke:"var(--lv-text-inverse)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,n.jsx)(tA.Z,{hex:I?null!==(l=e.hex)&&void 0!==l?l:"var(--lv-text-tertiary)":void 0,size:12,shape:"circle"}),(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-primary)",flex:1},children:e.label}),r&&(0,n.jsxs)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-disabled)",flexShrink:0},children:["used by ",null!==(t=i.claimedBy)&&void 0!==t?t:"another file"]})]},e.id)})}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mt:1,pt:1,borderTop:"1px solid var(--lv-border-default)"},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)"},children:["Selected: ",v.size," of ",C.length]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",gap:.75,alignItems:"center"},children:[(0,n.jsx)(L.Z,{onClick:()=>h(new Set(P)),sx:{fontSize:11,color:"var(--lv-brand)",cursor:"pointer","&:hover":{opacity:.8}},children:"Select Available"}),(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-disabled)"},children:"\xb7"}),(0,n.jsx)(L.Z,{onClick:()=>h(new Set),sx:{fontSize:11,color:"var(--lv-text-secondary)",cursor:"pointer","&:hover":{color:"var(--lv-text-primary)"}},children:"Deselect All"})]})]})]}),"specific"===c&&!g&&R.length>0&&(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"flex-start",ga
1p:.75,mb:1.5,px:1.25,py:.75,borderRadius:2,bgcolor:"var(--lv-brand-light)",border:"1px solid var(--lv-brand-border)"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,flexShrink:0},children:"\uD83D\uDCA1"}),(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)",lineHeight:1.4},children:["Tip: You'll need to assign the remaining"," ",(0,n.jsx)(y.Z,{component:"span",sx:{color:"var(--lv-text-primary)",fontWeight:500},children:R.map(e=>e.label).join(", ")})," ","to another design file."]})]})]})}function iy(e){let{onRename:l,onReplace:t,onRemove:i,onEditDesign:r}=e,[o,d]=(0,a.useState)(null);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(_.Z,{title:"More options",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{onClick:e=>d(e.currentTarget),sx:id,children:(0,n.jsx)(L.Z,{sx:{fontSize:14,lineHeight:1,letterSpacing:1},children:"\xb7\xb7\xb7"})})}),(0,n.jsx)(e2.Z,{anchorEl:o,open:!!o,onClose:()=>d(null),anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},minWidth:160,items:[...r?[{label:"Edit design",onClick:r}]:[],{label:"Rename",onClick:l},...t?[{label:"Replace file",onClick:t}]:[],{divider:!0},{label:"Remove from listing",onClick:i,danger:!0}]})]})}function ib(e,l){let t=parseFloat(e);return isNaN(t)?null:"cm"===l?parseFloat((t/2.54).toFixed(4)):"mm"===l?parseFloat((t/25.4).toFixed(4)):"px"===l?parseFloat((t/300).toFixed(4)):t}function ij(e,l){var t,n,i,r,o,a;return(0,eP.QZ)(e,{width:null!==(o=null==l?void 0:null===(n=l.file)||void 0===n?void 0:null===(t=n.metadata)||void 0===t?void 0:t.width)&&void 0!==o?o:null,height:null!==(a=null==l?void 0:null===(r=l.file)||void 0===r?void 0:null===(i=r.metadata)||void 0===i?void 0:i.height)&&void 0!==a?a:null})}function i_(e){var l,t,n,i,r,o,a,d,s,u,c,p,v,h,f,x,g,m,y;let b=null!==(l=e.unit)&&void 0!==l?l:"inches",j=e=>null==e?null:ib(e,b),_=null!==(n=null!==(t=null!=e.xOffset?null==(m
1=e.xOffset)?null:m<=25?"left":m>=75?"right":"center":null)&&void 0!==t?t:e.hAlign)&&void 0!==n?n:eP.Rd.align,w=null!==(r=null!==(i=null!=e.yOffset?null==(y=e.yOffset)?null:y<=25?"top":y>=75?"bottom":"center":null)&&void 0!==i?i:e.vAlign)&&void 0!==r?r:eP.Rd.vertical_align,S=null!=e.designWidthPct&&null!=e.designHeightPct&&null==(0,eP.L2)(e)?null:null!==(a=null!==(o=(0,eP.fH)(e.fitMode))&&void 0!==o?o:(0,eP.fH)(e.fit))&&void 0!==a?a:eP.Rd.fit,k=null!==(d=e.margins)&&void 0!==d?d:{},I=null!==(s=e.angle)&&void 0!==s?s:0;return{color_mapping:e.colorMapping&&"all"!==e.colorMapping?{type:"specific",option_ids:null!==(u=e.colorMapping.option_ids)&&void 0!==u?u:[]}:"all",placement:{rule:null!==(c=e.rule)&&void 0!==c?c:"cover"===e.fitMode?"fill_to_print_area":"max_width",...null!=S&&{fit:S},align:_,vertical_align:w,angle:I,max_width_in:j(e.maxWidth),max_height_in:j(e.maxHeight),...null!=e.designWidthPct&&{design_width_pct:e.designWidthPct},...null!=e.designHeightPct&&{design_height_pct:e.designHeightPct},...null!=e.xOffset&&{x_offset_pct:e.xOffset},...null!=e.yOffset&&{y_offset_pct:e.yOffset},margin_top_in:ib(null!==(p=k.top)&&void 0!==p?p:0,"inches"),margin_bottom_in:ib(null!==(v=k.bottom)&&void 0!==v?v:0,"inches"),margin_left_in:ib(null!==(h=k.left)&&void 0!==h?h:0,"inches"),margin_right_in:ib(null!==(f=k.right)&&void 0!==f?f:0,"inches")},print_constraints:{min_width_in:j(e.minWidth),min_height_in:j(e.minHeight),min_dpi:null!==(x=e.minDpi)&&void 0!==x?x:null,lock_as
1pect_ratio:null===(g=e.lockAspectRatio)||void 0===g||g}}}function iw(e,l,t){var n,i,r,o,a,d,s,u,c,p,v,h,f,x,g;let m=null!=e?e:{};return{id:"preset-file-".concat(l),type:"file",file:{id:null!==(n=m.id)&&void 0!==n?n:l,originalFilename:null!==(o=null!==(r=null!==(i=m.originalFilename)&&void 0!==i?i:m.fileName)&&void 0!==r?r:t)&&void 0!==o?o:"File",fileName:null!==(s=null!==(d=null!==(a=m.fileName)&&void 0!==a?a:m.originalFilename)&&void 0!==d?d:t)&&void 0!==s?s:"File",fileExtension:null!==(u=m.fileExtension)&&void 0!==u?u:"",metadata:null!==(c=m.metadata)&&void 0!==c?c:{},s3Url:null!==(v=null!==(p=m.s3Url)&&void 0!==p?p:m.activeUrl)&&void 0!==v?v:null,thumbnailUrl:null!==(f=null!==(h=m.thumbnailUrl)&&void 0!==h?h:m.activeUrl)&&void 0!==f?f:null,podStatus:null!==(x=m.podStatus)&&void 0!==x?x:"ready",uploadStatus:null!==(g=m.uploadStatus)&&void 0!==g?g:"ready"}}}let iS=0;function ik(e){return e?(e._placeholderId||(iS+=1,e._placeholderId="placeholder-".concat(Date.now(),"-").concat(iS)),e._placeholderId):e}function iI(e){var l;return!!e&&(null!==(l=e.asset_file_id)&&void 0!==l?l:e.assetFileId)==null&&"upload_required"===e.fillMode}function iC(e,l){var t,n,i,r,o,a;let d=e.find(e=>e.product.id===(null==l?void 0:l.productId)),s=null==d?void 0:d.podProductId;if(!s)return null;let u=l.printArea||"front",c=null!==(o=null===(n=d.product)||void 0===n?void 0:null===(t=n.print_areas)||void 0===t?void 0:t.find(e=>(e.name||e.position||"").toLowerCase()===u.toLowerCase()))&&void 0!==o?o:null===(r=d.product)||void 0===r?void 0:null===(i=r.print_areas)||void 0===i?void 0:i[0],p=null!==(a=null==c?void 0:c.id)&&void 0!==a?a:nY(d.product,u);return p?{pod_product_id:s,print_area_id:p}:null}function iZ(e){let{file:l,onEditDesign:t,podProducts:i,links:r,onLinksChange:o,onToggle:d,onRemove:s,onReplaceFile:u,conflictsByLink:c,claimedByOtherLink:p,hasOtherLinkAtSameAreaByLink:v,allFileLinks:h,onTransferOption:f,onReclaimOrphanedOptions:x,onSetLinkMapping:g,listingId:m,assignmentId:b,onAssignmentCreated:j,unlinkedProducts:S=[],orphanedAssetFileIds:k=[],canHealClaims:I,openCanvasForLinkId:C=null,onCanvasOpenConsumed:Z,onUserUnlinkedLastLink:P,onUserLinked:R,updateLinkRef:A}=e,[E,M]=(0,a.useState)(!1),[z,D]=(0,a.useState)(!1),[F,T]=(0,a.useState)(l.name),N=(0,a.useRef)({}),W=(0,a.useRef)(b);(0,a.useEffect)(()=>{W.current=b},[b]);let U=e=>{W.current=e,null==j||j(e)},H=(0,a.useRef)(Promise.resolve()),B=e=>{let l=H.current.then(e,e);return H.current=l.then(()=>{},()=>{}),l},V=async e=>{var t,n,r,o,a,d,s,u;if(I&&!I())return{healed:!1,alreadyLinked:!1};let c=await (0,eI.vv)(m),p=null!==(r=null!==(n=null==c?void 0:null===(t=c.data)||void 0===t?void 0:t.data)&&void 0!==n?n:null==c?void 0:c.data)&&void 0!==r?r:[],v=!1,f=!1;if(!W.current&&l.assetFileId){let t=p.find(e=>e.asset_file_id===l.assetFileId);t&&(U(t.id),v=!0,(null!==(o=t.assigned_to)&&void 0!==o?o:[]).some(l=>l.pod_product_id===e.pod_product_id&&l.print_area_id===e.print_area_id)&&(f=!0))}let x=e=>{var l;let t=(0,eZ.UE)(i,e.pod_product_id);if(!t)return!1;let n=(0,eP.z_)(null===(l=t.product)||void 0===l?void 0:l.print_areas,e.print_area_id);if(!n)return!0;let r=(n.name||n.position||"").toLowerCase();return Object.values(null!=h?h:{}).some(e=>(null!=e?e:[]).some(e=>e.productId===t.product.id&&(e.printArea||"front").toLowerCase()===r))};for(let l of p){if(l.id===W.current)continue;let t=null!==(d=null!==(a=l.asset_file_id)&&void 0!==a?a:l.assetFileId)&&void 0!==d?d:null,n=null!==(s=l.fillMode)&&void 0!==s?s:l.fill_mode;if(null!=t&&"upload_required"!==n&&!k.includes(t))for(let t of null!==(u=l.assigned_to)&&void 0!==u?u:[])t.pod_product_id===e.pod_product_id&&t.print_area_id===e.print_area_id&&(x(t)||(await (0,eI.uv)(m,l.id,-1,{pod_product_id:t.pod_product_id,print_area_id:t.print_area_id}),v=!0))}return{healed:v,alreadyLinked:f}},K=async function(e){var t,n,i,r,o,a,d,s,u,c,p,v,h,f,x,g,y;let{retried:b=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},j="upload_required"===l.fillMode?{fill_mode:"upload_required",file_name:l.fileName,assigned_to:[e]}:{asset_file_id:l.assetFileId,file_name:l.fileName,assigned_to:[e]},_=W.current;try{if(_)await (0,eI.fz)(m,_,e);else{let e=await (0,eI.Ps)(m,j),l=null!==(o=null!==(r=null==e?void 0:null===(n=e.data)||void 0===n?void 0:null===(t=n.data)||void 0===t?void 0:t.id)&&void 0!==r?r:null==e?void 0:null===(i=e.data)||void 0===i?void 0:i.id)&&void 0!==o?o:null;l&&U(l)}}catch(i){let l=null==i?void 0:null===(a=i.response)||void 0===a?void 0:a.status,t=null==i?void 0:null===(u=i.response)||void 0===u?void 0:null===(s=u.data)||void 0===s?void 0:null===(d=s.data)||void 0===d?void 0:d.code;if(_&&(404===l||"FILE_ASSIGNMENT_NOT_FOUND"===t)){U(null);let e=await (0,eI.Ps)(m,j),l=null!==(g=null!==(x=null==e?void 0:null===(h=e.data)||void 0===h?void 0:null===(v=h.data)||void 0===v?void 0:v.id)&&void 0!==x?x:null==e?void 0:null===(f=e.data)||void 0===f?void 0:f.id)&&void 0!==g?g:null;l&&U(l);return}let n=null!==(y=null==i?void 0:null===(p=i.response)||void 0===p?void 0:null===(c=p.data)||void 0===c?void 0:c.message)&&void 0!==y?y:"";if(422===l&&!b&&/already (claimed|assigned)/i.test(n)){let{healed:l,alreadyLinked:t}=await V(e);if(t)return;if(l)return K(e,{retried:!0})}throw i}},q=(0,a.useRef)(new Set),G=async e=>{var t,n,a,d,s,u,c;if(e&&r.some(l=>l.productId===e)||e&&q.current.has(e))return;e&&q.current.add(e);let p=e?i.find(l=>l.product.id===e):null,{chosenAreaObj:v,areaName:f,colorMapping:x}=ir({printAreas:null!==(n=null==p?void 0:null===(t=p.product)||void 0===t?void 0:t.print_areas)&&void 0!==n?n:[],productId:e,fileId:l.id,allFileLinks:h}),g=null!==(a=null==v?void 0:v.id)&&void 0!==a?a:nY(null==p?void 0:p.product,f);o([...r,{id:Date.now(),productId:null!=e?e:null,printArea:f,printAreaId:g,colorMapping:x,...eP.aP}]),null==R||R();let y="upload_required"===l.fillMode;if(!m||!l.assetFileId&&!y)return;let b=null==p?void 0:p.podProductId;if(!b)return;if(!g){console.warn("[PodDesignPanel addLink] no resolvable print area; skipping backend persist",{podProductId:b,printAreaName:f});return}let j={pod_product_id:b,print_area_id:g,color_mapping:x,placement:{...eP.Rd}};try{await B(()=>K(j))}catch(e){console.error("[PodDesignPanel addLink]",null!==(u=null==e?void 0:null===(d=e.response)||void 0===d?void 0:d.data)&&void 0!==u?u:e),O.Am.error(n4(e,"Couldn't link the design to \"".concat(null!==(c=null==p?void 0:null===(s=p.product)||void 0===s?void 0:s.name)&&void 0!==c?c:"this product",'".'),"Please try again."))}finally{e&&q.current.delete(e)}},Y=(e,t)=>
1{var n,a,d,s,u,c,p,v,f,g;let y=r[e],b=t.productId!==(null==y?void 0:y.productId),j=t.printArea!==(null==y?void 0:y.printArea),_=null;if((b||j)&&(null==y?void 0:y.productId)&&(null==y?void 0:y.printArea)){let e=i.find(e=>e.product.id===y.productId),l=nG(null==e?void 0:null===(n=e.product)||void 0===n?void 0:n.variations),t=null!==(a=null==l?void 0:l.id)&&void 0!==a?a:"colors",r=(null!==(d=null==l?void 0:l.options)&&void 0!==d?d:[]).filter(l=>{var n,i;return null==e?void 0:null===(i=e.selection)||void 0===i?void 0:null===(n=i[t])||void 0===n?void 0:n[l.id]}).map(e=>e.id),o=y.colorMapping&&"all"!==y.colorMapping?null!==(s=y.colorMapping.option_ids)&&void 0!==s?s:[]:r;o.length&&(_={productId:y.productId,printArea:y.printArea,orphanedIds:o})}if(j&&!b&&t.productId){let e=Object.entries(null!=h?h:{}).some(e=>{let[n,i]=e;return eA(n)!==eA(l.id)&&(null!=i?i:[]).some(e=>e.productId===t.productId&&e.printArea===t.printArea)});t={...t,colorMapping:e?{type:"specific",option_ids:[]}:"all"}}if(b||j){let e=i.find(e=>e.product.id===t.productId),l=t.printArea||"front",n=null!==(f=null==e?void 0:null===(c=e.product)||void 0===c?void 0:null===(u=c.print_areas)||void 0===u?void 0:u.find(e=>(e.name||e.position||"").toLowerCase()===l.toLowerCase()))&&void 0!==f?f:null==e?void 0:null===(v=e.product)||void 0===v?void 0:null===(p=v.print_areas)||void 0===p?void 0:p[0];t={...t,printAreaId:null!==(g=null==n?void 0:n.id)&&void 0!==g?g:nY(null==e?void 0:e.product,l)}}let w=o(r.map((l,n)=>n===e?t:l));if(!m){_&&!1!==w&&(null==x||x(_.productId,_.printArea,_.orphanedIds,l.id,e));return}if(b||j){let n=iC(i,y);B(async()=>{var l,r,o,a,d,s,u,c,p,v,h,f;let x=W.current;if(!x)return;try{let t=await (0,eI.uv)(m,x,e,n);(null!==(a=null==t?void 0:null===(r=t.data)||void 0===r?void 0:null===(l=r.data)||void 0===l?void 0:l.assignment_deleted)&&void 0!==a?a:null==t?void 0:null===(o=t.data)||void 0===o?void 0:o.assignment_deleted)&&U(null)}catch(e){console.error("[PodDesignPanel link-edit removeTarget]",null!==(c=null==e?void 0:null===(d=e.response)||void 0===d?void 0:d.data)&&void 0!==c?c:e),O.Am.error("Couldn't update the design link. ".concat(null!==(p=null==e?void 0:null===(u=e.response)||void 0===u?void 0:null===(s=u.data)||void 0===s?void 0:s.message)&&void 0!==p?p:"Please try again."));return}let g=i.find(e=>e.product.id===t.productId),y=null==g?void 0:g.podProductId;if(!y)return;let b=t.printArea||"front",j=t.printAreaId;if(!j){console.warn("[PodDesignPanel updateLink] no resolvable print area; skipping move persist",{podProductId:y,printAreaName:b});return}try{await K({pod_product_id:y,print_area_id:j,color_mapping:null!==(v=t.colorMapping)&&void 0!==v?v:"all",placement:i_(t).placement})}catch(e){console.error("[PodDesignPanel link-edit addTarget]",null!==(f=null==e?void 0:null===(h=e.response)||void 0===h?void 0:h.data)&&void 0!==f?f:e),O.Am.error(n4(e,"Couldn't move the design to ".concat(b,"."),"Please try again."))}}),_&&(null==x||x(_.productId,_.printArea,_.orphanedIds,l.id,e,{after:()=>H.current}))}else{let l=iC(i,t),n="".concat(e);clearTimeout(N.current[n]),N.current[n]=setTimeout(()=>{B(()=>{let n=W.current;
1return n?(0,eI.Tq)(m,n,e,i_(t),l).catch(e=>{var l,t;console.error("[PodDesignPanel link-edit updateTarget]",null!==(t=null==e?void 0:null===(l=e.response)||void 0===l?void 0:l.data)&&void 0!==t?t:e)}):Promise.resolve()})},600)}};A&&(A.current=Y);let Q=e=>{let t=r[e],n=null;if((null==t?void 0:t.productId)&&(null==t?void 0:t.printArea)){var a,d,s,u;let e=i.find(e=>e.product.id===t.productId),l=nG(null==e?void 0:null===(a=e.product)||void 0===a?void 0:a.variations),r=null!==(d=null==l?void 0:l.id)&&void 0!==d?d:"colors",o=(null!==(s=null==l?void 0:l.options)&&void 0!==s?s:[]).filter(l=>{var t,n;return null==e?void 0:null===(n=e.selection)||void 0===n?void 0:null===(t=n[r])||void 0===t?void 0:t[l.id]}).map(e=>e.id),c=t.colorMapping&&"all"!==t.colorMapping?null!==(u=t.colorMapping.option_ids)&&void 0!==u?u:[]:o;c.length&&(n={productId:t.productId,printArea:t.printArea,orphanedIds:c})}let c=o(r.filter((l,t)=>t!==e),{isExplicitUnlink:!0});if(1===r.length&&(null==P||P()),!m){n&&!1!==c&&(null==x||x(n.productId,n.printArea,n.orphanedIds,l.id,e));return}let p=iC(i,t);B(async()=>{var l,t,n,i,r,o,a,d,s,u;let c=W.current;if(c)try{let r=await (0,eI.uv)(m,c,e,p);(null!==(i=null==r?void 0:null===(t=r.data)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.assignment_deleted)&&void 0!==i?i:null==r?void 0:null===(n=r.data)||void 0===n?void 0:n.assignment_deleted)&&U(null)}catch(e){404!==(null==e?void 0:null===(r=e.response)||void 0===r?void 0:r.status)&&(console.error("[PodDesignPanel removeLink]",null!==(s=null==e?void 0:null===(o=e.response)||void 0===o?void 0:o.data)&&void 0!==s?s:e),O.Am.error("Couldn't unlink the design. ".concat(null!==(u=null==e?void 0:null===(d=e.response)||void 0===d?void 0:null===(a=d.data)||void 0===a?void 0:a.message)&&void 0!==u?u:"Please try again.")))}}),n&&(null==x||x(n.productId,n.printArea,n.orphanedIds,l.id,e,{after:()=>H.current}))};return(0,n.jsxs)(y.Z,{sx:{mb:3,border:"1px solid var(--lv-border-default)",borderRadius:"22px",bgcolor:"var(--lv-bg-elevated)",p:2.5,display:"flex",flexDirection:"column",gap:"15px"},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:1},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1.25,minWidth:0,flex:1},children:[l.thumbnail?(0,n.jsx)(y.Z,{component:"img",src:l.thumbnail,alt:l.name,sx:{width:60,height:60,borderRadius:"11px",objectFit:"cover",flexShrink:0,border:"1px solid var(--lv-border-default)"}}):(0,n.jsx)(is,{}),(0,n.jsxs)(y.Z,{sx:{minWidth:0},children:[z?(0,n.jsx)(y.Z,{component:"input",autoFocus:!0,value:F,onChange:e=>T(e.target.value),onBlur:()=>{D(!1);let e=F.trim();e&&e!==l.name&&l.assetFileId&&(0,er.Dd)(l.assetFileId,{fileName:e}).catch(()=>{})},onKeyDown:e=>{if("Enter"===e.key){D(!1);let e=F.trim();e&&e!==l.name&&l.assetFileId&&(0,er.Dd)(l.assetFileId,{fileName:e}).catch(()=>{})}"Escape"===e.key&&(T(l.name),D(!1))},sx:{width:"100%",border:"none",borderBottom:"1px solid var(--lv-brand)",outline:"none",background:"transparent",fontSize:15,fontWeight:500,color:"var(--lv-text-primary)",fontFamily:"inherit"}}):(0,n.jsx)(L.Z,{title:F,sx:{fontSize:15,fontWeight:500,color:"var(--lv-text-primary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:F}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.5},children:[(0,n.jsx)(_.Z,{title:l.highResolution?"DPI meets POD requirements (â¥300)":"DPI below 300 â may print poorly",placement:"top",disableInteractive:!0,children:(0,n.jsx)(L.Z,{sx:{fontSize:12.5,color:"var(--lv-text-primary)",opacity:.5,cursor:"default"},children:l.highResolution?"High Resolution":"Low Resolution"})}),(0,n.jsx)(L.Z,{sx:{fontSize:12.5,color:"var(--lv-text-primary)",opacity:.5},children:"â¢"}),(0,n.jsx)(y.Z,{sx:{px:.625,py:.25,borderRadius:"8px",bgcolor:"var(--lv-brand-light)"},children:(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-brand)",fontWeight:500,textTransform:"uppercase"},children:l.type})})]})]})]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.625},children:[(0,n.jsx)(iy,{onRename:()=>{D(!0),T(l.name)}
1,onReplace:()=>M(!0),onRemove:s,onEditDesign:t}),(0,n.jsx)(t_.Z,{options:[{value:!0,label:"On"},{value:!1,label:"Off"}],value:l.enabled,onChange:e=>d(e),activeColor:"var(--lv-selected)",size:"compact"})]})]}),(0,n.jsx)(n1.Z,{open:E,onClose:()=>M(!1),listingId:m,podOnly:!0,initialFilters:{podStatus:"valid"},onLinked:e=>{null==u||u(e),M(!1)}}),r.map((e,t)=>{var r,o,a;return(0,n.jsx)(ig,{podProducts:i,link:e,onChange:e=>Y(t,e),onRemove:()=>Q(t),conflictColorIds:null!==(r=null==c?void 0:c[e.id])&&void 0!==r?r:null,claimedByOther:null!==(o=null==p?void 0:p[e.id])&&void 0!==o?o:null,hasOtherLinkAtSameArea:null!==(a=null==v?void 0:v[e.id])&&void 0!==a&&a,onTransferOption:(e,n,i)=>null==f?void 0:f(l.id,t,e,n,i),onSetColorMapping:e=>null==g?void 0:g(l.id,t,e),file:l,listingId:m,openCanvasSignal:C===e.id,onCanvasOpenConsumed:Z},e.id)}),S.length>0&&(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1},children:[S.map(e=>(0,n.jsx)(iE,{podEntry:e,onLink:()=>G(e.product.id)},e.product.id)),S.length>1&&(0,n.jsx)(w.f,{text:"Link all",color:"white",width:"auto",className:"whitespace-nowrap",onClick:()=>{o([...r,...S.map(e=>{var l,t;let n=(0,nJ.q)(null===(l=e.product)||void 0===l?void 0:l.print_areas),i=(null==n?void 0:n.name)||(null==n?void 0:n.position)||"front";return{id:"bulk-".concat(Date.now(),"-").concat(Math.random()),productId:e.product.id,printArea:i,printAreaId:null!==(t=null==n?void 0:n.id)&&void 0!==t?t:nY(e.product,i),colorMapping:"all",...eP.aP}})]),null==R||R();let e="upload_required"===l.fillMode;m&&(l.assetFileId||e)&&B(async()=>{for(let s of S){var e,l,t,n,i,r,o,a,d;let u=s.podProductId;if(!u)continue;let c=(0,nJ.q)(null===(e=s.product)||void 0===e?void 0:e.print_areas),p=(null==c?void 0:c.name)||(null==c?void 0:c.position)||"front",v=null!==(l=null==c?void 0:c.id)&&void 0!==l?l:nY(s.product,p);if(!v){console.warn("[PodDesignPanel link-all] no resolvable print area; skipping product",{podProductId:u});continue}let h={pod_product_id:u,print_area_id:v,color_mapping:"all",placement:{...eP.Rd}};try{await K(h)}catch(e){console.error("[PodDesignPanel link-all addTarget]",null!==(o=null==e?void 0:null===(t=e.response)||void 0===t?void 0:t.data)&&void 0!==o?o:e),O.Am.error("Couldn't link the design to \"".concat(null!==(a=null===(n=s.product)||void 0===n?void 0:n.name)&&void 0!==a?a:"this product",'". ').concat(null!==(d=null==e?void 0:null===(r=e.response)||void 0===r?void 0:null===(i=r.data)||void 0===i?void 0:i.message)&&void 0!==d?d:"Please try again."))}}})}})]}),(()=>{let e=new Set(r.map(e=>e.productId).filter(Boolean)),l=new Set(S.map(e=>e.product.id)),t=i.filter(t=>!e.has(t.product.id)&&!l.has(t.product.id));return 0===t.length?null:(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1},children:t.map(e=>(0,n.jsx)(iE,{podEntry:e,onLink:()=>G(e.product.id)},e.product.id))})})()]})}function iP(e){let{placeholder:l,podProducts:t,links:i,onLinksChange:r,onRename:o,onToggle:d,onRemove:s,conflictsByLink:u,claimedByOtherLink:c,hasOtherLinkAtSameAreaByLink:p,allFileLinks:v,onTransferOption:h,onReclaimOrphanedOptions:f,onSetLinkMapping:x,unlinkedProducts:g=[]}=e,m=l.file_name||"Placeholder",b=!1!==l.is_enabled,[j,w]=(0,a.useState)(!1),[S,k]=(0,a.useState)(m),I=(0,a.useRef)(0),C=()=>{k(m),I.current=Date.now(),w(!0)},Z=()=>{w(!1);let e=S.trim();if(!e||e===m){k(m);return}o(e)},P=e=>{var n,o,a,d;if(!e||i.some(l=>l.productId===e))return;let s=null!==(o=t.find(l=>l.product.id===e))&&void 0!==o?o:null,{chosenAreaObj:u,areaName:c,colorMapping:p}=ir({printAreas:null!==(a=null==s?void 0:null===(n=s.product)||void 0===n?void 0:n.print_areas)&&void 0!==a?a:[],productId:e,fileId:l._placeholderId,allFileLinks:v});r([...i,{id:"placeholder-".concat(l._placeholderId,"-").concat(Date.now()),productId:e,printArea:c,printAreaId:null!==(d=null==u?void 0:u.id)&&void 0!==d?d:nY(null==s?void 0:s.product,c),colorMapping:p,...eP.aP}])},R=(e,n)=>{let o=i[e],a=n.productId!==(null==o?void 0:o.productId),d=n.printArea!==(null==o?void 0:o.printArea),s=null;if(d&&!a&&n.productId){if(null==o?void 0:o.printArea){var u,c,p,h;let e=t.find(e=>e.product.id===n.productId),l=nG(null==e?void 0:null===(u=e.product)||void 0===u?void 0:u.variations),i=null!==(c=null==l?void 0:l.id)&&void 0!==c?c:"colors",r=(null!==(p=null==l?void 0:l.options)&&void 0!==p?p:[]).filter(l=>{var t,n;return null==e?void 0:null===(n=e.selection)||void 0===n?void 0:null===(t=n[i])||void 0===t?void 0:t[l.id]}).map(e=>e.id),a=o.colorMapping&&"all"!==o.colorMapping?null!==(h=o.colorMapping.option_ids)&&void 0!==h?h:[]:r;a.length&&(s={productId:n.productId,printArea:o.printArea,orphanedIds:a})}let e=Object.entries(null!=v?v:{}).some(e=>{let[t,i]=e;return eA(t)!==eA(l._placeholderId)&&(null!=i?i:[]).some(e=>e.productId===n.productId&&e.printArea===n.printArea)});n={...n,colorMapping:e?{type:"specific",option_ids:[]}:"all"}}let x=r(i.map((l,t)=>t===e?n:l));s&&!1!==x&&(null==f||f(s.productId,s.printArea,s.orphanedIds,l._placeholderId,e))},A=e=>{let n=i[e],o=null;if((null==n?void 0:n.productId)&&(null==n?void 0:n.printArea)){var a,d,s,u;let e=t.find(e=>e.product.id===n.productId),l=nG(null==e?void 0:null===(a=e.product)||void 0===a?void 0:a.variations),i=null!==(d=null==l?void 0:l.id)&&void 0!==d?d:"colors",r=(null!==(s=null==l?void 0:l.options)&&void 0!==s?s:[]).filter(l=>{var t,n;return null==e?void 0:null===(n=e.selection)||void 0===n?void 0:null===(t=n[i])||void 0===t?void 0:t[l.id]}).map(e=>e.id),c=n.colorMapping&&"all"!==n.colorMapping?null!==(u=n.colorMapping.option_ids)&&void 0!==u?u:[]:r;c.length&&(o={productId:n.productId,printArea:n.printArea,orphanedIds:c})}let c=r(i.filter((l,t)=>
1t!==e),{isExplicitUnlink:!0});o&&!1!==c&&(null==f||f(o.productId,o.printArea,o.orphanedIds,l._placeholderId,e))};return(0,n.jsxs)(y.Z,{sx:{mb:3,border:"1.5px dashed var(--lv-border-default)",borderRadius:"22px",bgcolor:"var(--lv-bg-elevated)",p:2.5,display:"flex",flexDirection:"column",gap:"15px"},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:1},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1.25,minWidth:0,flex:1},children:[(0,n.jsx)(is,{variant:"placeholder"}),(0,n.jsxs)(y.Z,{sx:{minWidth:0,flex:1},children:[j?(0,n.jsx)(y.Z,{component:"input",autoFocus:!0,"aria-label":"Placeholder name",value:S,onFocus:e=>e.target.select(),onChange:e=>k(e.target.value),onBlur:()=>{Date.now()-I.current<200||Z()},onKeyDown:e=>{"Enter"===e.key&&Z(),"Escape"===e.key&&(k(m),w(!1))},sx:{width:"100%",border:"none",borderBottom:"1px solid var(--lv-selected)",outline:"none",background:"transparent",fontSize:15,fontWeight:500,color:"var(--lv-text-primary)",fontFamily:"inherit"}}):(0,n.jsx)(_.Z,{title:"Click to rename",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{role:"button",tabIndex:0,"aria-label":"Rename placeholder: ".concat(m),onClick:C,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),C())},sx:{width:"fit-content",maxWidth:"100%",minWidth:0,cursor:"pointer",borderRadius:"6px",px:.5,mx:-.5,border:"1px dashed transparent","&:hover":{borderColor:"var(--lv-border-default)"},"&:focus-visible":{outline:"2px solid var(--lv-selected)",outlineOffset:"1px"}},children:(0,n.jsx)(L.Z,{sx:{fontSize:15,fontWeight:500,color:"var(--lv-text-primary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:m})})}),(0,n.jsx)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5,mt:.5},children:(0,n.jsx)(ny.ZP,{badge:"placeholder",size:"sm"})})]})]}),(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.625},children:[(0,n.jsx)(iy,{onRename:C,onRemove:s}),(0,n.jsx)(t_.Z,{options:[{value:!0,label:"On"},{value:!1,label:"Off"}],value:b,onChange:e=>d(e),activeColor:"var(--lv-selected)",size:"compact"})]})]}),i.map((e,i)=>{var r,o,a;return(0,n.jsx)(ig,{podProducts:t,link:e,onChange:e=>R(i,e),onRemove:()=>A(i),conflictColorIds:null!==(r=null==u?void 0:u[e.id])&&void 0!==r?r:null,claimedByOther:null!==(o=null==c?void 0:c[e.id])&&void 0!==o?o:null,hasOtherLinkAtSameArea:null!==(a=null==p?void 0:p[e.id])&&void 0!==a&&a,onTransferOption:(e,t,n)=>null==h?void 0:h(l._placeholderId,i,e,t,n),onSetColorMapping:e=>null==x?void 0:x(l._placeholderId,i,e),file:{id:l._placeholderId,fillMode:"upload_required",assetFileId:null},listingId:void 0},e.id)}),g.length>0&&(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1},children:g.map(e=>(0,n.jsx)(iE,{podEntry:e,onLink:()=>P(e.product.id)},e.product.id))}),(()=>{let e=new Set(i.map(e=>e.productId).filter(Boolean)),l=new Set(g.map(e=>e.product.id)),r=t.filter(t=>!e.has(t.product.id)&&!l.has(t.product.id));return 0===r.length?null:(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1},children:r.map(e=>(0,n.jsx)(iE,{podEntry:e,onLink:()=>P(e.product.id)},e.product.id))})})()]})}function iR(e){let{ext:l}=e,t=(null!=l?l:"").replace(".","").toUpperCase().slice(0,4),i=["JPG","PNG","WEBP","GIF","SVG"].includes(t)?"#009CFF":"#D82042";return(0,n.jsx)(y.Z,{sx:{width:40,height:40,borderRadius:1.5,flexShrink:0,bgcolor:"".concat(i,"18"),border:"1px solid ".concat(i,"33"),display:"flex",alignItems:"center",justifyContent:"center"},children:(0,n.jsx)(L.Z,{sx:{fontSize:9,fontWeight:700,color:i,lineHeight:1},children:t})})}function iA(e){var l,t;let{item:i,onRemove:r}=e,o=i.file,a=null!==(l=o.fileExtension)&&void 0!==l?l:"",d=a.replace(".","").toUpperCase(),s=(t=o.fileSize)?"".concat(Math.round(t/1024)," KB"):"0 KB";return(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1.25,border:"1px solid var(--lv-border-default)",borderRadius:3,px:1.5,py:1.25,mb:1,opacity:.55,bgcolor:"var(--lv-bg-elevated)"},children:[o.thumbnailUrl?(0,n.jsx)(y.Z,{component:"img",src:o.thumbnailUrl,alt:o.originalFilename,sx:{width:40,height:40,borderRadius:1.5,objectFit:"cover",flexShrink:0}}):(0,n.jsx)(iR,{ext:a}),(0,n.jsxs)(y.Z,{sx:{flex:1,minWidth:0},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,fontWeight:500,color:"var(--lv-text-primary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:o.originalFilename}
1),(0,n.jsxs)(L.Z,{sx:{fontSize:10,color:"var(--lv-text-secondary)",mt:.25},children:[s," of ",s," ⢠",d]})]}),(0,n.jsx)(y.Z,{sx:{px:.75,py:.25,borderRadius:"4px",bgcolor:"var(--lv-error-bg)",border:"1px solid var(--lv-error)",flexShrink:0},children:(0,n.jsx)(L.Z,{sx:{fontSize:9,fontWeight:600,color:"var(--lv-error)"},children:"Invalid"})}),r&&(0,n.jsx)(_.Z,{title:"Remove from listing",placement:"top",disableInteractive:!0,children:(0,n.jsx)(y.Z,{component:"button",type:"button",onClick:r,"aria-label":"Remove from listing",sx:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,border:"1px solid var(--lv-border-default)",borderRadius:"6px",bgcolor:"transparent",color:"var(--lv-text-secondary)",cursor:"pointer",flexShrink:0,transition:"all 0.15s","&:hover":{color:"var(--lv-error)",borderColor:"var(--lv-error)",bgcolor:"var(--lv-error-bg)"}},children:(0,n.jsx)(nm.Z,{size:14})})})]})}function iE(e){var l,t,i,r;let{podEntry:o,onLink:a}=e,d=o.product,s=null!==(r=null!==(i=null===(l=d.supplier)||void 0===l?void 0:l.name)&&void 0!==i?i:null===(t=d.supplier)||void 0===t?void 0:t.slug)&&void 0!==r?r:"",u=(0,tS.Td)(d,tS.wD.MODEL),c=(0,tS.j4)(d),p=c&&c!==u?c:void 0;return(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1.25,px:1.25,py:1,border:"1px solid var(--lv-border-default)",borderRadius:"12px",bgcolor:"var(--lv-bg-card)"},children:[(0,n.jsx)(y.Z,{sx:{width:44,height:44,borderRadius:"10px",flexShrink:0,bgcolor:"var(--lv-bg-elevated)",overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"center"},children:d.image_url?(0,n.jsx)(y.Z,{component:"img",src:d.image_url,alt:u,sx:{width:"100%",height:"100%",objectFit:"cover"}}):(0,n.jsx)("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",children:(0,n.jsx)("path",{d:"M3 6l3-3 2 2a4 4 0 0 0 8 0l2-2 3 3-3 3v10H6V9L3 6z",fill:"var(--lv-border-strong)"})})}),(0,n.jsxs)(y.Z,{sx:{flex:1,minWidth:0},children:[(0,n.jsx)(L.Z,{title:p,sx:{fontSize:13,fontWeight:600,color:"var(--lv-text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u}),s&&(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)",mt:.25},children:s})]}),(0,n.jsx)(w.f,{text:"Link",color:"white",width:"auto",className:"whitespace-nowrap",onClick:()=>a(o)})]})}let iM={PROCESSING:"processing",CHECKING:"checking",FAILED:"failed"},iz={PROCESSING:"This design hasn't finished its print-readiness check yet.",CHECKING:"Checkingâ¦",LOOKUP_FAILED:"Couldn't check this upload's status. Try again.",ATTACH_FAILED:"Couldn't attach this design. Try again, or add it from Browse Library.",UPLOAD_FAILED:"This upload didn't finish on our side and can't be used.",NOT_POD_READY:"This file isn't print-ready, so it can't be used as a POD design.",PRESET_CHANGED:"A different preset was applied while this uploaded â attach it here with Retry."},iD="Couldn't attach the uploaded design â retry it below, or add it from Browse Library.",iL={COMMITTED:"committed",DUPLICATE:"duplicate",ABORTED:"aborted"},iO=new Set(["failed","quarantined","scan_failed"]),iF=e=>{var l,t;return null!==(t=null!==(l=null==e?void 0:e.originalFilename)&&void 0!==l?l:null==e?void 0:e.fileName)&&void 0!==t?t:"design"};function iT(e){var l;let t=String(null!==(l=null==e?void 0:e.uploadStatus)&&void 0!==l?l:"").toLowerCase();return iO.has(t)?{kind:iM.FAILED,message:iz.UPLOAD_FAILED}:"ready"!==t||(null==e?void 0:e.podStatus)==null?{kind:iM.PROCESSING,message:iz.PROCESSING}:(0,ea.oK)(e.podStatus)?null:{kind:iM.FAILED,message:iz.NOT_POD_READY}}function iN(e){var l;let{podProducts:t=[],listingId:i,onPayloadGetterReady:r,onUploadsInFlightChange:o,presetApplyGeneration:d=0,onResetReady:s,onDesignColorsChanged:u,onLinkedProductsChanged:c,initialFileAssignments:p,onPodSnapshotGetterReady:v,onPresetDesignsChanged:h,onPublishBlockedChange:f,initialParentFolder:x,onPresetSnapshotReady:g,autoLinkSuppression:m}=e,{available:b}=(0,T.Z)(),[j,S]=(0,a.useState)(null),[k,I]=(0,a.useState)(!1),[C,P]=(0,a.useState)({}),[R,A]=(0,a.useState)({}),[E,M]=(0,a.useState)({}),[z,D]=(0,a.useState)(null),[F,N]=(0,a.useState)(!1),W=(0,a.useRef)(null),[U,H]=(0,a.useState)([]),B=(0,a.useRef)([]);B.current=U;let V=(0,a.useCallback)(e=>{let l=e(B.current);return B.current=l,H(l),l},[]),K=(0,a.useRef)(null);(0,a.useEffect)(()=>
1{if(i||K.current===d)return;K.current=d;let e=(Array.isArray(p)?p:[]).map(e=>{if(!iI(e)||e._placeholderId)return e;let l={...e};return ik(l),l});H(e),B.current=e},[i,d]);let[G,Y]=(0,a.useState)([]),[Q,$]=(0,a.useState)(null),X=(0,a.useRef)(null),J=(0,a.useRef)(d);J.current=d;let[ee,el]=(0,a.useState)(null),et=(0,a.useCallback)(e=>{el(l=>l===e?l:e)},[]),en=!i&&ee===d,ei=(0,a.useRef)({}),eo=(0,a.useMemo)(()=>(Array.isArray(t)?t:[]).map(e=>{var l,t,n;return"".concat(null!==(t=null==e?void 0:e.podProductId)&&void 0!==t?t:"",":").concat(null!==(n=null==e?void 0:null===(l=e.product)||void 0===l?void 0:l.id)&&void 0!==n?n:"")}).join("|"),[t]),ed=(0,a.useRef)(t);ed.current=t;let es=(0,a.useCallback)(e=>{let l=[];for(let t of null!=e?e:[]){var n,i;for(let e of null!==(i=null!==(n=null==t?void 0:t.assigned_to)&&void 0!==n?n:null==t?void 0:t.targets)&&void 0!==i?i:[])(null==e?void 0:e.pod_product_id)!=null&&l.push(e.pod_product_id)}return!l.length||l.some(e=>null!=(0,eZ.UE)(t,e))},[t]);(0,a.useEffect)(()=>{if(i)return;let e=Array.isArray(p)?p:[];if(X.current===d)return;if(!e.length){X.current=d;let e=e=>{let l=!1,t={};for(let[n,i]of Object.entries(e))String(n).startsWith("preset-file-")?l=!0:t[n]=i;return l?t:e};Y(e=>e.length?[]:e),A(e),P(e),et(d);return}if(!es(e))return;X.current=d;let l=[],n=new Set;for(let t of e){var r;let e=null!==(r=t.asset_file_id)&&void 0!==r?r:t.assetFileId;if(!e)continue;let i=String(e);n.has(i)||(n.add(i),l.push(e))}if(!l.length){Y([]),et(d);return}let o=J.current,a=()=>J.current!==o;$(o);let s=l=>{if(null==l)return;let t=String(l);return e.find(e=>{var l;let n=null!==(l=null==e?void 0:e.asset_file_id)&&void 0!==l?l:null==e?void 0:e.assetFileId;return null!=n&&String(n)===t})};Promise.allSettled(l.map(e=>(0,er.hn)(e))).then(e=>{if(a())return;let n=[];e.forEach((e,t)=>{var i,r,o,a,d;if("fulfilled"!==e.status)return;let u=l[t],c=null!==(d=null!==(a=null===(r=e.value)||void 0===r?void 0:null===(i=r.data)||void 0===i?void 0:i.data)&&void 0!==a?a:null===(o=e.value)||void 0===o?void 0:o.data)&&void 0!==d?d:null;if(!c)return;let p=s(u);n.push(iw(c,u,null==p?void 0:p.file_name))}),Y(n);let i={},r={},o={};n.forEach(e=>{var l,n,a;let d=s(e.file.id);if(!d)return;r[e.id]=null===(l=d.is_enabled)||void 0===l||l;let u=null!==(a=null!==(n=d.targets)&&void 0!==n?n:d.assigned_to)&&void 0!==a?a:[],c=new Set,p=[],v=u.map((l,n)=>{var i,r,o;let a=(0,eZ.UE)(t,l.pod_product_id),d=null==a?void 0:null===(i=a.product)||void 0===i?void 0:i.id;if(!d)return null;if(c.has(d))return p.push(l),null;c.add(d);let s=(0,eP.z_)(null===(r=a.product)||void 0===r?void 0:r.print_areas,l.print_area_id),u=(null==s?void 0:s.name)||(null==s?void 0:s.position)||null;return ii((0,eP.lP)(l,{linkId:"preset-".concat(e.id,"-").concat(n),productId:d,printAreaName:u,printAreaId:null!==(o=null==s?void 0:s.id)&&void 0!==o?o:null,geometry:ij(s,e)}),a.product)}).filter(Boolean);v.length&&(i[e.id]=v),p.length&&(o[e.id]=p)});let u=e=>String(e).startsWith("preset-file-");for(let e of Object.keys(ei.current))u(e)&&delete ei.current[e];Object.assign(ei.current,o),P(e=>{let l={};for(let[t,n]of Object.entries(e))u(t)||(l[t]=n);return{...l,...r}}),A(e=>{let l={};for(let[t,n]of Object.entries(e))u(t)||(l[t]=n);return{...l,...i}}),et(d)}).finally(()=>$(e=>e===o?null:e))},[i,p,eo]);let eu=(0,a.useRef)(null),ec=(0,a.useRef)(!1);(0,a.useEffect)(()=>{var e;if(i||eu.current===d&&!ec.current)return;let l=(null!==(e=B.current)&&void 0!==e?e:[]).filter(iI);if(!es(l))return;eu.current=d;let n={},r={},o={},a=0;l.forEach(e=>{var l,i;r[e._placeholderId]=!1!==e.is_enabled;let d=null!==(i=null!==(l=e.assigned_to)&&void 0!==l?l:e.targets)&&void 0!==i?i:[],s=new Set,u=[],c=d.map((l,n)=>{var i,r,o;let d=(0,eZ.UE)(t,l.pod_product_id),c=null==d?void 0:null===(i=d.product)||void 0===i?void 0:i.id;if(!c)return u.push(l),a+=1,null;if(s.has(c))return u.push(l),null;s.add(c);let p=(0,eP.z_)(null===(r=d.product)||void 0===r?void 0:r.print_areas,l.print_area_id),v=(null==p?void 0:p.name)||(null==p?void 0:p.position)||null;return ii((0,eP.lP)(l,{linkId:"placeholder-".concat(e._placeholderId,"-").concat(n),productId:c,printAreaId:null!==(o=null==p?void 0:p.id)&&void 0!==o?o:null,printAreaName:v,geometry:ij(p,null)}),d.product)}
1).filter(Boolean);c.length&&(n[e._placeholderId]=c),u.length&&(o[e._placeholderId]=u)});let s=e=>String(e).startsWith("placeholder-");for(let e of Object.keys(ei.current))s(e)&&delete ei.current[e];Object.assign(ei.current,o),P(e=>{let l={};for(let[t,n]of Object.entries(e))s(t)||(l[t]=n);return{...l,...r}}),A(e=>{let l={};for(let[t,n]of Object.entries(e))s(t)||(l[t]=n);return{...l,...n}}),ec.current=a>0},[i,p,eo,U]);let ep=(0,a.useCallback)(async()=>{if(!i)return B.current.map(e=>{if(!e||!e._placeholderId)return e;let{_placeholderId:l,...t}=e;return t});try{var e,l,t;let n=await (0,eI.vv)(i),r=null!==(t=null!==(l=null==n?void 0:null===(e=n.data)||void 0===e?void 0:e.data)&&void 0!==l?l:null==n?void 0:n.data)&&void 0!==t?t:[];return Array.isArray(r)?r:[]}catch(e){return[]}},[i]);(0,a.useEffect)(()=>{null==v||v(ep)},[ep]),(0,a.useEffect)(()=>{i||null==h||h(U)},[i,U,h]),(0,a.useEffect)(()=>{let e=new Set(t.map(e=>e.product.id)),l=new Map(t.map(e=>{var l,t,n;let i=nG(e.product.variations),r=null!==(t=null==i?void 0:i.id)&&void 0!==t?t:"colors",o=null===(l=e.selection)||void 0===l?void 0:l[r],a=new Set((null!==(n=null==i?void 0:i.options)&&void 0!==n?n:[]).filter(e=>null==o?void 0:o[e.id]).map(e=>e.id)),d=!!o&&Object.keys(o).length>0;return[e.product.id,{ids:a,explicit:d}]}));A(t=>(function(e,l,t){let n=!1,i={};for(let[r,o]of Object.entries(e)){let e=[];for(let i of o){if(i.productId&&!l.has(i.productId)){n=!0;continue}let r=i.productId?t.get(i.productId):null;if(r&&(r.ids.size>0||r.explicit)&&i.colorMapping&&"all"!==i.colorMapping&&Array.isArray(i.colorMapping.option_ids)){let l=n$([...r.ids]),t=i.colorMapping.option_ids.filter(e=>l.has(nQ(e)));if(t.length!==i.colorMapping.option_ids.length){n=!0,e.push({...i,colorMapping:{...i.colorMapping,option_ids:t}});continue}}e.push(i)}i[r]=e}return n?i:e})(t,e,l))},[t]);let ev=(0,a.useRef)(null),eh=(0,a.useRef)(null),ef=(0,a.useRef)(null),ex=(0,a.useCallback)((e,l)=>{var t,n;null===(t=ef.current)||void 0===t||t.call(ef),O.Am.info("Your selected folder no longer exists â uploading to your library root instead.");let i=(null==l?void 0:l.tempId)!=null?lK.current.get(l.tempId):void 0;null===(n=eh.current)||void 0===n||n.call(eh,[e],null,i)},[]),{standaloneFiles:eg,uploadingFiles:em,uploadAndLink:ey,removeUploadingFile:eb,retryUpload:ej,addPendingDeliverable:e_,addDeliverableNow:ew,deleteDeliverableNow:eS,getDigitalFilesPayload:ek,refetch:eR,resetPendingOps:eL,isLoading:eO,fetchSucceeded:eF}=(0,nb.eo)(i,void 0,{assetCategory:"design_files",onParentUploadFailed:ex});ev.current=ey;let[eT,eN]=(0,a.useState)(x||null),eW=null!==(l=null==eT?void 0:eT.id)&&void 0!==l?l:null;ef.current=()=>eN(null),(0,a.useEffect)(()=>{eN(x||null)},[null==x?void 0:x.id]),(0,a.useEffect)(()=>{i&&(null==r||r(ek))},[i,ek]);let eU=(0,a.useRef)({parentFolder:eT});eU.current={parentFolder:eT},(0,a.useEffect)(()=>{g&&g(()=>{var e,l,t,n;return{parentCollectionId:null!==(t=null===(e=eU.current.parentFolder)||void 0===e?void 0:e.id)&&void 0!==t?t:null,parentCollectionName:null!==(n=null===(l=eU.current.parentFolder)||void 0===l?void 0:l.name)&&void 0!==n?n:null}})},[g]),(0,a.useEffect)(()=>{null==s||s(()=>{eL(),eR()})},[s,eL,eR]),(0,a.useEffect)(()=>{if(i&&t.length)return clearTimeout(W.current),W.current=setTimeout(async()=>{try{var e,l,t;let n=await (0,eI.Hq)(i),r=null!==(t=null!==(l=null==n?void 0:null===(e=n.data)||void 0===e?void 0:e.data)&&void 0!==l?l:null==n?void 0:n.data)&&void 0!==t?t:{};D(r),N(!1),eQ(!1)}catch(e){eQ(!0)}},1e3),()=>clearTimeout(W.current)},[t,R,i]);let[eH,eB]=(0,a.useState)(!1),[eV,eK]=(0,a.useState)([]),[eq,eG]=(0,a.useState)([]),[eY,eQ]=(0,a.useState)(!1),e$=(0,a.useMemo)(()=>Array.isArray(null==z?void 0:z.unfilledSlots)?z.unfilledSlots:[],[z]),eX=(0,a.useMemo)(()=>!!(null==z?void 0:z.publishBlocked)||e$.length>0,[z,e$]),eJ=(0,a.useMemo)(()=>{if(!i||!eH)return[];let e=new Set(eV);return eY||eq.forEach(l=>e.add(l)),Object.values(null!=R?R:{}).forEach(l=>
1{(null!=l?l:[]).forEach(l=>{l.productId&&e.add(l.productId)})}),t.filter(l=>{var t;return(null==l?void 0:null===(t=l.product)||void 0===t?void 0:t.id)&&!e.has(l.product.id)})},[i,eH,R,t,eV,eq,eY]),e0=eJ.length>0,e1=eX||e0;(0,a.useEffect)(()=>{i&&(null==f||f(e1,{unfilledSlotCount:e$.length,unfilledSlotIndexes:e$.map(e=>null==e?void 0:e.slotIndex).filter(e=>null!=e),reason:eX?void 0:e0?n3:void 0}))},[i,e1,e0,eX,e$]);let e5=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(i){if(eX&&!e5.current){e5.current=!0;let e=e$.map(e=>null==e?void 0:e.slotIndex).filter(e=>null!=e);(0,Z.L)("preset.upload_required_blocked_publish",{listingId:i,unfilledSlotCount:e$.length,unfilledSlotIndexes:e,errorCode:"UNFILLED_DESIGN_SLOTS"})}else eX||(e5.current=!1)}},[i,eX,e$]);let{validFiles:e2,invalidFiles:e3}=(0,a.useMemo)(()=>{var e,l;let t=i?eg:G,n=(null!=t?t:[]).filter(e=>e.file),r=new Set,o=[],a=e=>{var l;return String(null!==(l=e.id)&&void 0!==l?l:"").startsWith("pending-")};for(let l of n){if(a(l))continue;let t=null===(e=l.file)||void 0===e?void 0:e.id;if(null!=t){if(r.has(t))continue;r.add(t)}o.push(l)}for(let e of n){if(!a(e))continue;let t=null===(l=e.file)||void 0===l?void 0:l.id;if(null!=t){if(r.has(t))continue;r.add(t)}o.push(e)}return{validFiles:o.filter(e=>(0,ea.oK)(e.file.podStatus)),invalidFiles:o.filter(e=>!(0,ea.oK)(e.file.podStatus))}},[i,eg,G]),e4=(0,a.useMemo)(()=>{let e=e2.map((e,l)=>({id:e.id,label:il(l)}));return i||U.filter(iI).forEach((l,t)=>{e.push({id:l._placeholderId,label:il(e2.length+t)})}),e},[e2,i,U]),e7=(0,a.useMemo)(()=>{let e=new Set;return e4.forEach(l=>{!1===C[l.id]&&e.add(l.id)}),i||U.filter(iI).forEach(l=>{!1===l.is_enabled&&e.add(l._placeholderId)}),e},[e4,C,i,U]),{conflictsByLink:e6,claimedByOtherLink:e8,hasOtherLinkAtSameAreaByLink:e9}=(0,a.useMemo)(()=>(function(e){let{designEntities:l,fileLinks:t,podProducts:n,disabledEntityIds:i=null}=e,r={},o={},a={},d=e=>!!i&&i.has(e);
1return(null!=l?l:[]).forEach(e=>{var i;(null!==(i=null==t?void 0:t[e.id])&&void 0!==i?i:[]).forEach(i=>{var s,u,c,p;if(!i.productId||!i.printArea)return;let v=(null!=n?n:[]).find(e=>e.product.id===i.productId),h=null!==(s=null==v?void 0:v.product)&&void 0!==s?s:null,f=nG(null==h?void 0:h.variations),x=null!==(u=null==f?void 0:f.id)&&void 0!==u?u:"colors",g=(null!==(c=null==f?void 0:f.options)&&void 0!==c?c:[]).filter(e=>{var l,t;return null==v?void 0:null===(t=v.selection)||void 0===t?void 0:null===(l=t[x])||void 0===l?void 0:l[e.id]}),m=new Set("all"!==i.colorMapping&&i.colorMapping?(null!==(p=i.colorMapping.option_ids)&&void 0!==p?p:[]).map(String):g.map(e=>String(e.id))),y=new Set,b={},j=!1;(null!=l?l:[]).filter(l=>l.id!==e.id&&!d(l.id)).forEach(e=>{var l;(null!==(l=null==t?void 0:t[e.id])&&void 0!==l?l:[]).forEach((l,t)=>{var n;l.productId===i.productId&&l.printArea===i.printArea&&(j=!0,new Set("all"!==l.colorMapping&&l.colorMapping?(null!==(n=l.colorMapping.option_ids)&&void 0!==n?n:[]).map(String):g.map(e=>String(e.id))).forEach(l=>{m.has(l)&&y.add(l),b[l]||(b[l]={fileId:e.id,linkIdx:t,fileLabel:e.label})}))})}),y.size>0&&(r[i.id]=y),Object.keys(b).length>0&&(o[i.id]=b),a[i.id]=j})}),{conflictsByLink:r,claimedByOtherLink:o,hasOtherLinkAtSameAreaByLink:a}})({designEntities:e4,fileLinks:R,podProducts:t,disabledEntityIds:e7}),[e4,R,t,e7]),le=(0,a.useMemo)(()=>{let e=[];return[...e2,...e3].forEach(l=>{var t,n,i,r,o;
1if(!1===C[l.id])return;let a=null!==(i=R[l.id])&&void 0!==i?i:[];a.length&&e.push({key:l.id,links:a,advisory:(o=null===(t=l.file)||void 0===t?void 0:t.podStatus,(0,ea.oK)(o)?null:o===ea.FB.NON_COMPLIANT||o===ea.FB.NOT_APPLICABLE?nX.NOT_POD_READY:nX.PROCESSING),podStatus:null!==(r=null===(n=l.file)||void 0===n?void 0:n.podStatus)&&void 0!==r?r:null})}),i||U.filter(iI).forEach(l=>{var t;if(!1===l.is_enabled||!1===C[l._placeholderId])return;let n=null!==(t=R[l._placeholderId])&&void 0!==t?t:[];n.length&&e.push({key:l._placeholderId,links:n,advisory:null,podStatus:"upload_required"})}),e},[e2,e3,R,C,i,U]),{gaps:ll,advisories:lt}=(0,a.useMemo)(()=>(function(e){let{podProducts:l,claimants:t}=e,n={gaps:[],advisories:[]};if(!(null==l?void 0:l.length))return n;let i=new Map,r=new Set;if((null!=t?t:[]).forEach(e=>{var t;(null!==(t=e.links)&&void 0!==t?t:[]).forEach(t=>{var n;if(!t.productId)return;let o=l.find(e=>e.product.id===t.productId),a=null!==(n=t.printAreaId)&&void 0!==n?n:t.printArea?nY(null==o?void 0:o.product,t.printArea):null;if(!a){r.add(t.productId);return}let d="".concat(t.productId,"::").concat(a);i.has(d)||i.set(d,{productId:t.productId,areaId:a,entries:[]}),i.get(d).entries.push({link:t,claimant:e})})}),!i.size)return n;let o=[],a=[];return i.forEach(e=>{var t,n,i,d,s,u,c;let{productId:p,areaId:v,entries:h}=e,f=l.find(e=>e.product.id===p),x=null!==(n=null==f?void 0:f.product)&&void 0!==n?n:null,g=nG(null==x?void 0:x.variations),m=null!==(i=null==g?void 0:g.id)&&void 0!==i?i:"colors",y=(null!==(d=null==g?void 0:g.options)&&void 0!==d?d:[]).filter(e=>{var l,t;return null==f?void 0:null===(t=f.selection)||void 0===t?void 0:null===(l=t[m])||void 0===l?void 0:l[e.id]});if(!y.length)return;let b=new Set,j=new Map;h.forEach(e=>{var l;let{link:t,claimant:n}=e;(t.colorMapping&&"all"!==t.colorMapping?null!==(l=t.colorMapping.option_ids)&&void 0!==l?l:[]:y.map(e=>e.id)).forEach(e=>{let l=nQ(e);n.advisory?(j.has(l)||j.set(l,new Set),j.get(l).add(n.advisory)):b.add(l)})});let _=(0,eP.z_)(null==x?void 0:x.print_areas,v),w=(0,eP.tw)(null!==(u=null!==(s=null==_?void 0:_.name)&&void 0!==s?s:null==_?void 0:_.position)&&void 0!==u?u:""),S=null==x?void 0:null===(t=x.print_areas)||void 0===t?void 0:t[0],k=_?S===_:(null==S?void 0:S.id)===v,I={key:"".concat(p,"::").concat(v),productName:null!==(c=null==x?void 0:x.name)&&void 0!==c?c:p,printAreaLabel:w,isRequired:k},C=y.filter(e=>!b.has(nQ(e.id))&&!j.has(nQ(e.id)));C.length>0&&!r.has(p)&&o.push({...I,uncoveredColors:C});let Z=y.filter(e=>!b.has(nQ(e.id))&&j.has(nQ(e.id))).map(e=>({...e,reasons:[...j.get(nQ(e.id))]}));Z.length>0&&a.push({...I,colors:Z})}),{gaps:o,advisories:a}})({podProducts:t,claimants:le}),[t,le]),ln=(0,a.useRef)(!1);(0,a.useEffect)(()=>{ll.length&&!ln.current&&(ln.current=!0,(0,Z.L)("pod.coverage_gap_shown",{listingId:null!=i?i:null,surface:i?"listing":"preset",gapCount:ll.length,uncoveredColorCount:ll.reduce((e,l)=>e+l.uncoveredColors.length,0),hasIneligibleClaimants:lt.length>0,designs:[...e2,...e3].map(e=>{var l,t,n;return{podStatus:null!==(t=null===(l=e.file)||void 0===l?void 0:l.podStatus)&&void 0!==t?t:null,enabled:!1!==C[e.id],linkCount:(null!==(n=R[e.id])&&void 0!==n?n:[]).length}})}))},[ll,lt,e2,e3,C,R,i]),(0,a.useEffect)(()=>{if(!c)return;let e=new Set;Object.values(R).forEach(l=>
1{(null!=l?l:[]).forEach(l=>{l.productId&&e.add(l.productId)})}),c(e)},[R,c]);let li=(0,a.useRef)(null);(0,a.useEffect)(()=>{if(!i||!eH)return;let e=new Map((null!=e2?e2:[]).map(e=>{var l;return[eA(e.id),eA(null===(l=e.file)||void 0===l?void 0:l.id)]})),l=[];Object.entries(null!=R?R:{}).forEach(t=>{let[n,i]=t;(null!=i?i:[]).forEach(t=>{var i;l.push({assetFileId:null!==(i=e.get(eA(n)))&&void 0!==i?i:null,fileId:n,link:t})})});let t=Array.from(e.values()).filter(e=>null!=e),n=JSON.stringify({managedFileIds:t,links:l});li.current!==n&&(li.current=n,ez(eE,{listingId:i,managedFileIds:t,links:l}))},[i,eH,R,e2]);let[lr,lo]=(0,a.useState)(null),la=(0,a.useRef)(null),ld=(0,a.useCallback)(e=>{var l;let t=(null!=e2?e2:[]).find(l=>{var t;return(null===(t=l.file)||void 0===t?void 0:t.id)!=null&&eA(l.file.id)===eA(e.assetFileId)});if(!t)return!1;let n=null!==(l=R[t.id])&&void 0!==l?l:[],i=e.linkId&&n.find(l=>eA(l.id)===eA(e.linkId))||n.find(l=>eA(l.productId)===eA(e.productId)&&(null!=e.printAreaId&&eA(l.printAreaId)===eA(e.printAreaId)||null!=e.printArea&&l.printArea===e.printArea));return!!i&&(lo({fileId:t.id,linkId:i.id}),!0)},[e2,R]);(0,a.useEffect)(()=>{if(!i)return;let e=e=>{let l=null==e?void 0:e.detail;eD(null==l?void 0:l.listingId,i)&&(ld(l)||eH||(la.current=l))};return window.addEventListener(eM,e),()=>window.removeEventListener(eM,e)},[i,eH,ld]),(0,a.useEffect)(()=>{let e=la.current;e&&ld(e)&&(la.current=null)},[ld]),(0,a.useEffect)(()=>{if(!u)return;let e=ed.current;if(!e.length)return;let l=new Map;(null!=e2?e2:[]).forEach(t=>{var n;(null!==(n=R[t.id])&&void 0!==n?n:[]).forEach(t=>{var n,i,r,o,a,d;if(!t.productId)return;l.has(t.productId)||l.set(t.productId,new Set);let s=l.get(t.productId),u=e.find(e=>e.product.id===t.productId),c=nG(null==u?void 0:null===(n=u.product)||void 0===n?void 0:n.variations),p=null!==(i=null==c?void 0:c.options)&&void 0!==i?i:[];if(t.colorMapping&&"all"!==t.colorMapping)(null!==(d=t.colorMapping.option_ids)&&void 0!==d?d:[]).forEach(e=>s.add(e));else{let e=null!==(a=null==u?void 0:null===(r=u.selection)||void 0===r?void 0:r[null!==(o=null==c?void 0:c.id)&&void 0!==o?o:"colors"])&&void 0!==a?a:{};p.forEach(l=>{e[l.id]&&s.add(l.id)})}})}),l.forEach((l,t)=>{var n,i,r,o;let a=e.find(e=>e.product.id===t),d=nG(null==a?void 0:null===(n=a.product)||void 0===n?void 0:n.variations),s=null!==(r=null==d?void 0:d.id)&&void 0!==r?r:"colors",c=null!==(o=null==a?void 0:null===(i=a.selection)||void 0===i?void 0:i[s])&&void 0!==o?o:{};[...l].some(e=>!c[e])&&u(t,[...l])})},[R,e2,u]);let ls=(0,a.useRef)(!1),lu=(0,a.useRef)(!1),[lc,lp]=(0,a.useState)(!1),[lv,lh]=(0,a.useState)([]);(0,a.useEffect)(()=>{i&&!ls.current&&eF&&(null==t?void 0:t.length)&&(ls.current=!0,lu.current=!0,(0,eI.vv)(i).then(e=>{var l,n,i;let r=null!==(i=null!==(n=null==e?void 0:null===(l=e.data)||void 0===l?void 0:l.data)&&void 0!==n?n:null==e?void 0:e.data)&&void 0!==i?i:[];if(eB(!0),eK([]),eG([]),!Array.isArray(r)||!r.length)return;let o={},a={},d={},s=[],u=new Set,c=new Set,p=(e,l)=>{var n,i;if((null==e?void 0:e.is_enabled)===!1)return;let r=null!==(i=null!==(n=null==e?void 0:e.targets)&&void 0!==n?n:null==e?void 0:e.assigned_to)&&void 0!==i?i:[];(Array.isArray(r)?r:[]).forEach(e=>{var n;let i=(0,eZ.UE)(t,null==e?void 0:e.pod_product_id);(null==i?void 0:null===(n=i.product)||void 0===n?void 0:n.id)&&l.add(i.product.id)})};r.forEach(e=>{var l,n,i,r;let v=null!==(l=e.asset_file_id)&&void 0!==l?l:e.assetFileId,h=e.id;if(!v||!h){p(e,c);return}let f=eg.find(e=>{var l;return(null===(l=e.file)||void 0===l?void 0:l.id)!=null&&String(e.file.id)===String(v)});if(!f){s.push(v),p(e,u);return}o[f.id]=h,d[f.id]=null===(n=e.is_enabled)||void 0===n||n;let x=null!==(r=null!==(i=e.targets)&&void 0!==i?i:e.assigned_to)&&void 0!==r?r:[],g=new Set,m=[],y=x.map((e,l)=>{var n,i,r;let o=(0,eZ.UE)(t,e.pod_product_id),a=null==o?void 0:null===(n=o.product)||void 0===n?void 0:n.id;if(!a)return null;if(g.has(a))return m.push(e),null;g.add(a);let d=(0,eP.z_)(null===(i=o.product)||void 0===i?void 0:i.print_areas,e.print_area_id),s=(null==d?void 0:d.name)||(null==d?void 0:d.position)||null;return ii((0,eP.lP)(e,{linkId:"g1-".concat(h,"-").concat(l),productId:a,printAreaName:s,printAreaId:null!==(r=null==d?void 0:d.id)&&void 0!==r?r:null,geometry:ij(d,f)}),o.product)}
1).filter(Boolean);y.length&&(a[f.id]=y),m.length&&(ei.current[f.id]=m)}),eK([...u]),eG([...c]),Object.keys(o).length&&M(e=>({...e,...o})),P(e=>({...e,...d})),A(e=>{let l={...e};return Object.entries(a).forEach(e=>{var t;let[n,i]=e;(null===(t=l[n])||void 0===t?void 0:t.length)||(l[n]=i)}),l}),s.length>0&&lh(s)}).catch(e=>{var l,t;console.error("[PodDesignPanel G1 getFileAssignments]",null!==(t=null==e?void 0:null===(l=e.response)||void 0===l?void 0:l.data)&&void 0!==t?t:e),O.Am.error("Couldn't load this listing's design assignments â refresh to retry.")}).finally(()=>{lu.current=!1,lp(!0)}))},[i,eF,null==eg?void 0:eg.length,null==t?void 0:t.length]);let lf=(0,a.useCallback)(()=>eH||!ls.current,[eH]),lx=(0,a.useRef)(null);if(null===lx.current){let e=new Set;lx.current={suppress:l=>e.add(l),clear:l=>e.delete(l),isSuppressed:l=>e.has(l)}}let lg=null!=m?m:lx.current,lm=(0,a.useCallback)(e=>lg.suppress(n6(e,i)),[lg,i]),ly=(0,a.useCallback)(e=>lg.clear(n6(e,i)),[lg,i]),lb=(0,a.useCallback)(e=>lg.isSuppressed(n6(e,i)),[lg,i]),lj=(0,a.useRef)(R),l_=(0,a.useRef)(E),lw=(0,a.useRef)(e2),lS=(0,a.useRef)(i);(0,a.useEffect)(()=>{lj.current=R},[R]),(0,a.useEffect)(()=>{l_.current=E},[E]),(0,a.useEffect)(()=>{lw.current=e2},[e2]),(0,a.useEffect)(()=>{lS.current=i},[i]);let lk=(0,a.useRef)(null),lI=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(null===lk.current){lk.current=new Set(t.map(e=>e.product.id));return}let e=lk.current,l=lI.current,n=l?t:t.filter(l=>!e.has(l.product.id));if(lk.current=new Set(t.map(e=>e.product.id)),!n.length||e.size>0&&!l)return;if(!lf()){lI.current=!0;return}lI.current=!1;let i=lw.current,r=lj.current,o=l_.current,a=lS.current;if(!i.length)return;let d=i[0];if(lb(d))return;let s=(e,l)=>{var t,n,i,o,a,d;let{chosenAreaObj:s,areaName:u,allClaimed:c,colorMapping:p}=ir({printAreas:null===(t=e.product)||void 0===t?void 0:t.print_areas,productId:e.product.id,fileId:l.id,allFileLinks:r});if(c)return O.Am.info('"'.concat(null!==(i=null===(n=e.product)||void 0===n?void 0:n.name)&&void 0!==i?i:"This product","\" couldn't be auto-attached â every print area already has a design. Assign it manually.")),null;let v=null!==(o=null==s?void 0:s.id)&&void 0!==o?o:nY(e.product,u);return v?{id:"".concat(Date.now(),"-").concat(Math.random()),productId:e.product.id,printArea:u,printAreaId:v,colorMapping:p,...eP.aP}:(O.Am.info('"'.concat(null!==(d=null===(a=e.product)||void 0===a?void 0:a.name)&&void 0!==d?d:"This product","\" couldn't be auto-attached â its print area couldn't be resolved. Assign it manually.")),null)};if(!a){let e=function(e,l,t){let{fileId:n,makeLink:i}=t;if(null==n||"function"!=typeof i)return{};let r={};for(let t of null!=e?e:[]){var o,a;let e=null!==(a=null!==(o=r[n])&&void 0!==o?o:null==l?void 0:l[n])&&void 0!==a?a:[];if(e.some(e=>{var l;return e.productId===(null==t?void 0:null===(l=t.product)||void 0===l?void 0:l.id)}))continue;let d=i(t);d&&(r[n]=[...e,d])}return r}(n,r,{fileId:d.id,makeLink:e=>s(e,d)})[d.id];e&&l6(d.id,e);return}n.forEach(e=>{[d].forEach(l=>{var t,n;if((null!==(n=r[l.id])&&void 0!==n?n:[]).some(l=>l.productId===e.product.id))return;let i=s(e,l);if(!i||(A(t=>{var n;let r=null!==(n=t[l.id])&&void 0!==n?n:[];return r.some(l=>l.productId===e.product.id)?t:{...t,[l.id]:[...r,i]}}),!(null===(t=l.file)||void 0===t?void 0:t.id)||!e.podProductId))return;let d={pod_product_id:e.podProductId,print_area_id:i.printAreaId,color_mapping:i.colorMapping,placement:{...eP.Rd}},u=o[l.id];u?(0,eI.fz)(a,u,d).catch(async t=>{var n,i,r,o,s,c,p,v,h,f,x,g,m,y,b,j,_;let w=null==t?void 0:null===(n=t.response)||void 0===n?void 0:n.status,S=null==t?void 0:null===(o=t.response)||void 0===o?void 0:null===(r=o.data)||void 0===r?void 0:null===(i=r.data)||void 0===i?void 0:i.code;if(404===w||"FILE_ASSIGNMENT_NOT_FOUND"===S){M(e=>{let{[l.id]:t,...n}=e;return n});let e=l_.current[l.id];try{if(e&&e!==u)await (0,eI.fz)(a,e,d),M(t=>({...t,[l.id]:e}));else{let e=await (0,eI.Ps)(a,{asset_file_id:l.file.id,file_name:null!==(m=null!==(g=null===(p=l.file)||void 0===p?void 0:p.originalFilename)&&void 0!==g?g:null===(v=l.file)||void 0===v?void 0:v.fileName)&&void 0!==m?m:"",assigned_to:[d]}),t=null!==(b=null!==(y=null==e?void 0:null===(f=e.data)||void 0===f?void 0:null===(h=f.data)||void 0===h?void 0:h.id)&&void 0!==y?y:null==e?void 0:null===(x=e.data)||void 0===x?void 0:x.id)&&void 0!==b?b:null;t&&M(e=>({...e,[l.id]:t}))}return}catch(e){t=e}}console.error("[PodDesignPanel auto-link addTarget existing]",null!==(j=null==t?void 0:null===(s=t.response)||void 0===s?void 0:s.data)&&void 0!==j?j:t),O.Am.error(n4(t,"Couldn't attach the design to \"".concat(null!==(_=null===(c=e.product)||void 0===c?void 0:c.name)&&void 0!==_?_:"this product",'".'),"Please try again."))}):setTimeout(()=>{let t=l_.current[l.id];if(t)(0,eI.fz)(a,t,d).catch(async n=>{var i,r,o,s,u,c,p,v,h,f,x,g,m,y,b,j,_;let w=null==n?void 0:null===(i=n.response)||void 0===i?void 0:i.status,S=null==n?void 0:null===(s=n.response)||void 0===s?void 0:null===(o=s.data)||void 0===o?void 0:null===(r=o.data)||void 0===r?void 0:r.code;if(404===w||"FILE_ASSIGNMENT_NOT_FOUND"===S){M(e=>{let{[l.id]:t,...n}=e;return n});let e=l_.current[l.id];try{if(e&&e!==t)await (0,eI.fz)(a,e,d),M(t=>({...t,[l.id]:e}));else{let e=await (0,eI.Ps)(a,{asset_file_id:l.file.id,file_name:null!==(m=null!==(g=null===(p=l.file)||void 0===p?void 0:p.originalFilename)&&void 0!==g?g:null===(v=l.file)||void 0===v?void 0:v.fileName)&&void 0!==m?m:"",assigned_to:[d]}),t=null!==(b=null!==(y=null==e?void 0:null===(f=e.data)||void 0===f?void 0:null===(h=f.data)||void 0===h?void 0:h.id)&&void 0!==y?y:null==e?void 0:null===(x=e.data)||void 0===x?void 0:x.id)&&void 0!==b?b:null;t&&M(e=>({...e,[l.id]:t}))}return}catch(e){n=e}}console.error("[PodDesignPanel auto-link addTarget]",null!==(j=null==n?void 0:null===(u=n.response)||void 0===u?void 0:u.data)&&void 0!==j?j:n),O.Am.error(n4(n,"Couldn't attach the design to \"".concat(null!==(_=null===(c=e.product)||void 0===c?void 0:c.name)&&void 0!==_?_:"this product",'".'),"Please try again."))});else{var n,i,r,o;(0,eI.Ps)(a,{asset_file_id:l.file.id,file_name:null!==(o=null!==(r=null===(n=l.file)||void 0===n?void 0:n.originalFilename)&&void 0!==r?r:null===(i=l.file)||void 0===i?void 0:i.fileName)&&void 0!==o?o:"",assigned_to:[d]}).then(e=>{var t,n,i,r,o;let a=null!==(o=null!==(r=null==e?void 0:null===(n=e.data)||void 0===n?void 0:null===(t=n.data)||void 0===t?void 0:t.id)&&void 0!==r?r:null==e?void 0:null===(i=e.data)||void 0===i?void 0:i.id)&&void 0!==o?o:null;a&&M(e=>({...e,[l.id]:a}))}).catch(l=>{var t,n,i,r;console.error("[PodDesignPanel auto-link createFileAssignment]",null!==(i=null==l?void 0:null===(t=l.response)||void 0===t?void 0:t.data)&&void 0!==i?i:l),O.Am.error(n4(l,"Couldn't attach the design to \"".concat(null!==(r=null===(n=e.product)||void 0===n?void 0:n.name)&&void 0!==r?r:"this product",'".'),"Please try again."))})}},300)})})},[t,lf,lb]);let lC=(0,a.useRef)(!1);(0,a.useEffect)(()=>{var e,l,n,r,o,a,d,s,u,c,p,v,h,f,x;if(lC.current||!e2.length||!t.length||lu.current||!i&&!en||!lf())return;let g=e2[0];if((null===(e=R[g.id])||void 0===e?void 0:e.length)||lb(g))return;let m=[],y={claimed:[],unresolved:[]};for(let e of t){let{chosenAreaObj:l,areaName:t,allClaimed:i,colorMapping:u}=ir({printAreas:null===(n=e.product)||void 0===n?void 0:n.print_areas,productId:e.product.id,fileId:g.id,allFileLinks:R});if(i){y.claimed.push(null!==(o=null===(r=e.product)||void 0===r?void 0:r.name)&&void 0!==o?o:"this product");continue}let c=null!==(a=null==l?void 0:l.id)&&void 0!==a?a:nY(e.product,t);if(!c){y.unresolved.push(null!==(s=null===(d=e.product)||void 0===d?void 0:d.name)&&void 0!==s?s:"this product");continue}m.push({podEntry:e,printAreaId:c,link:{id:"".concat(Date.now(),"-").concat(m.length),productId:e.product.id,printArea:t,printAreaId:c,colors:null,colorMapping:u,...eP.aP}})}if(!m.length){lC.current=!0,y.claimed.length?O.Am.info("Design couldn't be auto-attached â every print area already has a design. Assign it manually."):y.unresolved.length&&O.Am.info("Design couldn't be auto-attached â its print area couldn't be resolved. Assign it manually.");return}(y.claimed.length||y.unresolved.length)&&O.Am.info("Design couldn't be auto-attached to ".concat([...y.claimed,...y.unresolved].join(", "),". Assign ").concat(y.claimed.length+y.unresolved.length>1?"them":"it"," manually."));let b=i?void 0:B.current.find(e=>{var l,t;let n=null!==(t=null==e?void 0:e.asset_file_id)&&void 0!==t?t:null==e?void 0:e.assetFileId;return null!=n&&(null===(l=g.file)||void 0===l?void 0:l.id)!=null&&String(n)===String(g.file.id)});if(b&&0===(null!==(c=null!==(u=b.assigned_to)&&void 0!==u?u:b.targets)&&void 0!==c?c:[]).length){let e=null!==(p=R[g.id])&&void 0!==p?p:[],l=m.map(e=>e.link).filter(l=>!e.some(e=>e.productId===l.productId));l.length&&l6(g.id,[...e,...l])}else A(e=>{var l;let t=null!==(l=e[g.id])&&void 0!==l?l:[],n=m.map(e=>e.link).filter(e=>!t.some(l=>l.productId===e.productId));return n.length?{...e,[g.id]:[...t,...n]}:e});lC.current=!0;let j=m.filter(e=>e.podEntry.podProductId);i&&j.length&&(null===(l=g.file)||void 0===l?void 0:l.id)&&!E[g.id]&&(0,eI.Ps)(i,{asset_file_id:g.file.id,file_name:null!==(x=null!==(f=null===(v=g.file)||void 0===v?void 0:v.originalFilename)&&void 0!==f?f:null===(h=g.file)||void 0===h?void 0:h.fileName)&&void 0!==x?x:"",assigned_to:j.map(e=>({pod_product_id:e.podEntry.podProductId,print_area_id:e.printAreaId,color_mapping:e.link.colorMapping,placement:{...eP.Rd}}))}).then(e=>{var l,t,n,i,r;let o=null!==(r=null!==(i=null==e?void 0:null===(t=e.data)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.id)&&void 0!==i?i:null==e?void 0:null===(n=e.data)||void 0===n?void 0:n.id)&&void 0!==r?r:null;o&&M(e=>({...e,[g.id]:o}))}).catch(e=>{var l,t;console.error("[PodDesignPanel initial auto-link]",null!==(t=null==e?void 0:null===(l=e.response)||void 0===l?void 0:l.data)&&void 0!==t?t:e),O.Am.error(n4(e,"Couldn't attach the design file.","Please try again."))})},[e2,t,R,i,lc,en,lf,lb]);let lZ=(0,a.useRef)(null),lP=(0,a.useCallback)((e,l,n)=>{var i,r,o,a,d,s,u,c,p,v,h,f,x,g,m;let y=null!==(v=lj.current[e])&&void 0!==v?v:[],b=l_.current[e],j=null!==(h=null===(i=l.tempDeliverable)||void 0===i?void 0:i.id)&&void 0!==h?h:"pending-file-".concat(null===(r=l.payload)||void 0===r?void 0:r.fileId),_=null!==(f=null===(o=l.payload)||void 0===o?void 0:o.fileId)&&void 0!==f?f:null===(d=l.tempDeliverable)||void 0===d?void 0:null===(a=d.file)||void 0===a?void 0:a.id,w=null!==(g=null!==(x=null===(u=l.tempDeliverable)||void 0===u?void 0:null===(s=u.file)||void 0===s?void 0:s.originalFilename)&&void 0!==x?x:null===(p=l.tempDeliverable)||void 0===p?void 0:null===(c=p.file)||void 0===c?void 0:c.fileName)&&void 0!==g?g:"";if(lZ.current={oldItemId:e,tempId:j,links:y,oldAssignmentId:b},ly(null!=n?n:{id:e}),ew({type:l.type,...l.payload},l.tempDeliverable),lS.current&&b&&y.length&&_){let l=y.map(e=>{var l,n,i,r,o;let a=t.find(l=>l.product.id===e.productId),d=null==a?void 0:a.podProductId;if(!d)return null;let s=null===(n=a.product)||void 0===n?void 0:null===(l=n.print_areas)||void 0===l?void 0:l.find(l=>
1l.name===e.printArea),u=null!==(r=null!==(i=null==s?void 0:s.id)&&void 0!==i?i:e.printAreaId)&&void 0!==r?r:nY(a.product,e.printArea||"front");return u?{pod_product_id:d,print_area_id:u,color_mapping:null!==(o=e.colorMapping)&&void 0!==o?o:"all",placement:i_(e).placement}:(console.warn("[PodDesignPanel handleReplaceFile] no resolvable print area; skipping target",{podProductId:d,printArea:e.printArea}),null)}).filter(Boolean),n=new Set(l.map(e=>"".concat(e.pod_product_id,"::").concat(e.print_area_id))),i=[...l,...(null!==(m=ei.current[e])&&void 0!==m?m:[]).map(e=>{var l,n,i,r,o;let a;let d=(0,eZ.UE)(t,e.pod_product_id),s=null==d?void 0:d.podProductId;if(!s)return console.warn("[PodDesignPanel handleReplaceFile] preserved target's product unresolvable; dropping",e),null;if(null==e.print_area_id||""===e.print_area_id){let e=null===(n=d.product)||void 0===n?void 0:null===(l=n.print_areas)||void 0===l?void 0:l[0];a=e?null!==(i=e.id)&&void 0!==i?i:"pa_1":null}else{let l=(0,eP.z_)(null===(r=d.product)||void 0===r?void 0:r.print_areas,e.print_area_id);a=null!==(o=null==l?void 0:l.id)&&void 0!==o?o:l?nY(d.product,l.name||l.position||""):nY(d.product,e.print_area_id)}return a?{...e,pod_product_id:s,print_area_id:a}:(console.warn("[PodDesignPanel handleReplaceFile] preserved target's print area unresolvable; dropping",e),null)}).filter(e=>e&&!n.has("".concat(e.pod_product_id,"::").concat(e.print_area_id)))];(0,eI.St)(lS.current,b).then(()=>{if(i.length)return(0,eI.Ps)(lS.current,{asset_file_id:_,file_name:w,assigned_to:i}).then(e=>{var l,t,n,i,r;let o=null!==(r=null!==(i=null==e?void 0:null===(t=e.data)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.id)&&void 0!==i?i:null==e?void 0:null===(n=e.data)||void 0===n?void 0:n.id)&&void 0!==r?r:null;o&&(lZ.current={...lZ.current,newAssignmentId:o})})}).catch(e=>{var l,t;console.error("[PodDesignPanel handleReplaceFile]",null!==(t=null==e?void 0:null===(l=e.response)||void 0===l?void 0:l.data)&&void 0!==t?t:e),O.Am.error(n4(e,"Couldn't re-create the design's product links after replacing the file.","Refresh and re-link the design."))})}},[t,e_,ly]);(0,a.useEffect)(()=>{let e=lZ.current;if(!e)return;let{oldItemId:l,tempId:t,links:n,newAssignmentId:i}=e,r=eg.find(e=>e.id===t);r&&(ei.current[l]&&(ei.current[r.id]=ei.current[l],delete ei.current[l]),A(e=>{let t={...e};return delete t[l],t[r.id]=n,t}),P(e=>{var t;let n={...e};return n[r.id]=null===(t=n[l])||void 0===t||t,delete n[l],n}),i&&M(e=>{let t={...e};return delete t[l],t[r.id]=i,t}),eS(l),lZ.current=null)},[eg]);let lR=(0,a.useCallback)(async e=>{var l,t,n,i,r,o,a,d,s;let u="function"==typeof(null==e?void 0:e.shouldAbort)?e.shouldAbort:()=>!1;if(u())return iL.ABORTED;let c=null==e?void 0:null===(l=e.tempDeliverable)||void 0===l?void 0:l.file,p=null!==(n=null==e?void 0:null===(t=e.payload)||void 0===t?void 0:t.fileId)&&void 0!==n?n:null==c?void 0:c.id;if(!p)return iL.ABORTED;let v=String(p),h=e=>{var l;let t=null!==(l=null==e?void 0:e.asset_file_id)&&void 0!==l?l:null==e?void 0:e.assetFileId;return null==t?null:String(t)};if(B.current.some(e=>h(e)===v))return iL.DUPLICATE;let f="preset-file-".concat(p),x=null!==(r=null!==(i=null==c?void 0:c.originalFilename)&&void 0!==i?i:null==c?void 0:c.fileName)&&void 0!==r?r:"design",g=null;try{let e=await (0,er.hn)(p);g=null!==(d=null!==(a=null==e?void 0:null===(o=e.data)||void 0===o?void 0:o.data)&&void 0!==a?a:null==e?void 0:e.data)&&void 0!==d?d:null}catch(e){g=null}if(u())return iL.ABORTED;if(B.current.some(e=>h(e)===v))return iL.DUPLICATE;let m=B.current.findIndex(iI);if(-1!==m){let e=B.current[m],l=e._placeholderId,t={...e,asset_file_id:p,file_name:x,fillMode:"fixed"};V(e=>e.map((e,l)=>l===m?t:e)),null!=l&&ei.current[l]&&(ei.current[f]=ei.current[l],delete ei.current[l]),A(e=>{var t;let n={...e},i=null!=l&&null!==(t=n[l])&&void 0!==t?t:[];return null!=l&&delete n[l],n[f]=i,n}),P(e=>{var t;let n={...e,[f]:null==l||null===(t=e[l])||void 0===t||t};return null!=l&&delete n[l],n});let n=iw(g,p,x);return Y(e=>e.some(e=>{var l;return(null===(l=e.file)||void 0===l?void 0:l.id)!=null&&String(e.file.id)===v})?e:[...e,n]),iL.COMMITTED}let y=null!==(s=ed.current)&&void 0!==s?s:[],b=[],j=[];
1y.forEach((e,l)=>{var t,n;if(!(null==e?void 0:e.podProductId))return;let i=(0,nJ.q)(null===(t=e.product)||void 0===t?void 0:t.print_areas),r=(null==i?void 0:i.name)||(null==i?void 0:i.position)||"front",o=null!==(n=null==i?void 0:i.id)&&void 0!==n?n:nY(e.product,r);if(!o){console.warn("[PodDesignPanel addPresetDesignFromLibrary] no resolvable print area; adding design unlinked",{podProductId:e.podProductId,printAreaName:r});return}let a=B.current.some(l=>{var t,n;return(null!==(n=null!==(t=l.assigned_to)&&void 0!==t?t:l.targets)&&void 0!==n?n:[]).some(l=>(0,eZ.UE)(y,null==l?void 0:l.pod_product_id)===e)}),d={pod_product_id:e.podProductId,print_area_id:o,color_mapping:a?{type:"specific",option_ids:[]}:"all",placement:{...eP.Rd}};b.push(d),j.push((0,eP.lP)(d,{linkId:"preset-".concat(f,"-").concat(l),productId:e.product.id,printAreaName:r,printAreaId:o,geometry:ij(i,null)}))});let _={asset_file_id:p,file_name:x,is_enabled:!0,fillMode:"fixed",assigned_to:b};V(e=>[...e,_]),j.length&&A(e=>{var l;return(null===(l=e[f])||void 0===l?void 0:l.length)?e:{...e,[f]:j}}),P(e=>({...e,[f]:!0}));let w=iw(g,p,x);return Y(e=>e.some(e=>{var l;return(null===(l=e.file)||void 0===l?void 0:l.id)!=null&&String(e.file.id)===v})?e:[...e,w]),iL.COMMITTED},[]),lA=(0,a.useRef)(new Set),lE=(0,a.useRef)(Promise.resolve()),lM=(0,a.useRef)(null);lM.current=lR;let lz=(0,a.useRef)(null);lz.current=eS;let[lD,lL]=(0,a.useState)({}),lO=(0,a.useRef)(new Map),lF=(0,a.useCallback)(e=>{var l;return null!==(l=lO.current.get(String(e)))&&void 0!==l?l:0},[]),lT=(0,a.useCallback)(e=>{var l;let t=String(e),n=(null!==(l=lO.current.get(t))&&void 0!==l?l:0)+1;return lO.current.set(t,n),n},[]),lN=(0,a.useCallback)(function(e,l){let{preserveUserAction:t=!1}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};lL(n=>{let i=String(e),r=n[i];return t&&((null==r?void 0:r.kind)===iM.CHECKING||(null==r?void 0:r.kind)===iM.FAILED)||r&&r.kind===l.kind&&r.message===l.message&&r.fileName===l.fileName&&r.deliverableId===l.deliverableId?n:{...n,[i]:{...l,presetGen:J.current}}})},[]),lW=(0,a.useCallback)(e=>{lL(l=>{let t=String(e);if(!(t in l))return l;let{[t]:n,...i}=l;return i})},[]),lU=(0,a.useCallback)(async(e,l,t,n)=>{var i,r;let o=null==l?void 0:l.id;if(null==o)return iL.ABORTED;let a=()=>null!=t&&lF(o)!==t||J.current!==n;if(a())return iL.ABORTED;let d=await (null===(i=lM.current)||void 0===i?void 0:i.call(lM,{payload:{fileId:o},tempDeliverable:{file:l},shouldAbort:a}));return d===iL.ABORTED||(null===(r=lz.current)||void 0===r||r.call(lz,e),a()||lW(o)),d},[lW,lF]);(0,a.useEffect)(()=>{if(i)return;let e=(null!=eg?eg:[]).filter(e=>{var l;return(null==e?void 0:null===(l=e.file)||void 0===l?void 0:l.id)!=null});if(e.length)for(let l of e){let e=l.file.id,t=String(e);if(lA.current.has(t))continue;let n=lG(l);if(n!==J.current){lA.current.add(t),lN(e,{fileId:e,deliverableId:l.id,fileName:iF(l.file),kind:iM.FAILED,message:iz.PRESET_CHANGED});continue}let i=iT(l.file);if(i){lN(e,{fileId:e,deliverableId:l.id,fileName:iF(l.file),...i},{preserveUserAction:!0});continue}lA.current.add(t);let r=l.id,o=l.file,a=lF(e);l$(),lE.current=lE.current.then(async()=>{await lU(r,o,a,n)===iL.ABORTED&&lF(e)===a&&J.current!==n&&lN(e,{fileId:e,deliverableId:r,fileName:iF(o),kind:iM.FAILED,message:iz.PRESET_CHANGED})}).catch(l=>{lF(e)===a&&(console.error("[PodDesignPanel preset upload adoption]",l),lN(e,{fileId:e,deliverableId:r,fileName:iF(o),kind:iM.FAILED,message:iz.ATTACH_FAILED}),O.Am.error(iD))}).finally(lX)}},[i,eg]);let lH=(0,a.useCallback)(async e=>{let{fileId:l}=e,t=String(l),n=lF(l),i=J.current;lN(l,{...e,kind:iM.CHECKING,message:iz.CHECKING});let r=null;try{var o,a,d;let e=await (0,er.hn)(l);r=null!==(d=null!==(a=null==e?void 0:null===(o=e.data)||void 0===o?void 0:o.data)&&void 0!==a?a:null==e?void 0:e.data)&&void 0!==d?d:null}catch(e){r=null}if(lF(l)!==n)return;if(J.current!==i){lN(l,{...e,kind:iM.FAILED,message:iz.PRESET_CHANGED});return}if(!r){lN(l,{...e,kind:iM.FAILED,message:iz.LOOKUP_FAILED});return}let s=iT(r);if(s){lN(l,{...e,fileName:iF(r)||e.fileName,...s}),O.Am.info(s.kind===iM.FAILED?s.message:"This design is still being checked for print readiness â try again in a moment.");return}lA.current.add(t);try{await lU(e.deliverableId,r,n,i)===iL.ABORTED&&lF(l)===n&&lN(l,{...e,kind:iM.FAILED,message:iz.PRESET_CHANGED})}catch(t){if(lF(l)!==n)return;console.error("[PodDesignPanel preset upload retry]",t),lN(l,{...e,kind:iM.FAILED,message:iz.ATTACH_FAILED}),O.Am.error(iD)}},[lU,lN,lF]),lB=(0,a.useCallback)(e=>{var l;lT(e.fileId),lA.current.add(String(e.fileId)),null===(l=lz.current)||void 0===l||l.call(lz,e.deliverableId),lW(e.fileId)},[lW,lT]);(0,a.useEffect)(()=>{lL(e=>{let l=!1,t={};for(let[n,i]of Object.entries(e))(i.kind===iM.PROCESSING||i.kind===iM.CHECKING)&&i.presetGen!==d?(t[n]={...i,kind:iM.FAILED,message:iz.PRESET_CHANGED},l=!0):t[n]=i;return l?t:e})},[d]);let lV=(0,a.useMemo)(()=>Object.values(lD),[lD]),lK=(0,a.useRef)(new Map),lq=(0,a.useCallback)((e,l,t)=>{var n,i;let r=null!=t?t:J.current,o=null!==(i=null===(n=ev.current)||void 0===n?void 0:n.call(ev,e,l))&&void 0!==i?i:[];for(let e of o)lK.current.set(e,r);return o},[]);eh.current=lq;let lG=(0,a.useCallback)(e=>{let l=null==e?void 0:e._uploadTempId,t=null!=l?lK.current.get(l):void 0;return null!=t?t:J.current},[]),[lY,lQ]=(0,a.useState)(0),l$=(0,a.useCallback)(()=>lQ(e=>e+1),[]),lX=(0,a.useCallback)(()=>lQ(e=>Math.max(0,e-1)),[]),lJ=(null!=em?em:[]).some(e=>"uploading"===e.status||"retrying"===e.status)||lV.some(e=>e.kind===iM.PROCESSING||e.kind===iM.CHECKING)||lY>0,l0=(0,a.useRef)(null);l0.current=o,(0,a.useEffect)(()=>{null==o||o(lJ)},[lJ]),(0,a.useEffect)(()=>()=>{var e;return null===(e=l0.current)||void 0===e?void 0:e.call(l0,!1)},[]);let l1=(0,a.useCallback)(()=>{V(e=>{let l=e.filter(iI).length,t={asset_file_id:null,file_name:"Placeholder ".concat(l+1),is_enabled:!0,fillMode:"upload_required",assigned_to:[]};return ik(t),[...e,t]}),(0,Z.L)("preset.mockup_slot_added",{surface:"preset",fillMode:"upload_required"})},[V]),l5=e=>{var l;
1(null!==(l=R[e])&&void 0!==l?l:[]).forEach((l,n)=>{var i,r,o,a;if(!(null==l?void 0:l.productId)||!(null==l?void 0:l.printArea))return;let d=t.find(e=>e.product.id===l.productId),s=nG(null==d?void 0:null===(i=d.product)||void 0===i?void 0:i.variations),u=null!==(r=null==s?void 0:s.id)&&void 0!==r?r:"colors",c=(null!==(o=null==s?void 0:s.options)&&void 0!==o?o:[]).filter(e=>{var l,t;return null==d?void 0:null===(t=d.selection)||void 0===t?void 0:null===(l=t[u])||void 0===l?void 0:l[e.id]}).map(e=>e.id),p=l.colorMapping&&"all"!==l.colorMapping?null!==(a=l.colorMapping.option_ids)&&void 0!==a?a:[]:c;p.length&&ti(l.productId,l.printArea,p,e,n)}),delete ei.current[e],Y(l=>l.filter(l=>l.id!==e)),V(l=>l.filter(l=>{var t;return l._placeholderId?l._placeholderId!==e:"preset-file-".concat(null!==(t=l.asset_file_id)&&void 0!==t?t:l.assetFileId)!==e})),A(l=>{if(!(e in l))return l;let t={...l};return delete t[e],t}),P(l=>{if(!(e in l))return l;let t={...l};return delete t[e],t})},l2=(e,l)=>{P(t=>({...t,[e]:l}));let t=E[e];i&&t&&(0,eI.Kf)(i,t,l).catch(()=>{})},l3=(0,a.useCallback)((e,l)=>{V(t=>t.map(t=>t._placeholderId===e?{...t,file_name:l}:t))},[V]),l4=(0,a.useCallback)((e,l)=>{V(t=>t.map(t=>t._placeholderId===e?{...t,is_enabled:l}:t))},[V]),l7=function(e,l,n){var i,r,o,a,d,s,u,c,p;let v=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},{isExplicitUnlink:h=!1,outcome:f=null}=v,x=e.findIndex(e=>e._placeholderId===l);if(-1!==x){let i=e[x],u=n.map(e=>{var l,n,i,r,o,a,d;let s=t.find(l=>l.product.id===e.productId),u=null==s?void 0:s.podProductId;if(!u)return f&&(f.skipped=(f.skipped||0)+1),null;let c=e.printArea||"front",p=null!==(o=null===(n=s.product)||void 0===n?void 0:null===(l=n.print_areas)||void 0===l?void 0:l.find(e=>(e.name||e.position||"").toLowerCase()===c.toLowerCase()))&&void 0!==o?o:null===(r=s.product)||void 0===r?void 0:null===(i=r.print_areas)||void 0===i?void 0:i[0],v=null!==(d=null!==(a=null==p?void 0:p.id)&&void 0!==a?a:e.printAreaId)&&void 0!==d?d:nY(s.product,c);if(!v)return console.warn("[PodDesignPanel patchSeedForLinks] no resolvable print area; skipping target",{podProductId:u,printAreaName:c}),f&&(f.skipped=(f.skipped||0)+1),null;let h=i_(e);return{pod_product_id:u,print_area_id:v,color_mapping:h.color_mapping,placement:h.placement,...h.print_constraints&&{print_constraints:h.print_constraints}}}).filter(Boolean),c=new Set(u.map(e=>"".concat(e.pod_product_id,"::").concat(e.print_area_id))),p=e=>{var l,n,i,r;let o=(0,eZ.UE)(t,e.pod_product_id),a=null!==(n=null==o?void 0:o.podProductId)&&void 0!==n?n:e.pod_product_id,d=(0,eP.z_)(null==o?void 0:null===(l=o.product)||void 0===l?void 0:l.print_areas,e.print_area_id),s=null!==(r=null!==(i=null==d?void 0:d.id)&&void 0!==i?i:o&&d?nY(o.product,d.name||d.position||""):null)&&void 0!==r?r:e.print_area_id;return"".concat(a,"::").concat(s)},v=(null!==(r=ei.current[l])&&void 0!==r?r:[]).filter(e=>!c.has(p(e))),g=(null!==(a=null!==(o=i.assigned_to)&&void 0!==o?o:i.targets)&&void 0!==a?a:[]).length>0,m=0===u.length&&0===v.length;if(g&&m&&!h)return console.warn("[PodDesignPanel patchSeedForLinks] refusing to empty a seeded placeholder's assigned_to â no explicit unlink",{itemId:l,storedTargetCount:(null!==(s=null!==(d=i.assigned_to)&&void 0!==d?d:i.targets)&&void 0!==s?s:[]).length}),f&&(f.refused=!0),e;let y=[...e];return y[x]={...i,assigned_to:[...u,...v]},y}let g=G.find(e=>e.id===l),m=null!==(u=null==g?void 0:null===(i=g.file)||void 0===i?void 0:i.id)&&void 0!==u?u:null;if(!m)return e;let y=String(m),b=e.findIndex(e=>{var l;let t=null!==(l=null==e?void 0:e.asset_file_id)&&void 0!==l?l:null==e?void 0:e.assetFileId;return null!=t&&String(t)===y});if(-1===b)return e;let j=e[b],_=null!==(p=null!==(c=j.targets)&&void 0!==c?c:j.assigned_to)&&void 0!==p?p:[],w=(e,l)=>{var t,n,i;return null!==(i=null===(t=(0,eP.z_)(null==l?void 0:null===(n=l.product)||void 0===n?void 0:n.print_areas,e.print_area_id))||void 0===t?void 0:t.id)&&void 0!==i?i:e.print_area_id},S=(e,l)=>{var t,n;return null!==(n=null!==(t=e.printAreaId)&&void 0!==t?t:nY(null==l?void 0:l.product,e.printArea||"front"))&&void 0!==n?n:null},k=new Set,I=new Map;_.forEach((e,l)=>{var i;let r=(0,eZ.UE)(t,e.pod_product_id),o=null==r?void 0:null===(i=r.product)||void 0===i?void 0:i.id;if(!o)return;let a=w(e,r),d=n.find(e=>{if(k.has(e)||e.productId!==o)return!1;let l=S(e,r);return null!=l&&String(l)===String(a)});d&&(k.add(d),I.set(l,{link:d,podEntry:r,areaMoved:!1}))}),_.forEach((e,l)=>{var i;if(I.has(l))return;let r=(0,eZ.UE)(t,e.pod_product_id),o=null==r?void 0:null===(i=r.product)||void 0===i?void 0:i.id;if(!o)return;let a=n.find(e=>!k.has(e)&&e.productId===o);a&&(k.add(a),I.set(l,{link:a,podEntry:r,areaMoved:!0}
1))});let C=_.map((e,l)=>{let t=I.get(l);if(!t)return e;let n=i_(t.link),i=t.areaMoved?S(t.link,t.podEntry):null,r=null!=i&&String(i)!==String(w(e,t.podEntry));return{...e,...r&&{print_area_id:i},color_mapping:n.color_mapping,placement:n.placement,...n.print_constraints&&{print_constraints:n.print_constraints}}}),Z=n.filter(e=>!k.has(e)).map(e=>{var l,n,i,r,o,a,d;let s=t.find(l=>l.product.id===e.productId),u=null==s?void 0:s.podProductId;if(!u)return null;let c=e.printArea||"front",p=null!==(o=null===(n=s.product)||void 0===n?void 0:null===(l=n.print_areas)||void 0===l?void 0:l.find(e=>(e.name||e.position||"").toLowerCase()===c.toLowerCase()))&&void 0!==o?o:null===(r=s.product)||void 0===r?void 0:null===(i=r.print_areas)||void 0===i?void 0:i[0],v=null!==(d=null!==(a=null==p?void 0:p.id)&&void 0!==a?a:e.printAreaId)&&void 0!==d?d:nY(s.product,c);if(!v)return console.warn("[PodDesignPanel patchSeedForLinks] no resolvable print area; skipping appended target",{podProductId:u,printAreaName:c}),null;if(C.some(e=>{var l,n,i,r;let o=(0,eZ.UE)(t,e.pod_product_id);return String(null!==(i=null==o?void 0:o.podProductId)&&void 0!==i?i:e.pod_product_id)===String(u)&&String(null!==(r=null===(l=(0,eP.z_)(null==o?void 0:null===(n=o.product)||void 0===n?void 0:n.print_areas,e.print_area_id))||void 0===l?void 0:l.id)&&void 0!==r?r:e.print_area_id)===String(v)}))return null;let h=i_(e);return{pod_product_id:u,print_area_id:v,color_mapping:h.color_mapping,placement:h.placement,...h.print_constraints&&{print_constraints:h.print_constraints}}}).filter(Boolean),P=[...e];return P[b]={...j,["targets"in j?"targets":"assigned_to"]:Z.length?[...C,...Z]:C},P},l6=function(e,l){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=ei.current[e];if((null==r?void 0:r.length)&&t.length){let n=new Set(l.map(e=>e.productId).filter(e=>null!=e)),i=r.filter(e=>{var l,i;let r=null===(i=(0,eZ.UE)(t,e.pod_product_id))||void 0===i?void 0:null===(l=i.product)||void 0===l?void 0:l.id;return null==r||n.has(r)});i.length!==r.length&&(i.length?ei.current[e]=i:delete ei.current[e])}if(i)return A(t=>({...t,[e]:l})),!0;let o={refused:!1,skipped:0},a=l7(B.current,e,l,{isExplicitUnlink:!0===n.isExplicitUnlink,outcome:o});return!o.refused&&!(o.skipped>0)&&(A(t=>({...t,[e]:l})),V(()=>a),!0)},l8=(0,a.useRef)(Promise.resolve()),l9=(0,a.useRef)(0),te=(0,a.useRef)(!1),tl=e=>{var l;return e&&"all"!==e?{type:"specific",option_ids:null!==(l=e.option_ids)&&void 0!==l?l:[]}:"all"},tt=function(e,l,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(!i)return;let{excludeFileId:o=null,excludeLinkIdx:a=null,after:d=null}=r,s=e=>{var l;return(null!==(l=R[e])&&void 0!==l?l:[]).map((l,t)=>{var i,r;return null!==(r=null===(i=n[e])||void 0===i?void 0:i.get(t))&&void 0!==r?r:l})},u=[],c=[];for(let t of e4){let n=E[t.id];n&&(e7.has(t.id)||s(t.id).forEach((i,r)=>{(t.id!==o||r!==a)&&i.productId===e&&i.printArea===l&&(u.push({assignment_id:n,color_mapping:tl(i.colorMapping)}),c.push({fid:t.id,idx:r}))}))}if(0===u.length)return;let p=iC(t,{productId:e,printArea:l});p&&(l9.current+=1,l8.current=l8.current.then(()=>{if(d)return Promise.resolve("function"==typeof d?d():d).catch(()=>{})}).then(()=>(0,eI.eU)(i,{pod_product_id:p.pod_product_id,print_area_id:p.print_area_id,entries:u})).then(()=>{l9.current-=1,te.current=!1}).catch(e=>{var l,t,n,i,r;l9.current-=1,te.current=!0,console.error("[PodDesignPanel] color partition rejected â reverting local state",null!==(i=null==e?void 0:null===(l=e.response)||void 0===l?void 0:l.data)&&void 0!==i?i:e),A(e=>{let l={...e},t=!1;return c.forEach(e=>{var n;let{fid:i,idx:r}=e,o=(null!==(n=R[i])&&void 0!==n?n:[])[r],a=l[i],d=null==a?void 0:a[r];if(!o||!d||d===o||String(d.id)!==String(o.id))return;let s=a.slice();s[r]=o,l[i]=s,t=!0}),t?l:e}),O.Am.error("Couldn't update which design prints on each color. ".concat(null!==(r=null==e?void 0:null===(n=e.response)||void 0===n?void 0:null===(t=n.data)||void 0===t?void 0:t.message)&&void 0!==r?r:"Please try again."))}))},tn=(e,l,n,r,o)=>{var a,d,s,u,c,p,v,h,f,x,g,m;let y=null!==(s=R[n])&&void 0!==s?s:[],b=null!==(u=R[e])&&void 0!==u?u:[],j=y[r],_=b[l];if(!j||!_||j.productId!==_.productId||j.printArea!==_.printArea)return;let w=t.find(e=>e.product.id===j.productId),S=nG(null==w?void 0:null===(a=w.product)||void 0===a?void 0:a.variations),k=null!==(c=null==S?void 0:S.id)&&void 0!==c?c:"colors",I=(null!==(p=null==S?void 0:S.options)&&void 0!==p?p:[]).filter(e=>{var l,t;return null==w?void 0:null===(t=w.selection)||void 0===t?void 0:null===(l=t[k])||void 0===l?void 0:l[e.id]}).map(e=>e.id),C=String(o),Z=j.colorMapping&&"all"!==j.colorMapping?{...j.colorMapping,type:"specific",option_ids:(null!==(v=j.colorMapping.option_ids)&&void 0!==v?v:[]).filter(e=>String(e)!==C)}:{type:"specific",option_ids:I.filter(e=>String(e)!==C)},P=null!==(h=null===(d=_.colorMapping)||void 0===d?void 0:d.option_ids)&&void 0!==h?h:[],E=_.colorMapping&&"all"!==_.colorMapping?{..._.colorMapping,type:"specific",option_ids:P.some(e=>String(e)===C)?P:[...P,o]}:_.colorMapping,M={...j,colorMapping:Z},z={..._,colorMapping:E};if(A(t=>{var i,o;let a={...t};return a[n]=(null!==(i=t[n])&&void 0!==i?i:[]).map((e,l)=>l===r?M:e),n===e?a[n]=a[n].map((e,t)=>t===l?z:e):a[e]=(null!==(o=t[e])&&void 0!==o?o:[]).map((e,t)=>t===l?z:e),a}),!i){let t={};(null!==(f=t[n])&&void 0!==f?f:t[n]=new Map).set(r,M),(null!==(x=t[e])&&void 0!==x?x:t[e]=new Map).set(l,z),V(e=>{let l=e;
1return Object.entries(t).forEach(e=>{var t;let[n,i]=e,r=(null!==(t=R[n])&&void 0!==t?t:[]).map((e,l)=>{var t;return null!==(t=i.get(l))&&void 0!==t?t:e});l=l7(l,n,r)}),l});return}let D={};(null!==(g=D[n])&&void 0!==g?g:D[n]=new Map).set(r,M),(null!==(m=D[e])&&void 0!==m?m:D[e]=new Map).set(l,z),tt(j.productId,j.printArea,D)},ti=function(e,l,n,r,o){var a,d,s,u,c,p;let v=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};if(!e||!l||!(null==n?void 0:n.length))return;let h=null;for(let t of e4){let n=t.id;if(e7.has(n))continue;let i=null!==(d=R[n])&&void 0!==d?d:[];for(let t=0;t<i.length;t++){if(n===r&&t===o)continue;let a=i[t];if(a.productId===e&&a.printArea===l){h={fileId:n,linkIdx:t,link:a};break}}if(h)break}if(!h)return;let f=h.link;if(!f.colorMapping||"all"===f.colorMapping)return;let x=t.find(l=>l.product.id===e),g=nG(null==x?void 0:null===(a=x.product)||void 0===a?void 0:a.variations),m=null!==(s=null==g?void 0:g.id)&&void 0!==s?s:"colors",y=(null!==(u=null==g?void 0:g.options)&&void 0!==u?u:[]).filter(e=>{var l,t;return null==x?void 0:null===(t=x.selection)||void 0===t?void 0:null===(l=t[m])||void 0===l?void 0:l[e.id]}).map(e=>e.id),b=new Set;e4.forEach(t=>{var n;e7.has(t.id)||(null!==(n=R[t.id])&&void 0!==n?n:[]).forEach((n,i)=>{var a;(t.id!==r||i!==o)&&(t.id!==h.fileId||i!==h.linkIdx)&&n.productId===e&&n.printArea===l&&(n.colorMapping&&"all"!==n.colorMapping?null!==(a=n.colorMapping.option_ids)&&void 0!==a?a:[]:y).forEach(e=>b.add(String(e)))})});let j=[...null!==(c=f.colorMapping.option_ids)&&void 0!==c?c:[]],_=new Set(j.map(String));n.forEach(e=>{b.has(String(e))||_.has(String(e))||(j.push(e),_.add(String(e)))});let w=y.length>0&&y.every(e=>_.has(String(e)))?"all":{...f.colorMapping,type:"specific",option_ids:j},S={...f,colorMapping:w};if(A(e=>{var l;let t={...e};return t[h.fileId]=(null!==(l=e[h.fileId])&&void 0!==l?l:[]).map((e,l)=>l===h.linkIdx?S:e),t}),!i){V(e=>{var l;let t=(null!==(l=R[h.fileId])&&void 0!==l?l:[]).map((e,l)=>l===h.linkIdx?S:e);return l7(e,h.fileId,t)});return}tt(e,l,{[h.fileId]:new Map([[h.linkIdx,S]])},{excludeFileId:r,excludeLinkIdx:o,after:null!==(p=v.after)&&void 0!==p?p:null})},tr=(e,l,n)=>{var r,o,a,d,s,u;let c=(null!==(o=R[e])&&void 0!==o?o:[])[l];if(!c)return;let p=t.find(e=>e.product.id===c.productId),v=nG(null==p?void 0:null===(r=p.product)||void 0===r?void 0:r.variations),h=null!==(a=null==v?void 0:v.id)&&void 0!==a?a:"colors",f=(null!==(d=null==v?void 0:v.options)&&void 0!==d?d:[]).filter(e=>{var l,t;return null==p?void 0:null===(t=p.selection)||void 0===t?void 0:null===(l=t[h])||void 0===l?void 0:l[e.id]}).map(e=>e.id),x=new Map;(null!==(s=null==v?void 0:v.options)&&void 0!==s?s:[]).forEach(e=>x.set(String(e.id),e.id));let g=e=>{let l=String(e);return x.has(l)||x.set(l,e),l},m=f.map(e=>String(e)),y=e=>{var l;return new Set((e&&"all"!==e?null!==(l=e.option_ids)&&void 0!==l?l:[]:f).map(g))},b=e=>[...e].map(e=>x.get(e)),j=y(c.colorMapping),_=y(n);[..._].filter(e=>!j.has(e));let w=[...j].filter(e=>!_.has(e)),S={},k=(e,l)=>{var t,n,i,r;return null!==(r=null!==(i=null===(t=S[e])||void 0===t?void 0:t.get(l))&&void 0!==i?i:(null!==(n=R[e])&&void 0!==n?n:[])[l])&&void 0!==r?r:null},I=(e,l,t)=>{S[e]||(S[e]=new Map),S[e].set(l,t)},C=new Map;e4.forEach(t=>{var n;(null!==(n=R[t.id])&&void 0!==n?n:[]).forEach((n,i)=>{var r;(t.id!==e||i!==l)&&n.productId===c.productId&&n.printArea===c.printArea&&(n.colorMapping&&"all"!==n.colorMapping?null!==(r=n.colorMapping.option_ids)&&void 0!==r?r:[]:f).forEach(e=>{let l=g(e);C.has(l)||C.set(l,[]),C.get(l).push({fileId:t.id,linkIdx:i})})})}),_.forEach(e=>{let l=C.get(e);l&&l.forEach(l=>{let t=k(l.fileId,l.linkIdx);if(!t)return;let n=y(t.colorMapping);n.has(e)&&(n.delete(e),I(l.fileId,l.linkIdx,{...t,colorMapping:{type:"specific",option_ids:b(n)}}))})});let Z=w.filter(e=>{var l;return!(null!==(l=C.get(e))&&void 0!==l?l:[]).some(l=>{let t=k(l.fileId,l.linkIdx);return t&&y(t.colorMapping).has(e)})});if(Z.length>0){let t=null;for(let n of e4){let i=null!==(u=R[n.id])&&void 0!==u?u:[];for(let r=0;r<i.length;r++){if(n.id===e&&r===l)continue;let o=i[r];if(o.productId===c.productId&&o.printArea===c.printArea){t={fileId:n.id,linkIdx:r};break}}if(t)break}if(t){let e=k(t.fileId,t.linkIdx);if(e){let l=y(e.colorMapping);
1Z.forEach(e=>l.add(e));let n=m.length>0&&m.every(e=>l.has(e));I(t.fileId,t.linkIdx,{...e,colorMapping:n?"all":{type:"specific",option_ids:b(l)}})}}}let P=m.length>0&&m.every(e=>_.has(e)),E=k(e,l);if(I(e,l,{...E,colorMapping:"all"===n||P?"all":{type:"specific",option_ids:b(_)}}),A(e=>{let l={...e};return Object.entries(S).forEach(t=>{var n;let[i,r]=t;l[i]=(null!==(n=e[i])&&void 0!==n?n:[]).map((e,l)=>{var t;return null!==(t=r.get(l))&&void 0!==t?t:e})}),l}),!i){V(e=>{let l=e;return Object.entries(S).forEach(e=>{var t;let[n,i]=e,r=(null!==(t=R[n])&&void 0!==t?t:[]).map((e,l)=>{var t;return null!==(t=i.get(l))&&void 0!==t?t:e});l=l7(l,n,r)}),l});return}tt(c.productId,c.printArea,S)},to=e=>{var l,t,n,i,r,o,a,d,s,u,c,p,v,h,f,x,g,m,y,b,j,_,w,S,k,I,Z,P,R;return{id:e.id,assetFileId:null!==(g=null===(l=e.file)||void 0===l?void 0:l.id)&&void 0!==g?g:null,name:null!==(m=null===(t=e.file)||void 0===t?void 0:t.originalFilename)&&void 0!==m?m:"File",fileName:null!==(b=null!==(y=null===(n=e.file)||void 0===n?void 0:n.originalFilename)&&void 0!==y?y:null===(i=e.file)||void 0===i?void 0:i.fileName)&&void 0!==b?b:"",type:(null!==(j=null===(r=e.file)||void 0===r?void 0:r.fileExtension)&&void 0!==j?j:"").replace(".","").toUpperCase(),highResolution:(null!==(_=null===(a=e.file)||void 0===a?void 0:null===(o=a.metadata)||void 0===o?void 0:o.dpi)&&void 0!==_?_:0)>=300,thumbnail:null!==(S=null!==(w=null===(d=e.file)||void 0===d?void 0:d.s3Url)&&void 0!==w?w:null===(s=e.file)||void 0===s?void 0:s.thumbnailUrl)&&void 0!==S?S:null,s3Url:null!==(k=null===(u=e.file)||void 0===u?void 0:u.s3Url)&&void 0!==k?k:null,enabled:null===(I=C[e.id])||void 0===I||I,width:null!==(Z=null===(p=e.file)||void 0===p?void 0:null===(c=p.metadata)||void 0===c?void 0:c.width)&&void 0!==Z?Z:null,height:null!==(P=null===(h=e.file)||void 0===h?void 0:null===(v=h.metadata)||void 0===v?void 0:v.height)&&void 0!==P?P:null,dpi:null!==(R=null===(x=e.file)||void 0===x?void 0:null===(f=x.metadata)||void 0===f?void 0:f.dpi)&&void 0!==R?R:null}};return eO||i&&ls.current&&!lc||Q===d?(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:200,gap:1.5,color:"var(--lv-text-secondary)"},children:[(0,n.jsx)(q.D8,{size:28,sx:{color:"var(--lv-brand)"}}),(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)"},children:"Loading filesâ¦"})]}):(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(L.Z,{sx:{fontSize:14,fontWeight:600,color:"var(--lv-text-primary)"},children:"Files"}),(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)",mb:1.5},children:"Manage files in this listing"}),eX&&!F&&t.length>0&&(0,n.jsx)(y.Z,{sx:{mb:1.5},children:(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"flex-start",gap:.75,px:1.25,py:.75,borderRadius:2,bgcolor:"var(--lv-error-bg)",border:"1px solid var(--lv-error)"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,flexShrink:0},children:"\uD83D\uDEAB"}),(0,n.jsxs)(y.Z,{sx:{flex:1},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:"var(--lv-error)",lineHeight:1.4,fontWeight:600},children:["Cannot publish: ",e$.length," reserved design slot",1!==e$.length?"s":""," ",1!==e$.length?"have":"has"," no design uploaded yet."]}),(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-error)",lineHeight:1.4,mt:.25},children:"Upload a design into each reserved slot before publishing."})]}),(0,n.jsx)(y.Z,{onClick:()=>N(!0),sx:{cursor:"pointer",color:"var(--lv-text-disabled)",fontSize:14,lineHeight:1,flexShrink:0,"&:hover":{color:"var(--lv-text-secondary)"}},children:"â"})]})}),e0&&!(eX&&!F)&&(0,n.jsx)(y.Z,{sx:{mb:1.5},children:(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"flex-start",gap:.75,px:1.25,py:.75,borderRadius:2,bgcolor:"var(--lv-error-bg)",border:"1px solid var(--lv-error)"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:12,flexShrink:0},children:"\uD83D\uDEAB"}),(0,n.jsxs)(y.Z,{sx:{flex:1},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:"var(--lv-error)",lineHeight:1.4,fontWeight:600},children:["Cannot publish: ",eJ.length," product",1!==eJ.length?"s":""," ",1!==eJ.length?"have":"has"," no design attached"," â ",eJ.map(e=>{var l;return null===(l=e.product)||void 0===l?void 0:l.name}
1).filter(Boolean).join(", "),"."]}),(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-error)",lineHeight:1.4,mt:.25},children:n3})]})]})}),!1,ll.length>0&&(0,n.jsxs)(y.Z,{sx:{mb:1.5,borderRadius:2,border:"1px solid var(--lv-warning)",overflow:"hidden"},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5,px:1.25,py:.75,bgcolor:"var(--lv-warning-bg)",borderBottom:"1px solid var(--lv-warning)"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:11},children:"â ï¸"}),(0,n.jsx)(L.Z,{sx:{fontSize:11,fontWeight:600,color:"var(--lv-warning)"},children:"Uncovered colors â every color must have a design assigned"})]}),(0,n.jsx)(y.Z,{sx:{px:1.25,py:.75,display:"flex",flexDirection:"column",gap:1},children:ll.map(e=>(0,n.jsxs)(y.Z,{children:[(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)",mb:.4},children:[e.productName," â ",e.printAreaLabel,e.isRequired&&(0,n.jsx)(y.Z,{component:"span",sx:{ml:.75,fontSize:10,color:"var(--lv-error)",fontWeight:600},children:"(required)"})]}),(0,n.jsx)(y.Z,{sx:{display:"flex",flexWrap:"wrap",gap:.75,pl:.5},children:e.uncoveredColors.map(e=>{var l;return(0,n.jsx)(_.Z,{title:"Not covered by any design file",placement:"top",disableInteractive:!0,children:(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.4,cursor:"default"},children:[(0,n.jsx)(tA.Z,{hex:null!==(l=e.hex)&&void 0!==l?l:"var(--lv-text-tertiary)",size:10,shape:"circle",sx:{border:"1.5px solid var(--lv-warning)"}}),(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-warning)"},children:e.label})]})},e.id)})})]},e.key))})]}),lt.length>0&&(0,n.jsxs)(y.Z,{sx:{mb:1.5,borderRadius:2,border:"1px solid var(--lv-info)",overflow:"hidden"},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.5,px:1.25,py:.75,bgcolor:"var(--lv-info-bg)",borderBottom:"1px solid var(--lv-info)"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:11},children:"â¹ï¸"}),(0,n.jsx)(L.Z,{sx:{fontSize:11,fontWeight:600,color:"var(--lv-info-strong)"},children:"Assigned â waiting on the design"})]}),(0,n.jsx)(y.Z,{sx:{px:1.25,py:.75,display:"flex",flexDirection:"column",gap:1},children:lt.map(e=>(0,n.jsxs)(y.Z,{children:[(0,n.jsxs)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-secondary)",mb:.4},children:[e.productName," â ",e.printAreaLabel]}),(0,n.jsx)(y.Z,{sx:{display:"flex",flexWrap:"wrap",gap:.75,pl:.5},children:e.colors.map(e=>{var l;return(0,n.jsx)(_.Z,{title:e.reasons.includes(nX.NOT_POD_READY)?"Assigned design isn't POD-ready â replace it or fix the file":"Design hasn't finished its print-readiness check â this color stays assigned to it",placement:"top",disableInteractive:!0,children:(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:.4,cursor:"default"},children:[(0,n.jsx)(tA.Z,{hex:null!==(l=e.hex)&&void 0!==l?l:"var(--lv-text-tertiary)",size:10,shape:"circle",sx:{border:"1.5px solid var(--lv-info)"}}),(0,n.jsx)(L.Z,{sx:{fontSize:10,color:"var(--lv-info-strong)"},children:e.label})]})},e.id)})})]},e.key))})]}),(0,n.jsx)(y.Z,{sx:{mb:2},children:(0,n.jsx)(n5.Z,{onFilesSelected:e=>lq(e,eW),onBrowseLibrary:()=>I(!0),destinationSlot:(0,n.jsx)(n2.Z,{parentFolder:eT,onSelect:e=>eN(e),onClear:()=>eN(null),tooltipTitle:eT?'Design files uploaded to this listing are automatically added to the "'.concat(eT.name,'" collection.'):"Choose a collection to automatically file uploaded design files into. By default they go to your library root."})})}),!i&&(0,n.jsx)(y.Z,{sx:{mb:2},children:(0,n.jsx)(w.f,{text:"Add a placeholder",color:"white",width:"auto",className:"whitespace-nowrap",onClick:l1})}),(0,n.jsx)(n0.Z,{uploadingFiles:em.filter(e=>{var l;return null!==(l=e.linkAsDeliverable)&&void 0!==l?l:!e.collectionId}),onRemove:eb,onRetry:ej}),!i&&lV.length>0&&(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:"8px",mb:1},children:lV.map(e=>{let l=e.kind===iM.FAILED,t=e.kind===iM.CHECKING;return(0,n.jsxs)(y.Z,{"data-testid":"preset-upload-pending",sx:{display:"flex",alignItems:"center",gap:1.5,px:"14px",py:"10px",bgcolor:l?"var(--lv-error-bg)":"var(--lv-bg-card)",borderRadius:"22px",border:l?"0.5px solid var(--lv-error)":"0.5px solid var(--lv-border-default)",boxShadow:"0px 1px 4px -2px var(--lv-shadow-sm)"},children:[!l&&(0,n.jsx)(q.D8,{size:16,thickness:5,sx:{flexShrink:0}}),(0,n.jsxs)(y.Z,{sx:{flex:1,minWidth:0},children:[(0,n.jsx)(L.Z,{title:e.fileName,sx:{fontSize:13,fontWeight:500,color:"var(--lv-text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.fileName}),(0,n.jsx)(L.Z,{sx:{fontSize:11,mt:.25,color:l?"var(--lv-error-strong)":"var(--lv-text-tertiary)"},children:e.message})]}),(0,n.jsx)(w.f,{text:"Retry",color:"white",width:"auto",className:"whitespace-nowrap",disabled:t,onClick:()=>lH(e)}),(0,n.jsx)(w.f,{text:"Dismiss",color:"no-background",width:"auto",className:"whitespace-nowrap",onClick:()=>lB(e)})]},String(e.fileId))})}),(()=>{let e=new Set;
1Object.values(R).forEach(l=>{(null!=l?l:[]).forEach(l=>{l.productId&&e.add(l.productId)})});let l=t.filter(l=>!e.has(l.product.id));return e2.map(e=>{var r,o,a;let d=to(e);return(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:"5px"},children:[(0,n.jsxs)(L.Z,{sx:{fontSize:14,fontWeight:600,color:"var(--lv-text-primary)"},children:["Design ",String.fromCharCode(65+e2.indexOf(e))]}),(0,n.jsx)(iZ,{file:d,onEditDesign:b&&(null==d?void 0:d.assetFileId)!=null&&"PSD"!==String(null!==(a=d.type)&&void 0!==a?a:"").toUpperCase()&&!(0,eC.Bp)({name:d.fileName||d.name||""})?()=>{var e,l,t,n;return S({id:null!==(e=null==d?void 0:d.assetFileId)&&void 0!==e?e:null,s3Url:null!==(l=null==d?void 0:d.s3Url)&&void 0!==l?l:null,originalFilename:(null==d?void 0:d.fileName)||(null==d?void 0:d.name)||null,metadata:{width:null!==(t=null==d?void 0:d.width)&&void 0!==t?t:null,height:null!==(n=null==d?void 0:d.height)&&void 0!==n?n:null}})}:void 0,podProducts:t,links:null!==(r=R[e.id])&&void 0!==r?r:[],onLinksChange:(l,t)=>l6(e.id,l,t),onToggle:l=>l2(e.id,l),onRemove:async()=>{var l,n,r,o,a,d,s,u,c,p;if(!i){l5(e.id);return}let v=E[e.id],h=Promise.resolve();if(i&&v)try{await (0,eI.St)(i,v)}catch(e){if((null==e?void 0:null===(l=e.response)||void 0===l?void 0:l.status)!==404){console.error("[PodDesignPanel removeDesign]",null!==(s=null==e?void 0:null===(n=e.response)||void 0===n?void 0:n.data)&&void 0!==s?s:e),O.Am.error("Couldn't remove the design link on the server. ".concat(null!==(c=null!==(u=null==e?void 0:null===(o=e.response)||void 0===o?void 0:null===(r=o.data)||void 0===r?void 0:r.message)&&void 0!==u?u:null==e?void 0:null===(d=e.response)||void 0===d?void 0:null===(a=d.data)||void 0===a?void 0:a.error)&&void 0!==c?c:"Please refresh and try again."));return}}(null!==(p=R[e.id])&&void 0!==p?p:[]).forEach((l,n)=>{var i,r,o,a;if(!(null==l?void 0:l.productId)||!(null==l?void 0:l.printArea))return;let d=t.find(e=>e.product.id===l.productId),s=nG(null==d?void 0:null===(i=d.product)||void 0===i?void 0:i.variations),u=null!==(r=null==s?void 0:s.id)&&void 0!==r?r:"colors",c=(null!==(o=null==s?void 0:s.options)&&void 0!==o?o:[]).filter(e=>{var l,t;return null==d?void 0:null===(t=d.selection)||void 0===t?void 0:null===(l=t[u])||void 0===l?void 0:l[e.id]}).map(e=>e.id),p=l.colorMapping&&"all"!==l.colorMapping?null!==(a=l.colorMapping.option_ids)&&void 0!==a?a:[]:c;p.length&&ti(l.productId,l.printArea,p,e.id,n,{after:h})}),M(l=>{let t={...l};return delete t[e.id],t}),delete ei.current[e.id],eS(e.id)},conflictsByLink:e6,claimedByOtherLink:e8,hasOtherLinkAtSameAreaByLink:e9,allFileLinks:R,onTransferOption:tn,onReclaimOrphanedOptions:ti,onSetLinkMapping:tr,listingId:i,assignmentId:null!==(o=E[e.id])&&void 0!==o?o:null,onAssignmentCreated:l=>M(t=>({...t,[e.id]:l})),onReplaceFile:l=>lP(e.id,l,e),unlinkedProducts:l,orphanedAssetFileIds:lv,canHealClaims:()=>!lu.current&&eH&&0===l9.current&&!te.current,openCanvasForLinkId:(null==lr?void 0:lr.fileId)===e.id?lr.linkId:null,onCanvasOpenConsumed:()=>lo(null),onUserUnlinkedLastLink:()=>lm(e),onUserLinked:()=>ly(e)})]},e.id)})})(),!i&&(()=>{let e=U.filter(iI);if(0===e.length)return null;let l=new Set;Object.values(R).forEach(e=>
1{(null!=e?e:[]).forEach(e=>{e.productId&&l.add(e.productId)})});let i=t.filter(e=>!l.has(e.product.id));return e.map((e,l)=>{var r;let o=e._placeholderId,a=il(e2.length+l);return(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:"5px"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:14,fontWeight:600,color:"var(--lv-text-primary)"},children:a}),(0,n.jsx)(iP,{placeholder:e,podProducts:t,links:null!==(r=R[o])&&void 0!==r?r:[],onLinksChange:(e,l)=>l6(o,e,l),onRename:e=>l3(o,e),onToggle:e=>l4(o,e),onRemove:()=>l5(o),conflictsByLink:e6,claimedByOtherLink:e8,hasOtherLinkAtSameAreaByLink:e9,allFileLinks:R,onTransferOption:tn,onReclaimOrphanedOptions:ti,onSetLinkMapping:tr,unlinkedProducts:i})]},o)})})(),e3.length>0&&(0,n.jsxs)(y.Z,{sx:{mt:e2.length>0?2:0},children:[(0,n.jsx)(L.Z,{sx:{fontSize:11,color:"var(--lv-text-disabled)",mb:1},children:"Not POD-ready"}),e3.map(e=>(0,n.jsx)(iA,{item:e,onRemove:()=>{if(!i){l5(e.id);return}delete ei.current[e.id],eS(e.id)}},e.id))]}),(0,n.jsx)(n1.Z,{open:k,onClose:()=>I(!1),listingId:i,podOnly:!0,initialFilters:{podStatus:"valid"},alreadyLinkedFileIds:[...[...e2,...e3].map(e=>{var l,t;return null!==(t=e.fileId)&&void 0!==t?t:null===(l=e.file)||void 0===l?void 0:l.id}).filter(Boolean),...lv],onLinked:e=>{if(!i){let l=J.current;lR({...e,shouldAbort:()=>J.current!==l});return}ew({type:e.type,...e.payload},e.tempDeliverable)}}),j&&(0,n.jsx)(n7,{open:!0,assetFile:j,onClose:()=>S(null),onSaved:e=>{e&&O.Am.success("Saved to your library")}})]})}var iW=t(50054),iU=t(47618),iH=t(71924),iB=t(22048);function iV(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{var t,n,i,r,o;let a=(0,tE.EO)(e);if(a)return O.Am.error(a.message,{toastId:a.code}),a;if((null==e?void 0:null===(t=e.response)||void 0===t?void 0:t.status)===401)return null;iB.Tb(e,{tags:{feature:"pod-draft-routing",operation:l.operation},extra:{operation:l.operation,listingId:null!==(i=l.listingId)&&void 0!==i?i:null,podProductId:null!==(r=l.podProductId)&&void 0!==r?r:null,status:null!==(o=null==e?void 0:null===(n=e.response)||void 0===n?void 0:n.status)&&void 0!==o?o:null}})}catch(e){}return null}let iK=["price_cents","quantity","sku","is_enabled"],iq=[{value:"physical",label:"Physical"},{value:"digital",label:"Digital"},...tN.jf?[{value:"pod",label:(0,n.jsxs)(n.Fragment,{children:["POD",(0,n.jsx)("span",{className:"ml-1 text-[10px] font-medium rounded border px-1.5 py-0 leading-4 bg-gray-50 text-lv-text-tertiary border-gray-300",children:"BETA"})]}),ariaLabel:"POD"}]:[]],iG=0,iY=e=>Array.isArray(e)?e.map(e=>(null==e?void 0:e.matrixKey)?e:{...e,matrixKey:(0,eI.wr)(null==e?void 0:e.color,null==e?void 0:e.size)}):e,iQ=(e,l)=>{if(!Array.isArray(e)||null==l)return e;let t=!1,n=e.map(e=>{let n=(null==e?void 0:e.matrixKey)?l[e.matrixKey]:null,i=null==n?void 0:n.sku;return"string"!=typeof i||""===i.trim()||e.sku===i?e:(t=!0,{...e,sku:i})});return t?n:e},i$=e=>{if(!e||!Array.isArray(e.rawVariants))return e;let l=iQ(iY(e.rawVariants),e.variant_matrix);return l===e.rawVariants?e:{...e,rawVariants:l}};function iX(e){var l,t,i,o,d;let{listingId:s,isPreset:u=!1,title:c,imageUrl:p,typeOption:v,setTypeOption:h,restoreSnapshot:f,setRestoreSnapshot:x,setPreviousType:g,restoreSnapshotInfo:m,setRestoreSnapshotInfo:b,rawInventory:j,setShippingProfile:_,setReturnPolicy:S,productsVaryByVariants:k,setProductsVaryByVariants:I,variants:C,setVariants:Z,variantInventory:P,setVariantInventory:R,onInventoryChange:A,aiInventoryPriceWrites:E,onAiInventoryPriceWritesApplied:M,aiPodPriceWrites:z,onAiPodPriceWritesApplied:D,aiVariantPricePreview:F,onPayloadGetterReady:T,onResetReady:N,onReplaceReady:W,onRawInventoryLoaded:U,onPdfSettingsChange:H,initialPdfOverrides:B=null,globalPrice:V,globalQuantity:K,globalSku:G,initialPodProducts:Y,initialFileAssignments:Q,onPodSnapshotGetterReady:X,onPresetDesignsChanged:J,initialDigitalDesignFiles:ee,onDigitalDesignFilesChanged:el,onCatalogRefreshed:et,onPodProductsChange:en,onPodEditorHydrated:ei,pdfPreviewRefreshKey:er=0,variationsRefreshKey:eo=0,podDesignsRefreshKey:ea=0,presetInstanceKey:ed,presetApplyGeneration:es,onOverridesFlushReady:eu,onPresetSnapshotReady:ec,initialParentFolder:ep,initialDeliverables:ev,preserveDigitalMount:eh=!1,onDigitalUploadingChange:ef,onReg
1isterTypeSwitch:ex}=e,[eg,em]=(0,a.useState)(!1),[ey,eb]=(0,a.useState)(!1);(0,a.useEffect)(()=>{null==ef||ef(eg||ey)},[eg,ey]);let ej=(0,lh.v9)(e=>{var l,t,n;return null===(n=e.user)||void 0===n?void 0:null===(t=n.optimizedListing)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.printify}),e_=(0,lh.v9)(e=>{var l;return null===(l=e.user)||void 0===l?void 0:l.myInfo}),ew=(null==ej?void 0:ej.connected)||(null==e_?void 0:e_.printifyConnected)||!1,eS=null!==(i=null==e_?void 0:e_.etsyShopId)&&void 0!==i?i:null,ek=(0,iH.ZP)(eS,{enabled:tN.jf&&ew}),[eC,eP]=(0,a.useState)(!1),eR=(0,a.useRef)(null),[eA,eE]=(0,a.useState)([]),eM=(0,a.useRef)(eA);eM.current=eA;let[ez,eD]=(0,a.useState)(null),[eL,eO]=(0,a.useState)(!!(null==Y?void 0:Y.length)),eF=(0,a.useRef)({}),eT=(0,a.useRef)(null),eN=(0,a.useRef)(ed),eW=(0,a.useRef)(!1),[eU,eH]=(0,a.useState)([]),eB=(0,a.useRef)([]),eV=(0,a.useCallback)(e=>{let l=Array.isArray(e)?e:[];eB.current=l,eH(l)},[]),[eK,eq]=(0,a.useState)(null),[eG,eY]=(0,a.useState)(null),[eQ,e$]=(0,a.useState)(null);(0,a.useEffect)(()=>{if(!(null==Y?void 0:Y.length)){if(!eW.current){eO(!1);return}eE([]),eO(!1),eF.current={},eT.current=null,eW.current=!1;return}let e=eZ.ZV,l=Y.map(l=>i$(e(l)?(0,eZ.oe)(l):(0,eZ.c9)(l)));if(l.length>1){let e=Math.max(...l.map(e=>{var l;return(null!==(l=e.product.variations)&&void 0!==l?l:[]).length}));l=l.map(t=>(0,eZ.Y7)(t,e,l))}let t=l.map(e=>e.podProductId).sort().join("|");(eT.current!==t||eN.current!==ed)&&(eF.current={}),eT.current=t,eN.current=ed;let n=eF.current;Object.keys(n).length>0&&(l=l.map(e=>{var l;let t=n[e.podProductId];if(!t)return e;let i=(null!==(l=e.rawVariants)&&void 0!==l?l:[]).map(e=>{let l=e.matrixKey?t[e.matrixKey]:null;return l?{...e,...l}:e});return{...e,rawVariants:i}})),eW.current=!0,null==ei||ei(),eE(l),h("pod"),eO(!1)},[Y,ed]),(0,a.useEffect)(()=>{(0!==eA.length||eW.current)&&(null==en||en(eA))},[eA,en]);let[eX,eJ]=(0,a.useState)(!1),e0=(0,a.useRef)({}),e1=(0,a.useRef)({}),e5=(0,a.useRef)({}),e2=(0,a.useRef)({}),{linked:e3,statusResolved:e4,markLinked:e7,status:e6,refreshStatus:e8}=(0,tD.Z)(s,{enabled:!u}),[e9,le]=(0,a.useState)(null),[ll,lt]=(0,a.useState)(!1),[ln,li]=(0,a.useState)(null),[lr,la]=(0,a.useState)(null),[ld,ls]=(0,a.useState)(null),lu=(0,a.useCallback)(e=>null!=e&&null!=ld&&ld.podProductId===e&&ld.observedStatus===e6,[ld,e6]),[lc,lp]=(0,a.useState)(!1),[lv,lf]=(0,a.useState)(null),[lx,lg]=(0,a.useState)(!0),[lm,ly]=(0,a.useState)(!0),[lb,lj]=(0,a.useState)(new Set),l_=(0,a.useRef)(null);if(null===l_.current){let e=new Set;l_.current={suppress:l=>e.add(l),clear:l=>e.delete(l),isSuppressed:l=>e.has(l)}}let[lw,lS]=(0,a.useState)(!1),[lk,lI]=(0,a.useState)(void 0),lC=(0,a.useCallback)((e,l)=>{lS(!!e),lI(null==l?void 0:l.reason)},[]),[lZ,lP]=(0,a.useState)([]),lR=(0,a.useCallback)(e=>{lP(e)},[]),[lA,lE]=(0,a.useState)([]),lM=(0,a.useCallback)(e=>{lE(e)},[]),[lz,lD]=(0,a.useState)(0),lL=(0,a.useCallback)(()=>lD(e=>e+1),[]),lO=(0,a.useCallback)((e,l)=>{var t,n,i;if(!e||!l||0===Object.keys(l).length)return;let r=null!==(n=(t=eF.current)[e])&&void 0!==n?n:t[e]={};for(let[e,t]of Object.entries(l)){if(!t||"object"!=typeof t)continue;let l={};for(let e of iK)e in t&&(l[e]=t[e]);Object.keys(l).length>0&&(r[e]={...null!==(i=r[e])&&void 0!==i?i:{},...l})}eE(t=>t.map(t=>{var n;if(t.podProductId!==e)return t;let i=(null!==(n=t.rawVariants)&&void 0!==n?n:[]).map(e=>{let t=l[e.matrixKey];return t?{...e,...t}:e});return{...t,rawVariants:i}}))},[]),lF="download"===v?"digital":"pod"===v&&tN.jf?"pod":"physical",lT=(0,a.useRef)(!1);(0,a.useEffect)(()=>{lT.current=!1},[lF]);let lN=e=>{if((eB.current||[]).length>0){eq(e);return}lU(e)},lW=async e=>{if("pod"===e&&!ew){eJ(!0);return}if("pod"===e&&!ek.canCreatePod){eR.current=e,eP(!0);return}
1if("pod"===lF&&"pod"!==e&&eA.length>0){eD(e);return}if("pod"===lF&&"pod"!==e&&0===eA.length&&s&&(0,eI.Tz)(s,(0,eI.Wi)(e)).catch(e=>console.error("[ProductEditor] clear empty-pod type failed:",e)),"physical"===lF&&"digital"===e){let l=((null==j?void 0:j.products)||[]).filter(e=>Array.isArray(null==e?void 0:e.property_values)&&e.property_values.length>0),t=l.length>0?l.length:(null==C?void 0:C.length)>0?C.length:0;if(t>0||k){eY({tab:e,variantCount:t||0});return}}if("digital"===lF&&("physical"===e||"pod"===e)&&s&&!lT.current)try{var l;let t=await lo.default.get("".concat("https://backend.listingview.io","/api/listings/").concat(s,"/inventory-snapshot/availability")),n=(null==t?void 0:null===(l=t.data)||void 0===l?void 0:l.data)||{};if(n.available){e$({tab:e,savedAt:n.savedAt,productCount:n.productCount||0,axes:n.axes||[]});return}}catch(e){}let t="digital"===lF&&("physical"===e||"pod"===e),n=eB.current||[];if(t&&n.length>0){eq(e);return}lU(e)},lU=e=>{"download"===v&&"digital"!==e&&(null==_||_(""),null==S||S("")),"digital"===e&&(null==x||x(null),null==b||b(null)),"digital"===e?h("download"):"pod"===e?(h("pod"),s&&(0,eI.Tz)(s,"pod").catch(e=>console.error("[ProductEditor] persist pod type failed:",e))):h("physical")},lH=async()=>{if(s)try{await (0,eI.Tz)(s,(0,eI.Wi)(ez))}catch(e){eD(null);return}eE([]),null==g||g("pod"),lU(ez),eD(null)},lB=(0,a.useRef)(null);lB.current=lW;let lK=(0,a.useCallback)(e=>{var l;null===(l=lB.current)||void 0===l||l.call(lB,e)},[]),lq=(0,a.useMemo)(()=>({value:lF,options:iq,onSelect:lK,disabled:!1}),[lF,lK]);(0,a.useEffect)(()=>{if(ex)return ex(lq),()=>ex(null)},[ex,lq]);let lG=async e=>{var l,t,n,i,r,o,a,d,u,c,p,v,h,f,x,g,m,y,b,j,_;let{product:w,selection:S,rawVariants:k=[]}=e,I=null,C=null,Z=null;if(s)try{let{selectedColors:e,selectedSizes:l}=(0,eI.qL)(w,S),t=null==w?void 0:w.provider,n=t&&"printify_choice"!==t.id&&null!=t.external_id&&""!==t.external_id?t.external_id:null,i=await (0,eI.aO)(s,w.id,e,l,n),y=null!==(a=null!==(o=null===(r=i.data)||void 0===r?void 0:r.data)&&void 0!==o?o:i.data)&&void 0!==a?a:{};if(I=null!==(d=y.id)&&void 0!==d?d:null,Array.isArray(y.print_areas)&&y.print_areas.length>0&&(C=y.print_areas),y.variant_matrix&&"object"==typeof y.variant_matrix){let t=null===(u=w.variations)||void 0===u?void 0:u.find(e=>e.is_design_variable),n=e.length>0?e:[null],i=l.length>0?l:[null],r=[];for(let e of n)for(let l of i){let n=(0,eI.wr)(e,l);if(!n)continue;let i=y.variant_matrix[n];if(!i)continue;let o=e?null==t?void 0:null===(c=t.options)||void 0===c?void 0:c.find(l=>l.label===e):null;r.push({matrixKey:n,color:null!=e?e:"",color_hex:null!==(p=null==o?void 0:o.hex)&&void 0!==p?p:null,size:null!=l?l:"",base_cost_cents:null!==(v=i.cost_cents)&&void 0!==v?v:null,catalog_cost_cents:null!==(h=i.catalog_cost_cents)&&void 0!==h?h:null,price_cents:null!==(f=i.price_cents)&&void 0!==f?f:null,quantity:null!==(x=i.quantity)&&void 0!==x?x:null,is_enabled:null===(g=i.is_enabled)||void 0===g||g,sku:null!==(m=i.sku)&&void 0!==m?m:null})}r.length>0&&(Z=r)}}catch(e){return}s||I||(I="preset-pod-".concat(Date.now(),"-").concat(iG+=1));let P=C?{...w,print_areas:C}:w,R={product:P,selection:S,prefixes:{},rawVariants:iY(Z&&Z.length>0?Z:k),podProductId:I,naturalVariationCount:(null!==(y=P.variations)&&void 0!==y?y:[]).length};eE(e=>(0,eZ.yo)(e,R));let A=null!==(j=null===(l=eA[0])||void 0===l?void 0:l.naturalVariationCount)&&void 0!==j?j:(null!==(b=null===(n=eA[0])||void 0===n?void 0:null===(t=n.product)||void 0===t?void 0:t.variations)&&void 0!==b?b:[]).length;if(1===eA.length&&A>1&&s&&(null===(i=eA[0])||void 0===i?void 0:i.podProductId)){let e=null!==(_=Object.values((0,eZ.fk)(eA[0].product))[0])&&void 0!==_?_:"";(0,eI.T0)(s,eA[0].podProductId,{prefix:e,prefix_source:"derived"}).catch(e=>iV(e,{operation:"updatePodProductOverrides:retroactivePrefix",listingId:s,podProductId:eA[0].podProductId}))}},lY=async e=>{let l=eA[e];if(s&&(null==l?void 0:l.podProductId))try{await (0,eI.Sv)(s,l.podProductId)}catch(e){(0,tO.vx)(e).code===tO.LB.REMOVE_UNSUPPORTED&&O.Am.info("This routing product cannot be removed. Use Edit Options or Change Provider instead.");return}eE(l=>l.filter((l,t)=>
1t!==e))},lQ=(0,a.useCallback)(async()=>{await e8(),lf(null),O.Am.info("Retry the Printify routing product from the status banner before editing again.")},[e8]),l$=(0,a.useCallback)(async(e,l)=>{var t,n,i,r;let o=eM.current.find(l=>l.product.id===e),a=null==o?void 0:null===(n=o.product)||void 0===n?void 0:null===(t=n.variations)||void 0===t?void 0:t.find(e=>e.is_design_variable);if(!o||!a)return;let d=o.podProductId,u=()=>eM.current.find(l=>{var t;return l.product.id===e&&String(null!==(t=l.podProductId)&&void 0!==t?t:"")===String(null!=d?d:"")}),c=new Set(l),p=null!==(r=null===(i=o.selection)||void 0===i?void 0:i[a.id])&&void 0!==r?r:{},v=a.options.filter(e=>c.has(e.id)&&!p[e.id]).map(e=>e.label);if(0===v.length)return;let h=()=>{eE(l=>{var t,n,i;let r=l.findIndex(l=>{var t;return l.product.id===e&&String(null!==(t=l.podProductId)&&void 0!==t?t:"")===String(null!=d?d:"")});if(-1===r)return l;let o=l[r],a=null===(t=o.product.variations)||void 0===t?void 0:t.find(e=>e.is_design_variable);if(!a)return l;let s=null!==(i=null===(n=o.selection)||void 0===n?void 0:n[a.id])&&void 0!==i?i:{},u={...s},p=!1;if(a.options.forEach(e=>{c.has(e.id)&&!s[e.id]&&(u[e.id]=!0,p=!0)}),!p)return l;let v=[...l];return v[r]={...o,selection:{...o.selection,[a.id]:u}},v})};if(!s||!o.podProductId){h();return}let f=await e8();if(u()){if(void 0===f){O.Am.error("Could not check Printify routing status. Try again shortly.");return}if(f&&(0,tO.kF)(f,o.podProductId)){O.Am.info("Use Edit Options to add colors to an active Printify routing product.");return}if(f){let e=(0,tO.Sf)({payload:f,podProductId:o.podProductId,draftLinked:!0});if(e.disabled){O.Am.info(e.reason);return}}try{let e=await (0,eI.bt)(s,d,{add_colors:v,remove_colors:[],add_sizes:[],remove_sizes:[]});if(!u())return;let l=(0,tO.Uy)(e);if(l){(0,tO.Cq)(l,s);return}h()}catch(e){if(!u())return;if((0,tO.vx)(e).code===tO.LB.RETRY_REQUIRED){await lQ();return}iV(e,{operation:"updatePodProductOptions:designColorSync",listingId:s,podProductId:d})&&e7()}}},[s,e7,e8,lQ]),lX=function(e){var l;let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=(0,tO.Sf)({payload:e6,podProductId:null===(l=eA[e])||void 0===l?void 0:l.podProductId,draftLinked:e3,statusResolved:e4});if(n.disabled){O.Am.info(n.reason);return}le(e),li(t),lt(!0)},lJ=e=>{var l,t;let n=(0,tO.Sf)({payload:e6,podProductId:null===(l=eA[e])||void 0===l?void 0:l.podProductId,draftLinked:e3,statusResolved:e4});if(n.disabled){O.Am.info(n.reason);return}let i=null===(t=eA[e])||void 0===t?void 0:t.podProductId;if(lu(i)||(0,tO.kF)(e6,i)&&!(0,tO.JS)(e6)){O.Am.info(tO.Tw);return}la(e),lp(!0)},l0=async function(e){var l,t,n,i,r,o,a,d,u,c,p,v;let h=arguments.length>1&&void 0!==arguments[1]?arguments[1]:lr;if(null==h)return!1;let f=eA[h];if(!(null==f?void 0:f.podProductId)||!(null==e?void 0:e.external_id))return!1;if(!s){let n=ne(e,null!==(t=null===(l=f.product)||void 0===l?void 0:l.print_areas)&&void 0!==t?t:null);return eE(l=>l.map((l,t)=>{var i,r,o,a,d,s;return t!==h?l:{...l,printProviderId:e.external_id,printProviderName:null!==(o=null==e?void 0:e.name)&&void 0!==o?o:null,...l.refreshMeta&&"object"==typeof l.refreshMeta?{refreshMeta:{...l.refreshMeta,print_provider_id:Number.isFinite(Number(e.external_id))?Number(e.external_id):e.external_id}}:{},product:{...l.product,...n?{print_areas:n}:{},provider:e,...(null===(i=l.product)||void 0===i?void 0:i.print_provider)?{print_provider:{id:e.external_id,name:null!==(a=null==e?void 0:e.name)&&void 0!==a?a:null}}:{},avg_production_days:null!==(s=null!==(d=null==e?void 0:e.avg_production_days)&&void 0!==d?d:null===(r=l.product)||void 0===r?void 0:r.avg_production_days)&&void 0!==s?s:null}}})),n?O.Am.success("Print provider switched."):O.Am.warn("Print provider switched, but this provider published no print-area sizes â the canvas is unchanged."),!0}try{let l=await (0,eI.lT)(s,f.podProductId,e.external_id),t=null!==(r=null!==(i=null===(n=l.data)||void 0===n?void 0:n.data)&&void 0!==i?i:l.data)&&void 0!==r?r:{},a=(0,tO.Uy)(l);if(a)return(0,tO.Cq)(a,s),lf(null),!0;let d=t.pod_product;if(!d)return O.Am.error("Provider change failed â please try again."),!1;let u=(0,eZ.c9)(d);eE(l=>l.map((l,t)=>{var n,i,r,o,a,d,s,c,p,v,f,x,g,m,y,b,j,_,w,S,k,I,C,Z,P,R,A,E,M;if(t!==h)return l;let z=null!==(a=l.product)&&void 0!==a?a:{};return{...u,refreshMeta:null!==(s=null!==(d=u.refreshMeta)&&void 0!==d?d:l.refreshMeta)&&void 0!==s?s:null,product:{...u.product,name:null!==(p=null!==(c=u.product.name)&&void 0!==c?c:z.name)&&void 0!==p?p:null,brand:null!==(f=null!==(v=u.product.brand)&&void 0!==v?v:z.brand)&&void 0!==f?f:null,model:null!==(g=null!==(x=u.product.model)&&void 0!==x?x:z.model)&&void 0!==g?g:null,image_url:null!==(y=null!==(m=u.product.image_url)&&void 0!==m?m:z.image_url)&&void 0!==y?y:null,images:(null===(n=u.product.images)||void 0===n?void 0:n.length)?u.product.images:null!==(b=z.images)&&void 0!==b?b:[],mockup_images:(null===(i=u.product.mockup_images)||void 0===i?void 0:i.length)?u.product.mockup_images:null!==(j=z.mockup_images)&&void 0!==j?j:[],slug:null!==(w=null!==(_=u.product.slug)&&void 0!==_?_:z.slug)&&void 0!==w?w:null,catalogProductId:null!==(k=null!==(S=u.product.catalogProductId)&&void 0!==S?S:z.catalogProductId)&&void 0!==k?k:null,provider:(null==e?void 0:e.name)?{name:e.name}:null!==(C=null!==(I=u.product.provider)&&void 0!==I?I:z.provider)&&void 0!==C?C:null,supplier:(null===(r=u.product.supplier)||void 0===r?void 0:r.name)?u.product.supplier:null!==(P=null!==(Z=z.supplier)&&void 0!==Z?Z:u.product.supplier)&&void 0!==P?P:null,shipping_summary:(null===(o=u.product.shipping_summary)||void 0===o?void 0:o.length)?u.product.shipping_summary:null!==(R=z.shipping_summary)&&void 0!==R?R:[],avg_production_days:null!==(M=null!==(E=null!==(A=null==e?void 0:e.avg_production_days)&&void 0!==A?A:u.product.avg_production_days)&&void 0!==E?E:z.avg_production_days)&&void 0!==M?M:null}}}));let c=Array.isArray(t.dropped_label_keys)?t.dropped_label_keys:[],p=null!==(o=t.preserved_variant_count)&&void 0!==o?o:0;return c.length>0?O.Am.warn("Note: this provider does not carry ".concat(c.length," of the color/size combinations you had â those rows have been removed from your matrix.").concat(p>0?" (".concat(p," kept with your existing prices.)"):""),{autoClose:8e3}):O.Am.success("Print provider switched."),lf(null),!0}catch(r){let l=(0,tO.vx)(r),t=null!==(p=null!==(c=null==r?void 0:null===(d=r.response)||void 0===d?void 0:null===(a=d.data)||void 0===a?void 0:a.data)&&void 0!==c?c:null==r?void 0:null===(u=r.response)||void 0===u?void 0:u.data)&&void 0!==p?p:{},{code:n,message:i}=l;if(n===tO.LB.ORDERS_IN_FLIGHT||n===tO.LB.MULTI_SHOP)return lf(t=>({...null!=t?t:{kind:"provider",proposedKeys:[],droppedCombinations:l5(f,e),splitUnsupported:!1,provider:e,index:h,podProductId:f.podProductId},assessment:l.assessment,loading:!1,error:i})),!1;if(n===tO.LB.PROVIDER_DISABLED)return O.Am.info(i||tO.Tw),null!=f.podProductId&&ls({podProductId:f.podProductId,observedStatus:e6}),await e8(),lf(null),!0;if(n===tO.LB.SPLIT_UNSUPPORTED)return lf(t=>({...null!=t?t:{kind:"provider",assessment:l.assessment,proposedKeys:[],droppedCombinations:l5(f,e),provider:e,index:h,podProductId:f.podProductId},splitUnsupported:!0,loading:!1,error:tO.cF})),!1;if(n===tO.LB.IN_PROGRESS){let e=await e8();return(0,tO.Cq)({status:null!==(v=null==e?void 0:e.edit_in_flight)&&void 0!==v?v:"replacing",operationId:null,podProductId:f.podProductId},s),lf(null),!0}if(n===tO.LB.RETRY_REQUIRED)return await lQ(),!1;if("POD_PROVIDER_PRINT_AREA_UNRESOLVED"===n){let e=[...new Set((Array.isArray(t.details)?t.details:[]).map(e=>(null==e?void 0:e.name)||(null==e?void 0:e.print_area_id)).filter(
1Boolean))];O.Am.error(e.length?"Provider change blocked â reassign or remove designs from: ".concat(e.join(", "),"."):"Provider change blocked â one or more assigned print areas are unavailable from that provider.")}else"POD_PROVIDER_NOT_FOUND"===n?O.Am.error("That provider is no longer available for this product â please refresh the catalog or pick a different one."):"POD_PROVIDER_INACTIVE"===n||"POD_PROVIDER_VARIANTS_EMPTY"===n?O.Am.warn("This provider is temporarily unavailable â try again after the next catalog sync."):O.Am.error(i||"Provider change failed â please try again.");return!1}},l1=e=>{var l,t;if(Array.isArray(null==e?void 0:e.variants)&&e.variants.length>0)return new Set(e.variants.map(e=>{var l,t;return"".concat(null!==(l=null==e?void 0:e.color)&&void 0!==l?l:"","|||").concat(null!==(t=null==e?void 0:e.size)&&void 0!==t?t:"")}));let n=null!==(l=null==e?void 0:e.colors)&&void 0!==l?l:[],i=null!==(t=null==e?void 0:e.sizes)&&void 0!==t?t:[],r=n.length?n.map(e=>{var l;return null!==(l=null==e?void 0:e.name)&&void 0!==l?l:e}).filter(Boolean):[""],o=i.length?i:[""];return new Set(r.flatMap(e=>o.map(l=>"".concat(e,"|||").concat(l))))},l5=(e,l)=>{var t;let n=l1(l);return Array.from(new Set((null!==(t=null==e?void 0:e.rawVariants)&&void 0!==t?t:[]).filter(e=>{var l,t;return!n.has("".concat(null!==(l=null==e?void 0:e.color)&&void 0!==l?l:"","|||").concat(null!==(t=null==e?void 0:e.size)&&void 0!==t?t:""))}).map(e=>[null==e?void 0:e.color,null==e?void 0:e.size].filter(Boolean).join(" / ")).filter(Boolean)))},l2=async e=>{let l=eA[lr];if(null==lr||!(null==l?void 0:l.podProductId))return!1;if(lu(l.podProductId))return O.Am.info(tO.Tw),!0;if(!e3||e6&&!(0,tO.kF)(e6,l.podProductId))return l0(e,lr);let t=await e8();return void 0===t?(O.Am.error("Could not check linked orders. Try again shortly."),!1):(0,tO.kF)(t,l.podProductId)?((0,tO.JS)(t)?lf({kind:"provider",assessment:(0,tO.nn)(t),proposedKeys:[],droppedCombinations:l5(l,e),splitUnsupported:(0,tO.y_)(t,l.podProductId),loading:!1,error:null,provider:e,index:lr,podProductId:l.podProductId}):O.Am.info(tO.Tw),!0):l0(e,lr)},l3=async()=>{if(lv){if("provider"===lv.kind){lf(e=>({...e,loading:!0,error:null})),await l0(lv.provider,lv.index);return}await l7(lv)}},l4=(e,l,t,n)=>{eE(i=>i.map((i,r)=>r===e?{...i,product:l,selection:t,rawVariants:iY(n)}:i))},l7=async e=>{let{index:l,podProductId:t,product:n,selection:i,mergedRawVariants:r,diff:o}=e;e.requiresConfirmation&&lf(l=>({...null!=l?l:e,loading:!0,error:null}));try{let e=await (0,eI.bt)(s,t,o),a=(0,tO.Uy)(e);return a?(0,tO.Cq)(a,s):l4(l,n,i,r),lf(null),!0}catch(n){var a,d,u;let l=(0,tO.vx)(n);if(l.code===tO.LB.ORDERS_IN_FLIGHT||l.code===tO.LB.MULTI_SHOP)return lf(t=>({...null!=t?t:e,assessment:l.assessment,loading:!1,error:l.message})),!1;if(l.code===tO.LB.SPLIT_UNSUPPORTED)return lf(l=>({...null!=l?l:e,splitUnsupported:!0,loading:!1,error:tO.cF})),!1;if(l.code===tO.LB.IN_PROGRESS){let e=await e8();return(0,tO.Cq)({status:null!==(a=null==e?void 0:e.edit_in_flight)&&void 0!==a?a:"updating",operationId:null,podProductId:t},s),lf(null),!0}if(l.code===tO.LB.RETRY_REQUIRED)return await lQ(),!1;if(l.code===tO.LB.UNCOVERED_VARIANTS)return null===(u=document.getElementById("pod-design-coverage"))||void 0===u||null===(d=u.scrollIntoView)||void 0===d||d.call(u,{behavior:"smooth",block:"start"}),lf(l=>({...null!=l?l:e,loading:!1,error:"Add design coverage for the new combinations, then retry."})),!1;return e.requiresConfirmation?lf(t=>({...null!=t?t:e,loading:!1,error:l.message||"Could not update product options. Try again."})):O.Am.error(l.message||"Could not update product options. Try again."),!1}},l6=async function(e,l){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=eA[e9],i=n?(0,eI.qv)(e,n.selection,l):null,r=i&&(i.add_colors.length||i.remove_colors.length||i.add_sizes.length||i.remove_sizes.length),o=Array.isArray(null==n?void 0:n.rawVariants)?n.rawVariants:[],a=new Set(o.map(e=>{var l,t;return"".concat(null!==(l=null==e?void 0:e.color)&&void 0!==l?l:"","|||").concat(null!==(t=null==e?void 0:e.size)&&void 0!==t?t:"")})),d=[...o,...(Array.isArray(t)?t:[]).filter(e=>{var l,t;return!a.has("".concat(null!==(l=null==e?void 0:e.color)&&void 0!==l?l:"","|||").concat(null!==(t=null==e?void 0:e.size)&&void 0!==t?t:""))})];if(!r)return!0;
1if(!s||!(null==n?void 0:n.podProductId))return l4(e9,e,l,d),!0;let u={kind:"options",assessment:null,proposedKeys:(0,tO.T5)(n.rawVariants,i),droppedCombinations:[],splitUnsupported:!1,loading:!1,error:null,index:e9,podProductId:n.podProductId,product:e,selection:l,mergedRawVariants:d,diff:i};if(!e3||e6&&!(0,tO.kF)(e6,n.podProductId))return l7(u);let c=await e8();if(void 0===c)return O.Am.error("Could not check linked orders. Try again shortly."),!1;let p={...u,assessment:(0,tO.nn)(c),splitUnsupported:(0,tO.y_)(c,n.podProductId)};return(0,tO.kF)(c,n.podProductId)?(lf({...p,requiresConfirmation:!0}),!0):l7(p)},l8=(0,a.useCallback)(async e=>{let l=e2.current[e];if(l&&s){delete e2.current[e],clearTimeout(e1.current[e]),delete e1.current[e],e5.current[e]=l.serialized;try{await (0,eI.T0)(s,e,{labels:l.labels,option_overrides:l.optionOverrides})}catch(l){delete e5.current[e]}}},[s]),l9=(e,l)=>{var t,n;if(!s||!e)return;let i=null!==(t=l.labels)&&void 0!==t?t:{},r=null!==(n=l.option_overrides)&&void 0!==n?n:{},o=Object.values(i).some(e=>""===e),a=Object.values(r).some(e=>(null==e?void 0:e.display_value)==="");if(o||a)return;let d=JSON.stringify({labels:i,option_overrides:r});e5.current[e]!==d&&(e2.current[e]={labels:i,optionOverrides:r,serialized:d},clearTimeout(e1.current[e]),e1.current[e]=setTimeout(()=>{l8(e)},600))},te=(0,a.useCallback)(async()=>{let e=Object.keys(e2.current);0!==e.length&&await Promise.all(e.map(e=>l8(e)))},[l8]);(0,a.useEffect)(()=>{null==eu||eu(te)},[eu,te]);let tl=(e,l,t,n)=>{eE(i=>i.map((i,r)=>{var o,a,d,s,u,c,p,v,h,f,x,g;if(r!==e)return i;let m=(null!==(v=i.product.variations)&&void 0!==v?v:[]).find(e=>e.id===l),y=(null==m?void 0:m._synthetic)===!0,b=null==m?void 0:null===(a=m.options)||void 0===a?void 0:null===(o=a.find(e=>e.id===t))||void 0===o?void 0:o.label,j=(null===(s=i.product.variations)||void 0===s?void 0:null===(d=s[0])||void 0===d?void 0:d.id)===l,_=(null===(c=i.product.variations)||void 0===c?void 0:null===(u=c[1])||void 0===u?void 0:u.id)===l,w=(null!==(h=i.product.variations)&&void 0!==h?h:[]).map(e=>e.id!==l?e:{...e,options:e.options.map(e=>{var l;return e.id!==t?e:{...e,...y?{}:{_original_label:null!==(l=e._original_label)&&void 0!==l?l:e.label},label:n}})}),S=(null!==(f=i.rawVariants)&&void 0!==f?f:[]).map(e=>j&&e.color===b?{...e,color:n}:_&&e.size===b?{...e,size:n}:e),k={...null!==(x=i.frontendOverride)&&void 0!==x?x:{prefix:null,labels:{},option_overrides:{}},option_overrides:{...null!==(g=null===(p=i.frontendOverride)||void 0===p?void 0:p.option_overrides)&&void 0!==g?g:{},[t]:{display_value:n}}};return l9(i.podProductId,k),{...i,product:{...i.product,variations:w},rawVariants:S,frontendOverride:k}}))},tt=(e,l,t)=>{eE(n=>n.map((n,i)=>{var r,o,a,d,s,u,c,p,v,h,f;if(i!==e)return n;let x=(null!==(c=n.product.variations)&&void 0!==c?c:[]).find(e=>e.id===l),g=null==x?void 0:null===(r=x.options)||void 0===r?void 0:r.find(e=>e.id===t);if(!g||void 0===g._original_label)return n;let m=g.label,y=g._original_label,b=(null===(a=n.product.variations)||void 0===a?void 0:null===(o=a[0])||void 0===o?void 0:o.id)===l,j=(null===(s=n.product.variations)||void 0===s?void 0:null===(d=s[1])||void 0===d?void 0:d.id)===l,_=(null!==(p=n.product.variations)&&void 0!==p?p:[]).map(e=>e.id!==l?e:{...e,options:e.options.map(e=>{if(e.id!==t)return e;let{_original_label:l,...n}=e;return{...n,label:l}})}),w=(null!==(v=n.rawVariants)&&void 0!==v?v:[]).map(e=>b&&e.color===m?{...e,color:y}:j&&e.size===m?{...e,size:y}:e),{[t]:S,...k}=null!==(h=null===(u=n.frontendOverride)||void 0===u?void 0:u.option_overrides)&&void 0!==h?h:{},I={...null!==(f=n.frontendOverride)&&void 0!==f?f:{prefix:null,labels:{},option_overrides:{}},option_overrides:k};return l9(n.podProductId,I),{...n,product:{...n.product,variations:_},rawVariants:w,frontendOverride:I}}))},tn=(e,l,t)=>{eE(n=>{var i,r,o;let a=null===(o=n[e])||void 0===o?void 0:null===(r=o.product)||void 0===r?void 0:null===(i=r.variations)||void 0===i?void 0:i.findIndex(e=>e.id===l);return null==a||a<0?n:n.map(e=>{var l,n,i,r,o;let d=null===(l=e.product.variations)||void 0===l?void 0:l[a];if(!d)return e;let s=(null!==(i=e.product.variations)&&void 0!==i?i:[]).map((e,l)=>{var n;return l!==a?e:{...e,_original_label:null!==(n=e._original_label)&&void 0!==n?n:e.label,label:t}}),u={...null!==(r=e.frontendOverride)&&void 0!==r?r:{prefix:null,labels:{},option_overrides:{}},labels:{...null!==(o=null===(n=e.frontendOverride)||void 0===n?void 0:n.labels)&&void 0!==o?o:{},[d.id]:t}};return l9(e.podProductId,u),{...e,product:{...e.product,variations:s},frontendOverride:u}})})},ti=(e,l)=>{eE(t=>{var n,i,r;let o=null===(r=t[e])||void 0===r?void 0:null===(i=r.product)||void 0===i?void 0:null===(n=i.variations)||void 0===n?void 0:n.findIndex(e=>e.id===l);return null==o||o<0?t:t.map(e=>{var l,t,n,i,r;let a=null===(l=e.product.variations)||void 0===l?void 0:l[o];if(!a||void 0===a._original_label)return e;let d=(null!==(n=e.product.variations)&&void 0!==n?n:[]).map((e,l)=>{if(l!==o||void 0===e._original_label)return e;let{_original_label:t,...n}=e;return{...n,label:t}}),{[a.id]:s,...u}=null!==(i=null===(t=e.frontendOverride)||void 0===t?void 0:t.labels)&&void 0!==i?i:{},c={...null!==(r=e.frontendOverride)&&void 0!==r?r:{prefix:null,labels:{},option_overrides:{}},labels:u};return l9(e.podProductId,c),{...e,product:{...e.product,variations:d},frontendOverride:c}})})},tr=(e,l,t)=>{var n,i,r;let o=eA[e],a=null==o?void 0:null===(i=o.product)||void 0===i?void 0:null===(n=i.variations)||void 0===n?void 0:n.find(e=>e.id===l),d=Math.max(0,...(null!==(r=null==a?void 0:a.options)&&void 0!==r?r:[]).map(e=>e.label.length)),u=t.slice(0,Math.max(0,20-d-3));if(eE(t=>t.map((t,n)=>{var i;return n===e?{...t,prefixes:{...null!==(i=t.prefixes)&&void 0!==i?i:{},[l]:u}}:t})),s&&(null==o?void 0:o.podProductId)){let l="".concat(e);clearTimeout(e0.current[l]),e0.current[l]=setTimeout(()=>{(0,eI.T0)(s,o.podProductId,{prefix:u,prefix_source:"seller"}).catch(e=>iV(e,{operation:"updatePodProductOverrides:prefix",listingId:s,podProductId:o.podProductId}))},600)}},ta=eA.flatMap(e=>{var l;let{product:t,selection:n,prefixes:i}=e;return(null!==(l=t.variations)&&void 0!==l?l:[]).flatMap(e=>{var l;let t=null!==(l=null==i?void 0:i[e.id])&&void 0!==l?l:"";return e.options.filter(l=>{var t;return null==n?void 0:null===(t=n[e.id])||void 0===t?void 0:t[l.id]}).map(e=>t?"".concat(t).concat(" - ").concat(e.label):e.label)})});return(0,n.jsxs)(r.Z,{id:"product",title:"Product",children:["physical"===lF&&null!==f&&m&&(0,n.jsxs)(y.Z,{sx:{mb:2,p:1.5,border:"1px solid var(--lv-border)",borderLeft:"3px solid ".concat(f?"var(--lv-brand, #7b5cff)":"var(--lv-text-tertiary, #888)"),borderRadius:1,backgroundColor:"var(--lv-surface-2, rgba(0,0,0,0.04))"},children:[(0,n.jsx)(L.Z,{sx:{fontSize:13,fontWeight:600,color:"var(--lv-text-primary)",mb:.5},children:f?"Variations will be restored on save":"Starting fresh â saved variations will be discarded on save"}),(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-secondary)",mb:(null===(l=m.axes)||void 0===l?void 0:l.length)>
10?.75:0},children:f?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("strong",{children:m.productCount})," variant",1===m.productCount?"":"s"," saved on"," ",new Date(m.savedAt).toISOString().slice(0,10),". Click ",(0,n.jsx)("strong",{children:"Save"})," to apply without activating, or"," ",(0,n.jsx)("strong",{children:"Publish"})," to apply and activate."]}):(0,n.jsxs)(n.Fragment,{children:["Discarding ",(0,n.jsx)("strong",{children:m.productCount})," ","saved variant",1===m.productCount?"":"s"," from"," ",new Date(m.savedAt).toISOString().slice(0,10),". Listing will go back to a single product."]})}),f&&(null===(t=m.axes)||void 0===t?void 0:t.length)>0&&(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:.25},children:m.axes.map(e=>{var l;return(0,n.jsxs)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-tertiary)"},children:[(0,n.jsx)("strong",{children:e.propertyName}),": ",e.valueCount," value",1===e.valueCount?"":"s",(null===(l=e.sampleValues)||void 0===l?void 0:l.length)>0?" (".concat(e.sampleValues.slice(0,3).join(", ")).concat(e.valueCount>3?"â¦":"",")"):""]},e.propertyName)})})]}),"physical"===lF&&(0,n.jsx)(lV,{id:"physical-variations",expanded:lx,onExpandedChange:lg,sx:{mb:"20px"},children:(0,n.jsx)(to,{listingId:s,productsVaryByVariants:k,setProductsVaryByVariants:I,variants:C,setVariants:Z,variantInventory:P,setVariantInventory:R,onInventoryChange:A,aiInventoryPriceWrites:E,onAiInventoryPriceWritesApplied:M,aiVariantPricePreview:F,onRawInventoryLoaded:U,globalPrice:V,globalQuantity:K,globalSku:G},"".concat(s,"-").concat(eo))}
1),tN.jf&&"pod"===lF&&(0,n.jsxs)(y.Z,{children:[eL&&(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:280,gap:1.5},children:[(0,n.jsx)(q.D8,{size:32,sx:{color:"var(--lv-brand)"}}),(0,n.jsx)(L.Z,{sx:{fontSize:13,color:"var(--lv-text-secondary)"},children:"Loading POD productsâ¦"})]}),!eL&&(0,n.jsxs)(y.Z,{sx:{containerType:"inline-size"},children:[(0,n.jsxs)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:3,mb:3},children:[(0,n.jsxs)(y.Z,{children:[(0,n.jsx)(y.Z,{sx:{mb:2},children:(0,n.jsx)(no,{onAddProduct:lG,hasProducts:eA.length>0,disabled:!1,disabledReason:null,existingPodProducts:eA})}),eA.length>0&&(0,n.jsx)(y.Z,{sx:{display:"flex",flexDirection:"column",gap:1.5,mb:2},children:eA.map((e,l)=>{var t,i,r;let{product:o,selection:a,prefixes:d,naturalVariationCount:s,podProductId:u}=e,c=(null!==(t=o.variations)&&void 0!==t?t:[]).flatMap(e=>{var l;let t=null!==(l=null==d?void 0:d[e.id])&&void 0!==l?l:"";return e.options.filter(l=>{var t;return null==a?void 0:null===(t=a[e.id])||void 0===t?void 0:t[l.id]}).map(e=>t?"".concat(t).concat(" - ").concat(e.label):e.label)}),p=ta.filter(e=>!c.includes(e)),v="Product ".concat(String.fromCharCode(65+l)),h=(0,tO.Sf)({payload:e6,podProductId:u,draftLinked:e3,statusResolved:e4});return(0,n.jsx)(nx,{product:o,selection:a,prefixes:d,label:v,showPrefix:eA.length>1&&(null!=s?s:(null!==(i=o.variations)&&void 0!==i?i:[]).length)>1,hasDesign:lb.has(o.id),onPrefixChange:(e,t)=>
1tr(l,e,t),onOptionLabelChange:(e,t,n)=>tl(l,e,t,n),onResetOptionLabel:(e,t)=>tt(l,e,t),onVariationLabelChange:(e,t)=>tn(l,e,t),onResetVariationLabel:e=>ti(l,e),onEditOptions:e=>lX(l,e),onChangeProvider:()=>lJ(l),draftLinked:e3,linkedEditUnsupported:h.disabled,linkedEditUnsupportedCopy:null!==(r=h.reason)&&void 0!==r?r:void 0,providerChangeUnavailable:lu(u)||(0,tO.kF)(e6,u)&&!(0,tO.JS)(e6),providerChangeUnavailableCopy:tO.Tw,onRemove:()=>lY(l),otherResolvedNames:p},"".concat(o.id,"-").concat(l))})}),null!==e9&&(0,n.jsx)(no,{open:ll,onClose:()=>{lt(!1),le(null),li(null)},editTarget:null!==(o=eA[e9])&&void 0!==o?o:null,initialVariationId:ln,onEditConfirm:l6,onAddProduct:lG,existingPodProducts:eA.filter((e,l)=>l!==e9)}),null!==lr&&(0,n.jsx)(no,{open:lc,onClose:()=>{lp(!1),la(null)},editTarget:null!==(d=eA[lr])&&void 0!==d?d:null,mode:"change-provider",onChangeProvider:l2,existingPodProducts:eA})]}),(0,n.jsx)(y.Z,{id:"pod-design-coverage",children:(0,n.jsx)(iN,{podProducts:eA,listingId:s,onPayloadGetterReady:T,onUploadsInFlightChange:eb,presetApplyGeneration:es,onResetReady:N,onDesignColorsChanged:l$,onLinkedProductsChanged:lj,initialFileAssignments:Q,onPodSnapshotGetterReady:X,onPresetDesignsChanged:J,onPublishBlockedChange:lC,autoLinkSuppression:l_.current,initialParentFolder:ep,onPresetSnapshotReady:ec},"".concat(null!=s?s:"preset","-").concat(null!=ed?ed:0,"-").concat(ea))})]}),eA.length>0&&(0,n.jsx)(lV,{id:"pod-variations",expanded:lm,onExpandedChange:ly,sx:{mt:2},children:(0,n.jsx)(t3,{podProducts:eA,listingId:s,isPreset:u,listingTitle:c,onVariantMatrixChange:lO,onCatalogRefreshed:et,aiPodPriceWrites:z,onAiPodPriceWritesApplied:D,aiVariantPricePreview:F,publishBlocked:lw,...lk?{publishBlockedReason:lk}:{}},"".concat(null!=s?s:"preset","-").concat(null!=ed?ed:0))})]})," "]}),(0,n.jsx)(tT,{open:null!=lv,kind:null==lv?void 0:lv.kind,assessment:null==lv?void 0:lv.assessment,proposedKeys:null==lv?void 0:lv.proposedKeys,droppedCombinations:null==lv?void 0:lv.droppedCombinations,splitUnsupported:null==lv?void 0:lv.splitUnsupported,loading:null==lv?void 0:lv.loading,error:null==lv?void 0:lv.error,onClose:()=>{(null==lv?void 0:lv.loading)||lf(null)},onConfirm:l3}),(0,n.jsx)($.Z,{open:!!ez,onClose:()=>eD(null),title:"Switch product type?",PaperProps:{sx:{maxWidth:420}},actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w.f,{text:"Cancel",color:"white",width:"auto",className:"whitespace-nowrap",onClick:()=>eD(null)}),(0,n.jsx)(w.f,{text:"Switch type",color:"purple",width:"auto",className:"whitespace-nowrap",onClick:lH})]}),children:(0,n.jsx)(L.Z,{sx:{fontSize:13,color:"var(--lv-text-secondary)",lineHeight:1.6},children:"Switching product type will remove all linked POD products, variant configurations, and design file mappings. This cannot be undone."})}),(0,n.jsxs)($.Z,{open:!!eK,onClose:()=>eq(null),title:"Remove Etsy-hosted files?",PaperProps:{sx:{maxWidth:480}},actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w.f,{text:"Cancel",color:"white",width:"auto",className:"whitespace-nowrap",onClick:()=>eq(null)}),(0,n.jsx)(w.f,{text:"Remove and switch",color:"purple",width:"auto",className:"whitespace-nowrap",onClick:()=>{eq(null),eK&&lU(eK)}})]}),children:[(0,n.jsxs)(L.Z,{sx:{fontSize:13,color:"var(--lv-text-secondary)",lineHeight:1.6,mb:1.5},children:["The following file",1===eU.length?"":"s"," ",1===eU.length?"is":"are"," hosted only on Etsy (not in ListingView). The next time you save or publish this listing as"," ","pod"===eK?"POD":"Physical",","," ",1===eU.length?"it":"they"," will be permanently removed from Etsy. Files hosted in ListingView are preserved and will reappear automatically if you switch the listing back to Digital and save again."]}),(0,n.jsx)(y.Z,{sx:{mt:1,border:"1px solid var(--lv-border-strong)",borderRadius:1,maxHeight:180,overflowY:"auto",p:1,display:"flex",flexDirection:"column",gap:.5},children:eU.map(e=>(0,n.jsx)(L.Z,{sx:{fontSize:12,color:"var(--lv-text-primary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:e.filename||e.name||"File ".concat(e.etsyFileId||e.id)},e.id||e.etsyFileId||e.filename))})]}),(0,n.jsx)($.Z,{open:!!eG,onClose:()=>eY(null),title:"Switching to digital will hide your variations",PaperProps:{sx:{maxWidth:480}},actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w.f,{text:"Cancel",color:"white",width:"auto",className:"whitespace-nowrap",onClick:()=>eY(null)}),(0,n.jsx)(w.f,{text:"Convert",color:"purple",width:"auto",className:"whitespace-nowrap",onClick:()=>{let e=null==eG?void 0:eG.tab;eY(null),e&&lU(e)}})]}),children:(0,n.jsxs)(L.Z,{sx:{fontSize:13,color:"var(--lv-text-secondary)",lineHeight:1.6},children:["Etsy doesn't allow variations on digital listings, so we'll temporarily reset this listing to a single product before converting."," ",(null==eG?void 0:eG.variantCount)>0?(0,n.jsxs)(n.Fragment,{children:["Your ",(0,n.jsx)("strong",{children:eG.variantCount})," ","variation",1===eG.variantCount?"":"s"," will be saved"]}):(0,n.jsx)(n.Fragment,{children:"Your variations will be saved"})," ","and automatically restored if you switch back to physical within 90 days."]})}),(0,n.jsx)($.Z,{open:!!eQ,onClose:()=>e$(null),title:"Restore your previous variations?",PaperProps:{sx:{maxWidth:480}},actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(w.f,{text:"Start fresh",color:"white",width:"auto",className:"whitespace-nowrap",onClick:()=>{let e=null==eQ?void 0:eQ.tab;e$(null),lT.current=!0,null==x||x(!1),null==b||b(eQ?{savedAt:eQ.savedAt,productC
1ount:eQ.productCount,axes:eQ.axes||[]}:null),e&&lN(e)}}),(0,n.jsx)(w.f,{text:"Restore variations",color:"purple",width:"auto",className:"whitespace-nowrap",onClick:()=>{let e=null==eQ?void 0:eQ.tab;e$(null),lT.current=!0,null==x||x(!0),null==b||b(eQ?{savedAt:eQ.savedAt,productCount:eQ.productCount,axes:eQ.axes||[]}:null),e&&lN(e)}})]}),children:(0,n.jsxs)(L.Z,{sx:{fontSize:13,color:"var(--lv-text-secondary)",lineHeight:1.6},children:["We saved your last variation setup",(null==eQ?void 0:eQ.savedAt)?(0,n.jsxs)(n.Fragment,{children:[" ","on"," ",(0,n.jsx)("strong",{children:new Date(eQ.savedAt).toISOString().slice(0,10)})]}):null,(null==eQ?void 0:eQ.productCount)?(0,n.jsxs)(n.Fragment,{children:[" ","with ",(0,n.jsx)("strong",{children:eQ.productCount})," ","variant",1===eQ.productCount?"":"s"]}):null,". When you switch back to"," ",(null==eQ?void 0:eQ.tab)==="pod"?"POD":"physical"," you can either restore them or start fresh with a single product."]})}),(0,n.jsx)(iW.Z,{open:eX,onClose:()=>eJ(!1)}),(0,n.jsx)(iU.Z,{open:eC,etsyShopId:eS,requireSelection:!0,preferredPrintifyShopId:ek.legacyPrintifyShopId,onSaved:async()=>{let e=eR.current;eR.current=null,await ek.refresh(),e&&lU(e)},onClose:()=>{eR.current=null,eP(!1)}}),("digital"===lF||eh)&&(0,n.jsx)(y.Z,{sx:{containerType:"inline-size",display:"digital"===lF?"block":"none"},children:(0,n.jsxs)(y.Z,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:3,alignItems:"start",["@container (max-width: ".concat(700,"px)")]:{gridTemplateColumns:"1fr"}},children:[(0,n.jsxs)(y.Z,{sx:{minWidth:0},children:[(0,n.jsx)(L.Z,{fontSize:15,color:"var(--lv-text-primary)",sx:{mb:.5},children:"Files"}),(0,n.jsx)(L.Z,{fontSize:12,color:"var(--lv-text-secondary)",sx:{mb:1.5},children:"Manage files in this listing"}),(p||c)&&(0,n.jsxs)(y.Z,{sx:{display:"flex",alignItems:"center",gap:1.5,mb:1.5},children:[p&&(0,n.jsx)(y.Z,{component:"img",src:p,sx:{width:36,height:36,borderRadius:1,objectFit:"cover",flexShrink:0}}),(0,n.jsx)(L.Z,{sx:{fontSize:13,fontWeight:500,color:"var(--lv-text-primary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:null!=c?c:"Listing ".concat(s)})]}),(0,n.jsx)(tg.Z,{listingId:s,onPayloadGetterReady:T,onResetReady:N,onReplaceReady:W,onPendingDeliverablesChanged:lR,onPendingEtsyRemovalsChanged:lM,onRefreshPreview:lL,onEtsyOnlyFilesChanged:eV,onPresetSnapshotReady:ec,initialParentFolder:ep,initialDeliverables:ev,initialDigitalDesignFiles:ee,onDigitalDesignFilesChanged:el,onUploadingChange:em})]}),(0,n.jsx)(y.Z,{sx:{minWidth:0,maxHeight:560,overflowY:"auto",overflowX:"hidden",pr:.5,"&::-webkit-scrollbar":{width:4},"&::-webkit-scrollbar-track":{background:"none"},"&::-webkit-scrollbar-thumb":{bgcolor:"var(--lv-border-strong)",borderRadius:4}},children:(0,n.jsx)(tm.Z,{listingId:s,listingTitle:c,onChange:H,initialOverrides:B,previewRefreshKey:er+lz,pendingDeliverables:lZ,pendingEtsyRemovals:lA})})]})})]})}},70740:function(e,l,t){t.d(l,{q:function(){return n}});function n(e){var l;let t=null!=e?e:[],n=t.find(e=>((null==e?void 0:e.name)||(null==e?void 0:e.position)||"").toLowerCase().includes("front"));return null!==(l=null!=n?n:t[0])&&void 0!==l?l:null}},65876:function(e,l,t){t.d(l,{M4:function(){return r},U:function(){return o},y6:function(){return i}});let n="Core Details",i="This is made by another company or person and isn't vintage, so Etsy requires a production partner. Add one below to continue.",r="".concat(n,": ").concat(i),o="".concat(n,": Etsy requires a production partner for this who-made / when-made combination â add one in ").concat(n,".")},39149:function(e,l,t){t.d(l,{XY:function(){return r}});var n=t(2265);function i(e){return{past:[],current:e,future:[],lastCoalesceKey:null}}function r(e){let{limit:l=50}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=(0,n.useRef)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:50;return function(l,t){switch(t.type){case"SET":return{...l,current:t.state,lastCoalesceKey:null};case"COMMIT":{let n=null==t.coalesceKey?null:t.coalesceKey;if(null!=n&&n===l.lastCoalesceKey&&"function"!=typeof t.rebase)return{...l,current:t.state,future:[]};let i="function"==typeof t.rebase?t.rebase:e=>e,r=i(Object.prototype.hasOwnProperty.call(t,"previousState")?t.previousState:l.current);return{past:[..."function"==typeof t.rebase?l.past.map(e=>i(e)):l.past,r].slice(-e),current:t.state,future:[],lastCoalesceKey:n}}case"UNDO":{if(!l.past.length)return l;let e=l.past[l.past.length-1];return{past:l.past.slice(0,-1),current:e,future:[l.current,...l.future],lastCoalesceKey:null}}case"REDO":{if(!l.future.length)return l;let e=l.future[0];return{past:[...l.past,l.current],current:e,future:l.future.slice(1),lastCoalesceKey:null}}case"RESET":return{past:[],current:t.state,future:[],lastCoalesceKey:null};default:return l}}}(l)).current,[r,o]=(0,n.useReducer)(t,e,i),a=(0,n.useRef)(r),d=(0,n.useCallback)(e=>{let l=a.current,n=t(l,e);return a.current=n,o(e),{changed:n!==l,previous:l.current,current:n.current}},[t]),s=(0,n.useCallback)(e=>{let l=a.current.current;return d({type:"SET",state:"function"==typeof e?e(l):e})},[d]),u=(0,n.useCallback)(function(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=a.current.current,n={type:"COMMIT",state:"function"==typeof e?e(t):e};return Object.prototype.hasOwnProperty.call(l,"previousState")&&(n.previousState=l.previousState),"function"==typeof l.rebase&&(n.rebase=l.rebase),null!=l.coalesceKey&&(n.coalesceKey=l.coalesceKey),d(n)},[d]),c=(0,n.useCallback)(()=>d({type:"UNDO"}),[d]),p=(0,n.useCallback)(()=>d({type:"REDO"}),[d]),v=(0,n.useCallback)(e=>{let l=a.current.current;return d({type:"RESET",state:"function"==typeof e?e(l):e})},[d]),h=(0,n.useCallback)(()=>a.current.current,[]);return{state:r.current,set:s,commit:u,undo:c,redo:p,reset:v,getState:h,canUndo:r.past.length>0,canRedo:r.future.length>0}}},70657:function(e,l,t){t.d(l,{N:function(){return o}});var n=t(2265),i=t(45335),r=t(34398);function o(){let{shortcuts:e,commands:l,handlers:t,onCommand:o,context:a,getContext:d,onAnalytics:s,onBlocked:u,onError:c,enabled:p=!0,scope:v="element",scopeElement:h,requireCanvasFocus:f=!1,modalActive:x,preventDefault:g=!0,stopPropagation:m=!1}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}
1,[y,b]=(0,n.useState)(null),j=(0,n.useRef)(null);return j.current={shortcuts:e,commands:l,handlers:t,onCommand:o,context:a,getContext:d,onAnalytics:s,onBlocked:u,onError:c,enabled:p,scopeElement:h,requireCanvasFocus:f,modalActive:x,preventDefault:g,stopPropagation:m},(0,n.useEffect)(()=>{let e="window"===v?window:y;if(!e)return;let l=e=>{var l,t,n,o;let a=j.current;if(!a.enabled)return;let d=(null==y?void 0:y.ownerDocument)||(null===(l=e.target)||void 0===l?void 0:l.ownerDocument)||("undefined"==typeof document?null:document),s="function"==typeof(o=a.scopeElement)?o()||y:o&&"object"==typeof o&&Object.prototype.hasOwnProperty.call(o,"current")?o.current||y:o||y;if(("element"===v||a.requireCanvasFocus)&&!(0,r.iP)(s,d,e.target)||(0,r.Xu)(e,{ownerDocument:d,modalActive:a.modalActive}))return;let u=a.commands||(a.handlers||a.onCommand?i.pM:null);if(u){let l=(null===(t=a.getContext)||void 0===t?void 0:t.call(a))||a.context||{},r=(0,i.GZ)(e,{commands:u,context:l});if(r){if(e.repeat&&!r.command.allowRepeat){a.preventDefault&&!1!==r.command.preventDefault&&e.preventDefault(),a.stopPropagation&&e.stopPropagation();return}let t=(0,i.Zt)(r.command,l);if((null===(n=a.handlers)||void 0===n?void 0:n[r.command.handler||r.command.id])||a.onCommand||t.disabled){a.preventDefault&&!1!==r.command.preventDefault&&e.preventDefault(),a.stopPropagation&&e.stopPropagation(),(0,i.ST)(r,{handlers:a.handlers,onCommand:a.onCommand,onAnalytics:a.onAnalytics,onBlocked:a.onBlocked,onError:a.onError,context:l,event:e,source:"keyboard"});return}}}let c=function(e,l){for(let[t,n]of Object.entries(l||{}))if((0,i.ed)(e,(0,i.mX)(t)))return{handler:n,shortcut:t};return null}(e,a.shortcuts);"function"==typeof(null==c?void 0:c.handler)&&c.handler(e)};return e.addEventListener("keydown",l),()=>e.removeEventListener("keydown",l)},[y,v]),{ref:(0,n.useCallback)(e=>b(e),[]),element:y}}},45641:function(e,l,t){function n(e,l,t){let n=e,i=1/0,r=null;for(let o of l){let l=Math.abs(e-o);l<t&&l<i&&(n=o,i=l,r=o)}return{value:n,snapped:null!==r,target:r}}function i(e){let{xTargets:l=[],yTargets:t=[],threshold:i=4}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n(e.x,l,i),o=n(e.y,t,i);return{point:{x:r.value,y:o.value},snappedX:r.snapped,snappedY:o.snapped,guideX:r.target,guideY:o.target}}t.d(l,{R:function(){return i},n:function(){return n}})},58501:function(e,l,t){t.d(l,{G0:function(){return a},ZP:function(){return d},ut:function(){return o}});var n=t(2265),i=t(59497);let r=e=>JSON.stringify(e,(e,l)=>l&&"object"==typeof l&&!Array.isArray(l)?Object.fromEntries(Object.keys(l).sort().map(e=>[e,l[e]])):l);function o(){var e,l,t;let{serverListing:n,tagScoreCache:i}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=(null==n?void 0:n.scoreInputs)&&"object"==typeof n.scoreInputs?n.scoreInputs:null,o=Object.create(null);if((null==r?void 0:r.tagDemand)&&"object"==typeof r.tagDemand)for(let e of Object.keys(r.tagDemand))o[e]=r.tagDemand[e];if(i&&"object"==typeof i)for(let l of Object.keys(i)){let t=null===(e=i[l])||void 0===e?void 0:e.demandScore;Number.isFinite(t)&&(o[l]=t)}return{tagDemand:o,priceBreakpoints:null!==(l=null==r?void 0:r.priceBreakpoints)&&void 0!==l?l:null,listingCurrency:null!==(t=null==r?void 0:r.listingCurrency)&&void 0!==t?t:null}}function a(e){var l,t;let n=null!==(t=null==e?void 0:e.id)&&void 0!==t?t:null==e?void 0:null===(l=e.full_details)||void 0===l?void 0:l.listing_id;return null==n||""===n?null:String(n)}function d(e,l,t){var o,d,s,u;let{title:c,description:p,tags:v,images:h,price:f,personalizationQuestions:x}=null!=e?e:{},g=(0,n.useMemo)(()=>{let e=(Array.isArray(h)?h:[]).filter(e=>e&&(e.src||"mockup_slot"===e.type)).map(e=>{var l,t;return"mockup_slot"===e.type?{full_width:2e3}:{full_width:null!==(t=null!==(l=e.full_width)&&void 0!==l?l:e.width)&&void 0!==t?t:null}}),l=Array.isArray(x)?x:[];return{title:null!=c?c:"",description:null!=p?p:"",tags:Array.isArray(v)?v:[],images:e,price:null!=f?f:null,is_personalizable:l.length>0,personalizationQuestionCount:l.length}},[c,p,v,h,f,x]),m=r({tagDemand:null!==(o=null==t?void 0:t.tagDemand)&&void 0!==o?o:{},priceBreakpoints:null!==(d=null==t?void 0:t.priceBreakpoints)&&void 0!==d?d:null,listingCurrency:null!==(s=null==t?void 0:t.listingCurrency)&&void 0!==s?s:null}),y=(0,n.useMemo)(()=>JSON.parse(m),[m]),b=a(l),j=null!==(u=null!=b?b:l)&&void 0!==u?u:null,[_,w]=(0,n.use
1State)(()=>({key:j,listing:g,inputs:y}));return _.key!==j&&w({key:j,listing:null,inputs:null}),(0,n.useEffect)(()=>{let e=setTimeout(()=>w({key:j,listing:g,inputs:y}),300);return()=>clearTimeout(e)},[j,g,y]),(0,n.useMemo)(()=>{if(!(null==l?void 0:l.score))return l;let{listing:e,inputs:t}=_;return e&&(e.title||e.description||0!==e.tags.length||0!==e.images.length)?{...l,score:(0,i.qE)({...e,currency_code:t.listingCurrency},{tagDemand:t.tagDemand,priceBreakpoints:t.priceBreakpoints})}:l},[l,_])}},64165:function(e,l,t){t.d(l,{Z:function(){return o},d:function(){return a}});var n=t(2265),i=t(86438),r=t(32090);function o(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{enabled:t=!0}=l,o=(0,i.Hd)(),a=t&&o?(0,r.XL)(e):null,[d,s]=(0,n.useState)(()=>null!=a&&!0===(0,r.P3)(a)),[u,c]=(0,n.useState)(()=>(0,r.ku)(a)),[p,v]=(0,n.useState)(()=>null==a||void 0!==(0,r.ku)(a)||!1===(0,r.P3)(a));return(0,n.useEffect)(()=>{if(null==a){s(e=>!e&&e),c(void 0),v(!0);return}let e=(0,r.P3)(a),l=(0,r.ku)(a);if(c(l),void 0!==e){s(l=>l===e?l:e),v(void 0!==l||!1===e);return}v(!1);let t=!1;return(0,r.ZP)(a).then(e=>{t||void 0===e||(s(e),v(!0)),t||c((0,r.ku)(a))}),()=>{t=!0}},[a]),(0,n.useEffect)(()=>{if(null==a)return;let e=e=>{var l,t,n;if(String(null==e?void 0:null===(l=e.detail)||void 0===l?void 0:l.listingId)!==a||!(null==e?void 0:null===(t=e.detail)||void 0===t?void 0:t.payload))return;let i=e.detail.payload;c(i),s(!!(null==i?void 0:null===(n=i.links)||void 0===n?void 0:n.length)),v(!0)};return window.addEventListener(r.SD,e),()=>window.removeEventListener(r.SD,e)},[a]),{linked:d,statusResolved:p,markLinked:(0,n.useCallback)(()=>{null!=a&&(0,r.dJ)(a,!0),s(!0),v(void 0!==u)},[a,u]),status:u,refreshStatus:(0,n.useCallback)(async()=>{if(null==a)return null;let e=await (0,r.JG)(a);if(void 0!==e){var l;c(null!=e?e:void 0),s(!!(null==e?void 0:null===(l=e.links)||void 0===l?void 0:l.length)),v(!0)}return e},[a])}}function a(e){let l=(0,i.Hd)(),t=(0,n.useMemo)(()=>{if(!l)return[];let t=new Set;for(let l of Array.isArray(e)?e:[]){let e=(0,r.XL)(l);null!=e&&t.add(e)}return Array.from(t).sort()},[l,(Array.isArray(e)?e:[]).join()]),[o,a]=(0,n.useState)(()=>new Set);return(0,n.useEffect)(()=>{let e=new Set(t.filter(e=>!0===(0,r.P3)(e)));a(l=>!function(e,l){if(e.size!==l.size)return!1;for(let t of e)if(!l.has(t))return!1;return!0}(l,e)?e:l);let l=t.filter(e=>void 0===(0,r.P3)(e));if(0===l.length)return;let n=!1;return(0,r.wK)(l).then(e=>{n||0===e.size||a(l=>{let t=new Set(l);return e.forEach(e=>t.add(e)),t})}),()=>{n=!0}},[t]),o}},39095:function(e,l,t){t.d(l,{Z:function(){return o}});var n=t(2265),i=t(15127),r=t(17339);function o(e){let l=(0,n.useRef)(new Map),t=(0,n.useCallback)(t=>{var n;let o=Date.now();o-(null!==(n=l.current.get(t))&&void 0!==n?n:0)<r.Nn||(l.current.set(t,o),(0,i.L)(r.wU,{surface:e}))},[e]),o=(0,n.useCallback)(e=>t(e),[t]),a=(0,n.useCallback)((e,l)=>{(0,r.mI)(e)&&(e.preventDefault(),t(l))},[t]);return{emitBlocked:t,handleLockedInteraction:o,handleLockedKeyDown:a}}},46257:function(e,l,t){t.d(l,{O3:function(){return r},gd:function(){return o},mk:function(){return a}});var n=t(4385);let i="".concat("https://backend.listingview.io","/api/catalog"),r=async function(e){var l,t,r;let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=o.withVariants?"?withVariants=1":"";return null!==(r=null===(t=(await n.default.get("".concat(i,"/products/").concat(e,"/providers").concat(a))).data)||void 0===t?void 0:null===(l=t.data)||void 0===l?void 0:l.providers)&&void 0!==r?r:[]},o=e=>{var l,t;let n=[];return(null===(l=e.colors)||void 0===l?void 0:l.length)>0&&n.push({id:"colors",label:"Colors",is_design_variable:!0,options:e.colors.map(e=>{var l;return{id:"color-".concat(e.name),label:e.name,hex:null!==(l=e.hex)&&void 0!==l?l:null}})}),(null===(t=e.sizes)||void 0===t?void 0:t.length)>0&&n.push({id:"sizes",label:"Sizes",is_design_variable:!1,options:e.sizes.map(e=>({id:"size-".concat(e),label:e}))}),n},a=async e=>{var l,t,r,o,a;let d=new URLSearchParams;return d.set("page",null!==(t=e.page)&&void 0!==t?t:1),d.set("limit",null!==(r=e.limit)&&void 0!==r?r:24),d.set("sort",null!==(o=e.sort)&&void 0!==o?o:"popular"),e.search&&d.set("search",e.search),e.supplier&&"all"!==e.supplier&&d.set("supplier",e.supplier),e.category&&"all"!==e.category&&d.set("category",e.category),null!=e.price_min&&d.set("price_min",e.price_min),null!=e.price_max&&d.set("price_max",e.price_max),null!==(a=null===(l=(await n.default.get("".concat(i,"/products?").concat(d.toString()))).data)||void 0===l?void 0:l.data)&&void 0!==a?a:{data:[],pagination:{},filters:{}}}},32090:function(e,l,t){t.d(l,{JG:function(){return y},NK:function(){return m},P3:function(){return p},SD:function(){return s},XK:function(){return g},XL:function(){return u},ZP:function(){return b},bd:function(){return x},dJ:function(){return v},ku:function(){return h},wK:function(){return j},wq:function(){return f}});var n=t(4465),i=t(86438);let r=new Map,o=new Set,a=new Map,d=new Map,s="listingview:pod-draft-status-updated";function u(e){return null==e||""===e?null:String(e)}function c(e){return Array.isArray(null==e?void 0:e.links)&&e.links.length>0}function p(e){if(null!=e)return r.get(e)}function v(e,l){null!=e&&(r.set(e,l),l&&o.delete(e))}function h(e){if(null!=e)return d.get(e)}function f(e,l){null!=e&&l&&(d.set(e,l),v(e,c(l)),window.dispatchEvent(new CustomEvent(s,{detail:{listingId:String(e),payload:l}})))}function x(e){return null!=e&&o.has(e)}function g(e){null!=e&&o.add(e)}function m(e){let l=u(e);null!=l&&o.delete(l)}
1async function y(e){var l,t,r;if(!(0,i.YC)())return null;let o=u(e);if(null==o)return null;try{let e=await (0,n.c5)(o),i=null!==(t=null==e?void 0:null===(l=e.data)||void 0===l?void 0:l.data)&&void 0!==t?t:null;return i&&f(o,i),i}catch(e){if((null==e?void 0:null===(r=e.response)||void 0===r?void 0:r.status)===404)return v(o,!1),g(o),d.delete(o),null;return}}async function b(e){if(!(0,i.YC)())return!1;let l=u(e);if(null==l)return!1;let t=r.get(l);if(void 0!==t)return t;if(o.has(l))return!1;let d=a.get(l);if(d)return d;let s=(async()=>{var e,t;try{let t=await (0,n.c5)(l),i=null==t?void 0:null===(e=t.data)||void 0===e?void 0:e.data,r=c(i);return i?f(l,i):v(l,r),r}catch(e){if((null==e?void 0:null===(t=e.response)||void 0===t?void 0:t.status)===404)return v(l,!1),g(l),!1;return}finally{a.delete(l)}})();return a.set(l,s),s}async function j(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{concurrency:t=6}=l,n=new Set;if(!(0,i.YC)())return n;let r=[],o=new Set;for(let l of Array.isArray(e)?e:[]){let e=u(l);null==e||o.has(e)||(o.add(e),r.push(e))}if(0===r.length)return n;let a=0,d=async()=>{for(;a<r.length;){let e=r[a];a+=1,await b(e)===!0&&n.add(e)}};return await Promise.all(Array.from({length:Math.min(t,r.length)},d)),n}},9017:function(e,l,t){t.d(l,{Cq:function(){return v},Iz:function(){return h},JS:function(){return u},LB:function(){return i},Mk:function(){return _},Sf:function(){return y},T5:function(){return j},Tw:function(){return d},Uy:function(){return p},cF:function(){return r},kF:function(){return g},m9:function(){return b},nn:function(){return f},vx:function(){return c},y$:function(){return n},y_:function(){return x}});let n="listingview:pod-linked-edit-started",i=Object.freeze({ORDERS_IN_FLIGHT:"POD_PROVIDER_CHANGE_ORDERS_IN_FLIGHT",SPLIT_UNSUPPORTED:"DRAFT_SPLIT_EDIT_UNSUPPORTED",REMOVE_UNSUPPORTED:"POD_ROUTABLE_PRODUCT_REMOVE_UNSUPPORTED",IN_PROGRESS:"POD_LINKED_EDIT_IN_PROGRESS",RETRY_REQUIRED:"POD_LINKED_EDIT_RETRY_REQUIRED",UNCOVERED_VARIANTS:"UNCOVERED_VARIANTS",PROVIDER_DISABLED:"POD_LINKED_EDIT_PROVIDER_DISABLED",MULTI_SHOP:"POD_LINKED_EDIT_MULTI_SHOP_UNSUPPORTED"}),r="split routing products are not editable yet",o="Checking Printify routing status before editing.",a=Object.freeze(["DRAFT_DELETED"]),d="Changing the print provider on a Printify-routed product is not available yet.",s=Object.freeze({ROUTABLE:"routable",NOT_ROUTABLE:"not-routable",UNRESOLVED:"unresolved"});function u(e){var l;return(null==e?void 0:null===(l=e.capabilities)||void 0===l?void 0:l.provider_edit)!==!1}function c(e){var l,t,n,i,r,o,a,d,s,u;let c=null==e?void 0:null===(l=e.response)||void 0===l?void 0:l.data,p=null!==(i=null==c?void 0:c.data)&&void 0!==i?i:{};return{status:null!==(r=null==e?void 0:null===(t=e.response)||void 0===t?void 0:t.status)&&void 0!==r?r:null,code:null!==(a=null!==(o=null==p?void 0:p.code)&&void 0!==o?o:null==c?void 0:c.code)&&void 0!==a?a:null,message:null!==(s=null!==(d=null==c?void 0:c.message)&&void 0!==d?d:null==p?void 0:p.message)&&void 0!==s?s:null,assessment:null!==(u=null==p?void 0:null===(n=p.details)||void 0===n?void 0:n.edit_assessment)&&void 0!==u?u:null}}function p(e){var l,t,n,i;let r=null!==(n=null!==(t=null==e?void 0:null===(l=e.data)||void 0===l?void 0:l.data)&&void 0!==t?t:null==e?void 0:e.data)&&void 0!==n?n:{};if((null==r?void 0:r.status)!=="updating"&&(null==r?void 0:r.status)!=="replacing")return null;let o="string"==typeof r.operation_id?r.operation_id.trim():"";if(!o)throw Error("Linked edit protocol error: a 202 response did not include operation_id.");return{status:r.status,operationId:o,podProductId:null!==(i=r.pod_product_id)&&void 0!==i?i:null}}function v(e){let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null==e?void 0:e.listingId;e&&null!=l&&window.dispatchEvent(new CustomEvent(n,{detail:{...e,listingId:String(l)}}))}function h(e,l){let t="string"==typeof(null==e?void 0:e.operationId)&&e.operationId.trim().length>0,n="string"==typeof(null==l?void 0:l.operationId)&&l.operationId.trim().length>0;return t&&!n?e:l}function f(e){var l;return null!==(l=null==e?void 0:e.edit_assessment)&&void 0!==l?l:null}function x(e,l){let t=(Array.isArray(null==e?void 0:e.links)?e.links:[]).filter(e=>String(null==e?void 0:e.pod_product_id)===String(l));return t.length>1||t.some(e=>Number(null==e?void 0:e.split_count)>1||Number(null==e?void 0:e.split_index)>0)}function g(e,l){let t=(Array.isArray(null==e?void 0:e.links)?e.links:[]).filter(e=>String(null==e?void 0:e.pod_product_id)===String(l));return 0!==t.length&&t.some(e=>(null==e?void 0:e.status)==="active"&&!!(null==e?void 0:e.printify_product_id))}function m(e){return!!((null==e?void 0:e.status)==="failed"&&a.includes(null==e?void 0:e.last_error_code))||(null==e||!e.printify_product_id)&&((null==e?void 0:e.status)==="failed"||(null==e?void 0:e.status)==="pending"&&(null==e?void 0:e.pending_reason)==="awaiting_designs")}function y(e){var l,t,n,i;let{payload:a,podProductId:d,draftLinked:u,statusResolved:c=void 0!==a}=e;if(!c&&void 0===a)return{eligibility:s.UNRESOLVED,disabled:!0,reason:o};if(!u&&void 0===a)return{eligibility:s.NOT_ROUTABLE,disabled:!1,reason:null};let p=(Array.isArray(null==a?void 0:a.links)?a.links:[]).filter(e=>String(null==e?void 0:e.pod_product_id)===String(d));if(0===p.length)return{eligibility:s.NOT_ROUTABLE,disabled:!1,reason:null};let v=x(a,d),h=1===p.length&&Number.isInteger(Number(null===(l=p[0])||void 0===l?void 0:l.split_count))&&1===Number(null===(t=p[0])||void 0===t?void 0:t.split_count)&&Number.isInteger(Number(null===(n=p[0])||void 0===n?void 0:n.split_index))&&0===Number(null===(i=p[0])||void 0===i?void 0:i.split_index),f=s.UNRESOLVED;h&&p.some(e=>(null==e?void 0:e.status)==="active"&&(null==e?void 0:e.printify_product_id))?f=s.ROUTABLE:p.length>0&&p.every(m)&&(f=s.NOT_ROUTABLE);let g=p.some(e=>((null==e?void 0:e.status)==="failed"||(null==e?void 0:e.status)==="stale")&&!!(null==e?void 0:e.printify_product_id)&&!m(e));return{eligibility:f,disabled:v||f===s.UNRESOLVED,reason:v?r:g?"Retry the Printify routing product before editing.":f===s.UNRESOLVED?o:null}}function b(e){let l=null==e?void 0:e.payload;if((null==l?void 0:l.success)!==!0)throw Error("Listing refresh failed after the linked edit settled.");return l}function j(e,l){var t,n;let i=new Set(null!==(t=null==l?void 0:l.remove_colors)&&void 0!==t?t:[]),r=new Set(null!==(n=null==l?void 0:l.remove_sizes)&&void 0!==n?n:[]);return(Array.isArray(e)?e:[]).filter(e=>i.has(null==e?void 0:e.color)||r.has(null==e?void 0:e.size)).map(e=>
1null==e?void 0:e.matrixKey).filter(Boolean)}function _(e,l){var t;let n=new Set(null!==(t=null==e?void 0:e.blocking_removals)&&void 0!==t?t:[]);return(null!=l?l:[]).filter(e=>n.has(e))}}}]);
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.