1import{c as tt,r as x,j as e,B as A,z as Ne,aj as rt,E as Pe,x as ne,Y as U,ak as Z,D as me,v as Kt,I as ee,C as nt,e as lt,b as Ut,d as Lt,A as Ue,u as Ni,Q as Ci,i5 as Ai,T as $i,V as wi,W as ki,H as Zs}from"./index-PoezL6ES.js";import{u as le}from"./useMutation-Ca8K5WS4.js";import{b as $t,j as qi,k as mt,i as Ti,l as Ii,m as ei,n as Vi,h as Ri,r as Ei}from"./configuratorV2Applicability-p9Cy5tzX.js";import{j as At,k as Oi,l as Ht,m as Us,n as Pi,a as Di,C as Mi,b as Fi}from"./ConfiguratorV2HybridWizard-BNRUVx2K.js";import{S as _e}from"./switch-CefUtPZb.js";import{U as Gi}from"./upload-DqRoLmpJ.js";import{T as ct,a as dt,b as Ie,c as Q,d as ot,e as L}from"./table-D3jrLQ9V.js";import{D as ht,a as xt,b as pt,c as vt,f as jt}from"./dialog-DpAlSBQJ.js";import{A as Tt,a as It,b as Vt,c as Rt,d as Et,e as Ot,f as Pt,g as Dt}from"./alert-dialog-0cb3CD-T.js";import{S as fe,a as be,b as ye,c as Se,d as se}from"./select-Dl42Pozm.js";import{D as As}from"./dollar-sign-C-KZLvuf.js";import{C as _i}from"./clock-BfEl87gl.js";import{P as Qe}from"./plus-DluERz8Z.js";import{C as Xt}from"./chevron-right-BX8n297W.js";import{C as Qt}from"./check-2btNc0ui.js";import{S as zt}from"./square-pen-OLoR_E7W.js";import{T as Xe}from"./trash-2-CU89lXRj.js";import{T as St}from"./triangle-alert-y3f0iGYq.js";import{E as ti}from"./eye-off-BJP4KLxI.js";import{E as Bt}from"./eye-CJRmOkqm.js";import{S as ds}from"./search-CfTFAZri.js";import{D as Ui}from"./download-CMU_g_rn.js";import{R as $s}from"./refresh-cw-D2XhFFlK.js";import{C as Li}from"./chevron-left-CdL5MLBf.js";import{M as ws}from"./message-square-Dhbn9UXD.js";import{U as Qi}from"./user-C99Ik3Ui.js";import{I as si}from"./info-Dk6JCfWp.js";import{C as ii}from"./chevron-up-BuIq7ATC.js";import{C as zi}from"./ConfiguratorV2Chat-BQW3Ipa1.js";import{T as Mt}from"./textarea-CB-BTtM8.js";import{C as Ki}from"./circle-check-DmitUVA1.js";import{S as os}from"./WebsiteIcon-B4JIVpv0.js";import{C as ri}from"./checkbox-BgX6zsV-.js";import{H as Bi}from"./history-DbBx2hbp.js";import{W as Zt}from"./wrench-CNifcqUc.js";import{I as ks}from"./image-CpmH0r0G.js";import{S as ai}from"./send-CE-_poEZ.js";import{C as Ji}from"./radio-group-BGjfh-xU.js";import{P as Wi}from"./pencil-DlBIg4gJ.js";import{T as Hi,a as Yi,b as ps,c as vs}from"./tabs-DmcbQoIZ.js";import{S as Xi}from"./settings-C3snpZNB.js";import{P as Zi}from"./package-PqA1FGEh.js";import"./WizardPhotoUploadCard-CcyCY2oY.js";import"./link-Djfzl-D7.js";import"./camera-FVXdMiN6.js";import"./rotate-ccw-BoTPDSl7.js";import"./circle-check-big-CVeaLYX_.js";import"./minus-p1hQDmq8.js";import"./index-C90WnT18.js";import"./index-BDbsAqtD.js";import"./shopping-bag-CI-KDocT.js";import"./index-Clfhxc8F.js";/** 2 * @license lucide-react v0.564.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const er=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],ls=tt("arrow-down",er);/** 7 * @license lucide-react v0.564.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const tr=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],ni=tt("arrow-up",tr);/** 12 * @license lucide-react v0.564.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const sr=[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]],ir=tt("book-open",sr);/** 17 * @license lucide-react v0.564.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const rr=[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["line",{x1:"8",x2:"16",y1:"6",y2:"6",key:"x4nwl0"}],["line",{x1:"16",x2:"16",y1:"14",y2:"18",key:"wjye3r"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M8 18h.01",key:"lrp35t"}]],Ss=tt("calculator",rr);/** 22 * @license lucide-react v0.564.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const ar=[["path",{d:"M21.54 15H17a2 2 0 0 0-2 2v4.54",key:"1djwo0"}],["path",{d:"M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",key:"1tzkfa"}],["path",{d:"M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05",key:"14pb5j"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],nr=tt("earth",ar);/** 27 * @license lucide-react v0.564.0 - ISC 28 * 29 * This source code is licensed under the ISC license. 30 * See the LICENSE file in the root directory of this source tree. 31 */const lr=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-
315-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],Ns=tt("flag",lr);/** 32 * @license lucide-react v0.564.0 - ISC 33 * 34 * This source code is licensed under the ISC license. 35 * See the LICENSE file in the root directory of this source tree. 36 */const cr=[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],Wt=tt("folder-plus",cr);/** 37 * @license lucide-react v0.564.0 - ISC 38 * 39 * This source code is licensed under the ISC license. 40 * See the LICENSE file in the root directory of this source tree. 41 */const dr=[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]],qt=tt("git-branch",dr);/** 42 * @license lucide-react v0.564.0 - ISC 43 * 44 * This source code is licensed under the ISC license. 45 * See the LICENSE file in the root directory of this source tree. 46 */const or=[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]],li=tt("layers",or);/** 47 * @license lucide-react v0.564.0 - ISC 48 * 49 * This source code is licensed under the ISC license. 50 * See the LICENSE file in the root directory of this source tree. 51 */const ur=[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]],mr=tt("lightbulb",ur);/** 52 * @license lucide-react v0.564.0 - ISC 53 * 54 * This source code is licensed under the ISC license. 55 * See the LICENSE file in the root directory of this source tree. 56 */const gr=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],ci=tt("link-2",gr);/** 57 * @license lucide-react v0.564.0 - ISC 58 * 59 * This source code is licensed under the ISC license. 60 * See the LICENSE file in the root directory of this source tree. 61 */const hr=[["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"M3 10a2 2 0 0 0 2 2h3",key:"1npucw"}],["path",{d:"M3 5v12a2 2 0 0 0 2 2h3",key:"x1gjn2"}]],Yt=tt("list-tree",hr);/** 62 * @license lucide-react v0.564.0 - ISC 63 * 64 * This source code is licensed under the ISC license. 65 * See the LICENSE file in the root directory of this source tree. 66 */const xr=[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]],di=tt("lock-keyhole",xr);/** 67 * @license lucide-react v0.564.0 - ISC 68 * 69 * This source code is licensed under the ISC license. 70 * See the LICENSE file in the root directory of this source tree. 71 */const pr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]],vr=tt("panel-right",pr);/** 72 * @license lucide-react v0.564.0 - ISC 73 * 74 * This source code is licensed under the ISC license. 75 * See the LICENSE file in the root directory of this source tree. 76 */const jr=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],oi=tt("sliders-horizontal",jr);/** 77 * @license lucide-react v0.564.0 - ISC 78 * 79 * This source code is licensed under the ISC license. 80 * See the LICENSE file in the root directory of this source tree. 81 */const fr=[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]],br=tt("unlink",fr);/** 82 * @license lucide-react v0.564.0 - ISC 83 * 84 * This source code is licensed under the ISC license. 85 * See the LICENSE file in the root directory of this source tree. 86 */const yr=[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]],Sr=tt("wand-sparkles",yr),qs=["repair","alteration","standard"],ui={repair:"Repair",alteration:"Alteration",standard:"Standard"};function Nr(t){const s=t==null?void 0:t.trim().toLowerCase();return qs.includes(s)?s:null}function wt({value:t,onChange:s,className:i}){const[r,l]=x.useState(!1),[a,d]=x.useState(null),o=x.useRef(null),n=async c=>{l(!0),d(null);try{const y=new FormData;y.append("file",c);const f=await fetch("/api/upload/configurator-image",{method:"POST",body:y,credentials:"include",headers:{"X-Requested-With":"XMLHttpRequest"}}),p=await f.json();if(!f.ok||!p.success){const S=typeof p.error=="object"?p.error.message||JSON.stringify(p.error):p.error||"Upload failed";throw new Error(S)}s(p.cdnUrl)}catch(y){d(y.message||"Upload failed")}finally{l(!1),o.current&&(o.current.value="")}},u=c=>{var f;const y=(f=c.target.files)==null?void 0:f[0];y&&n(y)},h=()=>{s("")};return e.jsxs("div",{className:`flex items-center gap-3 ${i||""}`,children:[e.jsx("input",{ref:o,type:"file",accept:"image/jpeg,image/png,image/webp",className:"hidden",onChange:u}),t?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:t,alt:"Preview",className:"h-14 w-14 object-cover rounded border"}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:()=>{var c;return(c=o.current)==null?void 0:c.click()},disabled:r,children:r?e.jsx(Ne,{className:"h-3 w-3 animate-spin"}):"Replace"}),e.jsxs(A,{type:"button",variant:"ghost",size:"sm",onClick:h,className:"text-destructive h-6 text-xs",children:[e.jsx(rt,{className:"h-3 w-3 mr-1"}),"Remove"]})]})]}):e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:()=>{var c;return(c=o.current)==null?void 0:c.click()},disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"h-3 w-3 mr-1 animate-spin"}),"Uploading..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Gi,{className:"h-3 w-3 mr-1"}),"Upload Image"]})}),a&&e.jsx("span",{className:"text-xs text-destructive",children:a})]})}function We(t){return`$${(t/100).toFixed(2)}`}function ts(t){return`${t>0?"+":""}${We(t)}`}function Ts(t){return t.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"")}function Is(t){return/^[a-z0-9-]*$/.test(t)}function Ls(t,s){const i=qi(t,s);return i.isReachableLeaf||i.reason==="has_active_children"}const es={tierSlug:null,showImported:!1};function us({noun:t}){return e.jsxs("div",{className:"rounded-md border border-dashed p-6 text-center","data-testid":"manage-tier-empty-state",children:[e.jsxs("p",{className:"text-sm font-medium",children:["No generated ",t," for this tier."]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Switch to All tiers to author catalog definitions, then regenerate products to refresh this view."})]})}const Cr=["v1-","v1g-","v1s-","v1a-","v1t-","v1q-","v1v-"];function Ft(t){return Cr.some(s=>t.startsWith(s))}function ms(t,s,i,r){const l=x.useMemo(()=>t.filter(a=>Ft(r(a))).length,[t,r]);return x.useEffect(()=>
86{i==null||i(s.tierSlug?0:l)},[l,s.tierSlug,i]),x.useMemo(()=>s.tierSlug||s.showImported?t:t.filter(a=>!Ft(r(a))),[t,s.showImported,s.tierSlug,r])}const js=Oi[0];function Ar(t,s){return t.length===s.length&&s.every(i=>t.includes(i))?null:t}function $r(t,s,i){const r=t??i,l=r.includes(s)?r.filter(a=>a!==s):[...r,s];return Ar(l,i)}function wr(t){const s=t.find(r=>r.verdict==="applied")??t.find(r=>r.verdict==="fallback"),i=(s==null?void 0:s.rowId)!=null?` #${s.rowId}`:"";switch(s==null?void 0:s.code){case"exact_scope_override":return`Cell override${i}`;case"garment_scope_override":return`Garment override${i}`;case"service_scope_override":return`Service override${i}`;case"base_value_adjustment":return`Value default${i}`;default:return"Resolved value adjustment"}}function ss({label:t,value:s,source:i,tone:r="default"}){const l=r==="quote"?"text-amber-700":r==="muted"?"text-muted-foreground":"text-foreground";return e.jsxs("div",{className:"rounded border bg-muted/20 p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{className:"font-medium",children:t}),e.jsx("span",{className:`font-mono text-right ${l}`,children:s})]}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:i})]})}function kr({cellId:t,garmentSlug:s,garmentName:i,serviceSlug:r,serviceName:l,basePriceCents:a,requiresQuote:d,catalogTierSlug:o,onClose:n}){const{toast:u}=Pe(),[h,c]=x.useState({}),[y,f]=x.useState(""),[p,S]=x.useState(null),[T,C]=x.useState({priceAdjustmentCents:"",minutesAdjustment:""}),{data:v=[]}=ne({queryKey:["configV2ServiceAttributes",r,"pricingDrilldown",o??"all"],queryFn:async()=>(await U("query($s:String!,$tierSlug:String){ configV2ServiceAttributes(serviceSlug:$s,tierSlug:$tier
86Slug,productBacked:true){ id serviceSlug attributeSlug isRequired displayOrder tierScope attributeName attributeType } }",{s:r,tierSlug:o})).configV2ServiceAttributes}),{data:O=[]}=ne({queryKey:["configV2Attributes","pricingDrilldown",o??"all"],queryFn:async()=>(await U("query($tierSlug:String){ configV2Attributes(tierSlug:$tierSlug) { slug name type summaryLabel questionText displayOrder isActive values { id attributeSlug value label skuCode priceAdjustmentCents minutesAdjustment displayOrder isDefault isActive disclaimerText disclaimerRequiresAck hiddenForGarments } } }",{tierSlug:o})).configV2Attributes}),{data:P=[]}=ne({queryKey:["configV2GarmentAttributes",s,"pricingDrilldown",o??"all"],queryFn:async()=>(await U("query($garmentSlug:String!,$tierSlug:String){configV2GarmentAttributes(garmentSlug:$garmentSlug,tierSlug:$tierSlug,productBacked:true){id garmentSlug attributeSlug isRequired displayOrder tierScope isActive attributeName attributeType}}",{garmentSlug:s,tierSlug:o})).configV2GarmentAttributes}),{data:$=[]}=ne({queryKey:["configV2GarmentServiceScopes",t],queryFn:async()=>(await U("query($garmentServiceId:Int!){configV2GarmentServiceScopes(garmentServiceId:$garmentServiceId){id garmentServiceId attributeSlug attributeValueSlug}}",{garmentServiceId:t})).configV2GarmentServiceScopes}),{data:b=[]}=ne({queryKey:["configV2AttributeValueOverrides","cell",s,r],queryFn:async()=>(await U("query($garmentSlug:String!,$serviceSlug:String!,$exactScope:Boolean!){configV2AttributeValueOverrides(garmentSlug:$garmentSlug,serviceSlug:$serviceSlug,exactScope:$exactScope){id attributeValueId garmentSlug serviceSlug priceAdjustmentCents minutesAdjustment isActive createdAt}}",{garmentSlug:s,serviceSlug:r,exactScope:!0})).configV2AttributeValueOverrides.filter(_=>_.isActive)}),{data:j=[]}=ne({queryKey:["configV2AttributeValueOverrides","applicable",s,r],queryFn:async()=>(await U("query($garmentSlug:String!,$serviceSlug:String!){configV2AttributeValueOverrides(garmentSlug:$garmentSlug,serviceSlug:$serviceSlug){id attributeValueId garmentSlug serviceSlug priceAdjustmentCents minutesAdjustment isActive createdAt}}",{garmentSlug:s,serviceSlug:r})).configV2AttributeValueOverrides.filter(_=>_.isActive)}),{data:V=[]}=ne({queryKey:["configV2Tiers"],queryFn:async()=>(await U("query { configV2Tiers { slug name description catalogMode priceMultiplier isActive } }")).configV2Tiers}),R=x.useMemo(()=>o?V.find(k=>k.slug===o):y?V.find(k=>k.slug===y):V.find(k=>k.slug==="direct")||V.find(k=>k.isActive)||V[0],[V,y,o]),D=x.useMemo(()=>new Map(b.map(k=>[k.attributeValueId,k])),[b]),E=x.useMemo(()=>j.map(k=>({...k,garmentSlug:k.garmentSlug??null,serviceSlug:k.serviceSlug??null})),[j]),N=x.useMemo(()=>!P.length||!O.length?[]:[...P].filter(k=>k.isActive!==!1).sort((k,_)=>k.displayOrder-_.displayOrder).map(k=>{const _=O.find(re=>re.slug===k.attributeSlug);if(!_||At(_.type))return null;const z=(_.values||[]).filter(re=>re.isActive&&!mt(re,s));return z.length===0?null:{...k,attributeName:_.name,attributeType:_.type,values:[...z].sort((re,ae)=>re.displayOrder-ae.displayOrder)}}).filter(Boolean),[P,O,s]),m=le({mutationFn:async k=>U("mutation($garmentServiceId:Int!,$scopes:[ConfigV2GarmentServiceScopeInput!]!){configV2SetGarmentServiceScopes(garmentServiceId:$garmentServiceId,scopes:$scopes)}",{garmentServiceId:t,scopes:k}),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2GarmentServiceScopes",t]}),Z.invalidateQueries({queryKey:["configV2PricingMatrix"]}),u({title:"Availability updated"})},onError:k=>u({title:"Error",description:k.message,variant:"destructive"})}),G=le({mutationFn:async k=>k.id?U("mutation($id:Int!,$garmentSlug:String,$serviceSlug:String,$priceAdjustmentCents:Int,$minutesAdjustment:Int,$isActive:Boolean){configV2UpdateAttributeValueOverride(id:$id,garmentSlug:$garmentSlug,serviceSlug:$serviceSlug,priceAdjustmentCents:$priceAdjustmentCents,minutesAdjustment:$minutesAdjustment,isActive:$isActive){id}}",{...k,garmentSlug:s,serviceSlug:r,isActive:!0}):U("mutation($attributeValueId:Int!,$garmentSlug:String,$serviceSlug:String,$priceAdjustmentCents:Int!,$minutesAdjustment:Int!,$isActive:Boolean){configV2CreateAttributeValueOverride(attributeValueId:$attributeValueId,garmentSlug:$garmentSlug,serviceSlug:$serviceSlug,priceAdjustmentCents:$priceAdjustmentCents,minutesAdjustment:$minutesAdjustment,isActive:$isActive){id}}",{...k,garmentSlug:s,serviceSlug:r,isActive:!0}),onSuccess:()=>{S(null),Z.invalidateQueries({queryKey:["configV2AttributeValueOverrides","cell",s,r]}),Z.invalidateQueries({queryKey:["configV2AttributeValueOverrides","applicable",s,r]}),Z.invalidateQueries({queryKey:["configV2Attributes"]}),u({title:"Cell override saved",description:"Regenerate V2 products before this price is considered live."})},onError:k=>u({title:"Error",description:k.message,variant:"destructive"})}),X=le({mutationFn:async k=>U("mutation($id:Int!){configV2DeleteAttributeValueOverride(id:$id)}",{id:k}),onSuccess:()=>{S(null),Z.invalidateQueries({queryKey:["configV2AttributeValueOverrides","cell",s,r]}),Z.invalidateQueries({queryKey:["configV2AttributeValueOverrides","applicable",s,r]}),Z.invalidateQueries({queryKey:["configV2Attributes"]}),u({title:"Cell override deleted",description:"Regenerate V2 products before relying on this pricing change."})},onError:k=>u({title:"Error",description:k.message,variant:"destructive"})}),ce=k=>Ti({id:k.id,priceAdjustmentCents:k.priceAdjustmentCents,minutesAdjustment:k.minutesAdjustment},E,{garmentSlug:s,serviceSlug:r}),de=k=>ce(k).adjustment.priceAdjustmentCents,De=k=>{const _=D.get(k.id);S(k.id),C({priceAdjustmentCents:String((((_==null?void 0:_.priceAdjustmentCents)??k.priceAdjustmentCents)/100).toFixed(2)),minutesAdjustment:String((_==null?void 0:_.minutesAdjustment)??k.minutesAdjustment??0
86)})},ge=(k,_,z)=>{const re=$.filter(H=>H.attributeSlug!==k).map(H=>({attributeSlug:H.attributeSlug,attributeValueSlug:H.attributeValueSlug})),ae=$.filter(H=>H.attributeSlug===k),K=ae.map(H=>H.attributeValueSlug),q=ae.length===0?[_]:K.includes(_)?K.filter(H=>H!==_):[...K,_],F=q.length===0||q.length===z.length&&z.every(H=>q.includes(H))?[]:q;m.mutate([...re,...F.map(H=>({attributeSlug:k,attributeValueSlug:H}))])},qe=k=>{m.mutate($.filter(_=>_.attributeSlug!==k).map(_=>({attributeSlug:_.attributeSlug,attributeValueSlug:_.attributeValueSlug})))},Te=x.useMemo(()=>!v.length||!O.length?[]:[...v].filter(k=>!(R!=null&&R.slug)||$t(k.tierScope,R.slug)).sort((k,_)=>k.displayOrder-_.displayOrder).map(k=>{var re;const _=O.find(ae=>ae.slug===k.attributeSlug);if(!_||At(_.type))return null;const z=((re=_.values)==null?void 0:re.filter(ae=>ae.isActive&&!mt(ae,s)))||[];return z.length===0?null:{slug:_.slug,name:_.name,type:_.type,questionText:_.questionText||_.name,isRequired:k.isRequired,displayOrder:k.displayOrder,values:[...z].sort((ae,K)=>ae.displayOrder-K.displayOrder)}}).filter(Boolean),[v,O,R==null?void 0:R.slug,s]);x.useEffect(()=>{const k=new Map(Te.map(_=>[_.slug,new Set(_.values.map(z=>z.value))]));c(_=>{var ae;let z=!1;const re={..._};for(const[K,q]of Object.entries(_))(ae=k.get(K))!=null&&ae.has(q)||(delete re[K],z=!0);return z?re:_})},[Te]);const Ce=(R==null?void 0:R.priceMultiplier)??1,Fe=x.useMemo(()=>{const k=[];for(const _ of Te){const z=h[_.slug];if(z){const re=_.values.find(ae=>ae.value===z);if(re){const ae=ce(re);k.push({attributeName:_.name,valueName:re.label,cents:ae.adjustment.priceAdjustmentCents,source:wr(ae.reasons)})}}}return k},[Te,h,E,s,r]),ke=Fe.reduce((k,_)=>k+_.cents,0),M=a+ke,ue=Math.round(M*Ce),ie=Object.keys(h).length>0;return e.jsxs(nt,{className:"border-blue-200 bg-blue-50/30",children:[e.jsx(Ut,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Lt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ss,{className:"h-4 w-4 text-blue-600"}),"Pricing Breakdown: ",i," â ",l]}),e.jsx(A,{variant:"ghost",size:"sm",onClick:n,children:e.jsx(rt,{className:"h-4 w-4"})})]})}),e.jsxs(lt,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:"Attributes for this service"}),Te.length===0?e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No attributes linked to this service."}):e.jsx("div",{className:"space-y-2",children:Te.map(k=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm font-medium flex items-center gap-1",children:[k.name,k.isRequired&&e.jsx("span",{className:"text-orange-500 text-xs",children:"(required)"}),!k.isRequired&&e.jsx("span",{className:"text-muted-foreground text-xs",children:"(optional)"})]}),e.jsxs(fe,{value:h[k.slug]||"",onValueChange:_=>{c(_==="__none__"?z=>{const re={...z};return delete re[k.slug],re}:z=>({...z,[k.slug]:_}))},children:[e.jsx(be,{className:"h-8 text-sm bg-white","aria-label":`Select ${k.name}`,children:e.jsx(ye,{placeholder:`Select ${k.name.toLowerCase()}...`})}),e.jsxs(Se,{children:[e.jsx(se,{value:"__none__",children:"â None â"}),k.values.map(_=>{const z=de(_);return e.jsxs(se,{value:_.value,children:[_.label,z!==0&&e.jsxs("span",{className:`ml-2 text-xs ${z>0?"text-red-600":"text-green-600"}`,children:["(",ts(z),")"]})]},_.id)})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:k.values.map(_=>{const z=D.get(_.id),re=de(_),ae=p===_.id;return e.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-gray-100 px-1.5 py-0.5 text-[10px] text-gray-600",children:[e.jsxs("span",{children:[_.label,": ",re===0?"â":ts(re)]}),z&&e.jsx(me,{variant:"secondary",className:"h-4 px-1 text-[9px]",children:"cell"}),!o&&ae?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ee,{className:"h-5 w-14 px-1 text-[10px]",value:T.priceAdjustmentCents,onChange:K=>C(q=>({...q,priceAdjustmentCents:K.target.value}))}),e.jsx(ee,{className:"h-5 w-10 px-1 text-[10px]",value:T.minutesAdjustment,onChange:K=>C(q=>({...q,minutesAdjustment:K.target.value}))}),e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>G.mutate({id:z==null?void 0:z.id,attributeValueId:_.id,priceAdjustmentCents:Math.round(parseFloat(T.priceAdjustmentCents||"0")*100),minutesAdjustment:parseInt(T.minutesAdjustment||"0",10)||0}),disabled:G.isPending,children:e.jsx(Qt,{className:"h-3 w-3"})}),e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>S(null),children:e.jsx(rt,{className:"h-3 w-3"})})]}):o?null:e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>De(_),children:e.jsx(As,{className:"h-3 w-3"})}),z&&!o&&!ae&&e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>X.mutate(z.id),disabled:X.isPending,children:e.jsx(Xe,{className:"h-3 w-3 text-red-600"})})]},_.id)})})]},k.slug))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:"Price Calculator"}),V.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:"Tier"}),e.jsxs(fe,{value:(R==null?void 0:R.slug)||"",onValueChange:f,disabled:!!o,children:[e.jsx(be,{className:"h-8 text-sm bg-white",children:e.jsx(ye,{})}),e.jsx(Se,{children:[...V].sort((k,_)=>k.name.localeCompare(_.name)).map(k=>
86e.jsxs(se,{value:k.slug,children:[k.name," (",k.priceMultiplier,"x)"]},k.slug))})]})]}),e.jsxs("div",{className:"bg-white rounded-lg border p-3 space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Base price"}),e.jsx("span",{className:"font-mono",children:We(a)})]}),Fe.filter(k=>k.cents!==0).map((k,_)=>e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground truncate mr-2",children:[k.attributeName,": ",k.valueName]}),e.jsx("span",{className:`font-mono shrink-0 ${k.cents>0?"text-red-600":"text-green-600"}`,children:ts(k.cents)})]},_)),ie&&ke!==0&&e.jsxs("div",{className:"flex justify-between text-sm border-t pt-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Subtotal"}),e.jsx("span",{className:"font-mono",children:We(M)})]}),Ce!==1&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Ã ",R==null?void 0:R.name," tier (",Ce,"x)"]}),e.jsx("span",{className:"font-mono",children:We(ue)})]}),e.jsxs("div",{className:"flex justify-between text-base font-semibold border-t pt-2",children:[e.jsx("span",{children:"Final Price"}),e.jsx("span",{className:"font-mono text-blue-700",children:We(ue)})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Estimate only; completed selections are still validated by product matching before ordering."}),!ie&&Te.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground italic mt-1",children:"Select attribute values above to see the full price breakdown."})]}),e.jsxs("div",{className:"bg-white rounded-lg border p-3 space-y-2","data-testid":"pricing-provenance",children:[e.jsxs("div",{className:"flex items-center gap-1 text-sm font-medium text-muted-foreground",children:[e.jsx(si,{className:"h-3.5 w-3.5"}),"Price sources"]}),e.jsx(ss,{label:"Base price source",value:We(a),source:`${i} x ${l} cell #${t}`}),e.jsx(ss,{label:"Quote source",value:d?"Quote-required":"Fixed price",source:`${i} x ${l} cell #${t}`,tone:d?"quote":"muted"}),Fe.map(k=>e.jsx(ss,{label:`${k.attributeName}: ${k.valueName}`,value:ts(k.cents),source:k.source},`${k.attributeName}-${k.valueName}`)),e.jsx(ss,{label:"Tier multiplier",value:`${(R==null?void 0:R.name)??"Default"} (${Ce}x)`,source:`Final price ${We(ue)}`})]})]})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground",children:"Pre-service descriptor availability"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Empty scope means this service is available for every visible value on this garment."})]}),!o&&m.isPending&&e.jsx(Ne,{className:"h-4 w-4 animate-spin text-muted-foreground"})]}),N.length===0?e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No pre-service descriptors are attached to this garment."}):e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:N.map(k=>{const _=$.filter(K=>K.attributeSlug===k.attributeSlug).map(K=>K.attributeValueSlug),z=new Set(_),re=k.values.map(K=>K.value),ae=_.length===0;return e.jsxs("div",{className:"rounded-md border bg-white p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:k.attributeName}),e.jsx("div",{className:"text-xs text-muted-foreground",children:ae?"All values allowed":`${_.length} value${_.length===1?"":"s"} allowed`})]}),!o&&!ae&&e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:()=>qe(k.attributeSlug),children:"Allow all"})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:k.values.map(K=>{const q=!ae&&z.has(K.value);return e.jsx(me,{variant:q?"default":"outline",className:`${o?"":"cursor-pointer"} text-xs ${ae?"border-dashed":q?"":"opacity-50"}`,title:o?void 0:ae?`Restrict this service to ${K.label}`:q?`Remove ${K.label} from the allowed list`:`Allow ${K.label}`,onClick:o?void 0:()=>ge(k.attributeSlug,K.value,re),children:K.label},K.id)})})]},k.attributeSlug)})})]})]})]})}function qr({lens:t=es,onImportedCountChange:s}={}){const{toast:i}=Pe(),r=t.tierSlug!==null,[l,a]=x.useState(null),[d,o]=x.useState(""),[n,u]=x.useState(null),[h,c]=x.useState(""),[y,f]=x.use
86State(!1),[p,S]=x.useState({garmentSlug:"",serviceSlug:"",price:"",requiresQuote:!1}),[T,C]=x.useState("grid"),[v,O]=x.useState("pricing"),[P,$]=x.useState("all"),[b,j]=x.useState(null),[V,R]=x.useState(new Set),{data:D,isLoading:E}=ne({queryKey:["configV2PricingMatrix",t.tierSlug??"all"],queryFn:async()=>{const q=await U("query($tierSlug:String){configV2PricingMatrix(tierSlug:$tierSlug){garments{slug name displayOrder isPriceable hasActiveChildren}services{slug name category displayOrder}cells}}",{tierSlug:t.tierSlug});return{...q.configV2PricingMatrix,cells:JSON.parse(q.configV2PricingMatrix.cells)}}}),{data:N=[]}=ne({queryKey:["configV2Garments"],queryFn:async()=>(await U("query { configV2Garments { slug name category parentSlug displayOrder isActive isPriceable hasActiveChildren } }")).configV2Garments}),{data:m=[]}=ne({queryKey:["configV2Services"],queryFn:async()=>(await U("query { configV2Services { slug name category description displayOrder isActive } }")).configV2Services}),{data:G=[]}=ne({queryKey:["configV2Attributes","pricingMatrixExpanded",t.tierSlug??"all"],queryFn:async()=>(await U("query($tierSlug:String){configV2Attributes(tierSlug:$tier
86Slug){slug name type questionText displayOrder isActive values{id attributeSlug value label skuCode priceAdjustmentCents minutesAdjustment displayOrder isDefault isActive disclaimerText disclaimerRequiresAck}}}",{tierSlug:t.tierSlug})).configV2Attributes,enabled:V.size>0}),[X,ce]=x.useState({}),[de,De]=x.useState(new Set),ge=async q=>{if(!X[q]){De(F=>new Set(F).add(q));try{const F=(await U("query($serviceSlug:String!,$tierSlug:String){configV2ServiceAttributes(serviceSlug:$serviceSlug,tierSlug:$tierSlug,productBacked:true){id serviceSlug attributeSlug isRequired displayOrder}}",{serviceSlug:q,tierSlug:t.tierSlug})).configV2ServiceAttributes;ce(H=>({...H,[q]:F}))}finally{De(F=>{const H=new Set(F);return H.delete(q),H})}}},qe=x.useMemo(()=>{const q={};if(!G.length)return q;for(const F of Array.from(V)){const H=X[F];H&&(q[F]=[...H].sort((W,xe)=>W.displayOrder-xe.displayOrder).map(W=>{const xe=G.find($e=>$e.slug===W.attributeSlug);if(!xe)return null;const J=(xe.values||[]).filter($e=>$e.isActive);return{slug:xe.slug,name:xe.name,questionText:xe.questionText||xe.name,isRequired:W.isRequired,displayOrder:W.displayOrder,values:[...J].sort(($e,oe)=>$e.displayOrder-oe.displayOrder)}}).filter(Boolean))}return q},[V,X,G]),Te=q=>{R(F=>{const H=new Set(F);return H.has(q)?H.delete(q):(H.add(q),ge(q)),H})},Ce=x.useMemo(()=>D?D.garments.filter(q=>Ft(q.slug)).length+D.services.filter(q=>Ft(q.slug)).length:0,[D]);x.useEffect(()=>{s==null||s(t.tierSlug?0:Ce)},[Ce,t.tierSlug,s]),x.useEffect(()=>{R(new Set),ce({})},[t.tierSlug]),x.useEffect(()=>{r&&(a(null),u(null),f(!1))},[r]);const Fe=le({mutationFn:async q=>U("mutation($garmentSlug:String!,$serviceSlug:String!,$basePriceCents:Int!,$requiresQuote:Boolean){configV2CreateGarmentService(garmentSlug:$garmentSlug,serviceSlug:$serviceSlug,basePriceCents:$basePriceCents,requiresQuote:$requiresQuote){id}}",q),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2PricingMatrix"]}),Z.invalidateQueries({queryKey:["configV2GarmentServices"]}),i({title:"Created"}),f(!1),S({garmentSlug:"",serviceSlug:"",price:"",requiresQuote:!1})},onError:q=>i({title:"Error",description:q.message,variant:"destructive"})}),ke=le({mutationFn:async q=>U("mutation($id:Int!,$basePriceCents:Int,$standardMinutes:Int,$requiresQuote:Boolean,$isActive:Boolean){configV2UpdateGarmentService(id:$id,basePriceCents:$basePriceCents,standardMinutes:$standardMinutes,requiresQuote:$requiresQuote,isActive:$isActive){id}}",q),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2PricingMatrix"]}),Z.invalidateQueries({queryKey:["configV2GarmentServices"]}),a(null),u(null)},onError:q=>i({title:"Error",description:q.message,variant:"destructive"})});if(E)return e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})});if(!D)return null;const M=t.tierSlug!==null||t.showImported,ue=[...D.garments].filter(q=>M||!Ft(q.slug)).sort((q,F)=>q.displayOrder-F.displayOrder),ie=N.filter(q=>Ls(N,q.slug)).sort((q,F)=>q.displayOrder-F.displayOrder),k=m.filter(q=>q.isActive!==!1).sort((q,F)=>q.displayOrder-F.displayOrder),_=D.services.filter(q=>M||!Ft(q.slug)),z=Array.from(new Set(_.map(q=>q.category))).sort(),re=P==="all"?[..._].sort((q,F)=>q.displayOrder-F.displayOrder):_.filter(q=>q.category===P).sort((q,F)=>q.displayOrder-F.displayOrder),ae=ue.length*re.length,K=Object.keys(D.cells).filter(q=>{const[F,H]=q.split("|");return ue.some(W=>W.slug===F)&&re.some(W=>W.slug===H)}).length;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(fe,{value:P,onValueChange:$,children:[e.jsx(be,{className:"w-48",children:e.jsx(ye,{placeholder:"All Categories"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"all",children:"All Categories"}),z.map(q=>e.jsx(se,{value:q,children:q},q))]})]}),e.jsxs(me,{variant:"outline",children:[K," / ",ae," configured"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center border rounded-md overflow-hidden",children:[e.jsxs(A,{size:"sm",variant:v==="pricing"?"default":"ghost",className:"rounded-none h-8 px-3",onClick:()=>O("pricing"),children:[e.jsx(As,{className:"h-3 w-3 mr-1"}),"Pricing"]}),e.jsxs(A,{size:"sm",variant:v==="minutes"?"default":"ghost",className:"rounded-none h-8 px-3",onClick:()=>O("minutes"),children:[e.jsx(_i,{className:"h-3 w-3 mr-1"}),"Minutes"]})]}),e.jsx("div",{className:"w-px h-6 bg-border"}),e.jsx(A,{size:"sm",variant:T==="grid"?"default":"outline",onClick:()=>C("grid"),children:"Grid"}),e.jsx(A,{size:"sm",variant:T==="list"?"default":"outline",onClick:()=>C("list"),children:"List"}),!r&&e.jsxs(A,{size:"sm",onClick:()=>f(!0),children:[e.jsx(Qe,{className:"h-4 w-4 mr-1"}),"Add"]})]})]}),r&&(ue.length===0||_.length===0)&&e.jsx(us,{noun:"catalog rows"}),T==="grid"?(()=>{const q=V.size>0,F=re.some(H=>{var W;return V.has(H.slug)&&(((W=qe[H.slug])==null?void 0:W.length)??0)>0}
86);return e.jsx("div",{className:"overflow-x-auto border rounded-lg",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsxs("thead",{children:[q&&F&&e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"sticky left-0 bg-muted/50 z-10",rowSpan:1}),re.map(H=>{const W=V.has(H.slug),xe=qe[H.slug]||[],J=xe.reduce(($e,oe)=>$e+oe.values.length,0);return W&&J>0?e.jsxs(x.Fragment,{children:[e.jsx("th",{className:"p-1 text-center bg-muted/50 border-l",rowSpan:1}),xe.map($e=>e.jsxs("th",{colSpan:$e.values.length,className:"p-1 text-center text-[10px] font-medium bg-gray-100 border-l border-r text-gray-500 whitespace-nowrap",children:[$e.name,$e.isRequired?e.jsx("span",{className:"text-orange-400 ml-0.5",children:"*"}):null]},$e.slug))]},H.slug):e.jsx("th",{className:"bg-muted/50",rowSpan:1},H.slug)})]}),e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"sticky left-0 bg-muted/50 z-10 p-2 text-left font-medium min-w-[140px]",children:"Garment"}),re.map(H=>{const W=V.has(H.slug),xe=qe[H.slug]||[],J=xe.reduce(($e,oe)=>$e+oe.values.length,0);return e.jsxs(x.Fragment,{children:[e.jsx("th",{className:`p-2 text-center font-medium min-w-[100px] whitespace-nowrap ${W&&J>0?"border-l":""}`,children:e.jsxs("button",{className:"inline-flex items-center gap-1 hover:text-blue-600 transition-colors",onClick:()=>Te(H.slug),title:W?"Collapse attributes":"Expand attributes",children:[W&&de.has(H.slug)?e.jsx(Ne,{className:"h-3 w-3 animate-spin"}):W?e.jsx(Kt,{className:"h-3 w-3"}):e.jsx(Xt,{className:"h-3 w-3"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs",children:H.name}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:H.category})]})]})}),W&&J>0&&xe.map($e=>$e.values.map(oe=>e.jsx("th",{className:"p-1 text-center min-w-[70px] bg-gray-50 border-l text-[10px] font-normal text-gray-500 whitespace-nowrap",title:`${$e.name}: ${oe.label}`,children:e.jsx("div",{className:"truncate max-w-[80px]",children:oe.label})},`${$e.slug}-${oe.value}`)))]},H.slug)})]})]}),e.jsx("tbody",{children:ue.map(H=>e.jsxs("tr",{className:"border-b hover:bg-muted/30",children:[e.jsx("td",{className:"sticky left-0 bg-background z-10 p-2 font-medium border-r",children:H.name}),re.map(W=>{const xe=`${H.slug}|${W.slug}`,J=D.cells[xe],$e=l===xe,oe=V.has(W.slug),Ye=qe[W.slug]||[],g=Ye.reduce((Ae,Ve)=>Ae+Ve.values.length,0),B=H.hasActiveChildren,ze=B?"Template":"Sellable",Ke=Ls(N,H.slug),ve=!J&&r?e.jsx("td",{className:`p-1 text-center text-xs text-muted-foreground/40 ${oe&&g>0?"border-l":""}`,children:"â"},W.slug):J?e.jsx("td",{className:`p-1 text-center ${J.isActive?"":"opacity-40"} ${oe&&g>0?"border-l":""}`,children:v==="pricing"?$e?e.jsxs("div",{className:"flex items-center gap-0.5 justify-center",children:[e.jsx("span",{className:"text-xs",children:"$"}),e.jsx(ee,{className:"w-16 h-6 text-xs px-1",value:d,autoFocus:!0,onChange:Ae=>o(Ae.target.value),onKeyDown:Ae=>{Ae.key==="Enter"&&ke.mutate({id:J.id,basePriceCents:Math.round(parseFloat(d)*100)}),Ae.key==="Escape"&&a(null)},onBlur:()=>{d&&parseFloat(d)>0?ke.mutate({id:J.id,basePriceCents:Math.round(parseFloat(d)*100)}):a(null)}})]}):e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{className:`w-full p-1 rounded text-xs font-mono ${r?"cursor-default":"cursor-pointer hover:bg-muted/50"}`,onClick:()=>{r||(a(xe),o((J.basePriceCents/100).toFixed(2)))},onContextMenu:Ae=>{var Ve;r||(Ae.preventDefault(),u(xe),c(((Ve=J.standardMinutes)==null?void 0:Ve.toString())??""))},title:`${H.name} - ${W.name}: ${We(J.basePriceCents)}${J.standardMinutes!=null?` | ${J.standardMinutes}min`:""}`,children:[e.jsx("div",{children:We(J.basePriceCents)}),e.jsx("div",{className:`text-[10px] font-sans ${B?"text-blue-700":"text-emerald-700"}`,children:ze}),J.standardMinutes!=null&&e.jsxs("div",{className:"text-[10px] text-muted-foreground font-sans",children:[J.standardMinutes,"m"]}),J.requiresQuote&&e.jsx("div",{className:"text-[10px] text-amber-700 font-sans",children:"Quote"})]}),e.jsx("button",{className:`absolute bottom-0 left-0 p-0.5 transition-opacity rounded-full shadow-sm border ${J.requiresQuote?"opacity-100 bg-amber-100 hover:bg-amber-200 border-amber-300":"opacity-0 group-hover:opacity-100 bg-white hover:bg-muted border-border"}`,disabled:r,onClick:Ae=>{Ae.stopPropagation(),ke.mutate({id:J.id,requiresQuote:!J.requiresQuote})},"aria-pressed":J.requiresQuote,"aria-label":`${J.requiresQuote?"Disable":"Enable"} quote requirement for ${H.name} ${W.name}`,title:J.requiresQuote?"Requires quote":"Mark as requires quote",children:e.jsx(Ns,{className:`h-3 w-3 ${J.requiresQuote?"text-amber-700":"text-muted-foreground"}`})}),e.jsx("button",{className:"absolute bottom-0 right-0 p-0.5 bg-blue-50 hover:bg-blue-100 rounded-full shadow-sm border border-blue-200",onClick:Ae=>{Ae.stopPropagation(),j({garmentSlug:H.slug,garmentName:H.name,serviceSlug:W.slug,serviceName:W.name,basePriceCents:J.basePriceCents,requiresQuote:J.requiresQuote,cellId:J.id})},"aria-label":`Explain price and quote for ${H.name} ${W.name}`,title:"Explain price and quote",children:e.jsx(Ss,{className:"h-3 w-3 text-blue-600"})})]}):n===xe?e.jsxs("div",{className:"flex items-center gap-0.5 justify-center",children:[e.jsx(ee,{className:"w-14 h-6 text-xs px-1",value:h,autoFocus:!0,placeholder:"min",onChange:Ae=>c(Ae.target.value),onKeyDown:Ae=>{if(Ae.key==="Enter"){const Ve=h.trim()===""?null:parseInt(h);ke.mutate({id:J.id,standardMinutes:Ve})}Ae.key==="Escape"&&u(null)},onBlur:()=>{const Ae=h.trim()===""?null:parseInt(h);Ae!==J.standardMinutes?ke.mutate({id:J.id,standardMinutes:Ae}):u(null)}}),e.jsx("span",{className:"text-[10px]",children:"min"})]}):e.jsxs("button",{className:`w-full p-1 rounded text-xs font-mono ${r?"cursor-default":"cursor-pointer hover:bg-muted/50"}`,onClick:()=>{var Ae;r||(u(xe),c(((Ae=J.standardMinutes)==null?void 0:Ae.toString())??""))},title:`${H.name} - ${W.name}: ${J.standardMinutes!=null?`${J.standardMinutes}min`:"Not set"}${J.basePriceCents?` | ${We(J.basePriceCents)}`:""}`,children:[e.jsx("div",{children:J.standardMinutes!=null?`${J.standardMinutes}
86m`:e.jsx("span",{className:"text-muted-foreground/40",children:"â"})}),e.jsx("div",{className:`text-[10px] font-sans ${B?"text-blue-700":"text-emerald-700"}`,children:ze}),e.jsx("div",{className:"text-[10px] text-muted-foreground font-sans",children:We(J.basePriceCents)}),J.requiresQuote&&e.jsx("div",{className:"text-[10px] text-amber-700 font-sans",children:"Quote"})]})},W.slug):e.jsx("td",{className:`p-1 text-center ${oe&&g>0?"border-l":""}`,children:e.jsx("button",{className:`w-full h-full p-2 rounded text-xs ${!r&&Ke?"text-muted-foreground/40 hover:bg-muted/50 hover:text-muted-foreground":"cursor-not-allowed text-muted-foreground/20"}`,disabled:r||!Ke,title:r?"This tier lens is read-only":Ke?B?"Add template service mapping":"Add sellable service mapping":"Service mappings can only be added to reachable active garments",onClick:()=>{Ke&&(S({garmentSlug:H.slug,serviceSlug:W.slug,price:"",requiresQuote:!1}),f(!0))},children:"+"})},W.slug),Oe=oe&&g>0?Ye.flatMap(Ae=>Ae.values.map(Ve=>e.jsx("td",{className:"p-1 text-center bg-gray-50/50 border-l cursor-pointer hover:bg-gray-100",onClick:()=>i({title:"Attribute pricing",description:r?"Switch to All tiers to change attribute prices.":"Change attribute prices using the Attributes tab."}),title:`${Ae.name}: ${Ve.label} â ${Ve.priceAdjustmentCents===0?"No adjustment":(Ve.priceAdjustmentCents>0?"+":"")+We(Ve.priceAdjustmentCents)}`,children:e.jsx("span",{className:"text-xs font-mono text-gray-400",children:Ve.priceAdjustmentCents===0?"â":`${Ve.priceAdjustmentCents>0?"+":""}${We(Ve.priceAdjustmentCents)}`})},`${Ae.slug}-${Ve.value}`))):null;return e.jsxs(x.Fragment,{children:[ve,Oe]},W.slug)})]},H.slug))})]})})})():e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"Garment"}),e.jsx(Q,{children:"Role"}),e.jsx(Q,{children:"Service"}),e.jsx(Q,{children:"Category"}),e.jsx(Q,{children:"Base Price"}),e.jsx(Q,{children:"Std Minutes"}),e.jsx(Q,{children:"Quote"}),e.jsx(Q,{children:"Active"}),e.jsx(Q,{children:e.jsx("span",{className:"sr-only",children:"Price sources"})})]})}),e.jsx(ot,{children:Object.entries(D.cells).filter(([q])=>{const[F,H]=q.split("|");return ue.some(W=>W.slug===F)&&re.some(W=>W.slug===H)}).sort(([q],[F])=>{const[H]=q.split("|"),[W]=F.split("|");return H.localeCompare(W)}).map(([q,F])=>{const[H,W]=q.split("|"),xe=ue.find(oe=>oe.slug===H),J=re.find(oe=>oe.slug===W);if(!xe||!J)return null;const $e=xe.hasActiveChildren;return e.jsxs(Ie,{children:[e.jsx(L,{children:xe.name}),e.jsx(L,{children:e.jsx(me,{variant:$e?"outline":"secondary",className:$e?"border-blue-300 text-blue-700":"border-emerald-200 text-emerald-700",children:$e?"Template":"Sellable"})}),e.jsx(L,{children:J.name}),e.jsx(L,{children:e.jsx(me,{variant:"outline",children:J.category})}),e.jsx(L,{children:l===q?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"$"}),e.jsx(ee,{className:"w-24 h-8",value:d,onChange:oe=>o(oe.target.value),onKeyDown:oe=>{oe.key==="Enter"&&ke.mutate({id:F.id,basePriceCents:Math.round(parseFloat(d)*100)})}}),e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>ke.mutate({id:F.id,basePriceCents:Math.round(parseFloat(d)*100)}),children:e.jsx(Qt,{className:"h-3 w-3"})}),e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>a(null),children:e.jsx(rt,{className:"h-3 w-3"})})]}):e.jsx("span",{className:r?"":"cursor-pointer hover:underline",onClick:()=>{r||(a(q),o((F.basePriceCents/100).toFixed(2)))},children:We(F.basePriceCents)})}),e.jsx(L,{children:n===q?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ee,{className:"w-20 h-8",value:h,placeholder:"â",onChange:oe=>c(oe.target.value),onKeyDown:oe=>{if(oe.key==="Enter"){const Ye=h.trim()===""?null:parseInt(h);ke.mutate({id:F.id,standardMinutes:Ye})}oe.key==="Escape"&&u(null)}}),e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>{const oe=h.trim()===""?null:parseInt(h);ke.mutate({id:F.id,standardMinutes:oe})},children:e.jsx(Qt,{className:"h-3 w-3"})}),e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>u(null),children:e.jsx(rt,{className:"h-3 w-3"})})]}):e.jsx("span",{className:r?"":"cursor-pointer hover:underline",onClick:()=>{var oe;r||(u(q),c(((oe=F.standardMinutes)==null?void 0:oe.toString())??""))},children:F.standardMinutes!=null?`${F.standardMinutes}m`:"â"})}),e.jsx(L,{children:e.jsx(_e,{checked:F.requiresQuote,disabled:r,onCheckedChange:oe=>ke.mutate({id:F.id,requiresQuote:oe}),"aria-label":`Requires quote for ${xe.name} ${J.name}`})}),e.jsx(L,{children:e.jsx(_e,{checked:F.isActive,disabled:r,onCheckedChange:oe=>ke.mutate({id:F.id,isActive:oe})})}),e.jsx(L,{children:e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0","aria-label":`Explain price and quote for ${xe.name} ${J.name}`,title:"Explain price and quote",onClick:()=>j({garmentSlug:xe.slug,garmentName:xe.name,serviceSlug:J.slug,serviceName:J.name,basePriceCents:F.basePriceCents,requiresQuote:F.requiresQuote,cellId:F.id}),children:e.jsx(Ss,{className:"h-4 w-4 text-blue-600"})})})]},q)})})]}),b&&e.jsx(kr,{cellId:b.cellId,garmentSlug:b.garmentSlug,garmentName:b.garmentName,serviceSlug:b.
86serviceSlug,serviceName:b.serviceName,basePriceCents:b.basePriceCents,requiresQuote:b.requiresQuote,catalogTierSlug:t.tierSlug,onClose:()=>j(null)},`${b.garmentSlug}-${b.serviceSlug}`),e.jsx(ht,{open:y,onOpenChange:f,children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsx(vt,{children:"Add Service Mapping"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(fe,{value:p.garmentSlug,onValueChange:q=>S(F=>({...F,garmentSlug:q})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select garment"})}),e.jsx(Se,{children:ie.map(q=>e.jsx(se,{value:q.slug,children:q.name},q.slug))})]}),e.jsxs(fe,{value:p.serviceSlug,onValueChange:q=>S(F=>({...F,serviceSlug:q})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select service"})}),e.jsx(Se,{children:k.map(q=>e.jsx(se,{value:q.slug,children:q.name},q.slug))})]}),e.jsx(ee,{placeholder:"Price (dollars)",value:p.price,onChange:q=>S(F=>({...F,price:q.target.value}))}),e.jsxs("div",{className:"flex items-center justify-between rounded-md border px-3 py-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Requires quote"}),e.jsx(_e,{checked:p.requiresQuote,onCheckedChange:q=>S(F=>({...F,requiresQuote:q}))})]})]}),e.jsx(jt,{children:e.jsx(A,{onClick:()=>Fe.mutate({garmentSlug:p.garmentSlug,serviceSlug:p.serviceSlug,basePriceCents:Math.round(parseFloat(p.price)*100),requiresQuote:p.requiresQuote}),disabled:!p.garmentSlug||!p.serviceSlug||!p.price,children:Fe.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):"Add"})})]})})]})}function Tr({lens:t=es,onImportedCountChange:s}={}){const{toast:i}=Pe(),r=t.tierSlug!==null,[l,a]=x.useState(!1),[d,o]=x.useState(null),[n,u]=x.useState({slug:"",name:"",parentSlug:"root",childQuestionText:"",imageUrl:""}),[h,c]=x.useState(null),[y,f]=x.useState("root"),[p,S]=x.useState(null),[T,C]=x.useState(!1),v=l&&n.parentSlug!=="root"?n.parentSlug:null,{data:O=[],isLoading:P}=ne({queryKey:["configV2Garments"],queryFn:async()=>(await U("query { configV2Garments { slug name category parentSlug childQuestionText imageUrl displayOrder isActive isPriceable hasActiveChildren hasVisibleDescendant } }")).configV2Garments}),{data:$=[],isLoading:b}=ne({queryKey:["configV2Garments","manageCatalogLens",t.tierSlug],queryFn:async()=>(await U("query($tierSlug:String!){configV2Garments(tierSlug:$tier
86Slug,productBacked:true){slug name category parentSlug childQuestionText imageUrl displayOrder isActive isPriceable hasActiveChildren hasVisibleDescendant}}",{tierSlug:t.tierSlug})).configV2Garments,enabled:!!t.tierSlug}),j=t.tierSlug?$:O,V=ms(j,t,s,I=>I.slug),{data:R,isFetching:D}=ne({queryKey:["configV2GarmentDeletionImpact",h],queryFn:async()=>(await U("query($slug:String!){configV2GarmentDeletionImpact(slug:$slug){slug entityName childSlugs activeChildSlugs childCount activeChildCount serviceCount skuCount canDelete blockingReasons}}",{slug:h})).configV2GarmentDeletionImpact,enabled:!!h}),{data:E,isFetching:N}=ne({queryKey:["configV2GarmentDeletionImpact",v],queryFn:async()=>(await U("query($slug:String!){configV2GarmentDeletionImpact(slug:$slug){slug entityName childSlugs activeChildSlugs childCount activeChildCount serviceCount skuCount canDelete blockingReasons}}",{slug:v})).configV2GarmentDeletionImpact,enabled:!!v}),{data:m=[]}=ne({queryKey:["configV2Attributes","garmentsPage"],queryFn:async()=>(await U("query { configV2Attributes { slug name type isActive } }")).configV2Attributes}),{data:G=[]}=ne({queryKey:["configV2Tiers"],queryFn:async()=>(await U("query { configV2Tiers { slug name description catalogMode priceMultiplier isActive } }")).configV2Tiers}),{data:X=[],refetch:ce}=ne({queryKey:["configV2GarmentAttributes",p,"garmentsPage",t.tierSlug??"all"],queryFn:async()=>p?(await U("query($garmentSlug:String!,$tierSlug:String){configV2GarmentAttributes(garmentSlug:$garmentSlug,tierSlug:$tier
86Slug,productBacked:true){id garmentSlug attributeSlug isRequired displayOrder tierScope isActive attributeName attributeType}}",{garmentSlug:p,tierSlug:t.tierSlug})).configV2GarmentAttributes:[],enabled:!!p}),de=()=>{Z.invalidateQueries({queryKey:["configV2Garments"]}),Z.invalidateQueries({queryKey:["configV2PricingMatrix"]}),Z.invalidateQueries({queryKey:["configV2GarmentServices"]})},De=le({mutationFn:async I=>U("mutation($slug:String!,$name:String!,$parentSlug:String,$childQuestionText:String,$imageUrl:String){configV2CreateGarment(slug:$slug,name:$name,parentSlug:$parentSlug,childQuestionText:$childQuestionText,imageUrl:$imageUrl){slug}}",I),onSuccess:()=>{de(),i({title:"Garment created"}),ie()},onError:I=>i({title:"Error",description:I.message,variant:"destructive"})}),ge=le({mutationFn:async I=>U("mutation($slug:String!,$name:String,$parentSlug:String,$childQuestionText:String,$imageUrl:String,$isActive:Boolean){configV2UpdateGarment(slug:$slug,name:$name,parentSlug:$parentSlug,childQuestionText:$childQuestionText,imageUrl:$imageUrl,isActive:$isActive){slug}}",I),onSuccess:()=>{de(),i({title:"Updated"}),ie()},onError:I=>i({title:"Error",description:I.message,variant:"destructive"})}),qe=le({mutationFn:async I=>{const Y=(await U('query($slug:String!){configV2DeactivationPreview(entityType:"garment",slug:$slug){canDeactivate dependencyBlockers{garmentSlug serviceSlug dependencySetIds}}}',{slug:I})).configV2DeactivationPreview;if(!Y.canDeactivate){const he=Y.dependencyBlockers.map(pe=>`${pe.garmentSlug}/${pe.serviceSlug} (rule set ${pe.dependencySetIds.join(", ")})`).join("; ");throw new Error(`Cannot deactivate: ${Y.dependencyBlockers.length} cell(s) are used as attachment-dependency rule contexts â ${he}. Move or remove those rules first.`)}return U('mutation($slug:String!){configV2DeactivateEntity(entityType:"garment",slug:$slug,synonymStrategy:"keep_active"){deactivatedProducts}}',{slug:I})},onSuccess:()=>{de(),i({title:"Garment branch deactivated"})},onError:I=>i({title:"Error",description:I.message,variant:"destructive"})}),Te=le({mutationFn:async I=>U('mutation($slug:String!){configV2ReactivateEntity(entityType:"garment",slug:$slug,reactivateSynonyms:false,reactivateGarmentServices:true){reactivatedGarmentServices}}',{slug:I}),onSuccess:()=>{de(),i({title:"Garment branch reactivated"})},onError:I=>i({title:"Error",description:I.message,variant:"destructive"})}),Ce=le({mutationFn:async I=>U("mutation($slug:String!){configV2DeleteGarment(slug:$slug)}",{slug:I}),onSuccess:()=>{de(),i({title:"Deleted"}),c(null)},onError:I=>i({title:"Error",description:I.message,variant:"destructive"})}),Fe=le({mutationFn:async I=>U("mutation($slug:String!,$newParentSlug:String){configV2ReassignGarmentChildren(slug:$slug,newParentSlug:$newParentSlug)}",I),onSuccess:(I,te)=>{de(),Z.invalidateQueries({queryKey:["configV2GarmentDeletionImpact",te.slug]}),i({title:"Children reassigned"}),f("root")},onError:I=>i({title:"Error",description:I.message,variant:"destructive"})}),ke=le({mutationFn:async I=>U("mutation($slugs:[String!]!){configV2ReorderGarments(slugs:$slugs)}",{slugs:I}),onSuccess:()=>de()}),M=le({mutationFn:async I=>U("mutation($garmentSlug:String!,$attributes:[ConfigV2GarmentAttributeInput!]!){configV2SetGarmentAttributes(garmentSlug:$garmentSlug,attributes:$attributes)}",I),onSuccess:()=>{ce(),Z.invalidateQueries({queryKey:["configV2GarmentAttributes",p]}),i({title:"Garment descriptors updated"})},onError:I=>i({title:"Error",description:I.message,variant:"destructive"})});x.useEffect(()=>{h&&f("root")},[h]);const ue=()=>({slug:n.slug,name:n.name,parentSlug:n.parentSlug==="root"?null:n.parentSlug,childQuestionText:n.childQuestionText.trim()||null,imageUrl:n.imageUrl}),ie=()=>{a(!1),o(null),u({slug:"",name:"",parentSlug:"root",childQuestionText:"",imageUrl:""})},k=I=>{o(I),u({slug:I.slug,name:I.name,parentSlug:I.parentSlug||"root",childQuestionText:I.childQuestionText||"",imageUrl:I.imageUrl||""}),a(!0)},_=()=>{o(null),u({slug:"",name:"",parentSlug:"root",childQuestionText:"",imageUrl:""}),a(!0)},z=(()=>{const I=new Map;for(const pe of V){const we=pe.parentSlug||null,Re=I.get(we)??[];Re.push(pe),I.set(we,Re)}for(const pe of I.values())pe.sort((we,Re)=>we.displayOrder-Re.displayOrder||we.name.localeCompare(Re.name));const te=[],Y=new Set,he=(pe,we=0)=>{if(!(we>5))for(const Re of I.get(pe)??[])Y.has(Re.slug)||(Y.add(Re.slug),te.push(Re),he(Re.slug,we+1))};he(null);for(const pe of[...V].sort((we,Re)=>we.displayOrder-Re.displayOrder||we.name.localeCompare(Re.name)))Y.has(pe.slug)||te.push(pe);return te})(),re=h?O.find(I=>I.slug===h):null,ae=h?O.filter(I=>I.parentSlug===h):[],K=ae.filter(I=>I.isActive),q=x.useMemo(()=>{const I=new Set;if(!h)return I;const te=Y=>{for(const he of O.filter(pe=>pe.parentSlug===Y))I.has(he.slug)||(I.add(he.slug),te(he.slug))};return te(h),I},[h,O]),F=O.filter(I=>I.slug!==h&&!q.has(I.slug)),H=(R==null?void 0:R.childCount)??ae.length,W=(R==null?void 0:R.activeChildCount)??K.length,xe=(R==null?void 0:R.serviceCount)??0,J=(R==null?void 0:R.skuCount)??0,$e=!!(R!=null&&R.canDelete)&&!D,oe=((E==null?void 0:E.serviceCount)??0)>0||((E==null?void 0:E.skuCount)??0)>0,Ye=v?O.find(I=>I.slug===v):null,g=oe&&(Ye==null?void 0:Ye.hasActiveChildren)!==!0,B=!r&&V.length===O.length,ze=m.filter(I=>I.isActive&&I.type!=="choice"&&!At(I.type)&&!X.some(te=>te.attributeSlug===I.slug)),Ke=I=>{let te=0,Y=I.parentSlug?O.find(pe=>pe.slug===I.parentSlug):void 0;const he=new Set([I.slug]);for(;Y&&!he.has(Y.slug)&&te<5;)he.add(Y.slug),te++,Y=Y.parentSlug?O.find(pe=>pe.slug===Y.parentSlug):void 0;return te},ve=(I,te)=>{const Y=z.map(pe=>pe.slug),he=I+te;he<0||he>=Y.length||([Y[I],Y[he]]=[Y[he],Y[I]],ke.mutate(Y))},Oe=I=>{if(!p)return;const te=[...X.map(Y=>({attributeSlug:Y.attributeSlug,isRequired:Y.isRequired,displayOrder:Y.displayOrder,tierScope:Y.tierScope})),{attributeSlug:I,isRequired:!0,displayOrder:X.length,tierScope:null}];M.mutate({garmentSlug:p,attributes:te}),C(!1)},Ae=I=>{if(!p)return;const te=X.filter(Y=>Y.attributeSlug!==I).map((Y,he)=>({attributeSlug:Y.attributeSlug,isRequired:Y.isRequired,displayOrder:he,tierScope:Y.tierScope}));M.mutate({garmentSlug:p,attributes:te})},Ve=(I,te)=>{if(!p)return;const Y=X.map(he=>({attributeSlug:he.attributeSlug,isRequired:he.attributeSlug===I?te:he.isRequired,displayOrder:he.displayOrder,tierScope:he.tierScope}));M.mutate({garmentSlug:p,attributes:Y})},yt=(I,te)=>{if(!p)return;const Y=G.map(pe=>pe.slug),he=X.map(pe=>({attributeSlug:pe.attributeSlug,isRequired:pe.isRequired,displayOrder:pe.displayOrder,tierScope:pe.attributeSlug===I?$r(pe.tierScope,te,Y):pe.tierScope}));M.mutate({garmentSlug:p,attributes:he})};return P||b?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):e.jsxs("div",{className:"space-y-4",children:[!r&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(A,{size:"sm",onClick:_,children:[e.jsx(Qe,{className:"h-4 w-4 mr-1"}),"Add Garment"]})}),r&&z.length===0&&e.jsx(us,{noun:"garments"}),e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{className:"w-8"}),e.jsx(Q,{children:"Name"}),e.jsx(Q,{children:"Slug"}),e.jsx(Q,{children:"Parent"}),e.jsx(Q,{children:"Root"}),e.jsx(Q,{children:"Pricing"}),e.jsx(Q,{children:"Order"}),e.jsx(Q,{children:"Active"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsx(ot,{children:z.map((I,te)=>e.jsxs(x.Fragment,{children:[e.jsxs(Ie,{className:"cursor-pointer",onClick:()=>
86{S(p===I.slug?null:I.slug),C(!1)},children:[e.jsx(L,{children:p===I.slug?e.jsx(Kt,{className:"h-4 w-4"}):e.jsx(Xt,{className:"h-4 w-4"})}),e.jsx(L,{className:"font-medium",children:e.jsx("span",{style:{paddingLeft:`${Ke(I)*16}px`},children:I.name})}),e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:I.slug})}),e.jsx(L,{children:I.parentSlug?e.jsx("code",{className:"text-xs",children:I.parentSlug}):e.jsx(me,{variant:"secondary",children:"Root"})}),e.jsx(L,{children:e.jsx(me,{variant:"outline",children:I.category})}),e.jsx(L,{children:I.isPriceable?e.jsx(me,{variant:"default",children:"Leaf"}):I.hasVisibleDescendant?e.jsx(me,{variant:"outline",children:"Node"}):e.jsx(me,{variant:"destructive",children:"Dead end"})}),e.jsx(L,{onClick:Y=>Y.stopPropagation(),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(A,{variant:"ghost",size:"sm",disabled:!B||te===0,title:B?"Move up":"Show the complete All tiers catalog before reordering",onClick:()=>ve(te,-1),children:"â"}),e.jsx("span",{className:"text-xs w-4 text-center",children:I.displayOrder}),e.jsx(A,{variant:"ghost",size:"sm",disabled:!B||te===z.length-1,title:B?"Move down":"Show the complete All tiers catalog before reordering",onClick:()=>ve(te,1),children:"â"})]})}),e.jsx(L,{onClick:Y=>Y.stopPropagation(),children:e.jsx(_e,{checked:I.isActive,disabled:r,onCheckedChange:Y=>Y?Te.mutate(I.slug):qe.mutate(I.slug)})}),e.jsxs(L,{className:"text-right",onClick:Y=>Y.stopPropagation(),children:[!r&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>k(I),children:e.jsx(zt,{className:"h-4 w-4"})}),!r&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>c(I.slug),children:e.jsx(Xe,{className:"h-4 w-4 text-red-600"})})]})]}),p===I.slug&&e.jsx(Ie,{children:e.jsxs(L,{colSpan:9,className:"bg-muted/30 p-4",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"flex items-center gap-1 text-sm font-medium",children:[e.jsx(ci,{className:"h-4 w-4"})," Pre-service descriptors for ",I.name]}),!r&&(T?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(fe,{onValueChange:Oe,children:[e.jsx(be,{className:"h-8 w-56",children:e.jsx(ye,{placeholder:"Select descriptor"})}),e.jsx(Se,{children:ze.map(Y=>e.jsx(se,{value:Y.slug,children:Y.name},Y.slug))})]}),e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>C(!1),children:e.jsx(rt,{className:"h-3 w-3"})})]}):e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>C(!0),children:[e.jsx(Qe,{className:"h-3 w-3 mr-1"}),"Add Descriptor"]}))]}),X.length===0?e.jsx("p",{className:"py-2 text-sm text-muted-foreground",children:"No pre-service descriptors attached to this garment."}):e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"Attribute Name"}),e.jsx(Q,{children:"Slug"}),e.jsx(Q,{children:"Type"}),e.jsx(Q,{children:"Required"}),e.jsx(Q,{children:"Tier Scope"}),e.jsx(Q,{children:"Display Order"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsx(ot,{children:[...X].sort((Y,he)=>Y.displayOrder-he.displayOrder).map(Y=>{const he=Y.attributeType==="choice";return e.jsxs(Ie,{children:[e.jsx(L,{className:"font-medium",children:Y.attributeName}),e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:Y.attributeSlug})}),e.jsx(L,{children:e.jsx(me,{variant:"outline",children:Y.attributeType})}),e.jsx(L,{children:e.jsx(_e,{checked:Y.isRequired,disabled:r||he,onCheckedChange:pe=>Ve(Y.attributeSlug,pe)})}),e.jsx(L,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:r?e.jsx(me,{variant:"secondary",className:"text-xs",children:t.tierSlug}):he?Y.tierScope==null?e.jsx(me,{variant:"secondary",className:"text-xs",children:"All"}):Y.tierScope.map(pe=>{var we;return e.jsx(me,{variant:"secondary",className:"text-xs",children:((we=G.find(Re=>Re.slug===pe))==null?void 0:we.name)??pe},pe)}):e.jsxs(e.Fragment,{children:[Y.tierScope==null?e.jsx(me,{variant:"secondary",className:"text-xs",children:"All"}):null,G.map(pe=>{const we=$t(Y.tierScope,pe.slug);return e.jsx(me,{variant:we?"default":"outline",className:`cursor-pointer text-xs ${we?"":"op
86acity-50"}`,onClick:()=>yt(Y.attributeSlug,pe.slug),children:pe.name},pe.slug)})]})})}),e.jsx(L,{children:Y.displayOrder}),e.jsx(L,{className:"text-right",children:!r&&!he&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>Ae(Y.attributeSlug),children:e.jsx(Xe,{className:"h-3 w-3 text-red-600"})})})]},Y.attributeSlug)})})]})]})})]},I.slug))})]}),e.jsx(ht,{open:l,onOpenChange:I=>{I||ie()},children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsx(vt,{children:d?"Edit Garment":"Add Garment"})}),e.jsxs("div",{className:"space-y-3",children:[!d&&e.jsxs("div",{children:[e.jsx(ee,{placeholder:"Slug (e.g. down-jacket)",value:n.slug,className:n.slug&&!Is(n.slug)?"border-red-500":"",onChange:I=>u(te=>({...te,slug:Ts(I.target.value)}))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Use lowercase with hyphens (e.g., down-jacket)"})]}),e.jsx(ee,{placeholder:"Name",value:n.name,onChange:I=>u(te=>({...te,name:I.target.value}))}),e.jsxs(fe,{value:n.parentSlug,onValueChange:I=>u(te=>({...te,parentSlug:I})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Parent garment"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"root",children:"Root garment"}),O.filter(I=>I.slug!==(d==null?void 0:d.slug)).map(I=>e.jsx(se,{value:I.slug,children:I.name},I.slug))]})]}),g&&E&&e.jsxs("div",{className:"flex gap-2 rounded-md border border-amber-200 bg-amber-50 p-3 text-xs text-amber-900",children:[e.jsx(St,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("span",{children:["This garment currently carries ",E.serviceCount," repair mapping",E.serviceCount===1?"":"s"," ","and ",E.skuCount," SKU",E.skuCount===1?"":"s",". Adding a child would turn those paths into category templates. Open Journey and use ",e.jsx("strong",{children:"Group garments"})," so the existing garment remains a sellable leaf."]})]}),oe&&!g&&E&&e.jsxs("div",{className:"flex gap-2 rounded-md border border-border bg-muted/40 p-3 text-xs text-muted-foreground",children:[e.jsx(St,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("span",{children:["This is already a category. Its ",E.serviceCount," template repair",E.serviceCount===1?"":"s"," will seed inactive, deny-all child drafts; pricing and audience membership are not activated automatically."]})]}),e.jsx(ee,{placeholder:"Child question (e.g. What kind of pants?)",value:n.childQuestionText,onChange:I=>u(te=>({...te,childQuestionText:I.target.value}))}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-muted-foreground mb-1 block",children:"Image"}),e.jsx(wt,{value:n.imageUrl,onChange:I=>u(te=>({...te,imageUrl:I}))})]})]}),e.jsx(jt,{children:e.jsx(A,{onClick:()=>d?ge.mutate({...ue(),slug:d.slug}):De.mutate(ue()),disabled:!n.name||!d&&!n.slug||g||!!v&&N,children:De.isPending||ge.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):d?"Save":"Create"})})]})}),e.jsx(Tt,{open:h!==null,onOpenChange:I=>{I||c(null)},children:e.jsxs(It,{children:[e.jsxs(Vt,{children:[e.jsxs(Rt,{children:['Delete garment "',h,'"?']}),e.jsx(Et,{asChild:!0,children:e.jsxs("div",{className:"space-y-3 text-sm text-muted-foreground",children:[D?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4 animate-spin"}),"Checking delete impact..."]}):H>0?e.jsxs("p",{children:["This garment has ",H," direct child garment",H===1?"":"s",W>0?` (${W} active).`:"."," Reassign the children, retire them first, or deactivate this whole branch instead."]}):xe>0||J>0?e.jsxs("p",{children:["This garment has ",xe," service mapping",xe===1?"":"s"," and"," ",J," SKU",J===1?"":"s",". Hard delete is blocked while those rows exist; deactivate the branch instead or remove the pricing rows first."]}):e.jsx("p",{children:"This permanently removes the garment. This cannot be undone."}),!D&&R&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(me,{variant:H>0?"destructive":"outline",children:[H," child",H===1?"":"ren"]}),e.jsxs(me,{variant:xe>0?"destructive":"outline",children:[xe," service",xe===1?"":"s"]}),e.jsxs(me,{variant:J>0?"destructive":"outline",children:[J," SKU",J===1?"":"s"]})]}),H>0&&e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:"Reassign children"}),e.jsx("div",{className:"break-words text-xs",children:((R==null?void 0:R.childSlugs)??ae.map(I=>I.slug)).join(", ")})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs(fe,{value:y,onValueChange:f,children:[e.jsx(be,{className:"sm:flex-1",children:e.jsx(ye,{placeholder:"New parent"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"root",children:"Root garment"}),F.map(I=>e.jsx(se,{value:I.slug,children:I.name},I.slug))]})]}),e.jsx(A,{variant:"outline",disabled:!h||Fe.isPending||D,onClick:()=>h&&Fe.mutate({slug:h,newParentSlug:y==="root"?null:y}),children:Fe.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):"Reassign"})]})]})]})})]}),e.jsxs(Ot,{children:[e.jsx(Pt,{children:"Cancel"}),(re==null?void 0:re.isActive)&&e.jsx(A,{variant:"outline",onClick:()=>{h&&qe.mutate(h),c(null)},children:"Deactivate branch"}),e.jsx(Dt,{className:"bg-red-600 hover:bg-red-700",disabled:!$e||Ce.isPending,onClick:()=>h&&Ce.mutate(h),children:Ce.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):"Delete"})]})]})})]})}function Ir({lens:t=es,onImportedCountChange:s}={}){const{toast:i}=Pe(),r=t.tierSlug!==null,[l,a]=x.useState(!1),[d,o]=x.useState(null),[n,u]=x.useState({slug:"",name:"",category:"repair",description:"",imageUrl:"",serviceGroup:"",disclaimerText:"",disclaimerRequiresAck:!1}
86),[h,c]=x.useState(null),[y,f]=x.useState(null),[p,S]=x.useState(!1),{data:T=[],isLoading:C}=ne({queryKey:["configV2Services"],queryFn:async()=>(await U("query { configV2Services { slug name category description imageUrl serviceGroup displayOrder isActive disclaimerText disclaimerRequiresAck } }")).configV2Services}),{data:v=[],isLoading:O}=ne({queryKey:["configV2Services","manageCatalogLens",t.tierSlug],queryFn:async()=>(await U("query($tierSlug:String!){configV2Services(tierSlug:$tierSlug){slug name category description imageUrl serviceGroup displayOrder isActive disclaimerText disclaimerRequiresAck}}",{tierSlug:t.tierSlug})).configV2Services,enabled:!!t.tierSlug}),P=t.tierSlug?v:T,$=ms(P,t,s,M=>M.slug),b=le({mutationFn:async M=>U("mutation($slug:String!,$name:String!,$category:String!,$description:String,$imageUrl:String,$serviceGroup:String,$disclaimerText:String,$disclaimerRequiresAck:Boolean){configV2CreateService(slug:$slug,name:$name,category:$category,description:$description,imageUrl:$imageUrl,serviceGroup:$serviceGroup,disclaimerText:$disclaimerText,disclaimerRequiresAck:$disclaimerRequiresAck){slug}}",M),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Services"]}),i({title:"Service created"}),X()},onError:M=>i({title:"Error",description:M.message,variant:"destructive"})}),j=le({mutationFn:async M=>U("mutation($slug:String!,$name:String,$category:String,$description:String,$imageUrl:String,$serviceGroup:String,$isActive:Boolean,$disclaimerText:String,$disclaimerRequiresAck:Boolean){configV2UpdateService(slug:$slug,name:$name,category:$category,description:$description,imageUrl:$imageUrl,serviceGroup:$serviceGroup,isActive:$isActive,disclaimerText:$disclaimerText,disclaimerRequiresAck:$disclaimerRequiresAck){slug}}",M),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Services"]}),i({title:"Updated"}),X()},onError:M=>i({title:"Error",description:M.message,variant:"destructive"})}),V=le({mutationFn:async M=>U("mutation($slug:String!){configV2DeleteService(slug:$slug)}",{slug:M}),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Services"]}),i({title:"Deleted"}),c(null)},onError:M=>i({title:"Error",description:M.message,variant:"destructive"})}),R=le({mutationFn:async M=>U("mutation($slugs:[String!]!){configV2ReorderServices(slugs:$slugs)}",{slugs:M}),onSuccess:()=>Z.invalidateQueries({queryKey:["configV2Services"]})}),{data:D=[]}=ne({queryKey:["configV2Attributes","servicesPage"],queryFn:async()=>(await U("query { configV2Attributes { slug name type isActive } }")).configV2Attributes}),{data:E=[],refetch:N}=ne({queryKey:["configV2ServiceAttributes",y,"servicesPage",t.tierSlug??"all"],queryFn:async()=>y?(await U("query($serviceSlug:String!,$tierSlug:String){configV2AttributesForService(serviceSlug:$serviceSlug,tierSlug:$tier
86Slug,productBacked:true){id serviceSlug attributeSlug isRequired displayOrder tierScope attributeName attributeType}}",{serviceSlug:y,tierSlug:t.tierSlug})).configV2AttributesForService:[],enabled:!!y}),m=le({mutationFn:async M=>U("mutation($serviceSlug:String!,$attributes:[ConfigV2ServiceAttributeInput!]!){configV2SetServiceAttributes(serviceSlug:$serviceSlug,attributes:$attributes)}",M),onSuccess:()=>{N(),i({title:"Service attributes updated"})},onError:M=>i({title:"Error",description:M.message,variant:"destructive"})}),{data:G=[]}=ne({queryKey:["configV2Tiers"],queryFn:async()=>(await U("query { configV2Tiers { slug name description catalogMode priceMultiplier isActive } }")).configV2Tiers}),X=()=>{a(!1),o(null),u({slug:"",name:"",category:"repair",description:"",imageUrl:"",serviceGroup:"",disclaimerText:"",disclaimerRequiresAck:!1})},ce=M=>{o(M),u({slug:M.slug,name:M.name,category:Nr(M.category)??"",description:M.description||"",imageUrl:M.imageUrl||"",serviceGroup:M.serviceGroup||"",disclaimerText:M.disclaimerText||"",disclaimerRequiresAck:M.disclaimerRequiresAck||!1}),a(!0)},de=[...$].sort((M,ue)=>M.displayOrder-ue.displayOrder),De=!r&&$.length===T.length,ge=D.filter(M=>M.isActive&&M.type!=="choice"&&!E.some(ue=>ue.attributeSlug===M.slug)),qe=M=>{const ue=[...E.map(ie=>({attributeSlug:ie.attributeSlug,isRequired:ie.isRequired,displayOrder:ie.displayOrder,tierScope:ie.tierScope})),{attributeSlug:M,isRequired:!1,displayOrder:E.length,tierScope:null}];m.mutate({serviceSlug:y,attributes:ue}),S(!1)},Te=M=>{const ue=E.filter(ie=>ie.attributeSlug!==M).map((ie,k)=>({attributeSlug:ie.attributeSlug,isRequired:ie.isRequired,displayOrder:k,tierScope:ie.tierScope}));m.mutate({serviceSlug:y,attributes:ue})},Ce=(M,ue)=>{const ie=E.map(k=>({attributeSlug:k.attributeSlug,isRequired:k.attributeSlug===M?ue:k.isRequired,displayOrder:k.displayOrder,tierScope:k.tierScope}));m.mutate({serviceSlug:y,attributes:ie})},Fe=(M,ue)=>{const ie=E.map(k=>{if(k.attributeSlug!==M)return{attributeSlug:k.attributeSlug,isRequired:k.isRequired,displayOrder:k.displayOrder,tierScope:k.tierScope};const _=G.map(K=>K.slug),z=k.tierScope??_,re=z.includes(ue)?z.filter(K=>K!==ue):[...z,ue],ae=re.length===_.length&&_.every(K=>re.includes(K))?null:re;return{attributeSlug:k.attributeSlug,isRequired:k.isRequired,displayOrder:k.displayOrder,tierScope:ae}});m.mutate({serviceSlug:y,attributes:ie})},ke=(M,ue)=>{const ie=de.map(_=>_.slug),k=M+ue;k<0||k>=ie.length||([ie[M],ie[k]]=[ie[k],ie[M]],R.mutate(ie))};return C||O?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):e.jsxs("div",{className:"space-y-4",children:[!r&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(A,{size:"sm",onClick:()=>{o(null),u({slug:"",name:"",category:"repair",description:"",imageUrl:"",serviceGroup:"",disclaimerText:"",disclaimerRequiresAck:!1}),a(!0)},children:[e.jsx(Qe,{className:"h-4 w-4 mr-1"}),"Add Service"]})}),r&&de.length===0&&e.jsx(us,{noun:"services"}),e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{className:"w-8"}),e.jsx(Q,{children:"Name"}),e.jsx(Q,{children:"Slug"}),e.jsx(Q,{children:"Category"}),e.jsx(Q,{children:"Group"}),e.jsx(Q,{children:"Description"}),e.jsx(Q,{children:"Order"}),e.jsx(Q,{children:"Active"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsx(ot,{children:de.map((M,ue)=>e.jsxs(x.Fragment,{children:[e.jsxs(Ie,{className:"cursor-pointer",onClick:()=>f(y===M.slug?null:M.slug),children:[e.jsx(L,{children:y===M.slug?e.jsx(Kt,{className:"h-4 w-4"}):e.jsx(Xt,{className:"h-4 w-4"})}),e.jsx(L,{className:"font-medium",children:M.name}),e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:M.slug})}),e.jsx(L,{children:e.jsx(me,{variant:"outline",children:M.category})}),e.jsx(L,{children:M.serviceGroup?e.jsx(me,{variant:"secondary",children:M.serviceGroup}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"â"})}),e.jsx(L,{className:"max-w-[200px] truncate text-sm text-muted-foreground",children:M.description||"â"}),e.jsx(L,{onClick:ie=>ie.stopPropagation(),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(A,{variant:"ghost",size:"sm",disabled:!De||ue===0,title:De?"Move up":"Show the complete All tiers catalog before reordering",onClick:()=>ke(ue,-1),children:"â"}),e.jsx("span",{className:"text-xs w-4 text-center",children:M.displayOrder}),e.jsx(A,{variant:"ghost",size:"sm",disabled:!De||ue===de.length-1,title:De?"Move down":"Show the complete All tiers catalog before reordering",onClick:()=>ke(ue,1),children:"â"})]})}),e.jsx(L,{onClick:ie=>ie.stopPropagation(),children:e.jsx(_e,{checked:M.isActive,disabled:r,onCheckedChange:ie=>j.mutate({slug:M.slug,isActive:ie})})}),e.jsxs(L,{className:"text-right",onClick:ie=>ie.stopPropagation(),children:[!r&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>ce(M),children:e.jsx(zt,{className:"h-4 w-4"})}),!r&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>c(M.slug),children:e.jsx(Xe,{className:"h-4 w-4 text-red-600"})})]})]}),y===M.slug&&e.jsx(Ie,{children:e.jsxs(L,{colSpan:9,className:"bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("span",{className:"text-sm font-medium flex items-center gap-1",children:[e.jsx(ci,{className:"h-4 w-4"})," Linked Attributes for ",M.name]}),!r&&e.jsx("div",{className:"flex items-center gap-2",children:p?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(fe,{onValueChange:ie=>qe(ie),children:[e.jsx(be,{className:"w-48 h-8",children:e.jsx(ye,{placeholder:"Select attribute"})}),e.jsx(Se,{children:ge.map(ie=>e.jsx(se,{value:ie.slug,children:ie.name},ie.slug))})]}),e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>S(!1),children:e.jsx(rt,{className:"h-3 w-3"})})]}):e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>S(!0),children:[e.jsx(Qe,{className:"h-3 w-3 mr-1"}),"Add Attribute"]})})]}),E.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"No attributes linked to this service yet."}):e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"Attribute Name"}),e.jsx(Q,{children:"Slug"}),e.jsx(Q,{children:"Required"}),e.jsx(Q,{children:"Tier Scope"}),e.jsx(Q,{children:"Display Order"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsx(ot,{children:[...E].sort((ie,k)=>ie.displayOrder-k.displayOrder).map(ie=>{const k=ie.attributeType==="choice";return e.jsxs(Ie,{children:[e.jsx(L,{className:"font-medium",children:ie.attributeName}),e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:ie.attributeSlug})}),e.jsx(L,{children:e.jsx(_e,{checked:ie.isRequired,disabled:r||k,onCheckedChange:_=>Ce(ie.attributeSlug,_)})}),e.jsx(L,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:r?e.jsx(me,{variant:"secondary",className:"text-xs",children:t.tierSlug}):k?ie.tierScope==null?e.jsx(me,{variant:"secondary",className:"text-xs",children:"All"}):ie.tierScope.map(_=>{var z;return e.jsx(me,{variant:"secondary",className:"text-xs",children:((z=G.find(re=>re.slug===_))==null?void 0:z.name)??_},_)}):e.jsxs(e.Fragment,{children:[ie.tierScope==null?e.jsx(me,{variant:"secondary",className:"text-xs",children:"All"}):null,G.map(_=>{const z=$t(ie.tierScope,_.slug);return e.jsx(me,{variant:z?"default":"outline",className:`text-xs cursor-pointer ${z?"":"op
86acity-50"}`,onClick:()=>Fe(ie.attributeSlug,_.slug),"data-testid":`tier-scope-chip-${ie.attributeSlug}-${_.slug}`,children:_.name},_.slug)})]})})}),e.jsx(L,{children:ie.displayOrder}),e.jsx(L,{className:"text-right",children:!r&&!k&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>Te(ie.attributeSlug),children:e.jsx(Xe,{className:"h-3 w-3 text-red-600"})})})]},ie.attributeSlug)})})]})]})})]},M.slug))})]}),e.jsx(ht,{open:l,onOpenChange:M=>{M||X()},children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsx(vt,{children:d?"Edit Service":"Add Service"})}),e.jsxs("div",{className:"space-y-3",children:[!d&&e.jsxs("div",{children:[e.jsx(ee,{placeholder:"Slug",value:n.slug,className:n.slug&&!Is(n.slug)?"border-red-500":"",onChange:M=>u(ue=>({...ue,slug:Ts(M.target.value)}))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Use lowercase with hyphens (e.g., down-jacket)"})]}),e.jsx(ee,{placeholder:"Name",value:n.name,onChange:M=>u(ue=>({...ue,name:M.target.value}))}),e.jsxs(fe,{value:n.category,onValueChange:M=>u(ue=>({...ue,category:M})),children:[e.jsx(be,{"aria-label":"Service category",children:e.jsx(ye,{placeholder:"Select category"})}),e.jsx(Se,{children:qs.map(M=>e.jsx(se,{value:M,children:ui[M]},M))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Catalog grouping only. It does not determine tax or the customer order classification."}),e.jsx(ee,{placeholder:"Service group (optional)",value:n.serviceGroup,onChange:M=>u(ue=>({...ue,serviceGroup:M.target.value}))}),e.jsx(ee,{placeholder:"Description",value:n.description,onChange:M=>u(ue=>({...ue,description:M.target.value}))}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-muted-foreground mb-1 block",children:"Image"}),e.jsx(wt,{value:n.imageUrl,onChange:M=>u(ue=>({...ue,imageUrl:M}))})]}),e.jsxs("div",{className:"border-t pt-3 mt-1",children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Disclaimer"}),e.jsx("textarea",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm min-h-[60px] resize-y",placeholder:"Optional disclaimer or acknowledgment text shown to customers",value:n.disclaimerText,onChange:M=>u(ue=>({...ue,disclaimerText:M.target.value}))}),n.disclaimerText&&e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx(_e,{checked:n.disclaimerRequiresAck,onCheckedChange:M=>u(ue=>({...ue,disclaimerRequiresAck:M}))}),e.jsx("span",{className:"text-sm",children:"Require customer acknowledgment"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:n.disclaimerRequiresAck?"Customer must check a box to agree before proceeding.":"Shown as informational text when this service is selected."})]})]}),e.jsx(jt,{children:e.jsx(A,{onClick:()=>{const M={...n,serviceGroup:n.serviceGroup.trim()||null};d?j.mutate({slug:d.slug,name:M.name,category:M.category,description:M.description,imageUrl:M.imageUrl,serviceGroup:M.serviceGroup,disclaimerText:M.disclaimerText||void 0,disclaimerRequiresAck:M.disclaimerRequiresAck}):b.mutate(M)},disabled:!n.name||!n.category||!d&&!n.slug,children:b.isPending||j.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):d?"Save":"Create"})})]})}),e.jsx(Tt,{open:h!==null,onOpenChange:()=>c(null),children:e.jsxs(It,{children:[e.jsxs(Vt,{children:[e.jsxs(Rt,{children:['Delete service "',h,'"?']}),e.jsx(Et,{children:"This will remove the service and associated data."})]}),e.jsxs(Ot,{children:[e.jsx(Pt,{children:"Cancel"}),e.jsx(Dt,{className:"bg-red-600 hover:bg-red-700",onClick:()=>h&&V.mutate(h),children:"Delete"})]})]})})]})}function Vr({lens:t=es,onImportedCountChange:s}={}){const{toast:i}=Pe(),r=t.tierSlug!==null,[l,a]=x.useState(null),[d,o]=x.useState(!1),[n,u]=x.useState(null),[h,c]=x.useState({slug:"",name:"",type:js,summaryLabel:"",questionText:"",helpText:"",imageUrl:""}),[y,f]=x.useState(null),[p,S]=x.useState(!1),[T,C]=x.useState(null),[v,O]=x.useState({attributeSlug:"",value:"",label:"",description:"",skuCode:"",imageUrl:"",priceAdjustmentCents:"0",minutesAdjustment:"0",isDefault:!1,disclaimerText:"",disclaimerRequiresAck:!1,hiddenForGarments:[]}
86),[P,$]=x.useState([]),[b,j]=x.useState(null),[V,R]=x.useState({garmentSlug:"any",serviceSlug:"any",priceAdjustmentCents:"0",minutesAdjustment:"0",isActive:!0}),[D,E]=x.useState(null),{data:N=[],isLoading:m}=ne({queryKey:["configV2Attributes","attributesPage"],queryFn:async()=>(await U("query { configV2Attributes { slug name type summaryLabel questionText helpText imageUrl displayOrder isActive values { id attributeSlug value label description imageUrl skuCode priceAdjustmentCents minutesAdjustment displayOrder isDefault isActive disclaimerText disclaimerRequiresAck hiddenForGarments } } }")).configV2Attributes}),{data:G=[],isLoading:X}=ne({queryKey:["configV2Attributes","attributesPage","manageCatalogLens",t.tierSlug],queryFn:async()=>(await U("query($tierSlug:String!){configV2Attributes(tierSlug:$tierSlug){slug name type summaryLabel questionText helpText imageUrl displayOrder isActive values{id attributeSlug value label description imageUrl skuCode priceAdjustmentCents minutesAdjustment displayOrder isDefault isActive disclaimerText disclaimerRequiresAck hiddenForGarments}}}",{tierSlug:t.tierSlug})).configV2Attributes,enabled:!!t.tierSlug}),ce=t.tierSlug?G:N,de=ms(ce,t,s,g=>g.slug),{data:De=[]}=ne({queryKey:["configV2Garments"],queryFn:async()=>(await U("query { configV2Garments { slug name category isActive } }")).configV2Garments}),{data:ge=[]}=ne({queryKey:["configV2Services"],queryFn:async()=>(await U("query { configV2Services { slug name category isActive } }")).configV2Services}),{data:qe=[]}=ne({queryKey:["configV2Tiers"],queryFn:async()=>(await U("query { configV2Tiers { slug name description catalogMode priceMultiplier isActive } }")).configV2Tiers}),{data:Te=[]}=ne({queryKey:["configV2GarmentServices"],queryFn:async()=>(await U("query { configV2GarmentServices { id garmentSlug serviceSlug requiresQuote isActive } }")).configV2GarmentServices}),{data:Ce=[]}=ne({queryKey:["configV2ServiceAttributes","all"],queryFn:async()=>(await U("query { configV2ServiceAttributes { id serviceSlug attributeSlug isRequired displayOrder tierScope attributeName attributeType } }")).configV2ServiceAttributes}),{data:Fe=[]}=ne({queryKey:["configV2Dependencies"],queryFn:async()=>(await U("query { configV2Dependencies { id attributeSlug dependsOnAttributeSlug dependsOnValue } }")).configV2Dependencies}),{data:ke=[],isLoading:M}=ne({queryKey:["configV2AttributeValueOverrides",T==null?void 0:T.id],queryFn:async()=>(await U("query($attributeValueId:Int){configV2AttributeValueOverrides(attributeValueId:$attributeValueId){id attributeValueId garmentSlug serviceSlug priceAdjustmentCents minutesAdjustment isActive createdAt}}",{attributeValueId:T==null?void 0:T.id})).configV2AttributeValueOverrides,enabled:!!T}),ue=x.useMemo(()=>new Map(De.map(g=>[g.slug,g.name])),[De]),ie=x.useMemo(()=>new Map(ge.map(g=>[g.slug,g.name])),[ge]),k=(g=T)=>{j(null),R({garmentSlug:"any",serviceSlug:"any",priceAdjustmentCents:String((((g==null?void 0:g.priceAdjustmentCents)??0)/100).toFixed(2)),minutesAdjustment:String((g==null?void 0:g.minutesAdjustment)??0),isActive:!0})},_=g=>{j(g),R({garmentSlug:g.garmentSlug||"any",serviceSlug:g.serviceSlug||"any",priceAdjustmentCents:String((g.priceAdjustmentCents/100).toFixed(2)),minutesAdjustment:String(g.minutesAdjustment||0),isActive:g.isActive})},z=g=>{const B=N.find(te=>te.slug===v.attributeSlug);if(!B||At(B.type))return[];const ze=new Map(N.map(te=>[te.slug,te])),Ke=new Map;for(const te of Fe){const Y=Ke.get(te.attributeSlug)??[];Y.push(te),Ke.set(te.attributeSlug,Y)}const ve=te=>{const Y=ze.get(te);return Y?(Y.values||[]).map(he=>T&&he.id===T.id?{...he,value:v.value||he.value,hiddenForGarments:g}:he):[]},Oe=(te,Y,he)=>ve(te).some(pe=>pe.isActive&&pe.value===Y&&!mt(pe,he)),Ae=(te,Y)=>ve(te).some(he=>he.isActive&&!mt(he,Y)),Ve=(te,Y,he,pe,we=new Set)=>{const Re=Ke.get(te.attributeSlug)??[];if(Re.length===0)return!0;const ut=Re[0].dependsOnAttributeSlug;if(we.has(ut))return!0;const gt=Y.find(Nt=>Nt.attributeSlug===ut);if(!gt)return!0;if(!$t(gt.tierScope,pe)||!Ve(gt,Y,he,pe,new Set([...we,te.attributeSlug])))return!1;const Gt=ze.get(ut);return!Gt||At(Gt.type)?!0:Re.some(Nt=>Nt.dependsOnValue==="*"?Ae(ut,he):Oe(ut,Nt.dependsOnValue,he))},yt=[],I=De.filter(te=>te.isActive!==!1);for(const te of I){if(Ae(B.slug,te.slug))continue;const Y=Te.filter(he=>he.isActive!==!1&&he.garmentSlug===te.slug);for(const he of Y){const pe=Ce.filter(Re=>Re.serviceSlug===he.serviceSlug),we=pe.filter(Re=>Re.attributeSlug===B.slug&&Re.isRequired&&!At(Re.attributeType));for(const Re of we)for(const ut of qe.filter(gt=>gt.isActive!==!1))$t(Re.tierScope,ut.slug)&&Ve(Re,pe,te.slug,ut.slug)&&yt.push({tierSlug:ut.slug,tierName:ut.name,garmentSlug:te.slug,garmentName:ue.get(te.slug)||te.slug,serviceSlug:he.serviceSlug,serviceName:ie.get(he.serviceSlug)||he.serviceSlug,attributeSlug:B.slug,attributeName:B.name})}}return yt},re=le({mutationFn:async g=>U("mutation($slug:String!,$name:String!,$type:String!,$summaryLabel:String,$questionText:String,$helpText:String,$imageUrl:String){configV2CreateAttribute(slug:$slug,name:$name,type:$type,summaryLabel:$summaryLabel,questionText:$questionText,helpText:$helpText,imageUrl:$imageUrl){slug}}",g),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Attributes"]}),i({title:"Attribute created"}),J()},onError:g=>i({title:"Error",description:g.message,variant:"destructive"})}),ae=le({mutationFn:async g=>U("mutation($slug:String!,$name:String,$type:String,$summaryLabel:String,$questionText:String,$helpText:String,$imageUrl:String,$isActive:Boolean){configV2UpdateAttribute(slug:$slug,name:$name,type:$type,summaryLabel:$summaryLabel,questionText:$questionText,helpText:$helpText,imageUrl:$imageUrl,isActive:$isActive){slug}}",g),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Attributes"]}),i({title:"Updated"}),J()},onError:g=>i({title:"Error",description:g.message,variant:"destructive"})}),K=le({mutationFn:async g=>U("mutation($slug:String!){configV2DeleteAttribute(slug:$slug)}",{slug:g}),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Attributes"]}),i({title:"Deleted"}),f(null)},onError:g=>i({title:"Error",description:g.message,variant:"destructive"})}),q=le({mutationFn:async g=>U("mutation($attributeSlug:String!,$value:String!,$label:String!,$description:String,$skuCode:String!,$imageUrl:String,$priceAdjustmentCents:Int,$minutesAdjustment:Int,$isDefault:Boolean,$disclaimerText:String,$disclaimerRequiresAck:Boolean,$hiddenForGarments:[String!]){configV2CreateAttributeValue(attributeSlug:$attributeSlug,value:$value,label:$label,description:$description,skuCode:$skuCode,imageUrl:$imageUrl,priceAdjustmentCents:$priceAdjustmentCents,minutesAdjustment:$minutesAdjustment,isDefault:$isDefault,disclaimerText:$disclaimerText,disclaimerRequiresAck:$disclaimerRequiresAck,hiddenForGarments:$hiddenForGarments){id}}",g),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Attributes"]}),i({title:"Value added"}),S(!1)},onError:g=>i({title:"Error",description:g.message,variant:"destructive"})}),F=le({mutationFn:async g=>U("mutation($id:Int!,$value:String,$label:String,$description:String,$skuCode:String,$imageUrl:String,$priceAdjustmentCents:Int,$minutesAdjustment:Int,$isDefault:Boolean,$disclaimerText:String,$disclaimerRequiresAck:Boolean,$hiddenForGarments:[String!]){configV2UpdateAttributeValue(id:$id,value:$value,label:$label,description:$description,skuCode:$skuCode,imageUrl:$imageUrl,priceAdjustmentCents:$priceAdjustmentCents,minutesAdjustment:$minutesAdjustment,isDefault:$isDefault,disclaimerText:$disclaimerText,disclaimerRequiresAck:$disclaimerRequiresAck,hiddenForGarments:$hiddenForGarments){id}}",g),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Attributes"]}),i({title:"Value updated"}),S(!1)},onError:g=>i({title:"Error",description:g.message,variant:"destructive"})}),H=le({mutationFn:async g=>U("mutation($id:Int!){configV2DeleteAttributeValue(id:$id)}",{id:g}),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Attributes"]}),i({title:"Value deleted"}),E(null)},onError:g=>i({title:"Error",description:g.message,variant:"destructive"})}),W=le({mutationFn:async g=>g.id?U("mutation($id:Int!,$garmentSlug:String,$serviceSlug:String,$priceAdjustmentCents:Int,$minutesAdjustment:Int,$isActive:Boolean){configV2UpdateAttributeValueOverride(id:$id,garmentSlug:$garmentSlug,serviceSlug:$serviceSlug,priceAdjustmentCents:$priceAdjustmentCents,minutesAdjustment:$minutesAdjustment,isActive:$isActive){id}}",g):U("mutation($attributeValueId:Int!,$garmentSlug:String,$serviceSlug:String,$priceAdjustmentCents:Int!,$minutesAdjustment:Int!,$isActive:Boolean){configV2CreateAttributeValueOverride(attributeValueId:$attributeValueId,garmentSlug:$garmentSlug,serviceSlug:$serviceSlug,priceAdjustmentCents:$priceAdjustmentCents,minutesAdjustment:$minutesAdjustment,isActive:$isActive){id}}",g),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2AttributeValueOverrides",T==null?void 0:T.id]}),Z.invalidateQueries({queryKey:["configV2Attributes"]}),Z.invalidateQueries({queryKey:["configV2AllAttributes"]}),k(),i({title:"Override saved",description:"Regenerate V2 products before this pricing change is considered live."})},onError:g=>i({title:"Error",description:g.message,variant:"destructive"})}),xe=le({mutationFn:async g=>U("mutation($id:Int!){configV2DeleteAttributeValueOverride(id:$id)}",{id:g}),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2AttributeValueOverrides",T==null?void 0:T.id]}),Z.invalidateQueries({queryKey:["configV2Attributes"]}),Z.invalidateQueries({queryKey:["configV2AllAttributes"]}),k(),i({title:"Override deleted",description:"Regenerate V2 products before relying on this pricing change."})},onError:g=>i({title:"Error",description:g.message,variant:"destructive"})}),J=()=>{o(!1),u(null),c({slug:"",name:"",type:js,summaryLabel:"",questionText:"",helpText:"",imageUrl:""})},$e=g=>{u(g),c({slug:g.slug,name:g.name,type:g.type,summaryLabel:g.summaryLabel||"",questionText:g.questionText||"",helpText:g.helpText||"",imageUrl:g.imageUrl||""}),o(!0)},oe=g=>{C(null),j(null),$([]),R({garmentSlug:"any",serviceSlug:"any",priceAdjustmentCents:"0.00",minutesAdjustment:"0",isActive:!0}),O({attributeSlug:g,value:"",label:"",description:"",skuCode:"",imageUrl:"",priceAdjustmentCents:"0",minutesAdjustment:"0",isDefault:!1,disclaimerText:"",disclaimerRequiresAck:!1,hiddenForGarments:[]}),S(!0)},Ye=g=>{C(g),j(null),$([]),R({garmentSlug:"any",serviceSlug:"any",priceAdjustmentCents:String((g.priceAdjustmentCents/100).toFixed(2)),minutesAdjustment:String(g.minutesAdjustment||0),isActive:!0}),O({attributeSlug:g.attributeSlug,value:g.value,label:g.label,description:g.description||"",skuCode:g.skuCode,imageUrl:g.imageUrl||"",priceAdjustmentCents:String(g.priceAdjustmentCents/100),minutesAdjustment:String(g.minutesAdjustment||0),isDefault:g.isDefault,disclaimerText:g.disclaimerText||"",disclaimerRequiresAck:g.disclaimerRequiresAck||!1,hiddenForGarments:g.hiddenForGarments??[]}),S(!0)};return m||X?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):e.jsxs("div",{className:"space-y-4",children:[!r&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(A,{size:"sm",onClick:()=>{u(null),c({slug:"",name:"",type:js,summaryLabel:"",questionText:"",helpText:"",imageUrl:""}),o(!0)},children:[e.jsx(Qe,{className:"h-4 w-4 mr-1"}),"Add Attribute"]})}),r&&de.length===0&&e.jsx(us,{noun:"attributes"}),e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{}),e.jsx(Q,{children:"Name"}),e.jsx(Q,{children:"Slug"}),e.jsx(Q,{children:"Type"}),e.jsx(Q,{children:"Summary Label"}),e.jsx(Q,{children:"Values"}),e.jsx(Q,{children:"Active"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsx(ot,{children:de.slice().sort((g,B)=>g.displayOrder-B.displayOrder).map(g=>{var Ke;const B=g.type==="choice",ze=(g.values||[]).filter(ve=>!Ht(g.type)&&(ve.priceAdjustmentCents!==0||ve.minutesAdjustment!==0));return e.jsxs(x.Fragment,{children:[e.jsxs(Ie,{className:"cursor-pointer",onClick:()=>a(l===g.slug?null:g.slug),children:[e.jsx(L,{children:l===g.slug?e.jsx(Kt,{className:"h-4 w-4"}):e.jsx(Xt,{className:"h-4 w-4"})}),e.jsx(L,{className:"font-medium",children:g.name}),e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:g.slug})}),e.jsx(L,{children:e.jsx(me,{variant:"outline",children:g.type})}),e.jsx(L,{children:g.summaryLabel?e.jsx(me,{variant:"secondary",children:g.summaryLabel}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"â"})}),e.jsx(L,{children:At(g.type)?"â":((Ke=g.values)==null?void 0:Ke.length)||0}),e.jsx(L,{children:e.jsx(_e,{checked:g.isActive,disabled:r||B,onCheckedChange:ve=>{ae.mutate({slug:g.slug,isActive:ve})},onClick:ve=>ve.stopPropagation()})}),e.jsxs(L,{className:"text-right",onClick:ve=>ve.stopPropagation(),children:[!r&&!B&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>$e(g),children:e.jsx(zt,{className:"h-4 w-4"})}),!r&&!B&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>f(g.slug),children:e.jsx(Xe,{className:"h-4 w-4 text-red-600"})})]})]},g.slug),l===g.slug&&e.jsx(Ie,{children:e.jsx(L,{colSpan:8,className:"bg-gray-50 p-4",children:At(g.type)?e.jsxs("div",{className:"text-sm text-muted-foreground py-2",children:[e.jsxs("p",{className:"font-medium text-amber-700 mb-1",children:[Us[g.type]," Attribute"]}),e.jsx("p",{children:"No discrete values are needed."}),ze.length>0&&e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"Legacy value"}),e.jsx(Q,{children:"Price Adj."}),e.jsx(Q,{children:"Min Adj."}),e.jsx(Q,{children:"Status"})]})}),e.jsx(ot,{children:ze.map(ve=>e.jsxs(Ie,{children:[e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:ve.value})}),e.jsx(L,{children:ve.priceAdjustmentCents!==0?We(ve.priceAdjustmentCents):"â"}),e.jsx(L,{children:ve.minutesAdjustment!==0?`${ve.minutesAdjustment>0?"+":""}${ve.minutesAdjustment}m`:"â"}),e.jsx(L,{children:e.jsx(me,{variant:"destructive",children:"Not charged by current runtime"})})]},ve.id))})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("span",{className:"text-sm font-medium",children:["Values for ",g.name]}),!r&&!B&&e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>oe(g.slug),children:[e.jsx(Qe,{className:"h-3 w-3 mr-1"}),"Add Value"]})]}),e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"Value"}),e.jsx(Q,{children:"Label"}),e.jsx(Q,{children:"SKU Code"}),e.jsx(Q,{children:"Price Adj."}),e.jsx(Q,{children:"Min Adj."}),e.jsx(Q,{children:"Default"}),e.jsx(Q,{children:"Hidden For"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsx(ot,{children:(g.values||[]).sort((ve,Oe)=>ve.displayOrder-Oe.displayOrder).map(ve=>{var Oe;return e.jsxs(Ie,{children:[e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:ve.value})}),e.jsx(L,{children:ve.label}),e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:ve.
86skuCode})}),e.jsxs(L,{children:[ve.priceAdjustmentCents!==0?We(ve.priceAdjustmentCents):"â",!Ht(g.type)&&(ve.priceAdjustmentCents!==0||ve.minutesAdjustment!==0)&&e.jsx(me,{variant:"destructive",className:"mt-1 block w-fit",children:"Not charged by current runtime"})]}),e.jsx(L,{children:ve.minutesAdjustment!==0?`${ve.minutesAdjustment>0?"+":""}${ve.minutesAdjustment}m`:"â"}),e.jsx(L,{children:ve.isDefault?e.jsx(me,{children:"Default"}):null}),e.jsx(L,{children:(((Oe=ve.hiddenForGarments)==null?void 0:Oe.length)??0)===0?e.jsx("span",{className:"text-xs text-muted-foreground",children:"Shown for all"}):e.jsxs("div",{className:"flex flex-wrap gap-1",children:[ve.hiddenForGarments.slice(0,2).map(Ae=>e.jsx(me,{variant:"secondary",className:"text-[10px]",children:ue.get(Ae)||Ae},Ae)),ve.hiddenForGarments.length>2&&e.jsxs(me,{variant:"outline",className:"text-[10px]",children:["+",ve.hiddenForGarments.length-2]})]})}),e.jsxs(L,{className:"text-right",children:[!r&&!B&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>Ye(ve),children:e.jsx(zt,{className:"h-3 w-3"})}),!r&&!B&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>E(ve.id),children:e.jsx(Xe,{className:"h-3 w-3 text-red-600"})})]})]},ve.id)})})]})]})})},`${g.slug}-values`)]},g.slug)})})]}),e.jsx(ht,{open:d,onOpenChange:g=>{g||J()},children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsx(vt,{children:n?"Edit Attribute":"Add Attribute"})}),e.jsxs("div",{className:"space-y-3",children:[!n&&e.jsxs("div",{children:[e.jsx(ee,{placeholder:"Slug",value:h.slug,className:h.slug&&!Is(h.slug)?"border-red-500":"",onChange:g=>c(B=>({...B,slug:Ts(g.target.value)}))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Use lowercase with hyphens (e.g., down-jacket)"})]}),e.jsx(ee,{placeholder:"Name",value:h.name,onChange:g=>c(B=>({...B,name:g.target.value}))}),e.jsx(ee,{placeholder:"Summary Label (optional)",value:h.summaryLabel,onChange:g=>c(B=>({...B,summaryLabel:g.target.value}))}),e.jsxs(fe,{value:h.type,onValueChange:g=>c(B=>({...B,type:g})),children:[e.jsx(be,{children:e.jsx(ye,{})}),e.jsx(Se,{children:Pi.filter(g=>g!=="choice").map(g=>e.jsx(se,{value:g,children:Us[g]},g))})]}),At(h.type)&&e.jsx("p",{className:"text-xs text-amber-600",children:"No discrete values are needed for this attribute type."}),e.jsx(ee,{placeholder:"Question Text",value:h.questionText,onChange:g=>c(B=>({...B,questionText:g.target.value}))}),e.jsx("textarea",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm min-h-[72px] resize-y",placeholder:"Help text shown below this question",value:h.helpText,onChange:g=>c(B=>({...B,helpText:g.target.value}))}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-muted-foreground mb-1 block",children:"Image"}),e.jsx(wt,{value:h.imageUrl,onChange:g=>c(B=>({...B,imageUrl:g}))})]})]}),e.jsx(jt,{children:e.jsx(A,{onClick:()=>{const g=h.summaryLabel.trim()||null;n?ae.mutate({slug:n.slug,name:h.name,type:h.type,summaryLabel:g,questionText:h.questionText,helpText:h.helpText.trim()||null,imageUrl:h.imageUrl}):re.mutate({...h,summaryLabel:g,helpText:h.helpText.trim()||void 0})},disabled:!h.name||!n&&!h.slug,children:n?"Save":"Create"})})]})}),e.jsx(ht,{open:p,onOpenChange:S,children:e.jsxs(xt,{className:"max-h-[90vh] overflow-y-auto",children:[e.jsx(pt,{children:e.jsx(vt,{children:T?"Edit Value":"Add Value"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(ee,{placeholder:"Value (e.g. small)",value:v.value,onChange:g=>O(B=>({...B,value:g.target.value}))}),e.jsx(ee,{placeholder:"Label (e.g. Small)",value:v.label,onChange:g=>O(B=>({...B,label:g.target.value}))}),e.jsx("textarea",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm min-h-[72px] resize-y",placeholder:"Description shown under this option",value:v.description,onChange:g=>O(B=>({...B,description:g.target.value}))}),e.jsx(ee,{placeholder:"SKU Code",value:v.skuCode,onChange:g=>O(B=>({...B,skuCode:g.target.value}))}),e.jsx(ee,{placeholder:"Price Adjustment ($)",value:v.priceAdjustmentCents,onChange:g=>O(B=>({...B,priceAdjustmentCents:g.target.value}))}),e.jsx(ee,{placeholder:"Minutes Adjustment (e.g. +15 or -5)",value:v.minutesAdjustment,onChange:g=>O(B=>({...B,minutesAdjustment:g.target.value}))}),T&&e.jsxs("div",{className:"border-t pt-3 mt-1 space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium block",children:"Scoped Price Overrides"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Overrides replace both price and minutes for this value in a garment and/or service scope. Regenerate products before the pricing change is live."})]}),M?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Ne,{className:"h-4 w-4 animate-spin"}),"Loading overrides"]}):ke.length>0?e.jsx("div",{className:"space-y-2",children:ke.map(g=>e.jsxs("div",{className:"flex flex-col gap-2 rounded-md border p-2 text-sm sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-medium",children:[g.garmentSlug?ue.get(g.garmentSlug)||g.garmentSlug:"Any garment"," / ",g.serviceSlug?ie.get(g.serviceSlug)||g.serviceSlug:"Any service"]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[We(g.priceAdjustmentCents)," / ",g.minutesAdjustment>0?"+":"",g.minutesAdjustment,"m",!g.isActive&&" · inactive"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:()=>_(g),children:"Edit"}),e.jsx(A,{type:"button",variant:"ghost",size:"sm",onClick:()=>xe.mutate(g.id),disabled:xe.isPending,children:e.jsx(Xe,{className:"h-3 w-3 text-red-600"})})]})]},g.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No scoped overrides yet."}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2",children:[e.jsxs(fe,{value:V.garmentSlug,onValueChange:g=>R(B=>({...B,garmentSlug:g})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Garment scope"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"any",children:"Any garment"}),De.map(g=>e.jsx(se,{value:g.slug,children:g.name},g.slug))]})]}),e.jsxs(fe,{value:V.serviceSlug,onValueChange:g=>R(B=>({...B,serviceSlug:g})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Service scope"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"any",children:"Any service"}),ge.map(g=>e.jsx(se,{value:g.slug,children:g.name},g.slug))]})]}),e.jsx(ee,{placeholder:"Override Price Adjustment ($)",value:V.priceAdjustmentCents,onChange:g=>R(B=>({...B,priceAdjustmentCents:g.target.value}))}),e.jsx(ee,{placeholder:"Override Minutes Adjustment",value:V.minutesAdjustment,onChange:g=>R(B=>({...B,minutesAdjustment:g.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{checked:V.isActive,onCheckedChange:g=>R(B=>({...B,isActive:g}))}),e.jsx("span",{className:"text-sm",children:"Active override"})]}),e.jsxs("div",{className:"flex gap-2",children:[b&&e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:()=>k(),children:"Cancel edit"}
86),e.jsx(A,{type:"button",size:"sm",disabled:W.isPending||V.garmentSlug==="any"&&V.serviceSlug==="any",onClick:()=>{const g=Math.round(parseFloat(V.priceAdjustmentCents||"0")*100),B=parseInt(V.minutesAdjustment||"0",10)||0;W.mutate({id:b==null?void 0:b.id,attributeValueId:T.id,garmentSlug:V.garmentSlug==="any"?null:V.garmentSlug,serviceSlug:V.serviceSlug==="any"?null:V.serviceSlug,priceAdjustmentCents:g,minutesAdjustment:B,isActive:V.isActive})},children:W.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):b?"Save override":"Add override"})]})]}),V.garmentSlug==="any"&&V.serviceSlug==="any"&&e.jsx("p",{className:"text-xs text-red-600",children:"Choose at least one garment or service scope."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-muted-foreground mb-1 block",children:"Image"}),e.jsx(wt,{value:v.imageUrl,onChange:g=>O(B=>({...B,imageUrl:g}))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{checked:v.isDefault,onCheckedChange:g=>O(B=>({...B,isDefault:g}))}),e.jsx("span",{className:"text-sm",children:"Default value"})]}),e.jsxs("div",{className:"border-t pt-3 mt-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium block",children:"Garment Scope"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Selected garments are hidden. Empty means this value is shown for all garments."})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:()=>{$([]),O(g=>({...g,hiddenForGarments:[]}))},children:"Show all"}),e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:()=>{$([]),O(g=>({...g,hiddenForGarments:De.map(B=>B.slug)}))},children:"Hide all"})]})]}),v.hiddenForGarments.length===0?e.jsx(me,{variant:"outline",className:"w-fit",children:"Shown for all garments"}):e.jsxs(me,{variant:"secondary",className:"w-fit",children:["Hidden for ",v.hiddenForGarments.length," garment",v.hiddenForGarments.length===1?"":"s"]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 max-h-44 overflow-y-auto pr-1",children:De.map(g=>{const B=v.hiddenForGarments.includes(g.slug);return e.jsxs(A,{type:"button",variant:B?"destructive":"outline",size:"sm",className:"justify-start",onClick:()=>{$([]),O(ze=>({...ze,hiddenForGarments:B?ze.hiddenForGarments.filter(Ke=>Ke!==g.slug):[...ze.hiddenForGarments,g.slug]}))},children:[B?e.jsx(ti,{className:"h-3 w-3 mr-2"}):e.jsx(Bt,{className:"h-3 w-3 mr-2"}),e.jsxs("span",{className:"truncate",children:[B?"Hidden: ":"",g.name]})]},g.slug)})})]}),e.jsxs("div",{className:"border-t pt-3 mt-1",children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Disclaimer"}),e.jsx("textarea",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm min-h-[60px] resize-y",placeholder:"Optional disclaimer shown when this value is selected",value:v.disclaimerText,onChange:g=>O(B=>({...B,disclaimerText:g.target.value}))}),v.disclaimerText&&e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx(_e,{checked:v.disclaimerRequiresAck,onCheckedChange:g=>O(B=>({...B,disclaimerRequiresAck:g}))}),e.jsx("span",{className:"text-sm",children:"Require customer acknowledgment"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:v.disclaimerRequiresAck?"Customer must check a box to agree before proceeding.":"Shown as informational text when this value is selected."})]}),P.length>0&&e.jsxs("div",{className:"border border-red-200 bg-red-50 rounded-md p-3 text-sm",children:[e.jsxs("div",{className:"font-medium text-red-700 flex items-center gap-2",children:[e.jsx(St,{className:"h-4 w-4"}),"Save blocked by garment scope"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"This would hide the last visible value for a required question in these cells."}),e.jsxs("div",{className:"max-h-32 overflow-y-auto mt-2 space-y-1",children:[P.slice(0,20).map((g,B)=>e.jsxs("div",{className:"text-xs",children:[e.jsx("span",{className:"font-medium",children:g.tierName})," / ",g.garmentName," / ",g.serviceName," â ",g.attributeName]},`${g.tierSlug}-${g.garmentSlug}-${g.serviceSlug}-${B}`)),P.length>20&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["+",P.length-20," more"]})]})]})]}),e.jsx(jt,{children:e.jsx(A,{onClick:()=>{const g=Math.round(parseFloat(v.priceAdjustmentCents||"0")*100),B=parseInt(v.minutesAdjustment||"0",10)||0;if(T){const ze=z(v.hiddenForGarments);if(ze.length>0){$(ze),i({title:"Garment scope blocked",description:`${ze.length} affected cell${ze.length===1?"":"s"} would have no visible value for this required attribute.`,variant:"destructive"});return}}T?F.mutate({id:T.id,value:v.value,label:v.label,description:v.description.trim()||null,skuCode:v.skuCode,imageUrl:v.imageUrl,priceAdjustmentCents:g,minutesAdjustment:B,isDefault:v.isDefault,disclaimerText:v.disclaimerText||void 0,disclaimerRequiresAck:v.disclaimerRequiresAck,hiddenForGarments:v.hiddenForGarments}):q.mutate({attributeSlug:v.attributeSlug,value:v.value,label:v.label,description:v.description.trim()||void 0,skuCode:v.skuCode,imageUrl:v.imageUrl,priceAdjustmentCents:g,minutesAdjustment:B,isDefault:v.isDefault,disclaimerText:v.disclaimerText||void 0,disclaimerRequiresAck:v.disclaimerRequiresAck,hiddenForGarments:v.hiddenForGarments})},disabled:!v.value||!v.label||!v.skuCode,children:T?"Save":"Add"})})]})}),e.jsx(Tt,{open:y!==null,onOpenChange:()=>f(null),children:e.jsxs(It,{children:[e.jsxs(Vt,{children:[e.jsxs(Rt,{children:['Delete attribute "',y,'"?']}),e.jsx(Et,{children:"This will delete the attribute and all its values."})]}),e.jsxs(Ot,{children:[e.jsx(Pt,{children:"Cancel"}),e.jsx(Dt,{className:"bg-red-600 hover:bg-red-700",onClick:()=>y&&K.mutate(y),children:"Delete"})]})]})}),e.jsx(Tt,{open:D!==null,onOpenChange:()=>E(null),children:e.jsxs(It,{children:[e.jsxs(Vt,{children:[e.jsx(Rt,{children:"Delete this attribute value?"}),e.jsx(Et,{children:"This action cannot be undone."})]}),e.jsxs(Ot,{children:[e.jsx(Pt,{children:"Cancel"}),e.jsx(Dt,{className:"bg-red-600 hover:bg-red-700",onClick:()=>D&&H.mutate(D),children:"Delete"})]})]})})]})}function Rr(){const{toast:t}=Pe(),[s,i]=x.useState(!1),[r,l]=x.useState(null),[a,d]=x.useState({slug:"",name:"",description:"",priceMultiplier:"1.0"}),[o,n]=x.useState(null),{data:u=[],isLoading:h}=ne({queryKey:["configV2Tiers"],queryFn:async()=>(await U("query { configV2Tiers { slug name description catalogMode priceMultiplier isActive } }")).configV2Tiers}),c=le({mutationFn:async S=>U("mutation($slug:String!,$name:String,$description:String,$priceMultiplier:Float){configV2UpdateTier(slug:$slug,name:$name,description:$description,priceMultiplier:$priceMultiplier){slug}}",S),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Tiers"]}),t({title:"Updated"}),f()},onError:S=>t({title:"Error",description:S.message,variant:"destructive"})}),y=le({mutationFn:async S=>U("mutation($slug:String!){configV2DeleteTier(slug:$slug)}",{slug:S}),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Tiers"]}),t({title:"Deleted"}),n(null)},onError:S=>t({title:"Error",description:S.message,variant:"destructive"})}),f=()=>{i(!1),l(null),d({slug:"",name:"",description:"",priceMultiplier:"1.0"})},p=S=>{l(S),d({slug:S.slug,name:S.name,description:S.description||"",priceMultiplier:String(S.priceMultiplier)}),i(!0)};return h?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between gap-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Create audiences in Journey, where global repair assignments are reviewed before anything is added. This advanced table retains tier metadata and lifecycle c
86ontrols."})}),e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"Name"}),e.jsx(Q,{children:"Slug"}),e.jsx(Q,{children:"Mode"}),e.jsx(Q,{children:"Legacy multiplier"}),e.jsx(Q,{children:"Status"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsx(ot,{children:[...u].sort((S,T)=>S.name.localeCompare(T.name)).map(S=>e.jsxs(Ie,{children:[e.jsx(L,{className:"font-medium",children:S.name}),e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:S.slug})}),e.jsx(L,{children:S.catalogMode==="v1_import"?"Imported":"Native"}),e.jsxs(L,{children:[S.priceMultiplier,"Ã"]}),e.jsx(L,{children:S.isActive?e.jsx(me,{children:"Active"}):e.jsx(me,{variant:"secondary",children:"Inactive"})}),e.jsxs(L,{className:"text-right",children:[e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>p(S),children:e.jsx(zt,{className:"h-4 w-4"})}),e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>n(S.slug),children:e.jsx(Xe,{className:"h-4 w-4 text-red-600"})})]})]},S.slug))})]}),e.jsx(ht,{open:s,onOpenChange:S=>{S||f()},children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsx(vt,{children:"Edit Tier"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(ee,{placeholder:"Name",value:a.name,onChange:S=>d(T=>({...T,name:S.target.value}))}),e.jsx(ee,{placeholder:"Description",value:a.description,onChange:S=>d(T=>({...T,description:S.target.value}))}),e.jsx(ee,{placeholder:"Price Multiplier",type:"number",step:"0.01",value:a.priceMultiplier,onChange:S=>d(T=>({...T,priceMultiplier:S.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This multiplier belongs to the legacy generated-product path. Compiled R1 pricing is authored in Journey."})]}),e.jsx(jt,{children:e.jsx(A,{onClick:()=>{const S=parseFloat(a.priceMultiplier);r&&c.mutate({slug:r.slug,name:a.name,description:a.description,priceMultiplier:S})},disabled:!r||!a.name,children:c.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):"Save"})})]})}),e.jsx(Tt,{open:o!==null,onOpenChange:()=>n(null),children:e.jsxs(It,{children:[e.jsxs(Vt,{children:[e.jsxs(Rt,{children:['Delete tier "',o,'"?']}),e.jsx(Et,{children:"This will remove the tier and associated products."})]}),e.jsxs(Ot,{children:[e.jsx(Pt,{children:"Cancel"}),e.jsx(Dt,{className:"bg-red-600 hover:bg-red-700",onClick:()=>o&&y.mutate(o),children:"Delete"})]})]})})]})}function Er(){var N;const{toast:t}=Pe(),[s,i]=x.useState("all"),[r,l]=x.useState(""),[a,d]=x.useState(""),[o,n]=x.useState(new Set),[u,h]=x.useState(!1),[c,y]=x.useState(null),[f,p]=x.useState({entityType:"garment",entitySlug:"",attributeSlug:"",term:"",matchType:"exact",confidence:"1.0"}),[S,T]=x.useState(null),{data:C=[],isLoading:v}=ne({queryKey:["configV2Synonyms",s==="all"?void 0:s,r||void 0,a||void 0],queryFn:async()=>{const m={};return s!=="all"&&(m.entityType=s),r&&(m.entitySlug=r),a&&(m.search=a),(await U("query($entityType:String,$entitySlug:String,$search:String){configV2Synonyms(entityType:$entityType,entitySlug:$entitySlug,search:$search){id entityType entitySlug attributeSlug term matchType confidence isActive source}}",m)).configV2Synonyms}}),{data:O=[]}=ne({queryKey:["configV2Garments"],queryFn:async()=>(await U("query { configV2Garments { slug name } }")).configV2Garments}),{data:P=[]}=ne({queryKey:["configV2Services"],queryFn:async()=>(await U("query { configV2Services { slug name } }")).configV2Services}),{data:$=[]}=ne({queryKey:["configV2Attributes","synonymsPage"],queryFn:async()=>(await U("query { configV2Attributes { slug name type isActive values { id attributeSlug value label } } }")).configV2Attributes}),b=le({mutationFn:async m=>U("mutation($entityType:String!,$entitySlug:String!,$attributeSlug:String,$term:String!,$matchType:String!,$confidence:Float){configV2CreateSynonym(entityType:$entityType,entitySlug:$entitySlug,attributeSlug:$attributeSlug,term:$term,matchType:$matchType,confidence:$confidence){id}}",m),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Synonyms"]}),t({title:"Synonym created"}),D()},onError:m=>t({title:"Error",description:m.message,variant:"destructive"})}),j=le({mutationFn:async m=>U("mutation($id:Int!,$term:String,$matchType:String,$confidence:Float,$isActive:Boolean){configV2UpdateSynonym(id:$id,term:$term,matchType:$matchType,confidence:$confidence,isActive:$isActive){id}}",m),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Synonyms"]}),t({title:"Updated"}),D()},onError:m=>t({title:"Error",description:m.message,variant:"destructive"})}),V=le({mutationFn:async m=>U("mutation($id:Int!){configV2DeleteSynonym(id:$id)}",{id:m}),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Synonyms"]}),t({title:"Deleted"}),T(null)},onError:m=>t({title:"Error",description:m.message,variant:"destructive"})}),R=le({mutationFn:async m=>U("mutation($ids:[Int!]!){configV2BulkDeleteSynonyms(ids:$ids)}",{ids:m}),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Synonyms"]}),t({title:`Deleted ${o.size} synonyms`}),n(new Set)},onError:m=>t({title:"Error",description:m.message,variant:"destructive"})}),D=()=>{h(!1),y(null),p({entityType:"garment",entitySlug:"",attributeSlug:"",term:"",matchType:"exact",confidence:"1.0"})},E=m=>{y(m),p({entityType:m.entityType,entitySlug:m.entitySlug,attributeSlug:m.attributeSlug||"",term:m.term,matchType:m.matchType,confidence:String(m.confidence)}),h(!0)};return v?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs(fe,{value:s,onValueChange:i,children:[e.jsx(be,{className:"w-44",children:e.jsx(ye,{})}),e.jsxs(Se,{children:[e.jsx(se,{value:"all",children:"All Types"}),e.jsx(se,{value:"garment",children:"Garment"}),e.jsx(se,{value:"service",children:"Service"}),e.jsx(se,{value:"attribute_value",children:"Attribute Value"})]})]}),e.jsx(ee,{className:"w-44",placeholder:"Entity slug...",value:r,onChange:m=>l(m.target.value)}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ds,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),e.jsx(ee,{className:"pl-9",placeholder:"Search terms...",value:a,onChange:m=>d(m.target.value)})]}),e.jsxs(A,{size:"sm",onClick:()=>{y(null),p({entityType:"garment",entitySlug:"",attributeSlug:"",term:"",matchType:"exact",confidence:"1.0"}),h(!0)},children:[e.jsx(Qe,{className:"h-4 w-4 mr-1"}),"Add"]}),e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>{const m=["term,entityType,entitySlug,attributeSlug,matchType,confidence,isActive,source",...C.map(de=>`"${de.term}",${de.entityType},${de.entitySlug},${de.attributeSlug||""},${de.matchType},${de.confidence},${de.isActive},${de.source}`)].join(` 87`),G=new Blob([m],{type:"text/csv"}),X=URL.createObjectURL(G),ce=document.createElement("a");ce.href=X,ce.download=`synonyms-export-${new Date().toISOString().slice(0,10)}.csv`,ce.click(),URL.revokeObjectURL(X)},children:[e.jsx(Ui,{className:"h-4 w-4 mr-1"}),"Export"]}),o.size>0&&e.jsxs(A,{size:"sm",variant:"destructive",onClick:()=>R.mutate(Array.from(o)),children:[e.jsx(Xe,{className:"h-4 w-4 mr-1"}),"Delete ",o.size]}),e.jsxs(me,{variant:"outline",children:[C.length," synonyms"]})]}),e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{className:"w-8",children:e.jsx("input",{type:"checkbox",checked:o.size===C.length&&C.length>0,onChange:m=>n(m.target.checked?new Set(C.map(G=>
87G.id)):new Set)})}),e.jsx(Q,{children:"Term"}),e.jsx(Q,{children:"Entity Type"}),e.jsx(Q,{children:"Entity Slug"}),e.jsx(Q,{children:"Attribute"}),e.jsx(Q,{children:"Match"}),e.jsx(Q,{children:"Confidence"}),e.jsx(Q,{children:"Active"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsx(ot,{children:C.map(m=>e.jsxs(Ie,{children:[e.jsx(L,{children:e.jsx("input",{type:"checkbox",checked:o.has(m.id),onChange:G=>{const X=new Set(o);G.target.checked?X.add(m.id):X.delete(m.id),n(X)}})}),e.jsx(L,{className:"font-medium",children:m.term}),e.jsx(L,{children:e.jsx(me,{variant:"outline",children:m.entityType})}),e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:m.entitySlug})}),e.jsx(L,{children:m.attributeSlug||"â"}),e.jsx(L,{children:m.matchType}),e.jsxs(L,{children:[Math.round(m.confidence*100),"%"]}),e.jsx(L,{children:e.jsx(_e,{checked:m.isActive,onCheckedChange:G=>j.mutate({id:m.id,isActive:G})})}),e.jsxs(L,{className:"text-right",children:[e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>E(m),children:e.jsx(zt,{className:"h-4 w-4"})}),e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>T(m.id),children:e.jsx(Xe,{className:"h-4 w-4 text-red-600"})})]})]},m.id))})]}),e.jsx(ht,{open:u,onOpenChange:m=>{m||D()},children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsx(vt,{children:c?"Edit Synonym":"Add Synonym"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(ee,{placeholder:"Term",value:f.term,onChange:m=>p(G=>({...G,term:m.target.value}))}),!c&&e.jsxs(e.Fragment,{children:[e.jsxs(fe,{value:f.entityType,onValueChange:m=>p(G=>({...G,entityType:m,entitySlug:"",attributeSlug:""})),children:[e.jsx(be,{children:e.jsx(ye,{})}),e.jsxs(Se,{children:[e.jsx(se,{value:"garment",children:"Garment"}),e.jsx(se,{value:"service",children:"Service"}),e.jsx(se,{value:"attribute_value",children:"Attribute Value"})]})]}),f.entityType==="garment"&&e.jsxs(fe,{value:f.entitySlug,onValueChange:m=>p(G=>({...G,entitySlug:m})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select garment"})}),e.jsx(Se,{children:O.map(m=>e.jsx(se,{value:m.slug,children:m.name},m.slug))})]}),f.entityType==="service"&&e.jsxs(fe,{value:f.entitySlug,onValueChange:m=>p(G=>({...G,entitySlug:m})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select service"})}),e.jsx(Se,{children:P.map(m=>e.jsx(se,{value:m.slug,children:m.name},m.slug))})]}),f.entityType==="attribute_value"&&e.jsxs(e.Fragment,{children:[e.jsxs(fe,{value:f.attributeSlug,onValueChange:m=>p(G=>({...G,attributeSlug:m,entitySlug:""})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select attribute"})}),e.jsx(Se,{children:$.map(m=>e.jsx(se,{value:m.slug,children:m.name},m.slug))})]}),f.attributeSlug&&e.jsxs(fe,{value:f.entitySlug,onValueChange:m=>p(G=>({...G,entitySlug:m})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select value"})}),e.jsx(Se,{children:(((N=$.find(m=>m.slug===f.attributeSlug))==null?void 0:N.values)||[]).map(m=>e.jsx(se,{value:m.value,children:m.label},m.value))})]})]})]}),e.jsxs(fe,{value:f.matchType,onValueChange:m=>p(G=>({...G,matchType:m})),children:[e.jsx(be,{children:e.jsx(ye,{})}),e.jsxs(Se,{children:[e.jsx(se,{value:"exact",children:"Exact"}),e.jsx(se,{value:"contains",children:"Contains"}),e.jsx(se,{value:"fuzzy",children:"Fuzzy"})]})]}),e.jsx(ee,{placeholder:"Confidence (0-1)",type:"number",step:"0.1",min:"0",max:"1",value:f.confidence,onChange:m=>p(G=>({...G,confidence:m.target.value}))})]}),e.jsx(jt,{children:e.jsx(A,{onClick:()=>{const m=parseFloat(f.confidence);c?j.mutate({id:c.id,term:f.term,matchType:f.matchType,confidence:m}):b.mutate({entityType:f.entityType,entitySlug:f.entitySlug,attributeSlug:f.attributeSlug||void 0,term:f.term,matchType:f.matchType,confidence:m})},disabled:!f.term||!c&&!f.entitySlug,children:c?"Save":"Create"})})]})}),e.jsx(Tt,{open:S!==null,onOpenChange:()=>T(null),children:e.jsxs(It,{children:[e.jsxs(Vt,{children:[e.jsx(Rt,{children:"Delete this synonym?"}),e.jsx(Et,{children:"This action cannot be undone."})]}),e.jsxs(Ot,{children:[e.jsx(Pt,{children:"Cancel"}),e.jsx(Dt,{className:"bg-red-600 hover:bg-red-700",onClick:()=>S&&V.mutate(S),children:"Delete"})]})]})})]})}function Or(){var j,V,R,D,E;const{toast:t}=Pe(),[s,i]=x.useState("all"),[r,l]=x.useState("all"),[a,d]=x.useState("all"),[o,n]=x.useState(""),[u,h]=x.useState(!1),{data:c=[],isLoading:y}=ne({queryKey:["configV2Products",s==="all"?void 0:s,r==="all"?void 0:r,a==="all"?void 0:a,o||void 0],queryFn:async()=>{const N={};return s!=="all"&&(N.tierSlug=s),r!=="all"&&(N.garmentSlug=r),a!=="all"&&(N.serviceSlug=a),o&&(N.search=o),(await U("query($tierSlug:String,$garmentSlug:String,$serviceSlug:String,$search:String){configV2Products(tierSlug:$tier
87Slug,garmentSlug:$garmentSlug,serviceSlug:$serviceSlug,search:$search){id sku tierSlug garmentSlug serviceSlug name garmentName serviceName basePriceCents finalPriceCents standardMinutes requiresQuote isActive}}",N)).configV2Products}}),{data:f}=ne({queryKey:["configV2ProductCount"],queryFn:async()=>(await U("query{configV2ProductCount{total byTier}}")).configV2ProductCount}),{data:p=[]}=ne({queryKey:["configV2Tiers"],queryFn:async()=>(await U("query{configV2Tiers{slug name description catalogMode priceMultiplier isActive}}")).configV2Tiers}),{data:S=[]}=ne({queryKey:["configV2Garments"],queryFn:async()=>(await U("query{configV2Garments{slug name}}")).configV2Garments}),{data:T=[]}=ne({queryKey:["configV2Services"],queryFn:async()=>(await U("query{configV2Services{slug name}}")).configV2Services}),{data:C,isLoading:v,refetch:O}=ne({queryKey:["configV2PreviewRegeneration"],queryFn:async()=>(await U("query{configV2PreviewRegeneration{added{sku name basePriceCents requiresQuote}removed{sku name requiresQuote}priceChanges{sku oldPrice newPrice}quoteChanges{sku oldRequiresQuote newRequiresQuote}totalNew totalRemoved totalChanged ambiguityWarnings{tierSlug garmentSlug serviceSlug slot differingValues candidateSkus} blockingIssues{tierSlug garmentSlug serviceSlug attributeSlug attributeName message} baseOnlyWarnings{tierSlug garmentSlug serviceSlug scopedOutAttributes sku}}}")).configV2PreviewRegeneration,enabled:u}),P=((j=C==null?void 0:C.blockingIssues)==null?void 0:j.length)??0,$=((V=C==null?void 0:C.baseOnlyWarnings)==null?void 0:V.length)??0,b=le({mutationFn:async()=>U("mutation{configV2ExecuteRegeneration}"),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Products"]}),Z.invalidateQueries({queryKey:["configV2ProductCount"]}),t({title:"Products regenerated"}),h(!1)},onError:N=>t({title:"Error",description:N.message,variant:"destructive"})});return y?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:f?`${f.total} total products`:""}),e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>{h(!0),O()},children:[e.jsx($s,{className:"h-4 w-4 mr-1"}),"Regenerate Products"]})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs(fe,{value:s,onValueChange:i,children:[e.jsx(be,{className:"w-40",children:e.jsx(ye,{placeholder:"All Tiers"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"all",children:"All Tiers"}),p.map(N=>e.jsx(se,{value:N.slug,children:N.name},N.slug))]})]}),e.jsxs(fe,{value:r,onValueChange:l,children:[e.jsx(be,{className:"w-40",children:e.jsx(ye,{placeholder:"All Garments"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"all",children:"All Garments"}),S.map(N=>e.jsx(se,{value:N.slug,children:N.name},N.slug))]})]}),e.jsxs(fe,{value:a,onValueChange:d,children:[e.jsx(be,{className:"w-40",children:e.jsx(ye,{placeholder:"All Services"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"all",children:"All Services"}),T.map(N=>e.jsx(se,{value:N.slug,children:N.name},N.slug))]})]}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ds,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),e.jsx(ee,{className:"pl-9",placeholder:"Search products...",value:o,onChange:N=>n(N.target.value)})]})]}),e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"SKU"}),e.jsx(Q,{children:"Name"}),e.jsx(Q,{children:"Tier"}),e.jsx(Q,{children:"Garment"}),e.jsx(Q,{children:"Service"}),e.jsx(Q,{children:"Base Price"}),e.jsx(Q,{children:"Final Price"}),e.jsx(Q,{children:"Std Min"}),e.jsx(Q,{children:"Quote"}),e.jsx(Q,{children:"Active"})]})}),e.jsx(ot,{children:c.map(N=>e.jsxs(Ie,{children:[e.jsx(L,{children:e.jsx("code",{className:"text-xs",children:N.sku})}),e.jsx(L,{className:"font-medium",children:N.name}),e.jsx(L,{children:e.jsx(me,{variant:"outline",children:N.tierSlug})}),e.jsx(L,{children:N.garmentName}),e.jsx(L,{children:N.serviceName}),e.jsx(L,{children:We(N.basePriceCents)}),e.jsx(L,{children:We(N.finalPriceCents)}),e.jsx(L,{className:"text-center",children:N.standardMinutes!=null?`${N.standardMinutes}m`:"â"}),e.jsx(L,{children:N.requiresQuote?e.jsx(me,{variant:"outline",className:"border-amber-300 text-amber-700",children:"Quote"}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx(L,{children:N.isActive?e.jsx(me,{children:"Active"}):e.jsx(me,{variant:"secondary",children:"Inactive"})})]},N.sku))})]}),e.jsx(ht,{open:u,onOpenChange:h,children:e.jsxs(xt,{className:"max-w-2xl",children:[e.jsx(pt,{children:e.jsx(vt,{children:"Regenerate Products Preview"})}),v?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):C?e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 xl:grid-cols-7 gap-3",children:[e.jsx(nt,{children:e.jsxs(lt,{className:"p-3 text-center",children:[e.jsxs("div",{className:"text-lg font-bold text-green-600",children:["+",C.totalNew]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"New"})]})}),e.jsx(nt,{children:e.jsxs(lt,{className:"p-3 text-center",children:[e.jsxs("div",{className:"text-lg font-bold text-red-600",children:["-",C.totalRemoved]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Removed"})]})}),e.jsx(nt,{children:e.jsxs(lt,{className:"p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-yellow-600",children:C.totalChanged}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Changed"})]})}),e.jsx(nt,{children:e.jsxs(lt,{className:"p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-amber-600",children:C.quoteChanges.length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Quote changes"})]})}),e.jsx(nt,{className:$>0?"border-amber-500":"",title:"Cells that emitted one bare-base SKU because every slot attribute is scoped out of a tier.","data-testid":"regen-base-only-card",children:e.jsxs(lt,{className:"p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-amber-600",children:$}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Base-only warnings"})]})}),e.jsx(nt,{className:P>0?"border-red-500":"",title:"Required garment-scope configuration issues that block product regeneration.","data-testid":"regen-blocking-card",children:e.jsxs(lt,{className:"p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-red-600",children:P}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Blocking issues"})]})}),e.jsx(nt,{className:(((R=C.ambiguityWarnings)==null?void 0:R.length)??0)>0?"border-amber-500":"",title:"Cells where multiple SKUs would still match a wizard-completed answer set. Fix by adding a dependency or removing orphan SKUs.","data-testid":"regen-ambiguity-card",children:e.jsxs(lt,{className:"p-3 text-center",children:[e.jsx("div",{className:"text-lg font-bold text-amber-600",children:((D=C.ambiguityWarnings)==null?void 0:D.length)??0}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Ambiguity warnings"})]})})]}),P>0&&e.jsxs("div",{"data-testid":"regen-blocking-list",children:[e.jsx("p",{className:"font-medium mb-1 text-red-700",children:"Regeneration blocked:"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"These required questions would have no visible garment-scoped answers. Keep one value visible, add another active value, deactivate or fix the affected cell manually, or intentionally change requiredness for the service."}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:C.blockingIssues.slice(0,50).map((N,m)=>e.jsxs("div",{className:"border border-red-200 bg-red-50 rounded px-2 py-1 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:N.tier
87Slug})," / ",N.garmentSlug," / ",N.serviceSlug," â",N.attributeName?e.jsxs(e.Fragment,{children:[" attribute ",e.jsx("code",{className:"bg-white px-1 rounded",children:N.attributeName})]}):e.jsx(e.Fragment,{children:" garment taxonomy"})]}),e.jsx("div",{className:"text-muted-foreground mt-0.5",children:N.message})]},`${N.tierSlug}-${N.garmentSlug}-${N.serviceSlug}-${N.attributeSlug??"taxonomy"}-${m}`))})]}),$>0&&e.jsxs("div",{"data-testid":"regen-base-only-list",children:[e.jsx("p",{className:"font-medium mb-1 text-amber-700",children:"Base-only warnings:"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"These cells will generate one bare-base SKU because every slot question is scoped out for the tier."}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:C.baseOnlyWarnings.slice(0,50).map((N,m)=>e.jsxs("div",{className:"border border-amber-200 bg-amber-50 rounded px-2 py-1 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:N.tierSlug})," / ",N.garmentSlug," / ",N.serviceSlug]}),e.jsxs("div",{className:"text-muted-foreground mt-0.5",children:["SKU ",e.jsx("code",{className:"bg-white px-1 rounded",children:N.sku}),"; scoped-out slots: ",N.scopedOutAttributes.join(", ")]})]},`${N.tierSlug}-${N.garmentSlug}-${N.serviceSlug}-${N.sku}-${m}`))})]}),C.priceChanges.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"font-medium mb-1",children:"Price Changes:"}),e.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:C.priceChanges.slice(0,20).map(N=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("code",{children:N.sku}),e.jsxs("span",{children:[We(N.oldPrice)," â ",We(N.newPrice)]})]},N.sku))})]}),C.quoteChanges.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"font-medium mb-1",children:"Quote Changes:"}),e.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:C.quoteChanges.slice(0,20).map(N=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("code",{children:N.sku}),e.jsxs("span",{children:[N.oldRequiresQuote?"Quote":"Priced"," â ",N.newRequiresQuote?"Quote":"Priced"]})]},N.sku))})]}),(((E=C.ambiguityWarnings)==null?void 0:E.length)??0)>0&&e.jsxs("div",{"data-testid":"regen-ambiguity-list",children:[e.jsx("p",{className:"font-medium mb-1 text-amber-700",children:"Ambiguity warnings:"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"These cells emit multiple SKUs that the wizard would not force the user to disambiguate. The runtime would silently pick one. Fix by adding a dependency or removing the orphan slot mapping."}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:C.ambiguityWarnings.slice(0,50).map((N,m)=>e.jsxs("div",{className:"border border-amber-200 bg-amber-50 rounded px-2 py-1 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:N.tierSlug})," / ",N.garmentSlug," / ",N.serviceSlug," â"," ","slot ",e.jsx("code",{className:"bg-white px-1 rounded",children:N.slot})," ","differs on ",N.differingValues.join(", ")]}),e.jsxs("div",{className:"text-muted-foreground mt-0.5",children:["SKUs: ",N.candidateSkus.slice(0,3).map((G,X)=>e.jsx("code",{className:"mr-1",children:G},X)),N.candidateSkus.length>3&&e.jsxs("span",{children:["+",N.candidateSkus.length-3," more"]})]})]},`${N.tierSlug}-${N.garmentSlug}-${N.serviceSlug}-${N.slot}-${m}`))})]})]}):null,e.jsxs(jt,{children:[e.jsx(A,{variant:"outline",onClick:()=>h(!1),children:"Cancel"}),e.jsxs(A,{onClick:()=>b.mutate(),disabled:b.isPending||P>0,children:[b.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin mr-1"}):null,"Confirm Regeneration"]})]})]})})]})}function Pr(){const{toast:t}=Pe(),[s,i]=x.useState("failed"),[r,l]=x.useState(null),{data:a=[],isLoading:d}=ne({queryKey:["configV2FailedParses"],queryFn:async()=>(await U("query{configV2FailedParses(limit:100){id inputText parsedResult missingEntities unmatchedTokens status createdAt}}")).configV2FailedParses}),{data:o=[],isLoading:n}=ne({queryKey:["configV2UnmatchedTerms"],queryFn:async()=>(await U("query{configV2UnmatchedTerms{term count lastSeen}}")).configV2UnmatchedTerms}),u=le({mutationFn:async c=>U("mutation($entityType:String!,$entitySlug:String!,$attributeSlug:String,$term:String!,$matchType:String!,$confidence:Float){configV2CreateSynonym(entityType:$entityType,entitySlug:$entitySlug,attributeSlug:$attributeSlug,term:$term,matchType:$matchType,confidence:$confidence){id}}",c),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Synonyms"]}),Z.invalidateQueries({queryKey:["configV2UnmatchedTerms"]}),t({title:"Synonym created from suggestion"})},onError:c=>t({title:"Error",description:c.message,variant:"destructive"})});return(s==="failed"?d:n)?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(A,{size:"sm",variant:s==="failed"?"default":"outline",onClick:()=>i("failed"),children:[e.jsx(St,{className:"h-4 w-4 mr-1"}),"Failed Parses (",a.length,")"]}),e.jsxs(A,{size:"sm",variant:s==="unmatched"?"default":"outline",onClick:()=>i("unmatched"),children:[e.jsx(mr,{className:"h-4 w-4 mr-1"}),"Learning Suggestions (",o.length,")"]})]}),s==="failed"?e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"Input"}),e.jsx(Q,{children:"Missing"}),e.jsx(Q,{children:"Unmatched"}),e.jsx(Q,{children:"Status"}),e.jsx(Q,{children:"Date"})]})}),e.jsxs(ot,{children:[a.map(c=>e.jsxs(Ie,{children:[e.jsx(L,{className:"max-w-[200px] truncate font-medium",children:c.inputText}),e.jsx(L,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:c.missingEntities.map((y,f)=>e.jsx(me,{variant:"secondary",className:"text-xs",children:y},f))})}),e.jsx(L,{children:e.jsx("div",{className:"flex flex-wrap gap-1",children:c.unmatchedTokens.map((y,f)=>e.jsx(me,{variant:"outline",className:"text-xs",children:y},f))})}),e.jsx(L,{children:e.jsx(me,{variant:c.status==="resolved"?"default":"secondary",children:c.status})}),e.jsx(L,{className:"text-xs text-muted-foreground",children:new Date(c.createdAt).toLocaleDateString()})]},c.id)),a.length===0&&e.jsx(Ie,{children:e.jsx(L,{colSpan:5,className:"text-center text-muted-foreground py-8",children:"No failed parses recorded"})})]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"These terms appeared in user inputs but couldn't be matched to any entity. Consider adding them as synonyms."}),e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"Term"}),e.jsx(Q,{children:"Occurrences"}),e.jsx(Q,{children:"Last Seen"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsxs(ot,{children:[o.map(c=>e.jsxs(Ie,{children:[e.jsx(L,{className:"font-medium",children:c.term}),e.jsx(L,{children:e.jsxs(me,{variant:"outline",children:[c.count,"x"]})}),e.jsx(L,{className:"text-xs text-muted-foreground",children:new Date(c.lastSeen).toLocaleDateString()}),e.jsx(L,{className:"text-right",children:e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>l({term:c.term,entityType:"garment",entitySlug:"",attributeSlug:""}),children:[e.jsx(Qe,{className:"h-3 w-3 mr-1"}),"Add as Synonym"]})})]},c.term)),o.length===0&&e.jsx(Ie,{children:e.jsx(L,{colSpan:4,className:"text-center text-muted-foreground py-8",children:"No unmatched terms found"})})]})]})]}),e.jsx(ht,{open:r!==null,onOpenChange:c=>{c||l(null)},children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsxs(vt,{children:['Create Synonym from "',r==null?void 0:r.term,'"']})}),r&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(ee,{value:r.term,disabled:!0}),e.jsxs(fe,{value:r.entityType,onValueChange:c=>l(y=>y?{...y,entityType:c}:null),children:[e.jsx(be,{children:e.jsx(ye,{})}),e.jsxs(Se,{children:[e.jsx(se,{value:"garment",children:"Garment"}),e.jsx(se,{value:"service",children:"Service"}),e.jsx(se,{value:"attribute_value",children:"Attribute Value"})]})]}),e.jsx(ee,{placeholder:"Entity Slug (e.g. down-jacket)",value:r.entitySlug,onChange:c=>l(y=>y?{...y,entitySlug:c.target.value}:null)}),r.entityType==="attribute_value"&&e.jsx(ee,{placeholder:"Attribute Slug (e.g. size)",value:r.attributeSlug,onChange:c=>l(y=>y?{...y,attributeSlug:c.target.value}:null)})]}),e.jsxs(jt,{children:[e.jsx(A,{variant:"outline",onClick:()=>l(null),children:"Cancel"}),e.jsx(A,{disabled:!(r!=null&&r.entitySlug),onClick:()=>{r&&(u.mutate({entityType:r.entityType,entitySlug:r.entitySlug,attributeSlug:r.attributeSlug||void 0,term:r.term,matchType:"exact",confidence:.8}),l(null))},children:"Create Synonym"})]})]})})]})}function Dr(){const{toast:t}=Pe(),[s,i]=x.useState(null),[r,l]=x.useState("all"),[a,d]=x.useState(!1),[o,n]=x.useState(null),[u,h]=x.useState(""),[c,y]=x.useState(null),f=ne({queryKey:["configV2ChatSessions",r,a],queryFn:async()=>{const v={limit:100};return a&&(v.flaggedOnly=!0),r!=="all"&&(v.status=r),(await U("query($limit:Int,$flaggedOnly:Boolean,$status:String){configV2ChatSessions(limit:$limit,flaggedOnly:$flaggedOnly,status:$status){id operatorName tierSlug status flagged flagNote messageCount transcript cartSnapshot startedAt endedAt}}
87",v)).configV2ChatSessions}}),p=le({mutationFn:async({sessionId:v,flagNote:O})=>{await U("mutation($sessionId:Int!,$flagNote:String!){configV2FlagChatSession(sessionId:$sessionId,flagNote:$flagNote){id}}",{sessionId:v,flagNote:O})},onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2ChatSessions"]}),t({title:"Session flagged"}),n(null),h("")}}),S=le({mutationFn:async v=>{await U("mutation($sessionId:Int!){configV2UnflagChatSession(sessionId:$sessionId){id}}",{sessionId:v})},onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2ChatSessions"]}),t({title:"Flag removed"})}}),T=le({mutationFn:async v=>{await U("mutation($sessionId:Int!){configV2DeleteChatSession(sessionId:$sessionId)}",{sessionId:v})},onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2ChatSessions"]}),t({title:"Session deleted"}),y(null),s&&i(null)}}),C=v=>{try{return JSON.parse(v)}catch{return[]}};if(s){const v=C(s.transcript);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(A,{variant:"ghost",size:"sm",onClick:()=>i(null),children:[e.jsx(Li,{className:"h-4 w-4 mr-1"})," Back to Sessions"]}),e.jsx("div",{className:"flex-1"}),s.flagged?e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>S.mutate(s.id),children:[e.jsx(rt,{className:"h-4 w-4 mr-1"})," Remove Flag"]}):e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>{n(s),h("")},children:[e.jsx(Ns,{className:"h-4 w-4 mr-1"})," Flag Session"]})]}),e.jsxs(nt,{children:[e.jsx(Ut,{children:e.jsxs(Lt,{className:"flex items-center gap-2",children:["Session #",s.id,s.flagged&&e.jsx(me,{variant:"destructive",children:"Flagged"}),e.jsx(me,{variant:s.status==="active"?"default":"secondary",children:s.status})]})}),e.jsxs(lt,{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Operator:"})," ",s.operatorName||"â"]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Tier:"})," ",s.tierSlug||"â"]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Messages:"})," ",s.messageCount]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Started:"})," ",new Date(s.startedAt).toLocaleString()]})]}),s.flagNote&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded p-2 text-red-700",children:[e.jsx("strong",{children:"Flag Note:"})," ",s.flagNote]})]})]}),e.jsxs(nt,{children:[e.jsx(Ut,{children:e.jsx(Lt,{children:"Transcript"})}),e.jsx(lt,{children:e.jsxs("div",{className:"space-y-3 max-h-[600px] overflow-y-auto",children:[v.length===0&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"No messages in this session."}),v.map((O,P)=>e.jsx("div",{className:`flex ${O.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] rounded-lg px-3 py-2 text-sm ${O.role==="user"?"bg-primary text-primary-foreground":O.role==="system"?"bg-muted text-muted-foreground italic":"bg-secondary"}`,children:[e.jsxs("div",{className:"font-medium text-xs mb-1 opacity-70",children:[O.role==="user"?"Customer":O.role==="assistant"?"Bot":"System",O.timestamp&&` · ${new Date(O.timestamp).toLocaleTimeString()}`]}),e.jsx("div",{children:O.content}),O.parseResult&&e.jsxs("details",{className:"mt-1",children:[e.jsx("summary",{className:"text-xs cursor-pointer opacity-70",children:"Parse Result"}),e.jsx("pre",{className:"text-xs mt-1 overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(O.parseResult,null,2)})]})]})},P))]})})]}),s.cartSnapshot&&e.jsxs(nt,{children:[e.jsx(Ut,{children:e.jsx(Lt,{children:"Cart Snapshot"})}),e.jsx(lt,{children:e.jsx("pre",{className:"text-xs overflow-x-auto whitespace-pre-wrap bg-muted p-3 rounded",children:(()=>{try{return JSON.stringify(JSON.parse(s.cartSnapshot),null,2)}catch{return s.cartSnapshot}})()})})]}),e.jsx(ht,{open:!!o,onOpenChange:()=>n(null),children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsx(vt,{children:"Flag Session"})}),e.jsx(ee,{placeholder:"Describe the issue...",value:u,onChange:O=>h(O.target.value)}),e.jsxs(jt,{children:[e.jsx(A,{variant:"outline",onClick:()=>n(null),children:"Cancel"}),e.jsx(A,{disabled:!u.trim(),onClick:()=>o&&p.mutate({sessionId:o.id,flagNote:u}),children:"Flag"})]})]})})]})}return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs(fe,{value:r,onValueChange:l,children:[e.jsx(be,{className:"w-[140px]",children:e.jsx(ye,{})}),e.jsxs(Se,{children:[e.jsx(se,{value:"all",children:"All Status"}),e.jsx(se,{value:"active",children:"Active"}),e.jsx(se,{value:"ended",children:"Ended"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{checked:a,onCheckedChange:d}),e.jsx("span",{className:"text-sm",children:"Flagged Only"})]}),e.jsx("div",{className:"flex-1"}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>f.refetch(),children:[e.jsx($s,{className:"h-4 w-4 mr-1"})," Refresh"]})]}),f.isLoading&&e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(Ne,{className:"h-6 w-6 animate-spin"})}),f.data&&f.data.length===0&&e.jsx(nt,{children:e.jsxs(lt,{className:"py-8 text-center text-muted-foreground",children:[e.jsx(ws,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}
87),e.jsx("p",{children:"No chat sessions yet. Start a test conversation in the Chat tab to begin logging sessions."})]})}),f.data&&f.data.length>0&&e.jsx(nt,{children:e.jsx(lt,{className:"p-0",children:e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{className:"w-[60px]",children:"ID"}),e.jsx(Q,{children:"Operator"}),e.jsx(Q,{children:"Tier"}),e.jsx(Q,{className:"text-center",children:"Messages"}),e.jsx(Q,{children:"Status"}),e.jsx(Q,{children:"Started"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsx(ot,{children:f.data.map(v=>e.jsxs(Ie,{className:v.flagged?"bg-red-50":"",children:[e.jsx(L,{className:"font-mono",children:v.id}),e.jsx(L,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Qi,{className:"h-3 w-3 text-muted-foreground"}),v.operatorName||"â"]})}),e.jsx(L,{children:v.tierSlug||"â"}),e.jsx(L,{className:"text-center",children:v.messageCount}),e.jsxs(L,{children:[e.jsx(me,{variant:v.status==="active"?"default":"secondary",children:v.status}),v.flagged&&e.jsx(me,{variant:"destructive",className:"ml-1",children:"Flagged"})]}),e.jsx(L,{className:"text-sm text-muted-foreground",children:new Date(v.startedAt).toLocaleString()}),e.jsx(L,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>i(v),title:"View",children:e.jsx(Bt,{className:"h-4 w-4"})}),v.flagged?e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>S.mutate(v.id),title:"Remove flag",children:e.jsx(rt,{className:"h-4 w-4 text-red-500"})}):e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>{n(v),h("")},title:"Flag",children:e.jsx(Ns,{className:"h-4 w-4"})}),e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>y(v.id),title:"Delete",children:e.jsx(Xe,{className:"h-4 w-4 text-destructive"})})]})})]},v.id))})]})})}),e.jsx(ht,{open:!!o,onOpenChange:()=>n(null),children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsx(vt,{children:"Flag Session"})}),e.jsx(ee,{placeholder:"Describe the issue...",value:u,onChange:v=>h(v.target.value)}),e.jsxs(jt,{children:[e.jsx(A,{variant:"outline",onClick:()=>n(null),children:"Cancel"}),e.jsx(A,{disabled:!u.trim(),onClick:()=>o&&p.mutate({sessionId:o.id,flagNote:u}),children:"Flag"})]})]})}),e.jsx(Tt,{open:c!==null,onOpenChange:()=>y(null),children:e.jsxs(It,{children:[e.jsxs(Vt,{children:[e.jsx(Rt,{children:"Delete Session?"}),e.jsx(Et,{children:"This permanently deletes the session and its transcript. This cannot be undone."})]}),e.jsxs(Ot,{children:[e.jsx(Pt,{children:"Cancel"}),e.jsx(Dt,{onClick:()=>c&&T.mutate(c),children:"Delete"})]})]})})]})}function Mr(t,s){return t.sets.filter(i=>s.kind==="service"?i.subjectServiceAttributeId===s.id:i.subjectGarmentAttributeId===s.id).map(i=>({contextTierSlug:i.contextTierSlug,contextGarmentServiceId:i.contextGarmentServiceId,isActive:i.isActive,groups:t.groups.filter(r=>r.dependencySetId===i.id).sort((r,l)=>r.displayOrder-l.displayOrder||r.id-l.id).map(r=>({parent:r.parentServiceAttributeId!=null?{kind:"service",id:r.parentServiceAttributeId}:r.parentGarmentAttributeId!=null?{kind:"garment",id:r.parentGarmentAttributeId}:null,attributeValueIds:t.values.filter(l=>l.dependencyGroupId===r.id).map(l=>l.attributeValueId)}))}))}function Fr({attributes:t}){const{toast:s}=Pe(),[i,r]=x.useState(""),[l,a]=x.useState([]),{data:d,isLoading:o}=ne({queryKey:["configV2AttachmentDependencySnapshot"],queryFn:async()=>(await U(` 88 query { 89 configV2AttachmentDependencySnapshot { 90 sets { id subjectServiceAttributeId subjectGarmentAttributeId contextTierSlug contextGarmentServiceId isActive } 91 groups { id dependencySetId parentServiceAttributeId parentGarmentAttributeId displayOrder } 92 values { dependencyGroupId attributeValueId } 93 } 94 } 95 `)).configV2AttachmentDependencySnapshot}),{data:n=[]}=ne({queryKey:["configV2ServiceAttributes","attachmentDependencies"],queryFn:async()=>(await U(` 96 query { configV2ServiceAttributes { id serviceSlug attributeSlug isRequired displayOrder tierScope isActive attributeName attributeType } } 97 `)).configV2ServiceAttributes}),{data:u=[]}=ne({queryKey:["configV2GarmentAttributes","attachmentDependencies"],queryFn:async()=>(await U(` 98 query { configV2GarmentAttributes { id garmentSlug attributeSlug isRequired displayOrder tierScope isActive attributeName attributeType } } 99 `)).configV2GarmentAttributes}),{data:h=[]}=ne({queryKey:["configV2GarmentServices","attachmentDependencies"],queryFn:async()=>(await U(` 100 query { configV2GarmentServices { id garmentSlug serviceSlug garmentName serviceName isActive } } 101 `)).configV2GarmentServices}),{data:c=[]}=ne({queryKey:["configV2Garments","attachmentDependencies"],queryFn:async()=>(await U(` 102 query { configV2Garments { slug name parentSlug isActive } } 103 `)).configV2Garments}),{data:y=[]}=ne({queryKey:["configV2Tiers","attachmentDependencies"],queryFn:async()=>(await U(` 104 query { configV2Tiers { slug name isActive } } 105 `)).configV2Tiers}),f=x.useMemo(()=>[...n.filter(j=>j.isActive!==!1).map(j=>({kind:"service",id:j.id,key:`service:${j.id}`,label:`${j.serviceSlug}: ${j.attributeName||j.attributeSlug}`,attributeSlug:j.attributeSlug,displayOrder:j.displayOrder,serviceSlug:j.serviceSlug})),...u.filter(j=>j.isActive!==!1).map(j=>({kind:"garment",id:j.id,key:`garment:${j.id}`,label:`${j.garmentSlug}: ${j.attributeName||j.attributeSlug}`,attributeSlug:j.attributeSlug,displayOrder:j.displayOrder,garmentSlug:j.garmentSlug}))],[u,n]),p=f.find(j=>j.key===i)??null;x.useEffect(()=>{if(!d||!p){a([]);return}a(Mr(d,p))},[p==null?void 0:p.key,d]);const S=x.useMemo(()=>p?p.kind==="service"?f.filter(j=>(j.kind==="garment"||j.serviceSlug===p.serviceSlug&&j.displayOrder<p.displayOrder)&&j.key!==p.key):f.filter(j=>j.kind==="garment"&&j.displayOrder<p.displayOrder&&j.key!==p.key):[],[f,p]),T=x.useMemo(()=>(p==null?void 0:p.kind)==="service"?h.filter(j=>j.isActive!==!1&&j.serviceSlug===p.serviceSlug&&Ii(c,h,j.garmentSlug)):[],[h,c,p]),
105C=(j,V)=>{a(R=>R.map((D,E)=>E===j?V(D):D))},v=(j,V,R)=>{C(j,D=>({...D,groups:D.groups.map((E,N)=>N===V?R(E):E)}))},O=j=>{var R;if(!j)return[];const V=f.find(D=>D.kind===j.kind&&D.id===j.id);return((R=t.find(D=>D.slug===(V==null?void 0:V.attributeSlug)))==null?void 0:R.values.filter(D=>D.isActive!==!1))??[]},P=l.some((j,V)=>l.some((R,D)=>V!==D&&j.contextTierSlug===R.contextTierSlug&&j.contextGarmentServiceId===R.contextGarmentServiceId)),$=l.length>0&&!P&&l.every(j=>j.groups.every(V=>V.parent!=null&&V.attributeValueIds.length>0)),b=le({mutationFn:async()=>{if(!p)throw new Error("Choose an attachment.");return U(` 106 mutation ReplaceAttachmentDependencies($subject: ConfigV2AttachmentDependencySubjectInput!, $sets: [ConfigV2AttachmentDependencySetInput!]!) { 107 configV2ReplaceAttachmentDependencySets(subject: $subject, sets: $sets) { 108 sets { id subjectServiceAttributeId subjectGarmentAttributeId contextTierSlug contextGarmentServiceId isActive } 109 groups { id dependencySetId parentServiceAttributeId parentGarmentAttributeId displayOrder } 110 values { dependencyGroupId attributeValueId } 111 } 112 } 113 `,{subject:p.kind==="service"?{serviceAttributeId:p.id}:{garmentAttributeId:p.id},sets:l.map(j=>({contextTierSlug:j.contextTierSlug,contextGarmentServiceId:p.kind==="service"?j.contextGarmentServiceId:null,isActive:j.isActive,groups:j.groups.map((V,R)=>{var D,E;return{parent:((D=V.parent)==null?void 0:D.kind)==="service"?{serviceAttributeId:V.parent.id}:{garmentAttributeId:(E=V.parent)==null?void 0:E.id},displayOrder:R,attributeValueIds:V.attributeValueIds}})}))})},onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2AttachmentDependencySnapshot"]}),s({title:"Attachment rules saved"})},onError:j=>s({title:"Unable to save attachment rules",description:j.message,variant:"destructive"})});return o?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(Ne,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsxs("section",{className:"space-y-3 border-b pb-6","data-testid":"attachment-dependency-authoring",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"min-w-72 flex-1",children:[e.jsx("div",{className:"mb-2 text-sm font-semibold",children:"Attachment Rules"}),e.jsx("label",{className:"text-sm font-medium",children:"Attachment"}),e.jsxs(fe,{value:i,onValueChange:r,children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select a question attachment"})}),e.jsx(Se,{children:f.map(j=>e.jsx(se,{value:j.key,children:j.label},j.key))})]})]}),e.jsxs(A,{size:"sm",onClick:()=>a(j=>[...j,{contextTierSlug:null,contextGarmentServiceId:null,isActive:!0,groups:[]}]),disabled:!p,"data-testid":"attachment-dependency-add-set",children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"Add Rule Set"]})]}),p&&l.length===0&&e.jsx("div",{className:"py-4 text-sm text-muted-foreground",children:"No canonical rule sets for this attachment."}),l.map((j,V)=>{var R;return e.jsxs("div",{className:"space-y-3 border p-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto_auto] md:items-end",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Audience"}),e.jsxs(fe,{value:j.contextTierSlug??"__all",onValueChange:D=>C(V,E=>({...E,contextTierSlug:D==="__all"?null:D})),children:[e.jsx(be,{children:e.jsx(ye,{})}),e.jsxs(Se,{children:[e.jsx(se,{value:"__all",children:"All audiences"}),y.filter(D=>D.isActive!==!1).map(D=>e.jsx(se,{value:D.slug,children:D.name},D.slug))]})]})]}),(p==null?void 0:p.kind)==="service"?e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Garment-service cell"}),e.jsxs(fe,{value:((R=j.contextGarmentServiceId)==null?void 0:R.toString())??"__all",onValueChange:D=>C(V,E=>({...E,contextGarmentServiceId:D==="__all"?null:Number(D)})),children:[e.jsx(be,{children:e.jsx(ye,{})}),e.jsxs(Se,{children:[e.jsx(se,{value:"__all",children:"All cells"}),T.map(D=>e.jsx(se,{value:String(D.id),children:D.garmentName||D.garmentSlug},D.id))]})]})]}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-2 pb-2",children:[e.jsx(_e,{checked:j.isActive,onCheckedChange:D=>C(V,E=>({...E,isActive:D}))}),e.jsx("span",{className:"text-sm",children:"Active"})]}),e.jsx(A,{variant:"ghost",size:"icon",title:"Remove rule set",onClick:()=>a(D=>D.filter((E,N)=>N!==V)),children:e.jsx(Xe,{className:"h-4 w-4 text-destructive"})})]}),e.jsxs("div",{className:"space-y-2",children:[j.groups.map((D,E)=>{const N=D.parent?`${D.parent.kind}:${D.parent.id}`:"__none",m=O(D.parent);return e.jsxs("div",{className:"space-y-2 border-l-2 pl-3",children:[e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"min-w-64 flex-1",children:[e.jsx("label",{className:"text-sm font-medium",children:"Parent attachment"}),e.jsxs(fe,{value:N,onValueChange:G=>{const X=G==="__none"?null:(()=>{const[ce,de]=G.split(":");return{kind:ce,id:Number(de)}})();v(V,E,()=>({parent:X,attributeValueIds:[]}))},children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select parent attachment"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"__none",children:"Select parent attachment"}),S.map(G=>e.jsx(se,{value:G.key,children:G.label},G.key))]})]})]}),e.jsx(A,{variant:"ghost",size:"icon",title:"Move condition earlier",disabled:E===0,onClick:()=>C(V,G=>{const X=[...G.groups];
113return[X[E-1],X[E]]=[X[E],X[E-1]],{...G,groups:X}}),children:e.jsx(ii,{className:"h-4 w-4"})}),e.jsx(A,{variant:"ghost",size:"icon",title:"Move condition later",disabled:E===j.groups.length-1,onClick:()=>C(V,G=>{const X=[...G.groups];return[X[E+1],X[E]]=[X[E],X[E+1]],{...G,groups:X}}),children:e.jsx(Kt,{className:"h-4 w-4"})}),e.jsx(A,{variant:"ghost",size:"icon",title:"Remove condition",onClick:()=>C(V,G=>({...G,groups:G.groups.filter((X,ce)=>ce!==E)})),children:e.jsx(Xe,{className:"h-4 w-4 text-destructive"})})]}),D.parent&&e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:m.map(G=>{const X=D.attributeValueIds.includes(G.id);return e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:X,onChange:()=>v(V,E,ce=>({...ce,attributeValueIds:X?ce.attributeValueIds.filter(de=>de!==G.id):[...ce.attributeValueIds,G.id]}))}),G.label]},G.id)})})]},E)}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>C(V,D=>({...D,groups:[...D.groups,{parent:null,attributeValueIds:[]}]})),children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"Add Condition"]})]})]},V)}),P&&e.jsx("div",{className:"text-sm text-destructive",children:"Each audience and garment-service context can have one rule set."}),p&&l.length>0&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(A,{disabled:!$||b.isPending,onClick:()=>b.mutate(),"data-testid":"attachment-dependency-save",children:[b.isPending?e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}):e.jsx(Qt,{className:"mr-1 h-4 w-4"}),"Save Attachment Rules"]})})]})}function Gr({lens:t=es,onImportedCountChange:s}={}){var T;const{toast:i}=Pe(),r=t.tierSlug!==null,[l,a]=x.useState(!1),[d,o]=x.useState({attributeSlug:"",dependsOnAttribute:"",dependsOnValue:""}),{data:n=[],isLoading:u}=ne({queryKey:["configV2Dependencies",t.tierSlug??"all"],queryFn:async()=>(await U("query($tierSlug:String){configV2Dependencies(tierSlug:$tier
113Slug){id attributeSlug dependsOnAttributeSlug dependsOnValue}}",{tierSlug:t.tierSlug})).configV2Dependencies}),h=ms(n,t,s,C=>Ft(C.attributeSlug)?C.attributeSlug:C.dependsOnAttributeSlug),{data:c=[]}=ne({queryKey:["configV2Attributes","dependenciesPage"],queryFn:async()=>(await U("query { configV2Attributes { slug name type isActive values { id attributeSlug value label isActive } } }")).configV2Attributes}),y=le({mutationFn:async C=>U("mutation($attributeSlug:String!,$dependsOnAttribute:String!,$dependsOnValue:String!){configV2CreateDependency(attributeSlug:$attributeSlug,dependsOnAttribute:$dependsOnAttribute,dependsOnValue:$dependsOnValue){id}}",C),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Dependencies"]}),i({title:"Dependency created"}),a(!1),o({attributeSlug:"",dependsOnAttribute:"",dependsOnValue:""})},onError:C=>i({title:"Error",description:C.message,variant:"destructive"})}),f=le({mutationFn:async C=>U("mutation($id:Int!){configV2DeleteDependency(id:$id)}",{id:C}),onSuccess:()=>{Z.invalidateQueries({queryKey:["configV2Dependencies"]}),i({title:"Dependency deleted"})},onError:C=>i({title:"Error",description:C.message,variant:"destructive"})}),p=C=>{var v;return((v=c.find(O=>O.slug===C))==null?void 0:v.name)||C},S=d.dependsOnAttribute?((T=c.find(C=>C.slug===d.dependsOnAttribute))==null?void 0:T.values)||[]:[];return u?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ne,{className:"h-8 w-8 animate-spin text-gray-400"})}):e.jsxs("div",{className:"space-y-4",children:[!r&&e.jsx(Fr,{attributes:c}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Legacy Global Dependencies"}),!r&&e.jsx("div",{children:e.jsxs(A,{size:"sm",onClick:()=>{o({attributeSlug:"",dependsOnAttribute:"",dependsOnValue:""}),a(!0)},children:[e.jsx(Qe,{className:"h-4 w-4 mr-1"}),"Add Dependency"]})})]}),e.jsxs(ct,{children:[e.jsx(dt,{children:e.jsxs(Ie,{children:[e.jsx(Q,{children:"Attribute"}),e.jsx(Q,{children:"Depends On"}),e.jsx(Q,{children:"Value"}),e.jsx(Q,{children:"Rule"}),e.jsx(Q,{className:"text-right",children:"Actions"})]})}),e.jsxs(ot,{children:[h.map(C=>e.jsxs(Ie,{children:[e.jsx(L,{className:"font-medium",children:p(C.attributeSlug)}),e.jsx(L,{children:p(C.dependsOnAttributeSlug)}),e.jsx(L,{children:e.jsx(me,{variant:"outline",children:C.dependsOnValue})}),e.jsxs(L,{className:"text-sm text-muted-foreground",children:["Show ",e.jsx("code",{className:"text-xs",children:C.attributeSlug})," only when ",e.jsx("code",{className:"text-xs",children:C.dependsOnAttributeSlug})," = ",e.jsx("code",{className:"text-xs",children:C.dependsOnValue})]}),e.jsx(L,{className:"text-right",children:!r&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>f.mutate(C.id),children:e.jsx(Xe,{className:"h-4 w-4 text-red-600"})})})]},C.id)),h.length===0&&e.jsx(Ie,{children:e.jsx(L,{colSpan:5,className:"text-center text-muted-foreground py-8",children:r?"No generated dependencies for this tier. Edit in All tiers, then regenerate products to refresh this view.":"No attribute dependencies defined"})})]})]}),e.jsx(ht,{open:l,onOpenChange:a,children:e.jsxs(xt,{children:[e.jsx(pt,{children:e.jsx(vt,{children:"Add Dependency"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Attribute (dependent)"}),e.jsxs(fe,{value:d.attributeSlug,onValueChange:C=>o(v=>({...v,attributeSlug:C})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select attribute"})}),e.jsx(Se,{children:c.filter(C=>C.isActive).map(C=>e.jsx(se,{value:C.slug,children:C.name},C.slug))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Depends on attribute"}),e.jsxs(fe,{value:d.dependsOnAttribute,onValueChange:C=>o(v=>({...v,dependsOnAttribute:C,dependsOnValue:""})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select attribute"})}),e.jsx(Se,{children:c.filter(C=>C.isActive&&C.slug!==d.attributeSlug).map(C=>e.jsx(se,{value:C.slug,children:C.name},C.slug))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Depends on value"}),e.jsxs(fe,{value:d.dependsOnValue,onValueChange:C=>o(v=>({...v,dependsOnValue:C})),children:[e.jsx(be,{children:e.jsx(ye,{placeholder:"Select value"})}),e.jsx(Se,{children:S.map(C=>e.jsx(se,{value:C.value,children:C.label},C.value))})]})]}),d.attributeSlug&&d.dependsOnAttribute&&d.dependsOnValue&&e.jsxs("div",{className:"text-sm bg-muted p-2 rounded",children:["Show ",e.jsx("strong",{children:p(d.attributeSlug)})," only when ",e.jsx("strong",{children:p(d.dependsOnAttribute)})," = ",e.jsx("strong",{children:d.dependsOnValue})]})]}),e.jsxs(jt,{children:[e.jsx(A,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(A,{disabled:!d.attributeSlug||!d.dependsOnAttribute||!d.dependsOnValue,onClick:()=>y.mutate(d),children:y.isPending?e.jsx(Ne,{className:"h-4 w-4 animate-spin"}):"Create"})]})]})})]})}const _r=` 114 query { 115 configV2Tiers { slug name description catalogMode isActive isPublicConfigurator journeyAuthoringAllowed }
116 configV2Garments { slug name parentSlug childQuestionText imageUrl displayOrder isActive hasActiveChildren } 117 configV2Services { slug name description imageUrl serviceGroup disclaimerText disclaimerRequiresAck } 118 configV2GarmentServices { id garmentSlug serviceSlug serviceName isActive hasAudienceMembership audienceTierSlugs } 119 configV2Attributes { 120 slug name type summaryLabel questionText helpText imageUrl isActive 121 values { id attributeSlug value label description imageUrl skuCode displayOrder isActive hiddenForGarments disclaimerText disclaimerRequiresAck } 122 } 123 configV2Dependencies { id attributeSlug dependsOnAttributeSlug dependsOnValue } 124 } 125`,Ur=` 126 query($tierSlug: String!, $garmentServiceId: Int!) { 127 configV2JourneyDraftStatus(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId) { 128 garmentServiceId status skipReason basePriceCents baseMinutes requiresQuote 129 publicationBlockers publicationWarnings currentPublishedVersion currentPublishedAt matchesCurrentPublication 130 } 131 } 132`,Lr=` 133 query { 134 configV2JourneyAudienceCreationPreflight { 135 fingerprint 136 existingAudiences { slug name isActive } 137 globalCells { garmentServiceId garmentSlug garmentName serviceSlug serviceName isActive } 138 } 139 } 140`,Qr=` 141 query($tierSlug: String!) { 142 configV2Dependencies(tierSlug: $tierSlug) { 143 id attributeSlug dependsOnAttributeSlug dependsOnValue 144 } 145 } 146`,zr=` 147 query($tierSlug: String!, $garmentServiceId: Int!, $selections: [ConfigV2JourneyPreviewSelectionInput!]!) { 148 configV2JourneyCompiledDraftPreview(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, selections: $selections) { 149 status reason blockers 150 garmentLabel garmentImageUrl 151 serviceLabel serviceDescription serviceImageUrl serviceGroup serviceDisclaimerText serviceDisclaimerRequiresAck 152 questions { 153 attachmentType attachmentId label kind required helpText summaryLabel imageUrl 154 values { id label description imageUrl disclaimerText disclaimerRequiresAck } 155 } 156 resolution { status message priceCents minutes requiresQuote } 157 } 158 } 159`,Kr=` 160 query($tierSlug: String!, $oracle: String!, $search: String) { 161 configV2JourneyLegacyProducts(tierSlug: $tierSlug, oracle: $oracle, search: $search) { 162 oracle 163 products { sku garmentSlug serviceSlug name garmentName serviceName finalPriceCents standardMinutes requiresQuote } 164 warnings blockingIssues baseOnlyWarnings 165 } 166 } 167`,Br=` 168 query($tierSlug: String!) { 169 configV2TierPublicationPreflight(tierSlug: $tierSlug) { 170 tierSlug fingerprint publishCount unchangedCount retireCount 171 blocked { garmentServiceId garmentSlug serviceSlug reason version } 172 skipped { garmentServiceId garmentSlug serviceSlug reason version } 173 stale { garmentServiceId garmentSlug serviceSlug reason version } 174 retire { garmentServiceId garmentSlug serviceSlug reason version } 175 baseOnlyWarnings 176 } 177 } 178`,Jr=` 179 query($garmentSlug: String!, $serviceSlug: String!, $tierSlug: String!) { 180 configV2GarmentAttributes(garmentSlug: $garmentSlug, tierSlug: $tierSlug) { 181 id garmentSlug attributeSlug isRequired displayOrder tierScope isActive 182 } 183 allGarmentAttributes: configV2GarmentAttributes { 184 id garmentSlug attributeSlug isRequired displayOrder tierScope isActive 185 } 186 configV2ServiceAttributes(serviceSlug: $serviceSlug) { 187 id serviceSlug attributeSlug isRequired displayOrder tierScope isActive 188 } 189 allServiceAttributes: configV2ServiceAttributes { 190 id serviceSlug attributeSlug isRequired displayOrder tierScope isActive 191 } 192 } 193`,Wr=` 194 query($garmentServiceId: Int) { 195 configV2GarmentServiceScopesSnapshot(garmentServiceId: $garmentServiceId) { 196 id garmentServiceId attributeSlug attributeValueSlug 197 } 198 } 199`,Hr=` 200 query { 201 configV2AttachmentDependencySnapshot { 202 sets { id subjectServiceAttributeId subjectGarmentAttributeId contextTierSlug contextGarmentServiceId isActive createdAt } 203 groups { id dependencySetId parentServiceAttributeId parentGarmentAttributeId displayOrder } 204 values { dependencyGroupId attributeValueId } 205 } 206 } 207`,Yr=` 208 query($tierSlug: String!, $garmentServiceId: Int!) { 209 configV2TierCellOfferDraft(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId) { 210 baseCents baseMinutes requiresQuote isActive 211 attachments { attachmentType attachmentId attributeSlug kind isRequired isActive activeValueIds } 212 effects { id subjectType subjectAttachmentId effectKind attributeValueId priceDeltaCents minutesDelta requiresQuote isActive } 213 } 214 } 215`,Xr=` 216 mutation($tierSlug: String!, $garmentServiceId: Int!, $draft: ConfigV2TierCellOfferDraftInput!) { 217 configV2ReplaceTierCellOfferDraft(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, draft: $draft) { baseCents } 218 } 219`,Zr=` 220 mutation($tierSlug: String!, $garmentServiceId: Int!, $attributeSlug: String!, $value: String!, $label: String!, $description: String, $skuCode: String, $imageUrl: String, $disclaimerText: String, $disclaimerRequiresAck: Boolean) { 221 configV2CreateJourneyAttributeValue(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attributeSlug: $attributeSlug, value: $value, label: $label, description: $description, skuCode: $skuCode, imageUrl: $imageUrl, disclaimerText: $disclaimerText, disclaimerRequiresAck: $disclaimerRequiresAck) { id } 222 } 223`,ea=` 224 mutation($tierSlug: String!, $garmentServiceId: Int!, $attributeValueId: Int!, $label: String!, $skuCode: String, $description: String, $imageUrl: String, $disclaimerText: String, $disclaimerRequiresAck: Boolean) { 225 configV2UpdateJourneyAttributeValueContent(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attributeValueId: $attributeValueId, label: $label, skuCode: $skuCode, description: $description, imageUrl: $imageUrl, disclaimerText: $disclaimerText, disclaimerRequiresAck: $disclaimerRequiresAck) { id } 226 } 227`,ta=` 228 mutation($tierSlug: String!, $garmentServiceId: Int!, $attributeSlug: String!, $activeValueIds: [Int!]!) { 229 configV2ReorderJourneyAttributeValues(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attributeSlug: $attributeSlug, activeValueIds: $activeValueIds) { id displayOrder isActive } 230 } 231`,sa=` 232 query($tierSlug: String!, $garmentServiceId: Int!, $attributeValueId: Int!, $requestedIsActive: Boolean!) { 233 configV2JourneyAttributeValueLifecyclePreflight(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attributeValueId: $attributeValueId, requestedIsActive: $requestedIsActive) { 234 fingerprint attributeValueId attributeSlug valueLabel currentIsActive requestedIsActive affectedRepairPaths 235 blockers { code message action } 236 } 237 } 238`,ia=` 239 mutation($tierSlug: String!, $garmentServiceId: Int!, $attributeValueId: Int!, $requestedIsActive: Boolean!, $expectedFingerprint: String!) { 240 configV2SetJourneyAttributeValueLifecycle(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attributeValueId: $attributeValueId, requestedIsActive: $requestedIsActive, expectedFingerprint: $expectedFingerprint) { id isActive displayOrder } 241 } 242`,ra=` 243 mutation($tierSlug: String!, $garmentServiceId: Int!, $name: String!, $imageUrl: String) { 244 configV2UpdateJourneyGarmentPresentation(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, name: $name, imageUrl: $imageUrl) { slug } 245 } 246`,aa=` 247 mutation($tierSlug: String!, $garmentServiceId: Int!, $attributeSlug: String!, $questionText: String, $helpText: String, $summaryLabel:
247String, $imageUrl: String) { 248 configV2UpdateJourneyQuestionContent(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attributeSlug: $attributeSlug, questionText: $questionText, helpText: $helpText, summaryLabel: $summaryLabel, imageUrl: $imageUrl) { slug } 249 } 250`,na=` 251 mutation($tierSlug: String!, $garmentServiceId: Int!, $name: String!, $description: String, $imageUrl: String, $serviceGroup: String, $disclaimerText: String, $disclaimerRequiresAck: Boolean) { 252 configV2UpdateJourneyServicePresentation(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, name: $name, description: $description, imageUrl: $imageUrl, serviceGroup: $serviceGroup, disclaimerText: $disclaimerText, disclaimerRequiresAck: $disclaimerRequiresAck) { slug } 253 } 254`,la=` 255 mutation($tierSlug: String!, $expectedFingerprint: String!) { 256 configV2PublishTier(tierSlug: $tierSlug, expectedFingerprint: $expectedFingerprint) { 257 tierSlug fingerprint publishedCount unchangedCount retiredCount 258 blocked { garmentServiceId garmentSlug serviceSlug reason version } 259 skipped { garmentServiceId garmentSlug serviceSlug reason version } 260 stale { garmentServiceId garmentSlug serviceSlug reason version } 261 retired { garmentServiceId garmentSlug serviceSlug reason version } 262 baseOnlyWarnings 263 } 264 } 265`,ca=` 266 mutation($tierSlug: String!, $isPublicDefault: Boolean!, $expectedFingerprint: String) { 267 configV2SetJourneyPublicDefault(tierSlug: $tierSlug, isPublicDefault: $isPublicDefault, expectedFingerprint: $expectedFingerprint) { 268 tier { slug name description catalogMode isActive isPublicConfigurator journeyAuthoringAllowed } 269 previousPublicTierSlugs currentPublicTierSlugs currentPointerCount fingerprint 270 } 271 } 272`,da=` 273 mutation($authoringTierSlug: String!, $garmentServiceId: Int!, $tierSlugs: [String!]!) { 274 configV2SetGarmentServiceTierMembership(authoringTierSlug: $authoringTierSlug, garmentServiceId: $garmentServiceId, tierSlugs: $tierSlugs) 275 } 276`,oa=` 277 mutation($sourceGarmentServiceId: Int!, $sourceTierSlug: String!, $targetGarmentSlug: String!) { 278 configV2ForkGarmentServiceCell(sourceGarmentServiceId: $sourceGarmentServiceId, sourceTierSlug: $sourceTierSlug, targetGarmentSlug: $targetGarmentSlug) { id garmentSlug serviceSlug isActive } 279 } 280`,ua=` 281 mutation($tierSlug: String!, $garmentSlug: String!, $garmentName: String, $serviceSlug: String!, $serviceName: String!, $serviceCategory: String!) { 282 configV2CreateJourneyRepairPath(tierSlug: $tierSlug, garmentSlug: $garmentSlug, garmentName: $garmentName, serviceSlug: $serviceSlug, serviceName: $serviceName, serviceCategory: $serviceCategory) { id garmentSlug serviceSlug isActive } 283 } 284`,ma=` 285 mutation($tierSlug: String!, $categorySlug: String!, $categoryName: String!, $childQuestionText: String!, $childGarmentSlugs: [String!]!) { 286 configV2GroupJourneyGarmentsIntoCategory(tierSlug: $tierSlug, categorySlug: $categorySlug, categoryName: $categoryName, childQuestionText: $childQuestionText, childGarmentSlugs: $childGarmentSlugs) { 287 category { slug name parentSlug childQuestionText imageUrl displayOrder isActive hasActiveChildren } 288 children { slug name parentSlug childQuestionText imageUrl displayOrder isActive hasActiveChildren } 289 } 290 } 291`,ga=` 292 mutation($tierSlug: String!, $parentSlug: String!, $slug: String!, $name: String!) { 293 configV2CreateJourneySubtype(tierSlug: $tierSlug, parentSlug: $parentSlug, slug: $slug, name: $name) { 294 slug name parentSlug childQuestionText imageUrl displayOrder isActive hasActiveChildren 295 } 296 } 297`,ha=` 298 mutation($slug: String!, $name: String!, $description: String, $expectedFingerprint: String!) { 299 configV2CreateJourneyAudience(slug: $slug, name: $name, description: $description, expectedFingerprint: $expectedFingerprint) { 300 audience { slug name description catalogMode isActive journeyAuthoringAllowed } 301 materializedCellCount 302 } 303 } 304`,xa=` 305 mutation($tierSlug: String!, $garmentServiceId: Int!, $isActive: Boolean!) { 306 configV2SetJourneyGarmentServiceActive(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, isActive: $isActive) { id isActive } 307 } 308`,pa=` 309 mutation($tierSlug: String!, $serviceSlug: String!, $slug: String!, $name: String!, $questionText: String!, $inputType: String!, $isRequired: Boolean) { 310 configV2CreateJourneyDynamicServiceQuestion(tierSlug: $tierSlug, serviceSlug: $serviceSlug, slug: $slug, name: $name, questionText: $questionText, inputType: $inputType, isRequired: $isRequired) { id serviceSlug attributeSlug isRequired displayOrder tierScope isActive attributeName attributeType } 311 } 312`,va=` 313 mutation($tierSlug: String!, $serviceSlug: String!, $slug: String!, $name: String!, $questionText: String!, $values: [ConfigV2JourneyChoiceValueInput!]!, $isRequired: Boolean) { 314 configV2CreateJourneyChoiceQuestion(tierSlug: $tierSlug, serviceSlug: $serviceSlug, slug: $slug, name: $name, questionText: $questionText, values: $values, isRequired: $isRequired) { id } 315 } 316`,ja=` 317 mutation($tierSlug: String!, $serviceSlug: String!, $slug: String!, $name: String!, $questionText: String!, $values: [ConfigV2JourneyChoiceValueInput!]!, $parentServiceAttributeId: Int!, $parentValueIds: [Int!]!, $isRequired: Boolean) { 318 configV2CreateJourneyConditionalChoiceQuestion(tierSlug: $tierSlug, serviceSlug: $serviceSlug, slug: $slug, name: $name, questionText: $questionText, values: $values, parentServiceAttributeId: $parentServiceAttributeId, parentValueIds: $parentValueIds, isRequired: $isRequired) { id } 319 } 320`,fa=` 321 mutation($tierSlug: String!, $garmentSlug: String!, $slug: String!, $name: String!, $questionText: String!, $values: [ConfigV2JourneyChoiceValueInput!]!) { 322 configV2CreateJourneyDescriptorQuestion(tierSlug: $tierSlug, garmentSlug: $garmentSlug, slug: $slug, name: $name, questionText: $questionText, values: $values) { id } 323 } 324`,ba=` 325 mutation($tierSlug: String!, $garmentSlug: String!, $attributeSlug: String!) { 326 configV2AttachJourneyDescriptorQuestion(tierSlug: $tierSlug, garmentSlug: $garmentSlug, attributeSlug: $attributeSlug) { id } 327 } 328`,ya=` 329 mutation($tierSlug: String!, $garmentServiceId: Int!, $attachmentId: Int!, $isRequired: Boolean!) { 330 configV2SetJourneyServiceQuestionRequiredness(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attachmentId: $attachmentId, isRequired: $isRequired) { id isRequired t
330ierScope } 331 } 332`,Sa=` 333 mutation($tierSlug: String!, $garmentServiceId: Int!, $attachmentId: Int!) { 334 configV2RemoveJourneyServiceQuestionFromAudience(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attachmentId: $attachmentId) { id isRequired tierScope } 335 } 336`,Na=` 337 mutation($tierSlug: String!, $garmentServiceId: Int!, $attachmentId: Int!, $groups: [ConfigV2AttachmentDependencyGroupInput!]!) { 338 configV2SetJourneyServiceQuestionCondition(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attachmentId: $attachmentId, groups: $groups) { 339 sets { id subjectServiceAttributeId subjectGarmentAttributeId contextTierSlug contextGarmentServiceId isActive } 340 groups { id dependencySetId parentServiceAttributeId parentGarmentAttributeId displayOrder } 341 values { dependencyGroupId attributeValueId } 342 } 343 } 344`,Ca=` 345 mutation($tierSlug: String!, $garmentSlug: String!, $serviceSlug: String!, $attributeSlug: String!, $hiddenValueIds: [Int!]!) { 346 configV2SetJourneyGarmentValueDenylists(tierSlug: $tierSlug, garmentSlug: $garmentSlug, serviceSlug: $serviceSlug, attributeSlug: $attributeSlug, hiddenValueIds: $hiddenValueIds) { id hiddenForGarments } 347 } 348`,Aa=` 349 mutation($tierSlug: String!, $garmentServiceId: Int!, $attributeSlug: String!, $allowedValueSlugs: [String!]!) { 350 configV2SetJourneyDescriptorServiceScope(tierSlug: $tierSlug, garmentServiceId: $garmentServiceId, attributeSlug: $attributeSlug, allowedValueSlugs: $allowedValueSlugs) { id garmentServiceId attributeSlug attributeValueSlug } 351 } 352`,$a=` 353 mutation($serviceSlug: String!, $attributeSlug: String!, $tierSlug: String!, $isRequired: Boolean, $displayOrder: Int) { 354 configV2CreateServiceAttribute(serviceSlug: $serviceSlug, attributeSlug: $attributeSlug, tierSlug: $tierSlug, isRequired: $isRequired, displayOrder: $displayOrder) { id } 355 } 356`,wa=` 357 mutation($serviceSlug: String!, $attributeSlug: String!, $tierSlug: String!) { 358 configV2AdmitServiceAttributeToAudience(serviceSlug: $serviceSlug, attributeSlug: $attributeSlug, tierSlug: $tierSlug) { id serviceSlug attributeSlug tierScope isActive } 359 } 360`,ka=` 361 mutation($serviceSlug: String!, $childAttributeSlug: String!, $tierSlug: String!, $parentServiceAttributeId: Int!, $parentValueIds: [Int!]!, $isRequired: Boolean, $displayOrder: Int) { 362 configV2CreateConditionalServiceAttribute(serviceSlug: $serviceSlug, childAttributeSlug: $childAttributeSlug, tierSlug: $tierSlug, parentServiceAttributeId: $parentServiceAttributeId, parentValueIds: $parentValueIds, isRequired: $isRequired, displayOrder: $displayOrder) { id } 363 } 364`,qa=` 365 mutation($serviceSlug: String!, $attachmentIds: [Int!]!) { 366 configV2ReorderServiceAttributes(serviceSlug: $serviceSlug, attachmentIds: $attachmentIds) 367 } 368`,Ta=` 369 mutation($garmentSlug: String!, $attachmentIds: [Int!]!) { 370 configV2ReorderGarmentAttributes(garmentSlug: $garmentSlug, attachmentIds: $attachmentIds) 371 } 372`;function Me(t,s){return U(t,s)}const Je={catalog:["configV2JourneyCatalog"],attachmentDependencies:["configV2AttachmentDependencySnapshot","journey-canvas"],legacyDependencies:t=>["configV2Dependencies","journey-canvas",t],attachmentsRoot:["configV2JourneyAttachments"],attachments:(t,s,i)=>["configV2JourneyAttachments",t,s,i],descriptorScopesRoot:["configV2JourneyDescriptorServiceScopes"],descriptorScopes:t=>["configV2JourneyDescriptorServiceScopes",t],descriptorScopeSnapshot:t=>["configV2JourneyDescriptorServiceScopes","snapshot",t],draftStatusRoot:["configV2JourneyDraftStatus"],draftStatus:(t,s)=>["configV2JourneyDraftStatus",t,s],compiledPreview:(t,s,i)=>["configV2JourneyCompiledDraftPreview",t,s,i],compiledPreviewRoot:["configV2JourneyCompiledDraftPreview"],legacyProducts:(t,s,i)=>["configV2JourneyLegacyProducts",t,s,i],publicationPreflightRoot:["configV2TierPublicationPreflight"],publicationPreflight:t=>["configV2TierPublicationPreflight",t],offerDraftRoot:["configV2TierCellOfferDraft"],offerDraft:(t,s)=>["configV2TierCellOfferDraft",t,s]},Ia={catalog:Je.catalog,attachmentDependencies:Je.attachmentDependencies,attachments:Je.attachmentsRoot,descriptorScopes:Je.descriptorScopesRoot,publicationPreflight:Je.publicationPreflightRoot,draftStatus:Je.draftStatusRoot,offerDraft:Je.offerDraftRoot,compiledPreview:Je.compiledPreviewRoot};
372function Le(t,...s){for(const i of new Set(s))t.invalidateQueries({queryKey:Ia[i]})}function He({error:t,fallback:s="The change could not be saved.",testId:i="jc-form-error"}){if(!t)return null;const r=t instanceof Error&&t.message.trim()?t.message:s;return e.jsx("p",{className:"border-l-2 border-destructive pl-3 text-sm text-destructive",role:"alert","data-testid":i,children:r})}function bt(t){return t.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80)}function mi(t,s){const i=s.trim();return!!i&&t.some(r=>r.slug===i)}function Va(t){return t.attributes.flatMap(s=>{if(!s.isActive||t.conditional&&s.type!=="choice")return[];const i=t.attachments.allServiceAttributes.filter(l=>l.serviceSlug===t.serviceSlug&&l.attributeSlug===s.slug);if(t.conditional)return i.length===0?[{attribute:s,admission:!1}]:[];if(i.length===0)return[{attribute:s,admission:!1}];const r=i.find(l=>l.isActive);return!r||$t(r.tierScope,t.tierSlug)?[]:[{attribute:s,admission:!0}]}).sort((s,i)=>s.attribute.name.localeCompare(i.attribute.name))}function Ra({tierSlug:t,serviceSlug:s,attributes:i,attachments:r,followUp:l,onClose:a}){const{toast:d}=Pe(),[o,n]=x.useState("new"),[u,h]=x.useState("choice"),[c,y]=x.useState(""),[f,p]=x.useState(""),[S,T]=x.useState(!1),[C,v]=x.useState(""),[O,P]=x.useState(!1),[$,b]=x.useState(!0),[j,V]=x.useState(""),[R,D]=x.useState(3),[E,N]=x.useState([{id:1,label:"",key:""},{id:2,label:"",key:""}]),m=x.useMemo(()=>Va({attributes:i,attachments:r,serviceSlug:s,tierSlug:t,conditional:!!l}),[r,i,l,s,t]),G=le({mutationFn:async()=>{if(o==="reuse"){const Ce=m.find(Fe=>Fe.attribute.slug===j);if(!Ce)throw new Error("Choose a reusable question.");return l?Me(ka,{serviceSlug:s,childAttributeSlug:Ce.attribute.slug,tierSlug:t,parentServiceAttributeId:l.parentServiceAttributeId,parentValueIds:[l.parentValueId],isRequired:$}):Me(Ce.admission?wa:$a,{serviceSlug:s,attributeSlug:Ce.attribute.slug,tierSlug:t,isRequired:$})}const ge=c.trim(),qe=f.trim(),Te=C.trim();if(!ge||!qe||!Te)throw new Error("Question name, key, and wording are required.");if(l||u==="choice"){const Ce=E.map(ke=>({value:ke.key.trim(),label:ke.label.trim()})).filter(ke=>ke.value||ke.label);if(Ce.length===0||Ce.some(ke=>!ke.value||!ke.label))throw new Error("Every choice needs a label and key.");const Fe={tierSlug:t,serviceSlug:s,slug:qe,name:ge,questionText:Te,values:Ce,isRequired:$};return Me(l?ja:va,l?{...Fe,parentServiceAttributeId:l.parentServiceAttributeId,parentValueIds:[l.parentValueId]}:Fe)}return Me(pa,{tierSlug:t,serviceSlug:s,slug:qe,name:ge,questionText:Te,inputType:u,isRequired:$})},onSuccess:()=>{Le(Z,"catalog","attachments","attachmentDependencies","draftStatus","offerDraft","compiledPreview"),d({title:l?"Follow-up added":"Question added"}),a()},onError:ge=>d({title:"Could not add question",description:ge.message,variant:"destructive"})}),X=ge=>{y(ge),S||p(bt(ge)),O||v(ge?`${ge}?`:"")},ce=(ge,qe)=>{N(Te=>Te.map(Ce=>Ce.id===ge?{...Ce,label:qe,key:Ce.key===bt(Ce.label)||!Ce.key?bt(qe):Ce.key}:Ce))},de=f.trim(),De=o==="new"&&mi(i,de);return e.jsxs("section",{className:"border-y border-border bg-background px-4 py-4","data-testid":"jc-add-question-picker",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l&&e.jsx(qt,{className:"h-4 w-4"}),e.jsx("h3",{className:"text-sm font-semibold",children:l?"Add follow-up question":"Add question"})]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:l?`Shown after ${l.questionLabel}: ${l.valueLabel}.`:"Create a question for this repair, or reuse a shared definition."}),l&&e.jsx("p",{className:"mt-2 border-l-2 border-amber-500 pl-3 text-xs text-amber-800","data-testid":"jc-conditional-shadow-note",children:"This follow-up is available in the compiled draft. The current order configurator will not apply newly authored conditions until canonical dependency adoption."})]}),e.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:a,title:"Close","aria-label":"Close question picker",children:e.jsx(rt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-4 flex min-h-10 items-center rounded-md border border-border p-1","aria-label":"Question source",children:[e.jsx(A,{type:"button",size:"sm",className:"flex-1",variant:o==="new"?"secondary":"ghost",onClick:()=>n("new"),children:"Create new"}),e.jsx(A,{type:"button",size:"sm",className:"flex-1",variant:o==="reuse"?"secondary":"ghost",onClick:()=>n("reuse"),children:"Reuse existing"})]}),o==="reuse"?e.jsx("div",{className:"mt-4 space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-reuse-question",children:"Question"}),e.jsxs(fe,{value:j,onValueChange:V,children:[e.jsx(be,{id:"jc-reuse-question",children:e.jsx(ye,{placeholder:"Choose a shared question"})}),e.jsx(Se,{children:m.map(({attribute:ge,admission:qe})=>e.jsxs(se,{value:ge.slug,children:[ge.name,qe?" â add to this audie
372nce":""]},ge.slug))})]}),m.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No eligible shared questions are available."})]})}):e.jsxs("div",{className:"mt-4 space-y-4",children:[!l&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-new-question-kind",children:"Question type"}),e.jsxs(fe,{value:u,onValueChange:ge=>h(ge),children:[e.jsx(be,{id:"jc-new-question-kind",children:e.jsx(ye,{})}),e.jsxs(Se,{children:[e.jsx(se,{value:"choice",children:"Pick one"}),e.jsx(se,{value:"quantity",children:"Quantity"}),e.jsx(se,{value:"text",children:"Text"})]})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-question-name",children:"Name"}),e.jsx(ee,{id:"jc-question-name",value:c,onChange:ge=>X(ge.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-question-key",children:"Key"}),e.jsx(ee,{id:"jc-question-key",value:f,onChange:ge=>{T(!0),p(ge.target.value)}}),De&&e.jsx("p",{className:"text-sm text-destructive",role:"alert","data-testid":"jc-question-key-error",children:"That question key is already in use."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-question-wording",children:"Customer wording"}),e.jsx(ee,{id:"jc-question-wording",value:C,onChange:ge=>{P(!0),v(ge.target.value)}})]}),(l||u==="choice")&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ue,{children:"Choices"}),e.jsxs(A,{type:"button",variant:"outline",size:"sm",onClick:()=>{N(ge=>[...ge,{id:R,label:"",key:""}]),D(ge=>ge+1)},children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"Add choice"]})]}),E.map(ge=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_36px] gap-2",children:[e.jsx(ee,{"aria-label":"Choice label",placeholder:"Label",value:ge.label,onChange:qe=>ce(ge.id,qe.target.value)}),e.jsx(ee,{"aria-label":"Choice key",placeholder:"key",value:ge.key,onChange:qe=>N(Te=>Te.map(Ce=>Ce.id===ge.id?{...Ce,key:qe.target.value}:Ce))}),e.jsx(A,{type:"button",variant:"ghost",size:"icon",onClick:()=>N(qe=>qe.filter(Te=>Te.id!==ge.id)),title:"Remove choice","aria-label":"Remove choice",children:e.jsx(Xe,{className:"h-4 w-4"})})]},ge.id))]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(He,{error:G.error,testId:"jc-question-form-error"})}),e.jsxs("div",{className:"mt-4 flex items-center justify-between border-t border-border pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{id:"jc-question-required",checked:$,onCheckedChange:b}),e.jsx(Ue,{htmlFor:"jc-question-required",children:"Required when shown"})]}),e.jsxs(A,{type:"button",onClick:()=>G.mutate(),disabled:G.isPending||De||o==="reuse"&&!j,"data-testid":"jc-save-question",children:[G.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),l?"Add follow-up":"Add question"]})]})]})}function Ea(t){const s=new Set(t.attachments.configV2GarmentAttributes.map(r=>r.attributeSlug)),i=t.attachments.allGarmentAttributes.filter(r=>r.garmentSlug===t.garmentSlug);return t.attributes.flatMap(r=>{if(r.type!=="descriptor"||!r.isActive||!r.values.some(a=>a.isActive&&!mt(a,t.garmentSlug)))return[];if(s.has(r.slug))return[];const l=i.find(a=>a.attributeSlug===r.slug);return l?!l.isActive||$t(l.tierScope,t.tierSlug)?[]:[{attribute:r,admission:!0}]:[{attribute:r,admission:!1}]}).sort((r,l)=>r.attribute.name.localeCompare(l.attribute.name))}function Oa({tierSlug:t,garmentSlug:s,attributes:i,attachments:r,onClose:l}){const{toast:a}=Pe(),[d,o]=x.useState("new"),[n,u]=x.useState(""),[h,c]=x.useState(""),[y,f]=x.useState(!1),[p,S]=x.useState(""),[T,C]=x.useState(!1),[v,O]=x.useState(""),[P,$]=x.useState(3),[b,j]=x.useState([{id:1,label:"",key:""},{id:2,label:"",key:""}]),V=x.useMemo(()=>Ea({attributes:i,attachments:r,garmentSlug:s,tierSlug:t}),[r,i,s,t]),R=le({mutationFn:async()=>{if(d==="reuse"){if(!V.some(({attribute:de})=>de.slug===v))throw new Error("Choose a reusable pre-repair question.");return Me(ba,{tierSlug:t,garmentSlug:s,attributeSlug:v})}const m=n.trim(),G=h.trim(),X=p.trim(),ce=b.map(de=>({value:de.key.trim(),label:de.label.trim()})).filter(de=>de.value||de.label);if(!m||!G||!X)throw new Error("Question name, key, and wording are required.");
372if(ce.length===0||ce.some(de=>!de.value||!de.label))throw new Error("Every answer needs a label and key.");return Me(fa,{tierSlug:t,garmentSlug:s,slug:G,name:m,questionText:X,values:ce})},onSuccess:()=>{Le(Z,"catalog","attachments","descriptorScopes","draftStatus","offerDraft","compiledPreview"),a({title:d==="reuse"?"Pre-repair question reused":"Pre-repair question added"}),l()},onError:m=>a({title:"Could not add pre-repair question",description:m.message,variant:"destructive"})}),D=m=>{u(m),y||c(bt(m)),T||S(m?`${m}?`:"")},E=(m,G)=>{j(X=>X.map(ce=>ce.id===m?{...ce,label:G,key:ce.key===bt(ce.label)||!ce.key?bt(G):ce.key}:ce))},N=d==="new"&&mi(i,h);return e.jsxs("section",{className:"border-y border-border bg-background px-4 py-4","data-testid":"jc-add-descriptor-picker",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Add pre-repair question"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Ask a required garment question before the repair menu, then choose which answers offer each repair."})]}),e.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:l,title:"Close","aria-label":"Close pre-repair question picker",children:e.jsx(rt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-4 flex min-h-10 items-center rounded-md border border-border p-1","aria-label":"Pre-repair question source",children:[e.jsx(A,{type:"button",size:"sm",className:"flex-1",variant:d==="new"?"secondary":"ghost",onClick:()=>o("new"),children:"Create new"}),e.jsx(A,{type:"button",size:"sm",className:"flex-1",variant:d==="reuse"?"secondary":"ghost",onClick:()=>o("reuse"),children:"Reuse existing"})]}),d==="reuse"?e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-reuse-descriptor",children:"Pre-repair question"}),e.jsxs(fe,{value:v,onValueChange:O,children:[e.jsx(be,{id:"jc-reuse-descriptor",children:e.jsx(ye,{placeholder:"Choose a shared pre-repair question"})}),e.jsx(Se,{children:V.map(({attribute:m,admission:G})=>e.jsxs(se,{value:m.slug,children:[m.name,G?" â add to this audience":""]},m.slug))})]}),V.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No unattached pre-repair questions are available."})]}):e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-descriptor-name",children:"Name"}),e.jsx(ee,{id:"jc-descriptor-name",value:n,onChange:m=>D(m.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-descriptor-key",children:"Key"}),e.jsx(ee,{id:"jc-descriptor-key",value:h,onChange:m=>{f(!0),c(m.target.value)}}),N&&e.jsx("p",{className:"text-sm text-destructive",role:"alert","data-testid":"jc-descriptor-key-error",children:"That question key is already in use."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-descriptor-wording",children:"Customer wording"}),e.jsx(ee,{id:"jc-descriptor-wording",value:p,onChange:m=>{C(!0),S(m.target.value)}})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ue,{children:"Answers"}),e.jsxs(A,{type:"button",variant:"outline",size:"sm",onClick:()=>{j(m=>[...m,{id:P,label:"",key:""}]),$(m=>m+1)},children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"Add answer"]})]}),b.map(m=>e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_36px] gap-2",children:[e.jsx(ee,{"aria-label":"Answer label",placeholder:"Label",value:m.label,onChange:G=>E(m.id,G.target.value)}),e.jsx(ee,{"aria-label":"Answer key",placeholder:"key",value:m.key,onChange:G=>j(X=>X.map(ce=>ce.id===m.id?{...ce,key:G.target.value}:ce))}),e.jsx(A,{type:"button",variant:"ghost",size:"icon",onClick:()=>j(G=>G.filter(X=>X.id!==m.id)),title:"Remove answer","aria-label":"Remove answer",children:e.jsx(Xe,{className:"h-4 w-4"})})]},m.id))]})]}),e.jsx("div",{className:"mt-4",children:e.jsx(He,{error:R.error,testId:"jc-descriptor-form-error"})}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-3 border-t border-border pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Required in the selected audience"}),e.jsxs(A,{type:"button",onClick:()=>R.mutate(),disabled:R.isPending||N||d==="reuse"&&!v,"data-testid":"jc-save-descriptor",children:[R.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),"Add pre-repair question"]})]})]})}function Pa(t){const s=t.garmentSlug.trim(),i=t.serviceSlug.trim();return{garment:t.creatingGarment&&!!s&&t.existingGarmentSlugs.includes(s),service:!!i&&t.existingServiceSlugs.includes(i)}}function fs({tierSlug:t,garment:s,catalog:i,onCreated:r,onClose:l}){const{toast:a}=Pe(),[d,o]=x.useState(""),[n,u]=x.useState((s==null?void 0:s.slug)??""),[h,c]=x.useState(!!s),[y,f]=x.use
372State(""),[p,S]=x.useState(""),[T,C]=x.useState(!1),[v,O]=x.useState("repair"),P=le({mutationFn:async()=>(await Me(ua,{tierSlug:t,garmentSlug:(s==null?void 0:s.slug)??n.trim(),garmentName:s?null:d.trim(),serviceSlug:p.trim(),serviceName:y.trim(),serviceCategory:v})).configV2CreateJourneyRepairPath,onSuccess:E=>{Le(Z,"catalog","attachments","draftStatus","compiledPreview"),a({title:s?"Draft repair added":"Draft garment and repair added"}),r(E)},onError:E=>a({title:"Could not add repair path",description:E.message,variant:"destructive"})}),$=(s==null?void 0:s.slug)??n.trim(),b=p.trim(),j=Pa({garmentSlug:$,serviceSlug:b,creatingGarment:!s,existingGarmentSlugs:i.configV2Garments.map(E=>E.slug),existingServiceSlugs:i.configV2Services.map(E=>E.slug)}),V=j.garment,R=j.service,D=!!((s||d.trim()&&n.trim())&&y.trim()&&p.trim())&&!V&&!R;return e.jsxs("section",{className:"border-y border-border bg-background p-4","data-testid":s?"jc-add-repair-form":"jc-add-garment-form",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:s?`Add repair to ${s.name}`:"Add garment and first repair"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"The new repair path starts inactive and outside every audience."})]}),e.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:l,title:"Close","aria-label":"Close repair form",children:e.jsx(rt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-4 space-y-4",children:[!s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-new-garment-name",children:"Garment name"}),e.jsx(ee,{id:"jc-new-garment-name",value:d,onChange:E=>{o(E.target.value),h||u(bt(E.target.value))}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-new-garment-key",children:"Garment key"}),e.jsx(ee,{id:"jc-new-garment-key",value:n,onChange:E=>{c(!0),u(E.target.value)}}),V&&e.jsx("p",{className:"text-sm text-destructive",role:"alert","data-testid":"jc-garment-key-error",children:"That garment key is already in use."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-new-repair-name",children:"Repair name"}),e.jsx(ee,{id:"jc-new-repair-name",value:y,onChange:E=>{f(E.target.value),T||S(bt(E.target.value))}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-new-repair-key",children:"Repair key"}),e.jsx(ee,{id:"jc-new-repair-key",value:p,onChange:E=>{C(!0),S(E.target.value)}}),R&&e.jsx("p",{className:"text-sm text-destructive",role:"alert","data-testid":"jc-repair-key-error",children:"That repair key is already in use."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-new-repair-category",children:"Category"}),e.jsxs(fe,{value:v,onValueChange:E=>O(E),children:[e.jsx(be,{id:"jc-new-repair-category",children:e.jsx(ye,{})}),e.jsx(Se,{children:qs.map(E=>e.jsx(se,{value:E,children:ui[E]},E))})]})]}),e.jsxs(A,{type:"button",className:"w-full",disabled:!D||P.isPending,onClick:()=>P.mutate(),"data-testid":"jc-save-repair-path",children:[P.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),"Create inactive draft"]}),e.jsx(He,{error:P.error,testId:"jc-repair-path-error"})]})]})}function Qs(t){return t.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,50)}function Da(t,s){const i=s.trim();return!!i&&t.some(r=>r.slug===i)}function Ma(t){return/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(t.trim())}function zs({tiers:t,onCreated:s,onClose:i}){var v,O;const{toast:r}=Pe(),[l,a]=x.useState(""),[d,o]=x.useState(""),[n,u]=x.useState(!1),[h,c]=x.useState(""),y=Da(t,d),f=!!d&&!Ma(d),p=ne({queryKey:["configV2JourneyAudienceCreationPreflight"],queryFn:async()=>(await Me(Lr)).configV2JourneyAudienceCreationPreflight}),S=le({mutationFn:async()=>{var $;if(!(($=p.data)!=null&&$.fingerprint))throw new Error("Review the audience preparation before creating this audience.");return(await Me(ha,{slug:d.trim(),name:l.trim(),description:h.trim()||null,expectedFingerprint:p.data.fingerprint})).configV2CreateJourneyAudience},onSuccess:({audience:P,materializedCellCount:$})=>{Le(Z,"catalog"),r({title:`${P.name}
372 audience created`,description:$>0?`${$} every-audience repair assignment${$===1?" was":"s were"} preserved explicitly.`:void 0}),s(P)},onError:P=>{p.refetch(),r({title:"Could not create audience",description:P.message,variant:"destructive"})}}),T=!!(l.trim()&&d.trim()&&((v=p.data)!=null&&v.fingerprint))&&!y&&!f&&!p.isFetching,C=((O=p.data)==null?void 0:O.globalCells)??[];return e.jsx("section",{className:"border-b border-border bg-background p-4","data-testid":"jc-add-audience-form",children:e.jsxs("div",{className:"mx-auto max-w-xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:"New authoring audience"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Starts active, native, and private. Public and partner access are separate launch decisions."})]}),e.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:i,title:"Close","aria-label":"Close audience form",children:e.jsx(rt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-new-audience-name",children:"Audience name"}),e.jsx(ee,{id:"jc-new-audience-name",value:l,onChange:P=>{a(P.target.value),n||o(Qs(P.target.value))},"data-testid":"jc-audience-name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-new-audience-key",children:"Audience key"}),e.jsx(ee,{id:"jc-new-audience-key",value:d,maxLength:50,"aria-invalid":y||f,"aria-describedby":"jc-new-audience-key-hint",onChange:P=>{u(!0);const $=P.target.value,b=/[^a-z0-9]$/i.test($)?"-":"";o(`${Qs($)}${b}`.slice(0,50))},"data-testid":"jc-audience-key"}),e.jsx("p",{id:"jc-new-audience-key-hint",className:"text-xs text-muted-foreground",children:"Filled in from the name. Lowercase letters and numbers, separated by single hyphens."}),y&&e.jsx("p",{className:"text-sm text-destructive",role:"alert","data-testid":"jc-audience-key-error",children:"That audience key is already in use."}),f&&e.jsx("p",{className:"text-sm text-destructive",role:"alert","data-testid":"jc-audience-key-format-error",children:"Use lowercase letters and numbers separated by single hyphens."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-new-audience-description",children:"Description"}),e.jsx(Mt,{id:"jc-new-audience-description",value:h,onChange:P=>c(P.target.value),"data-testid":"jc-audience-description"})]}),p.isLoading&&e.jsxs("div",{className:"flex items-center gap-2 border border-border p-3 text-sm text-muted-foreground","data-testid":"jc-audience-preflight-loading",children:[e.jsx(Ne,{className:"h-4 w-4 animate-spin"}),"Checking existing audience assignments..."]}),p.data&&C.length===0&&e.jsxs("div",{className:"flex items-start gap-2 border border-emerald-200 bg-emerald-50 p-3 text-sm text-emerald-900","data-testid":"jc-audience-preflight-clear",children:[e.jsx(Ki,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Every repair already has an explicit audience assignment. The new audience will start with no offered repairs."})]}),p.data&&C.length>0&&e.jsxs("div",{className:"space-y-3 border border-amber-300 bg-amber-50 p-3 text-amber-950","data-testid":"jc-audience-preflight-blocker",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(St,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Before this audience can be created"}),e.jsxs("p",{className:"mt-1 text-sm",children:[C.length," repair",C.length===1?" is":"s are"," set to ",e.jsx("strong",{children:"Every audience"}),". That setting would automatically offer ",C.length===1?"it":"them"," in this new audience."]})]})]}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Journey will preserve the current assignments:"}),e.jsxs("ul",{className:"mt-1 list-disc space-y-1 pl-5",children:[e.jsx("li",{children:"Keep these repairs in every existing native audience shown below."}),e.jsx("li",{children:"Exclude them from the new audience until they are intentionally admitted and priced."}),e.jsx("li",{children:"Leave pricing, content, activation, and published revisions unchanged."})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-1","aria-label":"Existing audiences preserved",children:[p.data.existingAudiences.map(P=>e.jsxs(me,{variant:"secondary",children:[P.name,P.isActive?"":" (inactive)"]},P.slug)),p.data.existingAudiences.length===0&&e.jsx("span",{className:"text-sm",children:"No existing native audiences"})]}),e.jsx("div",{className:"max-h-48 overflow-y-auto border border-amber-200 bg-background","data-testid":"jc-audience-global-repairs",children:C.map(P=>e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border px-3 py-2 text-sm last:border-b-0",children:[e.jsxs("span",{children:[e.jsx("strong",{children:P.garmentName})," / ",P.serviceName]}),e.jsx(me,{variant:P.isActive?"default":"secondary",children:P.isActive?"Active":"Inactive"})]},P.garmentServiceId))})]}),e.jsx(He,{error:p.error,fallback:"Journey could not check existing audience assignments.",testId:"jc-audience-preflight-error"}),!T&&!S.isPending&&e.jsx("p",{className:"text-xs text-muted-foreground",role:"status","data-testid":"jc-audience-save-blocked-reason",children:l.trim()?d.trim()?f?"Fix the audience key to continue: lowercase letters and numbers, separated by single hyphens.":y?"Choose a different audience key to continue: this one is already in use.":"Checking existing audience assignments...":"Enter an audie
372nce key to continue.":"Enter an audience name to continue."}),e.jsxs(A,{type:"button",className:"w-full",disabled:!T||S.isPending,onClick:()=>S.mutate(),"data-testid":"jc-save-audience",children:[S.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),C.length>0?"Preserve current assignments and create audience":"Create audience"]}),e.jsx(He,{error:S.error,testId:"jc-audience-error"})]})]})})}function Fa({garments:t,cells:s,selectedGarmentSlug:i,search:r,onSearchChange:l,onSelectGarment:a,onAddGarment:d,onGroupGarments:o,onAddSubtype:n,addGarmentForm:u}){const h=r.trim().toLocaleLowerCase(),c=new Map;for(const T of t){const C=T.parentSlug??null;c.set(C,[...c.get(C)??[],T])}for(const T of c.values())T.sort((C,v)=>C.displayOrder-v.displayOrder||C.name.localeCompare(v.name));const y=[],f=new Set,p=(T,C)=>{for(const v of c.get(T)??[])f.has(v.slug)||(f.add(v.slug),y.push({garment:v,depth:C}),p(v.slug,C+1))};p(null,0);for(const T of t)f.has(T.slug)||y.push({garment:T,depth:0});const S=y.filter(({garment:T})=>!h||T.name.toLocaleLowerCase().includes(h));return e.jsxs("aside",{className:"hidden min-h-0 border-r border-border bg-muted/20 xl:flex xl:flex-col","data-testid":"jc-catalog-rail",children:[e.jsxs("div",{className:"border-b border-border p-3",children:[e.jsxs("label",{className:"relative block",children:[e.jsx(ds,{className:"pointer-events-none absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ee,{value:r,onChange:T=>l(T.target.value),className:"pl-8",placeholder:"Find garment","aria-label":"Find garment"})]}),d&&!u&&e.jsxs(A,{type:"button",variant:"outline",className:"mt-2 w-full border-dashed",onClick:d,"data-testid":"jc-add-garment",children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"New garment"]}),o&&!u&&e.jsxs(A,{type:"button",variant:"outline",className:"mt-2 w-full",onClick:o,"data-testid":"jc-group-garments",children:[e.jsx(Yt,{className:"mr-1 h-4 w-4"}),"Group garments"]})]}),u,e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:[S.map(({garment:T,depth:C})=>{const v=s.filter(b=>b.garmentSlug===T.slug),O=v.filter(b=>!b.isActive).length,P=T.hasActiveChildren||v.length===0,$=T.slug===i;return e.jsxs("div",{className:`mb-1 flex items-stretch rounded-md border transition-colors ${$?"border-foreground bg-background":"border-transparent hover:bg-background"}`,style:{marginLeft:`${Math.min(C,3)*12}px`},children:[e.jsxs("button",{type:"button",onClick:()=>a(T.slug),className:"flex min-w-0 flex-1 items-start gap-2 px-3 py-2 text-left","data-testid":`jc-garment-${T.slug}`,children:[T.hasActiveChildren?e.jsx(Yt,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}):e.jsx(os,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:T.name}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:T.hasActiveChildren?"Category":`${v.length} repair${v.length===1?"":"s"}${O?` · ${O} draft`:""}`})]})]}),P&&n&&e.jsx(A,{type:"button",variant:"ghost",size:"icon",className:"my-1 mr-1 h-8 w-8 shrink-0",title:`Add subtype to ${T.name}`,"aria-label":`Add subtype to ${T.name}`,onClick:()=>n(T),"data-testid":`jc-add-subtype-${T.slug}`,children:e.jsx(Wt,{className:"h-4 w-4"})})]},T.slug)}),S.length===0&&e.jsx("p",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:"No garments found."})]})]})}function Ga(){return ne({queryKey:Je.catalog,queryFn:()=>Me(_r)})}const _a={sets:[],groups:[],values:[]};function Ua(t){return ne({queryKey:Je.attachmentDependencies,enabled:t.enabled,queryFn:async()=>(await Me(Hr)).configV2AttachmentDependencySnapshot??_a})}function La(t){return ne({queryKey:Je.legacyDependencies(t.tierSlug),enabled:t.enabled,queryFn:async()=>(await Me(Qr,{tierSlug:t.tierSlug})).configV2Dependencies})}function Qa(t){return ne({queryKey:Je.attachments(t.tierSlug,t.garmentSlug,t.serviceSlug),enabled:t.enabled,queryFn:()=>Me(Jr,{tierSlug:t.tierSlug,garmentSlug:t.garmentSlug,serviceSlug:t.serviceSlug})})}function za(t){return ne({queryKey:Je.descriptorScopeSnapshot(t.garmentServiceId),enabled:t.enabled,queryFn:async()=>(await Me(Wr,{garmentServiceId:t.garmentServiceId}
372)).configV2GarmentServiceScopesSnapshot})}function Ka(t){return ne({queryKey:Je.draftStatus(t.tierSlug,t.garmentServiceId),enabled:t.enabled,queryFn:async()=>(await Me(Ur,{tierSlug:t.tierSlug,garmentServiceId:t.garmentServiceId})).configV2JourneyDraftStatus??null})}function Ba(t){return ne({queryKey:Je.compiledPreview(t.tierSlug,t.garmentServiceId,t.selections),enabled:t.enabled,placeholderData:s=>s,queryFn:async()=>(await Me(zr,{tierSlug:t.tierSlug,garmentServiceId:t.garmentServiceId,selections:t.selections})).configV2JourneyCompiledDraftPreview})}function Ks(t){return ne({queryKey:Je.legacyProducts(t.tierSlug,t.oracle,t.search),enabled:t.enabled,queryFn:async()=>(await Me(Kr,{tierSlug:t.tierSlug,oracle:t.oracle,search:t.search})).configV2JourneyLegacyProducts})}function Ja(t){return ne({queryKey:Je.publicationPreflight(t.tierSlug),enabled:t.enabled,queryFn:async()=>(await Me(Br,{tierSlug:t.tierSlug})).configV2TierPublicationPreflight})}function Wa(t){return ne({queryKey:Je.offerDraft(t.tierSlug,t.garmentServiceId),enabled:t.enabled,queryFn:async()=>(await Me(Yr,{tierSlug:t.tierSlug,garmentServiceId:t.garmentServiceId})).configV2TierCellOfferDraft})}function Ha(t){return t.garmentSlug.startsWith("v1g-")||t.serviceSlug.startsWith("v1s-")}function Ya(t){return t.slug.startsWith("v1g-")}function cs(t){return`$${(t/100).toFixed(2)}`}function is(t){return(t/100).toFixed(2)}function rs(t,s){const i=Number(t.trim()),r=Math.round(i*100);if(!Number.isFinite(i)||!Number.isSafeInteger(r)||Math.abs(i*100-r)>1e-6)throw new Error(`${s} must be a whole number of cents.`);return r}function as(t,s){const i=Number(t.trim());if(!Number.isSafeInteger(i))throw new Error(`${s} must be a whole number.`);return i}function at(t){var s;return((s=t.questionText)==null?void 0:s.trim())||t.name}function Vs(t){return t.type==="quantity"?"Quantity":t.type==="text"||t.type==="text_input"?"Text":"Choice"}function Bs(t){return`${t.subjectType}:${t.subjectAttachmentId}:${t.effectKind}:${t.attributeValueId??"none"}`}function Xa(t,s,i){const r=new Set,l=[],a=(d,o,n,u)=>{const h=t.effects.find(c=>!r.has(c.id)&&c.subjectType===d&&c.subjectAttachmentId===o&&c.effectKind===n&&c.attributeValueId===u);return h&&r.add(h.id),h};for(const d of s){const o=t.attachments.find(n=>n.attachmentType===d.attachmentType&&n.attachmentId===d.attachmentId);if(o){if(o.kind==="value")for(const n of d.attribute.values.filter(u=>u.isActive&&!mt(u,i))){const u=a(d.attachmentType,d.attachmentId,"selected_value",n.id);l.push({key:Bs({subjectType:d.attachmentType,subjectAttachmentId:d.attachmentId,effectKind:"selected_value",attributeValueId:n.id}),subjectType:d.attachmentType,subjectAttachmentId:d.attachmentId,effectKind:"selected_value",attributeValueId:n.id,priceDollars:is((u==null?void 0:u.priceDeltaCents)??0),minutes:String((u==null?void 0:u.minutesDelta)??0),requiresQuote:(u==null?void 0:u.requiresQuote)??!1,isActive:(u==null?void 0:u.isActive)??!0,label:`${at(d.attribute)}: ${n.label}`,retained:!1})}else if(o.kind==="quantity"){const n=a(d.attachmentType,d.attachmentId,"multiply_selected",null),u=a(d.attachmentType,d.attachmentId,"additional_unit",null),h=n?"multiply_selected":"additional_unit";l.push({key:Bs({subjectType:d.attachmentType,subjectAttachmentId:d.attachmentId,effectKind:h,attributeValueId:null}),subjectType:d.attachmentType,subjectAttachmentId:d.attachmentId,effectKind:h,attributeValueId:null,priceDollars:is(h==="additional_unit"?(u==null?void 0:u.priceDeltaCents)??0:0),minutes:String(h==="additional_unit"?(u==null?void 0:u.minutesDelta)??0:0),requiresQuote:(u==null?void 0:u.requiresQuote)??!1,isActive:(n==null?void 0:n.isActive)??(u==null?void 0:u.isActive)??!0,label:`${at(d.attribute)}: each additional unit`,retained:!1})}}}for(const d of t.effects)r.has(d.id)||l.push({key:`retained:${d.id}`,subjectType:d.subjectType,subjectAttachmentId:d.subjectAttachmentId,effectKind:d.effectKind,attributeValueId:d.attributeValueId,priceDollars:is(d.priceDeltaCents),minutes:String(d.minutesDelta),requiresQuote:d.requiresQuote,isActive:d.isActive,label:`Unavailable saved effect #${d.id}`,retained:!0});return{baseDollars:t.baseCents==null?"":is(t.baseCents),baseMinutes:t.baseMinutes==null?"":String(t.baseMinutes),requiresQuote:t.requiresQuote??!1,effects:l}}function Za({tiers:t,resolution:s}){var b,j,V,R,D,E;const i=x.useMemo(()=>t.filter(N=>N.isActive),[t]),r=i.find(N=>N.catalogMode==="v1_import")??i[0],[l,a]=x.useState(!1),[d,o]=x.useState((r==null?void 0:r.slug)??""),n=i.find(N=>N.slug===d),[u,h]=x.useState((r==null?void 0:r.catalogMode)==="v1_import"?"runtime_snapshot":"live_walker"),[c,y]=x.useState(""),[f,p]=x.useState(""),S=Ks({tierSlug:d,oracle:u,search:c.trim(),enabled:!!(l&&d&&c.trim().length>=2)}),C=Ks({tierSlug:d,oracle:u==="live_walker"?"runtime_snapshot":"live_walker",search:f,enabled:!!(l&&d&&f&&(n==null?void 0:n.catalogMode)!=="v1_import")}),v=(b=S.data)==null?void 0:b.products.find(N=>N.sku===f),O=(j=C.data)==null?void 0:j.products.find(N=>N.sku===f),P=v!=null&&O!=null&&v.finalPriceCents===O.finalPriceCents&&v.standardMinutes===O.standardMinutes&&v.requiresQuote===O.requiresQuote,$=(s==null?void 0:s.status)==="resolved"&&v?[{label:"Price",source:v.requiresQuote?"Quote":cs(v.finalPriceCents),target:s.requiresQuote?"Quote":cs(s.priceCents??0),matches:v.requiresQuote===s.requiresQuote&&(v.requiresQuote||v.finalPriceCents===s.priceCents)},{label:"Minutes",source:v.standardMinutes==null?"Not set":String(v.standardMinutes),target:s.minutes==null?"Not set":String(s.minutes),matches:v.standardMinutes===s.minutes},{label:"Quote",source:v.requiresQuote?"Required":"Fixed",target:s.requiresQuote?"Required":"Fixed",matches:v.requiresQuote===s.requiresQuote}]:[];return e.jsxs("div",{className:"border-t border-border pt-4","data-testid":"jc-v1-reference-drawer",children:[e.jsxs(A,{type:"button",variant:"ghost",className:"w-full justify-between px-0",onClick:()=>a(N=>!N),"aria-expanded":l,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Bi,{className:"h-4 w-4"}),"V1 reference diff"]}),l?e.jsx(ii,{className:"h-4 w-4"}):e.jsx(Kt,{className:"h-4 w-4"})]}),l&&e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs(fe,{value:d||void 0,onValueChange:N=>{const m=i.find(G=>G.slug===N);o(N),h((m==null?void 0:m.catalogMode)==="v1_import"?"runtime_snapshot":"live_walker"),p("")},children:[e.jsx(be,{"aria-label":"V1 comparison audience",children:e.jsx(ye,{placeholder:"Source audience"})}),e.jsx(Se,{children:i.map(N=>e.jsx(se,{value:N.slug,children:N.name},N.slug))})]}),e.jsxs(fe,{value:u,onValueChange:N=>{h(N),p("")},children:[e.jsx(be,{"aria-label":"V1 comparison oracle",children:e.jsx(ye,{})}),e.jsxs(Se,{children:[e.jsx(se,{value:"live_walker",disabled:(n==null?void 0:n.catalogMode)==="v1_import",children:"Live walker"}),e.jsx(se,{value:"runtime_snapshot",children:"Runtime snapshot"})]})]}),e.jsx(ee,{value:c,onChange:N=>{y(N.target.value),p("")},placeholder:"Search garment, repair, or SKU","aria-label":"Search V1 products"}),d&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Source: ",u==="live_walker"?"live walker semantic model":"frozen runtime snapshot","."]}),e.jsxs(fe,{value:f||void 0,onValueChange:p,disabled:c.trim().length<2||S.isLoading||S.isError,children:[e.jsx(be,{"aria-label":"V1 reference product",children:e.jsx(ye,{placeholder:c.trim().length<2?"Search with at least two characters":S.isLoading?"Loading V1 products...":"Choose exact V1 product"})}),e.jsx(Se,{children:(((V=S.data)==null?void 0:V.products)??[]).map(N=>
372e.jsxs(se,{value:N.sku,children:[N.garmentName," / ",N.serviceName," / ",N.sku]},N.sku))})]}),S.isError&&e.jsx("p",{className:"text-xs text-destructive",role:"alert",children:S.error instanceof Error?S.error.message:"Could not load V1 products."}),(R=S.data)==null?void 0:R.blockingIssues.map(N=>e.jsxs("p",{className:"text-xs text-destructive",children:["Walker blocker: ",N]},`blocker:${N}`)),(D=S.data)==null?void 0:D.warnings.map(N=>e.jsxs("p",{className:"text-xs text-amber-700",children:["Walker warning: ",N]},`warning:${N}`)),(E=S.data)==null?void 0:E.baseOnlyWarnings.map(N=>e.jsxs("p",{className:"text-xs text-amber-700",children:["Walker bare-base warning: ",N]},`base:${N}`)),v&&e.jsxs("div",{className:"border-l-2 border-border pl-3 text-xs",children:[e.jsxs("p",{className:"font-medium",children:[v.garmentName," / ",v.serviceName]}),e.jsxs("p",{className:"mt-1 text-muted-foreground",children:[v.name," (",v.sku,")"]})]}),v&&(n==null?void 0:n.catalogMode)==="v1_import"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Live walker comparison is unavailable for an imported V1 catalog."}),v&&(n==null?void 0:n.catalogMode)!=="v1_import"&&e.jsx("p",{className:`text-xs ${C.isLoading?"text-muted-foreground":P?"text-emerald-700":"text-destructive"}`,children:C.isLoading?"Checking the other V1 source...":C.isError?"Could not check the other V1 source.":O?P?"V1 sources agree on price, minutes, and quote outcome.":"V1 sources resolve different outcomes for this SKU.":"The other V1 source has no product with this SKU."}),$.length>0&&e.jsx("div",{className:"divide-y divide-border border-y border-border text-xs",children:$.map(N=>e.jsxs("div",{className:"grid grid-cols-[4rem_minmax(0,1fr)_minmax(0,1fr)] gap-2 py-2","data-testid":`jc-v1-diff-${N.label.toLowerCase()}`,children:[e.jsx("span",{className:"text-muted-foreground",children:N.label}),e.jsx("span",{children:N.source}),e.jsx("span",{className:N.matches?"text-emerald-700":"text-destructive",children:N.target})]},N.label))})]})]})}function gi(t){const s=t.catalog.configV2Tiers.filter(a=>a.isActive),i=new Set(t.catalog.configV2Garments.filter(a=>a.isActive&&!a.hasActiveChildren&&ei(t.catalog.configV2Garments,a.slug)).map(a=>a.slug)),r=new Set,l=new Set;for(const a of s)for(const d of t.catalog.configV2GarmentServices)!d.isActive||!i.has(d.garmentSlug)||!t.includesCell(d)||!hi(d,a.slug)||(r.add(d.id),l.add(a.slug));return{repairPathCount:r.size,repairPathIds:Array.from(r).sort((a,d)=>a-d),audienceSlugs:Array.from(l).sort()}}function hi(t,s){var i;return t.hasAudienceMembership===!0?((i=t.audienceTierSlugs)==null?void 0:i.includes(s))===!0:!0}function xi(t){const s=t.catalog.configV2Tiers.filter(a=>a.isActive),i=new Set(t.catalog.configV2Garments.filter(a=>a.isActive&&!a.hasActiveChildren&&ei(t.catalog.configV2Garments,a.slug)).map(a=>a.slug)),r=new Set,l=new Set;for(const a of s)for(const d of t.catalog.configV2GarmentServices){if(!d.isActive||!i.has(d.garmentSlug)||!hi(d,a.slug))continue;const o=t.attachments.allServiceAttributes.some(u=>u.isActive&&u.serviceSlug===d.serviceSlug&&u.attributeSlug===t.attributeSlug&&$t(u.tierScope??null,a.slug)),n=Vi({garments:t.catalog.configV2Garments,garmentAttributes:t.attachments.allGarmentAttributes,attributes:t.catalog.configV2Attributes.map(u=>({slug:u.slug,name:u.name,attributeType:u.type,isActive:u.isActive})),garmentSlug:d.garmentSlug,tierSlug:a.slug}).some(u=>u.attributeSlug===t.attributeSlug);!o&&!n||(r.add(d.id),l.add(a.slug))}return{repairPathCount:r.size,repairPathIds:Array.from(r).sort((a,d)=>a-d),audienceSlugs:Array.from(l).sort()}}function en(t){return gi({catalog:t.catalog,includesCell:s=>s.serviceSlug===t.serviceSlug})}function tn(t){return gi({catalog:t.catalog,includesCell:s=>s.garmentSlug===t.garmentSlug})}function sn(t,s){var o,n;const i=t.configV2Tiers.find(u=>u.slug===s),r=(i==null?void 0:i.catalogMode)==="v1_import",l=t.configV2GarmentServices.filter(u=>{var h;return r!==Ha(u)?!1:!r&&(i==null?void 0:i.journeyAuthoringAllowed)===!0?!0:u.hasAudienceMembership&&!((h=u.audienceTierSlugs)!=null&&h.includes(s))?!1:u.isActive||!r&&u.hasAudienceMembership===!0}),a=new Set(l.map(u=>u.garmentSlug));if(!r&&(i==null?void 0:i.journeyAuthoringAllowed)===!0)for(const u of t.configV2Garments)u.isActive&&!Ya(u)&&a.add(u.slug);else{const u=new Map(t.configV2Garments.map(h=>[h.slug,h]));for(const h of[...a]){let c=((o=u.get(h))==null?void 0:o.parentSlug)??null;for(;
372c&&!a.has(c);)a.add(c),c=((n=u.get(c))==null?void 0:n.parentSlug)??null}}const d=t.configV2Garments.filter(u=>u.isActive&&a.has(u.slug)).sort((u,h)=>u.displayOrder-h.displayOrder||u.name.localeCompare(h.name));return{tier:i,cells:l,garments:d}}function pi(t){const s=new Map(t.catalog.configV2Attributes.filter(a=>a.isActive).map(a=>[a.slug,a])),i=t.attachments.configV2GarmentAttributes.filter(a=>a.isActive&&a.garmentSlug===t.garmentSlug).flatMap(a=>{const d=s.get(a.attributeSlug);return d?[{attachmentType:"garment",attachmentId:a.id,isRequired:a.isRequired,displayOrder:a.displayOrder,attribute:d}]:[]}),r=t.attachments.configV2ServiceAttributes.filter(a=>a.isActive&&a.serviceSlug===t.serviceSlug&&$t(a.tierScope,t.tierSlug)).flatMap(a=>{const d=s.get(a.attributeSlug);return d?[{attachmentType:"service",attachmentId:a.id,isRequired:a.isRequired,displayOrder:a.displayOrder,attribute:d}]:[]}),l=(a,d)=>a.displayOrder-d.displayOrder||a.attachmentId-d.attachmentId;return[...i.sort(l),...r.sort(l)]}function rn(t){const s=t.questions.filter(o=>o.attachmentType==="garment"),i=new Map(s.map(o=>[o.attachmentId,o])),r={};for(const o of t.selections){if(o.attachmentType!=="garment"||o.valueId==null)continue;const n=i.get(o.attachmentId),u=n==null?void 0:n.attribute.values.find(h=>h.id===o.valueId);n&&u&&(r[n.attribute.slug]=u.value)}const l=new Map;for(const o of t.scopes){const n=l.get(o.garmentServiceId)??new Map;n.set(o.attributeSlug,[...n.get(o.attributeSlug)??[],o]),l.set(o.garmentServiceId,n)}const a=s.flatMap(o=>o.attribute.values.map(n=>({attributeSlug:o.attribute.slug,slug:n.value,isActive:n.isActive,hiddenForGarments:n.hiddenForGarments}))),d=s.map(o=>({attributeSlug:o.attribute.slug}));return t.cells.map(o=>{var u,h;const n=Ri({garmentSlug:t.garmentSlug,garmentServiceId:o.id,expectedAttributes:d,scopesByGarmentServiceId:l,selections:r,attributeValues:a});return{cell:o,isAllowed:n.isAllowed,scopeAttributeSlugs:Array.from(((u=l.get(o.id))==null?void 0:u.keys())??[]).sort(),scopeValueSlugs:Object.fromEntries(Array.from(((h=l.get(o.id))==null?void 0:h.entries())??[]).map(([c,y])=>[c,y.map(f=>f.attributeValueSlug).sort()])),reasonCodes:n.reasons.map(c=>c.code)}})}function an(t){return`${t.attachmentType}:${t.attachmentId}`}function nn(t,s){const i=new Map;for(const r of t.attribute.values){if(!r.isActive||mt(r,s))continue;const l=r.label.trim().toLocaleLowerCase();if(!l)continue;const a=i.get(l)??{label:r.label.trim(),ids:[]};a.ids.push(r.id),i.set(l,a)}return Array.from(i.values()).filter(r=>r.ids.length>1).map(r=>({label:r.label,valueIds:r.ids})).sort((r,l)=>r.label.localeCompare(l.label))}function ln(t,s){if(t.parentServiceAttributeId!=null&&t.parentGarmentAttributeId==null)return s.get(`service:${t.parentServiceAttributeId}`);if(t.parentGarmentAttributeId!=null&&t.parentServiceAttributeId==null)return s.get(`garment:${t.parentGarmentAttributeId}`)}function cn(t){const s=t.question.attachmentType==="service"?{serviceAttributeId:t.question.attachmentId}:{garmentAttributeId:t.question.attachmentId},i=Ei({child:s,tierSlug:t.tierSlug,garmentServiceId:t.garmentServiceId,sets:t.snapshot.sets,groups:t.snapshot.groups,values:t.snapshot.values,availableParentSelections:[]});if(i.mode==="legacy")return null;const r=i.reasons.map(o=>o.code);
372if(i.selectedSetId==null)return{source:"canonical",selectedSetId:null,combinator:"all",conditional:!1,blocked:!0,reasonCodes:r,groups:[]};const l=t.snapshot.sets.find(o=>o.id===i.selectedSetId);if(!l||l.isActive===!1)return{source:"canonical",selectedSetId:i.selectedSetId,combinator:"all",conditional:!1,blocked:!0,reasonCodes:r,groups:[]};let a=!1;const d=t.snapshot.groups.filter(o=>o.dependencySetId===l.id).sort((o,n)=>o.displayOrder-n.displayOrder||o.id-n.id).map(o=>{const n=ln(o,t.questionsByKey),h=t.snapshot.values.filter(c=>c.dependencyGroupId===o.id).map(c=>c.attributeValueId).map(c=>{const y=n==null?void 0:n.attribute.values.find(f=>f.id===c);return y||(a=!0),{id:c,slug:(y==null?void 0:y.value)??`value-${c}`,label:(y==null?void 0:y.label)??`Unavailable choice #${c}`}});return(!n||h.length===0)&&(a=!0),{id:o.id,parentAttachmentType:(n==null?void 0:n.attachmentType)??null,parentAttachmentId:(n==null?void 0:n.attachmentId)??null,parentAttributeSlug:(n==null?void 0:n.attribute.slug)??"unavailable-parent",parentLabel:n?at(n.attribute):"Unavailable parent question",acceptedValues:h}});return{source:"canonical",selectedSetId:l.id,combinator:"all",conditional:d.length>0,blocked:a,reasonCodes:r,groups:d}}function dn(t){if(t.question.attachmentType==="garment")return{source:"none",selectedSetId:null,combinator:"any",conditional:!1,blocked:!1,reasonCodes:[],groups:[]};const s=t.dependencies.filter(a=>a.attributeSlug===t.question.attribute.slug);if(s.length===0)return{source:"none",selectedSetId:null,combinator:"any",conditional:!1,blocked:!1,reasonCodes:[],groups:[]};const i=new Map;for(const a of s){const d=i.get(a.dependsOnAttributeSlug)??[];d.push(a),i.set(a.dependsOnAttributeSlug,d)}let r=!1;const l=Array.from(i.entries()).map(([a,d])=>{const o=t.questions.filter(h=>h.attachmentType==="service"&&h.attribute.slug===a),n=o.length===1?o[0]:void 0;n||(r=!0);const u=d.map(h=>{if(h.dependsOnValue==="*")return{id:null,slug:"*",label:"Any answer"};const c=n==null?void 0:n.attribute.values.find(y=>y.value===h.dependsOnValue);return c||(r=!0),{id:(c==null?void 0:c.id)??null,slug:h.dependsOnValue,label:(c==null?void 0:c.label)??h.dependsOnValue}});return{id:null,parentAttachmentType:(n==null?void 0:n.attachmentType)??null,parentAttachmentId:(n==null?void 0:n.attachmentId)??null,parentAttributeSlug:a,parentLabel:n?at(n.attribute):a,acceptedValues:u}});return{source:"legacy",selectedSetId:null,combinator:"any",conditional:!0,blocked:r,reasonCodes:r?["legacy_dependency_reference_unavailable"]:[],groups:l}}function vi(t){const s=new Map(t.questions.map(i=>[an(i),i]));return t.questions.map(i=>{const r=cn({question:i,questionsByKey:s,tierSlug:t.tierSlug,garmentServiceId:t.garmentServiceId,snapshot:t.snapshot});return{question:i,dependency:r??dn({question:i,questions:t.questions,dependencies:t.legacyDependencies}),duplicateLabels:nn(i,t.garmentSlug)}})}function on(t,s){const{dependency:i}=t;if(i.blocked)return!1;if(!i.conditional)return!0;const r=new Map(s.map(a=>[`${a.attachmentType}:${a.attachmentId}`,a])),l=i.groups.map(a=>{var n;if(!a.parentAttachmentType||a.parentAttachmentId==null)return!1;const d=r.get(`${a.parentAttachmentType}:${a.parentAttachmentId}`);return!d||!(d.valueId!=null||d.quantity!=null&&d.quantity>0||(((n=d.textValue)==null?void 0:n.trim().length)??0)>0)?!1:a.acceptedValues.some(u=>u.slug==="*"||u.id===d.valueId)});return i.combinator==="all"?l.length>0&&l.every(Boolean):l.some(Boolean)}function un(t){return t.dependency.groups.map((s,i)=>({key:s.id==null?`condition-${i}`:`condition-${s.id}`,parentKey:s.parentAttachmentType&&s.parentAttachmentId!=null?`${s.parentAttachmentType}:${s.parentAttachmentId}`:"",valueIds:s.acceptedValues.flatMap(r=>r.id==null?[]:[r.id]).sort((r,l)=>r-l)}))}function Js(t){return JSON.stringify(t.map(s=>({parentKey:s.parentKey,valueIds:[...s.valueIds].sort((i,r)=>i-r)})))}function it(t){return t.trim()||null}function et({label:t,value:s}){return s?e.jsxs("div",{className:"border-b border-border py-3 last:border-b-0",children:[e.jsx("p",{className:"text-xs font-medium uppercase text-muted-foreground",children:t}),e.jsx("p",{className:"mt-1 break-words text-sm",children:s})]}):null}function gs({impact:t,catalog:s}){const i=new Map(s.configV2Tiers.map(l=>
372[l.slug,l.name])),r=t.audienceSlugs.map(l=>i.get(l)??l);return e.jsxs("div",{className:"border-y border-border py-3","data-testid":"jc-shared-scope",children:[e.jsxs(me,{variant:"secondary",children:["Shared à ",t.repairPathCount]}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:[t.repairPathCount," active repair ",t.repairPathCount===1?"path":"paths","."," ","Audience reach: ",r.length>0?r.join(", "):"no active audiences","."]})]})}function Jt({impact:t,confirming:s,isPending:i,disabled:r,onReview:l,onCancel:a,onConfirm:d,testIdPrefix:o,reviewLabel:n,confirmLabel:u}){const h=o?`${o}-review`:"jc-review-shared-change",c=o?`${o}-confirmation`:"jc-shared-confirmation",y=o?`${o}-confirm`:"jc-confirm-shared-change";return s?e.jsxs("div",{className:"space-y-3 border-l-2 border-amber-500 pl-3","data-testid":c,children:[e.jsx("p",{className:"text-sm",children:"This updates the shared definition immediately."}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(A,{variant:"outline",disabled:i,onClick:a,children:"Keep editing"}),e.jsxs(A,{disabled:r||i,onClick:d,"data-testid":y,children:[i&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),u??"Change everywhere"," (",t.repairPathCount," repair ",t.repairPathCount===1?"path":"paths",")"]})]})]}):e.jsx(A,{className:"w-full",disabled:r||i,onClick:l,"data-testid":h,children:n??"Review shared change"})}function mn({projection:t,context:s}){const i=t.question,r=s.catalog.configV2Tiers.find($=>$.slug===s.tierSlug),l=un(t),[a,d]=x.useState(l),[o,n]=x.useState(1),[u,h]=x.useState(!1),{toast:c}=Pe(),y=s.questions.filter($=>$.attachmentId!==i.attachmentId&&$.attribute.values.some(b=>b.isActive)&&($.attachmentType==="garment"||$.attachmentType==="service"&&$.displayOrder<i.displayOrder)),f=new Map(y.map($=>[`${$.attachmentType}:${$.attachmentId}`,$])),p=Js(a)!==Js(l),S=a.some($=>!$.parentKey||$.valueIds.length===0),T=s.dependencySnapshot.sets.find($=>$.id===t.dependency.selectedSetId),C=(T==null?void 0:T.contextGarmentServiceId)===s.garmentServiceId,v=C?1:s.catalog.configV2GarmentServices.filter($=>{var b,j;return $.serviceSlug===((b=s.catalog.configV2GarmentServices.find(V=>V.id===s.garmentServiceId))==null?void 0:b.serviceSlug)&&($.hasAudienceMembership!==!0||((j=$.audienceTierSlugs)==null?void 0:j.includes(s.tierSlug))===!0)}).length||1,O=le({mutationFn:()=>U(Na,{tierSlug:s.tierSlug,garmentServiceId:s.garmentServiceId,attachmentId:i.attachmentId,groups:a.map(($,b)=>{const[j,V]=$.parentKey.split(":"),R=Number(V);return{parent:{serviceAttributeId:j==="service"?R:null,garmentAttributeId:j==="garment"?R:null},displayOrder:b,attributeValueIds:$.valueIds}})}),onSuccess:()=>{Le(Z,"attachmentDependencies","draftStatus","offerDraft","compiledPreview","publicationPreflight"),h(!1),c({title:a.length===0?"Question is now always shown":"Condition updated"})},onError:$=>c({title:"Could not update condition",description:$.message,variant:"destructive"})});if(i.attachmentType!=="service")return null;if(t.dependency.source==="legacy")return e.jsxs("div",{className:"space-y-2 border-t border-border pt-4","data-testid":"jc-legacy-condition-guidance",children:[e.jsx("p",{className:"text-sm font-medium",children:"Condition"}),e.jsx("p",{className:"border-l-2 border-amber-500 pl-3 text-xs text-muted-foreground",children:"This condition comes from the legacy migration source. Correct the production crosswalk/oracle and rebuild it before canonical adoption; Journey will not silently replace a global legacy rule with a narrower rule."})]});const P=()=>{const $=y[0];d(b=>[...b,{key:`new-${o}`,parentKey:$?`${$.attachmentType}:${$.attachmentId}`:"",valueIds:[]}]),n(b=>b+1),h(!1)};return e.jsxs("div",{className:"space-y-4 border-t border-border pt-4","data-testid":"jc-question-condition-editor",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Condition"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a.length===0?"Always shown after the earlier questions.":"Every condition below must match; within one condition, any checked answer can reveal this question."})]}),a.map(($,b)=>{const j=f.get($.parentKey),V=(j==null?void 0:j.attribute.values.filter(R=>R.isActive&&!mt(R,s.garmentSlug)))??[];return e.jsxs("div",{className:"space-y-3 border-l-2 border-border pl-3","data-testid":`jc-condition-group-${b}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Earlier question"}),e.jsx(A,{type:"button",size:"icon",variant:"ghost",title:"Remove c
372ondition","aria-label":"Remove condition",onClick:()=>{d(R=>R.filter(D=>D.key!==$.key)),h(!1)},children:e.jsx(Xe,{className:"h-4 w-4"})})]}),e.jsxs(fe,{value:$.parentKey,onValueChange:R=>{d(D=>D.map(E=>E.key===$.key?{...E,parentKey:R,valueIds:[]}:E)),h(!1)},children:[e.jsx(be,{"aria-label":`Condition ${b+1} parent`,children:e.jsx(ye,{placeholder:"Choose an earlier pick-one"})}),e.jsx(Se,{children:y.map(R=>e.jsx(se,{value:`${R.attachmentType}:${R.attachmentId}`,children:at(R.attribute)},`${R.attachmentType}:${R.attachmentId}`))})]}),j&&e.jsx("div",{className:"space-y-2",role:"group","aria-label":`Accepted answers for ${at(j.attribute)}`,children:V.map(R=>{const D=$.valueIds.includes(R.id);return e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ri,{checked:D,onCheckedChange:E=>{d(N=>N.map(m=>m.key===$.key?{...m,valueIds:E===!0?Array.from(new Set([...m.valueIds,R.id])):m.valueIds.filter(G=>G!==R.id)}:m)),h(!1)}}),e.jsx("span",{children:R.label})]},R.id)})})]},$.key)}),a.length===0?e.jsxs(A,{type:"button",variant:"outline",className:"w-full",disabled:y.length===0,onClick:P,"data-testid":"jc-add-condition",children:[e.jsx(qt,{className:"mr-1 h-4 w-4"}),"Add condition"]}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(A,{type:"button",variant:"outline",onClick:P,disabled:y.length===0,"data-testid":"jc-add-condition-group",children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"Add AND condition"]}),e.jsx(A,{type:"button",variant:"ghost",onClick:()=>{d([]),h(!1)},"data-testid":"jc-make-unconditional",children:"Always show"})]}),y.length===0&&e.jsx("p",{className:"border-l-2 border-amber-500 pl-3 text-xs text-muted-foreground",children:"Add or move a pick-one question earlier in this Journey before adding a condition."}),p&&!u&&e.jsx(A,{type:"button",className:"w-full",disabled:S||O.isPending,onClick:()=>h(!0),"data-testid":"jc-review-condition-change",children:"Review condition change"}),p&&u&&e.jsxs("div",{className:"space-y-3 border-l-2 border-amber-500 pl-3","data-testid":"jc-condition-confirmation",children:[e.jsxs("p",{className:"text-sm",children:["This changes when the question appears in ",(r==null?void 0:r.name)??s.tierSlug," ",C?"on this repair path":`across ${v} matching repair ${v===1?"path":"paths"}`,". Other audiences keep their saved rule."]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The compiled draft updates n
372ow. The current order configurator will not apply newly authored canonical conditions until Step 10 adoption."}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(A,{type:"button",variant:"outline",disabled:O.isPending,onClick:()=>h(!1),children:"Keep editing"}),e.jsxs(A,{type:"button",disabled:S||O.isPending,onClick:()=>O.mutate(),"data-testid":"jc-confirm-condition-change",children:[O.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),"Save for ",(r==null?void 0:r.name)??s.tierSlug]})]})]}),e.jsx(He,{error:O.error,testId:"jc-condition-save-error"})]})}function gn({projection:t,context:s,impact:i}){var O;const r=t.question,l=r.attachmentType==="service"?s.attachments.configV2ServiceAttributes.find(P=>P.id===r.attachmentId):void 0,a=s.catalog.configV2Tiers.find(P=>P.slug===s.tierSlug),[d,o]=x.useState(r.isRequired),[n,u]=x.useState(!1),[h,c]=x.useState(!1),{toast:y}=Pe(),f=new Map;for(const P of s.catalog.configV2GarmentServices){if(P.serviceSlug!==(l==null?void 0:l.serviceSlug)||P.hasAudienceMembership===!0&&((O=P.audienceTierSlugs)==null?void 0:O.includes(s.tierSlug))!==!0)continue;const $=pi({catalog:s.catalog,attachments:{...s.attachments,configV2GarmentAttributes:s.attachments.allGarmentAttributes.filter(b=>b.garmentSlug===P.garmentSlug),configV2ServiceAttributes:s.attachments.allServiceAttributes.filter(b=>b.serviceSlug===P.serviceSlug)},tierSlug:s.tierSlug,garmentSlug:P.garmentSlug,serviceSlug:P.serviceSlug});for(const b of vi({questions:$,garmentSlug:P.garmentSlug,tierSlug:s.tierSlug,garmentServiceId:P.id,legacyDependencies:s.legacyDependencies,snapshot:s.dependencySnapshot}))b.question.attachmentType==="service"&&b.question.attachmentId!==r.attachmentId&&b.dependency.groups.some(j=>j.parentAttachmentType==="service"&&j.parentAttachmentId===r.attachmentId)&&f.set(b.question.attachmentId,b)}const p=Array.from(f.values()),T=s.catalog.configV2GarmentServices.filter(P=>{var $;return P.serviceSlug===(l==null?void 0:l.serviceSlug)&&(P.hasAudienceMembership!==!0||(($=P.audienceTierSlugs)==null?void 0:$.includes(s.tierSlug))===!0)}).length||1,C=le({mutationFn:()=>U(ya,{tierSlug:s.tierSlug,garmentServiceId:s.garmentServiceId,attachmentId:r.attachmentId,isRequired:d}),onSuccess:()=>{Le(Z,"attachments","draftStatus","offerDraft","compiledPreview"),u(!1),y({title:d?"Question is now required":"Question is now optional"})},onError:P=>y({title:"Could not update requiredness",description:P.message,variant:"destructive"})}),v=le({mutationFn:()=>U(Sa,{tierSlug:s.tierSlug,garmentServiceId:s.garmentServiceId,attachmentId:r.attachmentId}),onSuccess:()=>{Le(Z,"attachments","attachmentDependencies","draftStatus","offerDraft","compiledPreview","publicationPreflight"),c(!1),y({title:`Question removed from ${(a==null?void 0:a.name)??s.tierSlug}`})},onError:P=>y({title:"Could not remove question",description:P.message,variant:"destructive"})});return l?e.jsxs("div",{className:"space-y-4 border-t border-border pt-4","data-testid":"jc-question-placement",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Placement"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Requiredness is shared. Audience removal keeps this definition and its saved condition available for reuse."})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{children:"Required when shown"}),e.jsx(_e,{checked:d,onCheckedChange:P=>{o(P),u(!1)},"aria-label":"Required when shown","data-testid":"jc-question-requiredness"})]}),d!==r.isRequired&&e.jsx(Jt,{impact:i,confirming:n,isPending:C.isPending,onReview:()=>u(!0),onCancel:()=>u(!1),onConfirm:()=>C.mutate(),testIdPrefix:"jc-requiredness"}),e.jsx(He,{error:C.error,testId:"jc-requiredness-error"}),e.jsxs("div",{className:"space-y-3 border-t border-border pt-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium",children:["Remove from ",(a==null?void 0:a.name)??s.tierSlug]}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Removes this question from ",T," matching repair ",T===1?"path":"paths"," in this audie
372nce. Other audiences, wording, choices, pricing drafts, and the saved condition stay unchanged."]})]}),p.length>0&&e.jsxs("div",{className:"border-l-2 border-amber-500 pl-3 text-sm","data-testid":"jc-question-removal-blocker",children:[e.jsx("p",{className:"font-medium",children:"Remove or change these follow-ups first:"}),e.jsx("p",{className:"mt-1 text-muted-foreground",children:p.map(P=>{const $=P.dependency.groups.filter(j=>j.parentAttachmentType==="service"&&j.parentAttachmentId===r.attachmentId).flatMap(j=>j.acceptedValues.map(V=>V.label)),b=at(P.question.attribute);return $.length>0?`${b} (after ${$.join(" or ")})`:b}).join(", ")})]}),h?e.jsxs("div",{className:"space-y-3 border-l-2 border-destructive pl-3","data-testid":"jc-question-removal-confirmation",children:[e.jsxs("p",{className:"text-sm",children:["Customers in this audience will no longer be asked this question. Re-add it later through ",e.jsx("strong",{children:"Add question â Reuse existing"}),"."]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(A,{type:"button",variant:"outline",disabled:v.isPending,onClick:()=>c(!1),children:"Keep question"}),e.jsxs(A,{type:"button",variant:"destructive",disabled:v.isPending,onClick:()=>v.mutate(),"data-testid":"jc-confirm-question-removal",children:[v.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),"Remove from ",(a==null?void 0:a.name)??s.tierSlug]})]})]}):e.jsxs(A,{type:"button",variant:"outline",className:"w-full",disabled:p.length>0||v.isPending,onClick:()=>c(!0),"data-testid":"jc-review-question-removal",children:[e.jsx(br,{className:"mr-1 h-4 w-4"}),"Review audience removal"]}),e.jsx(He,{error:v.error,testId:"jc-question-removal-error"})]})]}):null}function hn({projection:t}){return e.jsxs("div",{className:"p-5","data-testid":"jc-inspector-question",children:[e.jsx(qt,{className:"mb-3 h-5 w-5"}),e.jsx("h3",{className:"text-base font-semibold",children:at(t.question.attribute)}),e.jsx(et,{label:"Kind",value:Vs(t.question.attribute)}),e.jsx(et,{label:"Key",value:t.question.attribute.slug}),e.jsx(et,{label:"Scope",value:t.question.attachmentType==="garment"?"Every repair on this garment":"Every path using this repair"}),e.jsx(et,{label:"Help",value:t.question.attribute.helpText}),e.jsx(et,{label:"Summary label",value:t.question.attribute.summaryLabel})]})}function xn({projection:t,context:s}){const i=t.question.attribute,r=xi({attributeSlug:i.slug,catalog:s.catalog,attachments:s.attachments}),[l,a]=x.useState({questionText:i.questionText??"",helpText:i.helpText??"",summaryLabel:i.summaryLabel??"",imageUrl:i.imageUrl??""}),[d,o]=x.useState(!1),{toast:n}=Pe(),u=le({mutationFn:()=>U(aa,{tierSlug:s.tierSlug,garmentServiceId:s.garmentServiceId,attributeSlug:i.slug,questionText:it(l.questionText),helpText:it(l.helpText),summaryLabel:it(l.summaryLabel),imageUrl:it(l.imageUrl)}),onSuccess:()=>{Le(Z,"catalog","draftStatus","compiledPreview"),o(!1),n({title:"Shared question updated"})},onError:h=>n({title:"Could not update question",description:h.message,variant:"destructive"})});return e.jsxs("div",{className:"space-y-4 p-5","data-testid":"jc-inspector-question-editor",children:[e.jsxs("div",{children:[e.jsx(qt,{className:"mb-3 h-5 w-5"}),e.jsx("h3",{className:"text-base font-semibold",children:at(i)}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[Vs(i)," · ",i.slug]})]}),e.jsx(gs,{impact:r,catalog:s.catalog}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Question"}),e.jsx(ee,{value:l.questionText,onChange:h=>{o(!1),a(c=>({...c,questionText:h.target.value}))},"aria-label":"Question wording"})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Help text"}),e.jsx(Mt,{value:l.helpText,onChange:h=>{o(!1),a(c=>({...c,helpText:h.target.value}))},"aria-label":"Question help text"})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Summary label"}),e.jsx(ee,{value:l.summaryLabel,onChange:h=>{o(!1),a(c=>({...c,summaryLabel:h.target.value}))},"aria-label":"Summary label"})]}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("span",{children:"Image"}),e.jsx(wt,{value:l.imageUrl,onChange:h=>{o(!1),a(c=>({...c,imageUrl:h}))}})]}),e.jsx(Jt,{impact:r,confirming:d,isPending:u.isPending,onReview:()=>o(!0),onCancel:()=>o(!1),onConfirm:()=>u.mutate()}),e.jsx(He,{error:u.error,testId:"jc-question-save-error"}),e.jsx(mn,{projection:t,context:s}),e.jsx(gn,{projection:t,context:s,impact:r}),i.type==="choice"&&e.jsx(jn,{attributeSlug:i.slug,impact:r,context:s}),(i.type==="choice"||Ht(i.type))&&e.jsxs(e.Fragment,{children:[e.jsx(pn,{projection:t,impact:r,context:s}),e.jsx(vn,{projection:t,context:s})]})]})}function pn({projection:t,impact:s,context:i}){const r=t.question.attribute.values.filter(S=>S.isActive).sort((S,T)=>S.displayOrder-T.displayOrder||S.id-T.id),l=r.map(S=>S.id),a=l.join(","),[d,o]=x.useState(l),[n,u]=x.useState(!1),{toast:h}=Pe();x.useEffect(()=>{o(l),u(!1)},[a]);const c=new Map(r.map(S=>[S.id,S])),y=d.join(",")!==a,f=le({mutationFn:()=>U(ta,{tierSlug:i.tierSlug,garmentServiceId:i.garmentServiceId,attributeSlug:t.question.attribute.slug,activeValueIds:d}),onSuccess:()=>{Le(Z,"catalog","offerDraft","draftStatus","compiledPreview"),u(!1),h({title:"Shared choice order updated"})},onError:S=>
372h({title:"Could not reorder choices",description:S.message,variant:"destructive"})}),p=(S,T)=>{u(!1),o(C=>{const v=S+T;if(v<0||v>=C.length)return C;const O=[...C];return[O[S],O[v]]=[O[v],O[S]],O})};return r.length<2?null:e.jsxs("div",{className:"space-y-3 border-t border-border pt-4","data-testid":"jc-choice-order-editor",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Choice order"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Customer-visible order shared by every path using this question."})]}),e.jsx("ol",{className:"divide-y divide-border border-y border-border",children:d.map((S,T)=>{const C=c.get(S);return C?e.jsxs("li",{className:"flex min-h-11 items-center gap-2 py-1.5","data-testid":`jc-choice-order-row-${S}`,children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm","data-testid":`jc-choice-order-label-${S}`,children:C.label}),e.jsxs(A,{type:"button",variant:"ghost",size:"icon",disabled:T===0||f.isPending,onClick:()=>p(T,-1),title:`Move ${C.label} up`,"data-testid":`jc-choice-order-up-${S}`,children:[e.jsx(ni,{className:"h-4 w-4"}),e.jsxs("span",{className:"sr-only",children:["Move ",C.label," up"]})]}),e.jsxs(A,{type:"button",variant:"ghost",size:"icon",disabled:T===d.length-1||f.isPending,onClick:()=>p(T,1),title:`Move ${C.label} down`,"data-testid":`jc-choice-order-down-${S}`,children:[e.jsx(ls,{className:"h-4 w-4"}),e.jsxs("span",{className:"sr-only",children:["Move ",C.label," down"]})]})]},S):null})}),e.jsx(Jt,{impact:s,confirming:n,isPending:f.isPending,disabled:!y,onReview:()=>u(!0),onCancel:()=>u(!1),onConfirm:()=>f.mutate(),testIdPrefix:"jc-choice-order",reviewLabel:"Review shared order",confirmLabel:"Change order everywhere"}),e.jsx(He,{error:f.error,testId:"jc-choice-order-error"})]})}function vn({projection:t,context:s}){const i=[...t.question.attribute.values].sort((c,y)=>Number(y.isActive)-Number(c.isActive)||c.displayOrder-y.displayOrder||c.id-y.id),r=i.map(c=>`${c.id}:${c.isActive}:${c.displayOrder}`).join(","),[l,a]=x.useState(null),{toast:d}=Pe();x.useEffect(()=>{a(null)},[r]);const o=ne({queryKey:["configurator-v2","journey-value-lifecycle",s.tierSlug,s.garmentServiceId,l==null?void 0:l.valueId,l==null?void 0:l.requestedIsActive],enabled:l!==null,queryFn:async()=>{if(!l)throw new Error("Select a choice to review.");return(await U(sa,{tierSlug:s.tierSlug,garmentServiceId:s.garmentServiceId,attributeValueId:l.valueId,requestedIsActive:l.requestedIsActive})).configV2JourneyAttributeValueLifecyclePreflight}}),n=le({mutationFn:async()=>{if(!l||!o.data)throw new Error("Review the current impact before saving.");return U(ia,{tierSlug:s.tierSlug,garmentServiceId:s.garmentServiceId,attributeValueId:l.valueId,requestedIsActive:l.requestedIsActive,expectedFingerprint:o.data.fingerprint})},onSuccess:()=>{const c=(l==null?void 0:l.requestedIsActive)===!0;Le(Z,"catalog","offerDraft","draftStatus","compiledPreview","descriptorScopes","attachmentDependencies"),a(null),d({title:c?"Shared choice restored":"Shared choice retired"})}}),u=l==null?void 0:i.find(c=>c.id===l.valueId),h=o.data;return e.jsxs("div",{className:"space-y-3 border-t border-border pt-4","data-testid":"jc-choice-lifecycle-editor",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Shared choice availability"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Retire without deleting, or restore after reviewing every shared path."})]}),e.jsx("div",{className:"divide-y divide-border border-y border-border",children:i.map(c=>e.jsxs("div",{className:"flex min-h-11 items-center gap-2 py-1.5","data-testid":`jc-choice-lifecycle-row-${c.id}`,children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:c.label}),e.jsx(me,{variant:c.isActive?"secondary":"outline",children:c.isActive?"Active":"Retired"}),e.jsx(A,{type:"button",variant:"outline",size:"sm",disabled:n.isPending,onClick:()=>a({valueId:c.id,requestedIsActive:!c.isActive}),"data-testid":`jc-choice-lifecycle-review-${c.id}`,children:c.isActive?"Review retirement":"Review restore"})]},c.id))}),l&&e.jsxs("div",{className:"space-y-3 border-l-2 border-amber-500 pl-3","data-testid":"jc-choice-lifecycle-review",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium",children:[l.requestedIsActive?"Restore":"Retire"," ",(u==null?void 0:u.label)??"choice"]}),o.isLoading&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Checking shared conditions, pricing, scopes, and repair paths..."})]}
372),o.error&&e.jsx(He,{error:o.error,testId:"jc-choice-lifecycle-preflight-error"}),h&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs text-muted-foreground","data-testid":"jc-choice-lifecycle-paths",children:[e.jsxs("p",{children:[h.affectedRepairPaths.length," affected repair ",h.affectedRepairPaths.length===1?"path":"paths"]}),h.affectedRepairPaths.slice(0,8).map(c=>e.jsx("p",{className:"mt-1",children:c},c)),h.affectedRepairPaths.length>8&&e.jsxs("p",{className:"mt-1",children:["+ ",h.affectedRepairPaths.length-8," more"]})]}),h.blockers.length>0&&e.jsxs("div",{className:"space-y-2","data-testid":"jc-choice-lifecycle-blockers",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:"Resolve these before continuing"}),h.blockers.map((c,y)=>e.jsxs("div",{className:"border-l-2 border-destructive pl-3 text-sm",role:"alert",children:[e.jsx("p",{children:c.message}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:c.action})]},`${c.code}-${y}`))]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(A,{type:"button",variant:"outline",onClick:()=>a(null),children:"Cancel"}),e.jsxs(A,{type:"button",disabled:h.blockers.length>0||n.isPending,onClick:()=>n.mutate(),"data-testid":"jc-choice-lifecycle-confirm",children:[n.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),l.requestedIsActive?"Restore everywhere":"Make unavailable everywhere"]})]}),e.jsx(He,{error:n.error,testId:"jc-choice-lifecycle-save-error"})]})]})]})}function jn({attributeSlug:t,impact:s,context:i}){var b;const{toast:r}=Pe(),[l,a]=x.useState(!1),[d,o]=x.useState(""),[n,u]=x.useState(""),[h,c]=x.useState(!1),[y,f]=x.useState(""),[p,S]=x.useState(""),[T,C]=x.useState(""),[v,O]=x.useState(!1),P=!!n.trim()&&((b=i.catalog.configV2Attributes.find(j=>j.slug===t))==null?void 0:b.values.some(j=>j.value===n.trim()))===!0,$=le({mutationFn:()=>U(Zr,{tierSlug:i.tierSlug,garmentServiceId:i.garmentServiceId,attributeSlug:t,value:n.trim(),label:d.trim(),skuCode:null,description:it(y),imageUrl:it(p),disclaimerText:it(T),disclaimerRequiresAck:!!T.trim()&&v}),onSuccess:()=>{Le(Z,"catalog","offerDraft","draftStatus","compiledPreview"),r({title:"Shared choice added"}),a(!1)},onError:j=>r({title:"Could not add choice",description:j.message,variant:"destructive"})});return l?e.jsxs("div",{className:"space-y-3 border-t border-border pt-4","data-testid":"jc-add-choice-form",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Add shared choice"}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Adds to all ",s.repairPathCount," repair paths. Price it through the pricing lens."]})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Label"}),e.jsx(ee,{value:d,onChange:j=>{o(j.target.value),h||u(bt(j.target.value))},"aria-label":"New choice label"})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Key"}),e.jsx(ee,{value:n,onChange:j=>{c(!0),u(j.target.value)},"aria-label":"New choice key"})]}),P&&e.jsx("p",{className:"text-sm text-destructive",role:"alert","data-testid":"jc-choice-key-error",children:"That choice key is already in use for this question."}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Description"}),e.jsx(Mt,{value:y,onChange:j=>f(j.target.value),"aria-label":"New choice description"})]}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("span",{children:"Image"}),e.jsx(wt,{value:p,onChange:S})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Disclaimer"}),e.jsx(Mt,{value:T,onChange:j=>C(j.target.value),"aria-label":"New choice disclaimer"})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{children:"Require acknowledgment"}),e.jsx(_e,{checked:v,disabled:!T.trim(),onCheckedChange:O,"aria-label":"New choice disclaimer requires acknowledgment"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{type:"button",variant:"outline",className:"flex-1",onClick:()=>a(!1),children:"Cancel"}),e.jsxs(A,{type:"button",className:"flex-1",disabled:!d.trim()||!n.trim()||P||$.isPending,onClick:()=>$.mutate(),"data-testid":"jc-save-choice",children:[$.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),"Add everywhere"]})]}
372),e.jsx(He,{error:$.error,testId:"jc-choice-create-error"})]}):e.jsxs(A,{type:"button",variant:"outline",className:"w-full border-dashed",onClick:()=>a(!0),"data-testid":"jc-add-choice",children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"Add choice"]})}function fn({projection:t,value:s}){const i=Ht(t.question.attribute.type);return e.jsxs("div",{className:"p-5","data-testid":"jc-inspector-value",children:[e.jsx(ks,{className:"mb-3 h-5 w-5"}),e.jsx("h3",{className:"text-base font-semibold",children:s.label}),e.jsx(et,{label:"Question",value:at(t.question.attribute)}),e.jsx(et,{label:"Key",value:s.value}),i&&e.jsx(et,{label:"SKU code",value:s.skuCode||"Not set"}),e.jsx(et,{label:"Description",value:s.description}),e.jsx(et,{label:"Image",value:s.imageUrl||"No image"}),e.jsx(et,{label:"Disclaimer",value:s.disclaimerText})]})}function bn({projection:t,value:s,context:i}){const r=Ht(t.question.attribute.type),l=xi({attributeSlug:t.question.attribute.slug,catalog:i.catalog,attachments:i.attachments}),[a,d]=x.useState({label:s.label,skuCode:s.skuCode??"",description:s.description??"",imageUrl:s.imageUrl??"",disclaimerText:s.disclaimerText??"",disclaimerRequiresAck:s.disclaimerRequiresAck}),[o,n]=x.useState(!1),{toast:u}=Pe(),h=le({mutationFn:()=>U(ea,{tierSlug:i.tierSlug,garmentServiceId:i.garmentServiceId,attributeValueId:s.id,label:a.label.trim(),skuCode:r?it(a.skuCode):null,description:it(a.description),imageUrl:it(a.imageUrl),disclaimerText:it(a.disclaimerText),disclaimerRequiresAck:!!a.disclaimerText.trim()&&a.disclaimerRequiresAck}),onSuccess:()=>{Le(Z,"catalog","offerDraft","draftStatus","compiledPreview"),n(!1),u({title:"Shared choice updated"})},onError:c=>u({title:"Could not update choice",description:c.message,variant:"destructive"})});return e.jsxs("div",{className:"space-y-4 p-5","data-testid":"jc-inspector-value-editor",children:[e.jsxs("div",{children:[e.jsx(ks,{className:"mb-3 h-5 w-5"}),e.jsx("h3",{className:"text-base font-semibold",children:s.label}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[at(t.question.attribute)," · ",s.value]})]}),e.jsx(gs,{impact:l,catalog:i.catalog}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Choice label"}),e.jsx(ee,{value:a.label,onChange:c=>{n(!1),d(y=>({...y,label:c.target.value}))},"aria-label":"Choice label"})]}),r&&e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"SKU code (optional)"}),e.jsx(ee,{value:a.skuCode,onChange:c=>{n(!1),d(y=>({...y,skuCode:c.target.value}))},"aria-label":"Choice SKU code"})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Description"}),e.jsx(Mt,{value:a.description,onChange:c=>{n(!1),d(y=>({...y,description:c.target.value}))},"aria-label":"Choice description"})]}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("span",{children:"Image"}),e.jsx(wt,{value:a.imageUrl,onChange:c=>{n(!1),d(y=>({...y,imageUrl:c}))}})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Disclaimer"}),e.jsx(Mt,{value:a.disclaimerText,onChange:c=>{n(!1),d(y=>({...y,disclaimerText:c.target.value}))},"aria-label":"Choice disclaimer"})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{children:"Require acknowledgment"}),e.jsx(_e,{checked:a.disclaimerRequiresAck,disabled:!a.disclaimerText.trim(),onCheckedChange:c=>{n(!1),d(y=>({...y,disclaimerRequiresAck:c}))},"aria-label":"Choice disclaimer requires acknowledgment"})]}),e.jsx(Jt,{impact:l,confirming:o,isPending:h.isPending,disabled:!a.label.trim(),onReview:()=>n(!0),onCancel:()=>n(!1),onConfirm:()=>h.mutate()}),e.jsx(He,{error:h.error,testId:"jc-choice-save-error"})]})}function yn({garment:t,context:s}){const i=tn({garmentSlug:t.slug,catalog:s.catalog}),[r,l]=x.useState({name:t.name,imageUrl:t.imageUrl??""}),[a,d]=x.useState(!1),{toast:o}=Pe(),n=le({mutationFn:()=>U(ra,{tierSlug:s.tierSlug,garmentServiceId:s.garmentServiceId,name:r.name.trim(),imageUrl:it(r.imageUrl)}),onSuccess:()=>{Le(Z,"catalog","compiledPreview"),d(!1),o({title:"Shared garment updated"})},onError:u=>o({title:"Could not update garment",description:u.message,variant:"destructive"})});return e.jsxs("div",{className:"space-y-4 p-5","data-testid":"jc-inspector-garment-editor",children:[e.jsxs("div",{children:[e.jsx(os,{className:"mb-3 h-5 w-5"}),e.jsx("h3",{className:"text-base font-semibold",children:t.name}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t.slug})]}),e.jsx(gs,{impact:i,catalog:s.catalog}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Garment name"}),e.jsx(ee,{maxLength:100,value:r.name,onChange:u=>{d(!1),l(h=>({...h,name:u.target.value}))},"aria-label":"Garment name"})]}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("span",{children:"Garment image"}
372),e.jsx(wt,{value:r.imageUrl,onChange:u=>{d(!1),l(h=>({...h,imageUrl:u}))}})]}),e.jsx(Jt,{impact:i,confirming:a,isPending:n.isPending,disabled:!r.name.trim(),onReview:()=>d(!0),onCancel:()=>d(!1),onConfirm:()=>n.mutate()}),e.jsx(He,{error:n.error,testId:"jc-garment-save-error"})]})}function Sn({cell:t,service:s,context:i}){const r=en({serviceSlug:t.serviceSlug,catalog:i.catalog}),[l,a]=x.useState({name:s.name,description:s.description??"",imageUrl:s.imageUrl??"",serviceGroup:s.serviceGroup??"",disclaimerText:s.disclaimerText??"",disclaimerRequiresAck:s.disclaimerRequiresAck}),[d,o]=x.useState(!1),[n,u]=x.useState(""),{toast:h}=Pe(),c=le({mutationFn:()=>U(na,{tierSlug:i.tierSlug,garmentServiceId:i.garmentServiceId,name:l.name.trim(),description:it(l.description),imageUrl:it(l.imageUrl),serviceGroup:it(l.serviceGroup),disclaimerText:it(l.disclaimerText),disclaimerRequiresAck:!!l.disclaimerText.trim()&&l.disclaimerRequiresAck}),onSuccess:()=>{Le(Z,"catalog","compiledPreview"),o(!1),h({title:"Shared repair presentation updated"})},onError:p=>h({title:"Could not update repair presentation",description:p.message,variant:"destructive"})}),y=i.catalog.configV2Garments.filter(p=>p.isActive&&!p.hasActiveChildren&&p.slug!==t.garmentSlug&&!i.catalog.configV2GarmentServices.some(S=>S.garmentSlug===p.slug&&S.serviceSlug===t.serviceSlug)),f=le({mutationFn:()=>U(oa,{sourceGarmentServiceId:t.id,sourceTierSlug:i.tierSlug,targetGarmentSlug:n}),onSuccess:p=>{var T;const S=p.configV2ForkGarmentServiceCell;Le(Z,"catalog","draftStatus","offerDraft","compiledPreview"),h({title:"Draft fork created"}),(T=i.onNavigateToCell)==null||T.call(i,S.garmentSlug,S.id)},onError:p=>h({title:"Could not fork repair",description:p.message,variant:"destructive"})});return e.jsxs("div",{className:"space-y-4 p-5","data-testid":"jc-inspector-repair-editor",children:[e.jsxs("div",{children:[e.jsx(Zt,{className:"mb-3 h-5 w-5"}),e.jsx("h3",{className:"text-base font-semibold",children:s.name}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t.serviceSlug})]}),e.jsx(gs,{impact:r,catalog:i.catalog}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Repair name"}),e.jsx(ee,{maxLength:100,value:l.name,onChange:p=>{o(!1),a(S=>({...S,name:p.target.value}))},"aria-label":"Repair name"})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Description"}),e.jsx(Mt,{value:l.description,onChange:p=>{o(!1),a(S=>({...S,description:p.target.value}))},"aria-label":"Repair description"})]}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsx("span",{children:"Image"}),e.jsx(wt,{value:l.imageUrl,onChange:p=>{o(!1),a(S=>({...S,imageUrl:p}))}})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Service group"}),e.jsx(ee,{value:l.serviceGroup,onChange:p=>{o(!1),a(S=>({...S,serviceGroup:p.target.value}))},"aria-label":"Repair service group"})]}),e.jsxs("label",{className:"block space-y-1 text-sm",children:[e.jsx("span",{children:"Disclaimer"}),e.jsx(Mt,{value:l.disclaimerText,onChange:p=>{o(!1),a(S=>({...S,disclaimerText:p.target.value}))},"aria-label":"Repair disclaimer"})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{children:"Require acknowledgment"}),e.jsx(_e,{checked:l.disclaimerRequiresAck,disabled:!l.disclaimerText.trim(),onCheckedChange:p=>{o(!1),a(S=>({...S,disclaimerRequiresAck:p}))},"aria-label":"Repair disclaimer requires acknowledgment"})]}),e.jsx(Jt,{impact:r,confirming:d,isPending:c.isPending,disabled:!l.name.trim(),onReview:()=>o(!0),onCancel:()=>o(!1),onConfirm:()=>c.mutate()}),e.jsx(He,{error:c.error,testId:"jc-repair-save-error"}),e.jsxs("div",{className:"space-y-3 border-t border-border pt-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Fork repair draft"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t.isActive?"Copies this audience's R1 draft to another garment. The fork starts inactive, outside every audience, and unpublished.":"Activate this priced source repair before forking it."})]}),e.jsxs(fe,{value:n,onValueChange:u,children:[e.jsx(be,{"aria-label":"Fork target garment",children:e.jsx(ye,{placeholder:"Choose target garment"})}),e.jsx(Se,{children:y.map(p=>e.jsx(se,{value:p.slug,children:p.name},p.slug))})]}),e.jsxs(A,{type:"button",variant:"outline",className:"w-full",disabled:!t.isActive||!n||f.isPending,onClick:()=>f.mutate(),"data-testid":"jc-fork-repair",children:[f.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),"Create draft fork"]}),e.jsx(He,{error:f.error,testId:"jc-fork-error"})]})]})}function ns({cell:t,service:s,context:i,focus:r}){var O,P;const{toast:l}=Pe(),[a,d]=x.useState(()=>i.pricingDraft?Xa(i.pricingDraft,i.questions,i.garmentSlug):null),[o]=x.useState(a),[n,u]=x.useState(null),h=le({mutationFn:$=>U(Xr,{tierSlug:i.tierSlug,garmentServiceId:i.garmentServiceId,draft:{baseCents:rs((a==null?void 0:a.baseDollars)??"","Base price"),baseMinutes:a!=null&&a.baseMinutes.trim()?as(a.baseMinutes,"Base minutes"):null,requiresQuote:(a==null?void 0:a.requiresQuote)??!1,isActive:!0,effects:$}}),onSuccess:()=>{Le(Z,"draftStatus","offerDraft","compiledPreview"),l({title:"Pricing draft saved"})},onError:$=>l({title:"Could not save pricing draft",description:$.message,variant:"destructive"})}),c=($,b)=>d(j=>j==null?j:{...j,effects:j.effects.map(V=>V.key===$?{...V,...b}:V)}),y=()=>
372{if(a){u(null);try{const $=a.effects.flatMap(b=>{const j=rs(b.priceDollars,`${b.label} price`),V=as(b.minutes,`${b.label} minutes`);return b.effectKind==="multiply_selected"?[{subjectType:b.subjectType,subjectAttachmentId:b.subjectAttachmentId,effectKind:"multiply_selected",attributeValueId:null,priceDeltaCents:0,minutesDelta:0,requiresQuote:!1,isActive:b.isActive},...b.requiresQuote?[{subjectType:b.subjectType,subjectAttachmentId:b.subjectAttachmentId,effectKind:"additional_unit",attributeValueId:null,priceDeltaCents:0,minutesDelta:0,requiresQuote:!0,isActive:b.isActive}]:[]]:b.retained||j!==0||V!==0||b.requiresQuote?[{subjectType:b.subjectType,subjectAttachmentId:b.subjectAttachmentId,effectKind:b.effectKind,attributeValueId:b.attributeValueId,priceDeltaCents:j,minutesDelta:V,requiresQuote:b.requiresQuote,isActive:b.isActive}]:[]});rs(a.baseDollars,"Base price"),a.baseMinutes.trim()&&as(a.baseMinutes,"Base minutes"),h.mutate($)}catch($){const b=$ instanceof Error?$:new Error("Pricing values are invalid.");u(b),l({title:"Check pricing values",description:b.message,variant:"destructive"})}}},f=x.useMemo(()=>{if(!a||!o)return[];const $=m=>{try{return rs(m,"price")}catch{return Number.NaN}},b=m=>{if(!m.trim())return null;try{return as(m,"minutes")}catch{return Number.NaN}},j=(m,G)=>m===null||G===null?m===G:Object.is(m,G),V=m=>{const G=$(m);return Number.isNaN(G)?`"${m}"`:`$${(G/100).toFixed(2)}`},R=m=>{const G=b(m);return G===null?"none":Number.isNaN(G)?`"${m}"`:`${G}m`},D=m=>m==="multiply_selected"?"Repeat total":m==="additional_unit"?"Additional unit":"Selected value",E=[];Object.is($(o.baseDollars),$(a.baseDollars))||E.push({chipKeys:["base"],text:`Base price ${V(o.baseDollars)} â ${V(a.baseDollars)}`}),j(b(o.baseMinutes),b(a.baseMinutes))||E.push({chipKeys:["base"],text:`Base minutes ${R(o.baseMinutes)} â ${R(a.baseMinutes)}`}),o.requiresQuote!==a.requiresQuote&&E.push({chipKeys:["base"],text:`Quote required ${o.requiresQuote?"on":"off"} â ${a.requiresQuote?"on":"off"}`});const N=new Map(o.effects.map(m=>[m.key,m]));for(const m of a.effects){const G=N.get(m.key);if(!G)continue;const X=[`${m.subjectType}:${m.subjectAttachmentId}`,...m.attributeValueId==null?[]:[`${m.subjectType}:${m.subjectAttachmentId}:${m.attributeValueId}`]];G.effectKind!==m.effectKind&&E.push({chipKeys:X,text:`${m.label}: mode ${D(G.effectKind)} â ${D(m.effectKind)}`}),Object.is($(G.priceDollars),$(m.priceDollars))||E.push({chipKeys:X,text:`${m.label}: price ${V(G.priceDollars)} â ${V(m.priceDollars)}`}),j(b(G.minutes),b(m.minutes))||E.push({chipKeys:X,text:`${m.label}: minutes ${R(G.minutes)} â ${R(m.minutes)}`}),G.requiresQuote!==m.requiresQuote&&E.push({chipKeys:X,text:`${m.label}: quote ${G.requiresQuote?"on":"off"} â ${m.requiresQuote?"on":"off"}`})}return E},[a,o]),p=x.useMemo(()=>Array.from(new Set(f.flatMap($=>$.chipKeys))).sort(),[f]),S=i.onPricingDirtyChange;x.useEffect(()=>{S==null||S(p)},[p,S]),x.useEffect(()=>()=>S==null?void 0:S([]),[S]);const T=((O=i.catalog.configV2Tiers.find($=>$.slug===i.tierSlug))==null?void 0:O.name)??i.tierSlug,C=(s==null?void 0:s.name)??t.serviceName??t.serviceSlug,v=r==="base"?(a==null?void 0:a.effects.filter($=>$.retained))??[]:(a==null?void 0:a.effects.filter($=>$.subjectType===r.attachmentType&&$.subjectAttachmentId===r.attachmentId&&(r.valueId==null||$.attributeValueId===r.valueId)))??[];return a?e.jsxs("div",{className:"space-y-4 p-5","data-testid":"jc-inspector-pricing-editor",children:[e.jsxs("div",{children:[e.jsx(Zt,{className:"mb-3 h-5 w-5"}),e.jsx("h3",{className:"text-base font-semibold",children:(s==null?void 0:s.name)??t.serviceName??t.serviceSlug}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Pricing · this audience and repair path"})]}),r==="base"&&e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("label",{className:"space-y-1 text-sm",children:[e.jsx("span",{children:"Base price"}),e.jsx(ee,{inputMode:"decimal",value:a.baseDollars,onChange:$=>d(b=>b&&{...b,baseDollars:$.target.value}),"aria-label":"Base price"})]}),e.jsxs("label",{className:"space-y-1 text-sm",children:[e.jsx("span",{children:"Base minutes"}),e.jsx(ee,{inputMode:"numeric",value:a.baseMinutes,onChange:$=>d(b=>b&&{...b,baseMinutes:$.target.value}),"aria-label":"Base minutes"})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{children:"Quote required"}),e.jsx(_e,{checked:a.requiresQuote,onCheckedChange:$=>d(b=>b&&{...b,requiresQuote:$}),"aria-label":"Base quote required"})]})]}),r!=="base"&&v.length===0&&e.jsx("p",{className:"border-l-2 border-amber-500 pl-3 text-sm text-muted-foreground",children:"No price effect is available for this question in the current R1 draft."}),v.map($=>{const b=$.retained,j=$.effectKind!=="selected_value",V=$.effectKind==="multiply_selected";return e.jsxs("div",{className:"space-y-3 border-t border-border pt-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:$.label}),b&&e.jsxs("p",{className:"mt-1 text-xs text-amber-700",children:[e.jsx(St,{className:"mr-1 inline h-3.5 w-3.5"}),"Saved effect is unavailable and will be retained."]})]}),j&&!b&&e.jsxs("div",{className:"grid grid-cols-2",role:"group","aria-label":`${$.label} pricing mode`,children:[e.jsx(A,{size:"sm",variant:V?"outline":"default",className:"rounded-r-none","aria-pressed":!V,onClick:()=>c($.key,{effectKind:"additional_unit"}),children:"Additional unit"}),e.jsx(A,{size:"sm",variant:V?"default":"outline",className:"rounded-l-none border-l-0","aria-pressed":V,onClick:()=>c($.key,{effectKind:"multiply_selected",priceDollars:"0.00",minutes:"0"}),children:"Repeat total"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"space-y-1 text-sm",children:[e.jsx("span",{children:j?"Additional price":"Price delta"}),e.jsx(ee,{inputMode:"decimal",disabled:b||V,value:$.priceDollars,onChange:R=>c($.key,{priceDollars:R.target.value}),"aria-label":`${$.label} price delta`})]}),e.jsxs("label",{className:"space-y-1 text-sm",children:[e.jsx("span",{children:j?"Additional minutes":"Minutes"}),e.jsx(ee,{inputMode:"numeric",disabled:b||V,value:$.minutes,onChange:R=>c($.key,{minutes:R.target.value}),"aria-label":`${$.label} minutes delta`})]})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{children:"Quote for this answer"}),e.jsx(_e,{checked:$.requiresQuote,disabled:b,onCheckedChange:R=>c($.key,{requiresQuote:R}),"aria-label":`${$.label} quote required`})]})]},$.key)}),f.length>0?e.jsxs("div",{className:"rounded-md border border-amber-500/50 bg-amber-500/10 p-3 text-xs","data-testid":"jc-pricing-change-manifest",children:[e.jsxs("p",{className:"font-medium",children:["Saving commits this repair's whole pricing draft â ",f.length," pending change",f.length===1?"":"s",", including any not shown in the current view:"]}),e.jsx("ul",{className:"mt-1.5 list-disc space-y-0.5 pl-4",children:f.map($=>e.jsx("li",{children:$.text},$.text))})]}):e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"jc-pricing-no-ch
372anges",children:"No unsaved pricing changes."}),e.jsxs(A,{className:"h-auto min-h-10 w-full whitespace-normal",disabled:h.isPending,onClick:y,"data-testid":"jc-save-pricing",children:[h.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),"Save pricing â ",C," · ",T]}),e.jsx(He,{error:n??h.error,testId:"jc-pricing-save-error"}),r==="base"&&e.jsx(Za,{tiers:i.catalog.configV2Tiers,resolution:(P=i.compiledPreview)==null?void 0:P.resolution})]}):e.jsxs("div",{className:"p-5 text-sm text-muted-foreground",children:[e.jsx(Ne,{className:"mb-3 h-5 w-5 animate-spin"}),"Loading pricing draft..."]})}function Ws({selection:t,context:s}){var l,a,d,o;if(!t)return e.jsxs("div",{className:"p-5 text-sm text-muted-foreground","data-testid":"jc-inspector-empty",children:[e.jsx(si,{className:"mb-3 h-5 w-5"}),"Select something in the walk."]});const i=s==null?void 0:s.catalog.configV2GarmentServices.find(n=>n.id===s.garmentServiceId),r=i?s==null?void 0:s.catalog.configV2Services.find(n=>n.slug===i.serviceSlug):void 0;if(t.kind==="garment")return s&&!s.isReadOnly?e.jsx(yn,{garment:t.garment,context:s},`${t.garment.slug}:${t.garment.imageUrl??""}`):e.jsxs("div",{className:"p-5","data-testid":"jc-inspector-garment",children:[e.jsx(os,{className:"mb-3 h-5 w-5"}),e.jsx("h3",{className:"text-base font-semibold",children:t.garment.name}),e.jsx(et,{label:"Key",value:t.garment.slug}),e.jsx(et,{label:"Image",value:t.garment.imageUrl||"No image"})]});if(t.kind==="pricing")return s&&!s.isReadOnly?e.jsx(ns,{cell:t.cell,service:t.service,context:s,focus:"base"},`${s.tierSlug}:${s.garmentServiceId}:${JSON.stringify(s.pricingDraft)}`):e.jsx("div",{className:"p-5 text-sm text-muted-foreground",children:"Pricing is read-only in this audience."});if(t.kind==="repair")return s&&!s.isReadOnly&&s.lens==="pricing"&&s.garmentServiceId===t.cell.id?e.jsx(ns,{cell:t.cell,service:t.service,context:s,focus:"base"},`${s.tierSlug}:${s.garmentServiceId}:${JSON.stringify(s.pricingDraft)}`):s&&!s.isReadOnly&&t.service?e.jsx(Sn,{cell:t.cell,service:t.service,context:s},`${t.cell.serviceSlug}:${JSON.stringify(t.service)}`):e.jsxs("div",{className:"p-5","data-testid":"jc-inspector-repair",children:[e.jsx(Zt,{className:"mb-3 h-5 w-5"}),e.jsx("h3",{className:"text-base font-semibold",children:((l=t.service)==null?void 0:l.name)??t.cell.serviceName??t.cell.serviceSlug}),e.jsx(et,{label:"Key",value:t.cell.serviceSlug}),e.jsx(et,{label:"Group",value:((a=t.service)==null?void 0:a.serviceGroup)||"Ungrouped"}),e.jsx(et,{label:"Description",value:(d=t.service)==null?void 0:d.description}),e.jsx(et,{label:"Disclaimer",value:(o=t.service)==null?void 0:o.disclaimerText})]});if(t.kind==="value")return s&&i&&!s.isReadOnly&&s.lens==="pricing"?e.jsx(ns,{cell:i,service:r,context:s,focus:{attachmentType:t.projection.question.attachmentType,attachmentId:t.projection.question.attachmentId,valueId:t.value.id}},`${s.tierSlug}:${s.garmentServiceId}:${JSON.stringify(s.pricingDraft)}`):s&&!s.isReadOnly?e.jsx(bn,{projection:t.projection,value:t.value,context:s},`${t.value.id}:${JSON.stringify(t.value)}`):e.jsx(fn,{projection:t.projection,value:t.value});if(s&&!s.isReadOnly&&s.lens==="pricing"){const n=s.catalog.configV2GarmentServices.find(u=>u.id===s.garmentServiceId);if(n)return e.jsx(ns,{cell:n,service:s.catalog.configV2Services.find(u=>u.slug===n.serviceSlug),context:s,focus:{attachmentType:t.projection.question.attachmentType,attachmentId:t.projection.question.attachmentId}},`${s.tierSlug}:${s.garmentServiceId}:${JSON.stringify(s.pricingDraft)}`)}return s&&!s.isReadOnly?e.jsx(xn,{projection:t.projection,context:s},`${t.projection.question.attribute.slug}:${JSON.stringify(t.projection.question.attribute)}:${JSON.stringify(t.projection.dependency)}`):e.jsx(hn,{projection:t.projection})}const Nn=[{value:"content",label:"Content"},{value:"pricing",label:"Pricing"},{value:"availability",label:"Availability"}];function Cn(t){const s=new Map(((t==null?void 0:t.configV2Garments)??[]).map(a=>[a.slug,a.name])),i=new Map(((t==null?void 0:t.configV2Services)??[]).map(a=>[a.slug,a.name])),r=(a,d)=>`${s.get(a)??a} ⺠${i.get(d)??d}`;return{cellLabel:r,humanizeWarning:a=>{const d=a.match(/^([a-z0-9-]+)\/([a-z0-9-]+):\s*(.*)$/i);if(!d)return a;const[,o,n,u]=d,h=u.replace(/^Offer\s+\S+\s+/,"").replace("has no selectable attachments and resolves at base only","prices at its base amount only â it has no answer options that add pricing");return`${r(o,n)}: ${h}`}}}
372function An({blocked:t,skipped:s,stale:i,cellLabel:r}){const l=new Map(i.map(a=>[a.garmentServiceId,a]));return e.jsx("div",{className:"mt-3 divide-y divide-border border-y border-border text-sm",children:t.concat(s).map(a=>{const d=l.get(a.garmentServiceId);return e.jsxs("div",{className:"py-2",children:[e.jsx("p",{className:"font-medium",title:`${a.garmentSlug} / ${a.serviceSlug}`,children:r(a.garmentSlug,a.serviceSlug)}),e.jsxs("p",{className:"mt-0.5 text-muted-foreground",children:[a.reason,d?` Revision v${d.version} remains live and stale.`:""]})]},`${a.garmentServiceId}:${a.reason}`)})})}function $n({rows:t,cellLabel:s}){return e.jsx("div",{className:"mt-3 divide-y divide-border border-y border-border text-sm",children:t.map(i=>e.jsxs("div",{className:"py-2",children:[e.jsx("p",{className:"font-medium",title:`${i.garmentSlug} / ${i.serviceSlug}`,children:s(i.garmentSlug,i.serviceSlug)}),e.jsxs("p",{className:"mt-0.5 text-destructive",children:[i.reason," Revision v",i.version," will leave this audience; its history remains available for restoration."]})]},i.garmentServiceId))})}function wn({tier:t,catalog:s,plan:i,result:r,isLoading:l,isError:a,error:d,isPublishing:o,onRefresh:n,onPublish:u,onClose:h}){const c=r??i,y=(r==null?void 0:r.publishedCount)??(i==null?void 0:i.publishCount)??0,f=(r==null?void 0:r.retired)??(i==null?void 0:i.retire)??[],p=(r==null?void 0:r.retiredCount)??(i==null?void 0:i.retireCount)??0,S=(c==null?void 0:c.unchangedCount)??0,T=((c==null?void 0:c.blocked.length)??0)+((c==null?void 0:c.skipped.length)??0),{cellLabel:C,humanizeWarning:v}=Cn(s);return e.jsx("section",{className:"border-b border-border bg-background px-4 py-4","aria-labelledby":"jc-publish-heading","data-testid":"jc-publish-preflight",children:e.jsxs("div",{className:"mx-auto max-w-4xl",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{id:"jc-publish-heading",className:"text-sm font-semibold",children:r?`Publication report · ${t.name}`:`Publish ${t.name}`}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Audience-wide. Withheld repairs keep their last live revision; explicit retirements leave the audience but keep their history."})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[!r&&e.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:n,disabled:l||o,title:"Refresh preflight","aria-label":"Refresh publication preflight",children:e.jsx($s,{className:`h-4 w-4 ${l?"animate-spin":""}`})}),e.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:h,disabled:o,title:"Close","aria-label":"Close publication preflight",children:e.jsx(rt,{className:"h-4 w-4"})})]})]}),l&&!c&&e.jsxs("p",{className:"mt-4 flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Ne,{className:"h-4 w-4 animate-spin"}),"Compiling the audience publication plan..."]}),a&&!c&&e.jsxs("p",{className:"mt-4 flex items-start gap-2 text-sm text-destructive",role:"alert",children:[e.jsx(St,{className:"mt-0.5 h-4 w-4 shrink-0"}),(d==null?void 0:d.message)??"Could not build publication preflight."]}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-3 sm:grid-cols-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:r?"Published":"Will publish"}),e.jsx("p",{className:"text-xl font-semibold",children:y})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Already current"}),e.jsx("p",{className:"text-xl font-semibold",children:S})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Withheld"}),e.jsx("p",{className:"text-xl font-semibold",children:T})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Retained stale"}),e.jsx("p",{className:"text-xl font-semibold",children:c.stale.length})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:r?"Retired":"Will retire"}),e.jsx("p",{className:"text-xl font-semibold",children:p})]})]}),T>0&&e.jsx(An,{blocked:c.blocked,skipped:c.skipped,stale:c.stale,cellLabel:C}),p>0&&e.jsx($n,{rows:f,cellLabel:C}),c.baseOnlyWarnings.length>0&&e.jsx("div",{className:"mt-3 space-y-1 text-xs text-amber-700",children:c.baseOnlyWarnings.map(O=>e.jsx("p",{title:O,children:v(O)},O))}),e.jsx("div",{className:"mt-4 flex justify-end",children:r?e.jsxs("p",{className:"flex items-center gap-2 text-sm text-emerald-700",children:[e.jsx(Qt,{className:"h-4 w-4"}),"Publication transaction completed."]}):e.jsxs(A,{type:"button",onClick:u,disabled:o||l,"data-testid":"jc-publish-confirm",children:[o?e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}):e.jsx(ai,{className:"mr-1 h-4 w-4"}),y>0&&p>0?`Publish ${y} and retire ${p}`:p>0?`Retire ${p} offer${p===1?"":"s"} now`:`Publish ${y} offer${y===1?"":"s"} now`]})})]})]})})}function ji(t){return t?t.length<=30&&/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(t)?null:"Use at most 30 lowercase letters, numbers, and single hyphens.":null}function kn({tierSlug:t,garments:s,cells:i,initialGarmentSlug:r,onCreated:l,onClose:a}){const{toast:d}=Pe(),o=x.useMemo(()=>s.filter(j=>j.isActive&&!j.parentSlug&&!j.hasActiveChildren&&!j.slug.startsWith("v1g-")),[s]),[n,u]=x.useState(""),[h,c]=x.useState(""),[y,f]=x.use
372State(!1),[p,S]=x.useState("What kind of garment is this?"),[T,C]=x.useState(r&&o.some(j=>j.slug===r)?[r]:[]),v=h.trim(),O=!!v&&s.some(j=>j.slug===v),P=ji(v),$=le({mutationFn:async()=>(await Me(ma,{tierSlug:t,categorySlug:v,categoryName:n.trim(),childQuestionText:p.trim(),childGarmentSlugs:T})).configV2GroupJourneyGarmentsIntoCategory,onSuccess:j=>{Le(Z,"catalog","attachments","draftStatus","compiledPreview"),d({title:`${j.children.length} garment${j.children.length===1?"":"s"} grouped`}),l(j)}}),b=!!(n.trim()&&v&&p.trim()&&T.length)&&!O&&!P;return e.jsx("section",{className:"border-y border-border bg-background p-4","data-testid":"jc-group-garments-form",children:e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(Yt,{className:"h-4 w-4"}),"Group garments into a category"]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Existing garments remain sellable leaves. Their repair IDs, audience membership, pricing, and published revisions are not copied or changed."})]}),e.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:a,title:"Close","aria-label":"Close category form",children:e.jsx(rt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-4 grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-category-name",children:"Category name"}),e.jsx(ee,{id:"jc-category-name",maxLength:100,value:n,onChange:j=>{u(j.target.value),y||c(bt(j.target.value).slice(0,30))}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-category-key",children:"Category key"}),e.jsx(ee,{id:"jc-category-key",maxLength:30,value:h,onChange:j=>{f(!0),c(j.target.value)}}),O&&e.jsx("p",{className:"text-sm text-destructive",role:"alert",children:"That garment key is already in use."}),P&&e.jsx("p",{className:"text-sm text-destructive",role:"alert",children:P})]})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-category-question",children:"Customer question"}),e.jsx(ee,{id:"jc-category-question",value:p,onChange:j=>S(j.target.value)})]}),e.jsxs("fieldset",{className:"mt-4 space-y-2",children:[e.jsx("legend",{className:"text-sm font-medium",children:"Garments to keep beneath this category"}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:o.map(j=>{const V=i.filter(D=>D.garmentSlug===j.slug).length,R=T.includes(j.slug);return e.jsxs("label",{className:"flex items-start gap-2 border border-border p-3 text-sm",children:[e.jsx(ri,{checked:R,onCheckedChange:D=>C(E=>D?[...E,j.slug]:E.filter(N=>N!==j.slug))}),e.jsxs("span",{children:[e.jsx("span",{className:"block font-medium",children:j.name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[V," repair",V===1?"":"s"," preserved"]})]})]},j.slug)})}),o.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No ungrouped leaf garments are available."})]}),e.jsxs(A,{type:"button",className:"mt-4 w-full",disabled:!b||$.isPending,onClick:()=>$.mutate(),"data-testid":"jc-save-category-group",children:[$.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),"Create category without moving repair facts"]}),e.jsx(He,{error:$.error,testId:"jc-category-group-error"})]})})}function qn({tierSlug:t,parent:s,garments:i,parentRepairCount:r,onCreated:l,onClose:a}){var v;const{toast:d}=Pe(),[o,n]=x.useState(""),[u,h]=x.useState(""),[c,y]=x.useState(!1),f=u.trim(),p=!!f&&i.some(O=>O.slug===f),S=ji(f),T=le({mutationFn:async()=>(await Me(ga,{tierSlug:t,parentSlug:s.slug,slug:f,name:o.trim()})).configV2CreateJourneySubtype,onSuccess:O=>{Le(Z,"catalog","attachments","draftStatus","compiledPreview"),d({title:"Subtype draft created"}),l(O)}}),C=!!(o.trim()&&f)&&!p&&!S;return e.jsx("section",{className:"border-y border-border bg-background p-4","data-testid":"jc-add-subtype-form",children:e.jsxs("div",{className:"mx-auto max-w-xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(Wt,{className:"h-4 w-4"}),"Add subtype to ",s.name]}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r>0?`The ${r} category template repair${r===1?"":"s"} will seed inactive, deny-all drafts. Scope, price, and activate each one before publishing.`:"This category has no template repairs. Add or fork repairs onto the new subtype after creating it."})]}),e.jsx(A,{type:"button",size:"icon",variant:"ghost",onClick:a,title:"Close","aria-label":"Close subtype form",children:e.jsx(rt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-subtype-name",children:"Subtype name"}),e.jsx(ee,{id:"jc-subtype-name",maxLength:100,value:o,onChange:O=>{n(O.target.value),c||h(bt(O.target.value).slice(0,30))}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ue,{htmlFor:"jc-subtype-key",children:"Subtype key"}),e.jsx(ee,{id:"jc-subtype-key",maxLength:30,value:u,onChange:O=>{y(!0),h(O.target.value)}}),p&&e.jsx("p",{className:"text-sm text-destructive",role:"alert",children:"That garment key is already in use."}),S&&e.jsx("p",{className:"text-sm text-destructive",role:"alert",children:S})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Customer prompt: ",((v=s.childQuestionText)==null?void 0:v.trim())||`What kind of ${s.name}?`]}),e.jsxs(A,{type:"button",className:"w-full",disabled:!C||T.isPending,onClick:()=>T.mutate(),"data-testid":"jc-save-subtype",children:[T.isPending&&e.jsx(Ne,{className:"mr-1 h-4 w-4 animate-spin"}),r>0?"Create subtype with inactive repair drafts":"Create subtype"]}),e.jsx(He,{error:T.error,testId:"jc-subtype-error"})]})]})})}function Tn({cell:t,tier:s,draftStatus:i,onSetActive:r,activationPending:l=!1}){var n;const a=!t.hasAudienceMembership||((n=t.audienceTierSlugs)==null?void 0:n.includes(s.slug))===!0,d=(i==null?void 0:i.status)==="ready",o=[{label:"Built",value:"Repair exists",complete:!0},{label:"Priced",value:i==null?"Not inspected":d?"Draft ready":"Needs pricing",complete:d,warning:(i==null?void 0:i.status)==="blocked"},{label:"Offered",value:a&&t.isActive?`${s.name}; active for members`:a?"Inactive for all audiences":"Not in audience",complete:a&&t.isActive},{label:"Published",value:(i==null?void 0:i.currentPublishedVersion)==null?"No revision":`v${i.currentPublishedVersion}`,complete:(i==null?void 0:i.currentPublishedVersion)!=null&&i.matchesCurrentPublication,warning:(i==null?void 0:i.currentPublishedVersion)!=null&&!i.matchesCurrentPublication}];return e.jsx("div",{className:"grid min-h-20 grid-cols-2 border-b border-border bg-muted/30 lg:grid-cols-4","data-testid":"jc-lifecycle-rail",children:o.map((u,h)=>{const c=u.warning?St:u.complete?Qt:h===3?di:Ji;return e.jsxs("div",{className:"flex min-w-0 items-center gap-2 border-b border-r border-border px-3 py-3 last:border-r-0 lg:border-b-0",children:[e.jsx(c,{className:`h-4 w-4 shrink-0 ${u.warning?"text-amber-600":u.complete?"text-emerald-700":"text-muted-foreground"}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium uppercase text-muted-foreground",children:u.label}),e.jsx("p",{className:"truncate text-sm font-medium",title:u.value,children:u.value})]}),u.label==="Offered"&&r&&e.jsx(_e,{className:"ml-auto shrink-0",checked:t.isActive,disabled:!a||l,onCheckedChange:r,title:a?"Cell-wide activation across its member audiences":`Add this repair to ${s.name} before changing activation`,"aria-label":t.isActive?"Deactivate repair path":"Activate repair path","data-testid":"jc-cell-active"})]},u.label)})})}function ft(t){return`${t.attachmentType}:${t.attachmentId}`}function In(t){return t.conditional?t.groups.map(i=>
372{const r=i.acceptedValues.map(l=>l.label).join(" or ");return`${i.parentLabel}: ${r||"no available choices"}`}).join(t.combinator==="all"?" and ":" or "):null}function Vn(t){const s={unexpected_scoped_attribute:"repair scope references an unavailable garment question",missing_selection:"choose the required garment answer",inactive_hidden_or_missing_selection:"the selected garment answer is unavailable",no_matching_scope_row:"the current garment answers do not offer this repair"},i=t.map(r=>s[r]).filter(r=>!!r);return i.length>0?i.join("; "):"the current garment answers do not offer this repair"}function Cs({testId:t}){return e.jsx("span",{role:"img","aria-label":"Unsaved pricing edit",title:"Unsaved pricing edit â save or discard it in the Inspector",className:"inline-block h-2 w-2 shrink-0 rounded-full bg-amber-500","data-testid":t})}function Rn({projection:t,garmentSlug:s,lens:i,selection:r,forkValueIds:l,pricingDraft:a,pricingDirtyKeys:d,onSelect:o,onInspect:n,onAddFollowUp:u,onSetValueAvailable:h,compiledQuestion:c,dragHandle:y}){const{question:f,dependency:p,duplicateLabels:S}=t,T=i==="pricing"&&(d==null?void 0:d.has(`${f.attachmentType}:${f.attachmentId}`))===!0,C=In(p),v=(c==null?void 0:c.label)??at(f.attribute),O=(c==null?void 0:c.helpText)??f.attribute.helpText,P=f.attribute.values.filter(b=>b.isActive&&(i==="availability"||!mt(b,s))),$=b=>a==null?void 0:a.effects.find(j=>j.subjectType===f.attachmentType&&j.subjectAttachmentId===f.attachmentId&&j.effectKind==="selected_value"&&j.attributeValueId===b.id);return e.jsxs("section",{className:"rounded-md border border-border bg-background p-4","data-testid":`jc-question-${f.attachmentType}-${f.attachmentId}`,onClick:()=>n({kind:"question",projection:t}),children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-sm font-semibold",children:v}),e.jsx(me,{variant:"outline",children:Vs(f.attribute)}),((c==null?void 0:c.required)??f.isRequired)&&e.jsx(me,{variant:"secondary",children:"Required"}),T&&e.jsx(Cs,{testId:`jc-pricing-dirty-${f.attachmentType}-${f.attachmentId}`})]}),(c==null?void 0:c.summaryLabel)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Summary: ",c.summaryLabel]}),O&&e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:O})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[((c==null?void 0:c.imageUrl)??f.attribute.imageUrl)&&e.jsx("img",{src:(c==null?void 0:c.imageUrl)??f.attribute.imageUrl??"",alt:"",className:"h-12 w-12 rounded-sm border border-border object-cover"}),y]})]}),C&&e.jsxs("div",{className:"mt-3 flex items-start gap-2 border-l-2 border-amber-500 pl-3 text-xs text-muted-foreground",children:[e.jsx(qt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsxs("span",{children:["Only after ",C]})]}),p.blocked&&e.jsxs("div",{className:"mt-3 flex items-start gap-2 text-xs text-destructive",children:[e.jsx(St,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{children:"This condition cannot resolve in the selected audience and repair."})]}),S.map(b=>e.jsxs("div",{className:"mt-3 flex items-center gap-2 text-xs text-amber-700","data-testid":"jc-duplicate-label-warning",children:[e.jsx(St,{className:"h-3.5 w-3.5"}),b.label," appears ",b.valueIds.length," times in this question."]},b.label)),i==="availability"&&h&&e.jsx("p",{className:"mt-3 border-l-2 border-amber-500 pl-3 text-xs font-medium text-amber-700","data-testid":"jc-availability-scope-garment",children:"Answer availability below is garment-wide: switching an answer off hides it for every repair and every audience on this garment."}),f.attribute.type==="quantity"?e.jsx(ee,{className:"mt-4 max-w-32",type:"number",min:1,disabled:p.blocked,value:(r==null?void 0:r.quantity)??"","aria-label":v,"data-testid":`jc-answer-${f.attachmentType}-${f.attachmentId}-quantity`,onClick:b=>b.stopPropagation(),onChange:b=>o({attachmentType:f.attachmentType,attachmentId:f.attachmentId,quantity:b.target.value?Number(b.target.value):null})}):f.attribute.type==="text"||f.attribute.type==="text_input"?e.jsx(ee,{className:"mt-4",disabled:p.blocked,value:(r==null?void 0:r.textValue)??"","aria-label":v,"data-testid":`jc-answer-${f.attachmentType}-${f.attachmentId}-text`,onClick:b=>b.stopPropagation(),onChange:b=>o({attachmentType:f.attachmentType,attachmentId:f.attachmentId,textValue:b.target.value})}):e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:P.map(b=>{const j=(r==null?void 0:r.valueId)===b.id,V=$(b),R=!mt(b,s),D=c==null?void 0:c.values.find(m=>m.id===b.id),N=P.filter(m=>m.label===b.label).length>1?b.value:null;return e.jsxs("div",{className:"flex items-stretch gap-1",children:[e.jsxs(A,{type:"button",size:"sm",disabled:p.blocked||!R,variant:j?"default":"outline",className:"h-auto min-h-9 whitespace-normal py-2",onClick:m=>{m.stopPropagation(),o({attachmentType:f.attachmentType,attachmentId:f.attachmentId,valueId:b.id}),n({kind:"value",projection:t,value:b})},"data-testid":`jc-answer-${f.attachmentType}-${f.attachmentId}-${b.id}`,children:[((D==null?void 0:D.imageUrl)??b.imageUrl)&&e.jsx("img",{src:(D==null?void 0:D.imageUrl)??b.imageUrl??"",alt:"",className:"mr-1.5 h-8 w-8 rounded-sm border border-current/20 object-cover"}),e.jsx("span",{children:(D==null?void 0:D.label)??b.label}),N&&e.jsxs("span",{className:"ml-1.5 text-xs opacity-70","data-testid":`jc-value-disambiguator-${b.id}`,children:["(",N,")"]}),l.has(b.id)&&e.jsx(qt,{className:"ml-1.5 h-3.5 w-3.5","aria-label":"Opens a follow-up"}),i==="pricing"&&V&&(V.priceDeltaCents!==0||V.minutesDelta!==0||V.requiresQuote)&&e.jsxs("span",{className:"ml-1.5 text-xs opacity-80",children:[V.priceDeltaCents?`${V.priceDeltaCents>0?"+":""}${cs(V.priceDeltaCents)}`:"",V.minutesDelta?` ${V.minutesDelta>0?"+":""}${V.minutesDelta}m`:"",V.requiresQuote?" Quote":""]}),i==="pricing"&&(d==null?void 0:d.has(`${f.attachmentType}:${f.attachmentId}:${b.id}`))&&e.jsx("span",{className:"ml-1.5 flex items-center",children:e.jsx(Cs,{testId:`jc-pricing-dirty-value-${b.id}`})})]}),i==="availability"&&h&&e.jsx(_e,{className:"my-auto ml-1",checked:R,disabled:R&&P.filter(m=>!mt(m,s)).length===1,onCheckedChange:m=>h(t,b,m),"aria-label":`${b.label}${N?` (${N})`:""} available for ${s}`,title:"Garment-wide: affects every repair and every audience on this garment","data-testid":`jc-value-available-${b.id}`}),u&&f.attachmentType==="service"&&e.jsx(A,{type:"button",size:"icon",variant:"ghost",className:"h-auto min-h-9 w-8",disabled:p.blocked,onClick:m=>{m.stopPropagation(),u({parentServiceAttributeId:f.attachmentId,parentValueId:b.id,questionLabel:at(f.attribute),valueLabel:b.label})},title:`Add follow-up after ${b.label}`,"aria-label":`Add follow-up after ${b.label}`,"data-testid":`jc-add-follow-up-${b.id}`,children:e.jsx(qt,{className:"h-4 w-4"})})]},b.id)})}),(r==null?void 0:r.valueId)!=null&&(()=>{const b=c==null?void 0:c.values.find(j=>j.id===r.valueId);return!b||!b.description&&!b.disclaimerText?null:e.jsxs("div",{className:"mt-3 border-l-2 border-border pl-3 text-sm text-muted-foreground","data-testid":`jc-selected-value-content-${b.id}`,children:[b.description&&e.jsx("p",{children:b.description}),b.disclaimerText&&e.jsx("p",{className:"mt-1",children:b.disclaimerText}),b.disclaimerText&&b.disclaimerRequiresAck&&e.jsx(me,{variant:"outline",className:"mt-2",children:"Acknowledgement required"})]})})(),i==="availability"&&e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:f.attribute.values.length>0?"Choice availability is garment-wide across every repair and audience. At least one choice must remain available.":f.attachmentType==="garment"?"Asked before every repair on this garment.":"Asked for this repair in the selected audience."})]})}function Hs({sortableId:t,reorderEnabled:s,onMoveEarlier:i,onMoveLater:r,...l}){return e.jsx(Rn,{...l,dragHandle:s?e.jsxs("div",{className:"flex items-center",onClick:a=>a.stopPropagation(),children:[e.jsx(A,{type:"button",variant:"ghost",size:"icon",disabled:!i,onClick:i,title:"Move question earlier","aria-label":"Move question earlier","data-testid":`jc-move-question-earlier-${t}`,children:e.jsx(ni,{className:"h-4 w-4"})}),e.jsx(A,{type:"button",variant:"ghost",size:"icon",disabled:!r,onClick:r,title:"Move question later","aria-label":"Move question later","data-testid":`jc-move-question-later-${t}`,children:e.jsx(ls,{className:"h-4 w-4"})})]}):void 0})}function En({garmentSlug:t,serviceLabel:s,projections:i,selections:r,forkValueIds:l,repairAvailable:a,onSelect:d}){const o=new Map(r.map(f=>[ft(f),f])),n=i.filter(f=>{const{question:p}=f;return p.attribute.type==="descriptor"||p.attribute.values.some(S=>l.has(S.id))}),u=f=>{const p=o.get(ft(f.question));return f.question.attribute.values.find(S=>S.id===(p==null?void 0:p.valueId))},h=n.filter(f=>f.question.attachmentType==="garment").flatMap(f=>{var p;return((p=u(f))==null?void 0:p.label)??[]}),c=n.filter(f=>f.question.attachmentType==="service").flatMap(f=>{var p;return((p=u(f))==null?void 0:p.label)??[]}),y=[...h,a?s:"Choose repair",...c];return e.jsxs("nav",{className:"border-b border-border bg-background px-3 py-3","aria-label":"Current journey lane","data-testid":"jc-lane-trail",children:[e.jsxs("p",{className:"truncate text-xs text-muted-foreground",title:y.join(" > "),children:[e.jsx("span",{className:"font-medium text-foreground",children:"Walking:"})," ",y.join(" > ")]}),n.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:n.map(f=>{const{question:p}=f,S=o.get(ft(p)),T=p.attribute.values.filter(C=>C.isActive&&!mt(C,t));return e.jsxs("div",{className:"min-w-44 max-w-full",children:[e.jsx("p",{className:"mb-1 text-xs text-muted-foreground",children:at(p.attribute)}),e.jsxs(fe,{value:(S==null?void 0:S.valueId)==null?void 0:String(S.valueId),onValueChange:C=>d({attachmentType:p.attachmentType,attachmentId:p.attachmentId,valueId:Number(C)}),children:[e.jsx(be,{className:"h-9","aria-label":`Switch ${at(p.attribute)} lane`,children:e.jsx(ye,{placeholder:"Choose branch"})}),e.jsx(Se,{children:T.map(C=>e.jsx(se,{value:String(C.id),children:C.label},C.id))})]})]},ft(p))})})]})}function On({tier:t,garment:s,menuProjections:i,menuAvailabilityStatus:r,selectedCell:l,services:a,projections:d,selections:o,preview:n,draftStatus:u,pricingDraft:h,pricingDirtyKeys:c,lens:y,onSelectCell:f,onSelectAnswer:p,onInspect:S,onAddPreServiceQuestion:T,preServiceComposer:C,onAddQuestion:v,onAddFollowUp:O,composer:P,onAddRepair:$,repairComposer:b,onSetCellActive:j,activationPending:V,onSetCellMembership:R,onSetValueAvailable:D,onSetDescriptorScope:E,descriptorScopeMutation:N,onReorderQuestions:m,reorderError:G}){var k,_,z,re,ae;const X=new Map(a.map(K=>[K.slug,K])),ce=X.get(l.serviceSlug),de=new Map(o.map(K=>[ft(K),K])),De=(n==null?void 0:n.status)==="ready"?new Set(n.questions.map(K=>`${K.attachmentType}:${K.attachmentId}`)):null,ge=d.filter(K=>y==="availability"||!K.dependency.blocked&&(De?De.has(ft(K.question)):on(K,o))),qe=ge.filter(K=>K.question.attachmentType==="garment"),Te=i.find(K=>
372K.cell.id===l.id),Ce=r==="ready"&&(Te==null?void 0:Te.isAllowed)===!0,Fe=Ce?ge.filter(K=>K.question.attachmentType==="service"):[],ke=new Set(d.flatMap(K=>K.dependency.groups.flatMap(q=>q.acceptedValues.flatMap(F=>F.id==null?[]:[F.id])))),M=i.filter(K=>y==="availability"||K.isAllowed),ue=new Map;for(const K of M){const q=((_=(k=X.get(K.cell.serviceSlug))==null?void 0:k.serviceGroup)==null?void 0:_.trim())||"Repairs";ue.set(q,[...ue.get(q)??[],K])}const ie=qe.flatMap(K=>{if(K.question.attribute.type!=="descriptor")return[];const q=de.get(ft(K.question)),F=K.question.attribute.values.find(H=>H.id===(q==null?void 0:q.valueId));return F?[F.label]:[]});return e.jsxs("main",{className:"min-w-0 bg-muted/10","data-testid":"jc-walk",children:[e.jsx(Tn,{cell:l,tier:t,draftStatus:u,onSetActive:j,activationPending:V}),e.jsx(En,{garmentSlug:s.slug,serviceLabel:(ce==null?void 0:ce.name)??l.serviceName??l.serviceSlug,projections:ge,selections:o,forkValueIds:ke,repairAvailable:Ce,onSelect:p}),e.jsxs("div",{className:"mx-auto max-w-3xl space-y-4 p-4 lg:p-6",children:[G&&e.jsx("p",{className:"border-l-2 border-destructive py-2 pl-3 text-sm text-destructive",role:"alert","data-testid":"jc-reorder-error",children:G}),y==="availability"&&m&&e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"jc-order-scope",children:"Question order is shared everywhere; which audiences ask a question is managed separately."}),e.jsxs("section",{className:"flex min-h-24 items-center gap-4 border-b border-border pb-4",onClick:()=>S({kind:"garment",garment:s}),"data-testid":"jc-garment-moment",children:[s.imageUrl?e.jsx("img",{src:s.imageUrl,alt:"",className:"h-20 w-20 rounded-sm border border-border object-cover"}):e.jsx("div",{className:"flex h-20 w-20 items-center justify-center rounded-sm border border-dashed border-border text-muted-foreground",children:e.jsx(ks,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium uppercase text-muted-foreground",children:"Garment"}),e.jsx("h2",{className:"text-xl font-semibold",children:s.name})]})]}),e.jsx("div",{className:"space-y-4",children:qe.map((K,q)=>e.jsx(Hs,{sortableId:K.question.attachmentId,reorderEnabled:y==="availability"&&!!m,projection:K,garmentSlug:s.slug,lens:y,selection:de.get(ft(K.question)),forkValueIds:ke,pricingDraft:h,pricingDirtyKeys:c,onSelect:p,onInspect:S,onSetValueAvailable:D,compiledQuestion:n==null?void 0:n.questions.find(F=>F.attachmentType===K.question.attachmentType&&F.attachmentId===K.question.attachmentId),onMoveEarlier:q===0?void 0:()=>m==null?void 0:m("garment",K.question.attachmentId,qe[q-1].question.attachmentId),onMoveLater:q===qe.length-1?void 0:()=>m==null?void 0:m("garment",K.question.attachmentId,qe[q+1].question.attachmentId)},ft(K.question)))}),C,T&&!C&&e.jsxs(A,{type:"button",variant:"outline",className:"w-full border-dashed",onClick:T,"data-testid":"jc-add-pre-service-question",children:[e.jsx(Qe,{className:"mr-1.5 h-4 w-4"}),"Add pre-repair question"]}),e.jsx(ls,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsxs("section",{className:"rounded-md border border-border bg-background","data-testid":"jc-repair-menu",children:[e.jsxs("div",{className:"border-b border-border px-4 py-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium uppercase text-muted-foreground",children:"Repair menu"}),e.jsx("h3",{className:"text-sm font-semibold",children:"Choose a repair"})]}),$&&!b&&e.jsxs(A,{type:"button",size:"sm",variant:"outline",onClick:$,"data-testid":"jc-add-repair",children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"Add repair"]})]}),ie.length>0&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground","data-testid":"jc-menu-descriptor-context",children:["Showing repairs offered for: ",ie.join(" + ")]})]}),b,Array.from(ue.entries()).map(([K,q])=>e.jsxs("div",{className:"border-b border-border p-3 last:border-b-0",children:[e.jsx("p",{className:"mb-2 text-xs font-medium text-muted-foreground",children:K}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:q.map(({cell:F,isAllowed:H,scopeAttributeSlugs:W,scopeValueSlugs:xe,reasonCodes:J})=>{var Ye;const $e=X.get(F.serviceSlug),oe=!F.hasAudienceMembership||((Ye=F.audienceTierSlugs)==null?void 0:Ye.includes(t.slug))===!0;return e.jsxs("div",{className:"rounded-md border border-border bg-background",children:[e.jsxs("div",{className:"flex items-stretch gap-1 p-1",children:[e.jsxs("button",{type:"button",className:`flex min-h-12 min-w-0 flex-1 items-center gap-2 rounded-sm px-2 py-1 text-left ${F.id===l.id?"bg-muted":"hover:bg-muted/50"} ${H?"":"opacity-70"}`,onClick:()=>{f(F.id),S({kind:"repair",cell:F,service:$e})},"data-testid":`jc-repair-${F.id}`,children:[e.jsx(Zt,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:($e==null?void 0:$e.name)??F.serviceName??F.serviceSlug}),y==="availability"&&e.jsx("span",{className:"block text-xs text-muted-foreground",children:oe?H?W.length>0?`Offered through ${W.join(", ")}`:F.hasAudienceMembership?F.isActive?`Offered in ${t.name}
372 â this audience only`:"Inactive draft":"Offered in every audience (unscoped)":`Withheld: ${Vn(J)}`:`Not offered in ${t.name} â this audience only`})]})]}),y==="availability"&&R&&e.jsx(_e,{className:"my-auto mr-2",checked:oe,onCheckedChange:g=>R(F,g),"aria-label":`${($e==null?void 0:$e.name)??F.serviceSlug} offered in ${t.name}`,title:F.hasAudienceMembership?`Membership in ${t.name}`:"Universal membership: changing this replaces the all-audiences scope","data-testid":`jc-cell-member-${F.id}`})]}),y==="availability"&&E&&qe.filter(g=>g.question.attribute.type==="descriptor").map(g=>{const B=g.question.attribute,ze=B.values.filter(Ve=>Ve.isActive&&!mt(Ve,s.slug)),Ke=xe[B.slug]??[],ve=new Set(Ke.length>0?Ke:ze.map(Ve=>Ve.value)),Oe=`${F.id}:${B.slug}`,Ae=(N==null?void 0:N.targetKey)===Oe;return e.jsxs("div",{className:"border-t border-border px-3 py-2",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Which ",at(B)," answers offer this repair ·"," ",e.jsx("span",{className:"font-medium text-amber-700",children:"applies to every audience"})," · at least one answer must remain"]}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-2",children:ze.map(Ve=>{const yt=ve.has(Ve.value);return e.jsxs("label",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx(_e,{checked:yt,disabled:(N==null?void 0:N.pending)||yt&&ve.size===1,onCheckedChange:I=>{const te=new Set(ve);I?te.add(Ve.value):te.delete(Ve.value),E(F,B.slug,Array.from(te))},"aria-label":`${Ve.label} offers ${($e==null?void 0:$e.name)??F.serviceSlug}`,title:N!=null&&N.pending?"Wait for the current repair-availability save to finish":yt&&ve.size===1?"At least one answer must continue to offer this repair":void 0,"data-testid":`jc-descriptor-scope-${F.id}-${B.slug}-${Ve.id}`}),Ve.label]},Ve.id)})}),Ae&&(N==null?void 0:N.pending)&&e.jsxs("p",{className:"mt-2 flex items-center gap-1.5 text-xs text-muted-foreground","data-testid":"jc-descriptor-scope-saving",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 animate-spin"}),"Saving repair availability"]}),Ae&&(N==null?void 0:N.error)&&!N.pending&&e.jsx("p",{className:"mt-2 text-xs text-destructive",role:"alert","data-testid":"jc-descriptor-scope-error",children:N.error})]},B.slug)})]},F.id)})})]},K)),M.length===0&&e.jsx("p",{className:"p-5 text-sm text-muted-foreground","data-testid":"jc-repair-menu-empty",children:r==="loading"?"Loading repair availability...":r==="error"?"Repair availability could not be loaded.":"Choose the garment questions above to reveal available repairs."})]}),Ce?e.jsxs(e.Fragment,{children:[e.jsx(ls,{className:"mx-auto h-5 w-5 text-muted-foreground"}),(n==null?void 0:n.status)==="ready"&&e.jsxs("section",{className:"flex items-start gap-4 border-b border-border pb-4","data-testid":"jc-selected-repair-content",children:[n.serviceImageUrl&&e.jsx("img",{src:n.serviceImageUrl,alt:n.serviceLabel??"Repair",className:"h-20 w-20 shrink-0 rounded-sm border border-border object-cover"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"text-base font-semibold",children:n.serviceLabel}),n.serviceDescription&&e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:n.serviceDescription}),n.serviceGroup&&e.jsx(me,{variant:"secondary",className:"mt-2",children:n.serviceGroup}),n.serviceDisclaimerText&&e.jsxs("div",{className:"mt-3 border-l-2 border-border pl-3 text-sm text-muted-foreground",children:[e.jsx("p",{children:n.serviceDisclaimerText}),n.serviceDisclaimerRequiresAck&&e.jsx(me,{variant:"outline",className:"mt-2",children:"Acknowledgement required"})]})]})]}),e.jsx("div",{className:"space-y-4",children:Fe.map((K,q)=>{var F;return e.jsxs(x.Fragment,{children:[e.jsx(Hs,{sortableId:K.question.attachmentId,reorderEnabled:y==="availability"&&!!m,projection:K,garmentSlug:s.slug,lens:y,selection:de.get(ft(K.question)),forkValueIds:ke,pricingDraft:h,pricingDirtyKeys:c,onSelect:p,onInspect:S,onAddFollowUp:O,onSetValueAvailable:D,compiledQuestion:n==null?void 0:n.questions.find(H=>H.attachmentType===K.question.attachmentType&&H.attachmentId===K.question.attachmentId),onMoveEarlier:q===0?void 0:()=>m==null?void 0:m("service",K.question.attachmentId,Fe[q-1].question.attachmentId),onMoveLater:q===Fe.length-1?void 0:()=>m==null?void 0:m("service",K.question.attachmentId,Fe[q+1].question.attachmentId)}),((F=P==null?void 0:P.followUp)==null?void 0:F.parentServiceAttributeId)===K.question.attachmentId&&P.content]},ft(K.question))})}),P&&!P.followUp&&P.content,v&&!P&&e.jsxs(A,{type:"button",variant:"outline",className:"w-full border-dashed",onClick:v,"data-testid":"jc-add-question",children:[e.jsx(Qe,{className:"mr-1.5 h-4 w-4"}),"Add question"]}),e.jsxs("section",{className:"cursor-pointer rounded-md border border-border bg-background p-4","data-testid":"jc-price-moment",onClick:()=>S(y==="pricing"?{kind:"pricing",cell:l,service:ce}:{kind:"repair",cell:l,service:ce}),children:[e.jsxs("p",{className:"flex items-center gap-2 text-xs font-medium uppercase text-muted-foreground",children:["Resolved repair",y==="pricing"&&(c==null?void 0:c.has("base"))&&e.jsx(Cs,{testId:"jc-pricing-dirty-base"})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold",children:(n==null?void 0:n.serviceLabel)??(ce==null?void 0:ce.name)??l.serviceName??l.serviceSlug}),y==="content"&&((n==null?void 0:n.serviceDescription)??(ce==null?void 0:ce.description))&&e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:(n==null?void 0:n.serviceDescription)??(ce==null?void 0:ce.description)})]}),e.jsx("p",{className:"text-lg font-semibold",children:((z=n==null?void 0:n.resolution)==null?void 0:z.status)==="resolved"?n.resolution.requiresQuote?"Quote":cs(n.resolution.priceCents??0):((re=n==null?void 0:n.resolution)==null?void 0:re.message)??(n==null?void 0:n.reason)??"Choose answers to resolve"})]}),((ae=n==null?void 0:n.resolution)==null?void 0:ae.minutes)!=null&&e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:[n.resolution.minutes," minutes"]}),u==null?void 0:u.publicationBlockers.map(K=>e.jsx("p",{className:"mt-2 text-sm text-destructive",children:K},K))]})]}):e.jsx("p",{className:"border-l-2 border-amber-500 py-2 pl-3 text-sm text-muted-foreground",children:"The focused repair is not offered for the current garment answers. Choose an available repair above."})]})]})}const Ys={sets:[],groups:[],values:[]};function bs(t){return`${t.attachmentType}:${t.attachmentId}`}function Pn(){var Os,Ps,Ds,Ms,Fs,Gs;const{user:t}=Ni(),s=(t==null?void 0:t.role)==="superuser",{toast:i}=Pe(),r=Ga(),l=r.data,a=x.useMemo(()=>((l==null?void 0:l.configV2Tiers)??[]).filter(w=>w.isActive),[l]),[d,o]=x.useState(null),[n,u]=x.useState(null),[h,c]=x.useState(null),[y,f]=x.use
372State("content"),[p,S]=x.useState("author"),[T,C]=x.useState(""),[v,O]=x.useState([]),[P,$]=x.useState(null),[b,j]=x.useState(!1),[V,R]=x.useState(!1),[D,E]=x.useState(null),[N,m]=x.useState(!1),[G,X]=x.useState(null),[ce,de]=x.useState(null),[De,ge]=x.useState(!1),[qe,Te]=x.useState(null),[Ce,Fe]=x.useState(null),[ke,M]=x.useState(!1),[ue,ie]=x.useState(!1),[k,_]=x.useState(null);x.useEffect(()=>{const w=window.matchMedia("(max-width: 1535px)"),je=()=>{R(w.matches),w.matches||j(!1)};return w.addEventListener("change",je),je(),()=>w.removeEventListener("change",je)},[]);const z=d&&a.some(w=>w.slug===d)?d:((Os=a.find(w=>w.slug==="direct"))==null?void 0:Os.slug)??((Ps=a[0])==null?void 0:Ps.slug)??null,re=x.useMemo(()=>l&&z?sn(l,z):null,[l,z]),ae=re==null?void 0:re.tier,K=(re==null?void 0:re.garments)??[],q=n&&K.some(w=>w.slug===n)?n:((Ds=K[0])==null?void 0:Ds.slug)??null,F=K.find(w=>w.slug===q),H=x.useMemo(()=>((re==null?void 0:re.cells)??[]).filter(w=>w.garmentSlug===q),[re==null?void 0:re.cells,q]),W=h!=null?H.find(w=>w.id===h)??H[0]:H[0],xe=(ae==null?void 0:ae.journeyAuthoringAllowed)!==!0,J=xe||p==="walk",$e=w=>{$(w),V&&j(!0)},oe=Qa({tierSlug:z,garmentSlug:q,serviceSlug:W==null?void 0:W.serviceSlug,enabled:!!(z&&q&&W)}),Ye=Ua({enabled:!!z}),g=La({tierSlug:z,enabled:!!z}),B=za({enabled:!!z}),ze=Ka({tierSlug:z,garmentServiceId:W==null?void 0:W.id,enabled:!!(z&&W&&!xe)}),Ke=Ba({tierSlug:z,garmentServiceId:W==null?void 0:W.id,selections:v,enabled:!!(z&&W&&!xe)}),ve=Wa({tierSlug:z,garmentServiceId:W==null?void 0:W.id,enabled:!!(z&&W&&!xe)}),Oe=Ja({tierSlug:z,enabled:!!(z&&!xe&&(ke||ue&&(ae==null?void 0:ae.isPublicConfigurator)!==!0))}),Ae=le({mutationFn:w=>Me(xa,w),onSuccess:()=>{Le(Z,"catalog","draftStatus","compiledPreview"),i({title:"Repair activation updated"})},onError:w=>i({title:"Could not update activation",description:w.message,variant:"destructive"})}),Ve=le({mutationFn:w=>Me(da,w),onSuccess:()=>{Le(Z,"catalog","draftStatus","compiledPreview"),i({title:"Audience membership updated"})},onError:w=>i({title:"Could not update audience membership",description:w.message,variant:"destructive"})}),yt=le({mutationFn:w=>Me(Ca,w),onSuccess:()=>{Le(Z,"catalog","draftStatus","compiledPreview","descriptorScopes"),i({title:"Choice availability updated"})},onError:w=>i({title:"Could not update choice availability",description:w.message,variant:"destructive"})}),I=le({mutationFn:w=>Me(Aa,w),onMutate:w=>{Fe(`${w.garmentServiceId}:${w.attributeSlug}`)},onSuccess:async()=>{await Promise.all([Z.invalidateQueries({queryKey:Je.descriptorScopesRoot}),Z.invalidateQueries({queryKey:Je.draftStatusRoot}),Z.invalidateQueries({queryKey:Je.compiledPreviewRoot})]),Fe(null),i({title:"Repair availability updated"})},onError:w=>i({title:"Could not update repair availability",description:w.message,variant:"destructive"})}),te=le({mutationFn:w=>Me(qa,w),onMutate:()=>Te(null),onSuccess:()=>{Le(Z,"attachments","draftStatus","compiledPreview"),i({title:"Question order saved"})},onError:w=>{Te(w.message),i({title:"Could not reorder questions",description:w.message,variant:"destructive"})}}),Y=le({mutationFn:w=>Me(Ta,w),onMutate:()=>Te(null),onSuccess:()=>{Le(Z,"attachments","draftStatus","compiledPreview"),i({title:"Question order saved"})},onError:w=>{Te(w.message),i({title:"Could not reorder questions",description:w.message,variant:"destructive"})}}),he=le({mutationFn:async()=>{var Ee;const w=(Ee=Oe.data)==null?void 0:Ee.fingerprint;if(!w)throw new Error("Review the publication preflight before publishing.");return(await Me(la,{tierSlug:z,expectedFingerprint:w})).configV2PublishTier},onSuccess:w=>{_(w),Le(Z,"draftStatus","publicationPreflight");const je=`Published ${w.publishedCount} revision${w.publishedCount===1?"":"s"}`,Ee=`retired ${w.retiredCount} offer${w.retiredCount===1?"":"s"}`;i({title:w.retiredCount>0?`${je}; ${Ee}`:je})},onError:w=>{_(null),Oe.refetch(),i({title:"Could not publish audience",description:w.message,variant:"destructive"})}}),pe=le({mutationFn:async w=>{var Ge;if(!z)throw new Error("Choose an audience first.");const je=w?((Ge=Oe.data)==null?void 0:Ge.fingerprint)??null:null;if(w&&!je)throw new Error("Review the current promotion preflight before making this audie
372nce public.");return(await Me(ca,{tierSlug:z,isPublicDefault:w,expectedFingerprint:je})).configV2SetJourneyPublicDefault},onSuccess:w=>{ie(!1),Le(Z,"catalog","publicationPreflight"),i({title:w.tier.isPublicConfigurator?`${w.tier.name} is now the public default`:"Public repair routing returned to V1"})},onError:w=>{(ae==null?void 0:ae.isPublicConfigurator)!==!0&&Oe.refetch(),i({title:"Could not change public routing",description:w.message,variant:"destructive"})}}),we=Oe.data,Re=((we==null?void 0:we.blocked.length)??0)+((we==null?void 0:we.skipped.length)??0),ut=!!(we&&we.publishCount===0&&we.unchangedCount>0&&Re===0&&we.stale.length===0&&we.retireCount===0),gt=x.useMemo(()=>!l||!oe.data||!z||!q||!W?[]:pi({catalog:l,attachments:oe.data,tierSlug:z,garmentSlug:q,serviceSlug:W.serviceSlug}),[oe.data,l,q,W,z]),Gt=x.useMemo(()=>!z||!q||!W?[]:vi({questions:gt,garmentSlug:q,tierSlug:z,garmentServiceId:W.id,legacyDependencies:g.data??[],snapshot:Ye.data??Ys}),[Ye.data,q,g.data,gt,W,z]),Nt=x.useMemo(()=>!q||!B.data?[]:rn({cells:H,garmentSlug:q,questions:gt,selections:v,scopes:B.data??[]}),[H,B.data,q,gt,v]),hs=B.isError?"error":B.data?"ready":"loading",[fi,bi]=x.useState(new Set),Rs=x.useCallback(w=>{bi(je=>je.size===w.length&&w.every(Ee=>je.has(Ee))?je:new Set(w))},[]),Es=x.useMemo(()=>{if(!(!l||!oe.data||!z||!q||!W))return{tierSlug:z,garmentServiceId:W.id,garmentSlug:q,isReadOnly:J,lens:y,catalog:l,attachments:oe.data,questions:gt,dependencySnapshot:Ye.data??Ys,legacyDependencies:g.data??[],pricingDraft:ve.data,compiledPreview:Ke.data,onNavigateToCell:(w,je)=>{u(w),c(je)},onPricingDirtyChange:Rs}},[oe.data,l,Ye.data,q,Rs,J,g.data,y,ve.data,Ke.data,gt,W,z]);x.useEffect(()=>{if(hs!=="ready"||oe.isFetching||B.isFetching||!W||Nt.some(je=>je.cell.id===W.id&&je.isAllowed))return;const w=Nt.find(je=>je.isAllowed);w&&c(w.cell.id)},[oe.isFetching,B.isFetching,hs,Nt,W]),x.useEffect(()=>{O([]),$(null),E(null),m(!1),X(null),de(null),Te(null),M(!1),_(null)},[q,z]),x.useEffect(()=>{O(w=>w.filter(je=>je.attachmentType==="garment")),$(null),E(null),m(!1),X(null),Te(null)},[W==null?void 0:W.id]),x.useEffect(()=>{$(w=>{if(!w||!l)return w;if(w.kind==="garment"){const Ge=l.configV2Garments.find(Be=>Be.slug===w.garment.slug);return!Ge||Ge===w.garment?w:{kind:"garment",garment:Ge}}if(w.kind==="repair"||w.kind==="pricing"){const Ge=re==null?void 0:re.cells.find(Ze=>Ze.id===w.cell.id);if(!Ge)return null;const Be=l.configV2Services.find(Ze=>Ze.slug===Ge.serviceSlug);return Ge===w.cell&&Be===w.service?w:{kind:w.kind,cell:Ge,service:Be}}const je=Gt.find(Ge=>Ge.question.attachmentType===w.projection.question.attachmentType&&Ge.question.attachmentId===w.projection.question.attachmentId);if(!je)return null;if(w.kind==="question")return je===w.projection?w:{kind:"question",projection:je};const Ee=je.question.attribute.values.find(Ge=>Ge.id===w.value.id);return Ee?je===w.projection&&Ee===w.value?w:{kind:"value",projection:je,value:Ee}:null})},[re==null?void 0:re.cells,l,Gt]),x.useEffect(()=>{P||j(!1)},[P]),x.useEffect(()=>{if(xe)return;const w=Ke.data;if(!w||w.status!=="ready")return;const je=new Map(w.questions.map(Ee=>[`${Ee.attachmentType}:${Ee.attachmentId}`,Ee]));O(Ee=>{const Ge=Ee.filter(Be=>{const Ze=je.get(bs(Be));return Ze?Ze.kind==="value"?Be.valueId!=null&&Ze.values.some(xs=>xs.id===Be.valueId):Ze.kind==="quantity"?Number.isSafeInteger(Be.quantity)&&Be.quantity>0:typeof Be.textValue=="string"&&Be.textValue.length>0:!1});return Ge.length===Ee.length?Ee:Ge})},[xe,Ke.data]);const yi=w=>{O(je=>[...je.filter(Ee=>bs(Ee)!==bs(w)),w])};return r.isLoading?e.jsx("div",{className:"border border-border p-8 text-sm text-muted-foreground",children:"Loading Journey..."}):l?!ae||!z?e.jsxs("div",{className:"border border-border bg-background","data-testid":"configurator-v2-journey-canvas",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-border px-4 py-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Journey audiences"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No active audiences are available."})]}),e.jsxs(A,{type:"button",variant:"outline",size:"sm",onClick:()=>ge(w=>!w),"data-testid":"jc-add-audience",children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"New audience"]})]}),De&&e.jsx(zs,{tiers:l.configV2Tiers,onClose:()=>ge(!1),onCreated:w=>{o(w.slug),ge(!1)}}),!De&&e.jsx("div",{className:"p-10 text-center text-sm text-muted-foreground",children:"Create a private audience to begin authoring a journey."})]}):e.jsxs("div",{className:"border border-border bg-background","data-testid":"configurator-v2-journey-canvas",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 border-b border-border px-3 py-3",children:[e.jsxs("div",{className:"min-w-52",children:[e.jsx("p",{className:"mb-1 text-xs font-medium uppercase text-muted-foreground",children:"Authoring in"}),e.jsxs(fe,{value:z,onValueChange:o,children:[e.jsx(be,{"data-testid":"jc-audience-select","aria-label":"Authoring audience",children:e.jsx(ye,{})}),e.jsx(Se,{children:a.map(w=>e.jsx(se,{value:w.slug,children:w.name},w.slug))})]})]}),(xe||p==="author")&&e.jsxs(A,{type:"button",variant:"outline",size:"sm",onClick:()=>ge(w=>!w),"data-testid":"jc-add-audience",children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"New audience"]}),e.jsxs("div",{className:"min-w-52 flex-1 sm:flex-none xl:hidden",children:[e.jsx("p",{className:"mb-1 text-xs font-medium uppercase text-muted-foreground",children:"Garment"}),e.jsxs(fe,{value:q??void 0,onValueChange:u,children:[e.jsx(be,{"aria-label":"Garment",children:e.jsx(ye,{placeholder:"Choose garment"})}),e.jsx(Se,{children:K.map(w=>e.jsx(se,{value:w.slug,children:w.name},w.slug))})]})]}),e.jsxs("div",{className:"flex min-h-10 items-center rounded-md border border-border p-1","aria-label":"Journey lens",children:[e.jsx(oi,{className:"mx-2 h-4 w-4 text-muted-foreground"}),Nn.map(w=>e.jsx(A,{type:"button",size:"sm",variant:y===w.value?"secondary":"ghost",onClick:()=>f(w.value),"data-testid":`jc-lens-${w.value}`,children:w.label},w.value))]}),e.jsxs("div",{className:"ml-auto flex min-h-10 items-center rounded-md border border-border p-1","aria-label":"Journey mode",children:[e.jsxs(A,{type:"button",size:"sm",variant:J?"ghost":"secondary",disabled:xe,onClick:()=>S("author"),"data-testid":"jc-mode-author",children:[e.jsx(Wi,{className:"mr-1 h-4 w-4"}),"Author"]}),e.jsxs(A,{type:"button",size:"sm",variant:J?"secondary":"ghost",onClick:()=>{S("walk"),f("content"),E(null),m(!1),X(null),de(null),ge(!1),$(null),j(!1),M(!1),ie(!1),_(null)},"data-testid":"jc-mode-walk",children:[e.jsx(Bt,{className:"mr-1 h-4 w-4"}),"Walk"]})]}),!J&&e.jsxs(A,{type:"button",variant:"outline",size:"sm",onClick:()=>{_(null),M(!0)},disabled:he.isPending,"data-testid":"jc-open-publish",children:[e.jsx(ai,{className:"mr-1 h-4 w-4"}),"Publish audience"]}),!J&&s&&e.jsxs("div",{className:"flex min-h-10 items-center gap-2 border-l border-border pl-3",children:[e.jsx(nr,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{className:"hidden lg:block",children:[e.jsx("p",{className:"text-xs font-medium",children:"Public default"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Unkeyed public repair visits"})]}),e.jsx(_e,{checked:ae.isPublicConfigurator,onCheckedChange:()=>ie(!0),disabled:pe.isPending,"aria-label":ae.isPublicConfigurator?`Return ${ae.name}
372 public routing to V1`:`Set ${ae.name} as the public default`,"data-testid":"jc-public-default-switch"})]}),!J&&e.jsx(A,{type:"button",variant:"outline",size:"icon",className:"xl:hidden",title:"New garment","aria-label":"New garment",onClick:()=>X("new-garment"),children:e.jsx(Qe,{className:"h-4 w-4"})}),!J&&e.jsx(A,{type:"button",variant:"outline",size:"icon",className:"xl:hidden",title:"Group garments","aria-label":"Group garments",onClick:()=>de({kind:"group"}),children:e.jsx(Yt,{className:"h-4 w-4"})}),!J&&F&&(F.hasActiveChildren||H.length===0)&&e.jsx(A,{type:"button",variant:"outline",size:"icon",className:"xl:hidden",title:`Add subtype to ${F.name}`,"aria-label":`Add subtype to ${F.name}`,onClick:()=>de({kind:"subtype",parentSlug:F.slug}),children:e.jsx(Wt,{className:"h-4 w-4"})}),e.jsxs(Ci,{open:b,onOpenChange:j,children:[e.jsx(Ai,{asChild:!0,children:e.jsx(A,{type:"button",variant:"outline",size:"icon",className:"2xl:hidden",title:"Open inspector","aria-label":"Open inspector",children:e.jsx(vr,{className:"h-4 w-4"})})}),e.jsxs($i,{className:"w-full overflow-y-auto sm:max-w-sm",children:[e.jsx(wi,{children:e.jsx(ki,{children:"Inspector"})}),e.jsx(Ws,{selection:P,context:Es})]})]})]}),e.jsx(Tt,{open:ue,onOpenChange:w=>{pe.isPending||ie(w)},children:e.jsxs(It,{"data-testid":"jc-public-default-dialog",children:[e.jsxs(Vt,{children:[e.jsx(Rt,{children:ae.isPublicConfigurator?"Return public repair routing to V1?":`Make ${ae.name} the public default?`}),e.jsx(Et,{children:ae.isPublicConfigurator?"New unkeyed repair visits will use V1. In-flight V2 carts will fail stale and customers will be asked to restart their repair. Rollback does not depend on catalog preflight.":"New unkeyed repair visits will use this audience. Staff catalog previews and partner links keep their existing routing precedence."})]}),!ae.isPublicConfigurator&&e.jsx("div",{className:"border-y border-border py-3 text-sm","aria-live":"polite",children:Oe.isLoading||Oe.isFetching?e.jsx("p",{className:"text-muted-foreground",children:"Checking the current published catalog..."}):Oe.isError?e.jsx("p",{className:"text-destructive",role:"alert",children:Oe.error instanceof Error?Oe.error.message:"Promotion preflight could not run."}):we?e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Current offers"}),e.jsx("p",{className:"font-semibold",children:we.unchangedCount})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Pending"}),e.jsx("p",{className:"font-semibold",children:we.publishCount})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Withheld / stale"}),e.jsx("p",{className:"font-semibold",children:Re+we.stale.length})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Retirements"}),e.jsx("p",{className:"font-semibold",children:we.retireCount})]}),!ut&&e.jsx("p",{className:"col-span-full mt-1 text-destructive",role:"alert",children:"Publish pending revisions and resolve every withheld, stale, or retirement row before promotion."})]}):null}),e.jsxs(Ot,{children:[e.jsx(Pt,{disabled:pe.isPending,children:"Cancel"}),e.jsx(Dt,{onClick:w=>{w.preventDefault(),pe.mutate(!ae.isPublicConfigurator)},disabled:pe.isPending||!ae.isPublicConfigurator&&!ut,"data-testid":"jc-public-default-confirm",children:ae.isPublicConfigurator?"Return to V1":"Make public default"})]})]})}),De&&e.jsx(zs,{tiers:l.configV2Tiers,onClose:()=>ge(!1),onCreated:w=>{o(w.slug),ge(!1)}}),xe&&e.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-amber-50 px-4 py-2 text-sm text-amber-900","data-testid":"jc-read-only-banner",children:[e.jsx(di,{className:"h-4 w-4"}),ae.catalogMode==="v1_import"?`${ae.name} is imported and inspect-only. Rebuild the path in a native audience.`:`${ae.name} still serves mutable catalog rows. Return it to private routing, publish it, then restore customer routing before authoring here.`]}),!xe&&ke&&e.jsx(wn,{tier:ae,catalog:l,plan:Oe.data,result:k,isLoading:Oe.isLoading||Oe.isFetching,isError:Oe.isError,error:Oe.error instanceof Error?Oe.error:null,isPublishing:he.isPending,onRefresh:()=>{_(null),Oe.refetch()},onPublish:()=>he.mutate(),onClose:()=>{M(!1),_(null)}}),!J&&(ce==null?void 0:ce.kind)==="group"&&e.jsx(kn,{tierSlug:z,garments:l.configV2Garments,cells:re.cells,initialGarmentSlug:q,onClose:()=>de(null),onCreated:w=>{u(w.category.slug),c(null),de(null)}}),!J&&(ce==null?void 0:ce.kind)==="subtype"&&(()=>{const w=l.configV2Garments.find(je=>je.slug===ce.parentSlug);return w?e.jsx(qn,{tierSlug:z,parent:w,garments:l.configV2Garments,parentRepairCount:re.cells.filter(je=>je.garmentSlug===w.slug).length,onClose:()=>de(null),onCreated:je=>{u(je.slug),c(null),de(null)}}):null})(),!J&&G==="new-garment"&&e.jsx("div",{className:"border-b border-border",children:e.jsx("div",{className:"mx-auto max-w-xl",children:e.jsx(fs,{tier
372Slug:z,catalog:l,onClose:()=>X(null),onCreated:w=>{u(w.garmentSlug),c(w.id),X(null)}})})}),F?e.jsxs("div",{className:"grid min-h-[720px] grid-cols-1 xl:grid-cols-[220px_minmax(0,1fr)] 2xl:grid-cols-[240px_minmax(640px,1fr)_320px]",children:[e.jsx(Fa,{garments:K,cells:re.cells,selectedGarmentSlug:q,search:T,onSearchChange:C,onSelectGarment:w=>{u(w),c(null)},onAddGarment:J?void 0:()=>X("new-garment"),onGroupGarments:J?void 0:()=>de({kind:"group"}),onAddSubtype:J?void 0:w=>de({kind:"subtype",parentSlug:w.slug})}),W?e.jsx(On,{tier:ae,garment:F,menuProjections:Nt,menuAvailabilityStatus:hs,selectedCell:W,services:l.configV2Services,projections:Gt,selections:v,preview:xe?void 0:Ke.data,draftStatus:xe?void 0:ze.data??void 0,pricingDraft:xe?void 0:ve.data,pricingDirtyKeys:xe||J?void 0:fi,lens:y,onSelectCell:c,onSelectAnswer:yi,onInspect:$e,onAddPreServiceQuestion:J||!oe.data?void 0:()=>{E(null),m(!0)},preServiceComposer:!J&&N&&oe.data?e.jsx(Oa,{tierSlug:z,garmentSlug:F.slug,attributes:l.configV2Attributes,attachments:oe.data,onClose:()=>m(!1)},`${z}:${F.slug}`):null,onAddQuestion:J?void 0:()=>{m(!1),E({})},onAddFollowUp:J?void 0:w=>{m(!1),E({followUp:w})},composer:!J&&D&&oe.data?{followUp:D.followUp,content:e.jsx(Ra,{tierSlug:z,serviceSlug:W.serviceSlug,attributes:l.configV2Attributes,attachments:oe.data,followUp:D.followUp,onClose:()=>E(null)},`${W.id}:${((Ms=D.followUp)==null?void 0:Ms.parentServiceAttributeId)??"root"}:${((Fs=D.followUp)==null?void 0:Fs.parentValueId)??"new"}`)}:null,onAddRepair:J||F.hasActiveChildren?void 0:()=>X("new-repair"),repairComposer:!J&&G==="new-repair"?e.jsx(fs,{tierSlug:z,garment:F,catalog:l,onClose:()=>X(null),onCreated:w=>{c(w.id),X(null)}},F.slug):null,onSetCellActive:J?void 0:w=>Ae.mutate({tierSlug:z,garmentServiceId:W.id,isActive:w}),activationPending:Ae.isPending,onSetCellMembership:J?void 0:(w,je)=>{const Ee=w.audienceTierSlugs??[],Ge=je?Array.from(new Set([...Ee,z])):Ee.filter(Be=>Be!==z);Ve.mutate({authoringTierSlug:z,garmentServiceId:w.id,tierSlugs:Ge})},onSetValueAvailable:J?void 0:(w,je,Ee)=>{const Ge=w.question.attribute.values.filter(Ze=>Ze.hiddenForGarments.includes(F.slug)).map(Ze=>Ze.id),Be=Ee?Ge.filter(Ze=>Ze!==je.id):Array.from(new Set([...Ge,je.id]));yt.mutate({tierSlug:z,garmentSlug:F.slug,serviceSlug:W.serviceSlug,attributeSlug:w.question.attribute.slug,hiddenValueIds:Be})},onSetDescriptorScope:J?void 0:(w,je,Ee)=>{I.isPending||I.mutate({tierSlug:z,garmentServiceId:w.id,attributeSlug:je,allowedValueSlugs:Ee})},descriptorScopeMutation:{targetKey:Ce,pending:I.isPending,error:((Gs=I.error)==null?void 0:Gs.message)??null},reorderError:qe,onReorderQuestions:J||te.isPending||Y.isPending||!oe.data?void 0:(w,je,Ee)=>{const Ge=st=>{const kt=st.indexOf(je),Ct=st.indexOf(Ee);if(kt<0||Ct<0)return null;const _t=[...st],[Si]=_t.splice(kt,1);return _t.splice(Ct,0,Si),_t};if(w==="service"){const st=oe.data.allServiceAttributes.filter(Ct=>Ct.serviceSlug===W.serviceSlug).sort((Ct,_t)=>Ct.displayOrder-_t.displayOrder||Ct.id-_t.id).map(Ct=>Ct.id),kt=Ge(st);kt&&te.mutate({serviceSlug:W.serviceSlug,attachmentIds:kt});return}const Be=oe.data.allGarmentAttributes.find(st=>st.id===je),Ze=oe.data.allGarmentAttributes.find(st=>st.id===Ee);if(!Be||!Ze||Be.garmentSlug!==Ze.garmentSlug){Te("Questions can only move within the garment level where they are attached.");return}const xs=oe.data.allGarmentAttributes.filter(st=>st.garmentSlug===Be.garmentSlug).sort((st,kt)=>st.displayOrder-kt.displayOrder||st.id-kt.id).map(st=>st.id),_s=Ge(xs);_s&&Y.mutate({garmentSlug:Be.garmentSlug,attachmentIds:_s})}}):e.jsxs("section",{className:"flex min-h-[520px] flex-col items-center justify-center px-6 py-12 text-center","data-testid":"jc-empty-garment",children:[F.hasActiveChildren?e.jsx(Yt,{className:"h-8 w-8 text-muted-foreground"}):e.jsx(Qe,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("h2",{className:"mt-3 text-base font-semibold",children:F.name}),e.jsx("p",{className:"mt-1 max-w-md text-sm text-muted-foreground",children:F.hasActiveChildren?"This category keeps its existing garments and repair facts beneath it. Add another subtype when the taxonomy needs a new leaf.":"This garment has no repairs yet. Add its first inactive repair draft, or make it a category by adding a subtype."}),!J&&F.hasActiveChildren&&e.jsxs(A,{type:"button",variant:"outline",className:"mt-4",onClick:()=>de({kind:"subtype",parentSlug:F.slug}),"data-testid":"jc-empty-add-subtype",children:[e.jsx(Wt,{className:"mr-1 h-4 w-4"}),"Add subtype"]}),!J&&!F.hasActiveChildren&&G!=="new-repair"&&e.jsxs("div",{className:"mt-4 flex flex-wrap justify-center gap-2",children:[e.jsxs(A,{type:"button",variant:"outline",onClick:()=>X("new-repair"),"data-testid":"jc-empty-add-repair",children:[e.jsx(Qe,{className:"mr-1 h-4 w-4"}),"Add repair"]}),e.jsxs(A,{type:"button",variant:"outline",onClick:()=>de({kind:"subtype",parentSlug:F.slug}),"data-testid":"jc-empty-make-category",children:[e.jsx(Wt,{className:"mr-1 h-4 w-4"}),"Add subtype"]})]}),!J&&!F.hasActiveChildren&&G==="new-repair"&&e.jsx("div",{className:"mt-5 w-full max-w-xl text-left",children:e.jsx(fs,{tier
372Slug:z,garment:F,catalog:l,onClose:()=>X(null),onCreated:w=>{c(w.id),X(null)}},F.slug)})]}),e.jsx("aside",{className:"hidden min-h-0 border-l border-border bg-muted/20 2xl:block","data-testid":"jc-inspector",children:e.jsx(Ws,{selection:P,context:Es})})]}):e.jsx("div",{className:"p-10 text-center text-sm text-muted-foreground",children:"No repair paths are available in this audience."})]}):e.jsx("div",{className:"border border-border p-8 text-sm text-muted-foreground",children:"Journey could not load the audience catalog."})}const Dn=[{value:"robin",label:"Robin (Catalog V3)",description:"Grouped pieces, garment zones and whole-piece prices."},{value:"card-wizard",label:"Card Wizard (recommended)",description:"Guided one-card-per-step flow."},{value:"wizard",label:"Classic Wizard",description:"Multi-step page wizard with grids."},{value:"hybrid-wizard",label:"Hybrid Wizard",description:"Card wizard plus inline questions."},{value:"chat",label:"Chat",description:"Conversational repair assistant."}],ys=["public-configurator-mode"];function Mn(){const{toast:t}=Pe(),[s,i]=x.useState(!1),{data:r,isLoading:l}=ne({queryKey:ys,queryFn:async()=>{const o=await(await fetch("/graphql",{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify({query:"query GetPublicConfiguratorMode { publicConfiguratorMode }"})})).json();if(o.errors)throw new Error(o.errors[0].message);return o.data.publicConfiguratorMode}}),a=le({mutationFn:async d=>{i(!0);const n=await(await fetch("/graphql",{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},credentials:"include",body:JSON.stringify({query:"mutation UpdatePublicConfiguratorMode($mode: String!) { updatePublicConfiguratorMode(mode: $mode) }",variables:{mode:d}})})).json();if(n.errors)throw new Error(n.errors[0].message);return n.data.updatePublicConfiguratorMode},onSuccess:(d,o)=>{Z.setQueryData(ys,o),Z.invalidateQueries({queryKey:ys}),t({title:"Configurator mode updated",description:`Public /repair now uses "${o}".`})},onError:d=>{t({title:"Could not update mode",description:(d==null?void 0:d.message)||"Unknown error",variant:"destructive"})},onSettled:()=>i(!1)});return e.jsxs(nt,{children:[e.jsxs(Ut,{children:[e.jsx(Lt,{children:"Public Configurator Mode"}),e.jsxs(Zs,{children:["Choose which configurator experience visitors see on /repair. Customers can override per session via ",e.jsx("code",{children:"?mode="}),"."]})]}),e.jsxs(lt,{className:"space-y-3",children:[e.jsx(Ue,{htmlFor:"public-config-mode-select",children:"Active mode"}),e.jsxs(fe,{value:r||"card-wizard",onValueChange:d=>a.mutate(d),disabled:l||s,children:[e.jsx(be,{id:"public-config-mode-select","data-testid":"select-public-configurator-mode",className:"max-w-md",children:e.jsx(ye,{placeholder:"Select mode..."})}),e.jsx(Se,{children:Dn.map(d=>e.jsx(se,{value:d.value,"data-testid":`option-mode-${d.value}`,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:d.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:d.description})]})},d.value))})]})]})]})}function Fn(){const[t,s]=x.useState("card-wizard");return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Mn,{}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(A,{asChild:!0,variant:"outline",size:"sm",children:e.jsx("a",{href:"/admin/catalog-preview?mode=robin",children:"Robin (V3 catalogs)"})}),e.jsxs(A,{variant:t==="card-wizard"?"default":"outline",size:"sm",onClick:()=>s("card-wizard"),"data-testid":"button-preview-mode-card-wizard",children:[e.jsx(Bt,{className:"h-4 w-4 mr-1"}),"Card Wizard"]}),e.jsxs(A,{variant:t==="wizard"?"default":"outline",size:"sm",onClick:()=>s("wizard"),"data-testid":"button-preview-mode-wizard",children:[e.jsx(Sr,{className:"h-4 w-4 mr-1"}),"Wizard"]}),e.jsxs(A,{variant:t==="hybrid-wizard"?"default":"outline",size:"sm",onClick:()=>s("hybrid-wizard"),"data-testid":"button-preview-mode-hybrid-wizard",children:[e.jsx(li,{className:"h-4 w-4 mr-1"}),"Hybrid Wizard"]}),e.jsxs(A,{variant:t==="chat"?"default":"outline",size:"sm",onClick:()=>s("chat"),"data-testid":"button-preview-mode-chat",children:[e.jsx(ws,{className:"h-4 w-4 mr-1"}),"Chat"]})]}),t==="wizard"?e.jsx(Di,{}):t==="card-wizard"?e.jsx(Mi,{}):t==="hybrid-wizard"?e.jsx(Fi,{}):e.jsx(zi,{})]})}const Xs=[{id:"pricing-matrix",label:"Pricing Matrix",icon:As},{id:"garments",label:"Garments",icon:os},{id:"services",label:"Services",icon:Zt},{id:"attributes",label:"Attributes",icon:oi},{id:"dependencies",label:"Dependencies",icon:qt},{id:"tiers",label:"Tiers",icon:li},{id:"synonyms",label:"Synonyms",icon:ir},{id:"products",label:"Products",icon:Zi},{id:"failed-parses",label:"Learning",icon:ds},{id:"sessions",label:"Sessions",icon:ws}],Gn=new Set(["pricing-matrix","garments","services","attributes","dependencies"]);async function _n(){return(await U("query { configV2Tiers { slug name isActive } }")).configV2Tiers}function Un(){const[t,s]=x.useState("pricing-matrix"),[i,r]=x.use
372State("all"),[l,a]=x.useState(!1),[d,o]=x.useState(0),n=Xs.find(y=>y.id===t),u=Gn.has(t),h={tierSlug:i==="all"?null:i,showImported:l},{data:c=[]}=ne({queryKey:["configV2Tiers","manageCatalogLens"],queryFn:_n});return e.jsxs("div",{className:"flex gap-6",children:[e.jsx("div",{className:"w-48 shrink-0",children:e.jsx("nav",{className:"space-y-1",children:Xs.map(y=>{const f=y.icon;return e.jsxs("button",{onClick:()=>{o(0),s(y.id)},className:`w-full flex items-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition-colors ${t===y.id?"bg-blue-100 text-blue-700":"text-gray-600 hover:text-gray-900 hover:bg-gray-50"}`,children:[e.jsx(f,{className:"h-4 w-4"}),y.label]},y.id)})})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs(nt,{children:[e.jsxs(Ut,{children:[e.jsxs(Lt,{className:"flex items-center gap-2",children:[n&&e.jsx(n.icon,{className:"h-5 w-5"}),n==null?void 0:n.label]}),e.jsxs(Zs,{children:["Manage configurator ",n==null?void 0:n.label.toLowerCase()]}),u&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-2","data-testid":"manage-catalog-lens",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Catalog lens"}),e.jsxs(fe,{value:i,onValueChange:y=>{o(0),r(y)},children:[e.jsx(be,{className:"w-56","data-testid":"manage-catalog-tier-trigger",children:e.jsx(ye,{placeholder:"All tiers"})}),e.jsxs(Se,{children:[e.jsx(se,{value:"all",children:"All tiers"}),c.map(y=>e.jsxs(se,{value:y.slug,children:[y.name,y.isActive===!1?" (inactive)":""]},y.slug))]})]}),h.tierSlug?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm","data-testid":"manage-tier-catalog-note",children:[e.jsx("span",{className:"font-medium",children:"Generated sellable catalog"}),e.jsx("span",{className:"text-muted-foreground",children:"From the last regeneration; current deactivations also apply. Read-only."}),e.jsx(A,{size:"sm",variant:"outline",onClick:()=>r("all"),children:"Edit in All tiers"})]}):d>0?e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>a(y=>!y),"aria-pressed":l,"data-testid":"manage-imported-toggle",children:[l?e.jsx(ti,{className:"h-4 w-4 mr-1"}):e.jsx(Bt,{className:"h-4 w-4 mr-1"}),l?"Hide imported":`${d} imported hidden - Show`]}):null]})]}),e.jsxs(lt,{children:[t==="pricing-matrix"&&e.jsx(qr,{lens:h,onImportedCountChange:o}),t==="garments"&&e.jsx(Tr,{lens:h,onImportedCountChange:o}),t==="services"&&e.jsx(Ir,{lens:h,onImportedCountChange:o}),t==="attributes"&&e.jsx(Vr,{lens:h,onImportedCountChange:o}),t==="dependencies"&&e.jsx(Gr,{lens:h,onImportedCountChange:o}),t==="tiers"&&e.jsx(Rr,{}),t==="synonyms"&&e.jsx(Er,{}),t==="products"&&e.jsx(Or,{}),t==="failed-parses"&&e.jsx(Pr,{}),t==="sessions"&&e.jsx(Dr,{})]})]})})]})}function _l(){const[t,s]=x.useState("journey");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Legacy V2 editor"}),e.jsx("p",{className:"text-gray-500 mt-1",children:"Edit retained V2 catalogs here. Use Catalogs for the new catalog builder."}),e.jsx(A,{asChild:!0,variant:"outline",className:"mt-3 mr-3",children:e.jsx("a",{href:"/admin/catalogs",children:"Catalogs"})}),e.jsx(A,{asChild:!0,variant:"outline",className:"mt-3",children:e.jsx("a",{href:"/admin/catalog-preview",children:"Catalog previews"})})]}),e.jsxs(Hi,{value:t,onValueChange:s,children:[e.jsxs(Yi,{className:"h-auto max-w-full flex-wrap justify-start",children:[e.jsxs(ps,{value:"journey",children:[e.jsx(Xt,{className:"h-4 w-4 mr-1"}),"Journey"]}),e.jsxs(ps,{value:"preview",children:[e.jsx(Bt,{className:"h-4 w-4 mr-1"}),"Preview"]}),e.jsxs(ps,{value:"manage",children:[e.jsx(Xi,{className:"h-4 w-4 mr-1"}),"Manage"]})]}),e.jsx(vs,{value:"journey",children:e.jsx(Pn,{})}),e.jsx(vs,{value:"preview",children:e.jsx(Fn,{})}),e.jsx(vs,{value:"manage",children:e.jsx(Un,{})})]})]})}export{_l as ConfiguratorV2};
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.