PageSourceSearch

https://app.merlinai.co/_next/static/chunks/67264-ad97cbf580dd38ed.js

js merlinai.co collected 2026-09-30 05:40:35 UTC 124,765 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[67264],{263241:function(e,t,s){s.d(t,{n:function(){return d}});var n=s(785893),a=s(667294),r=s(715956),l=s(526202),o=s(980379),i=s(817211),c=s(672139);function d(e){let{instance:t,productId:s,hoveredScope:d,commitMessage:u,canCommit:x=!0,fabIngest:p,onDropFabPackage:m}=e,h=(0,a.useMemo)(()=>(0,r.Z)(null!=s?s:""),[s]),f=t.draft?(0,n.jsx)("div",{className:"border-b border-stroke-soft-200 px-3 py-3",children:(0,n.jsx)(i.N,{draft:t.draft,canCommit:x,interruptReason:t.pendingInterrupt?t.pendingInterrupt.reason:null,onCommit:()=>t.raiseGate(u||"Commit the catalog scope."),onConfirmCommit:()=>t.confirmCommit(),onDecline:()=>t.pendingInterrupt?t.decline():t.startNewChat()})}):(0,n.jsxs)("div",{className:"border-b border-stroke-soft-200",children:[p&&m&&(0,n.jsx)(c.W,{status:p.status,fileName:p.fileName,error:p.error,onFile:m,onRetry:p.retry}),(0,n.jsx)(o.h,{node:d})]});return(0,n.jsx)("div",{"data-testid":"module-chat-sidebar",className:"flex h-full shrink-0 border-l border-stroke-soft-200",children:(0,n.jsx)(l.ys,{config:h,instance:t,subHeader:f})})}},858004:function(e,t,s){s.d(t,{J:function(){return l}});var n=s(785893),a=s(667294),r=s(682322);function l(e){let{src:t,alt:s="",className:l,fallback:o}=e,{data:i,isLoading:c}=(0,r.M$)(t),[d,u]=(0,a.useState)(!1);return t?c?(0,n.jsx)("div",{className:l,style:{background:"var(--color-bg-soft-200)"}}):(null==i?void 0:i.signedUrl)&&!d?(0,n.jsx)("img",{src:i.signedUrl,alt:s,className:l,onError:()=>u(!0)}):(0,n.jsx)(n.Fragment,{children:null!=o?o:null}):(0,n.jsx)(n.Fragment,{children:null!=o?o:null})}},324031:function(e,t,s){s.d(t,{R:function(){return p}});var n=s(785893),a=s(667294),r=s(678884),l=s(860693),o=s(14066),i=s(970112),c=s(682322),d=s(569070),u=s(958649);function x(e){let{sourceFile:t,draftId:s,open:a,onOpenChange:x}=e,{data:p,isLoading:m}=(0,c.nv)(s,a),h=(0,u.Qn)(),f=p?function(e,t){let s=Object.keys(d.BY_DRAFT_COUNT_LABELS);return s.reduce((s,n)=>{var a,r;return s[n]=(null!==(a=e[n])&&void 0!==a?a:0)+(null!==(r=t[n])&&void 0!==r?r:0),s},{})}(p.kept,p.removed):null;return(0,n.jsxs)(o.J2e,{open:a,onOpenChange:x,children:[(0,n.jsx)(o.xol,{asChild:!0,children:(0,n.jsxs)("button",{type:"button","data-testid":"catalog-source-chip",onClick:e=>e.stopPropagation(),className:"inline-flex items-center gap-1 truncate text-xs text-text-sub-600 hover:text-text-strong-950 hover:underline",children:[(0,n.jsx)(r.Z,{className:"h-3 w-3 shrink-0"}),"From ",t]})}),(0,n.jsx)(o.yky,{align:"start",className:"w-64 text-sm",onClick:e=>e.stopPropagation(),children:m?(0,n.jsx)(o.OdW,{className:"h-16 w-full"}):p&&f?(0,n.jsxs)("div",{className:"space-y-2",children:[null!=p.earliestCreatedAt&&(0,n.jsxs)("p",{"data-testid":"source-chip-peek-date",className:"text-xs text-text-sub-600",children:["Imported ",(0,i.p6)(new Date(p.earliestCreatedAt))]}),(0,n.jsxs)("div",{className:"text-xs",children:[(0,n.jsx)("p",{className:"font-medium text-text-strong-950",children:"This import created"}),(0,n.jsx)(u.RI,{counts:f,emptyLabel:null})]}),(0,n.jsxs)("p",{"data-testid":"source-chip-undo-window",className:"text-xs text-text-soft-400",children:["Undo available for ",d.UNDO_WINDOW_DAYS," days after import."]}),(0,n.jsxs)(o.zxk,{"data-testid":"undo-this-import",variant:"outline",size:"sm",className:"w-full gap-1.5 text-state-warning",onClick:()=>{x(!1),h({draftId:s,sourceFile:t})},children:[(0,n.jsx)(l.Z,{className:"h-3.5 w-3.5"})," Undo this import"]})]}):(0,n.jsx)("p",{className:"text-xs text-text-soft-400",children:"Could not load this import."})})]})}function p(e){let{sourceFile:t,draftId:s}=e,[r,l]=(0,a.useState)(!1);return t&&s?(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),children:(0,n.jsx)(x,{sourceFile:t,draftId:s,open:r,onOpenChange:l})}):null}},958649:function(e,t,s){s.d(t,{Qn:function(){return x},RI:function(){return p},_v:function(){return h}});var n=s(785893),a=s(667294),r=s(860693),l=s(14066),o=s(970112),i=s(921156),c=s(682322),d=s(569070);let u=(0,a.createContext)(null);function x(){let e=(0,a.useContext)(u);if(!e)throw Error("useOpenCatalogUndoDrawer must be used within a CatalogUndoDrawerHost");return e}function p(e){var t;let{counts:s,emptyLabel:a="None"}=e,r=Object.keys(d.BY_DRAFT_COUNT_LABELS).map(e=>[e,null!==(t=s[e])&&void 0!==t?t:0]).filter(e=>{let[,t]=e;return t>0});return 0===r.length?a?(0,n.jsx)("p",{className:"text-xs text-text-soft-400",children:a}):null:(0,n.jsx)("ul",{className:"space-y-0.5 text-xs text-text-sub-600",children:r.map(e=>{let[t,s]=e,[a,r]=d.BY_DRAFT_COUNT_LABELS[t];return(0,n.jsxs)("li",{children:[s," ",1===s?a:r]},t)})})}function m(e){let{result:t}=e;return(0,n.jsxs)("p",{"data-testid":"undo-result-sentence",className:"rounded-md bg-state-success-lighter px-3 py-2 text-state-success-dark",children:["Removed ",t.productsDeleted," product",1===t.productsDeleted?"":"s",","," ",t.variantsDeleted," variant",1===t.variantsDeleted?"":"s",","," ",t.scopesDeleted," scope",1===t.scopesDeleted?"":"s",","," ",t.setsDeleted," solution set",1===t.setsDeleted?"":"s",","," ",t.requirementsDeleted," requirement",1===t.requirementsDeleted?"":"s","."]})}function h(e){var t,s,x;let{children:h}=e,[f,g]=(0,a.useState)(null),[b,v]=(0,a.useState)(null),y=null!=f,{data:j,isLoading:N}=(0,c.nv)(null!==(t=null==f?void 0:f.draftId)&&void 0!==t?t:null,y),w=(0,c.hl)(),k=w.reset,S=(0,a.useMemo)(()=>e=>{g(e),v(null),k()},[k]),C=j?null==(x=j.earliestCreatedAt)?null:x+864e5*d.UNDO_WINDOW_DAYS:null,I=null!=C&&Date.now()>C;return(0,n.jsxs)(u.Provider,{value:S,children:[h,(0,n.jsx)(l.yoO,{open:y,onOpenChange:e=>{e||(g(null),v(null))},children:(0,n.jsxs)(l.uei,{side:"right",className:"w-full sm:max-w-md",children:[(0,n.jsx)(l.Tuv,{children:(0,n.jsxs)(l.bCQ,{className:"flex items-center gap-2 text-base",children:[(0,n.jsx)(r.Z,{className:"h-4 w-4 text-state-warning"}),"Undo this import",f?" — ".concat(f.sourceFile):""]})}),(0,n.jsx)("div",{className:"mt-4 space-y-4 text-sm",children:b?(0,n.jsx)(m,{result:b}):N?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)(l.OdW,{className:"h-4 w-2/3"}),(0,n.jsx)(l.OdW,{className:"h-16 w-full"})]}):j?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"mb-1 font-medium text-text-strong-950",children:"Will be removed"}),(0,n.jsx)(p,{counts:j.removed})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"mb-1 font-medium text-text-strong-950",children:"Will be kept — referenced by an estimate"}),(0,n.jsx)(p,{counts:j.kept})]}),(0,n.jsx)("p",{"data-testid":"undo-window",className:"text-xs text-text-soft-400",children:null==C?"Undo available for ".concat(d.UNDO_WINDOW_DAYS," days after import."):I?"The ".concat(d.UNDO_WINDOW_DAYS,"-day undo window closed on ").concat((0,o.p6)(new Date(C)),". Remove these products individually instead."):"Undo available until ".concat((0,o.p6)(new Date(C)),".")}),w.isError&&(0,n.jsx)("p",{"data-testid":"undo-error",className:"text-xs text-state-error",children:null!==(s=(0,i.Aj)(w.error))&&void 0!==s?s:(0,i.XI)(w.error)===i.pe?"This import can no longer be und
1one.":"Could not undo this import — refresh the library to see its current state."}),(0,n.jsx)(l.zxk,{"data-testid":"undo-confirm",variant:"destructive",size:"sm",disabled:w.isPending||!f||I,onClick:()=>f&&w.mutate(f.draftId,{onSuccess:e=>v(e)}),children:w.isPending?"Undoing…":"Confirm undo"})]}):(0,n.jsx)("p",{className:"text-text-soft-400",children:"Could not load this import's undo preview."})})]})})]})}},672139:function(e,t,s){s.d(t,{W:function(){return c}});var n=s(785893),a=s(667294),r=s(636316),l=s(987756),o=s(140116),i=s(904349);function c(e){let{status:t,fileName:s,error:c,onFile:d,onRetry:u}=e,x=(0,a.useRef)(null),[p,m]=(0,a.useState)(!1);if("ready"===t)return null;let h=e=>{var t;e.preventDefault(),m(!1);let s=null===(t=e.dataTransfer.files)||void 0===t?void 0:t[0];s&&d(s)};return"uploading"===t?(0,n.jsxs)("div",{className:"flex items-start gap-2.5 px-4 py-3",children:[(0,n.jsx)(r.Z,{className:"mt-0.5 h-4 w-4 shrink-0 animate-spin text-state-warning"}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("p",{className:"truncate text-sm font-semibold text-text-strong-950",children:"Uploading the fabrication package…"}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-text-sub-600",children:"Handing ".concat(s?"“".concat(s,"”"):"the package"," to the catalog agent.")})]})]}):"failed"===t?(0,n.jsxs)("div",{className:"flex items-start gap-2.5 px-4 py-3",children:[(0,n.jsx)(o.Z,{className:"mt-0.5 h-4 w-4 shrink-0 text-state-error"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"text-sm font-semibold text-text-strong-950",children:"Couldn't upload the package"}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-text-sub-600",children:null!=c?c:"Something went wrong uploading the fabrication package."}),(0,n.jsx)(i.z,{variant:"outline",size:"sm",className:"mt-2 h-7 text-xs",onClick:u,children:"Retry"})]})]}):(0,n.jsxs)("div",{className:"px-3 py-3",children:[(0,n.jsx)("input",{ref:x,type:"file",accept:"application/pdf",className:"hidden",onChange:e=>{var t;let s=null===(t=e.target.files)||void 0===t?void 0:t[0];e.target.value="",s&&d(s)}}),(0,n.jsxs)("button",{type:"button",onClick:()=>{var e;return null===(e=x.current)||void 0===e?void 0:e.click()},onDragOver:e=>{e.preventDefault(),m(!0)},onDragLeave:()=>m(!1),onDrop:h,className:["flex w-full flex-col items-center gap-1.5 rounded-lg border border-dashed px-4 py-5 text-center transition-colors",p?"border-brand-primary bg-primary-alpha-10":"border-stroke-sub-300 bg-bg-weak-50 hover:bg-bg-soft-200"].join(" "),children:[(0,n.jsx)(l.Z,{className:"h-5 w-5 text-icon-sub-600"}),(0,n.jsx)("span",{className:"text-sm font-semibold text-text-strong-950",children:"Drop a fabrication package"}),(0,n.jsx)("span",{className:"text-xs text-text-sub-600",children:"The agent reads the WO and drafts your catalog scope. PDF only."})]})]})}},296148:function(e,t,s){s.d(t,{G:function(){return c}});var n=s(785893),a=s(667294),r=s(270240),l=s(14066),o=s(682322),i=s(960917);function c(e){let{productId:t,title:s,description:c,size:d="sm",className:u}=e,[x,p]=(0,a.useState)(null),m=(0,o.AD)(),h=!!((null==s?void 0:s.trim())||(null==c?void 0:c.trim())),f=()=>{m.mutate(t,{onSuccess:e=>p(e.jobId)})},g=(0,n.jsxs)(l.zxk,{variant:"ghost",size:"icon"===d?"icon":"sm",className:u,onClick:f,disabled:!h||m.isPending,children:[(0,n.jsx)(r.Z,{size:14}),"icon"!==d&&(m.isPending?"Starting...":"Generate icon")]});return(0,n.jsxs)(n.Fragment,{children:[h?g:(0,n.jsx)(l.pnl,{children:(0,n.jsxs)(l.ua7,{children:[(0,n.jsx)(l.aJU,{asChild:!0,children:(0,n.jsx)("span",{children:g})}),(0,n.jsx)(l._vU,{children:"Add a product description before generating an icon"})]})}),x&&(0,n.jsx)(i.j,{isOpen:!0,onClose:()=>p(null),productId:t,jobId:x})]})}},113263:function(e,t,s){s.d(t,{O:function(){return u}});var n=s(785893),a=s(313742),r=s(27949),l=s(140116),o=s(541352);function i(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"shrink-0 opacity-70","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#FCB03A"})})}function c(e){let{nodeId:t,dropped:s,onToggle:r,disabled:l=!1}=e;return(0,n.jsx)("button",{type:"button","data-testid":"keep-drop-toggle-".concat(t),"aria-pressed":!s,"aria-label":s?"Keep this node":"Drop this node",disabled:l,onClick:e=>{e.stopPropagation(),l||r(t)},className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-md border transition-colors ".concat(l?"cursor-not-allowed":"cursor-pointer"," ").concat(s?"border-stroke-soft-200 text-text-soft-400 hover:bg-bg-weak-50":"border-state-success/40 bg-state-success-lighter text-state-success-dark hover:bg-state-success-light"),children:s?(0,n.jsx)(o.Z,{className:"h-3.5 w-3.5"}):(0,n.jsx)(a.Z,{className:"h-3.5 w-3.5"})})}function d(e){let{req:t,dropped:s,parentDropped:a,onToggle:r}=e,o=null!=t.conflict;return(0,n.jsxs)("div",{"data-testid":"ghost-requirement-node","data-node-id":t.nodeId,"data-dropped":s?"true":"false",className:"flex items-center gap-2.5 border-l border-dashed border-stroke-sub-300 py-1.5 pl-4 pr-2 ".concat(s?"opacity-40":""),children:[(0,n.jsx)("span",{"data-testid":"ghost-requirement-node-".concat(t.no
1deId),"data-dropped":s?"true":"false",className:"contents"}),(0,n.jsxs)("span",{className:"min-w-0 flex-1 truncate text-xs ".concat(s?"text-text-soft-400 line-through":"text-text-sub-600"),children:[t.displayName,(0,n.jsxs)("span",{className:"ml-1.5 text-text-soft-400",children:["\xb7 ",t.qty," ",t.uom]})]}),o&&(0,n.jsxs)("span",{"data-testid":"conflict-flag","data-node-id":t.nodeId,"data-conflict-node":t.nodeId,className:"inline-flex shrink-0 items-center gap-1 rounded-md bg-state-warning-lighter px-1.5 py-0.5 text-[10px] font-medium text-state-warning-dark",children:[(0,n.jsx)("span",{"data-testid":"ghost-conflict-flag-".concat(t.nodeId),className:"contents"}),(0,n.jsx)(l.Z,{className:"h-3 w-3"}),"needs review"]}),(0,n.jsx)(c,{nodeId:t.nodeId,dropped:s,disabled:a,onToggle:r})]})}function u(e){let{draft:t,error:s,isDropped:a,onToggle:l}=e;if(!t)return s?(0,n.jsxs)("div",{"data-testid":"ghost-scope-tree-error",className:"mb-2 flex items-start gap-2 rounded-md border border-state-error-light bg-state-error-lighter px-3 py-2 text-xs text-state-error-dark",children:[(0,n.jsx)(r.Z,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),(0,n.jsx)("span",{children:s})]}):null;let{counts:o,types:u}=t,x=o.assembliesExtracted<o.assembliesTotal,p=0===o.typesFound||0===u.length;return(0,n.jsxs)("div",{"data-testid":"ghost-scope-tree","data-draft":"true",className:"mb-2 space-y-2",children:[x&&(0,n.jsxs)("p",{"data-testid":"ghost-scope-tree-partial",className:"flex items-center gap-1.5 rounded-md bg-state-warning-lighter px-2.5 py-1.5 text-xs text-state-warning-dark",children:[(0,n.jsx)(r.Z,{className:"h-3.5 w-3.5 shrink-0"}),o.assembliesExtracted," of ",o.assembliesTotal," assemblies extracted; the rest are in the KB."]}),p?(0,n.jsx)("p",{"data-testid":"ghost-scope-tree-no-clusters",className:"rounded-md border border-dashed border-stroke-sub-300 bg-bg-weak-50 px-3 py-2.5 text-xs text-text-sub-600",children:"No reusable TYPES found; nothing proposed for the catalog. KB entries still landed."}):u.map(e=>{let t=a(e.nodeId);return(0,n.jsxs)("div",{"data-testid":"ghost-scope-node","data-node-id":e.nodeId,"data-dropped":t?"true":"false",className:"overflow-hidden rounded-md border border-dashed border-brand-300 bg-brand-50/40 ".concat(t?"opacity-40":""),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2",children:[(0,n.jsx)(i,{}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate text-sm font-semibold ".concat(t?"text-text-soft-400 line-through":"text-text-strong-950"),children:e.typeName}),(0,n.jsx)("span",{className:"shrink-0 rounded-md bg-brand-100 px-1.5 py-0.5 text-[10px] font-medium text-brand-700",children:"proposed"}),(0,n.jsxs)("span",{className:"shrink-0 tabular-nums text-xs text-text-sub-600",children:[e.instanceCount," instances"]}),(0,n.jsx)(c,{nodeId:e.nodeId,dropped:t,onToggle:l})]}),(0,n.jsx)("div",{className:"space-y-0.5 px-3 pb-2",children:e.requirements.map(e=>(0,n.jsx)(d,{req:e,dropped:t||a(e.nodeId),parentDropped:t,onToggle:l},e.nodeId))})]},e.nodeId)})]})}},960917:function(e,t,s){s.d(t,{j:function(){return d}});var n=s(785893),a=s(667294),r=s(636316),l=s(142297),o=s(14066),i=s(436645),c=s(682322);function d(e){let{isOpen:t,onClose:s,productId:d,jobId:u}=e,[x,p]=(0,a.useState)(u),[m,h]=(0,a.useState)(null),{data:f,isLoading:g}=(0,c.ws)(d,x),b=(0,c.AD)(),v=(0,c.HH)(),y=g||(null==f?void 0:f.status)==="PENDING"||(null==f?void 0:f.status)==="PROCESSING",j=(null==f?void 0:f.status)==="COMPLETED"?f.candidateKeys:[],N=()=>{h(null),b.mutate(d,{onSuccess:e=>p(e.jobId)})},w=()=>{null!==m&&v.mutate({productId:d,candidateKey:j[m]},{onSuccess:s})};return(0,n.jsx)(o.VqE,{open:t,onOpenChange:e=>!e&&s(),children:(0,n.jsxs)(o.cZJ,{className:"sm:max-w-[520px]",children:[(0,n.jsxs)(o.fKu,{children:[(0,n.jsx)(o.$N8,{children:"Choose an icon"}),(0,n.jsx)("p",{className:"text-sm text-[var(--text-sub-600)]",children:"Generated from the product's description. Pick one to apply, or regenerate for new options."})]}),y?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 py-10",children:[(0,n.jsx)(r.Z,{className:"h-5 w-5 animate-spin text-text-soft-400"}),(0,n.jsx)("p",{className:"text-sm text-text-soft-400",children:"Generating icons — this can take a minute..."})]}):(null==f?void 0:f.status)==="FAILED"?(0,n.jsx)("div",{className:"flex flex-col items-center justify-center gap-2 py-10",children:(0,n.jsx)("p",{className:"text-sm text-state-error",children:f.errorMessage||"Icon generation failed"})}):(0,n.jsx)("div",{className:"grid grid-cols-4 gap-3 py-2",children:j.map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>h(t),disabled:b.isPending||v.isPending,className:"aspect-square rounded-none p-1 transition-colors",style:{border:"2px s
1olid ".concat(m===t?"var(--color-primary-base)":"var(--color-stroke-soft-200)"),background:"var(--color-bg-white-0)"},children:(0,n.jsx)(i.d,{src:e,alt:"Icon option ".concat(t+1),className:"h-full w-full object-contain"})},e))}),(0,n.jsxs)(o.cNS,{className:"flex items-center justify-between sm:justify-between",children:[(0,n.jsxs)(o.zxk,{variant:"ghost",onClick:N,disabled:y||b.isPending||v.isPending,children:[(0,n.jsx)(l.Z,{className:"mr-1.5 h-3.5 w-3.5 ".concat(b.isPending?"animate-spin":"")}),"Regenerate"]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)(o.zxk,{variant:"ghost",onClick:s,disabled:v.isPending,children:"Cancel"}),(0,n.jsx)(o.zxk,{onClick:w,disabled:null===m||v.isPending||y,style:{background:"var(--color-primary-base)"},children:v.isPending?"Applying...":"Apply icon"})]})]})]})})}},787379:function(e,t,s){s.d(t,{M8:function(){return J},R3:function(){return M},Xq:function(){return X},cF:function(){return G}});var n=s(785893),a=s(667294),r=s(430202),l=s(811163),o=s(53219),i=s(931012),c=s(613718),d=s(390470),u=s(541352),x=s(313742),p=s(808971),m=s(364998),h=s(884979),f=s(636316),g=s(956989),b=s(283900),v=s(14066),y=s(407800),j=s(816080),N=s(682322),w=s(569070),k=s(218754),S=s(379983),C=s(329821),I=s(851184),P=s(48743),_=s(263241),z=s(113263),A=s(62093),W=s(332922),R=s(911269),D=s(820888),T=s(351085),E=s(770382),q=s(797071),Z=s(603367),F=s(489087),B=s(858004),L=s(436645),U=s(296148),O=s(324031),V=s(958649);let K=0;function M(){var e,t,d,p,h,w,T,E;let q=(0,l.useRouter)(),M=(0,r.NL)(),{toast:G}=(0,y.pm)(),Y=q.query.id,X="new"===Y||!Y,{data:J,isLoading:ee}=(0,N.Ir)(null!=Y?Y:""),{data:es=[]}=(0,N.Rk)(X?"":null!=Y?Y:""),en=(0,N.KA)(),ea=(0,N.At)(),er=(0,N.Ay)(),el=(0,N.gl)(),{data:eo=[]}=(0,N.Ap)(),{data:ei}=(0,N.Br)(null!=Y?Y:""),{data:ec=[]}=(0,N.Xh)(null!=Y?Y:""),ed=(0,N.Iv)(null!=Y?Y:""),eu=(0,N.QD)(null!=Y?Y:""),ex=(0,N.F4)(null!=Y?Y:""),[ep,em]=(0,a.useState)(""),[eh,ef]=(0,a.useState)(""),[eg,eb]=(0,a.useState)([]),[ev,ey]=(0,a.useState)(""),[ej,eN]=(0,a.useState)(null),[ew,ek]=(0,a.useState)(null),[eS,eC]=(0,a.useState)(!1),[eI,eP]=(0,a.useState)([]),[e_,ez]=(0,a.useState)([]),[eA,eW]=(0,a.useState)([]),[eR,eD]=(0,a.useState)([]),[eT,eE]=(0,a.useState)(0),[eq,eZ]=(0,a.useState)(!0),[eF,eB]=(0,a.useState)(!0),[eL,eU]=(0,a.useState)(!0),[eO,eV]=(0,a.useState)(new Set),[eK,eM]=(0,a.useState)(null),[eH,e$]=(0,a.useState)(null),[eG,eY]=(0,a.useState)(null),{user:eQ}=(0,j.Z)(),eX=(0,A.w)(null!=Y?Y:"",null!==(e=null==eQ?void 0:eQ.orgId)&&void 0!==e?e:"",W.x,W.H),eJ=(0,R.F)(eX.draft),e0=(0,D.U)({sendMessage:eX.sendMessage}),e1=(0,a.useCallback)(e=>{e0.ingestThenAsk(e,{productId:null!=Y?Y:"",askMessage:"Build a catalog scope from this fabrication package."})},[e0,Y]),[e5,e2]=(0,a.useState)(null),[e3,e6]=(0,a.useState)("idle"),e4=(0,a.useRef)(null),e7=(0,a.useRef)(!0);(0,a.useEffect)(()=>{if(!X&&Y&&!e7.current&&!eS)return e4.current&&clearTimeout(e4.current),e4.current=setTimeout(async()=>{e6("saving");try{await er.mutateAsync({id:Y,title:ep.trim(),description:eh.trim()||void 0,status:"READY",tags:eg,image:ej&&!ej.startsWith("blob:")?ej:void 0}),await ea.mutateAsync({productId:Y,variables:eI,configRules:e_}),e6("saved"),setTimeout(()=>e6("idle"),2e3)}catch(e){e6("idle")}},1e3),()=>{e4.current&&clearTimeout(e4.current)}},[ep,eh,eg,ej,eI,e_]),(0,a.useEffect)(()=>{J&&e7.current&&setTimeout(()=>{e7.current=!1},500)},[J]);let[e8,e9]=(0,a.useState)(!1),[te,tt]=(0,a.useState)(""),ts=(0,a.useRef)(null),tn=(0,N.j9)(null!=Y?Y:""),ta=(0,N.e3)(null!=Y?Y:""),{data:tr=[]}=(0,N.Jq)();(0,a.useEffect)(()=>{if(J){var e,t,s;em(null!==(e=J.title)&&void 0!==e?e:""),ef(null!==(t=J.description)&&void 0!==t?t:""),eb(null!==(s=J.tags)&&void 0!==s?s:[]),J.variables&&eP(J.variables),J.configRules&&ez(J.configRules),J.image&&eN(J.image)}},[J]);let tl=(0,a.useCallback)(async e=>{var t;let n=null===(t=e.target.files)||void 0===t?void 0:t[0];if(!n)return;let a=URL.createObjectURL(n);ek(a),eC(!0);try{let{getImageUploadUrl:e}=await Promise.resolve().then(s.bind(s,569070)),{uploadFileToS3:t}=await s.e(17279).then(s.bind(s,317279)),a=await e(n.name),{uploadUrl:r,cdnUrl:l,uuid:o}=a;if(!r)throw Error("No upload URL returned from backend");await t(n,r);let i=l||o;if(!i)throw Error("Backend returned no cdnUrl or uuid");Y&&!X&&await er.mutateAsync({id:Y,image:i}),eN(i),ek(null),G({title:"Image uploaded"})}catch(e){ek(null),G({title:"Upload failed",description:e instanceof Error?e.message:void 0,variant:"destructive"})}finally{eC(!1)}},[Y,X,er,G]),to=(0,a.useCallback)(()=>{let e=ev.trim();e&&!eg.includes(e)&&(eb(t=>[...t,e]),ey(""))},[ev,eg]),ti=(0,a.useCallback)(e=>{eb(t=>t.filter(t=>t!==e))},[]),tc=(0,a.useCallback)(()=>{eP(e=>[...e,{id:"id-".concat(Date.now(),"-").concat(K++),name:"",options:""}])},[]),td=(0,a.useCallback)((e,t,s)=>{eP(n=>n.map(n=>n.id===e?{...n,[t]:s}:n))},[]),tu=(0,a.useCallback)(e=>{eP(t=>t.filter(t=>t.id!==e)),ez(t=>t.filter(t=>t.ifVariableId!==e&&t.thenVariableId!==e))},[]),tx=(0,a.useCallback)(e=>{var t;let s=eI.filter(t=>t.id!==e);ez(n=>{var a;return[...n,{id:"rule-".concat(Date.now()),ifVariableId:e,ifValue:"",thenVariableId:null!==(t=null===(a=s[0])||void 0===a?void 0:a.id)&&void 0!==t?t:"",thenAllowedValues:[]}]})},[eI]),tp=(0,a.useCallback)((e,t)=>{ez(s=>s.map(s=>s.id===e?{...s,...t}:s))},[]),tm=(0,a.useCallback)(e=>{ez(t=>t.filter(t=>t.id!==e))},[]),th=(0,a.useCallback)(async()=>
1{if(X){let t=await el.mutateAsync({title:ep.trim(),description:eh.trim()||void 0,tags:eg,image:ej&&!ej.startsWith("blob:")?ej:void 0,variables:eI,configRules:e_,connectedProductRefs:eR.length>0?eR.map(e=>({productId:e.productId,qty:e.qty})):void 0});for(let t of eA){var e;await ed.mutateAsync({name:null!==(e=t.scope.name)&&void 0!==e?e:"",connectedProductRefs:[]})}try{await er.mutateAsync({id:t.id,title:ep.trim(),description:eh.trim()||void 0,status:"READY",tags:eg,image:ej&&!ej.startsWith("blob:")?ej:void 0})}catch(e){}q.push("/catalog/library/".concat(t.id))}else Y&&(await er.mutateAsync({id:Y,title:ep.trim(),description:eh.trim()||void 0,status:"READY",tags:eg,image:ej&&!ej.startsWith("blob:")?ej:void 0}),await ea.mutateAsync({productId:Y,variables:eI,configRules:e_}),G({title:"Product saved"}))},[X,Y,ep,eh,eg,ej,eI,e_,eA,el,er,ea,q,G]),tf=(0,a.useCallback)(async e=>{if(!e.isComputed||!Y||X)return e.id;let t=await en.mutateAsync({productId:Y,name:e.name,attributes:e.attributes});return t.id},[Y,X,en]),tg=(0,a.useCallback)(async e=>{if(!Y||X){G({title:"Save the product first to manage variants"});return}let t=await tf(e);eM(t)},[Y,X,tf,G]),tb=(0,a.useCallback)(()=>{e9(!0),tt(""),setTimeout(()=>{var e;return null===(e=ts.current)||void 0===e?void 0:e.focus()},50)},[]),tv=(0,a.useCallback)(async()=>{let e=te.trim();if(!e){e9(!1);return}if(X){let t={scope:{id:"local-scope-".concat(Date.now()),name:e,description:null,tags:[],allowance:null,estimatedPrice:0,parentType:"PRODUCT",parentId:"",inherited:!1,connectedProductRefs:[]},solutionSets:[],childScopes:[]};eW(e=>[...e,t])}else await ed.mutateAsync({name:e,requirements:[],connectedProductRefs:[]});e9(!1),tt("")},[te,X,ed]),ty=(0,a.useCallback)(async e=>{if(X){eW(t=>t.filter(t=>t.scope.id!==e));return}await eu.mutateAsync(e)},[X,eu]),tj=X?eA:ec;null!==(t=null==ei?void 0:ei.totalEstimatedPrice)&&void 0!==t||tj.reduce((e,t)=>e+(0,k.$3)(t),0);let tN=null!==(d=null==ei?void 0:ei.totalAllowance)&&void 0!==d?d:tj.reduce((e,t)=>e+(0,k.ik)(t),0),tw=(0,a.useMemo)(()=>es.map(e=>({id:e.id,name:null!==(p=e.name)&&void 0!==p?p:e.id,attributes:null!==(h=e.attributes)&&void 0!==h?h:{},tags:null!==(w=e.tags)&&void 0!==w?w:[],connectedProductRefs:null!==(T=e.connectedProductRefs)&&void 0!==T?T:[],externalCode:null!==(E=e.externalCode)&&void 0!==E?E:null})),[es]),tk=(0,a.useMemo)(()=>(0,S.Sj)(eI,e_,tw),[eI,e_,tw]),tS=eI.some(e=>e.name.trim()&&e.options.trim()),tC=(0,a.useMemo)(()=>new Set(tw.map(e=>e.id)),[tw]),tI=(0,a.useMemo)(()=>tS?tk.filter(e=>!tC.has(e.id)):[],[tS,tk,tC]),[tP,t_]=(0,a.useState)(!1),tz=X?tI:tw;return q.isReady&&(X||!ee)?J||X?(0,n.jsx)(V._v,{children:(0,n.jsxs)("div",{className:"flex h-full flex-col",style:{background:"var(--color-bg-weak-50)"},children:[(0,n.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-b border-b-[var(--color-stroke-soft-200)] bg-bg-white-0 px-8 py-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("button",{onClick:()=>q.push("/catalog/library"),className:"flex h-8 w-8 cursor-pointer items-center justify-center rounded-none hover:bg-bg-soft-200",children:(0,n.jsx)(o.Z,{className:"h-4 w-4 text-text-sub-600"})}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h1",{style:{fontSize:16,fontWeight:800,letterSpacing:"-0.01em"},children:X?"Create Product":"Edit: Product"}),!X&&(0,n.jsx)(O.R,{sourceFile:null==J?void 0:J.sourceFile,draftId:null==J?void 0:J.createdByDraftId})]}),(0,n.jsx)("p",{className:"text-text-soft-400",style:{fontSize:11},children:"Define work steps and attach solutions to build your product"})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-2"})]}),(0,n.jsxs)("div",{className:"flex flex-1 overflow-hidden",children:[(0,n.jsx)("div",{className:"min-w-0 flex-1 overflow-y-auto px-8 py-6",children:(0,n.jsxs)("div",{className:"mx-auto max-w-3xl space-y-5",children:[(0,n.jsxs)(H,{number:1,title:"Product Basics",subtitle:"Identity, image, category, and short description",expanded:eq,onToggle:()=>eZ(e=>!e),children:[(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"mb-1.5 block text-sm font-medium text-text-sub-600",children:"Images"}),(0,n.jsxs)("label",{className:"relative flex h-24 w-24 cursor-pointer flex-col items-center justify-center overflow-hidden rounded-none border border-dashed border-stroke-sub-300 hover:bg-bg-weak-50",children:[ew?(0,n.jsx)("img",{src:ew,alt:"Product",className:"absolute inset-0 h-full w-full object-cover"}):ej?(0,n.jsx)(B.J,{src:ej,alt:"Product",className:"absolute inset-0 h-full w-full object-cover",fallback:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(i.Z,{className:"h-4 w-4 text-text-soft-400"}),(0,n.jsx)("span",{className:"text-xs text-text-soft-400",children:"Add image"})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(i.Z,{className:"h-4 w-4 text-text-soft-400"}),(0,n.jsx)("span",{className:"text-xs text-text-soft-400",children:"Add image"})]}),eS&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-black/30",children:(0,n.jsx)(f.Z,{className:"h-5 w-5 animate-spin text-white"})}),(0,n.jsx)("input",{type:"file",accept:"image/*",className:"hidden",onChange:tl})]})]}),Y&&"new"!==Y&&(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"mb-1.5 block text-sm font-medium text-text-sub-600",children:"Icon"}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("div",{className:"flex h-12 w-12 items-center justify-center overflow-hidden rounded-none border border-stroke-soft-200",style:{background:"var(--color-bg-weak-50)"},children:(0,n.jsx)(L.d,{src:null==J?void 0:J.icon,alt:"Product icon",className:"h-full w-full object-contain p-1",fallback:(0,n.jsx)(i.Z,{className:"h-3.5 w-3.5 text-text-soft-400"})})}),(0,n.jsx)(U.G,{productId:Y,title:ep,description:eh})]})]}),(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsxs)("label",{className:"mb-1.5 block text-sm font-medium text-text-sub-600",children:["Product Name ",(0,n.jsx)("span",{className:"text-state-error",children:"*"})]}),(0,n.jsx)("input",{value:ep,onChange:e=>em(e.target.value),placeholder:"Product name",className:"w-full rounded-none bg-bg-white-0 px-4 py-2.5 text-text-strong-950 outline-none",style:{border:"1.5px solid var(--color-stroke-soft-200)",fontSize:13,fontWeight:600}})]}),(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("label",{className:"mb-1.5 block text-sm font-medium text-text-sub-600",children:"Tags"}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 rounded-none bg-bg-white-0 px-3 py-2",style:{border:"1.5px solid var(--color-stroke-soft-200)",minHeight:42},children:[eg.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-none px-2.5 py-1",style:{background:"var(--color-bg-soft-200)",fontSize:12,fontWeight:500},children:[e,(0,n.jsx)("button",{onClick:()=>ti(e),className:"cursor-pointer hover:opacity-60",children:(0,n.jsx)(u.Z,{className:"h-3 w-3"})})]},e)),(0,n.jsx)("input",{value:ev,onChange:e=>ey(e.target.value),onKeyDown:e=>
1{("Enter"===e.key||","===e.key)&&(e.preventDefault(),to())},onBlur:to,placeholder:0===eg.length?"Type and press Enter to add tags...":"Add another...",className:"min-w-[100px] flex-1 bg-transparent outline-none",style:{fontSize:12}})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"mb-1.5 block text-sm font-medium text-text-sub-600",children:"Short Description"}),(0,n.jsx)("textarea",{value:eh,onChange:e=>ef(e.target.value),placeholder:"Brief description...",rows:3,className:"w-full rounded-none bg-bg-white-0 px-4 py-2.5 text-text-sub-600 outline-none",style:{border:"1px solid var(--color-stroke-soft-200)",fontSize:12,resize:"vertical"}})]}),X&&(0,n.jsx)(v.zxk,{onClick:th,disabled:!ep.trim()||el.isPending,className:"mt-4 w-full rounded-none",style:{background:"var(--color-primary-base)",color:"white",fontSize:14,fontWeight:700,padding:"12px"},children:el.isPending?"Creating...":"Create Product"})]}),(0,n.jsxs)(H,{number:2,title:"Define Scope",badge:"Global",expanded:eF,onToggle:()=>eB(e=>!e),disabled:X,children:[(0,n.jsx)(z.O,{draft:eX.draft,error:eX.lastError,isDropped:eJ.isDropped,onToggle:eJ.toggleNode}),tj.length>0?(0,n.jsx)("div",{className:"space-y-2",children:tj.map(e=>(0,n.jsx)("div",{onMouseEnter:()=>eY(e),children:(0,n.jsx)(P.C,{node:e,onClick:()=>e$(e.scope.id),onDelete:()=>ty(e.scope.id),onRename:t=>{!X&&Y?ex.mutate({scopeId:e.scope.id,name:t}):eW(s=>s.map(s=>s.scope.id===e.scope.id?{...s,scope:{...s.scope,name:t}}:s))}})},e.scope.id))}):null,e8&&(0,n.jsxs)("div",{className:"mt-2 flex items-center gap-2 rounded-none bg-bg-white-0 px-4 py-3",style:{border:"1.5px solid var(--color-state-warning-base)"},children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#FCB03A"})}),(0,n.jsx)("input",{ref:ts,value:te,onChange:e=>tt(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),tv()),"Escape"===e.key&&e9(!1)},placeholder:"Scope name...",className:"min-w-0 flex-1 bg-transparent text-text-strong-950 outline-none",style:{fontSize:13,fontWeight:600},autoFocus:!0}),(0,n.jsx)("button",{onClick:tv,disabled:!te.trim(),className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded-none bg-[var(--color-state-success-base)] text-white disabled:opacity-40",children:(0,n.jsx)(x.Z,{className:"h-3.5 w-3.5"})}),(0,n.jsx)("button",{onClick:()=>e9(!1),className:"flex h-6 w-6 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-bg-soft-200",children:(0,n.jsx)(u.Z,{className:"h-3.5 w-3.5"})})]}),(0,n.jsxs)("div",{className:"mt-3 flex items-center gap-3",children:[!e8&&(0,n.jsxs)("button",{onClick:tb,className:"flex cursor-pointer items-center gap-1.5 rounded-none border border-dashed px-3 py-2 text-[var(--color-state-warning-dark)] hover:bg-[var(--color-state-warning-lighter)]",style:{borderColor:"var(--color-state-warning-base)",fontSize:12,fontWeight:600},children:[(0,n.jsx)(i.Z,{className:"h-3.5 w-3.5"}),"Add Scope"]}),(0,n.jsx)(F.P,{excludeIds:new Set(Y?[Y]:[]),onSelect:async e=>{var t;X?eD(t=>{var s;return t.some(t=>t.productId===e.id)?t:[...t,{productId:e.id,title:null!==(s=e.title)&&void 0!==s?s:e.id,qty:1}]}):Y&&await tn.mutateAsync({productId:e.id,qty:1}),G({title:"Product added",description:null!==(t=e.title)&&void 0!==t?t:""})}})]}),(()=>{var e;let t=X?eR.map(e=>({id:e.productId,label:e.title})):(null!==(e=null==J?void 0:J.connectedProductRefs)&&void 0!==e?e:[]).map(e=>{var t,s,n;let a=tr.find(t=>t.id===e.productId);return{id:null!==(t=e.productId)&&void 0!==t?t:"",label:null!==(n=null!==(s=null==a?void 0:a.title)&&void 0!==s?s:e.productId)&&void 0!==n?n:"Unknown"}});return 0===t.length?null:(0,n.jsx)("div",{className:"mt-2 space-y-1.5",children:t.map(e=>(0,n.jsxs)("div",{className:"flex cursor-pointer items-center gap-2 rounded-none bg-bg-white-0 px-3 py-2 transition-colors hover:bg-bg-weak-50",style:{border:"1px solid var(--color-primary-alpha-16)"},onClick:()=>e2(e.id),children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,
1children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#6E3785"})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate text-text-sub-600",style:{fontSize:12,fontWeight:500},children:e.label}),(()=>{var t;let s=null==ei?void 0:null===(t=ei.connectedProducts)||void 0===t?void 0:t.find(t=>t.productId===e.id);return!s||s.totalEstimatedPrice<=0?null:(0,n.jsxs)("span",{className:"shrink-0 tabular-nums",style:{fontSize:12,fontWeight:600,color:"var(--color-text-strong-950)"},children:["$",s.totalEstimatedPrice.toLocaleString()]})})(),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),X?eD(t=>t.filter(t=>t.productId!==e.id)):ta.mutate(e.id)},className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-state-error-lighter hover:text-state-error",children:(0,n.jsx)(c.Z,{className:"h-3.5 w-3.5"})}),(0,n.jsx)(m.Z,{className:"h-3.5 w-3.5 shrink-0 text-text-disabled-300"})]},e.id))})})(),(0,n.jsxs)("div",{className:"mt-4 flex items-start gap-2 rounded-none px-4 py-3",style:{background:"var(--color-state-warning-lighter)",border:"1px solid var(--color-state-warning-lighter)"},children:[(0,n.jsx)(g.Z,{className:"mt-0.5 h-3.5 w-3.5 shrink-0",style:{color:"var(--color-state-warning-dark)"}}),(0,n.jsx)("p",{style:{fontSize:11,color:"var(--color-state-warning-dark)",lineHeight:"16px"},children:"Global scopes are inherited by all variants. You can add variant-specific scopes in Step 3."})]}),!X&&ei&&(0,n.jsxs)("div",{className:"mt-4 flex items-center justify-between rounded-none px-4 py-3",style:{background:"var(--color-bg-weak-50)",border:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"block text-text-soft-400",style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Total Estimated"}),(0,n.jsx)("span",{className:"tabular-nums",style:{fontSize:15,fontWeight:700,color:"var(--color-text-strong-950)"},children:ei.totalEstimatedPrice>0?"$".concat(ei.totalEstimatedPrice.toLocaleString()):"—"})]}),tN>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"block text-text-soft-400",style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Total Allowance"}),(0,n.jsxs)("span",{className:"tabular-nums",style:{fontSize:15,fontWeight:700,color:"var(--color-text-strong-950)"},children:["$",tN.toLocaleString()]})]})]}),tN>0&&(0,n.jsxs)("span",{className:"rounded-none px-2.5 py-1 tabular-nums",style:{fontSize:11,fontWeight:700,background:ei.totalEstimatedPrice<=tN?"var(--color-state-success-lighter)":"var(--color-state-error-lighter)",color:ei.totalEstimatedPrice<=tN?"var(--color-state-success-dark)":"var(--color-state-error-dark)"},children:[ei.totalEstimatedPrice<=tN?"Under":"Over"," budget"]})]})]}),(0,n.jsxs)(H,{number:3,title:"Variants Configuration",subtitle:"Variables, rules, and generated variants",expanded:eL,onToggle:()=>eU(e=>!e),disabled:X,headerRight:(0,n.jsxs)("button",{onClick:tc,className:"flex cursor-pointer items-center gap-1 text-[var(--color-primary-base)] hover:underline",style:{fontSize:12,fontWeight:600},children:[(0,n.jsx)(i.Z,{className:"h-3 w-3"}),"Add Variable"]}),children:[eI.length>0&&(0,n.jsx)("div",{className:"space-y-4",children:eI.map(e=>(0,n.jsx)($,{variable:e,onUpdate:(t,s)=>td(e.id,t,s),onRemove:()=>tu(e.id),allVariables:eI,rules:e_.filter(t=>t.ifVariableId===e.id),onAddRule:()=>tx(e.id),onUpdateRule:tp,onRemoveRule:tm},e.id))}),1===eI.length&&(0,n.jsx)("div",{className:"mt-4 rounded-none px-4 py-3",style:{background:"var(--color-state-warning-lighter)",border:"1px solid var(--color-state-warning-lighter)"},children:(0,n.jsx)("p",{style:{fontSize:11,color:"var(--color-state-warning-dark)"},children:"Add at least two variables to create configuration rules between them."})}),(tz.length>0||tI.length>0)&&(0,n.jsxs)("div",{className:"mt-6 border-t border-dashed border-stroke-soft-200 pt-5",children:[(0,n.jsx)("div",{className:"mb-3 flex items-center justify-between",children:(0,n.jsxs)("p",{style:{fontSize:14,fontWeight:700},children:["Generated Variants"," ",(0,n.jsxs)("span",{className:"text-text-soft-400",style:{fontWeight:400},children:["\xb7 ",tz.length," variant",1!==tz.length?"s":""]})]})}),!X&&eO.size>0&&(0,n.jsxs)("div",{className:"mb-3 flex items-center gap-3 rounded-none px-4 py-2.5",style:{background:"var(--color-bg-weak-50)",border:"1.5px solid var(--color-primary-alpha-16)"},children:[(0,n.jsxs)("span",{style:{fontSize:12,fontWeight:700,color:"var(--color-state-warning-dark)"},children:[eO.size," selected"]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{onClick:()=>eV(new Set),className:"cursor-pointer text-text-soft-400 hover:text-text-sub-600",
1style:{fontSize:11,fontWeight:600},children:"Clear selection"})]}),(0,n.jsx)("div",{className:"overflow-hidden rounded-none",style:{border:"1px solid var(--color-stroke-soft-200)"},children:X?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"bg-bg-white-0 px-4 py-2.5",style:{borderBottom:"1px solid var(--color-stroke-soft-200)"},children:(0,n.jsx)("span",{className:"text-text-sub-600",style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Variant Name"})}),tz.map((e,t)=>(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2.5",style:{borderBottom:t<tz.length-1?"1px solid var(--color-stroke-soft-200)":"none"},children:[(0,n.jsx)("span",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-none tabular-nums",style:{background:"var(--color-primary-alpha-10)",color:"var(--color-primary-base)",fontSize:9,fontWeight:700},children:t+1}),(0,n.jsx)("span",{className:"truncate text-text-sub-600",style:{fontSize:12,fontWeight:500},children:e.name})]},e.id))]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid items-center gap-3 bg-bg-white-0 px-4 py-2.5",style:{gridTemplateColumns:"28px 28px 1fr 80px 80px",borderBottom:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsx)("div",{children:(0,n.jsx)("input",{type:"checkbox",checked:eO.size===tw.length&&tw.length>0,onChange:()=>{eO.size===tw.length?eV(new Set):eV(new Set(tw.map(e=>e.id)))},className:"h-3.5 w-3.5 cursor-pointer accent-[var(--color-primary-base)]"})}),(0,n.jsx)("div",{}),(0,n.jsx)("span",{className:"text-text-sub-600",style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Variant Name"}),(0,n.jsx)("span",{className:"text-text-sub-600",style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Scopes"}),(0,n.jsx)("span",{className:"text-text-sub-600",style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Products"})]}),tw.map((e,t)=>{var s,a;let r=eO.has(e.id),l=tj.length,o=(null!==(a=null==J?void 0:null===(s=J.connectedProductRefs)||void 0===s?void 0:s.length)&&void 0!==a?a:0)+e.connectedProductRefs.length;return(0,n.jsxs)("div",{className:"grid cursor-pointer items-center gap-3 px-4 py-2.5 transition-colors hover:bg-bg-weak-50",style:{gridTemplateColumns:"28px 28px 1fr 80px 80px",borderBottom:t<tw.length-1?"1px solid var(--color-stroke-soft-200)":"none",background:r?"var(--color-primary-alpha-10)":void 0},onClick:()=>tg(e),children:[(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),children:(0,n.jsx)("input",{type:"checkbox",checked:r,onChange:()=>{eV(t=>{let s=new Set(t);return s.has(e.id)?s.delete(e.id):s.add(e.id),s})},className:"h-3.5 w-3.5 cursor-pointer accent-[var(--color-primary-base)]"})}),(0,n.jsx)("span",{className:"flex h-5 w-5 items-center justify-center rounded-none tabular-nums",style:{background:"var(--color-primary-alpha-10)",color:"var(--color-primary-base)",fontSize:9,fontWeight:700},children:t+1}),(0,n.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5",children:[(0,n.jsx)("span",{className:"truncate rounded-none bg-bg-soft-200 px-2 py-0.5",style:{fontSize:12,fontWeight:500},children:e.name}),(0,n.jsx)(C.f,{attributes:e.attributes,variables:eI})]}),(0,n.jsx)("span",{className:"rounded-none px-2 py-0.5",style:{background:l>0?"var(--color-state-success-lighter)":"var(--color-bg-soft-200)",color:l>0?"var(--color-state-success-dark)":"var(--color-text-soft-400)",fontSize:11,fontWeight:600,textAlign:"center"},children:l>0?"".concat(l," scope").concat(1!==l?"s":""):"No scopes"}),(0,n.jsx)("span",{className:"rounded-none px-2 py-0.5",style:{background:o>0?"var(--color-primary-alpha-10)":"var(--color-bg-soft-200)",color:o>0?"var(--color-primary-base)":"var(--color-text-soft-400)",fontSize:11,fontWeight:600,textAlign:"center"},children:o>0?"".concat(o," product").concat(1!==o?"s":""):"None"})]},e.id)}),tI.length>0&&(0,n.jsxs)("div",{style:{borderTop:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-4 py-2",children:[(0,n.jsxs)("button",{type:"button","data-testid":"uncreated-combinations-toggle",onClick:()=>t_(e=>!e),className:"text-text-sub-600 underline-offset-2 hover:underline",style:{fontSize:11,fontWeight:600},children:[tP?"Hide":"Show"," — ",tI.length," more combination",1===tI.length?"":"s"," possible — not created"]}),(0,n.jsx)(I.C,{content:"Combinations of this product's variables that no variant uses yet. Click one to create it.",children:(0,n.jsx)(g.Z,{className:"h-3 w-3 text-text-soft-400",tabIndex:0,"aria-label":"Combinations not created"})})]}),tP&&tI.map(e=>(0,n.jsxs)("div",{"data-testid":"uncreated-combination-row",className:"grid cursor-pointer items-center gap-3 px-4 py-2.5 transition-colors hover:bg-bg-weak-50",style:{gridTemplateColumns:"28px 28px 1fr 80px 80px"},onClick:()=>tg(e),children:[(0,n.jsx)("div",{}),(0,n.jsx)("div",{}),(0,n.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5",children:[(0,n.jsx)("span",{className:"truncate rounded-none bg-bg-soft-200 px-2 py-0.5 text-text-soft-400",style:{fontSize:12,fontWeight:500},children:e.name}),(0,n.jsx)(C.f,{attributes:e.attributes,variables:eI}),(0,n.jsx)("span",{className:"shrink-0 rounded-none px-2 py-0.5 text-text-soft-400",style:{background:"var(--color-bg-soft-200)",fontSize:11,fontWeight:500},children:"not created"})]}),(0,n.jsx)("div",{}),(0,n.jsx)("div",{})]},e.id))]})]})})]})]})]})}),(0,n.jsx)(_.n,{instance:eX,productId:Y,hoveredScope:eG,commitMessage:eJ.commitMessage,canCommit:eJ.canCommit,fabIngest:e0,onDropFabPackage:e1})]}),eH&&(()=>{var e;let t=tj.find(e=>e.scope.id===eH);return t?(0,n.jsx)("div",{onClick:()=>e$(null),className:"fixed inset-0 z-50 flex items-center justify-center p-6",style:{background:"rgba(0,0,0,0.4)"},children:(0,n.jsxs)(b.E.div,{initial:{opacity:0,scale:.96}
1,animate:{opacity:1,scale:1},exit:{opacity:0,scale:.96},transition:{type:"spring",damping:30,stiffness:300},onClick:e=>e.stopPropagation(),className:"flex max-h-[85vh] w-full max-w-3xl flex-col overflow-hidden bg-bg-white-0",style:{border:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-6 py-5",style:{borderBottom:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#FCB03A"})}),(0,n.jsx)("h3",{className:"min-w-0 flex-1 truncate",style:{fontSize:16,fontWeight:700},children:null!==(e=t.scope.name)&&void 0!==e?e:"Scope"}),(0,n.jsx)("button",{onClick:()=>e$(null),className:"flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-bg-soft-200 hover:text-text-sub-600",title:"Close",children:(0,n.jsx)(u.Z,{className:"h-4 w-4"})})]}),(0,n.jsx)(Q,{node:t,productId:null!=Y?Y:"",allProducts:tr,onRefresh:()=>M.invalidateQueries({queryKey:["catalog","product-scopes",Y]})})]})}):null})(),eK&&Y&&(0,n.jsx)(Z.g,{productId:Y,variantId:eK,allVariants:tw.map(e=>({id:e.id,name:e.name,attributes:e.attributes,tags:e.tags,externalCode:e.externalCode})),onClose:()=>eM(null)}),e5&&(0,n.jsx)(et,{productId:e5,allProducts:tr,onClose:()=>e2(null)})]})}):(0,n.jsxs)("div",{className:"flex h-64 flex-col items-center justify-center gap-3",children:[(0,n.jsx)("p",{className:"text-sm text-text-soft-400",children:"Product not found"}),(0,n.jsx)(v.zxk,{variant:"outline",className:"rounded-none",onClick:()=>q.push("/catalog/library"),children:"Back to Library"})]}):(0,n.jsx)("div",{className:"flex h-64 items-center justify-center",children:(0,n.jsx)(f.Z,{className:"h-5 w-5 animate-spin text-text-soft-400"})})}function H(e){let{number:t,title:s,subtitle:a,badge:r,expanded:l,onToggle:o,complete:i,headerRight:c,disabled:d,children:u}=e;return(0,n.jsxs)("div",{className:"rounded-none bg-bg-white-0 ".concat(d?"pointer-events-none opacity-50":""),style:{border:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsxs)("button",{type:"button",onClick:d?void 0:o,className:"flex w-full items-center gap-3 px-6 py-4",children:[i?(0,n.jsx)("div",{className:"flex h-6 w-6 items-center justify-center rounded-none",style:{background:"var(--color-state-success-base)"},children:(0,n.jsx)("svg",{viewBox:"0 0 16 16",className:"h-3.5 w-3.5 text-white",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"3.5 8 7 11 12.5 5"})})}):(0,n.jsx)("span",{className:"flex h-6 w-6 items-center justify-center rounded-none tabular-nums",style:{background:"var(--color-primary-base)",color:"white",fontSize:11,fontWeight:700},children:t}),(0,n.jsxs)("div",{className:"min-w-0 flex-1 text-left",children:[(0,n.jsx)("span",{style:{fontSize:14,fontWeight:700,color:"var(--color-text-strong-950)"},children:s}),r&&(0,n.jsx)("span",{className:"ml-2 rounded-none px-2 py-0.5",style:{background:"var(--color-state-success-lighter)",color:"var(--color-state-success-base)",fontSize:10,fontWeight:700,border:"1px solid var(--color-state-success-light)"},children:r}),a&&(0,n.jsx)("p",{className:"text-text-soft-400",style:{fontSize:11},children:a})]}),c&&(0,n.jsx)("div",{onClick:e=>e.stopPropagation(),children:c}),(0,n.jsx)(h.Z,{className:"h-4 w-4 text-text-soft-400 transition-transform",style:{transform:l?"rotate(0deg)":"rotate(180deg)"}})]}),l&&!d&&(0,n.jsx)("div",{className:"px-6 pb-5",children:u})]})}function $(e){let{variable:t,onUpdate:s,onRemove:r,allVariables:l,rules:o,onAddRule:d,onUpdateRule:x,onRemoveRule:p}=e,[m,h]=(0,a.useState)(""),f=t.options.split(",").map(e=>e.trim()).filter(Boolean),g=()=>{let e=m.trim();!e||f.includes(e)||(s("options",[...f,e].join(", ")),h(""))},b=e=>{s("options",f.filter(t=>t!==e).join(", "))};return(0,n.jsxs)("div",{className:"rounded-none",style:{border:"1px solid var(--color-stroke-soft-200)",padding:"16px"},children:[(0,n.jsxs)("div",{className:"mb-3 flex items-center gap-2",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,
1children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#5D2F70"})}),(0,n.jsx)("input",{value:t.name,onChange:e=>s("name",e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.currentTarget.blur())},placeholder:"Type variable name and press Enter...",className:"min-w-0 flex-1 rounded-none px-2 py-1 text-text-strong-950 outline-none transition-colors ".concat(t.name.trim()?"bg-transparent":"bg-bg-weak-50"),style:{fontSize:14,fontWeight:700,border:t.name.trim()?"none":"1px dashed var(--color-stroke-sub-300)"}}),(0,n.jsxs)("span",{className:"text-text-soft-400",style:{fontSize:11},children:[f.length," option",1!==f.length?"s":""]}),(0,n.jsx)("button",{onClick:r,className:"cursor-pointer text-text-soft-400 hover:text-state-error",children:(0,n.jsx)(c.Z,{className:"h-3.5 w-3.5"})})]}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[f.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-none border px-2.5 py-1",style:{background:"var(--color-bg-white-0)",borderColor:"var(--color-stroke-soft-200)",fontSize:12,fontWeight:500},children:[e,(0,n.jsx)("button",{onClick:()=>b(e),className:"cursor-pointer hover:opacity-60",children:(0,n.jsx)(u.Z,{className:"h-2.5 w-2.5 text-text-soft-400"})})]},e)),(0,n.jsx)("input",{value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{("Enter"===e.key||","===e.key)&&(e.preventDefault(),g())},onBlur:g,placeholder:0===f.length?"Type and press Enter to add values...":"Add another...",className:"min-w-[80px] bg-transparent text-text-sub-600 outline-none",style:{fontSize:12}})]}),o.length>0&&(0,n.jsxs)("div",{className:"mt-4",children:[(0,n.jsxs)("p",{className:"mb-2 flex items-center gap-1 text-text-sub-600",style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Rules for ",t.name]}),o.map(e=>{var s;let a=l.find(t=>t.id===e.thenVariableId),r=null!==(s=null==a?void 0:a.options.split(",").map(e=>e.trim()).filter(Boolean))&&void 0!==s?s:[];return(0,n.jsxs)("div",{className:"mb-2 rounded-none bg-bg-weak-50 px-3 py-2",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[(0,n.jsx)("span",{className:"rounded-none bg-[var(--color-state-warning-dark)] px-1.5 py-0.5 text-white",style:{fontSize:9,fontWeight:700},children:"IF"}),(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600},children:t.name}),(0,n.jsx)("span",{className:"text-text-soft-400",style:{fontSize:11},children:"="}),(0,n.jsxs)("select",{value:e.ifValue,onChange:t=>x(e.id,{ifValue:t.target.value}),className:"rounded-none border bg-bg-white-0 px-2 py-0.5",style:{fontSize:11},children:[(0,n.jsx)("option",{value:"",children:"Select..."}),f.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]}),(0,n.jsx)("button",{onClick:()=>p(e.id),className:"ml-auto cursor-pointer text-text-soft-400 hover:text-state-error",children:(0,n.jsx)(c.Z,{className:"h-3 w-3"})})]}),(0,n.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[(0,n.jsx)("span",{className:"rounded-none bg-[var(--color-primary-base)] px-1.5 py-0.5 text-white",style:{fontSize:9,fontWeight:700},children:"THEN"}),(0,n.jsx)("select",{value:e.thenVariableId,onChange:t=>x(e.id,{thenVariableId:t.target.value,thenAllowedValues:[]}),className:"rounded-none border bg-bg-white-0 px-2 py-0.5",style:{fontSize:11},children:l.filter(e=>e.id!==t.id).map(e=>(0,n.jsx)("option",{value:e.id,children:e.name||"(unnamed)"},e.id))}),(0,n.jsx)("span",{className:"text-text-soft-400",style:{fontSize:11},children:"allows"}),r.map(t=>{let s=e.thenAllowedValues.includes(t);return(0,n.jsxs)("button",{onClick:()=>{let n=s?e.thenAllowedValues.filter(e=>e!==t):[...e.thenAllowedValues,t];x(e.id,{thenAllowedValues:n})},className:"cursor-pointer rounded-none border px-2 py-0.5",style:{background:s?"var(--color-primary-alpha-10)":"var(--color-bg-white-0)",borderColor:s?"var(--color-primary-base)":"var(--color-stroke-soft-200)",color:s?"var(--color-primary-base)":"var(--color-text-soft-400)",fontSize:11,fontWeight:s?600:400},children:[s&&"✓ ",t]},t)})]}),e.ifValue&&(0,n.jsx)("p",{className:"mt-1.5 rounded-none px-2 py-1",style:{background:e.thenAllowedValues.length>0?"var(--color-state-success-lighter)":"var(--color-state-error-lighter)",color:e.thenAllowedValues.length>0?"var(--color-state-success-dark)":"var(--color-state-error-dark)",fontSize:10,fontWeight:500},children:e.thenAllowedValues.length>0?(0,n.jsxs)(n.Fragment,{children:["When ",(0,n.jsx)("b",{children:t.name})," is ",(0,n.jsx)("b",{children:e.ifValue}),", ",(0,n.jsx)("b",{children:null==a?void 0:a.name})," is limited to: ",(0,n.jsx)("b",{children:e.thenAllowedValues.join(", ")})]}):(0,n.jsxs)(n.Fragment,{children:["When ",(0,n.jsx)("b",{children:t.name})," is ",(0,n.jsx)("b",{children:e.ifValue}),", no variants are allowed"]})})]},e.id)})]}),(0,n.jsxs)("button",{onClick:d,className:"mt-2 flex cursor-pointer items-center gap-1 text-[var(--color-primary-base)] hover:underline",style:{fontSize:11,fontWeight:600},children:[(0,n.jsx)(i.Z,{className:"h-3 w-3"})," Add Rule"]})]})}function G(e){let{index:t,isLast:s,children:a}=e;return(0,n.jsxs)("div",{className:"flex gap-3",children:[(0,n.jsxs)("div",{className:"relative w-6 shrink-0",children:[t>0&&(0,n.jsx)("div",{className:"absolute left-1/2 top-0 w-px -translate-x-1/2",style:{height:18,background:"var(--color-stroke-soft-200)"}}),!s&&(0,n.jsx)("div",{className:"absolute bottom-0 left-1/2 w-px -translate-x-1/2",style:{to
1p:18,background:"var(--color-stroke-soft-200)"}}),(0,n.jsx)("div",{className:"absolute left-1/2 z-10 flex h-6 w-6 -translate-x-1/2 items-center justify-center rounded-none bg-bg-white-0 tabular-nums",style:{top:6,border:"1.5px solid var(--color-primary-alpha-16)",color:"var(--color-primary-base)",fontSize:11,fontWeight:700},children:t+1})]}),(0,n.jsx)("div",{className:"min-w-0 flex-1 ".concat(s?"":"pb-2"),children:a})]})}function Y(e){var t,s,r;let{node:l,productId:o,allProducts:c,onRefresh:d,api:p}=e,{toast:m}=(0,y.pm)(),h=null!=p?p:{addRequirement:(e,t)=>w.addProductScopeRequirement(o,e,t),updateRequirement:(e,t,s)=>w.updateProductScopeRequirement(o,e,t,s),deleteRequirement:(e,t)=>w.deleteProductScopeRequirement(o,e,t),deleteScope:e=>w.deleteProductScope(o,e),updateScope:(e,t)=>w.updateProductScope(o,e,t)},[f,g]=(0,a.useState)(()=>{var e;return null!==(s=null===(e=(0,k.C6)(l))||void 0===e?void 0:e.set.id)&&void 0!==s?s:null}),[b,v]=(0,a.useState)(!1),[j,N]=(0,a.useState)(""),[S,C]=(0,a.useState)(!1),[I,P]=(0,a.useState)(""),_=l.scope.id,z=null!==(r=null===(t=l.solutionSets.find(e=>e.set.id===f))||void 0===t?void 0:t.requirements)&&void 0!==r?r:[],A=async()=>{let e=j.trim();if(e&&f)try{await h.addRequirement(_,{name:e,qty:1,uom:"EA",rate:0,solutionSetId:f}),d(),N(""),v(!1)}catch(e){m({title:"Failed to add solution",variant:"destructive"})}},W=async()=>{let e=I.trim();if(e)try{await w.addSubScope(_,{name:e,requirements:[],connectedProductRefs:[]}),d(),P(""),C(!1)}catch(e){m({title:"Failed to add scope",variant:"destructive"})}},R=async e=>{try{await w.addScopeConnectedProduct(_,{productId:e.id,qty:1}),d()}catch(e){m({title:"Failed to add product",variant:"destructive"})}};return(0,n.jsxs)("div",{className:"space-y-5",children:[l.scope.tags&&l.scope.tags.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap gap-1.5",children:l.scope.tags.map(e=>(0,n.jsx)("span",{className:"rounded-none px-2.5 py-1",style:{background:"var(--color-bg-soft-200)",fontSize:11,fontWeight:500,color:"var(--color-text-sub-600)"},children:e},e))}),(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Options Package"}),(0,n.jsx)(q.x,{node:l,activeSetId:f,onSelectSet:g,productId:o}),l.solutionSets.length>0&&z.length>0&&f&&(0,n.jsx)("div",{children:(0,n.jsx)(E.v,{scopeId:_,solutionSetId:f,requirements:z,onRefresh:d,renderRow:(e,t,s)=>(0,n.jsx)(G,{index:t,isLast:s,children:(0,n.jsx)(T.z,{requirement:e,onUpdate:async t=>{try{await h.updateRequirement(_,e.id,t),d()}catch(e){d(),m({title:"Failed to update solution",variant:"destructive"})}},onDelete:async()=>{try{await h.deleteRequirement(_,e.id),d()}catch(e){m({title:"Failed to delete solution",variant:"destructive"})}}})})})})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Scopes (",l.childScopes.length,")"]}),l.childScopes.length>0&&(0,n.jsx)("div",{children:l.childScopes.map((e,t)=>(0,n.jsx)(G,{index:t,isLast:t===l.childScopes.length-1,children:(0,n.jsx)(X,{node:e,productId:o,allProducts:c,onRefresh:d,api:p,onDelete:async()=>{try{await h.deleteScope(e.scope.id),d()}catch(e){m({title:"Failed to delete scope",variant:"destructive"})}},onRename:async t=>{try{await h.updateScope(e.scope.id,{name:t}),d()}catch(e){m({title:"Failed to rename scope",variant:"destructive"})}}})},e.scope.id))})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Connected Products (",l.scope.connectedProductRefs.length,")"]}),l.scope.connectedProductRefs.length>0&&(0,n.jsx)("div",{children:l.scope.connectedProductRefs.map((e,t)=>{var s,a,r;let o=c.find(t=>t.id===e.productId);return(0,n.jsx)(G,{index:t,isLast:t===l.scope.connectedProductRefs.length-1,children:(0,n.jsx)(J,{productId:null!==(s=e.productId)&&void 0!==s?s:"",name:null!==(r=null!==(a=null==o?void 0:o.title)&&void 0!==a?a:e.productId)&&void 0!==r?r:"Product",allProducts:c,onRemove:async()=>
1{if(e.productId)try{await w.removeScopeConnectedProduct(_,e.productId),d()}catch(e){m({title:"Failed to remove product",variant:"destructive"})}}})},e.productId)})})]}),(0,n.jsxs)("div",{className:"flex items-stretch gap-2",children:[b?(0,n.jsxs)("div",{className:"flex flex-1 items-center gap-2 rounded-none bg-bg-white-0 px-3 py-2",style:{border:"1px solid var(--color-state-success-light)"},children:[(0,n.jsx)("input",{value:j,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),A()),"Escape"===e.key&&(N(""),v(!1))},placeholder:"Solution name...",className:"min-w-0 flex-1 bg-transparent text-text-strong-950 outline-none",style:{fontSize:12,fontWeight:600},autoFocus:!0}),(0,n.jsx)("button",{onClick:A,disabled:!j.trim(),className:"flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded-none bg-[var(--color-state-success-base)] text-white disabled:opacity-40",children:(0,n.jsx)(x.Z,{className:"h-3 w-3"})}),(0,n.jsx)("button",{onClick:()=>{N(""),v(!1)},className:"flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-bg-soft-200",children:(0,n.jsx)(u.Z,{className:"h-3 w-3"})})]}):(0,n.jsxs)("button",{onClick:()=>{v(!0),N("")},disabled:0===l.solutionSets.length,title:0===l.solutionSets.length?"Add an options package first":void 0,className:"flex flex-1 items-center justify-center gap-1.5 rounded-none border border-dashed py-2.5 text-text-sub-600 hover:bg-bg-white-0 hover:text-text-sub-600 disabled:cursor-not-allowed disabled:opacity-40",style:{borderColor:"var(--color-stroke-sub-300)",fontSize:12,fontWeight:600},children:[(0,n.jsx)(i.Z,{className:"h-3.5 w-3.5"})," Add Solution"]}),S?(0,n.jsxs)("div",{className:"flex flex-1 items-center gap-2 rounded-none px-3 py-2",style:{border:"1.5px dashed var(--color-state-warning-base)",background:"var(--color-state-warning-lighter)"},children:[(0,n.jsx)("input",{value:I,onChange:e=>P(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),W()),"Escape"===e.key&&(P(""),C(!1))},placeholder:"Scope name...",className:"min-w-0 flex-1 bg-transparent text-text-sub-600 outline-none",style:{fontSize:13},autoFocus:!0}),(0,n.jsx)("button",{onClick:W,disabled:!I.trim(),className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none bg-[var(--color-state-warning-base)] text-white disabled:opacity-40",children:(0,n.jsx)(x.Z,{className:"h-3 w-3"})}),(0,n.jsx)("button",{onClick:()=>{P(""),C(!1)},className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-bg-soft-200",children:(0,n.jsx)(u.Z,{className:"h-3 w-3"})})]}):(0,n.jsxs)("button",{onClick:()=>{C(!0),P("")},className:"flex flex-1 items-center justify-center gap-1.5 rounded-none border border-dashed py-2.5",style:{borderColor:"var(--color-state-warning-base)",color:"var(--color-state-warning-dark)",fontSize:12,fontWeight:600},children:[(0,n.jsx)(i.Z,{className:"h-3.5 w-3.5"})," Add Scope"]}),(0,n.jsx)("div",{className:"flex flex-1",children:(0,n.jsx)(F.P,{fullWidth:!0,onSelect:R})})]})]})}function Q(e){let{node:t,productId:s,allProducts:a,onRefresh:r}=e;return(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5",style:{background:"var(--color-bg-weak-50)"},children:(0,n.jsx)(Y,{node:t,productId:s,allProducts:a,onRefresh:r})})}function X(e){var t,s;let{node:r,productId:l,allProducts:o,onRefresh:i,onDelete:u,onRename:x,api:m}=e,[h,f]=(0,a.useState)(!1),g=r.scope,b=(0,k.$3)(r),v=(0,k.ik)(r),[y,j]=(0,a.useState)(!1),[N,w]=(0,a.useState)(null!==(t=g.name)&&void 0!==t?t:""),S=(0,a.useRef)(null);(0,a.useEffect)(()=>{var e;w(null!==(e=g.name)&&void 0!==e?e:"")},[g.name]),(0,a.useEffect)(()=>{var e;y&&(null===(e=S.current)||void 0===e||e.focus())},[y]);let C=()=>{let e=N.trim();e&&e!==g.name&&(null==x||x(e)),j(!1)};return(0,n.jsxs)("div",{className:"overflow-hidden rounded-none bg-bg-white-0",style:{border:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsxs)("div",{className:"flex cursor-pointer items-center gap-3 px-4 py-3 hover:bg-bg-weak-50",onClick:y?void 0:()=>f(e=>!e),children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,
1children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#FCB03A"})}),y?(0,n.jsx)("input",{ref:S,value:N,onClick:e=>e.stopPropagation(),onChange:e=>w(e.target.value),onBlur:C,onKeyDown:e=>{if("Enter"===e.key&&(e.preventDefault(),C()),"Escape"===e.key){var t;w(null!==(t=g.name)&&void 0!==t?t:""),j(!1)}},className:"min-w-0 flex-1 rounded-none border border-stroke-soft-200 bg-bg-white-0 px-2 py-1 text-[13px] font-semibold text-text-strong-950 outline-none focus:ring-1 focus:ring-[var(--color-primary-base)]"}):(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",style:{fontSize:13,fontWeight:600,color:"var(--color-text-strong-950)"},children:null!==(s=g.name)&&void 0!==s?s:"Untitled scope"}),!y&&b>0&&(0,n.jsxs)("span",{className:"shrink-0 rounded-none px-1.5 py-0.5 tabular-nums",style:{background:"var(--color-bg-soft-200)",fontSize:"calc(11px * var(--font-scale, 1))",fontWeight:600,color:"var(--color-text-sub-600)"},children:["Est. $",b.toLocaleString()]}),!y&&v>0&&(0,n.jsxs)("span",{className:"shrink-0 rounded-none px-1.5 py-0.5 tabular-nums",style:{background:"var(--color-state-success-lighter)",fontSize:"calc(11px * var(--font-scale, 1))",fontWeight:600,color:"var(--color-state-success-dark)"},children:["Allowance $",v.toLocaleString()]}),x&&!y&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),j(!0)},className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-bg-soft-200 hover:text-text-sub-600",title:"Rename scope",children:(0,n.jsx)(d.Z,{className:"h-3 w-3"})}),!y&&(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),u()},className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-state-error-lighter hover:text-state-error",title:"Delete scope",children:(0,n.jsx)(c.Z,{className:"h-3.5 w-3.5"})}),!y&&(0,n.jsx)(p.Z,{className:"h-4 w-4 shrink-0 text-text-soft-400 transition-transform ".concat(h?"rotate-180":"")})]}),h&&(0,n.jsx)("div",{className:"px-4 py-4",style:{borderTop:"1px solid var(--color-stroke-soft-200)",background:"var(--color-bg-white-0)"},children:(0,n.jsx)(Y,{node:r,productId:l,allProducts:o,onRefresh:i,api:m})})]})}function J(e){let{productId:t,name:s,allProducts:r,onRemove:l}=e,[o,i]=(0,a.useState)(!1);return(0,n.jsxs)("div",{className:"overflow-hidden rounded-none bg-bg-white-0",style:{border:"1px solid var(--color-primary-alpha-16)"},children:[(0,n.jsxs)("div",{className:"flex cursor-pointer items-center gap-2 px-3 py-2.5 hover:bg-bg-weak-50",onClick:()=>i(e=>!e),children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#6E3785"})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate text-text-sub-600",style:{fontSize:12,fontWeight:500},children:s}),(0,n.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-state-error-lighter hover:text-state-error",title:"Remove product",children:(0,n.jsx)(c.Z,{className:"h-3 w-3"})}),(0,n.jsx)(p.Z,{className:"h-4 w-4 shrink-0 text-text-soft-400 transition-transform ".concat(o?"rotate-180":"")})]}),o&&t&&(0,n.jsx)("div",{className:"px-4 py-4",style:{borderTop:"1px solid var(--color-stroke-soft-200)",background:"var(--color-bg-white-0)"},children:(0,n.jsx)(ee,{productId:t,allProducts:r})})]})}function ee(e){var t;let{productId:s,allProducts:l}=e,o=(0,r.NL)(),{toast:c}=(0,y.pm)(),{data:d=[]}=(0,N.Xh)(s),{data:p}=(0,N.Ir)(s),[m,h]=(0,a.useState)(!1),[f,g]=(0,a.useState)(""),b=null!==(t=null==p?void 0:p.connectedProductRefs)&&void 0!==t?t:[],v=()=>{o.invalidateQueries({queryKey:["catalog","product-scopes",s]}),o.invalidateQueries({queryKey:["catalog","product-detail",s]})},j=async()=>{let e=f.trim();if(e)try{await w.addProductScope(s,{name:e,requirements:[],connectedProductRefs:[]}),v(),g(""),h(!1)}catch(e){c({title:"Failed to add scope",variant:"destructive"})}},k=async e=>{try{await w.addConnectedProduct(s,{productId:e.id,qty:1}),v()}catch(e){c({title:"Failed to add product",variant:"destructive"})}};return(0,n.jsxs)("div",{className:"space-y-5",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("span",{className:"mb-2 block text-text-sub-600",
1style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Scopes (",d.length,")"]}),d.length>0&&(0,n.jsx)("div",{children:d.map((e,t)=>(0,n.jsx)(G,{index:t,isLast:t===d.length-1,children:(0,n.jsx)(X,{node:e,productId:s,allProducts:l,onRefresh:v,onDelete:async()=>{try{await w.deleteProductScope(s,e.scope.id),v()}catch(e){c({title:"Failed to delete scope",variant:"destructive"})}},onRename:async t=>{try{await w.updateProductScope(s,e.scope.id,{name:t}),v()}catch(e){c({title:"Failed to rename scope",variant:"destructive"})}}})},e.scope.id))})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Connected Products (",b.length,")"]}),b.length>0&&(0,n.jsx)("div",{children:b.map((e,t)=>{var a,r,o;let i=l.find(t=>t.id===e.productId);return(0,n.jsx)(G,{index:t,isLast:t===b.length-1,children:(0,n.jsx)(J,{productId:null!==(a=e.productId)&&void 0!==a?a:"",name:null!==(o=null!==(r=null==i?void 0:i.title)&&void 0!==r?r:e.productId)&&void 0!==o?o:"Product",allProducts:l,onRemove:async()=>{if(e.productId)try{await w.removeConnectedProduct(s,e.productId),v()}catch(e){c({title:"Failed to remove product",variant:"destructive"})}}})},e.productId)})})]}),(0,n.jsxs)("div",{className:"flex items-stretch gap-2",children:[m?(0,n.jsxs)("div",{className:"flex flex-1 items-center gap-2 rounded-none px-3 py-2",style:{border:"1.5px dashed var(--color-state-warning-base)",background:"var(--color-state-warning-lighter)"},children:[(0,n.jsx)("input",{value:f,onChange:e=>g(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),j()),"Escape"===e.key&&(g(""),h(!1))},placeholder:"Scope name...",className:"min-w-0 flex-1 bg-transparent text-text-sub-600 outline-none",style:{fontSize:13},autoFocus:!0}),(0,n.jsx)("button",{onClick:j,disabled:!f.trim(),className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none bg-[var(--color-state-warning-base)] text-white disabled:opacity-40",children:(0,n.jsx)(x.Z,{className:"h-3 w-3"})}),(0,n.jsx)("button",{onClick:()=>{g(""),h(!1)},className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-bg-soft-200",children:(0,n.jsx)(u.Z,{className:"h-3 w-3"})})]}):(0,n.jsxs)("button",{onClick:()=>{h(!0),g("")},className:"flex flex-1 items-center justify-center gap-1.5 rounded-none border border-dashed py-2.5",style:{borderColor:"var(--color-state-warning-base)",color:"var(--color-state-warning-dark)",fontSize:12,fontWeight:600},children:[(0,n.jsx)(i.Z,{className:"h-3.5 w-3.5"})," Add Scope"]}),(0,n.jsx)("div",{className:"flex flex-1",children:(0,n.jsx)(F.P,{fullWidth:!0,onSelect:k})})]})]})}function et(e){var t,s;let{productId:a,allProducts:r,onClose:l}=e,o=null!==(s=null===(t=r.find(e=>e.id===a))||void 0===t?void 0:t.title)&&void 0!==s?s:"Product";return(0,n.jsx)("div",{onClick:l,className:"fixed inset-0 z-50 flex items-center justify-center p-6",style:{background:"rgba(0,0,0,0.4)"},children:(0,n.jsxs)(b.E.div,{initial:{opacity:0,scale:.96},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.96},transition:{type:"spring",damping:30,stiffness:300},onClick:e=>e.stopPropagation(),className:"flex max-h-[85vh] w-full max-w-3xl flex-col overflow-hidden bg-bg-white-0",style:{border:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsxs)("div",{className:"flex shrink-0 items-center gap-2 px-6 py-5",style:{borderBottom:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#6E3785"})}),(0,n.jsx)("h3",{className:"min-w-0 flex-1 truncate",style:{fontSize:16,fontWeight:700},children:o}),(0,n.jsx)("button",{onClick:l,className:"flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-bg-soft-200 hover:text-text-sub-600",title:"Close",children:(0,n.jsx)(u.Z,{className:"h-4 w-4"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5",style:{background:"var(--color-bg-weak-50)"},children:(0,n.jsx)(ee,{productId:a,allProducts:r})})]})})}},980379:function(e,t,s){s.d(t,{h:function(){return o}});var n=s(785893),a=s(113542),r=s(379983);let l="var(--color-primary-base)";function o(e){var t,s;let{node:o}=e,i=o?[...o.solutionSets].sort((e,n)=>(null!==(t=e.set.position)&&void 0!==t?t:0)-(null!==(s=n.set.position)&&void 0!==s?s:0)):[];return(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsx)("div",{className:"sticky top-0 z-10 shrink-0 bg-bg-white-0 px-4 py-3",style:{borderBottom:"1px solid var(--color-stroke-soft-200)"},children:o?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,
1children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#FCB03A"})}),(0,n.jsx)("p",{className:"min-w-0 flex-1 truncate text-text-strong-950",style:{fontSize:"calc(13px * var(--font-scale, 1))",fontWeight:700},children:o.scope.name||"Untitled scope"})]}):(0,n.jsx)("p",{className:"text-text-sub-600",style:{fontSize:"calc(12px * var(--font-scale, 1))",fontWeight:600},children:"Solutions"})}),(0,n.jsx)("div",{children:o?0===i.length?(0,n.jsx)("p",{className:"px-4 py-12 text-center text-text-soft-400",style:{fontSize:"calc(12px * var(--font-scale, 1))"},children:"No solutions for this scope yet."}):i.map((e,t)=>{var s;let{set:a,requirements:o}=e,i=(null===(s=a.name)||void 0===s?void 0:s.trim())||"Package ".concat(t+1);return(0,n.jsxs)("div",{className:"px-4 py-3",style:{borderTop:t>0?"1px solid var(--color-stroke-soft-200)":"none"},children:[(0,n.jsxs)("div",{className:"mb-2 flex items-center gap-1.5",children:[0===t&&(0,n.jsx)("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full",style:{background:l},title:"Default package"}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",style:{fontSize:"calc(12px * var(--font-scale, 1))",fontWeight:700,color:l},children:i}),a.estimatedPrice>0&&(0,n.jsx)("span",{className:"shrink-0 tabular-nums text-text-sub-600",style:{fontSize:"calc(11px * var(--font-scale, 1))",fontWeight:600},children:(0,r.ZP)(a.estimatedPrice)})]}),0===o.length?(0,n.jsx)("p",{className:"text-text-soft-400",style:{fontSize:"calc(11px * var(--font-scale, 1))"},children:"No solutions in this package."}):(0,n.jsx)("div",{className:"space-y-1.5",children:o.map(e=>(0,n.jsxs)("div",{className:"flex items-start gap-2 rounded-none px-2 py-1.5",style:{background:"var(--color-bg-weak-50)"},children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"truncate text-text-strong-950",style:{fontSize:"calc(12px * var(--font-scale, 1))",fontWeight:600},children:e.name||"Untitled solution"}),(0,n.jsxs)("p",{className:"truncate tabular-nums text-text-sub-600",style:{fontSize:"calc(10px * var(--font-scale, 1))"},children:[e.qty," ",e.uom||"EA"," @ ",(0,r.ZP)(e.rate),e.skuAttachments.length>0&&" \xb7 ".concat(e.skuAttachments.length," SKU").concat(1===e.skuAttachments.length?"":"s")]})]}),e.qty*e.rate>0&&(0,n.jsx)("span",{className:"shrink-0 tabular-nums text-text-sub-600",style:{fontSize:"calc(11px * var(--font-scale, 1))",fontWeight:600},children:(0,r.ZP)(e.qty*e.rate)})]},e.id))})]},a.id)}):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-12 text-center",children:[(0,n.jsx)(a.Z,{className:"h-5 w-5 text-text-disabled-300"}),(0,n.jsx)("p",{className:"text-text-soft-400",style:{fontSize:"calc(12px * var(--font-scale, 1))"},children:"Hover a scope to preview its solutions."})]})})]})}},817211:function(e,t,s){s.d(t,{N:function(){return k}});var n=s(785893),a=s(667294),r=s(811163),l=s(808971),o=s(884979),i=s(27949),c=s(956989),d=s(114199),u=s(630800),x=s(854463),p=s(140116),m=s(904349),h=s(14066),f=s(851184);function g(e){let{canCommit:t,hasGate:s,interruptReason:a,disableConfirm:r,onCommit:l,onConfirmCommit:o,onDecline:i}=e;return s?(0,n.jsxs)("div",{"data-testid":"commit-affordance",className:"mt-3 space-y-2",children:[(0,n.jsxs)("p",{className:"flex items-center gap-1.5 text-xs text-text-sub-600",children:[(0,n.jsx)(x.Z,{className:"h-3.5 w-3.5 shrink-0 text-brand-primary"}),a]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(m.z,{"data-testid":"scope-tree-draft-confirm",size:"sm",disabled:r,className:"h-7 flex-1 bg-brand-primary text-static-white hover:bg-brand-primary/85",onClick:o,children:"Confirm commit"}),(0,n.jsx)(m.z,{"data-testid":"scope-tree-draft-gate-decline",size:"sm",variant:"ghost",className:"h-7 text-text-sub-600",onClick:i,children:"Decline"})]})]}):(0,n.jsxs)("div",{className:"mt-3 flex items-center gap-2",children:[(0,n.jsx)(m.z,{"data-testid":"scope-tree-draft-commit",size:"sm",disabled:!t,className:"h-7 flex-1 bg-brand-primary text-static-white hover:bg-brand-primary/85",onClick:l,children:"Commit"}),(0,n.jsx)(m.z,{"data-testid":"scope-tree-draft-decline",size:"sm",variant:"ghost",className:"h-7 text-text-sub-600",onClick:i,children:"Decline"})]})}
1function b(e){let{count:t,hits:s}=e,[r,i]=(0,a.useState)(!1);return(0,n.jsxs)("div",{"data-testid":"already-in-catalog-bucket",className:"mt-2 rounded-md bg-state-success-lighter px-2 py-1.5 text-xs text-state-success-dark",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(u.Z,{className:"h-3.5 w-3.5 shrink-0"}),t," assembl",1===t?"y was":"ies were"," imported from an identical workbook row before"]}),(0,n.jsxs)("button",{type:"button","data-testid":"already-in-catalog-show-these",onClick:()=>i(e=>!e),className:"flex shrink-0 items-center gap-0.5 font-medium underline-offset-2 hover:underline",children:[r?"Hide":"Show these",r?(0,n.jsx)(o.Z,{className:"h-3 w-3"}):(0,n.jsx)(l.Z,{className:"h-3 w-3"})]})]}),r&&(0,n.jsx)("ul",{className:"mt-1.5 space-y-0.5 pl-5",children:s.map(e=>(0,n.jsx)("li",{className:"truncate",children:(0,n.jsx)(v,{hit:e})},e.scopeId))})]})}function v(e){let{hit:t}=e,[s,l]=(0,a.useState)(!1),o=(0,r.useRouter)();return(0,n.jsxs)(h.J2e,{open:s,onOpenChange:l,children:[(0,n.jsx)(h.xol,{asChild:!0,children:(0,n.jsx)("button",{type:"button","data-testid":"already-in-catalog-hit",className:"max-w-full truncate text-left underline-offset-2 hover:underline",children:t.name})}),(0,n.jsx)(h.yky,{align:"start",className:"w-72 text-sm",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("p",{"data-testid":"hit-peek-name",className:"font-medium text-text-strong-950",children:t.name}),(0,n.jsxs)("div",{className:"text-xs text-text-sub-600",children:[(0,n.jsxs)("p",{className:"flex items-center gap-1 font-medium text-text-sub-600",children:["Workbook row",(0,n.jsx)(f.C,{content:"The workbook row this scope was imported from. Two imports of the same row produce the same key — that is how a re-import is recognised.",children:(0,n.jsx)(c.Z,{className:"h-3 w-3",tabIndex:0,"aria-label":"Workbook row"})})]}),(0,n.jsx)("p",{"data-testid":"hit-peek-match-key",className:"mt-0.5 break-all font-mono text-[11px]",children:t.matchKey})]}),(0,n.jsx)(m.z,{"data-testid":"hit-peek-open-scope",variant:"outline",size:"sm",className:"w-full",onClick:()=>{l(!1),o.push("/catalog/scope/".concat(t.scopeId))},children:"Open scope"})]})})]})}function y(e){let{products:t}=e;return(0,n.jsxs)("div",{"data-testid":"bulk-products",className:"mt-2 space-y-1.5",children:[(0,n.jsxs)("p",{className:"text-xs font-medium text-text-sub-600",children:[t.length," product",1===t.length?"":"s"]}),t.map(e=>(0,n.jsxs)("div",{"data-testid":"bulk-product-row",className:"rounded-md bg-bg-weak-50 px-2.5 py-1.5",children:[(0,n.jsx)("p",{className:"truncate text-xs font-medium text-text-strong-950",children:e.name}),(0,n.jsxs)("p",{className:"truncate text-xs text-text-sub-600",children:[e.variantCount," variant",1===e.variantCount?"":"s",0===e.variables.length?" \xb7 no axes":" \xb7 ".concat(e.variables.length," ").concat(1===e.variables.length?"axis":"axes",": ").concat(e.variables.map(e=>"".concat(e.name," ").concat(e.optionCount)).join(" \xb7 "))]})]},e.productKey))]})}function j(e){let{vocabulary:t,truncated:s}=e;return(0,n.jsxs)("div",{"data-testid":"bulk-scope-vocabulary",className:"mt-2",children:[(0,n.jsx)("p",{className:"text-xs font-medium text-text-sub-600",children:"Scope names"}),(0,n.jsxs)("div",{className:"mt-1 flex flex-wrap items-center gap-1",children:[t.map(e=>(0,n.jsxs)("span",{"data-testid":"bulk-scope-name-chip",className:"rounded-none bg-bg-soft-200 px-2 py-0.5 text-[11px] font-medium text-text-sub-600",children:[e.name," \xd7",e.count]},e.name)),s&&(0,n.jsx)("span",{"data-testid":"bulk-scope-vocabulary-more",className:"text-[11px] text-text-soft-400",children:"+more"})]})]})}function N(e){let{exceptions:t}=e,[s,r]=(0,a.useState)(!1),i=t.unpricedLines>0||t.zeroPricedLines>0,c=[...t.singleValueAxes.map(e=>({key:"sva-".concat(e.productKey,"-").concat(e.axis,"-").concat(e.value),text:"".concat(e.axis," has only one value under ").concat(e.productKey," — ").concat(e.value)})),...t.singletonValues.map(e=>({key:"sv-".concat(e.productKey,"-").concat(e.axis,"-").concat(e.value),text:"".concat(e.axis," = ").concat(e.value," is used by exactly one variant of ").concat(e.productKey)})),...t.unmatchedPartNumbers.map(e=>({key:"unmatched-".concat(e),text:"".concat(e," matched no SKU")}))],d=c.length+(i?1:0)+(t.unmatchedTruncated?1:0);return 0===d?null:(0,n.jsxs)("div",{"data-testid":"bulk-exceptions-bucket",className:"mt-2 rounded-md bg-bg-weak-50 px-2 py-1.5 text-xs text-text-sub-600",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(p.Z,{className:"h-3.5 w-3.5 shrink-0"}),d," thing",1===d?"":"s"," worth a glance"]}),(0,n.jsxs)("button",{type:"button","data-testid":"bulk-exceptions-show-these",onClick:()=>r(e=>!e),className:"flex shrink-0 items-center gap-0.5 font-medium underline-offset-2 hover:underline",children:[s?"Hide":"Show these",s?(0,n.jsx)(o.Z,{className:"h-3 w-3"}):(0,n.jsx)(l.Z,{className:"h-3 w-3"})]})]}),s&&(0,n.jsxs)("ul",{className:"mt-1.5 space-y-0.5 pl-5",children:[i&&(0,n.jsxs)("li",{"data-testid":"bulk-exceptions-price-line",children:[t.unpricedLines," part line",1===t.unpricedLines?"":"s"," have no price \xb7 ",t.zeroPricedLines," are priced at 0.00"]}),c.map(e=>(0,n.jsx)("li",{"data-testid":"bulk-exception-item",children:e.text},e.key)),t.unmatchedTruncated&&(0,n.jsx)("li",{"data-testid":"bulk-exceptions-unmatched-more",className:"text-text-soft-400",children:"…and more unmatched part numbers"})]})]})}function w(e){let{sample:t}=e,s=t.filter(e=>!("matchKey"in e)),a=[...s].sort((e,t)=>
1e.tier-t.tier),r=a.slice(0,5);return(0,n.jsxs)("div",{"data-testid":"bulk-spot-check-sample",className:"mt-2 space-y-1.5",children:[(0,n.jsx)("p",{className:"text-xs font-medium text-text-sub-600",children:a.length<5?"Showing all ".concat(a.length," sample rows"):"Top 5 by review priority"}),r.map((e,t)=>(0,n.jsxs)("div",{"data-testid":"bulk-spot-check-row","data-tier":e.tier,className:"rounded-md bg-bg-weak-50 px-2.5 py-1.5",children:[(0,n.jsx)("p",{className:"truncate text-xs font-medium text-text-strong-950",children:e.label}),(0,n.jsx)("p",{className:"truncate text-xs text-text-sub-600",children:e.detail})]},"".concat(e.tier,"-").concat(e.label,"-").concat(t)))]})}function k(e){let{draft:t,canCommit:s=!0,interruptReason:a=null,onCommit:r,onConfirmCommit:l,onDecline:o}=e,c=null!=a;if("assemblyAttribution"in t){let{counts:e,reconciliation:u,assemblyAttribution:x,skuCounts:p,ambiguousSkus:m,spotCheckSample:h,generationNotice:f,alreadyInCatalog:v,products:k,scopeVocabulary:S,exceptions:C}=t,I=s&&e.products>0;return(0,n.jsxs)("div",{"data-testid":"scope-tree-draft-card",className:"rounded-lg border border-stroke-soft-200 bg-bg-white-0 p-3 text-sm",children:[(0,n.jsxs)("div",{className:"mb-2 flex items-center gap-2",children:[(0,n.jsx)(d.Z,{className:"h-4 w-4 shrink-0 text-brand-primary"}),(0,n.jsxs)("span",{className:"flex-1 truncate font-semibold text-text-strong-950",children:["Catalog scope draft — ",t.sourceFile]}),(0,n.jsx)("span",{"data-testid":"bulk-draft-id",className:"shrink-0 font-mono text-[11px] text-text-soft-400",children:t.draftId})]}),(null==f?void 0:f.mintedGeneration)!=null&&(0,n.jsxs)("p",{"data-testid":"bulk-generation-notice",className:"mb-2 flex items-center gap-1.5 rounded-md bg-state-info-lighter px-2 py-1 text-xs text-state-info-dark",children:[(0,n.jsx)(i.Z,{className:"h-3.5 w-3.5 shrink-0"}),"Re-import — generation ",f.mintedGeneration,"."]}),(0,n.jsxs)("p",{"data-testid":"bulk-reconciliation",className:"text-xs text-text-sub-600",children:["All new",u.titleCollisionCount>0?" \xb7 ".concat(u.titleCollisionCount," title collision").concat(1===u.titleCollisionCount?"":"s"):""]}),(0,n.jsxs)("div",{"data-testid":"bulk-assembly-attribution",className:"mt-2 grid grid-cols-2 gap-x-3 gap-y-1 rounded-md bg-bg-weak-50 px-2.5 py-2 text-xs",children:[(0,n.jsxs)("span",{"data-testid":"bulk-attribution-proposed",children:["Proposed: ",x.proposed]}),(0,n.jsxs)("span",{"data-testid":"bulk-attribution-held-parse-conflict",children:["Parse conflict: ",x.heldParseConflict]}),(0,n.jsxs)("span",{"data-testid":"bulk-attribution-held-decision-deferred",children:["Needs decision: ",x.heldDecisionDeferred]}),(0,n.jsxs)("span",{"data-testid":"bulk-attribution-unassigned",children:["Unassigned: ",x.unassigned]})]}),(0,n.jsxs)("p",{"data-testid":"bulk-counts-line",className:"mt-2 text-xs text-text-sub-600",children:[e.assembliesProposed," of ",e.assembliesInFile," assemblies proposed \xb7 ",e.bomLines," BOM lines \xb7 ",e.distinctPartNumbers," part numbers",null!=e.variantsWithAttributes&&(0,n.jsxs)(n.Fragment,{children:[" \xb7 ",e.variants," variant",1===e.variants?"":"s"," (",e.variantsWithAttributes," with a vector)"]}),null!=e.containerScopes&&(0,n.jsxs)(n.Fragment,{children:[" \xb7 ",e.containerScopes," container",1===e.containerScopes?"":"s"]})]}),null!=k&&k.length>0&&(0,n.jsx)(y,{products:k}),null!=S&&S.length>0&&(0,n.jsx)(j,{vocabulary:S,truncated:!0===t.scopeVocabularyTruncated}),null!=C&&(0,n.jsx)(N,{exceptions:C}),(p.unmatched>0||p.ambiguous>0)&&(0,n.jsxs)("p",{"data-testid":"bulk-sku-counts",className:"mt-1 text-xs text-text-sub-600",children:[p.unmatched," SKU",1===p.unmatched?"":"s"," unmatched \xb7 ",p.ambiguous," ambiguous"]}),m.length>0&&(0,n.jsx)("ul",{"data-testid":"bulk-ambiguous-skus",className:"mt-1 space-y-0.5 pl-5 text-xs text-text-sub-600",children:m.map(e=>(0,n.jsxs)("li",{"data-testid":"bulk-ambiguous-sku",className:"truncate",children:[e.partNumber," (",e.candidateCount," candidates)"]},e.partNumber))}),h.length>0&&(0,n.jsx)(w,{sample:h}),v.count>0&&(0,n.jsx)(b,{count:v.count,hits:v.hits}
1),(0,n.jsx)(g,{canCommit:I,hasGate:c,interruptReason:a,disableConfirm:!1,onCommit:r,onConfirmCommit:l,onDecline:o})]})}let{counts:u,types:x}=t,h=u.assembliesExtracted<u.assembliesTotal,f=0===u.typesFound||0===x.length,v=t.conflicts.length>0||x.some(e=>e.requirements.some(e=>null!=e.conflict));return(0,n.jsxs)("div",{"data-testid":"scope-tree-draft-card",className:"rounded-lg border border-stroke-soft-200 bg-bg-white-0 p-3 text-sm",children:[(0,n.jsxs)("div",{className:"mb-2 flex items-center gap-2",children:[(0,n.jsx)(d.Z,{className:"h-4 w-4 shrink-0 text-brand-primary"}),(0,n.jsx)("span",{className:"flex-1 truncate font-semibold text-text-strong-950",children:"Catalog scope draft"})]}),h&&(0,n.jsxs)("p",{"data-testid":"scope-tree-draft-partial",className:"mb-2 flex items-center gap-1.5 rounded-md bg-state-warning-lighter px-2 py-1 text-xs text-state-warning-dark",children:[(0,n.jsx)(i.Z,{className:"h-3.5 w-3.5 shrink-0"}),u.assembliesExtracted," of ",u.assembliesTotal," assemblies extracted; the rest are in the KB."]}),f?(0,n.jsxs)("div",{"data-testid":"scope-tree-draft-no-clusters",children:[(0,n.jsx)("p",{className:"text-xs text-text-sub-600",children:"No reusable TYPES found; nothing proposed for the catalog. KB entries still landed."}),(0,n.jsx)("div",{className:"mt-3 flex items-center",children:(0,n.jsx)(m.z,{"data-testid":"scope-tree-draft-noclusters-decline",size:"sm",variant:"ghost",className:"h-7 text-text-sub-600",onClick:o,children:"Decline"})})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"space-y-2",children:x.map(e=>(0,n.jsxs)("div",{"data-testid":"scope-tree-draft-type",className:"rounded-md bg-bg-weak-50 px-2.5 py-2",children:[(0,n.jsxs)("div",{className:"flex items-baseline justify-between gap-2",children:[(0,n.jsx)("span",{className:"truncate font-medium text-text-strong-950",children:e.typeName}),(0,n.jsxs)("span",{className:"shrink-0 tabular-nums text-xs text-text-sub-600",children:[e.instanceCount," instances"]})]}),(0,n.jsxs)("p",{"data-testid":"scope-tree-draft-recipe",className:"mt-0.5 text-xs text-text-sub-600",children:[e.requirements.length," requirements \xb7 rate: TBD"]})]},e.nodeId))}),v&&(0,n.jsxs)("p",{"data-testid":"conflict-flag-card",className:"mt-2 flex items-center gap-1.5 rounded-md bg-state-warning-lighter px-2 py-1 text-xs text-state-warning-dark",children:[(0,n.jsx)(p.Z,{className:"h-3.5 w-3.5 shrink-0"}),"Needs review — a value disagrees across pages. Resolve or drop the flagged node to commit."]}),(0,n.jsx)(g,{canCommit:s,hasGate:c,interruptReason:a,disableConfirm:v,onCommit:r,onConfirmCommit:l,onDecline:o})]})]})}},329821:function(e,t,s){s.d(t,{f:function(){return a}});var n=s(785893);function a(e){let{attributes:t,variables:s}=e,a=function(e,t){let s=new Set,n=[];for(let a of t){let t=a.name.trim();if(!t||s.has(t))continue;let r=e[t];null!=r&&""!==r&&(s.add(t),n.push({name:t,value:r}))}for(let[t,a]of Object.entries(e))s.has(t)||null==a||""===a||n.push({name:t,value:a});return n}(t,s);return 0===a.length?null:(0,n.jsx)("span",{"data-testid":"variant-attribute-chips",className:"flex min-w-0 flex-wrap items-center gap-1",children:a.map(e=>(0,n.jsxs)("span",{"data-testid":"variant-attribute-chip",className:"shrink-0 rounded-none bg-bg-soft-200 px-2 py-0.5 text-text-sub-600",style:{fontSize:11,fontWeight:500},children:[e.name," ",e.value]},e.name))})}},603367:function(e,t,s){s.d(t,{g:function(){return j}});var n=s(785893),a=s(667294),r=s(430202),l=s(53219),o=s(931012),i=s(541352),c=s(313742),d=s(956989),u=s(283900),x=s(407800),p=s(329821),m=s(851184),h=s(218754),f=s(682322),g=s(48743),b=s(351085),v=s(489087),y=s(787379);function j(e){var t,s,j,w,k,S,C,I,P,_,z;let{productId:A,variantId:W,allVariants:R,onClose:D}=e,{data:T}=(0,f.Ir)(A),{data:E}=(0,f.Mt)(A,W),{data:q=[]}=(0,f.vy)(A,W),{data:Z=[]}=(0,f.Xh)(A),{data:F}=(0,f.n4)(A,W),B=(0,f.w1)(A),L=(0,f.pz)(A),U=(0,f.c9)(A),O=(0,f.ss)(A),V=(0,f.Qe)(A),K=(0,f.du)(A),M=R.find(e=>e.id===W),H=null!==(j=null==M?void 0:M.name)&&void 0!==j?j:W,[$,G]=(0,a.useState)(!1),[Y,Q]=(0,a.useState)(""),[X,J]=(0,a.useState)(""),[ee,et]=(0,a.useState)(()=>null!==(w=null==M?void 0:M.tags)&&void 0!==w?w:[]),[es,en]=(0,a.useState)(null),[ea,er]=(0,a.useState)(null),[el,eo]=(0,a.useState)(!1),[ei,ec]=(0,a.useState)(""),{toast:ed}=(0,x.pm)(),eu=(0,r.NL)(),ex=(0,f.O2)(A),ep=(0,f.yU)(A),em=(0,f.eW)(A),eh=(0,a.useCallback)(()=>
1{eu.invalidateQueries({queryKey:f.U7.productDetail(A)}),eu.invalidateQueries({queryKey:f.U7.effectiveScopes(A,W)}),eu.invalidateQueries({queryKey:f.U7.productVariants(A)})},[eu,A,W]),{data:ef=[]}=(0,f.Jq)(),eg=(0,a.useCallback)(()=>{eu.invalidateQueries({queryKey:f.U7.variantScopesTree(A,W)}),eu.invalidateQueries({queryKey:f.U7.effectiveScopes(A,W)})},[eu,A,W]),eb={addRequirement:(e,t)=>U.mutateAsync({variantId:W,scopeId:e,requirement:t}),updateRequirement:(e,t,s)=>O.mutateAsync({variantId:W,scopeId:e,requirementId:t,data:s}),deleteRequirement:(e,t)=>V.mutateAsync({variantId:W,scopeId:e,requirementId:t}),deleteScope:e=>L.mutateAsync({variantId:W,scopeId:e}),updateScope:(e,t)=>K.mutateAsync({variantId:W,scopeId:e,...t})},ev=null!==(k=null==E?void 0:E.globalScopes)&&void 0!==k?k:[],ey=null!==(S=null==E?void 0:E.variantScopes)&&void 0!==S?S:[],ej=new Set(ey.map(e=>e.id)),eN=new Set(ev.map(e=>e.id)),ew=q.filter(e=>ej.has(e.scope.id)),ek=q.filter(e=>eN.has(e.scope.id)),eS=(0,a.useCallback)(async()=>{if(!Y.trim()){G(!1);return}await B.mutateAsync({variantId:W,scope:{name:Y.trim(),requirements:[],connectedProductRefs:[]}}),G(!1),Q("")},[B,W,Y]),eC=(0,a.useCallback)(async e=>{await L.mutateAsync({variantId:W,scopeId:e})},[L,W]);return(0,a.useCallback)(async(e,t)=>{t.trim()&&await U.mutateAsync({variantId:W,scopeId:e,requirement:{name:t.trim(),qty:1,uom:"EA",rate:0}})},[U,W]),(0,a.useCallback)(async(e,t,s)=>{await O.mutateAsync({variantId:W,scopeId:e,requirementId:t,data:s})},[O,W]),(0,a.useCallback)(async(e,t)=>{await V.mutateAsync({variantId:W,scopeId:e,requirementId:t})},[V,W]),(0,n.jsx)("div",{onClick:D,className:"fixed inset-0 z-50 flex items-center justify-center p-6",style:{background:"rgba(0,0,0,0.4)"},children:(0,n.jsxs)(u.E.div,{initial:{opacity:0,scale:.96},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.96},transition:{type:"spring",damping:30,stiffness:300},onClick:e=>e.stopPropagation(),className:"flex max-h-[85vh] w-full max-w-3xl flex-col overflow-hidden bg-bg-white-0",style:{border:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsxs)("div",{className:"flex shrink-0 items-center justify-between px-6 py-5",style:{borderBottom:"1px solid var(--color-stroke-soft-200)"},children:[es?(0,n.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[(0,n.jsx)("button",{onClick:()=>{en(null),eo(!1)},className:"flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-none hover:bg-bg-soft-200",children:(0,n.jsx)(l.Z,{className:"h-4 w-4 text-text-sub-600"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"text-text-soft-400",style:{fontSize:"calc(10px * var(--font-scale, 1))"},children:H}),(0,n.jsxs)("p",{style:{fontSize:"calc(15px * var(--font-scale, 1))",fontWeight:700},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 14 14",className:"mr-1 inline-block","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#FCB03A"})}),null!==(I=null===(t=null!==(C=ey.find(e=>e.id===es))&&void 0!==C?C:ev.find(e=>e.id===es))||void 0===t?void 0:t.name)&&void 0!==I?I:"Scope"]})]})]}):ea?(0,n.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[(0,n.jsx)("button",{onClick:()=>er(null),className:"flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-none hover:bg-bg-soft-200",children:(0,n.jsx)(l.Z,{className:"h-4 w-4 text-text-sub-600"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"text-text-soft-400",style:{fontSize:"calc(10px * var(--font-scale, 1))"},children:H}),(0,n.jsxs)("p",{style:{fontSize:"calc(15px * var(--font-scale, 1))",fontWeight:700},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 14 14",className:"mr-1 inline-block","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#6E3785"})}),null!==(P=null===(s=ef.find(e=>e.id===ea))||void 0===s?void 0:s.title)&&void 0!==P?P:"Product"]})]})]}):(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("h3",{style:{fontSize:"calc(16px * var(--font-scale, 1))",fontWeight:700},children:H}),(null==M?void 0:M.externalCode)!=null&&""!==M.externalCode&&(0,n.jsxs)("p",{"data-testid":"variant-external-code",className:"mt-0.5 flex items-center gap-1 text-text-sub-600",
1style:{fontSize:"calc(11px * var(--font-scale, 1))"},children:["Code: ",(0,n.jsx)("span",{className:"font-mono",children:M.externalCode}),(0,n.jsx)(m.C,{content:"The code your own system uses for this variant. Set by import; not editable here.",children:(0,n.jsx)(d.Z,{className:"h-3 w-3",tabIndex:0,"aria-label":"Code"})})]}),(0,n.jsx)("div",{className:"mt-1",children:(0,n.jsx)(p.f,{attributes:null!==(_=null==M?void 0:M.attributes)&&void 0!==_?_:{},variables:null!==(z=null==T?void 0:T.variables)&&void 0!==z?z:[]})})]}),(0,n.jsx)("button",{onClick:D,className:"flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-bg-soft-200 hover:text-text-sub-600",title:"Close",children:(0,n.jsx)(i.Z,{className:"h-4 w-4"})})]}),es?(()=>{var e,t,s,a;let r=null!==(t=ey.find(e=>e.id===es))&&void 0!==t?t:ev.find(e=>e.id===es);if(!r)return null;let l=(e,t)=>{for(let s of e){if(s.scope.id===t)return s;let e=l(s.childScopes,t);if(e)return e}},o=null!==(s=l(q,es))&&void 0!==s?s:l(Z,es),i=o&&null!==(a=null===(e=(0,h.C6)(o))||void 0===e?void 0:e.requirements)&&void 0!==a?a:[],c=o?(0,h.$3)(o):0,d=o?(0,h.ik)(o):0;return(0,n.jsxs)("div",{className:"flex-1 space-y-5 overflow-y-auto px-6 py-5",children:[r.tags&&r.tags.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap gap-1.5",children:r.tags.map(e=>(0,n.jsx)("span",{className:"rounded-none px-2.5 py-1",style:{background:"var(--color-bg-soft-200)",fontSize:"calc(11px * var(--font-scale, 1))",fontWeight:500,color:"var(--color-text-sub-600)"},children:e},e))}),i.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"mb-2 flex items-center justify-between",children:[(0,n.jsxs)("span",{className:"text-text-sub-600",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Solutions (",i.length,")"]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[c>0&&(0,n.jsxs)("span",{className:"tabular-nums text-text-sub-600",style:{fontSize:"calc(12px * var(--font-scale, 1))",fontWeight:600},children:["Est. $",c.toLocaleString()]}),d>0&&(0,n.jsxs)("span",{className:"tabular-nums",style:{fontSize:"calc(12px * var(--font-scale, 1))",fontWeight:600,color:"var(--color-state-success-dark)"},children:["Allowance $",d.toLocaleString()]})]})]}),(0,n.jsx)("div",{className:"space-y-2",children:i.map(e=>(0,n.jsx)(b.z,{requirement:e,readOnly:!0},e.id))})]}),o&&o.childScopes.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Scopes (",o.childScopes.length,")"]}),(0,n.jsx)("div",{className:"space-y-2",children:o.childScopes.map(e=>(0,n.jsx)(g.C,{node:e,readOnly:!0},e.scope.id))})]}),r.connectedProductRefs.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Connected Products (",r.connectedProductRefs.length,")"]}),(0,n.jsx)("div",{className:"space-y-1.5",children:r.connectedProductRefs.map(e=>{var t;let s=ef.find(t=>t.id===e.productId);return(0,n.jsxs)("div",{className:"flex items-center gap-2 rounded-none bg-bg-white-0 px-3 py-2",style:{border:"1px solid var(--color-primary-alpha-16)"},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#6E3785"})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate text-text-sub-600",style:{fontSize:"calc(12px * var(--font-scale, 1))",fontWeight:500},children:null!==(t=null==s?void 0:s.title)&&void 0!==t?t:e.productId})]},e.productId)})})]}),0===i.length&&(!o||0===o.childScopes.length)&&0===r.connectedProductRefs.length&&(0,n.jsx)("p",{className:"py-8 text-center text-text-soft-400",style:{fontSize:"calc(12px * var(--font-scale, 1))"},children:"No content in this scope"})]})})():ea?(0,n.jsx)(N,{productId:ea}):(0,n.jsxs)("div",{className:"flex-1 space-y-5 overflow-y-auto px-6 py-5",children:[F&&(0,n.jsxs)("div",{className:"flex items-center justify-between rounded-none px-4 py-3",style:{background:"var(--color-bg-weak-50)",border:"1px solid var(--color-stroke-soft-200)"},children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"block text-text-soft-400",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Total Estimated"}),(0,n.jsx)("span",{className:"tabular-nums",style:{fontSize:"calc(15px * var(--font-scale, 1))",fontWeight:700,color:"var(--color-text-strong-950)"},children:F.totalEstimatedPrice>
10?"$".concat(F.totalEstimatedPrice.toLocaleString()):"—"})]}),F.totalAllowance>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"block text-text-soft-400",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Total Allowance"}),(0,n.jsxs)("span",{className:"tabular-nums",style:{fontSize:"calc(15px * var(--font-scale, 1))",fontWeight:700,color:"var(--color-text-strong-950)"},children:["$",F.totalAllowance.toLocaleString()]})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"mb-1.5 block text-text-sub-600",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Category Tags"}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 rounded-none bg-bg-white-0 px-3 py-2",style:{border:"1px solid var(--color-stroke-soft-200)",minHeight:40},children:[ee.map(e=>(0,n.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-none px-2 py-0.5",style:{background:"var(--color-bg-soft-200)",fontSize:"calc(11px * var(--font-scale, 1))",fontWeight:500},children:[e,(0,n.jsx)("button",{onClick:()=>{let t=ee.filter(t=>t!==e);et(t),em.mutate({variantId:W,tags:t})},className:"cursor-pointer hover:opacity-60",children:(0,n.jsx)(i.Z,{className:"h-2.5 w-2.5 text-text-soft-400"})})]},e)),(0,n.jsx)("input",{value:X,onChange:e=>J(e.target.value),onKeyDown:e=>{if("Enter"===e.key){e.preventDefault();let t=X.trim();if(t&&!ee.includes(t)){let e=[...ee,t];et(e),J(""),em.mutate({variantId:W,tags:e})}}},placeholder:0===ee.length?"Add tags...":"",className:"min-w-[80px] flex-1 bg-transparent outline-none",style:{fontSize:"calc(12px * var(--font-scale, 1))"}})]})]}),ek.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Inherited Scopes"}),(0,n.jsx)("div",{children:ek.map((e,t)=>(0,n.jsx)(y.cF,{index:t,isLast:t===ek.length-1,children:(0,n.jsx)(y.Xq,{node:e,productId:A,allProducts:ef,onRefresh:eg,api:eb,onDelete:()=>eC(e.scope.id)})},e.scope.id))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Variant Scopes"}),(0,n.jsxs)("div",{children:[ew.map((e,t)=>(0,n.jsx)(y.cF,{index:t,isLast:t===ew.length-1,children:(0,n.jsx)(y.Xq,{node:e,productId:A,allProducts:ef,onRefresh:eg,api:eb,onDelete:()=>eC(e.scope.id),onRename:async t=>{try{await eb.updateScope(e.scope.id,{name:t}),eg()}catch(e){ed({title:"Failed to rename scope",variant:"destructive"})}}})},e.scope.id)),0===ew.length&&(0,n.jsx)("p",{className:"text-text-soft-400",style:{fontSize:"calc(11px * var(--font-scale, 1))"},children:"No variant-specific scopes yet."})]}),(()=>{var e,t;let s=null!==(t=null!==(e=null==E?void 0:E.connectedProductRefs)&&void 0!==e?e:null==M?void 0:M.connectedProductRefs)&&void 0!==t?t:[];return 0===s.length?null:(0,n.jsxs)("div",{className:"mt-3",children:[(0,n.jsx)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Connected Products"}),(0,n.jsx)("div",{children:s.map((e,t)=>{var a,r,l;let o=ef.find(t=>t.id===e.productId);return(0,n.jsx)(y.cF,{index:t,isLast:t===s.length-1,children:(0,n.jsx)(y.M8,{productId:null!==(a=e.productId)&&void 0!==a?a:"",name:null!==(l=null!==(r=null==o?void 0:o.title)&&void 0!==r?r:e.productId)&&void 0!==l?l:"Product",allProducts:ef,onRemove:async()=>{e.productId&&(await ep.mutateAsync({variantId:W,refProductId:e.productId}),eh())}})},e.productId)})})]})})(),(0,n.jsxs)("div",{className:"mt-3 flex items-stretch gap-2",children:[$?(0,n.jsxs)("div",{className:"flex flex-1 items-center gap-2 rounded-none px-3 py-2",style:{border:"1.5px dashed var(--color-state-warning-base)",background:"var(--color-state-warning-lighter)"},children:[(0,n.jsx)("input",{value:Y,onChange:e=>Q(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),eS()),"Escape"===e.key&&(G(!1),Q(""))},placeholder:"Scope name...",className:"min-w-0 flex-1 bg-transparent text-text-sub-600 outline-none",style:{fontSize:"calc(13px * var(--font-scale, 1))"},autoFocus:!0}),(0,n.jsx)("button",{onClick:eS,disabled:!Y.trim(),className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none bg-[var(--color-state-warning-base)] text-white disabled:opacity-40",children:(0,n.jsx)(c.Z,{className:"h-3 w-3"})}),(0,n.jsx)("button",{onClick:()=>{G(!1),Q("")},className:"flex h-6 w-6 shrink-0 cursor-pointer items-center justify-center rounded-none text-text-soft-400 hover:bg-bg-soft-200",children:(0,n.jsx)(i.Z,{className:"h-3 w-3"})})]}):(0,n.jsxs)("button",{onClick:()=>{G(!0),Q("")},className:"flex flex-1 items-center justify-center gap-1.5 rounded-none border border-dashed py-2.5",style:{borderColor:"var(--color-state-warning-base)",color:"var(--color-state-warning-dark)",fontSize:"calc(12px * var(--font-scale, 1))",fontWeight:600},children:[(0,n.jsx)(o.Z,{className:"h-3.5 w-3.5"})," Add Scope"]}),(0,n.jsx)("div",{className:"flex flex-1",children:(0,n.jsx)(v.P,{fullWidth:!0,excludeIds:new Set([A]),onSelect:async e=>{var t;await ex.mutateAsync({variantId:W,ref:{productId:e.id,qty:1}}),eh(),ed({title:"Product added",description:null!==(t=e.title)&&void 0!==t?t:""})}})})]})]})]})]})})}function N(e){var t;let{productId:s}=e,{data:a=[]}=(0,f.Xh)(s),{data:r}=(0,f.Ir)(s),{data:l=[]}=(0,f.Jq)(),o=null!==(t=null==r?void 0:r.connectedProductRefs)&&void 0!==t?t:[];return(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:[a.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("span",{className:"mb-2 block text-text-sub-600",
1style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Scopes (",a.length,")"]}),(0,n.jsx)("div",{className:"space-y-2",children:a.map(e=>(0,n.jsx)(g.C,{node:e,readOnly:!0},e.scope.id))})]}),o.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("span",{className:"mb-2 block text-text-sub-600",style:{fontSize:"calc(10px * var(--font-scale, 1))",fontWeight:700,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Connected Products (",o.length,")"]}),(0,n.jsx)("div",{className:"space-y-1.5",children:o.map(e=>{var t;let s=l.find(t=>t.id===e.productId);return(0,n.jsxs)("div",{className:"flex items-center gap-2 rounded-none bg-bg-white-0 px-3 py-2",style:{border:"1px solid var(--color-primary-alpha-16)"},children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 14 14",className:"shrink-0","aria-hidden":!0,children:(0,n.jsx)("polygon",{points:"7,0.5 13,3.5 13,10.5 7,13.5 1,10.5 1,3.5",fill:"#6E3785"})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate text-text-sub-600",style:{fontSize:"calc(12px * var(--font-scale, 1))",fontWeight:500},children:null!==(t=null==s?void 0:s.title)&&void 0!==t?t:e.productId})]},e.productId)})})]}),0===a.length&&0===o.length&&(0,n.jsx)("p",{className:"py-8 text-center text-text-soft-400",style:{fontSize:"calc(12px * var(--font-scale, 1))"},children:"No scopes or connected products"})]})}},62093:function(e,t,s){s.d(t,{w:function(){return u}});var n=s(667294),a=s(973935),r=s(80628),l=s(23226);let o="Your last import could not be restored — starting a new one.",i={extract_fab_package:"Parsing the fabrication package… (this can take a minute)",cluster_assemblies:"Clustering assemblies into reusable types…",match_sku:"Matching catalog SKUs…",emit_result:"Building the scope draft…",commit_scope_tree:"Committing the scope to the catalog…",undo_scope_tree:"Undoing the commit…"},c=0,d=()=>"cat-".concat(Date.now(),"-").concat(c++);function u(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:l.de,c=arguments.length>3&&void 0!==arguments[3]?arguments[3]:l.IL,u=arguments.length>4?arguments[4]:void 0,[x,p]=(0,n.useState)([]),[m,h]=(0,n.useState)(!1),[f,g]=(0,n.useState)(null),[b,v]=(0,n.useState)(!1),[y,j]=(0,n.useState)(null),[N,w]=(0,n.useState)(null),[k,S]=(0,n.useState)(null),[C,I]=(0,n.useState)(null),P=(0,n.useRef)(null),_=(0,n.useRef)(!1),z=(0,n.useRef)(null),A=(0,n.useCallback)(e=>{z.current=e,S(e)},[]);(0,n.useEffect)(()=>{if(!u)return;let e=!1;return(async()=>{var t,s,n,a,i;let c=await (0,r.ZX)(u);if(e)return;if(!(null==c?void 0:c.data)){w(o);return}if(!c.data.hasPendingInterrupt&&!c.data.isRunning)return;let d=[...null!==(t=c.data.toolTrace)&&void 0!==t?t:[]].reverse().find(e=>"result"===e.kind&&e.toolName===l.T8&&null!=e.structuredResult&&(null==e.resultSchema||"catalog.scope_tree_draft"===e.resultSchema));if(!d){w(o);return}if(_.current||null!=P.current)return;P.current=u,I(u);let x=(null!==(s=c.data.items)&&void 0!==s?s:[]).map((e,t)=>{var s;return{id:"restored-".concat(null!==(n=e.sequence_number)&&void 0!==n?n:t),role:(null===(s=e.role)||void 0===s?void 0:s.toLowerCase())==="user"?"user":"assistant",content:null!==(a=e.content)&&void 0!==a?a:"",timestamp:""}});p(x),j(d.structuredResult),c.data.hasPendingInterrupt&&A({tool_use_id:null!==(i=d.toolUseId)&&void 0!==i?i:"restored",tool_name:l.Bb,reason:"Catalog scope ready to commit. Approve to write or decline."})})(),()=>{e=!0}},[u]);let W=(0,n.useCallback)(async(e,t)=>{for await(let r of e){var s,n;if(r.thread_id&&P.current!==r.thread_id&&(P.current=r.thread_id,I(r.thread_id)),"tool_start"===r.type&&r.tool_name){let e=i[r.tool_name];e&&g(e)}else if("text"===r.type&&r.text){let e=r.text;(0,a.unstable_batchedUpdates)(()=>{g(e),p(s=>s.map(s=>s.id===t?{...s,content:s.content+e}:s))})}else if((0,l.$p)(r))w(null),A(null),j(r.tool_output);else if((0,l.vi)(r)){let e=r.interrupt_info,t=String(null!==(s=e.reason)&&void 0!==s?s:"").slice(0,500);w(null),A({...e,reason:t})}else"error"===r.type&&w(null!==(n=r.error)&&void 0!==n?n:"Something went wrong processing the package.")}},[A]),R=(0,n.useCallback)(e=>{let t={id:d(),role:"user",content:e,timestamp:new Date().toISOString()},s={id:d(),role:"assistant",content:"",timestamp:new Date().toISOString()};return p(e=>[...e,t,s]),s.id},[]),D=(0,n.useCallback)(async(n,a)=>{var r;let l=n.trim();if(!l||_.current)return;if(!t)throw Error("orgId not resolved yet — cannot start a catalog agent turn.");let o=null!==(r=null==a?void 0:a.files)&&void 0!==r?r:[],i=R(l);w(null),h(!0),_.current=!0;let c={orgId:t,threadId:P.current,message:l,files:o,workerHint:"catalog_design",...e?{productId:e}:{}};try{await W(s(c),i)}finally{h(!1),_.current=!1,g(null)}},[t,e,s,W,R]),T=(0,n.useCallback)(async e=>{let s=P.current;if(!s||_.current||null==z.current)return;if(!t)throw Error("orgId not resolved yet — cannot start a catalog agent turn.");let n=R(e?"Approve":"Decline");h(!0),_.current=!0;try{await W(c({orgId:t,threadId:s,humanResponse:{approved:e}}),n),A(null),e||j(null)}finally{h(!1),_.current=!1,g(null)}},[t,c,W,R,A]),E=(0,n.useCallback)(async e=>{await D(e)},[D]),q=(0,n.useCallback)(async()=>{await T(!0)},[T]),Z=(0,n.useCallback)(async e=>{if(await D(e),null==z.current)throw Error("Commit failed: the approval gate was not raised by the kept-set turn.");await T(!0)},[D,T]),F=(0,n.useCallback)(async()=>{await T(!1)},[T]),B=(0,n.useCallback)(()=>{p([]),j(null),w(null),A(null),I(null),P.current=null,g(null)},[A]),L=(0,n.useCallback)(()=>{},[]),U=(0,n.useCallback)(async()=>"valid",[]);return(0,n.useMemo)(()=>({messages:x,isStreaming:m,streamingStatus:f,isLoadingHistory:!1,isOpen:b,setIsOpen:v,sendMessage:D,stopStreaming:L,retryLastMessage:L,startNewChat:B,openInAskAI:L,loadConversation:U,conversationId:C,lastPromotedMessage:null,promotedOnResume:!1,lastScopeError:null,draft:y,lastError:N,pendingInterrupt:k,commit:Z,raiseGate:E,confirmCommit:q,decline:F}),[x,m,f,b,D,B,L,U,C,y,N,k,Z,E,q,F])}},820888:function(e,t,s){s.d(t,{U:function(){return r}});var n=s(667294),a=s(262834);function r(e){let{sendMessage:t}
1=e,[s,r]=(0,n.useState)("idle"),[l,o]=(0,n.useState)(null),[i,c]=(0,n.useState)(null),d=(0,n.useRef)(!1),u=(0,n.useRef)(null),x=(0,n.useCallback)(e=>{c(e),r("failed"),d.current=!1},[]),p=(0,n.useCallback)(async(e,s)=>{let n;if(d.current)return;d.current=!0,u.current={file:e,productId:s.productId,askMessage:s.askMessage},c(null),o(e.name),r("uploading");try{let t=await (0,a.We)([e]);if(t.oversizedNames.length>0){x('"'.concat(e.name,'" is too large to upload.'));return}if(!(n=t.uploaded)||0===n.length){x("Could not upload the fabrication package.");return}}catch(e){x(e instanceof Error?e.message:"Could not upload the fabrication package.");return}let l=n.map(e=>({fileName:e.fileName,s3Path:e.s3Path}));r("ready"),d.current=!1,t(s.askMessage,{files:l})},[x,t]),m=(0,n.useCallback)(()=>{let e=u.current;e&&!d.current&&p(e.file,{productId:e.productId,askMessage:e.askMessage})},[p]),h=(0,n.useCallback)(()=>{d.current=!1,r("idle"),o(null),c(null)},[]);return{status:s,fileName:l,error:i,ingestThenAsk:p,retry:m,reset:h}}},911269:function(e,t,s){s.d(t,{F:function(){return r}});var n=s(667294),a=s(98043);function r(e){var t;let[s,r]=(0,n.useState)(()=>new Set),l=null!==(t=null==e?void 0:e.draftId)&&void 0!==t?t:null;(0,n.useEffect)(()=>{r(new Set)},[l]);let o=(0,n.useCallback)(e=>s.has(e),[s]),i=(0,n.useCallback)(e=>{r(t=>{let s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})},[]),c=(0,n.useMemo)(()=>e?(0,a.hR)(e,s):[],[e,s]),d=(0,n.useMemo)(()=>e?(0,a.Ps)(e,s):"",[e,s]),u=(0,n.useMemo)(()=>!!e&&0!==c.length&&!(0,a.nx)(e,s),[e,s,c]);return{isDropped:o,toggleNode:i,keptNodeIds:c,commitMessage:d,canCommit:u}}},332922:function(e,t,s){s.d(t,{H:function(){return i},x:function(){return o}});var n=s(80628);class a{push(e){this.closed||(this.queue.push(e),this.wake())}close(){this.closed||(this.closed=!0,this.wake())}wake(){let e=this.resolveNext;this.resolveNext=null,null==e||e()}async *drain(){for(;;){if(this.queue.length>0){yield this.queue.shift();continue}if(this.closed)return;await new Promise(e=>{this.resolveNext=e})}}constructor(){this.queue=[],this.resolveNext=null,this.closed=!1}}function r(e,t,s){var n;let a=()=>null!==(n=t())&&void 0!==n?n:"";return{onThreadId:e=>{s(e)},onText:t=>{e.push({type:"text",thread_id:a(),text:t})},onToolStart:t=>{var s,n;e.push({type:"tool_start",thread_id:a(),tool_name:t.toolName,tool_use_id:t.toolUseId,tool_input:null!==(s=t.toolInput)&&void 0!==s?s:null,subagent_context:null!==(n=t.subagentContext)&&void 0!==n?n:null})},onToolResult:t=>{var s;e.push({type:"tool_result",thread_id:a(),tool_name:t.toolName,tool_use_id:t.toolUseId,tool_output:t.toolOutput,is_error:t.isError,subagent_context:null!==(s=t.subagentContext)&&void 0!==s?s:null})},onInterrupt:t=>{e.push({type:"interrupt",thread_id:a(),interrupt_info:t}),e.close()},onTurnEnd:n=>{var a,r;n&&s(n),e.push({type:"turn_end",thread_id:null!==(r=null!==(a=t())&&void 0!==a?a:n)&&void 0!==r?r:""})},onDone:()=>{e.push({type:"turn_end",thread_id:a()}),e.close()},onError:t=>{e.push({type:"error",thread_id:a(),is_error:!0,error:String(t)}),e.close()}}}function l(e){return e.split("::")[0]}async function*o(e){var t;let s=new a,o=null!==(t=e.threadId)&&void 0!==t?t:null,i=r(s,()=>o,e=>{o=l(e)});(0,n.Q$)(e.orgId,e.threadId?l(e.threadId):null,e.message,e.files,i,void 0,{...e.productId?{productId:e.productId}:{},...e.workerHint?{workerHint:e.workerHint}:{}}).catch(e=>{s.push({type:"error",thread_id:null!=o?o:"",is_error:!0,error:String(e)})}).finally(()=>{s.close()}),yield*s.drain()}async function*i(e){let t=new a,s=e.threadId,o=r(t,()=>s,e=>{s=l(e)});(0,n.P2)(e.orgId,l(e.threadId),e.humanResponse.approved?"approve":"decline",o).catch(e=>{t.push({type:"error",thread_id:null!=s?s:"",is_error:!0,error:String(e)})}).finally(()=>{t.close()}),yield*t.drain()}},23226:function(e,t,s){s.d(t,{$p:function(){return l},Bb:function(){return r},IL:function(){return c},T8:function(){return a},de:function(){return i},kJ:function(){return n},vi:function(){return o}});let n="__CATALOG_COMMIT_TURN__",a="emit_result",r="commit_scope_tree";function l(e){return"tool_result"===e.type&&e.tool_name===a&&"object"==typeof e.tool_output&&null!=e.tool_output&&!Array.isArray(e.tool_output)&&"draftId"in e.tool_output}function o(e){return"interrupt"===e.type&&"object"==typeof e.interrupt_info&&null!=e.interrupt_info&&"tool_use_id"in e.interrupt_info}async function*i(e){var t,s,l,o,i;let c=e.threadId||"stub-thread-catalog-0001";if(e.message.includes(n)){yield{type:"text",thread_id:c,text:"Locking the catalog scope plan for your approval…"};let e="toolu_02WriteTreeXyz";yield{type:"interrupt",thread_id:c,text:"Catalog scope is ready to commit. Approve to write, or decline.",interrupt_info:{tool_use_id:e,tool_name:r,reason:"Catalog scope ready to commit. Approve to write or decline.",payload:{type:"requires_confirmation",tool_use_id:e}}};return}let d=null!==(o=null!==(l=null===(t=e.files[0])||void 0===t?void 0:t.s3Path)&&void 0!==l?l:null===(s=e.files[0])||void 0===s?void 0:s.fileName)&&void 0!==o?o:"WO-package.pdf",u=function(e){let t=e.toLowerCase();return t.includes("no clusters")||t.includes("no-clusters")?"no-clusters":t.includes("error")||t.includes("fail")?"error":t.includes("conflict")?"conflict":t.includes("complete")?"complete":"happy"}(e.message),x=null!==(i=e.productId)&&void 0!==i?i:"stub-product";if(yield{type:"text",thread_id:c,text:"Indexing the fabrication package and clustering assemblies into reusable TYPES…"},"error"===u){yield{type:"error",thread_id:c,is_error:!0,error:"The fabrication package could not be processed. Re-upload the WO package and try again."};return}yield{type:"tool_result",thread_id:c,tool_name:a,tool_use_id:"toolu_01EmitDraftAbc",tool_output:function(e,t,s){let n={draftId:"draft_9f3c2a",sourceFile:s,productId:t,counts:{assembliesExtracted:187,assembliesTotal:235,typesFound:1},types:[{nodeId:"node_scope_iwp",typeName:"Interior Wall Panel",instanceCount:187,requirements:[{nodeId:"node_req_bp",role:"BP",material:"SPF",qty:1,uom:"EA",dis
1playName:"Bottom Plate",dims:{lengthMm:571,crossSection:"3\xbd\xd71\xbd"},skuAttachment:null,conflict:null},{nodeId:"node_req_cap",role:"Cap Plate",material:"SPF",qty:1,uom:"EA",displayName:"Cap Plate",dims:{lengthMm:571,crossSection:"3\xbd\xd71\xbd"},skuAttachment:null,conflict:null},{nodeId:"node_req_stud",role:"Stud",material:"SPF",qty:3,uom:"EA",displayName:"Stud \xd7N(width)",dims:{lengthMm:2491,crossSection:"3\xbd\xd71\xbd"},skuAttachment:{skuId:"sku_spf_3x1",skuName:"SPF 3\xbd\xd71\xbd",supplier:"ABC Lumber"},conflict:null},{nodeId:"node_req_tp",role:"TP",material:"SPF",qty:1,uom:"EA",displayName:"Top Plate",dims:{lengthMm:571,crossSection:"3\xbd\xd71\xbd"},skuAttachment:null,conflict:null},{nodeId:"node_req_face",role:"face",material:'Birch Ply \xbd"',qty:2,uom:"EA",displayName:"Sheathing face \xd72",dims:{lengthMm:2438,widthMm:571},skuAttachment:null,conflict:null}]}],conflicts:[]};switch(e){case"no-clusters":return{...n,counts:{...n.counts,typesFound:0},types:[]};case"complete":return{...n,counts:{...n.counts,assembliesExtracted:n.counts.assembliesTotal}};case"conflict":return{...n,types:[{...n.types[0],requirements:n.types[0].requirements.map(e=>"Stud"===e.role?{...e,conflict:{field:"stud_count",pageA:3,valueA:"3",pageB:7,valueB:"4",nodeId:e.nodeId}}:e)}],conflicts:[{field:"stud_count",pageA:3,valueA:"3",pageB:7,valueB:"4",nodeId:"node_req_stud"}]};default:return n}}(u,x,d)},yield{type:"turn_end",thread_id:c}}async function*c(e){let t=e.threadId,s=e.humanResponse.approved;s?(yield{type:"tool_result",thread_id:t,tool_name:r,tool_use_id:"toolu_02WriteTreeXyz",tool_output:{draftId:"draft_9f3c2a",scopeIds:["stub_scope_iwp"],requirementIds:["stub_r_bp","stub_r_cap","stub_r_stud","stub_r_tp","stub_r_face"]}},yield{type:"text",thread_id:t,text:"Committed the catalog scope. The proposed nodes are now live on the product."}):yield{type:"text",thread_id:t,text:"Declined — nothing was written. The draft was discarded."},yield{type:"done",thread_id:t}}},715956:function(e,t,s){s.d(t,{Z:function(){return l},p:function(){return a}});let n=[{label:"Draft scope from a fab package",prompt:"Build a catalog scope from this fabrication package."},{label:"What's in this package?",prompt:"Summarize the assemblies in the uploaded fabrication package."}],a="catalog-library",r=[{label:"Bulk-import a catalog workbook",prompt:"Import this catalog workbook."},{label:"What will this import create?",prompt:"Summarize what this workbook will add to the catalog."}];function l(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"product",s="library"===t;return{endpoint:"/agent-loop/chat",title:"Merlin Catalog Agent",railLabel:"Catalog Agent",storageKey:"catalog-chat",conversationScopeKey:e,promptBubbles:s?r:n,placeholder:s?"Upload a catalog workbook to bulk-import, or ask about this import…":"Upload a fabrication package or ask about this product…",...s?{}:{enableVoiceInput:!0,voiceProvider:"wispr"}}}},98043:function(e,t,s){s.d(t,{Ps:function(){return r},hR:function(){return a},nx:function(){return l}});var n=s(23226);function a(e,t){let s=[];for(let n of e.types)if(!t.has(n.nodeId))for(let e of(s.push(n.nodeId),n.requirements))t.has(e.nodeId)||s.push(e.nodeId);return s}function r(e,t){let s=a(e,t),r=function(e,t){let s=[];for(let n of e.types){if(t.has(n.nodeId)){s.push(n.nodeId);continue}for(let e of n.requirements)t.has(e.nodeId)&&s.push(e.nodeId)}return s}(e,t),l=s.length>0?s.join(", "):"none",o=r.length>0?r.join(", "):"none";return["".concat(n.kJ," Commit the catalog scope from draft ").concat(e.draftId,"."),"Keep nodes: ".concat(l,"."),"Drop nodes: ".concat(o,".")].join("\n")}function l(e,t){for(let s of e.types)if(!t.has(s.nodeId)){for(let e of s.requirements)if(!t.has(e.nodeId)&&null!=e.conflict)return!0}return!1}},379983:function(e,t,s){function n(e,t){return e.filter(e=>{var s,n;let a=t.search.toLowerCase(),r=!a||(null!==(s=e.title)&&void 0!==s?s:"").toLowerCase().includes(a)||(null!==(n=e.description)&&void 0!==n?n:"").toLowerCase().includes(a)||e.tags.some(e=>e.toLowerCase().includes(a)),l=0===t.statuses.length||t.statuses.includes(e.status),o=0===t.tags.length||t.tags.some(t=>e.tags.includes(t));return r&&l&&o})}function a(e,t){var s,n,a,r;let l=[...e];switch(t){case"name":l.sort((e,t)=>
1(null!==(s=e.title)&&void 0!==s?s:"").localeCompare(null!==(n=t.title)&&void 0!==n?n:""));break;case"date":l.sort((e,t)=>(null!==(a=t.createdAt)&&void 0!==a?a:"").localeCompare(null!==(r=e.createdAt)&&void 0!==r?r:""))}return l}function r(e,t,s){return t&&s?[...e].sort((e,n)=>{let a=e[t],r=n[t];if(null==a&&null==r)return 0;if(null==a)return 1;if(null==r)return -1;let l="number"==typeof a&&"number"==typeof r?a-r:String(a).localeCompare(String(r));return"asc"===s?l:-l}):e}function l(e,t,s){var n;let a=e.filter(e=>e.name.trim()&&e.options.trim());if(0===a.length)return[];let r=a.map(e=>({name:e.name,options:e.options.split(",").map(e=>e.trim()).filter(Boolean)})),l=function e(t){if(0===t.length)return[{}];let[s,...n]=t,a=e(n),r=[];for(let e of s.options)for(let t of a)r.push({[s.name]:e,...t});return r}(r),o=l.filter(s=>t.every(t=>{if(!t.ifValue||!t.thenVariableId)return!0;let n=e.find(e=>e.id===t.ifVariableId),a=e.find(e=>e.id===t.thenVariableId);return!n||!a||s[n.name]!==t.ifValue||0!==t.thenAllowedValues.length&&t.thenAllowedValues.includes(s[a.name])})),i=e=>Object.entries(e).sort((e,t)=>{let[s]=e,[n]=t;return s.localeCompare(n)}).map(e=>{let[t,s]=e;return"".concat(t,"=").concat(s)}).join("||"),c=new Map(s.map(e=>[i(null!==(n=e.attributes)&&void 0!==n?n:{}),e]));return o.map(e=>{var t,s,n,a;let r=i(e),l=c.get(r),o=Object.values(e).join(" / ");return{id:null!==(t=null==l?void 0:l.id)&&void 0!==t?t:"computed-".concat(r),name:null!==(s=null==l?void 0:l.name)&&void 0!==s?s:o,attributes:e,tags:null!==(n=null==l?void 0:l.tags)&&void 0!==n?n:[],connectedProductRefs:null!==(a=null==l?void 0:l.connectedProductRefs)&&void 0!==a?a:[],isComputed:!l}})}function o(e){return"$"+e.toLocaleString("en-US",{maximumFractionDigits:0})}function i(e){return(100*e).toFixed(1)+"%"}function c(e,t){if(0===e.length)return[];let s=[];for(let t of e)for(let e of Object.keys(t.attributes))s.includes(e)||s.push(e);return s.map(s=>{let n=e=>Object.entries(t).every(t=>{let[n,a]=t;return n===s||!a||e[n]===a}),a=[];for(let t of e){if(!n(t.attributes))continue;let e=t.attributes[s];e&&!a.includes(e)&&a.push(e)}let r=t[s];return{name:s,options:a,selected:r&&a.includes(r)?r:null}})}function d(e,t){var s;let n=c(e,t);return 0===n.length||n.some(e=>null===e.selected)?null:null!==(s=e.find(e=>n.every(t=>e.attributes[t.name]===t.selected)))&&void 0!==s?s:null}s.d(t,{Sj:function(){return l},YC:function(){return r},ZP:function(){return o},Zj:function(){return a},at:function(){return i},ft:function(){return n},gr:function(){return function e(t){if(0===t.length)return[{}];let[s,...n]=t,a=e(n),r=[];for(let e of s.values)for(let t of a)r.push({[s.name]:e,...t});return r}},qX:function(){return c},w7:function(){return d}})}}]);

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.