1(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,369330,e=>{"use strict";var a=e.i(830182),t=e.i(597450),s=e.i(511737),l=e.i(961120),r=e.i(942647),i=e.i(167881),n=e.i(630374),o=e.i(23750),c=e.i(10708),d=e.i(398232),u=e.i(62870),m=e.i(720460),h=e.i(739914);async function p(e,a,t){let s=await fetch(`/api/internal/phase-defaults/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(a),signal:t}),l={};try{l=await s.json()}catch{}if(!s.ok||!0!==l.success||void 0===l.data)throw(0,h.serverMessageError)(l,`HTTP ${s.status}`);return l.data}function x(e,a){return"location"!==a?a:"purchase"===e?"receivingLocation":"manufacture"===e?"productionLocation":"location"}function g({role:e}){let t=(0,l.useTranslations)("bridge.data.phaseDefaults"),i=(0,m.useServerMessage)(),[o,c]=(0,s.useState)(void 0),[d,u]=(0,s.useState)(null),[h,y]=(0,s.useState)(null),[j,b]=(0,s.useState)(0);return((0,s.useEffect)(()=>{var a;let t=new AbortController;return(a={signal:t.signal},p("query",{role:e},a?.signal)).then(e=>{t.signal.aborted||(c(e),u(null))}).catch(e=>{t.signal.aborted||(c(null),u(i(e,{uncoded:"generic"})))}),()=>t.abort()},[e,j,i]),void 0===o||o?.state==="no-system")?null:null===o?(0,a.jsx)(r.ManageSection,{title:t("title"),state:{kind:"empty",title:d??t("unavailable")}}):(0,a.jsxs)(r.ManageSection,{title:t("title"),children:[(0,a.jsx)(r.ManageRowList,{children:o.defaults.map(s=>(0,a.jsx)(r.ManageRow,{title:t(x(e,s.key)),summary:s.label??(null!==s.value?t("recordId",{id:s.value}):t("notSet")),onClick:()=>y(s),"data-testid":`phase-default-${s.key}`},s.key))}),(0,a.jsx)(n.Dialog,{open:null!==h,onOpenChange:e=>{e||y(null)},children:h?(0,a.jsx)(f,{role:e,entry:h,revision:o.revision,onClose:()=>y(null),onSaved:()=>{y(null),b(e=>e+1)}}):null})]})}function f({role:e,entry:t,revision:r,onClose:h,onSaved:g}){let y=(0,l.useTranslations)("bridge.data.phaseDefaults"),j=(0,m.useServerMessage)(),[b,v]=(0,s.useState)(null!==t.value?String(t.value):""),[S,k]=(0,s.useState)(!1),[w,N]=(0,s.useState)(null),C=y(x(e,t.key)),T=Number(b),F=Number.isSafeInteger(T)&&T>0,D=T===t.value;async function A(){if(F&&!S){k(!0),N(null);try{var a;await (a={role:e,key:t.key,value:T,expectedRevision:r},p("execute",{operation:"save",...a})),g()}catch(e){N(j(e,{uncoded:"generic"})),k(!1)}}}return(0,a.jsxs)(n.DialogContent,{children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:C})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-4",children:[t.options.length>0?(0,a.jsxs)(u.Select,{value:b,onValueChange:v,disabled:S,children:[(0,a.jsx)(u.SelectTrigger,{className:"w-full","aria-label":C,children:(0,a.jsx)(u.SelectValue,{placeholder:y("notSet")})}),(0,a.jsx)(u.SelectContent,{children:t.options.map(e=>(0,a.jsx)(u.SelectItem,{value:String(e.id),children:e.label},e.id))})]}):(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{htmlFor:"phase-default-id",children:y("idLabel")}),(0,a.jsx)(o.Input,{id:"phase-default-id",inputMode:"numeric",value:b,onChange:e=>v(e.target.value),disabled:S})]}),w?(0,a.jsx)(d.Notice,{tone:"blocker",title:w}):null]}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{type:"button",variant:"quiet",onClick:h,disabled:S,children:y("cancel")}),(0,a.jsx)(i.Button,{type:"button",onClick:()=>void A(),disabled:!F||D||S,"aria-busy":S||void 0,children:y("save")})]})]})}var y=e.i(958135),j=e.i(791383),b=e.i(683223),v=e.i(994179),S=e.i(906336),k=e.i(671428),w=e.i(950216),N=e.i(883647),C=e.i(750184),T=e.i(243484),F=e.i(57559),D=e.i(647163);let A={seasons:"seasons",seasonality:"seasonality",locations:"locations",brands:"brands",brandConfigs:"brandConfigs",deliveryTerms:"deliveryTerms",shipMethods:"shipMethods",paymentTerms:"paymentTerms",paymentMethods:"paymentMethods",orderTypes:"orderTypes",sizeAssortments:"sizeAssortments",sizeConversions:"sizeConversions",productAttributes:"productAttributes",destinationBindings:"destinationBindings",products:"products",housekeepingRules:"housekeepingRules",customers:"customers",vendors:"vendors",supplierProfiles:"supplierProfiles",supplierVendorReview:"supplierVendorReview",manufacturerSites:"manufacturerSites",systemProductMatches:"systemProductMatches",phaseDefaults:"phaseDefaults",inventory:"inventory",manufacturingComponents:"manufacturingComponents",manufacturableKnits:"manufacturableKnits",yarnItems:"yarnItems",secondQualityReasons:"secondQualityReasons",manufacturingSteps:"manufacturingSteps",productCardModules:"productCardModules",models:"models",parents:"parents",dataSources:"dataSources",productReferences:"productReferences",colorPalette:"colorPalette",destinationLevelMaps:"destinationLevelMaps",accounts:"accounts",subsidiaries:"subsidiaries",classes:"classes",departments:"departments",taxSchedules:"taxSchedules",priceLevels:"priceLevels",unitsTypes:"unitsTypes",currencies:"currencies",outputProfiles:"outputProfiles",companyFacts:"companyFacts",companyAssets:"companyAssets",labelMarkMappings:"labelMarkMappings",classificationMappings:"classificationMappings",catalogues:"catalogues",customerCatalogues:"customerCatalogues",catalogueProductCandidates:"catalogueProductCandidates",markets:"markets",priceChannels:"priceChannels",catalogueReadinessRequirements:"catalogueReadinessRequirements",catalogueRequirementGroups:"catalogueRequirementGroups",stockReadinessRequirements:"stockReadinessRequirements",salesOrderLifecycle:"salesOrderLifecycle",salesSpecialHandling:"salesSpecialHandling",orderFormFilters:"orderFormFilters",workOrderRules:"workOrderRules",preliminaryCollections:"preliminaryCollections"},L={"seasons.start":"seasonsStart","seasons.end":"seasonsEnd","seasons.orderStart":"seasonsOrderStart","seasons.orderEnd":"seasonsOrderEnd","seasons.shipStart":"seasonsShipStart","seasons.shipEnd":"seasonsShipEnd","sizeAssortments.sizes":"sizeAssortmentsSizes","locations.kind":"locationsKind","markets.countryCode":"marketsCountryCode"},E={"locations.kind.warehouse":"locationsKindWarehouse","locations.kind.store":"locationsKindStore","locations.kind.b2b":"locationsKindB2b","locations.kind.marketplace":"locationsKindMarketplace","locations.kind.other":"locationsKindOther"};function M(){let e=(0,l.useTranslations)("bridge.data.valueSetTypes"),a=(0,l.useTranslations)("bridge.data.valueSetFields"),t=(0,l.useTranslations)("bridge.data.valueSetFieldOptions");return{typeLabel:a=>Object.hasOwn(A,a)?e(A[a]):a,fieldLabel:(e,t)=>
1{let s=L[`${e}.${t.key}`];return s?a(s):t.label},optionLabel:(e,a,s)=>{let l=E[`${e}.${a.key}.${s.value}`];return l?t(l):s.label}}}var R=e.i(114390),P=e.i(989615),O=e.i(535909),B=e.i(172300),I=e.i(628854),z=e.i(709666),$=e.i(98318),_=e.i(625959),K=e.i(756226),H=e.i(645953),U=e.i(129875);let q={netsuite:{products:{referenceType:"products",cacheTTL:"24h"},vendors:{referenceType:"vendors",cacheTTL:"24h"},locations:{referenceType:"locations",cacheTTL:"7d"},paymentTerms:{referenceType:"paymentTerms",cacheTTL:"7d"},shipMethods:{referenceType:"shipMethods",cacheTTL:"7d"}},shopify:{locations:{referenceType:"locations",cacheTTL:"7d"}}};var V=e.i(319036);let G="flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm shadow-xs transition-colors placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",J={locations:{queryType:"netsuiteLocation",Form:function({value:e,onChange:t}){let s=(0,l.useTranslations)("poc.intra.products.sources.netsuite.location"),r=(e.excludeIds??[]).join(", ");return(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{children:s("excludeIds")}),(0,a.jsx)("input",{type:"text",defaultValue:r,onBlur:a=>t({...e,excludeIds:a.target.value.split(",").map(e=>parseInt(e.trim(),10)).filter(e=>!isNaN(e)&&e>0)}),placeholder:"3, 7",className:"flex h-9 w-full rounded-lg border border-input bg-background px-3 py-1 text-sm shadow-xs transition-colors placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:s("excludeIdsHint")})]})},initialConfig:()=>({type:"netsuiteLocation"})},brands:{queryType:"netsuiteClass",Form:function({value:e,onChange:t}){let s=(0,l.useTranslations)("poc.intra.products.sources.netsuite.class"),r=(e.excludeClassIds??[]).join(", ");return(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)(_.Checkbox,{id:"ns-class-dismiss-children",checked:!0===e.dismissChildren,onCheckedChange:a=>t({...e,dismissChildren:!0===a})}),(0,a.jsx)(c.Label,{htmlFor:"ns-class-dismiss-children",children:s("dismissChildren")})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{children:s("excludeIds")}),(0,a.jsx)("input",{type:"text",defaultValue:r,onBlur:a=>t({...e,excludeClassIds:a.target.value.split(",").map(e=>parseInt(e.trim(),10)).filter(e=>!isNaN(e)&&e>0)}),placeholder:"17, 8",className:"flex h-9 w-full rounded-lg border border-input bg-background px-3 py-1 text-sm shadow-xs transition-colors placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:s("excludeIdsHint")})]})]})},initialConfig:()=>({type:"netsuiteClass"})},customers:{queryType:"netsuiteCustomer",Form:function(e){let t=(0,l.useTranslations)("poc.intra.products.sources.netsuite.customer");return(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:t("hint")})},initialConfig:()=>({type:"netsuiteCustomer"})},shipMethods:{queryType:"netsuiteShipMethods",Form:function(e){let t=(0,l.useTranslations)("poc.intra.products.sources.netsuite.shipMethods");return(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:t("hint")})},initialConfig:()=>({type:"netsuiteShipMethods"})},deliveryTerms:{queryType:"netsuiteDeliveryTerms",Form:function({value:e,onChange:t}){let r=(0,l.useTranslations)("poc.intra.products.sources.netsuite.deliveryTerms"),[n,o]=(0,s.useState)(null),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(0);(0,s.useEffect)(()=>{let e=!1;return d(!1),o(null),fetch("/api/organization/value-sets/sell-delivery-terms").then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(a=>{e||o(Array.isArray(a.deliveryTerms)?a.deliveryTerms:[])}).catch(()=>{e||d(!0)}),()=>{e=!0}},[u]);let h=new Set(e.excludeIds??[]),p=(0,s.useCallback)((a,s)=>{let l=e.excludeIds??[],r=s?l.filter(e=>e!==a):[...new Set([...l,a])];t({...e,excludeIds:r})},[t,e]);return(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,a.jsx)("p",{className:"text-meta text-ink-muted",children:r("hint")}
1),c?(0,a.jsx)(N.StatePanel,{form:"inline",tone:"blocker",title:r("unavailable"),action:(0,a.jsx)(i.Button,{type:"button",variant:"secondary",size:"sm",onClick:()=>m(e=>e+1),children:r("retry")})}):null===n?(0,a.jsx)("div",{className:"flex flex-col gap-1.5","aria-label":r("loading"),role:"status",children:[0,1,2].map(e=>(0,a.jsx)(k.Skeleton,{className:"h-11 rounded-lg"},e))}):0===n.length?(0,a.jsx)(N.StatePanel,{form:"inline",title:r("empty")}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"text-meta text-ink-muted tabular-nums",children:r("enabledCount",{enabled:n.filter(e=>!h.has(e.id)).length,total:n.length})}),(0,a.jsx)(S.RowList,{className:"max-h-80 overflow-y-auto",children:n.map(e=>(0,a.jsx)(S.Row,{className:"py-2",title:e.name,trailing:(0,a.jsx)(V.Switch,{checked:!h.has(e.id),onCheckedChange:a=>p(e.id,a),"aria-label":r("useOnSalesOrders",{name:e.name})})},e.id))})]})]})},initialConfig:()=>({type:"netsuiteDeliveryTerms"})},paymentMethods:{queryType:"netsuitePaymentMethod",Form:function({value:e,onChange:t}){let s=(0,l.useTranslations)("poc.intra.products.sources.netsuite.paymentMethod"),r=!!(e.fallbackFieldId&&e.fallbackFieldId.trim()),i=e.fallbackFieldType??"boolean";return(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{children:s("primaryField")}),(0,a.jsx)("input",{type:"text",value:e.primaryFieldId??"",onChange:a=>t({...e,primaryFieldId:a.target.value}),placeholder:"custbody_gs_payment_instrument",className:G}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:s("primaryFieldHint")})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{children:s("fallbackField")}),(0,a.jsx)("input",{type:"text",value:e.fallbackFieldId??"",onChange:a=>t({...e,fallbackFieldId:a.target.value,...a.target.value.trim()?{fallbackFieldType:e.fallbackFieldType??"boolean"}:{fallbackFieldType:void 0,fallbackLabel:void 0}}),placeholder:"custbody_gs_factoring_sale",className:G}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:s("fallbackFieldHint")})]}),r&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{children:s("fallbackFieldType")}),(0,a.jsxs)(u.Select,{value:i,onValueChange:a=>t({...e,fallbackFieldType:a,..."string"===a?{fallbackLabel:void 0}:{}}),children:[(0,a.jsx)(u.SelectTrigger,{children:(0,a.jsx)(u.SelectValue,{})}),(0,a.jsxs)(u.SelectContent,{children:[(0,a.jsx)(u.SelectItem,{value:"boolean",children:s("typeBoolean")}),(0,a.jsx)(u.SelectItem,{value:"string",children:s("typeString")})]})]})]}),"boolean"===i&&(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{children:s("fallbackLabel")}),(0,a.jsx)("input",{type:"text",value:e.fallbackLabel??"",onChange:a=>t({...e,fallbackLabel:a.target.value}),placeholder:s("fallbackLabelPlaceholder"),className:G}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:s("fallbackLabelHint")})]})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{children:s("noneLabel")}),(0,a.jsx)("input",{type:"text",value:e.noneLabel??"",onChange:a=>t({...e,noneLabel:a.target.value}),placeholder:s("noneLabelPlaceholder"),className:G}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:s("noneLabelHint")})]})]})},initialConfig:()=>({type:"netsuitePaymentMethod",primaryFieldId:""}),validate:e=>"netsuitePaymentMethod"===e.type?e.primaryFieldId?.trim()?e.fallbackFieldId?.trim()&&"boolean"===e.fallbackFieldType&&!e.fallbackLabel?.trim()?"fallbackLabelRequired":null:"primaryFieldRequired":null},products:{queryType:"netsuiteSkuSearch",Form:function(e){let t=(0,l.useTranslations)("poc.intra.products.sources.netsuite.skuSearch");return(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:t("hint")})},initialConfig:()=>({type:"netsuiteSkuSearch"})}};var Q=e.i(485601),W=e.i(777043);let Y="__unmapped__",X="__external__";function Z({open:e,onOpenChange:t,valueSet:r,onSaved:c,connectedProviders:m=[]}){var h;let p,x,g,f=(0,l.useTranslations)("bridge.data"),y=(0,l.useTranslations)("poc.intra.products.sources.netsuite.paymentMethod"),j=(0,l.useTranslations)("components.glossaryTermC
1ard"),[b,v]=(0,s.useState)(null),[S,k]=(0,s.useState)(null),[w,C]=(0,s.useState)(!1),{orgSlug:D}=(0,Q.useIntraLayout)(),[A,L]=(0,s.useState)(!1),E=M(),V=E.typeLabel(r.type),G="seasons"===r.type,ee=Object.keys(r.availableServiceEntities||{}),ea=ee.length>0,et=U.VALUE_SET_FIELD_SCHEMAS[r.type]||[],es=et.length>0,[el,er]=(0,s.useState)(()=>r.externalSource?.type==="service-query"?"service-query":r.externalSource?.type==="service"?"service":r.externalSource?"url":"entries"),[ei,en]=(0,s.useState)(()=>r.data.map(e=>{let a={...e};for(let e of et)Array.isArray(a[e.key])&&(a[e.key]=a[e.key].join(", "));return a})),eo=(h=r.type,Object.entries(q).filter(([,e])=>Object.values(e).some(e=>e.referenceType===h)).map(([e])=>e)),[ec,ed]=(0,s.useState)(r.externalSource?.type==="service"?r.externalSource?.provider??"":""),eu=J[r.type],[em,eh]=(0,s.useState)(()=>eu?r.externalSource?.type==="service-query"&&r.externalSource.queryConfig?r.externalSource.queryConfig:eu.initialConfig():null),[ep,ex]=(0,s.useState)(r.externalSource?.path??""),[eg,ef]=(0,s.useState)(r.externalSource?.provider??""),[ey,ej]=(0,s.useState)(r.externalSource?.mapping?.key??""),[eb,ev]=(0,s.useState)(r.externalSource?.mapping?.label??""),[eS,ek]=(0,s.useState)(r.externalSource?.filterColumn??""),[ew,eN]=(0,s.useState)(r.externalSource?.filterValue??""),[eC,eT]=(0,s.useState)(!r.externalSource),[eF,eD]=(0,s.useState)([]),[eA,eL]=(0,s.useState)(!1),eE=eF.map(e=>({value:e,label:e})),[eM,eR]=(0,s.useState)(()=>{let e={};for(let a of ee){e[a]={};let t=r.serviceMappings.find(e=>e.provider===a);if(t?.mappings)for(let[s,l]of Object.entries(t.mappings))e[a][s]=String(l)}return e}),eP=JSON.stringify([el,ei,ec,em,ep,eg,ey,eb,eS,ew,eM]),eO=(0,s.useRef)(eP),eB=(0,F.useConfirmDiscard)(),eI=async()=>{A||(eP===eO.current||await eB())&&t(!1)},ez=async()=>{if(v(null),C(!1),"url"===el&&!ep.trim())return void v(f("externalSource.urlRequired"));if("service"===el&&!ec)return void v(f("source.serviceProviderRequired"));if("service-query"===el){if(!eu||!em)return void v(f("mapData.serviceQueryUnsupported"));let e=eu.validate?.(em)??null;if(e)return void v(y(e))}let e=ei.filter(e=>e.label.trim().length>0||e.key.trim().length>0).map(e=>{let a={...e,key:e.key||(0,H.slugify)(e.label)};return es?function(e,a){let t={...e};for(let e of a){let a=t[e.key];if(null==a||""===a){delete t[e.key];continue}if("sizes"===e.key&&"string"==typeof a)t[e.key]=a.split(",").map(e=>e.trim()).filter(Boolean);else if("number"===e.type&&"string"==typeof a){let s=Number(a);isNaN(s)||(t[e.key]=s)}}return t}(a,et):a}),a=e.map(e=>e.key);if(new Set(a).size!==a.length)return void v(f("errors.duplicateKeys"));L(!0);try{let a="*"!==r.scope?`?scope=${r.scope}`:"",s={data:e};if("url"===el){let e={};ey.trim()&&(e.key=ey.trim()),eb.trim()&&(e.label=eb.trim()),s.externalSource={type:"url",path:ep.trim(),...eg?{provider:eg}:{},...Object.keys(e).length>0?{mapping:e}:{},...eS.trim()?{filterColumn:eS.trim()}:{},...ew.trim()?{filterValue:ew.trim()}:{}}}else"service"===el?s.externalSource={type:"service",path:"",provider:ec}:"service-query"===el&&em?s.externalSource={type:"service-query",path:"",provider:"netsuite",queryConfig:em}:s.externalSource=null;let l=await fetch(`/api/organization/value-sets/${r.type}${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!l.ok)throw Error(await l.text());if(ea&&e.length>0){let t={};for(let[a,s]of Object.entries(eM)){let l={};for(let[a,t]of Object.entries(s))t&&e.some(e=>e.key===a)&&(l[a]=t);t[a]=l}let s=await fetch(`/api/organization/value-sets/${r.type}/mappings${a}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mappings:t})});if(!s.ok)throw Error(await s.text())}C(!0),await c(),t(!1)}catch{C(!1),v(f("errors.saveFailed"))}finally{L(!1)}},e$=ei.map((e,a)=>({...e,rowIndex:a})),e_=et.map(e=>({key:e.key,label:E.fieldLabel(r.type,e),format:(t,s)=>((e,t)=>{let s,l=null==(s=e[t.key])?"":Array.isArray(s)?s.join(", "):String(s),i=E.fieldLabel(r.type,t),n=a=>en(s=>s.map((s,l)=>l===e.rowIndex?{...s,[t.key]:a}:s));if(G){let e=t.options?.find(e=>e.value===l);return(0,a.jsx)("span",{className:"break-words text-meta text-ink-muted",children:"select"===t.type?e?E.optionLabel(r.type,t,e):"â":l||"â"})}return"select"===t.type?(0,a.jsxs)(u.Select,{value:l||"__none",onValueChange:e=>n("__none"===e?"":e),children:[(0,a.jsx)(u.SelectTrigger,{className:"min-w-36","aria-label":`${e.label} â ${i}`,children:(0,a.jsx)(u.SelectValue,{placeholder:"â"})}),(0,a.jsx)(u.SelectContent,{children:t.options?.map(e=>(0,a.jsx)(u.SelectItem,{value:e.value||"__none",children:E.optionLabel(r.type,t,e)},e.value||"__none"))})]}):(0,a.jsx)(o.Input,{type:"number"===t.type?"number":"date"===t.type?"date":"text",value:l,onCh
1ange:e=>n(e.target.value),"aria-label":`${e.label} â ${i}`,className:"min-w-36"})})(s,e)})),eK=[{key:"label",label:f("mapping.yourData"),format:(e,t)=>G?(0,a.jsx)("span",{className:"break-words",children:t.label}):(0,a.jsx)(o.Input,{value:t.label,onChange:e=>{var a,s;return a=t.rowIndex,s=e.target.value,void en(e=>e.map((e,t)=>t!==a?e:{...e,label:s,key:e.key||(0,H.slugify)(s)}))},onBlur:()=>{var e;return e=t.rowIndex,void en(a=>a.map((a,t)=>t!==e?a:!a.key&&a.label?{...a,key:(0,H.slugify)(a.label)}:a))},placeholder:f("dataSet.labelPlaceholder"),"aria-label":f("mapData.labelColumn"),className:"min-w-44"})},...e_,...ee.map(e=>({key:e,label:(0,a.jsxs)(a.Fragment,{children:[e.charAt(0).toUpperCase()+e.slice(1)," ",(0,a.jsxs)("span",{className:"font-normal",children:["(",r.availableServiceEntities[e].entities.length,")"]})]}),format:(t,s)=>{let l=s.key||(0,H.slugify)(s.label);return(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:`${s.label} â ${e}`,value:eM[e]?.[l]||Y,onChange:a=>{eR(t=>({...t,[e]:{...t[e],[l]:a===Y?"":a}}))},placeholder:f("mapping.notMapped"),options:[{value:Y,label:f("mapping.notMapped")},...r.availableServiceEntities[e].entities.map(e=>({value:e.id,label:e.name}))],className:"min-w-44"})}})),...G?[]:[{key:"__remove",label:null,format:(e,t)=>(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":`${j("delete")} ${t.label}`,onClick:()=>{var e;let a;return a=ei[e=t.rowIndex],void(en(a=>a.filter((a,t)=>t!==e)),a.key&&eR(e=>{let t={...e};for(let e of ee)t[e]?.[a.key]&&(t[e]={...t[e]},delete t[e][a.key]);return t}))},children:(0,a.jsx)(T.Trash2,{className:"size-4"})})}
1]],eH="entries"===el&&(ea||es);return(0,a.jsxs)(a.Fragment,{children:[w&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:f("success.saved")}),(0,a.jsx)(n.Dialog,{open:e,onOpenChange:e=>{e?t(!0):eI()},children:(0,a.jsxs)(n.DialogContent,{size:eH?"xl":"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:V})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-4",onChange:()=>C(!1),children:[S&&(0,a.jsx)(d.Notice,{title:f("pull.pulled"),description:S}),"seasons"===r.type&&(0,a.jsxs)($.default,{href:D?(0,W.buildAuthenticatedActionHref)(D,"manage-catalogues"):(0,W.buildLegacyActionHref)("manage-catalogues"),className:"flex items-center gap-2 rounded-lg border bg-primary/2 px-4 py-3 text-sm text-foreground hover:bg-primary/5 transition-colors",children:[(0,a.jsx)("span",{className:"flex-1",children:f("seasonActionLink",{action:f("mapData.manageCatalogues")})}),(0,a.jsx)(P.ArrowUpRight,{className:"h-4 w-4 text-muted-foreground"})]}),"seasons"!==r.type&&(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs font-medium text-muted-foreground",children:f("source.dataSource")}),(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:f("source.dataSource"),value:"service"===el?`service:${ec}`:el,onChange:e=>{e.startsWith("service:")?(er("service"),ed(e.replace("service:",""))):(er(e),"service"!==e&&ed(""),"service-query"===e&&eu&&!em&&eh(eu.initialConfig()))},placeholder:f("source.selectSource"),options:[{value:"entries",label:f("source.entries")},{value:"url",label:f("source.url")},...r.type in J?[{value:"service-query",label:f("mapData.serviceQueryOption")}]:[],...eo.map(e=>({value:`service:${e}`,label:e.charAt(0).toUpperCase()+e.slice(1)}))],className:"mt-1 w-full"})]}),"service-query"===el&&eu&&em&&"netsuiteLocation"!==em.type&&(p=eu.Form,(0,a.jsxs)("div",{className:"rounded-lg border bg-muted/20 p-3 space-y-2",children:[(0,a.jsx)("p",{className:"text-eyebrow text-muted-foreground",children:f("mapData.netsuiteQuery")}),(0,a.jsx)(p,{value:em,onChange:e=>eh(e)})]})),"service-query"===el&&(es||em?.type==="netsuiteLocation")&&ei.length>0&&(g=(x=em?.type==="netsuiteLocation")?new Set((em.excludeIds??[]).map(e=>String(e))):new Set,(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("p",{className:"text-eyebrow text-muted-foreground",children:f("mapData.tagEntries")}),(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:f("mapData.tagEntriesDescription")}),(0,a.jsx)(R.DataTable,{rows:e$,getRowKey:e=>e.key||e.rowIndex,columns:[{key:"label",label:f("mapData.labelColumn"),rowHeader:!0,format:(e,t)=>(0,a.jsx)("span",{className:"break-words",children:t.label})},...e_,...x?[{key:"__excluded",label:f("mapData.exclude"),format:(e,t)=>{let s=String(t.externalId??"");return(0,a.jsx)(_.Checkbox,{checked:g.has(s),onCheckedChange:()=>(e=>{if(!x||!e)return;let a=em.excludeIds??[],t=parseInt(e,10);if(isNaN(t))return;let s=a.includes(t)?a.filter(e=>e!==t):[...a,t];eh({...em,excludeIds:s})})(s),disabled:!s,"aria-label":f("mapData.excludeEntry",{label:t.label})})}}]:[]]})]})),"url"===el&&(0,a.jsx)("div",{className:"space-y-3",children:eC?(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:f("source.urlDescription")}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs font-medium text-muted-foreground",children:f("source.url")}),(0,a.jsxs)("div",{className:"flex gap-2 mt-1",children:[(0,a.jsx)(o.Input,{value:ep,onChange:e=>ex(e.target.value),placeholder:f("mapData.urlPlaceholder"),className:"text-sm flex-1"}),ep.trim()&&(0,a.jsxs)(i.Button,{variant:"outline",size:"sm",onClick:async()=>{eL(!0);try{let e=await fetch(`/api/organization/value-sets/parse-headers?url=${encodeURIComponent(ep.trim())}`);if(e.ok){let a=await e.json();eD(a.headers??[])}}catch{}finally{eL(!1)}},disabled:eA,children:[eA&&(0,a.jsx)(B.Loader2,{className:"h-3.5 w-3.5 mr-1 animate-spin"}),f("add.catalog.fetchHeaders")]})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs font-medium text-muted-foreground",children:f("externalSource.provider")}),(0,a.jsx)("p",{className:"text-chip text-muted-foreground",children:f("externalSource.providerHint")}),(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:f("externalSource.provider"),value:eg||X,onChange:e=>ef(e===X?"":e),placeholder:f("externalSource.providerExternal"),options:[{value:X,label:f("externalSource.providerExternal")},...m.map(e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)}))],className:"mt-1 w-full"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs font-medium text-muted-foreground",children:f("add.catalog.keyColumn")}),eF.length>0?(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:f("add.catalog.keyColumn"),placeholder:f("add.catalog.autoDetect"),options:eE,value:ey,onChange:ej,allowClear:!0,className:"w-full mt-1"}):(0,a.jsx)(o.Input,{value:ey,onChange:e=>ej(e.target.value),placeholder:f("externalSource.keyColumnPlaceholder"),className:"h-9 text-sm mt-1"})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs font-medium text-muted-foreground",children:f("add.catalog.labelColumn")}),eF.length>0?(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:f("add.catalog.labelColumn"),placeholder:f("add.catalog.autoDetect"),options:eE,value:eb,onChange:ev,allowClear:!0,className:"w-full mt-1"}):(0,a.jsx)(o.Input,{value:eb,onChange:e=>ev(e.target.value),placeholder:f("externalSource.labelColumnPlaceholder"),className:"h-9 text-sm mt-1"})]})]}),(0,a.jsxs)("div",{className:"border-t pt-3 space-y-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs font-medium text-muted-foreground",children:f("add.catalog.filterColumn")}),(0,a.jsx)("p",{className:"text-chip text-muted-foreground",children:f("add.catalog.filterHint")}),eF.length>0?(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:f("add.catalog.filterColumn"),placeholder:f("add.catalog.noFilter"),options:eE,value:eS,onChange:e=>{ek(e),e||eN("")},allowClear:!0,className:"w-full mt-1"}):(0,a.jsx)(o.Input,{value:eS,onChange:e=>{ek(e.target.value),e.target.value||eN("")},placeholder:f("add.catalog.noFilter"),className:"h-9 text-sm mt-1"})]}),eS&&(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{className:"text-xs font-medium text-muted-foreground",children:f("add.catalog.filterValue")}),(0,a.jsx)(o.Input,{value:ew,onChange:e=>eN(e.target.value),placeholder:f("add.catalog.filterValuePlaceholder",{column:eS}),className:"h-9 text-sm mt-1"})]})]}),ep&&(ey||eb)&&(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>eT(!1),children:f("add.catalog.back")})]}):(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"rounded-lg border bg-muted/30 p-3 space-y-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{className:"text-eyebrow text-muted-foreground",children:f("source.url")}),(0,a.jsx)("p",{className:"mt-0.5 break-words text-sm [overflow-wrap:anywhere]",children:ep})]}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-x-6 gap-y-1.5",children:[eg&&(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{className:"text-eyebrow text-muted-foreground",children:f("externalSource.provider")}),(0,a.jsx)("p",{className:"text-sm capitalize",children:eg})]}),ey&&(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{className:"text-eyebrow text-muted-foreground",children:f("add.catalog.keyColumn")}),(0,a.jsx)("p",{className:"text-sm",children:ey})]}),eb&&(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{className:"text-eyebrow text-muted-foreground",children:f("add.catalog.labelColumn")}),(0,a.jsx)("p",{className:"text-sm",children:eb})]}),eS&&(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{className:"text-eyebrow text-muted-foreground",children:f("add.catalog.filterColumn")}),(0,a.jsxs)("p",{className:"text-sm",children:[eS," = ",ew||"â"]}
1)]})]})]}),(0,a.jsxs)(i.Button,{type:"button",variant:"outline",size:"sm",onClick:async()=>{if(eT(!0),ep.trim()&&0===eF.length){eL(!0);try{let e=await fetch(`/api/organization/value-sets/parse-headers?url=${encodeURIComponent(ep.trim())}`);if(e.ok){let a=await e.json();eD(a.headers??[])}}catch{}finally{eL(!1)}}},disabled:eA,children:[eA?(0,a.jsx)(B.Loader2,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):(0,a.jsx)(I.Pencil,{className:"h-3.5 w-3.5 mr-1.5"}),f("dataSet.editMapping")]})]})}),"service"===el&&ec&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:f("source.serviceDescription")}),"entries"===el&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(R.DataTable,{rows:e$,columns:eK,getRowKey:e=>e.rowIndex,empty:(0,a.jsx)(N.StatePanel,{form:"inline",title:f("dataSet.noEntries")})}),!G&&(0,a.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,a.jsxs)(i.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{en(e=>[...e,{key:"",label:""}])},children:[(0,a.jsx)(z.Plus,{className:"h-4 w-4 mr-1"}),f("dataSet.addEntry")]}),ee.map(e=>{let t=r.availableServiceEntities[e];if(!t||0===t.entities.length)return null;let s=e.charAt(0).toUpperCase()+e.slice(1);return(0,a.jsxs)(i.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>(e=>{let a=r.availableServiceEntities[e];if(!a)return;let t=new Set(ei.map(e=>e.key||(0,H.slugify)(e.label))),s=[],l={...eM[e]||{}};for(let e of a.entities){let a=(0,H.slugify)(e.name);if(t.has(a)){l[a]||(l[a]=e.id);continue}s.push({key:a,label:e.name}),l[a]=e.id,t.add(a)}s.length>0&&en(e=>[...e,...s]),eR(a=>({...a,[e]:l})),k(f("pull.pulledDescription",{count:s.length,provider:e.charAt(0).toUpperCase()+e.slice(1)}))})(e),children:[(0,a.jsx)(O.Download,{className:"h-4 w-4 mr-1"}),f("pull.pullFrom",{provider:s})]},e)})]})]})]}),b&&(0,a.jsx)(d.Notice,{tone:"blocker",title:f("errors.title"),description:b,className:"mx-6 mb-3 shrink-0"}),!G&&(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void eI(),children:f("dataSet.cancel")}),(0,a.jsxs)(i.Button,{onClick:ez,disabled:A,children:[A&&(0,a.jsx)(B.Loader2,{className:"h-4 w-4 animate-spin mr-2"}),f("dataSet.save")]})]})]})})]})}function ee({valueSet:e,onSaved:t,onDeleted:n,isScoped:o=!1,connectedProviders:c,focus:d=!1,alsoUsedBy:u,showOrigin:m=!1}
1){let[h,p]=(0,s.useState)(!1),[x,g]=(0,s.useState)(!1),f=(0,s.useRef)(null),[y,j]=(0,s.useState)(!1);(0,s.useEffect)(()=>{if(!d)return;f.current?.scrollIntoView({behavior:"smooth",block:"center"}),j(!0),p(!0);let e=setTimeout(()=>j(!1),1800);return()=>clearTimeout(e)},[d]);let b=(0,l.useTranslations)("bridge.data"),S=(0,F.useConfirm)(),N=(0,l.useTranslations)("confirmDialog.dataSet"),A=(0,l.useTranslations)("states.delete"),L=M().typeLabel(e.type),E=new Set(e.serviceMappings.filter(e=>e.mappings&&Object.keys(e.mappings).length>0).map(e=>e.provider)),R=Object.keys(e.availableServiceEntities||{}),P=!!e.externalSource,O=e.externalSource?.type,B="service"===O||"service-query"===O,I=e.externalSource?.provider,z=e.data.length,[$,_]=(0,s.useState)(null),[K,H]=(0,s.useState)(!1),[U,q]=(0,s.useState)("ready"),V=e.externalSource?`${e.externalSource.type}:${e.externalSource.provider??e.externalSource.path}`:"";(0,s.useEffect)(()=>{if(!P){_(null),q("ready");return}H(!0),fetch(`/api/organization/value-sets/external-count?id=${e.id}`).then(async e=>{let a=await e.json().catch(()=>null);if(e.ok&&a){_(a.count),q("ready");return}_(null),q(a?.state==="not-ready"?"not-ready":"error")}).catch(()=>{_(null),q("error")}).finally(()=>H(!1))},[e.id,P,V]);let G=P?$:z,J=async()=>{await S({title:N("title",{type:L,scope:e.scope}
1),description:N("description"),confirmLabel:N("confirm"),tone:"danger",onConfirm:async()=>{g(!0);try{if(!(await fetch(`/api/organization/value-sets/${encodeURIComponent(e.type)}?scope=${encodeURIComponent(e.scope)}`,{method:"DELETE"})).ok)throw Error(A("failed",{object:L}))}finally{g(!1)}}})&&(n?.(L),t())};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{ref:f,className:(0,D.cn)("flex flex-wrap items-center gap-2 rounded-lg transition-shadow",y?"ring-2 ring-ring/50":""),children:[(0,a.jsx)(r.ManageRow,{className:"basis-full sm:basis-0 sm:flex-1",wrap:!0,title:L,"aria-label":`${b("dataSet.manage")} ${L}`,onClick:()=>p(!0),summary:(0,a.jsxs)("span",{className:"flex flex-col gap-1.5",children:[(0,a.jsx)("span",{children:K?(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-24"}):P&&"not-ready"===U?b("dataSet.fetching"):P&&"error"===U?b("dataSet.loadFailed"):null===G||0===G?b("dataSet.noEntries"):b("dataSet.entries",{count:G})}),(0,a.jsxs)("span",{className:"flex flex-wrap gap-1",children:[e.externalSource?(0,a.jsxs)(v.Badge,{tone:"neutral",title:B?I:e.externalSource.path,children:[(0,a.jsx)(C.Globe,{"aria-hidden":"true",className:"size-3"}),B?I?I.charAt(0).toUpperCase()+I.slice(1):b("dataSet.service"):"URL"]}):m?(0,a.jsx)(v.Badge,{tone:"neutral",children:b("dataSet.keptInAhti")}):null,u?(0,a.jsx)(v.Badge,{tone:"neutral",className:"h-auto min-h-5 max-w-full whitespace-normal break-words",children:b("dataSet.alsoUsedBy",{phases:u})}):null,o?(0,a.jsx)(v.Badge,{tone:"neutral",className:"h-auto min-h-5 max-w-full whitespace-normal break-all",children:e.scope}):null,R.map(e=>(0,a.jsx)(v.Badge,{tone:E.has(e)?"progress":"neutral",className:"h-auto min-h-5 max-w-full whitespace-normal break-all capitalize",children:e},e))]})]})}),o&&(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon",onClick:J,disabled:x,"aria-label":N("deleteLabel",{type:L,scope:e.scope}),title:N("deleteLabel",{type:L,scope:e.scope}),className:"size-8 text-lingon-ink hover:bg-lingon-soft hover:text-lingon-ink",children:x?(0,a.jsx)(w.Spinner,{size:14}):(0,a.jsx)(T.Trash2,{"aria-hidden":"true",className:"h-4 w-4"})})]}),h&&(0,a.jsx)(Z,{open:h,onOpenChange:p,valueSet:e,onSaved:t,connectedProviders:c})]})}let ea="/api/organization/value-sets/salesSpecialHandling?scope=*",et="discontinued-preorder-reservation";function es(){return{enabled:!1,productAttributeKey:"",productAttributeLevel:"sku",value:"",netsuiteAllocationStrategyId:"",netsuiteAllocationStrategyName:""}}function el(e){return e?{enabled:e.enabled,productAttributeKey:e.condition.productAttributeKey,productAttributeLevel:e.condition.productAttributeLevel,value:String(e.condition.value),netsuiteAllocationStrategyId:e.effect.destination?.provider==="netsuite"?e.effect.destination.allocationStrategy.internalId:"",netsuiteAllocationStrategyName:e.effect.destination?.provider==="netsuite"?e.effect.destination.allocationStrategy.displayName:""}:es()}function er(){let e=(0,l.useTranslations)("bridge.data.salesSpecialHandling"),t=(0,m.useServerMessage)(),[c,u]=(0,s.useState)(null),[p,x]=(0,s.useState)(!1),g=(0,F.useConfirmDiscard)(),[f,y]=(0,s.useState)(!0),[j,b]=(0,s.useState)(!1),[v,S]=(0,s.useState)(!1),[N,C]=(0,s.useState)([]),[T,D]=(0,s.use
1State)(),[A,L]=(0,s.useState)(es()),[E,M]=(0,s.useState)([]),[R,P]=(0,s.useState)(!1),[O,I]=(0,s.useState)(null),z=(0,s.useCallback)(async()=>{y(!0);try{let[e,a]=await Promise.all([fetch("/api/organization/value-sets/productAttributes?scope=*"),fetch(ea)]);if(e.ok){let a=await e.json();C(Array.isArray(a?.data)?a.data:[])}if(a.ok){let e=await a.json(),t=Array.isArray(e?.data)?e.data:[];D(t.find(e=>e.key===et))}}catch(e){console.error("[SalesSpecialHandlingCard] fetch failed",e)}finally{y(!1)}},[]);(0,s.useEffect)(()=>{z()},[z]);let $=(0,s.useCallback)(async()=>{P(!0),I(null);try{let e=await fetch("/api/organization/netsuite/order-allocation-strategies");if(!e.ok){let a=await e.json().catch(()=>({error:`HTTP ${e.status}`}));throw Error(a.error??`HTTP ${e.status}`)}let a=await e.json(),t=Array.isArray(a?.strategies)?a.strategies:[];M(t)}catch(e){console.error("[SalesSpecialHandlingCard] allocation strategy fetch failed",e),I(e instanceof Error?e.message:String(e)),M([])}finally{P(!1)}},[]);(0,s.useEffect)(()=>{j&&L(el(T))},[j,T]),(0,s.useEffect)(()=>{j&&$()},[$,j]);let _=j&&JSON.stringify(A)!==JSON.stringify(el(T)),H=async()=>{v||(!_||await g())&&b(!1)},U=(0,s.useMemo)(()=>N.find(e=>e.key===A.productAttributeKey&&e.level===A.productAttributeLevel),[N,A.productAttributeKey,A.productAttributeLevel]),q=(0,s.useMemo)(()=>{let e;return e=U?.constructor,e?.kind==="selected-from-source"&&Array.isArray(e.inlineOptions)?e.inlineOptions.map(e=>({value:String(e.value),label:e.label??String(e.value)})):U?.dataType==="boolean"?[{value:"true",label:"True"},{value:"false",label:"False"}]:[]},[U]),G=(0,s.useMemo)(()=>A.netsuiteAllocationStrategyId&&A.netsuiteAllocationStrategyName&&!E.some(e=>e.id===A.netsuiteAllocationStrategyId)?[...E,{id:A.netsuiteAllocationStrategyId,name:A.netsuiteAllocationStrategyName}]:E,[E,A.netsuiteAllocationStrategyId,A.netsuiteAllocationStrategyName]),J=T?.enabled?e("summaryEnabled",{attribute:T.condition.productAttributeKey,value:String(T.condition.value),strategy:T.effect.destination?.provider==="netsuite"?T.effect.destination.allocationStrategy.displayName:e("strategyValue")}):e("summaryDisabled"),Q=async()=>{u(null),x(!1),S(!0);try{if(!A.productAttributeKey)throw Error(e("errors.attributeRequired"));if(!A.value.trim())throw Error(e("errors.valueRequired"));if(!A.netsuiteAllocationStrategyId.trim()||!A.netsuiteAllocationStrategyName.trim())throw Error(e("errors.allocationStrategyRequired"));let a=U?.dataType==="boolean"?"true"===A.value:A.value.trim(),t={key:et,label:e("ruleLabel"),enabled:A.enabled,condition:{productAttributeKey:A.productAttributeKey,productAttributeLevel:A.productAttributeLevel,operator:"equals",value:a},effect:{kind:"sales-order-line-allocation",strategy:"reserve-from-on-hand",destination:{provider:"netsuite",allocationStrategy:{internalId:A.netsuiteAllocationStrategyId.trim(),displayName:A.netsuiteAllocationStrategyName.trim()}}}},s=await fetch(ea,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:"Sales special handling",data:[t]})});if(!s.ok)throw(0,h.serverMessageError)(await s.json().catch(()=>null),`HTTP ${s.status}`);let l=await s.json(),r=Array.isArray(l?.data)?l.data:[t];D(r.find(e=>e.key===et)??t),x(!0),b(!1)}catch(e){u(e instanceof Error?t(e):String(e))}finally{S(!1)}};return f?(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:J,onClick:()=>{x(!1),u(null),b(!0)}}),p&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("toast.saved")}),(0,a.jsx)(n.Dialog,{open:j,onOpenChange:e=>{e?b(!0):H()},children:(0,a.jsxs)(n.DialogContent,{size:"lg",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-4",children:[(0,a.jsxs)("label",{className:"flex items-center justify-between gap-4 roun
1ded-lg border bg-muted/20 px-4 py-3",children:[(0,a.jsxs)("span",{className:"min-w-0 space-y-0.5 break-words [overflow-wrap:anywhere]",children:[(0,a.jsx)("span",{className:"block text-sm font-medium",children:e("enabled")}),(0,a.jsx)("span",{className:"block text-xs text-muted-foreground",children:e("enabledDescription")})]}),(0,a.jsx)(V.Switch,{checked:A.enabled,onCheckedChange:e=>L(a=>({...a,enabled:e})),"aria-label":e("enabled")})]}),(0,a.jsxs)("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)] gap-3 sm:grid-cols-[minmax(0,1fr)_160px]",children:[(0,a.jsxs)("label",{className:"block min-w-0 space-y-1.5",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:e("attribute")}),(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:e("attribute"),placeholder:e("attributePlaceholder"),options:N.map(e=>({value:`${e.key}:${e.level}`,label:`${e.label} (${e.level})`})),value:A.productAttributeKey?`${A.productAttributeKey}:${A.productAttributeLevel}`:"",onChange:e=>{let[a,t]=e.split(":");L(e=>({...e,productAttributeKey:a,productAttributeLevel:t,value:""}))},allowClear:!0,className:"h-9 w-full min-w-0 sm:w-full sm:min-w-0"})]}),(0,a.jsxs)("label",{className:"block min-w-0 space-y-1.5",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:e("value")}),q.length>0?(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:e("value"),placeholder:e("valuePlaceholder"),options:q,value:A.value,onChange:e=>L(a=>({...a,value:e})),allowClear:!0,className:"h-9 w-full min-w-0 sm:w-full sm:min-w-0"}):(0,a.jsx)(o.Input,{value:A.value,onChange:e=>L(a=>({...a,value:e.target.value})),placeholder:e("valuePlaceholder")})]})]}),(0,a.jsxs)("div",{className:"rounded-lg border bg-muted/20 px-4 py-3 text-sm",children:[(0,a.jsx)("span",{className:"font-medium",children:e("strategy")}),(0,a.jsx)("span",{className:"ml-2 text-muted-foreground",children:e("strategyValue")})]}),(0,a.jsxs)("div",{className:"min-w-0 rounded-lg border bg-muted/20 px-4 py-3 space-y-3",children:[(0,a.jsxs)("label",{className:"block min-w-0 space-y-1.5",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:e("allocationStrategy")}),(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:e("allocationStrategy"),value:A.netsuiteAllocationStrategyId,disabled:R||0===G.length,onChange:e=>{let a=G.find(a=>a.id===e);L(t=>({...t,netsuiteAllocationStrategyId:e,netsuiteAllocationStrategyName:a?.name??""}))},placeholder:R?e("loadingStrategies"):e("allocationStrategyPlaceholder"),options:G.map(e=>({value:e.id,label:e.name})),className:"w-full min-w-0 sm:w-full sm:min-w-0"})]}),R&&(0,a.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,a.jsx)(w.Spinner,{size:14}),(0,a.jsx)("span",{children:e("loadingStrategies")})]}),!R&&O&&(0,a.jsx)(d.Notice,{tone:"blocker",description:e("strategiesLoadFailed")}),!R&&!O&&0===G.length&&(0,a.jsx)("div",{className:"text-xs text-muted-foreground",children:e("noStrategies")})]})]}),c&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("toast.saveFailed"),description:c,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void H(),disabled:v,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:Q,disabled:v||R,children:[v&&(0,a.jsx)(B.Loader2,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}),e("save")]})]})]})})]})}var ei=e.i(445077),en=e.i(73702),eo=e.i(154477),ec=e.i(141541);let ed="/api/organization/value-sets/orderFormFilters?scope=*",eu=["product","article","sku"],em=["ahti-grid-v3","wholesale-preorder-v1"],eh={product:"levels.product",article:"levels.article",sku:"levels.sku"};function ep(e){return`${e.key}:${e.level}`}function ex(e){return{key:ep(e),label:e.label,attributeKey:e.key,attributeLevel:e.level,enabled:!0}}function eg(e,a){return a("attributeOption",{label:e.label,level:a(eh[e.level])})}function ef(){return{"ahti-grid-v3":[],"wholesale-preorder-v1":[]}}function ey(e,a){return 0===e?a("groupingPrimary"):1===e?a("groupingSecondary"):2===e?a("groupingTertiary"):a("groupingNumbered",{number:e+1})}function ej(e,a){return Array.from(new Set(e.filter(e=>a.has(e))))}function eb(){let e=(0,l.useTranslations)("bridge.data.orderFormFilters"),t=(0,m.useServerMessage)(),[c,p]=(0,s.use
1State)(null),[x,g]=(0,s.useState)(!1),f=(0,F.useConfirmDiscard)(),[y,j]=(0,s.useState)(!0),[b,v]=(0,s.useState)(!1),[S,w]=(0,s.useState)(!1),[N,C]=(0,s.useState)([]),[T,D]=(0,s.useState)([]),[A,L]=(0,s.useState)(eo.MIN_ORDER_FORM_SHEET_COUNT),[E,M]=(0,s.useState)(eo.DEFAULT_ORDER_FORM_LAYOUT_KEY),[R,P]=(0,s.useState)([]),[O,I]=(0,s.useState)(eo.DEFAULT_PRODUCT_DATA_SHEET_PROFILE_KEY),[z,$]=(0,s.useState)([]),[H,U]=(0,s.useState)(),[q,V]=(0,s.useState)(new Set),[G,J]=(0,s.useState)(ef),[Q,W]=(0,s.useState)(String(eo.MIN_ORDER_FORM_SHEET_COUNT)),[Y,X]=(0,s.useState)(eo.DEFAULT_ORDER_FORM_LAYOUT_KEY),[Z,ee]=(0,s.useState)(eo.DEFAULT_PRODUCT_DATA_SHEET_PROFILE_KEY),[ea,et]=(0,s.useState)(""),[es,el]=(0,s.useState)("all"),er=(0,s.useCallback)(async()=>{j(!0);try{let[e,a,t]=await Promise.all([fetch("/api/organization/value-sets/productAttributes?scope=*"),fetch(ed),fetch("/api/organization/output-profiles")]);if(e.ok){let a=await e.json();C(Array.isArray(a?.data)?a.data:[])}if(a.ok){let e=await a.json(),t=(0,eo.normalizeOrderFormConfig)(e?.data);D(t.filters),L(t.workbook.orderSheetCount),M(t.workbook.layoutKey),P(t.workbook.groupByFilterKeys),U(t.workbook.layouts),I(t.productDataSheetProfileKey)}else 404===a.status&&(D([]),L(eo.MIN_ORDER_FORM_SHEET_COUNT),M(eo.DEFAULT_ORDER_FORM_LAYOUT_KEY),P([]),U(void 0),I(eo.DEFAULT_PRODUCT_DATA_SHEET_PROFILE_KEY));if(t.ok){let e=await t.json();$(function(e){let a=new Map;for(let t of e.systemProfiles??[])t.key&&a.set(t.key,t);for(let t of e.profiles??[])t.key&&!a.has(t.key)&&a.set(t.key,t);return Array.from(a.values())}(e))}else{let e=await fetch("/api/organization/value-sets/outputProfiles?scope=*");if(e.ok){let a=await e.json();$(Array.isArray(a.data)?a.data.map(e=>({key:e.key,label:e.label})):[])}else 404===e.status&&$([])}}catch(e){console.error("[OrderFormFiltersCard] fetch failed",e)}finally{j(!1)}},[]);(0,s.useEffect)(()=>{er()},[er]),(0,s.useEffect)(()=>{b&&(V(new Set((0,eo.normalizeOrderFormFilters)(T).map(e=>e.key))),J({"ahti-grid-v3":H?.["ahti-grid-v3"]?.groupByFilterKeys??R,"wholesale-preorder-v1":H?.["wholesale-preorder-v1"]?.groupByFilterKeys??R}),W(String(A)),X(E),ee(O),et(""),el("all"))},[T,R,H,E,b,A,O]);let ei=JSON.stringify({keys:(0,eo.normalizeOrderFormFilters)(T).map(e=>e.key).sort(),grouping:{"ahti-grid-v3":H?.["ahti-grid-v3"]?.groupByFilterKeys??R,"wholesale-preorder-v1":H?.["wholesale-preorder-v1"]?.groupByFilterKeys??R},count:String(A),layout:E,profile:O}),eh=JSON.stringify({keys:Array.from(q).sort(),grouping:{"ahti-grid-v3":G["ahti-grid-v3"]??[],"wholesale-preorder-v1":G["wholesale-preorder-v1"]??[]},count:Q,layout:Y,profile:Z}),eb=b&&eh!==ei,ev=async()=>{S||(!eb||await f())&&v(!1)},eS=(0,s.useMemo)(()=>N.filter(e=>e.key&&e.label&&eu.includes(e.level)),[N]),ek=(0,s.useMemo)(()=>eS.reduce((e,a)=>({...e,[a.level]:e[a.level]+1}),{product:0,article:0,sku:0}),[eS]),ew=(0,s.useMemo)(()=>{let e=ea.trim().toLowerCase();return eS.filter(a=>("all"===es||a.level===es)&&(!e||[a.label,a.key,a.level].some(a=>a.toLowerCase().includes(e))))},[es,ea,eS]),eN=(0,eo.groupByFilterKeysForLayout)({layoutKey:E,groupByFilterKeys:R,layouts:H}),eC=0===T.length?e("summaryWithSheetsAndGroups",{filters:e("summaryEmpty"),count:A,groups:eN.length}):e("summaryWithSheetsAndGroups",{filters:T.map(e=>e.label).join(", "),count:A,groups:eN.length}),eT=async()=>{p(null),g(!1),w(!0);try{let e=em.flatMap(e=>G[e]??[]),a=new Set([...Array.from(q),...e]),t=eS.filter(e=>a.has(ep(e))).map(ex),s=(0,eo.normalizeOrderSheetCount)(Q),l=new Set(t.map(e=>e.key)),r=ej(G["ahti-grid-v3"]??[],l),i={};for(let e of em){if("ahti-grid-v3"===e||e!==Y&&!H?.[e])continue;let a=ej(G[e]??[],l);i[e]={groupByFilterKeys:a}}let n=(0,eo.buildOrderFormConfigData)(t,{layoutKey:Y,orderSheetCount:s,groupByFilterKeys:r,...i&&Object.keys(i).length>0?{layouts:i}:{}},{productDataSheetProfileKey:Z}),o=await fetch(ed,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:"Order forms",data:n})});if(!o.ok)throw(0,h.serverMessageError)(await o.json().catch(()=>null),`HTTP ${o.status}`);let c=await o.json(),d=(0,eo.normalizeOrderFormConfig)(c?.data??n);D(d.filters),L(d.workbook.orderSheetCount),M(d.workbook.layoutKey),P(d.workbook.groupBy
1FilterKeys),U(d.workbook.layouts),I(d.productDataSheetProfileKey),(0,ec.invalidateSellOrderFormsCache)({family:"season-commercial"}),g(!0),v(!1)}catch(e){p(t(e,{uncoded:"generic"}))}finally{w(!1)}};if(y)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});let eF=new Set(eS.map(ep)),eD=ej(G[Y]??[],eF),eA=new Set([...Array.from(q),...eD]),eL=0===eS.length?0:Math.min(3,eS.length),eE="wholesale-preorder-v1"!==Y,eM=z.length>0?z:[{key:O,label:O}];return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:eC,onClick:()=>{g(!1),p(null),v(!0)}}),x&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("toast.saved")}),(0,a.jsx)(n.Dialog,{open:b,onOpenChange:e=>{e?v(!0):ev()},children:(0,a.jsxs)(n.DialogContent,{size:"lg",scrollable:!0,children:[(0,a.jsxs)(n.DialogHeader,{children:[(0,a.jsx)(n.DialogTitle,{children:e("title")}),(0,a.jsx)(n.DialogDescription,{children:e("description")})]}),(0,a.jsxs)(n.DialogBody,{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsx)("div",{className:"rounded-lg border bg-muted/30 px-3 py-3",children:(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-[1fr_auto]",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("label",{htmlFor:"order-form-sheet-count",className:"text-sm font-medium",children:e("orderSheets.label")}),(0,a.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:e("orderSheets.description")})]}),(0,a.jsx)(o.Input,{id:"order-form-sheet-count",type:"number",min:eo.MIN_ORDER_FORM_SHEET_COUNT,max:eo.MAX_ORDER_FORM_SHEET_COUNT,step:1,value:Q,onChange:e=>W(e.target.value),"aria-label":e("orderSheets.label"),className:"w-24 text-center"})]})}),(0,a.jsx)("div",{className:"rounded-lg border bg-muted/30 px-3 py-3",children:(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-[1fr_220px]",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("label",{htmlFor:"order-form-layout",className:"text-sm font-medium",children:e("workbookLayout")}),(0,a.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:e("workbookLayoutDescription")})]}),(0,a.jsxs)(u.Select,{value:Y,onValueChange:e=>X(e),children:[(0,a.jsx)(u.SelectTrigger,{id:"order-form-layout","aria-label":e("workbookLayout"),className:"h-9 w-full text-sm",children:(0,a.jsx)(u.SelectValue,{})}),(0,a.jsxs)(u.SelectContent,{children:[(0,a.jsx)(u.SelectItem,{value:"ahti-grid-v3",children:e("layoutAhtiGrid")}),(0,a.jsx)(u.SelectItem,{value:"wholesale-preorder-v1",children:e("layoutWholesalePreorder")})]})]})]})}),(0,a.jsx)("div",{className:"rounded-lg border bg-muted/30 px-3 py-3",children:(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-[1fr_260px]",children:[(0,a.jsx)("div",{className:"min-w-0",children:(0,a.jsx)("label",{htmlFor:"order-form-product-sheet",className:"text-sm font-medium",children:e("globalProductDataSheet")})}),(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:e("globalProductDataSheet"),placeholder:e("globalProductDataSheet"),options:eM.map(e=>({value:e.key,label:e.label})),value:Z,onChange:ee,disabled:0===eM.length,className:"h-9 w-full min-w-0"})]})}),(0,a.jsx)("div",{className:"rounded-lg border bg-muted/30 px-3 py-3",children:(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("div",{className:"min-w-0",children:[(0,a.jsx)("p",{className:"text-sm font-medium",children:e("groupingOrder")}),(0,a.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:e("groupingOrderDescription")})]}),0===eL?(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:e("groupingEmpty")}):(0,a.jsx)("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:Array.from({length:eL},(t,s)=>{let l=eD[s]??"",r=new Set(eD.filter((e,a)=>a!==s));return(0,a.jsxs)("label",{className:"min-w-0 space-y-1",children:[(0,a.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:ey(s,e)}),(0,a.jsx)(K.SearchablePickerButton,{ariaLabel:ey(s,e),placeholder:e("noGrouping"),options:eS.filter(e=>{let a=ep(e);return a===l||!r.has(a)}).map(a=>({value:ep(a),label:eg(a,e)}
1)),value:l,onChange:e=>{J(a=>{let t=new Set(eS.map(ep)),l=ej(a[Y]??[],t).filter((a,t)=>t!==s&&a!==e);return e&&l.splice(Math.min(s,l.length),0,e),{...a,[Y]:ej(l,t)}})},allowClear:!0,className:"h-9 w-full min-w-0"})]},`${Y}:${s}`)})})]})}),eE&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)(en.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),(0,a.jsx)(o.Input,{type:"search",value:ea,onChange:e=>et(e.target.value),placeholder:e("searchPlaceholder"),"aria-label":e("searchPlaceholder"),className:"pl-9"})]}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-1.5","aria-label":e("levelFilterLabel"),children:[(0,a.jsxs)(i.Button,{type:"button",size:"sm",variant:"all"===es?"default":"outline",onClick:()=>el("all"),"aria-label":e("levels.all"),children:[e("levels.all"),(0,a.jsx)("span",{className:"ml-1.5 text-xs opacity-70",children:eS.length})]}),eu.map(t=>(0,a.jsxs)(i.Button,{type:"button",size:"sm",variant:es===t?"default":"outline",onClick:()=>el(t),"aria-label":e(`levels.${t}`),children:[e(`levels.${t}`),(0,a.jsx)("span",{className:"ml-1.5 text-xs opacity-70",children:ek[t]})]},t))]})]})]}),eE&&(0,a.jsx)("div",{className:"min-w-0","data-testid":"order-form-filters-list",children:0===eS.length?(0,a.jsx)("div",{className:"rounded-lg border border-dashed px-4 py-5 text-sm text-muted-foreground",children:e("emptyAttributes")}):0===ew.length?(0,a.jsx)("div",{className:"rounded-lg border border-dashed px-4 py-5 text-sm text-muted-foreground",children:e("emptySearch")}):(0,a.jsx)("div",{className:"space-y-1.5",children:ew.map(t=>{let s=ep(t),l=eg(t,e),r=q.has(s);return(0,a.jsxs)("div",{className:"flex min-h-11 items-center gap-3 rounded-lg border border-transparent px-3 py-2 hover:bg-muted",children:[(0,a.jsx)(_.Checkbox,{checked:r,onCheckedChange:e=>{var a;return a=!0===e,void(V(e=>{let t=new Set(e);return a?t.add(s):t.delete(s),t}),!a&&J(e=>Object.fromEntries(em.map(a=>[a,e[a].filter(e=>e!==s)]))))},"aria-label":l}),(0,a.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,a.jsx)("span",{className:"block break-words text-sm font-medium [overflow-wrap:anywhere]",children:l}),(0,a.jsx)("span",{className:"block break-words font-mono text-chip text-muted-foreground/70 [overflow-wrap:anywhere]",children:s})]})]},s)})})}),!eE&&(0,a.jsx)("div",{className:"min-w-0","data-testid":"order-form-filters-list-hidden"})]}),c&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("toast.saveFailed"),description:c,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{className:"sm:items-center sm:justify-between","data-testid":"order-form-filters-footer",children:[(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:e("selectedCount",{count:eA.size})}),(0,a.jsxs)("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void ev(),disabled:S,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:eT,disabled:S,children:[S&&(0,a.jsx)(B.Loader2,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}),e("save")]})]})]})]})})]})}var ev=e.i(338412),eS=e.i(506332),ek=e.i(870926),ew=e.i(696186),eN=e.i(634716);let eC="/api/organization/value-sets/manufacturingSteps?scope=*";function eT({icon:e,label:t,meta:s}){return(0,a.jsxs)("li",{className:"flex h-11 items-center gap-3 rounded-lg bg-surface-sunken px-3 text-ink-muted",children:[e,(0,a.jsx)("span",{className:"flex-1 text-sm font-medium text-ink",children:t}),(0,a.jsx)("span",{className:"text-xs",children:s})]})}function eF(){let e=(0,l.useTranslations)("bridge.data.manufacturingSteps"),t=(0,m.useServerMessage)(),c=(0,F.useConfirmDiscard)(),[u,p]=(0,s.useState)(!0),[x,g]=(0,s.useState)([]),[f,y]=(0,s.useState)([]),[j,b]=(0,s.useState)(!1),[v,S]=(0,s.useState)(!1),[w,N]=(0,s.useState)(null),[C,T]=(0,s.useState)(!1),[D,A]=(0,s.useState)(0),L=(0,s.useCallback)(async()=>{p(!0);try{let e=await fetch(eC),a=e.ok?await e.json():null;g(Array.isArray(a?.data)?a.data:[])}catch(e){console.error("[ManufacturingStepsCard] fetch failed",e)}finally{p(!1)}},[]);(0,s.useEffect)(()=>{L()},[L]),(0,s.useEffect)(()=>{j&&y(x)},[j,x]),(0,s.useEffect)(()=>
1{if(!j)return;let e=!1;return fetch("/api/build-work-orders/steps?inProgress=1").then(async e=>e.ok?e.json():null).then(a=>{e||A("number"==typeof a?.inProgress?a.inProgress:0)}).catch(()=>{e||A(0)}),()=>{e=!0}},[j]);let E=j&&JSON.stringify(f)!==JSON.stringify(x),M=async()=>{v||(!E||await c())&&b(!1)},R=(e,a)=>y(t=>{let s=[...t],l=e+a;return l<0||l>=s.length?t:([s[e],s[l]]=[s[l],s[e]],s)}),P=async()=>{N(null),T(!1);let a=f.map(e=>({...e,label:e.label.trim()}));if(a.some(e=>!e.label))return void N(e("nameRequired"));let s=a.map(e=>e.label.toLocaleLowerCase());if(new Set(s).size!==s.length)return void N(e("duplicateNames"));S(!0);try{let e=await fetch(eC,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:"Manufacturing steps",data:a})});if(!e.ok)throw(0,h.serverMessageError)(await e.json().catch(()=>null),`HTTP ${e.status}`);let t=await e.json();g(Array.isArray(t?.data)?t.data:a),T(!0),b(!1)}catch(e){N(e instanceof Error?t(e):String(e))}finally{S(!1)}};return u?(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:x.length>0?x.map(e=>e.label).join(" · "):e("summaryEmpty"),onClick:()=>{T(!1),N(null),b(!0)}}),C&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:j,onOpenChange:e=>{e?b(!0):M()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-3",children:[D>0?(0,a.jsx)(d.Notice,{tone:"attention",description:e("inProgress",{count:D})}):null,(0,a.jsxs)("ol",{className:"flex flex-col gap-1.5","aria-label":e("title"),children:[(0,a.jsx)(eT,{icon:(0,a.jsx)(ew.Play,{className:"size-4","aria-hidden":"true"}),label:e("start"),meta:e("startMeta")}),f.map((t,s)=>(0,a.jsxs)("li",{className:"flex h-11 items-center gap-2 rounded-lg border border-line pl-3 pr-1",children:[(0,a.jsx)("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-full bg-deep text-chip font-semibold text-on-deep tabular-nums",children:s+1}),(0,a.jsx)(o.Input,{"aria-label":e("stepName",{number:s+1}),value:t.label,placeholder:e("namePlaceholder"),onChange:e=>{let a=e.target.value;y(e=>e.map(e=>e.key===t.key?{...e,label:a}:e))},className:"h-8 flex-1 border-0 shadow-none"}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":e("moveUp",{name:t.label}),disabled:0===s,onClick:()=>R(s,-1),children:(0,a.jsx)(eS.ChevronUp,{className:"size-4","aria-hidden":"true"})}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":e("moveDown",{name:t.label}),disabled:s===f.length-1,onClick:()=>R(s,1),children:(0,a.jsx)(ev.ChevronDown,{className:"size-4","aria-hidden":"true"})}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":e("remove",{name:t.label}),onClick:()=>y(e=>e.filter(e=>e.key!==t.key)),children:(0,a.jsx)(eN.X,{className:"size-4","aria-hidden":"true"})})]},t.key)),(0,a.jsx)("li",{children:(0,a.jsxs)(i.Button,{type:"button",variant:"outline",className:"h-11 w-full border-dashed",onClick:()=>y(e=>[...e,{key:function(e){for(;;){let a=`step_${Math.random().toString(36).slice(2,10).padEnd(8,"0")}`;if(!e.has(a))return a}}(new Set(e.map(e=>e.key))),label:""}]),children:[(0,a.jsx)(z.Plus,{className:"size-4","aria-hidden":"true"}),e("add")]})}),(0,a.jsx)(eT,{icon:(0,a.jsx)(ek.CircleCheck,{className:"size-4","aria-hidden":"true"}),label:e("build"),meta:e("buildMeta")})]})]}),w&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:w,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void M(),disabled:v,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>void P(),disabled:v||!E,children:[v&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}var eD=e.i(621664),eA=e.i(429318);let eL="/api/organization/value-sets/secondQualityReasons?scope=*";function eE(){let e=(0,l.useTranslations)("bridge.data.secondQuality"),t=(0,eD.useLocale)(),c=(0,m.useServerMessage)(),u=(0,F.useConfirmDiscard)(),[p,x]=(0,s.use
1State)(!0),[g,f]=(0,s.useState)([]),[y,j]=(0,s.useState)([]),[b,v]=(0,s.useState)(!1),[S,w]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[T,D]=(0,s.useState)(!1),A=(0,s.useCallback)(async()=>{x(!0);try{let e=await fetch(eL),a=e.ok?await e.json():null;f(Array.isArray(a?.data)?a.data:[])}catch(e){console.error("[SecondQualityReasonsCard] fetch failed",e)}finally{x(!1)}},[]);(0,s.useEffect)(()=>{A()},[A]),(0,s.useEffect)(()=>{b&&j(g)},[b,g]);let L=y.filter(e=>!eA.RETIRED_SECOND_QUALITY_REASON_CODES.has(e.key)),E=b&&JSON.stringify(y)!==JSON.stringify(g),M=async()=>{S||(!E||await u())&&v(!1)},R=(e,a)=>j(t=>t.map(t=>t.key===e?{...t,...a}:t)),P=async()=>{C(null),D(!1);let a=L.map(e=>(0,eA.labelForSecondQualityReason)(e,t).trim());if(a.some(e=>!e))return void C(e("nameRequired"));if(new Set(a.map(e=>e.toLocaleLowerCase())).size!==a.length)return void C(e("duplicateNames"));let s=new Set(y.filter(e=>!e.isNew).map(e=>e.key)),l=y.map(({isNew:e,...a})=>{if(!e)return a;let t=function(e,a){let t=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"reason",s=t;for(let e=2;a.has(s)||eA.RETIRED_SECOND_QUALITY_REASON_CODES.has(s);e+=1)s=`${t}_${e}`;return s}(a.label,s);return s.add(t),{...a,key:t}});w(!0);try{let e=await fetch(eL,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({label:"2nd-quality reason codes",data:l})});if(!e.ok)throw(0,h.serverMessageError)(await e.json().catch(()=>null),`HTTP ${e.status}`);let a=await e.json();f(Array.isArray(a?.data)?a.data:l),D(!0),v(!1)}catch(e){C(e instanceof Error?c(e):String(e))}finally{w(!1)}};if(p)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});let O=g.filter(eA.isSecondQualityReasonActive);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:O.length>0?e("summary",{count:O.length}):e("summaryEmpty"),onClick:()=>{D(!1),C(null),v(!0)}}),T&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:b,onOpenChange:e=>{e?v(!0):M()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsx)(n.DialogBody,{className:"space-y-3",children:(0,a.jsxs)("ul",{className:"flex flex-col gap-1.5","aria-label":e("reasons"),children:[L.map((s,l)=>{let r=(0,eA.labelForSecondQualityReason)(s,t);return(0,a.jsxs)("li",{className:"flex h-11 items-center gap-2 rounded-lg border border-line pl-1 pr-3",children:[(0,a.jsx)(o.Input,{"aria-label":e("reasonName",{number:l+1}),value:r,placeholder:e("namePlaceholder"),onChange:e=>{let a=e.target.value;R(s.key,{labels:{...s.labels,[t.split("-")[0]??t]:a},...s.isNew||t.startsWith("en")?{label:a}:{}})},className:"h-8 flex-1 border-0 shadow-none"}),(0,a.jsx)(V.Switch,{"aria-label":e("active",{name:r}),checked:!1!==s.active,onCheckedChange:e=>R(s.key,{active:e})})]},s.key)}),(0,a.jsx)("li",{children:(0,a.jsxs)(i.Button,{type:"button",variant:"outline",className:"h-11 w-full border-dashed",onClick:()=>j(e=>[...e,{key:`new:${e.length}:${Date.now()}`,label:"",active:!0,isNew:!0}]),children:[(0,a.jsx)(z.Plus,{className:"size-4","aria-hidden":"true"}),e("add")]})})]})}),N&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:N,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void M(),disabled:S,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>void P(),disabled:S||!E,children:[S&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}async function eM(e,a,t){let s=await fetch(`/api/internal/purchase-rules/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(a),signal:t}),l={};try{l=await s.json()}catch{}if(!s.ok||!0!==l.success||void 0===l.data)throw(0,h.serverMessageError)(l,`HTTP ${s.status}`);return l.data}function eR(e){return eM("query",{},e?.signal)}function eP(){let e=(0,l.useTranslations)("bridge.data.inventoryAccounts"),t=(0,m.useServerMessage)(),u=(0,F.useConfirmDiscard)(),[h,p]=(0,s.use
1State)(null),[x,g]=(0,s.useState)([]),[f,y]=(0,s.useState)(""),[j,b]=(0,s.useState)(!1),[v,S]=(0,s.useState)(!1),[k,w]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),T=(0,s.useCallback)(async e=>{try{p((await eR({signal:e})).inventoryAccounts)}catch{}},[]);(0,s.useEffect)(()=>{let e=new AbortController;return T(e.signal),()=>e.abort()},[T]),(0,s.useEffect)(()=>{j&&h&&(g(h.accountIds),y(""))},[j,h]);let D=(0,s.useMemo)(()=>{let e=f.trim().toLowerCase(),a=[...h?.accounts??[]].sort((e,a)=>Number(x.includes(a.id))-Number(x.includes(e.id)));return e?a.filter(a=>a.label.toLowerCase().includes(e)):a},[h,f,j]);if(!h)return null;let A=h.accounts.filter(e=>x.includes(e.id)).map(e=>e.id),L=h.accounts.filter(e=>h.accountIds.includes(e.id)),E=j&&[...A].sort().join()!==L.map(e=>e.id).sort().join(),M=async()=>{v||(!E||await u())&&b(!1)},R=async()=>{w(null),C(!1),S(!0);try{var e;let{revision:a}=await (e={accountIds:A,expectedRevision:h.revision},eM("execute",{operation:"set-inventory-accounts",...e}));p({...h,accountIds:A,revision:a}),C(!0),b(!1)}catch(e){w(e instanceof Error?t(e):String(e))}finally{S(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:L.length>0?e("summary",{count:L.length}):e("summaryEmpty"),onClick:()=>{C(!1),w(null),b(!0)}}),N&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:j,onOpenChange:e=>{e?b(!0):M()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-3",children:[(0,a.jsx)(o.Input,{"aria-label":e("search"),placeholder:e("search"),value:f,onChange:e=>y(e.target.value)}),(0,a.jsx)("ul",{className:"flex flex-col gap-1.5","aria-label":e("title"),children:D.map(e=>(0,a.jsxs)("li",{className:"flex h-11 items-center gap-3 rounded-lg border border-line px-3",children:[(0,a.jsx)(_.Checkbox,{id:`inventory-account-${e.id}`,checked:x.includes(e.id),onCheckedChange:a=>g(t=>!0===a?[...t,e.id]:t.filter(a=>a!==e.id))}),(0,a.jsx)(c.Label,{htmlFor:`inventory-account-${e.id}`,className:"flex-1",children:e.label})]},e.id))}),(0,a.jsx)("p",{className:"text-meta text-ink-muted tabular-nums",children:e("count",{chosen:A.length,total:h.accounts.length})})]}),k&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:k,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void M(),disabled:v,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>void R(),disabled:v||!E,children:[v&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}function eO(){let e=(0,l.useTranslations)("bridge.data.itemCodePrefixes"),t=(0,m.useServerMessage)(),c=(0,F.useConfirmDiscard)(),[u,h]=(0,s.useState)(null),[p,x]=(0,s.useState)(!1),[g,f]=(0,s.useState)([]),[y,j]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[S,w]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),T=(0,s.useCallback)(async e=>{try{h(await eR({signal:e})),x(!1)}catch(e){e?.name!=="AbortError"&&x(!0)}},[]);if((0,s.useEffect)(()=>{let e=new AbortController;return T(e.signal),()=>e.abort()},[T]),(0,s.useEffect)(()=>{y&&u&&f(u.itemCodePrefixes)},[y,u]),p)return(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("loadFailed")});if(!u)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});let D=y&&JSON.stringify(g)!==JSON.stringify(u.itemCodePrefixes),A=async()=>{b||(!D||await c())&&j(!1)},L=(e,a)=>f(t=>t.map((t,s)=>s===e?{...t,...a}:t)),E=async()=>{w(null),C(!1);let a=g.map(e=>({keyword:e.keyword.trim(),prefix:e.prefix.trim()}));if(a.some(e=>!e.keyword||!e.prefix))return void w(e("incomplete"));let s=a.map(e=>e.keyword.toLocaleLowerCase());if(new Set(s).size!==s.length)return void w(e("duplicate"));v(!0);try{var l;let{revision:e}=await (l={itemCodePrefixes:a,expectedRevision:u.revision},eM("execute",{operation:"set-item-code-prefixes",...l}));h({...u,itemCodePrefixes:a,revision:e}),C(!0),j(!1)}catch(e){w(e instanceof Error?t(e):String(e))}finally{v(!1)}},M=u.itemCodePrefixes.length;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:M>0?e("summary",{count:M}):e("summaryEmpty"),onClick:()=>{C(!1),w(null),j(!0)}}),N&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:y,onOpenChange:e=>{e?j(!0):A()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsx)(n.DialogBody,{className:"space-y-3",children:(0,a.jsxs)("ul",{className:"flex flex-col gap-1.5","aria-label":e("title"),children:[g.map((t,s)=>(0,a.jsxs)("li",{className:"flex h-11 items-center gap-2 rounded-lg border border-line pl-1 pr-1",children:[(0,a.jsx)(o.Input,{"aria-label":e("keyword",{number:s+1}),value:t.keyword,placeholder:e("keywordPlaceholder"),onChange:e=>L(s,{keyword:e.target.value}),className:"h-8 flex-1 border-0 shadow-none"}),(0,a.jsx)(o.Input,{"aria-label":e("prefix",{number:s+1}),value:t.prefix,placeholder:e("prefixPlaceholder"),onChange:e=>L(s,{prefix:e.target.value}),className:"h-8 flex-1 border-0 font-mono shadow-none"}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":e("remove",{name:t.keyword||String(s+1)}),onClick:()=>f(e=>e.filter((e,a)=>a!==s)),children:(0,a.jsx)(eN.X,{className:"size-4","aria-hidden":"true"})})]},s)),(0,a.jsx)("li",{children:(0,a.jsxs)(i.Button,{type:"button",variant:"outline",className:"h-11 w-full border-dashed",onClick:()=>f(e=>[...e,{keyword:"",prefix:""}]),children:[(0,a.jsx)(z.Plus,{className:"size-4","aria-hidden":"true"}),e("add")]})})]})}),S&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:S,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void A(),disabled:b,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>
1void E(),disabled:b||!D,children:[b&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}var eB=e.i(871516);let eI={season:"FW26",brand:"north-outdoor",factoryCode:"LT",sourceOrderNumber:"928282",poNumber:"PO26107"};function ez(){let e=(0,l.useTranslations)("bridge.data.orderMemo"),t=(0,l.useTranslations)("bridge.data.orderMemo.parts"),o=(0,m.useServerMessage)(),h=(0,F.useConfirmDiscard)(),[p,x]=(0,s.useState)(null),[g,f]=(0,s.useState)(!1),[y,j]=(0,s.useState)([]),[b,v]=(0,s.useState)(" "),[S,w]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[T,D]=(0,s.useState)(null),[A,L]=(0,s.useState)(!1),E=(0,s.useCallback)(async e=>{try{x(await eR({signal:e})),f(!1)}catch(e){e?.name!=="AbortError"&&f(!0)}},[]);if((0,s.useEffect)(()=>{let e=new AbortController;return E(e.signal),()=>e.abort()},[E]),(0,s.useEffect)(()=>{if(S&&p){var e;j([...(e=p.orderMemo).parts.map(e=>({part:e,on:!0})),...eB.ORDER_MEMO_PARTS.filter(a=>!e.parts.includes(a)).map(e=>({part:e,on:!1}))]),v(p.orderMemo.separator)}},[S,p]),g)return(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("loadFailed")});if(!p)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});let M={parts:y.filter(e=>e.on).map(e=>e.part),separator:b},R=S&&JSON.stringify(M)!==JSON.stringify(p.orderMemo),P=async()=>{N||(!R||await h())&&w(!1)},O=(e,a)=>j(t=>{let s=e+a;if(s<0||s>=t.length)return t;let l=[...t];return[l[e],l[s]]=[l[s],l[e]],l}),I=async()=>{if(D(null),L(!1),0===M.parts.length)return void D(e("needsPart"));C(!0);try{var a;let{revision:e}=await (a={orderMemo:M,expectedRevision:p.orderMemoRevision},eM("execute",{operation:"set-order-memo",...a}));x({...p,orderMemo:M,orderMemoRevision:e}),L(!0),w(!1)}catch(e){D(e instanceof Error?o(e):String(e))}finally{C(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:p.orderMemo.parts.map(e=>t(e)).join(" "===p.orderMemo.separator?" · ":p.orderMemo.separator),onClick:()=>{L(!1),D(null),w(!0)}}),A&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:S,onOpenChange:e=>{e?w(!0):P()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-4",children:[(0,a.jsx)("ol",{className:"flex flex-col gap-1.5","aria-label":e("partsLabel"),children:y.map((s,l)=>{let r=t(s.part);return(0,a.jsxs)("li",{className:"flex h-11 items-center gap-2 rounded-lg border border-line pl-3 pr-1",children:[(0,a.jsx)("span",{className:"flex-1 text-sm font-medium text-ink",children:r}),(0,a.jsx)(V.Switch,{"aria-label":e("include",{name:r}),checked:s.on,onCheckedChange:e=>j(a=>a.map(a=>a.part===s.part?{...a,on:e}:a))}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":e("moveUp",{name:r}),disabled:0===l,onClick:()=>O(l,-1),children:(0,a.jsx)(eS.ChevronUp,{className:"size-4","aria-hidden":"true"})}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":e("moveDown",{name:r}),disabled:l===y.length-1,onClick:()=>O(l,1),children:(0,a.jsx)(ev.ChevronDown,{className:"size-4","aria-hidden":"true"})})]},s.part)})}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{htmlFor:"order-memo-separator",children:e("separator")}),(0,a.jsxs)(u.Select,{value:b,onValueChange:e=>v(e),children:[(0,a.jsx)(u.SelectTrigger,{id:"order-memo-separator",className:"w-40",children:(0,a.jsx)(u.SelectValue,{})}),(0,a.jsx)(u.SelectContent,{children:eB.ORDER_MEMO_SEPARATORS.map(t=>(0,a.jsx)(u.SelectItem,{value:t,children:" "===t?e("space"):t.trim()},t))})]})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)("p",{className:"text-meta text-ink-muted",children:e("example")}),(0,a.jsx)("p",{className:"rounded-lg bg-surface-sunken px-3 py-2 font-mono text-sm","data-testid":"order-memo-example",children:(0,eB.buildOrderMemo)(M,eI)})]})]}),T&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:T,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void P(),disabled:N,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>
1void I(),disabled:N||!R,children:[N&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}var e$=e.i(184762);let e_=["hs","fedas","hsHelper","fedasHelper","hsLookup","fedasLookup"],eK={hs:{storeKey:"hsRules",matchFields:["brandKey","fabricCode","garmentType","targetGroup"],optionalFields:[],codeField:"hsCode",codeDigits:10},fedas:{storeKey:"fedasRules",matchFields:["brandKey","garmentType","targetGroup"],optionalFields:["productType"],codeField:"fedasCode",codeDigits:6},hsHelper:{storeKey:"hsHelperMappings",matchFields:["brandKey","productCode"],optionalFields:[],codeField:"hsCode",codeDigits:10,allowsSeveralCodes:!0},hsLookup:{storeKey:"hsClassificationLookup",matchFields:["brandKey","classificationCode","targetGroup"],optionalFields:["fabricCode"],codeField:"code",codeDigits:10},fedasLookup:{storeKey:"fedasClassificationLookup",matchFields:["brandKey","classificationCode","targetGroup"],optionalFields:["fabricCode"],codeField:"code",codeDigits:6},fedasHelper:{storeKey:"fedasHelperMappings",matchFields:["brandKey","productCode"],optionalFields:[],codeField:"fedasCode",codeDigits:6,allowsSeveralCodes:!0}};function eH(e){let a=eK[e];return[...a.matchFields,...a.optionalFields,a.codeField]}let eU=e=>"string"==typeof e?e.trim():"",eq=e=>e.normalize("NFC").toLowerCase();async function eV(e,a,t){let s=await fetch(`/api/internal/product-rules/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(a),signal:t}),l={};try{l=await s.json()}catch{}if(!s.ok||!0!==l.success||void 0===l.data)throw(0,h.serverMessageError)(l,`HTTP ${s.status}`);return l.data}function eG(e){return eV("query",{},e?.signal)}let eJ={hs:"hsTitle",fedas:"fedasTitle",hsHelper:"hsHelperTitle",fedasHelper:"fedasHelperTitle",hsLookup:"hsLookupTitle",fedasLookup:"fedasLookupTitle"};function eQ({kind:e,rules:t,revision:c,onSaved:u}){let h=(0,l.useTranslations)("bridge.data.classificationRules"),p=(0,l.useTranslations)("bridge.data.classificationRules.fields"),x=(0,m.useServerMessage)(),g=(0,F.useConfirmDiscard)(),[f,y]=(0,s.useState)(!1),[j,b]=(0,s.useState)(t),[v,S]=(0,s.useState)(""),[k,w]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[T,D]=(0,s.use
1State)(!1);(0,s.useEffect)(()=>{f&&(b(t),S(""))},[f,t]);let A=eH(e),L=eK[e].codeField,E=h(eJ[e]),M=(0,s.useMemo)(()=>{let e=v.trim().toLowerCase();return j.map((e,a)=>({rule:e,index:a})).filter(({rule:a})=>!e||A.some(t=>(a[t]??"").toLowerCase().includes(e)))},[j,A,v]),R=f&&JSON.stringify(j)!==JSON.stringify(t),P=async()=>{k||(!R||await g())&&y(!1)},O=async()=>{D(!1);let a=function(e,a){let t=eK[e],s=RegExp(`^\\d{${t.codeDigits}}$`),l=new Map,r=[];for(let[i,n]of a.entries()){let a=Object.fromEntries(eH(e).flatMap(e=>eU(n[e])?[[e,eU(n[e])]]:[]));if(t.matchFields.some(e=>!a[e]))return{ok:!1,issue:"incomplete",index:i};let o=a[t.codeField]??"";if(!s.test(o)||/^0+$/.test(o))return{ok:!1,issue:"code",index:i};let c=[...t.matchFields,...t.optionalFields].map(e=>eq(a[e]??"")).join("\0"),d=t.allowsSeveralCodes?`${c}\u0000${o}`:c,u=l.get(d);if(u!==o){if(void 0!==u)return{ok:!1,issue:"conflict",index:i};l.set(d,o),r.push(a)}}return{ok:!0,rules:r}}(e,j);if(!a.ok)return void C(h(a.issue,{row:a.index+1}));C(null),w(!0);try{var t;let s=await (t={kind:e,rules:a.rules,expectedRevision:c},eV("execute",{operation:"set-classification-rules",...t}));u(a.rules,s.revision),D(!0),y(!1)}catch(e){C(e instanceof Error?x(e):String(e))}finally{w(!1)}},I={gridTemplateColumns:`2rem repeat(${A.length}, minmax(0, 1fr)) 2rem`};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:E,summary:h("summary",{count:t.length}),onClick:()=>{D(!1),C(null),y(!0)}}),T&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:h("saved")}),(0,a.jsx)(n.Dialog,{open:f,onOpenChange:e=>{e?y(!0):P()},children:(0,a.jsxs)(n.DialogContent,{size:"xl",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:E})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-3",children:[(0,a.jsx)(o.Input,{"aria-label":h("search"),placeholder:h("search"),value:v,onChange:e=>S(e.target.value)}),(0,a.jsxs)("div",{role:"table","aria-label":E,className:"rounded-lg bg-surface-sunken",children:[(0,a.jsxs)("div",{role:"row",className:"grid gap-2 px-3 py-2 text-eyebrow text-ink-muted",style:I,children:[(0,a.jsx)("span",{role:"columnheader"}),A.map(e=>(0,a.jsx)("span",{role:"columnheader",children:p(e)},e)),(0,a.jsx)("span",{role:"columnheader"})]}),M.map(({rule:e,index:t})=>(0,a.jsxs)("div",{role:"row",className:"grid items-center gap-2 border-t border-line px-3 py-1.5",style:I,children:[(0,a.jsx)("span",{role:"cell",className:"text-meta text-ink-muted tabular-nums",children:t+1}),A.map(s=>(0,a.jsx)(o.Input,{role:"cell","aria-label":h("cell",{field:p(s),row:t+1}),value:e[s]??"",inputMode:s===L?"numeric":void 0,className:s===L?"h-8 font-mono tabular-nums":"h-8",onChange:e=>{let a=e.target.value;b(e=>e.map((e,l)=>l===t?{...e,[s]:a}:e))}},s)),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":h("remove",{row:t+1}),onClick:()=>b(e=>e.filter((e,a)=>a!==t)),children:(0,a.jsx)(eN.X,{className:"size-4","aria-hidden":"true"})})]},t))]}),(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,a.jsxs)(i.Button,{type:"button",variant:"outline",onClick:()=>{S(""),b(e=>[...e,{}])},children:[(0,a.jsx)(z.Plus,{className:"size-4","aria-hidden":"true"}),h("add")]}),(0,a.jsx)("span",{className:"text-meta text-ink-muted tabular-nums",children:h("shown",{shown:M.length,total:j.length})})]})]}),N&&(0,a.jsx)(d.Notice,{tone:"blocker",title:h("saveFailed"),description:N,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void P(),disabled:k,children:h("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>void O(),disabled:k||!R,children:[k&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),h("save")]})]})]})})]})}let eW={"sales-order-prices":"salesOrderPrices","basic-info":"basicInfo","item-availability":"itemAvailability"};function eY({card:e,onSaved:t}){let o=(0,l.useTranslations)("bridge.data.productCard"),c=(0,l.useTranslations)("lookUpProduct.blocks.salesOrderPrices"),u=(0,l.useTranslations)("lookUpProduct.blocks.basicInfo"),h=(0,l.useTranslations)("lookUpProduct.blocks.itemAvailability"),p=(0,m.useServerMessage)(),x=(0,F.useConfirmDiscard)(),[g,f]=(0,s.use
1State)(!1),[y,j]=(0,s.useState)(e.modules),[b,v]=(0,s.useState)(!1),[S,k]=(0,s.useState)(null),[w,N]=(0,s.useState)(!1);(0,s.useEffect)(()=>{g&&j(e.modules)},[g,e.modules]);let C=e=>{let a=eW[e];return"salesOrderPrices"===a?c("title"):"basicInfo"===a?u("title"):h("title")},T=g&&JSON.stringify(y)!==JSON.stringify(e.modules),D=async()=>{b||(!T||await x())&&f(!1)},A=(e,a)=>j(t=>{let s=e+a;if(s<0||s>=t.length)return t;let l=[...t];return[l[e],l[s]]=[l[s],l[e]],l}),L=async()=>{k(null),N(!1),v(!0);try{var a;let s=[...y.filter(e=>e.enabled),...y.filter(e=>!e.enabled)],{revision:l}=await (a={modules:s,expectedRevision:e.revision},eV("execute",{operation:"set-product-card",...a}));t({modules:s,revision:l}),N(!0),f(!1)}catch(e){k(e instanceof Error?p(e):String(e))}finally{v(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:o("title"),summary:e.modules.filter(e=>e.enabled).map(e=>C(e.key)).join(" · "),onClick:()=>{N(!1),k(null),f(!0)}}),w&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:o("saved")}),(0,a.jsx)(n.Dialog,{open:g,onOpenChange:e=>{e?f(!0):D()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:o("title")})}),(0,a.jsx)(n.DialogBody,{children:(0,a.jsx)("ol",{className:"flex flex-col gap-1.5","aria-label":o("title"),children:y.map((e,t)=>{let s=C(e.key);return(0,a.jsxs)("li",{className:"flex h-11 items-center gap-2 rounded-lg border border-line pl-3 pr-1",children:[(0,a.jsx)("span",{className:"flex-1 text-sm font-medium text-ink",children:s}),(0,a.jsx)(V.Switch,{"aria-label":o("show",{name:s}),checked:e.enabled,disabled:"sales-order-prices"===e.key,onCheckedChange:a=>j(t=>t.map(t=>t.key===e.key?{...t,enabled:a}:t))}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":o("moveUp",{name:s}),disabled:0===t,onClick:()=>A(t,-1),children:(0,a.jsx)(eS.ChevronUp,{className:"size-4","aria-hidden":"true"})}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":o("moveDown",{name:s}),disabled:t===y.length-1,onClick:()=>A(t,1),children:(0,a.jsx)(ev.ChevronDown,{className:"size-4","aria-hidden":"true"})})]},e.key)})})}),S&&(0,a.jsx)(d.Notice,{tone:"blocker",title:o("saveFailed"),description:S,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void D(),disabled:b,children:o("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>void L(),disabled:b||!T,children:[b&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),o("save")]})]})]})})]})}function eX({title:e,fields:t,values:o,onSave:u}){let h=(0,l.useTranslations)("bridge.data.productGuidance"),p=(0,m.useServerMessage)(),x=(0,F.useConfirmDiscard)(),[g,f]=(0,s.useState)(!1),[y,j]=(0,s.useState)(o),[b,v]=(0,s.useState)(!1),[S,k]=(0,s.useState)(null),[w,N]=(0,s.useState)(!1);(0,s.useEffect)(()=>{g&&j(o)},[g,o]);let C=g&&t.some(e=>(y[e.key]??"").trim()!==(o[e.key]??"").trim()),T=async()=>{b||(!C||await x())&&f(!1)},D=async()=>{k(null),N(!1),v(!0);try{await u(Object.fromEntries(t.map(e=>[e.key,(y[e.key]??"").trim()]))),N(!0),f(!1)}catch(e){k(e instanceof Error?p(e):String(e))}finally{v(!1)}},A=t.filter(e=>(o[e.key]??"").trim());return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e,summary:0===A.length?h("notSet"):1===t.length?h("set"):A.map(e=>e.label).join(" · "),onClick:()=>{N(!1),k(null),f(!0)}}),w&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:h("saved")}),(0,a.jsx)(n.Dialog,{open:g,onOpenChange:e=>{e?f(!0):T()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e})}),(0,a.jsx)(n.DialogBody,{className:"space-y-4",children:t.map(e=>(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{htmlFor:`guidance-${e.key}`,children:e.label}),(0,a.jsx)(e$.Textarea,{id:`guidance-${e.key}`,rows:1===t.length?8:5,maxLength:4e3,value:y[e.key]??"",onChange:a=>j(t=>({...t,[e.key]:a.target.value}))})]},e.key))}),S&&(0,a.jsx)(d.Notice,{tone:"blocker",title:h("saveFailed"),description:S,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void T(),disabled:b,children:h("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>
1void D(),disabled:b||!C,children:[b&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),h("save")]})]})]})})]})}function eZ(e,a){return e?{...e,revision:a}:null}function e0(){let e=(0,l.useTranslations)("bridge.data.productGuidance"),[t,r]=(0,s.useState)(null),i=(0,s.useCallback)(async e=>{try{r(await eG({signal:e}))}catch{}},[]);if((0,s.useEffect)(()=>{let e=new AbortController;return i(e.signal),()=>e.abort()},[i]),!t)return null;let{classificationGuidance:n,classificationRules:o,designGuidance:c}=t,d=(e,a)=>r({...t,...e,classificationGuidance:eZ(e.classificationGuidance??n,a),classificationRules:eZ(e.classificationRules??o,a)});return(0,a.jsxs)(a.Fragment,{children:[o?e_.map(e=>(0,a.jsx)(eQ,{kind:e,rules:o[e],revision:o.revision,onSaved:(a,t)=>d({classificationRules:{...o,[e]:a}},t)},e)):null,n?(0,a.jsx)(eX,{title:e("classification"),fields:[{key:"hs-codes",label:e("hs")},{key:"fedas-codes",label:e("fedas")}],values:n.texts,onSave:async e=>{let a={"hs-codes":e["hs-codes"]??"","fedas-codes":e["fedas-codes"]??""},{revision:t}=await eV("execute",{operation:"set-classification-guidance",...{texts:a,expectedRevision:n.revision}});d({classificationGuidance:{texts:a,revision:t}},t)}}):null,c?(0,a.jsx)(eX,{title:e("design"),fields:[{key:"text",label:e("guidance")}],values:{text:c.text},onSave:async e=>{let a=e.text??"",{revision:s}=await eV("execute",{operation:"set-design-guidance",...{text:a,expectedRevision:c.revision}});r({...t,designGuidance:{text:a,revision:s}})}}):null,(0,a.jsx)(eY,{card:t.productCard,onSaved:e=>r({...t,productCard:e})})]})}let e1="__none__",e3={gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1.2fr) minmax(0, 1fr) 2.5rem 2rem"},e5={key:"",sourceAttributeKey:"",sourceValues:"",markKey:"",brandKey:"",enabled:!0},e2=e=>({...e,sourceValues:e.sourceValues.join(", ")}),e4=e=>e.sourceValues.split(",").map(e=>e.trim()).filter(Boolean),e6=e=>({...e,sourceAttributeKey:e.sourceAttributeKey.trim(),sourceValues:e4(e)});function e8(){let e=(0,l.useTranslations)("bridge.data.labelMarks"),t=(0,m.useServerMessage)(),c=(0,F.useConfirmDiscard)(),[h,p]=(0,s.use
1State)(void 0),[x,g]=(0,s.useState)(null),[f,y]=(0,s.useState)(null),[j,b]=(0,s.useState)([]),[v,S]=(0,s.useState)(""),[w,N]=(0,s.useState)(!1),[C,T]=(0,s.useState)(!1),[D,A]=(0,s.useState)(null),[L,E]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let e=new AbortController;return eG({signal:e.signal}).then(e=>p(e.labelMarkRules)).catch(e=>{e?.name!=="AbortError"&&p(null)}),()=>e.abort()},[]),(0,s.useEffect)(()=>{var e;if(!w)return;let a=new AbortController;return g(null),b([]),S(""),y(null),(e={signal:a.signal},eV("query",{view:"label-marks"},e?.signal)).then(e=>{g(e),b(e.rules.map(e2))}).catch(e=>{e?.name!=="AbortError"&&y(e instanceof Error?t(e):String(e))}),()=>a.abort()},[w]);let M=(0,s.useMemo)(()=>{let e=v.trim().toLowerCase();return j.map((e,a)=>({row:e,index:a})).filter(({row:a})=>!e||`${a.sourceAttributeKey} ${a.sourceValues} ${a.markKey} ${a.brandKey}`.toLowerCase().includes(e))},[j,v]);if(null===h)return null;if(void 0===h)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});let R=w&&!!x&&JSON.stringify(j)!==JSON.stringify(x.rules.map(e2)),P=async()=>{C||(!R||await c())&&N(!1)},O=(e,a)=>b(t=>t.map((t,s)=>s===e?{...t,...a}:t)),I=async()=>{if(!x)return;E(!1);let a=j.findIndex(e=>!(e.sourceAttributeKey.trim().length>0&&e4(e).length>0));if(a>=0)return void A(e("incomplete",{row:a+1}));A(null),T(!0);try{var s;await (s={labelMarks:j.map(e6),expectedRevision:x.revision},eV("execute",{operation:"set-label-marks",...s})),p(j.length),E(!0),N(!1)}catch(e){A(e instanceof Error?t(e):String(e))}finally{T(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("summary",{count:h}),onClick:()=>{E(!1),A(null),N(!0)}}),L&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:w,onOpenChange:e=>{e?N(!0):P()},children:(0,a.jsxs)(n.DialogContent,{size:"xl",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-3",children:[f&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("loadFailed"),description:f}),!f&&!x&&(0,a.jsxs)("div",{"aria-busy":"true",children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"h-48 w-full"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]}),x&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(o.Input,{"aria-label":e("search"),placeholder:e("search"),value:v,onChange:e=>S(e.target.value)}),(0,a.jsxs)("div",{role:"table","aria-label":e("title"),className:"rounded-lg bg-surface-sunken",children:[(0,a.jsxs)("div",{role:"row",className:"grid gap-2 px-3 py-2 text-eyebrow text-ink-muted",style:e3,children:[(0,a.jsx)("span",{role:"columnheader",children:e("sourceAttributeKey")}),(0,a.jsx)("span",{role:"columnheader",children:e("sourceValues")}),(0,a.jsx)("span",{role:"columnheader",children:e("markKey")}),(0,a.jsx)("span",{role:"columnheader",children:e("brandKey")}),(0,a.jsx)("span",{role:"columnheader",children:e("enabled")}),(0,a.jsx)("span",{role:"columnheader"})]}),M.map(({row:t,index:s})=>(0,a.jsxs)("div",{role:"row",className:"grid items-center gap-2 border-t border-line px-3 py-1.5",style:e3,children:[(0,a.jsx)(o.Input,{role:"cell","aria-label":e("cell",{field:e("sourceAttributeKey"),row:s+1}),value:t.sourceAttributeKey,className:"h-8 font-mono",onChange:e=>O(s,{sourceAttributeKey:e.target.value})}),(0,a.jsx)(o.Input,{role:"cell","aria-label":e("cell",{field:e("sourceValues"),row:s+1}),value:t.sourceValues,className:"h-8",onChange:e=>O(s,{sourceValues:e.target.value})}),(0,a.jsxs)(u.Select,{value:t.markKey||e1,onValueChange:e=>O(s,{markKey:e===e1?"":e}),children:[(0,a.jsx)(u.SelectTrigger,{role:"cell","aria-label":e("cell",{field:e("markKey"),row:s+1}),className:"h-8",children:(0,a.jsx)(u.SelectValue,{})}),(0,a.jsxs)(u.SelectContent,{children:[(0,a.jsx)(u.SelectItem,{value:e1,children:e("noMark")}),x.marks.map(e=>(0,a.jsx)(u.SelectItem,{value:e.id,children:e.label},e.id))]})]}),(0,a.jsxs)(u.Select,{value:t.brandKey||e1,onValueChange:e=>O(s,{brandKey:e===e1?"":e}),children:[(0,a.jsx)(u.SelectTrigger,{role:"cell","aria-label":e("cell",{field:e("brandKey"),row:s+1}),className:"h-8",children:(0,a.jsx)(u.SelectValue,{})}),(0,a.jsxs)(u.SelectContent,{children:[(0,a.jsx)(u.SelectItem,{value:e1,children:e("allBrands")}),x.brands.map(e=>(0,a.jsx)(u.SelectItem,{value:e.id,children:e.label},e.id))]})]}),(0,a.jsx)(V.Switch,{role:"cell","aria-label":e("cell",{field:e("enabled"),row:s+1}),checked:t.enabled,onCheckedChange:e=>O(s,{enabled:e})}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":e("remove",{row:s+1}),onClick:()=>b(e=>e.filter((e,a)=>a!==s)),children:(0,a.jsx)(eN.X,{className:"size-4","aria-hidden":"true"})})]},s))]}),(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,a.jsxs)(i.Button,{type:"button",variant:"outline",onClick:()=>{S(""),b(e=>[...e,e5])},children:[(0,a.jsx)(z.Plus,{className:"size-4","aria-hidden":"true"}),e("add")]}),(0,a.jsx)("span",{className:"text-meta text-ink-muted tabular-nums",children:e("shown",{shown:M.length,total:j.length})})]})]})]}),D&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:D,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void P(),disabled:C,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>
1void I(),disabled:C||!R,children:[C&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}let e7={gridTemplateColumns:"7rem minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1.6fr) 2rem"},e9=["netsuite","plytix","shopify"].map(e=>({id:e,label:({netsuite:"NetSuite",plytix:"Plytix",shopify:"Shopify"})[e]})),ae={system:"netsuite",field:"",value:"",classificationCode:""},aa=e=>e,at=e=>({...e,field:e.field.trim(),value:e.value.trim()});function as(){let e=(0,l.useTranslations)("bridge.data.categoryMappings"),t=(0,m.useServerMessage)(),c=(0,F.useConfirmDiscard)(),[h,p]=(0,s.useState)(void 0),[x,g]=(0,s.useState)(null),[f,y]=(0,s.useState)(null),[j,b]=(0,s.useState)([]),[v,S]=(0,s.useState)(""),[w,N]=(0,s.useState)(!1),[C,T]=(0,s.useState)(!1),[D,A]=(0,s.useState)(null),[L,E]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let e=new AbortController;return eG({signal:e.signal}).then(e=>p(e.categoryMappings)).catch(e=>{e?.name!=="AbortError"&&p(null)}),()=>e.abort()},[]),(0,s.useEffect)(()=>{var e;if(!w)return;let a=new AbortController;return g(null),b([]),S(""),y(null),(e={signal:a.signal},eV("query",{view:"category-mappings"},e?.signal)).then(e=>{g(e),b(e.mappings.map(aa))}).catch(e=>{e?.name!=="AbortError"&&y(e instanceof Error?t(e):String(e))}),()=>a.abort()},[w]);let M=(0,s.useMemo)(()=>{let e=v.trim().toLowerCase();return j.map((e,a)=>({row:e,index:a})).filter(({row:a})=>!e||`${a.system} ${a.field} ${a.value} ${a.classificationCode}`.toLowerCase().includes(e))},[j,v]);if(null===h)return null;if(void 0===h)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});let R=w&&!!x&&JSON.stringify(j)!==JSON.stringify(x.mappings.map(aa)),P=async()=>{C||(!R||await c())&&N(!1)},O=(e,a)=>b(t=>t.map((t,s)=>s===e?{...t,...a}:t)),I=async()=>{if(!x)return;E(!1);let a=j.findIndex(e=>!(e.field.trim().length>0&&e.value.trim().length>0&&e.classificationCode.length>0));if(a>=0)return void A(e("incomplete",{row:a+1}));A(null),T(!0);try{var s;await (s={mappings:j.map(at),expectedRevision:x.revision},eV("execute",{operation:"set-category-mappings",...s})),p(j.length),E(!0),N(!1)}catch(e){A(e instanceof Error?t(e):String(e))}finally{T(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("summary",{count:h}),onClick:()=>{E(!1),A(null),N(!0)}}),L&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:w,onOpenChange:e=>{e?N(!0):P()},children:(0,a.jsxs)(n.DialogContent,{size:"xl",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-3",children:[f&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("loadFailed"),description:f}),!f&&!x&&(0,a.jsxs)("div",{"aria-busy":"true",children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"h-48 w-full"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]}),x&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(o.Input,{"aria-label":e("search"),placeholder:e("search"),value:v,onChange:e=>S(e.target.value)}),(0,a.jsxs)("div",{role:"table","aria-label":e("title"),className:"rounded-lg bg-surface-sunken",children:[(0,a.jsxs)("div",{role:"row",className:"grid gap-2 px-3 py-2 text-eyebrow text-ink-muted",style:e7,children:[(0,a.jsx)("span",{role:"columnheader",children:e("system")}),(0,a.jsx)("span",{role:"columnheader",children:e("field")}),(0,a.jsx)("span",{role:"columnheader",children:e("value")}),(0,a.jsx)("span",{role:"columnheader",children:e("classificationCode")}),(0,a.jsx)("span",{role:"columnheader"})]}),M.map(({row:t,index:s})=>(0,a.jsxs)("div",{role:"row",className:"grid items-center gap-2 border-t border-line px-3 py-1.5",style:e7,children:[(0,a.jsxs)(u.Select,{value:t.system||void 0,onValueChange:e=>O(s,{system:e}),children:[(0,a.jsx)(u.SelectTrigger,{role:"cell","aria-label":e("cell",{field:e("system"),row:s+1}),className:"h-8",children:(0,a.jsx)(u.SelectValue,{})}),(0,a.jsx)(u.SelectContent,{children:e9.map(e=>(0,a.jsx)(u.SelectItem,{value:e.id,children:e.label},e.id))})]}),(0,a.jsx)(o.Input,{role:"cell","aria-label":e("cell",{field:e("field"),row:s+1}),value:t.field,className:"h-8 font-mono",onChange:e=>O(s,{field:e.target.value})}),(0,a.jsx)(o.Input,{role:"cell","aria-label":e("cell",{field:e("value"),row:s+1}),value:t.value,className:"h-8",onChange:e=>O(s,{value:e.target.value})}),(0,a.jsxs)(u.Select,{value:t.classificationCode||void 0,onValueChange:e=>O(s,{classificationCode:e}),children:[(0,a.jsx)(u.SelectTrigger,{role:"cell","aria-label":e("cell",{field:e("classificationCode"),row:s+1}),className:"h-8",children:(0,a.jsx)(u.SelectValue,{})}),(0,a.jsx)(u.SelectContent,{children:x.places.map(e=>(0,a.jsx)(u.SelectItem,{value:e.id,children:e.label},e.id))})]}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":e("remove",{row:s+1}),onClick:()=>b(e=>e.filter((e,a)=>a!==s)),children:(0,a.jsx)(eN.X,{className:"size-4","aria-hidden":"true"})})]},s))]}),(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,a.jsxs)(i.Button,{type:"button",variant:"outline",onClick:()=>{S(""),b(e=>[...e,ae])},children:[(0,a.jsx)(z.Plus,{className:"size-4","aria-hidden":"true"}),e("add")]}),(0,a.jsx)("span",{className:"text-meta text-ink-muted tabular-nums",children:e("shown",{shown:M.length,total:j.length})})]})]})]}),D&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:D,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void P(),disabled:C,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>
1void I(),disabled:C||!R,children:[C&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}async function al(e,a,t){let s=await fetch(`/api/internal/manufacture-rules/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(a),signal:t}),l={};try{l=await s.json()}catch{}if(!s.ok||!0!==l.success||void 0===l.data)throw(0,h.serverMessageError)(l,`HTTP ${s.status}`);return l.data}function ar(e){return al("query",{},e?.signal)}function ai(){let e=(0,l.useTranslations)("bridge.data.materialClasses"),t=(0,m.useServerMessage)(),o=(0,F.useConfirmDiscard)(),[u,h]=(0,s.useState)(null),[p,x]=(0,s.useState)(!1),[g,f]=(0,s.useState)([]),[y,j]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[S,w]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),T=(0,s.useCallback)(async e=>{try{h(await ar({signal:e})),x(!1)}catch(e){e?.name!=="AbortError"&&x(!0)}},[]);if((0,s.useEffect)(()=>{let e=new AbortController;return T(e.signal),()=>e.abort()},[T]),(0,s.useEffect)(()=>{y&&u&&f(u.materialClassIds)},[y,u]),p)return(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("loadFailed")});if(!u)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});if("no-system"===u.state)return(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("noSystem")});let D=u.classes.filter(e=>g.includes(e.id)).map(e=>e.id),A=u.classes.filter(e=>u.materialClassIds.includes(e.id)),L=y&&D.join()!==A.map(e=>e.id).join(),E=async()=>{b||(!L||await o())&&j(!1)},M=async()=>{w(null),C(!1),v(!0);try{var e;let{revision:a}=await (e={materialClassIds:D,expectedRevision:u.revision},al("execute",{operation:"set-material-classes",...e}));h({...u,materialClassIds:D,revision:a}),C(!0),j(!1)}catch(e){w(e instanceof Error?t(e):String(e))}finally{v(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:A.length>0?A.map(e=>e.label).join(" · "):e("summaryEmpty"),onClick:()=>{C(!1),w(null),j(!0)}}),N&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:y,onOpenChange:e=>{e?j(!0):E()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-3",children:[(0,a.jsx)("ul",{className:"flex flex-col gap-1.5","aria-label":e("title"),children:u.classes.map(e=>(0,a.jsxs)("li",{className:"flex h-11 items-center gap-3 rounded-lg border border-line px-3",children:[(0,a.jsx)(_.Checkbox,{id:`material-class-${e.id}`,checked:g.includes(e.id),onCheckedChange:a=>f(t=>!0===a?[...t,e.id]:t.filter(a=>a!==e.id))}),(0,a.jsx)(c.Label,{htmlFor:`material-class-${e.id}`,className:"flex-1",children:e.label})]},e.id))}),(0,a.jsx)("p",{className:"text-meta text-ink-muted tabular-nums",children:e("count",{chosen:D.length,total:u.classes.length})})]}),S&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:S,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void E(),disabled:b,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>void M(),disabled:b||!L,children:[b&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}function an(e){return[...new Set(("string"==typeof e?e.split(/[,\s]+/):Array.isArray(e)?e:[]).flatMap(e=>"string"==typeof e&&e.trim()?[e.trim().toUpperCase()]:[]))]}function ao(e){if(e.length<2)return null;let a=e.flatMap(e=>an(e.skuPrefixes));
1return new Set(a).size!==a.length?"shared-prefix":1===e.filter(e=>0===an(e.skuPrefixes).length).length?null:"all-other"}function ac(){let e=(0,l.useTranslations)("bridge.data.secondQualityItems"),t=(0,m.useServerMessage)(),c=(0,F.useConfirmDiscard)(),[u,h]=(0,s.useState)(null),[p,x]=(0,s.useState)(!1),[g,f]=(0,s.useState)([]),[y,j]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[S,w]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),T=(0,s.useCallback)(async e=>{try{h(await ar({signal:e})),x(!1)}catch(e){e?.name!=="AbortError"&&x(!0)}},[]);if((0,s.useEffect)(()=>{let e=new AbortController;return T(e.signal),()=>e.abort()},[T]),(0,s.useEffect)(()=>{y&&u&&f(u.secondQualityItems.map(e=>({id:e.key,itemSku:e.itemSku,displayName:e.displayName,prefixes:e.skuPrefixes.join(", ")})))},[y,u]),p)return(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("loadFailed")});if(!u)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});if("no-system"===u.state)return(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("noSystem")});let D=u.secondQualityItems,A=g.map(e=>({itemSku:e.itemSku.trim(),displayName:e.displayName.trim(),skuPrefixes:an(e.prefixes)})),L=y&&JSON.stringify(A)!==JSON.stringify(D.map(({itemSku:e,displayName:a,skuPrefixes:t})=>({itemSku:e,displayName:a,skuPrefixes:t}))),E=null===ao(D)&&D.length>1,M=async()=>{b||(!L||await c())&&j(!1)},R=(e,a)=>f(t=>t.map(t=>t.id===e?{...t,...a}:t)),P=async()=>{if(w(null),C(!1),A.some(e=>!e.itemSku||!e.displayName))return void w(e("incomplete"));if(new Set(A.map(e=>e.itemSku)).size!==A.length)return void w(e("duplicate"));let a=ao(A);if(a)return void w(e("shared-prefix"===a?"sharedPrefix":"allOther"));v(!0);try{var s;let e=await (s={items:A,expectedRevision:u.revision},al("execute",{operation:"set-second-quality-items",...s}));h({...u,secondQualityItems:e.items,revision:e.revision}),C(!0),j(!1)}catch(e){w(e instanceof Error?t(e):String(e))}finally{v(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:D.length>0?E?D.map(a=>`${a.itemSku} ${a.displayName} \xb7 ${a.skuPrefixes.join(", ")||e("allOtherSummary")}`).join(" â "):D.map(e=>`${e.itemSku} ${e.displayName}`).join(" · "):e("summaryEmpty"),onClick:()=>{C(!1),w(null),j(!0)}}),N&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:y,onOpenChange:e=>{e?j(!0):M()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-3",children:[g.length>1&&(0,a.jsxs)("div",{className:"flex items-center gap-2 pl-1 pr-10 text-xs font-semibold text-ink-muted","aria-hidden":"true",children:[(0,a.jsx)("span",{className:"w-28 px-3",children:e("skuPlaceholder")}),(0,a.jsx)("span",{className:"flex-1 px-3",children:e("namePlaceholder")}),(0,a.jsx)("span",{className:"w-32 px-3",children:e("prefixesHeading")})]}),(0,a.jsxs)("ul",{className:"flex flex-col gap-1.5","aria-label":e("title"),children:[g.map((t,s)=>(0,a.jsxs)("li",{className:"flex h-11 items-center gap-2 rounded-lg border border-line pl-1 pr-1",children:[(0,a.jsx)(o.Input,{"aria-label":e("sku",{number:s+1}),value:t.itemSku,placeholder:e("skuPlaceholder"),onChange:e=>R(t.id,{itemSku:e.target.value}),className:"h-8 w-28 border-0 font-mono shadow-none"}),(0,a.jsx)(o.Input,{"aria-label":e("name",{number:s+1}),value:t.displayName,placeholder:e("namePlaceholder"),onChange:e=>R(t.id,{displayName:e.target.value}),className:"h-8 flex-1 border-0 shadow-none"}),g.length>1&&(0,a.jsx)(o.Input,{"aria-label":e("prefixes",{number:s+1}),value:t.prefixes,placeholder:e("prefixesPlaceholder"),onChange:e=>R(t.id,{prefixes:e.target.value}),className:"h-8 w-32 border-0 font-mono shadow-none"}),(0,a.jsx)(i.Button,{type:"button",variant:"ghost",size:"icon","aria-label":e("remove",{name:t.displayName.trim()||t.itemSku.trim()||String(s+1)}),onClick:()=>f(e=>e.filter(e=>e.id!==t.id)),children:(0,a.jsx)(eN.X,{className:"size-4","aria-hidden":"true"})})]},t.id)),(0,a.jsx)("li",{children:(0,a.jsxs)(i.Button,{type:"button",variant:"outline",className:"h-11 w-full border-dashed",onClick:()=>f(e=>[...e,{id:`new:${e.length}:${Date.now()}`,itemSku:"",displayName:"",prefixes:""}]),children:[(0,a.jsx)(z.Plus,{className:"size-4","aria-hidden":"true"}),e("add")]})})]})]}),S&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:S,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void M(),disabled:b,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>
1void P(),disabled:b||!L,children:[b&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}function ad(){let e=(0,l.useTranslations)("bridge.data.workOrderSheet"),t=(0,m.useServerMessage)(),u=(0,F.useConfirmDiscard)(),[h,p]=(0,s.useState)(null),[x,g]=(0,s.useState)(""),[f,y]=(0,s.useState)(!1),[j,b]=(0,s.useState)(!1),[v,S]=(0,s.useState)(null),[k,w]=(0,s.useState)(!1),N=(0,s.useCallback)(async e=>{try{p((await ar({signal:e})).workOrderSheet)}catch{}},[]);if((0,s.useEffect)(()=>{let e=new AbortController;return N(e.signal),()=>e.abort()},[N]),(0,s.useEffect)(()=>{f&&h&&g(h.url)},[f,h]),!h)return null;let C=f&&x.trim()!==h.url,T=async()=>{j||(!C||await u())&&y(!1)},D=async()=>{S(null),w(!1),b(!0);try{var e;let a=x.trim(),{revision:t}=await (e={url:a,expectedRevision:h.revision},al("execute",{operation:"set-work-order-sheet",...e}));p({url:a,revision:t}),w(!0),y(!1)}catch(e){S(e instanceof Error?t(e):String(e))}finally{b(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:h.url?function(e){try{return new URL(e).host}catch{return e}}(h.url):e("notSet"),onClick:()=>{w(!1),S(null),y(!0)}}),k&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:f,onOpenChange:e=>{e?y(!0):T()},children:(0,a.jsxs)(n.DialogContent,{size:"md",children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{htmlFor:"work-order-sheet-link",children:e("link")}),(0,a.jsx)(o.Input,{id:"work-order-sheet-link",type:"url",className:"font-mono",value:x,onChange:e=>g(e.target.value)})]}),v&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:v,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void T(),disabled:j,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>void D(),disabled:j||!C,children:[j&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}let au=["poNumber","shippingAddress","shippingMethod"];async function am(e,a,t){let s=await fetch(`/api/internal/sell-rules/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(a),signal:t}),l={};try{l=await s.json()}catch{}if(!s.ok||!0!==l.success||void 0===l.data)throw(0,h.serverMessageError)(l,`HTTP ${s.status}`);return l.data}function ah(e){return am("query",{},e?.signal)}function ap(e){return am("query",{view:"customer-fields"},e?.signal)}function ax(){let e=(0,l.useTranslations)("bridge.data.orderReviewFields"),t=(0,l.useTranslations)("bridge.data.orderReviewFields.fields"),o=(0,m.useServerMessage)(),u=(0,F.useConfirmDiscard)(),[h,p]=(0,s.use
1State)(null),[x,g]=(0,s.useState)(!1),[f,y]=(0,s.useState)([]),[j,b]=(0,s.useState)(!1),[v,S]=(0,s.useState)(!1),[w,N]=(0,s.useState)(null),[C,T]=(0,s.useState)(!1),D=(0,s.useCallback)(async e=>{try{p(await ah({signal:e})),g(!1)}catch(e){e?.name!=="AbortError"&&g(!0)}},[]);if((0,s.useEffect)(()=>{let e=new AbortController;return D(e.signal),()=>e.abort()},[D]),(0,s.useEffect)(()=>{j&&h&&y(h.orderReviewFields)},[j,h]),x)return(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("loadFailed")});if(!h)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});let A=au.filter(e=>f.includes(e)),L=j&&A.join()!==h.orderReviewFields.join(),E=async()=>{v||(!L||await u())&&b(!1)},M=async()=>{N(null),T(!1),S(!0);try{var e;let{revision:a}=await (e={orderReviewFields:A,expectedRevision:h.revision},am("execute",{operation:"set-order-review-fields",...e}));p({...h,orderReviewFields:A,revision:a}),T(!0),b(!1)}catch(e){N(e instanceof Error?o(e):String(e))}finally{S(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:h.orderReviewFields.length>0?h.orderReviewFields.map(e=>t(e)).join(" · "):e("summaryEmpty"),onClick:()=>{T(!1),N(null),b(!0)}}),C&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:j,onOpenChange:e=>{e?b(!0):E()},children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsx)(n.DialogBody,{children:(0,a.jsx)("ul",{className:"flex flex-col gap-1.5",children:au.map(e=>(0,a.jsxs)("li",{className:"flex h-11 items-center justify-between gap-3 rounded-lg border border-line px-3",children:[(0,a.jsx)(c.Label,{htmlFor:`order-review-field-${e}`,children:t(e)}),(0,a.jsx)(V.Switch,{id:`order-review-field-${e}`,checked:f.includes(e),onCheckedChange:a=>y(t=>a?[...t,e]:t.filter(a=>a!==e))})]},e))})}),w&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:w,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void E(),disabled:v,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>void M(),disabled:v||!L,children:[v&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}let ag="__not-set__";function af(e){return{channels:e.channels,entityStatusId:e.entityStatusId,receivablesAccountId:e.receivablesAccountId}}function ay(e){let t=e.value&&!e.options.some(a=>a.id===e.value)?[{id:e.value,label:e.value},...e.options]:e.options;return(0,a.jsxs)(u.Select,{value:e.value||ag,onValueChange:a=>e.onChange(a===ag?"":a),children:[(0,a.jsx)(u.SelectTrigger,{"aria-label":e.label,className:e.className,children:(0,a.jsx)(u.SelectValue,{})}),(0,a.jsxs)(u.SelectContent,{children:[null===e.optional&&e.value?null:(0,a.jsx)(u.SelectItem,{value:ag,children:e.optional??""}),t.map(e=>(0,a.jsx)(u.SelectItem,{value:e.id,children:e.label},e.id))]})]})}function aj(){let e=(0,l.useTranslations)("bridge.data.customerDefaults"),t=(0,l.useTranslations)("bridge.data.customerDefaults.customerType"),o=(0,m.useServerMessage)(),u=(0,F.useConfirmDiscard)(),[h,p]=(0,s.use
1State)(void 0),[x,g]=(0,s.useState)(null),[f,y]=(0,s.useState)(null),[j,b]=(0,s.useState)(null),[v,S]=(0,s.useState)(!1),[w,N]=(0,s.useState)(!1),[C,T]=(0,s.useState)(null),[D,A]=(0,s.useState)(!1),L=(0,s.useCallback)(async e=>{try{p((await ah({signal:e})).customerDefaults)}catch(e){e?.name!=="AbortError"&&p(null)}},[]);if((0,s.useEffect)(()=>{let e=new AbortController;return L(e.signal),()=>e.abort()},[L]),(0,s.useEffect)(()=>{var e;if(!v)return;let a=new AbortController;return g(null),b(null),y(null),(e={signal:a.signal},am("query",{view:"customer-defaults"},e?.signal)).then(e=>{g(e),b(af(e))}).catch(e=>{e?.name!=="AbortError"&&y(e instanceof Error?o(e):String(e))}),()=>a.abort()},[v]),null===h)return null;if(void 0===h)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});let E=v&&!!x&&!!j&&JSON.stringify(j)!==JSON.stringify(af(x)),M=async()=>{w||(!E||await u())&&S(!1)},R=(e,a)=>b(t=>t&&{...t,channels:t.channels.map(t=>t.customerType===e?{...t,...a}:t)}),P=async()=>{if(x&&j){if(T(null),A(!1),!j.entityStatusId||j.channels.some(e=>{let a=[e.channelKey,e.currencyCode,e.categoryId].filter(Boolean).length;return a>0&&a<3}))return void T(e("incomplete"));N(!0);try{var a;let{revision:e}=await (a={...j,expectedRevision:x.revision},am("execute",{operation:"set-customer-defaults",...a}));p({...j,revision:e}),A(!0),S(!1)}catch(e){T(e instanceof Error?o(e):String(e))}finally{N(!1)}}},O=h.channels.filter(e=>e.channelKey);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:O.length>0?O.map(e=>`${t(e.customerType)} ${e.currencyCode}`).join(" · "):e("notSet"),onClick:()=>{A(!1),T(null),S(!0)}}),D&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:v,onOpenChange:e=>{e?S(!0):M()},children:(0,a.jsxs)(n.DialogContent,{size:"lg",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-5",children:[f&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("loadFailed"),description:f}),!f&&(!x||!j)&&(0,a.jsxs)("div",{"aria-busy":"true",children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"h-32 w-full"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]}),x&&j&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("table",{className:"w-full text-body",children:[(0,a.jsx)("thead",{children:(0,a.jsxs)("tr",{className:"text-left text-meta text-ink-muted",children:[(0,a.jsx)("th",{scope:"col",className:"pb-2 pr-3 font-medium",children:e("customerTypeColumn")}),(0,a.jsx)("th",{scope:"col",className:"pb-2 pr-3 font-medium",children:e("salesChannel")}),(0,a.jsx)("th",{scope:"col",className:"pb-2 pr-3 font-medium",children:e("currency")}),(0,a.jsx)("th",{scope:"col",className:"pb-2 font-medium",children:e("category")})]})}),(0,a.jsx)("tbody",{children:j.channels.map(s=>{let l=t(s.customerType);return(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{scope:"row",className:"py-1 pr-3 text-left font-medium",children:l}),(0,a.jsx)("td",{className:"py-1 pr-3",children:(0,a.jsx)(ay,{label:e("salesChannelFor",{name:l}),value:s.channelKey,options:x.options.channels,optional:e("notSet"),onChange:e=>R(s.customerType,{channelKey:e})})}),(0,a.jsx)("td",{className:"py-1 pr-3",children:(0,a.jsx)(ay,{label:e("currencyFor",{name:l}),value:s.currencyCode,options:x.options.currencies,optional:e("notSet"),onChange:e=>R(s.customerType,{currencyCode:e})})}),(0,a.jsx)("td",{className:"py-1",children:(0,a.jsx)(ay,{label:e("categoryFor",{name:l}),value:s.categoryId,options:x.options.categories,optional:e("notSet"),onChange:e=>R(s.customerType,{categoryId:e})})})]},s.customerType)})})]}),(0,a.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{children:e("status")}),(0,a.jsx)(ay,{label:e("status"),value:j.entityStatusId,options:x.options.statuses,optional:null,onChange:e=>b({...j,entityStatusId:e})})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(c.Label,{children:e("receivablesAccount")}
1),(0,a.jsx)(ay,{label:e("receivablesAccount"),value:j.receivablesAccountId,options:x.options.accounts,optional:e("notSet"),onChange:e=>b({...j,receivablesAccountId:e})})]})]})]})]}),C&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:C,className:"mx-6 mb-3 shrink-0"}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void M(),disabled:w,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>void P(),disabled:w||!E,children:[w&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}function ab(){let e=(0,l.useTranslations)("bridge.data.customerFields"),t=(0,l.useTranslations)("bridge.data.customerFields.facts"),o=(0,l.useTranslations)("bridge.data.customerFields.keptOnValues"),c=(0,m.useServerMessage)(),h=(0,F.useConfirmDiscard)(),[p,x]=(0,s.useState)(void 0),[g,f]=(0,s.useState)(null),[y,j]=(0,s.useState)(null),[b,v]=(0,s.useState)([]),[S,w]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[T,D]=(0,s.useState)(null),[A,L]=(0,s.useState)(!1),[E,M]=(0,s.useState)(!1),R=(0,s.useCallback)(async e=>{try{x((await ah({signal:e})).customerFieldsRequired)}catch(e){e?.name!=="AbortError"&&x(null)}},[]);if((0,s.useEffect)(()=>{let e=new AbortController;return R(e.signal),()=>e.abort()},[R]),(0,s.useEffect)(()=>{if(!S)return;let e=new AbortController;return f(null),v([]),j(null),ap({signal:e.signal}).then(e=>{f(e),v(e.fields)}).catch(e=>{e?.name!=="AbortError"&&j(e instanceof Error?c(e):String(e))}),()=>e.abort()},[S]),null===p)return null;if(void 0===p)return(0,a.jsx)(r.ManageRow,{title:e("title"),"aria-busy":"true",summary:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"mt-1 h-3 w-40"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]})});let P=g?b.filter((e,a)=>e.required!==g.fields[a].required||e.serviceField!==g.fields[a].serviceField):[],O=S&&P.length>0,I=async()=>{N||(!O||await h())&&w(!1)},z=(e,a)=>v(t=>t.map(t=>t.key===e?{...t,...a}:t)),$=async()=>{if(g){D(null),M(!1),C(!0);try{var e;await (e={expectedRevision:g.revision},am("execute",{operation:"refresh-customer-choices",...e}));let a=await ap();f(a),v(a.fields),M(!0)}catch(e){D(e instanceof Error?c(e):String(e))}finally{C(!1)}}},_=async()=>{if(g){D(null),L(!1),C(!0);try{var e;await (e={fields:P.map(e=>({key:e.key,required:e.required,...e.fieldEditable&&e.serviceField?{serviceField:e.serviceField}:{}})),expectedRevision:g.revision},am("execute",{operation:"set-customer-fields",...e})),x(b.filter(e=>e.required).length),L(!0),w(!1)}catch(e){D(e instanceof Error?c(e):String(e))}finally{C(!1)}}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:e("title"),summary:e("summary",{count:p}),onClick:()=>{L(!1),D(null),w(!0)}}),A&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("saved")}),(0,a.jsx)(n.Dialog,{open:S,onOpenChange:e=>{e?w(!0):I()},children:(0,a.jsxs)(n.DialogContent,{size:"lg",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:e("title")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-3",children:[y&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("loadFailed"),description:y}),!y&&!g&&(0,a.jsxs)("div",{"aria-busy":"true",children:[(0,a.jsx)(k.Skeleton,{"aria-hidden":"true",className:"h-64 w-full"}),(0,a.jsx)("span",{className:"sr-only",children:e("loading")})]}),g&&(0,a.jsxs)("table",{className:"w-full text-body",children:[(0,a.jsx)("thead",{children:(0,a.jsxs)("tr",{className:"text-left text-meta text-ink-muted",children:[(0,a.jsx)("th",{scope:"col",className:"pb-2 pr-3 font-medium",children:e("fact")}),(0,a.jsx)("th",{scope:"col",className:"pb-2 pr-3 font-medium",children:e("field")}),(0,a.jsx)("th",{scope:"col",className:"pb-2 pr-3 font-medium",children:e("keptOn")}),(0,a.jsx)("th",{scope:"col",className:"pb-2 font-medium",children:e("required")})]})}),(0,a.jsx)("tbody",{children:b.map(s=>{let l=t(s.key),r=s.serviceField&&!g.fieldOptions.some(e=>e.id===s.serviceField)?[{id:s.serviceField,label:s.fieldLabel},...g.fieldOptions]:g.fieldOptions;return(0,a.jsxs)("tr",{className:"border-t border-line",children:[(0,a.jsx)("th",{scope:"row",className:"py-1.5 pr-3 text-left font-medium",children:l}),(0,a.jsx)("td",{className:"py-1.5 pr-3",children:s.fieldEditable?(0,a.jsxs)(u.Select,{value:s.serviceField||void 0,onValueChange:e=>z(s.key,{serviceField:e}),children:[(0,a.jsx)(u.SelectTrigger,{"aria-label":e("fieldFor",{name:l}),children:(0,a.jsx)(u.SelectValue,{placeholder:e("notSet")})}),(0,a.jsx)(u.SelectContent,{children:r.map(e=>(0,a.jsx)(u.SelectItem,{value:e.id,children:e.label},e.id))})]}):(0,a.jsx)("span",{children:s.fieldLabel||e("notSet")})}),(0,a.jsxs)("td",{className:"py-1.5 pr-3 text-ink-muted",children:[o(s.keptOn),null!==s.choices?` \xb7 ${e("choices",{count:s.choices})}`:""]}),(0,a.jsx)("td",{className:"py-1.5",children:(0,a.jsx)(V.Switch,{"aria-label":e("requiredFor",{name:l}),checked:s.required,disabled:s.requiredLocked,onCheckedChange:e=>z(s.key,{required:e})})})]},s.key)})})]})]}),T&&(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed"),description:T,className:"mx-6 mb-3 shrink-0"}),E&&(0,a.jsx)("p",{role:"status",className:"sr-only",children:e("choicesRead")}),(0,a.jsxs)(n.DialogFooter,{children:[(0,a.jsx)(i.Button,{variant:"ghost",className:"mr-auto",onClick:()=>void $(),disabled:N||!g||O,children:e("readAgain")}),(0,a.jsx)(i.Button,{variant:"outline",onClick:()=>void I(),disabled:N,children:e("cancel")}),(0,a.jsxs)(i.Button,{onClick:()=>
1void _(),disabled:N||!O,children:[N&&(0,a.jsx)(B.Loader2,{className:"mr-1.5 h-3.5 w-3.5 animate-spin","aria-hidden":"true"}),e("save")]})]})]})})]})}var av=e.i(54615),aS=e.i(764240),ak=e.i(515253),aw=e.i(741722);function aN({actionId:e}){let t=(0,l.useTranslations)("bridge.actions.createSalesOrders.customerSubmissions"),[r,i]=(0,s.useState)(null),[n,o]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[h,p]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let a=new AbortController;return fetch(`/api/organization/actions/${e}/customer-submissions-config`,{signal:a.signal}).then(e=>e.json()).then(e=>i(!!e.enabled)).catch(e=>{e?.name!=="AbortError"&&i(!1)}),()=>a.abort()},[e]);let x=async a=>{if(!n){o(!0),m(!1),p(!1),i(a);try{let t=await fetch(`/api/organization/actions/${e}/customer-submissions-config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:a})});if(!t.ok)throw Error(`HTTP ${t.status}`);(0,ec.invalidateSellOrderFormsCache)({family:"customer-submissions"}),p(!0)}catch{i(r),m(!0)}finally{o(!1)}}};return null===r?(0,a.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,a.jsx)("span",{role:"status",className:"sr-only",children:t("loading")}),(0,a.jsxs)("div",{className:"space-y-2 flex-1",children:[(0,a.jsx)(k.Skeleton,{className:"h-4 w-40"}),(0,a.jsx)(k.Skeleton,{className:"h-4 w-72 max-w-full"})]}),(0,a.jsx)(k.Skeleton,{className:"h-5 w-9 rounded-full"})]}):(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,a.jsx)(c.Label,{id:"customer-submissions-toggle-label",children:t("title")}),(0,a.jsxs)("span",{className:"flex shrink-0 items-center gap-2","aria-busy":n,children:[n?(0,a.jsx)(w.Spinner,{size:14}):null,(0,a.jsx)(V.Switch,{checked:r,onCheckedChange:x,disabled:n,"aria-labelledby":"customer-submissions-toggle-label"})]})]}),(0,a.jsx)("p",{className:"text-meta text-ink-muted",children:t("description")}),u?(0,a.jsx)(d.Notice,{tone:"blocker",title:t("errorToast")}):null,(0,a.jsx)("span",{role:"status","aria-live":"polite",className:"sr-only",children:h?t(r?"enabledToast":"disabledToast"):""})]})}var aC=e.i(60910);let aT={supportedTargetLanguages:[],generalGuidancePrompt:"",titleGuidancePrompt:"",terminologyGuidancePrompt:""};function aF({actionId:e}){let t=(0,l.useTranslations)("bridge.actions.productLocalisation"),r=(0,m.useServerMessage)(),[u,p]=(0,s.useState)(aT),[x,g]=(0,s.useState)(!0),[f,y]=(0,s.useState)(!1),[j,b]=(0,s.useState)(null),[v,S]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let a=new AbortController;return g(!0),fetch(`/api/organization/actions/${e}/product-localisation-config`,{signal:a.signal}).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(e=>{p({supportedTargetLanguages:Array.isArray(e.supportedTargetLanguages)?e.supportedTargetLanguages:[],generalGuidancePrompt:"string"==typeof e.generalGuidancePrompt?e.generalGuidancePrompt:"",titleGuidancePrompt:"string"==typeof e.titleGuidancePrompt?e.titleGuidancePrompt:"",terminologyGuidancePrompt:"string"==typeof e.terminologyGuidancePrompt?e.terminologyGuidancePrompt:""}),b(null)}).catch(e=>{e?.name!=="AbortError"&&b(t("loadError"))}).finally(()=>g(!1)),()=>a.abort()},[e,t]);let w=(e,a,t)=>{p(s=>({...s,supportedTargetLanguages:s.supportedTargetLanguages.map((s,l)=>l===e?{...s,[a]:"code"===a?t.toUpperCase():t}:s)}))},N=async()=>{if(f)return;y(!0),b(null),S(!1);let a={...u,supportedTargetLanguages:u.supportedTargetLanguages.map(e=>({code:e.code.trim().toUpperCase(),label:e.label.trim()})).filter(e=>e.code&&e.label)};try{let t=await fetch(`/api/organization/actions/${e}/product-localisation-config`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),s=await t.json();if(!t.ok)throw(0,h.serverMessageError)(s,`HTTP ${t.status}`);p(s),S(!0)}catch(e){b(r(e,{uncoded:"generic"}))}finally{y(!1)}};return x?(0,a.jsxs)(n.DialogBody,{className:"space-y-5",children:[(0,a.jsx)("span",{role:"status",className:"sr-only",children:t("loading")}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(k.Skeleton,{className:"h-4 w-48"}),(0,a.jsx)(k.Skeleton,{className:"h-4 w-80 max-w-full"})]}),(0,a.jsxs)("div",{className:"space-y-1.5",children:[(0,a.jsx)(k.Skeleton,{className:"h-9 w-full"}),(0,a.jsx)(k.Skeleton,{className:"h-9 w-full"})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(n.DialogBody,{className:"space-y-5",onChange:()=>S(!1),onClick:()=>S(!1),children:[(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(c.Label,{children:t("languages")}),(0,a.jsx)("div",{className:"space-y-1.5",children:u.supportedTargetLanguages.map((e,s)=>(0,a.jsxs)("div",{className:"grid grid-cols-[96px_1fr_36px] gap-2",children:[(0,a.jsx)(o.Input,{value:e.code,onChange:e=>w(s,"code",e.target.value),placeholder:"IT",maxLength:8,"aria-label":t("languageCode")}),(0,a.jsx)(o.Input,{value:e.label,onChange:e=>w(s,"label",e.target.value),placeholder:t("languageLabelPlaceholder"),"aria-label":t("languageLabel")}),(0,a.jsx)(i.Button,{type:"button",variant:"outline",size:"icon",onClick:()=>{p(e=>({...e,supportedTargetLanguages:e.supportedTargetLanguages.filter((e,a)=>a!==s)}))},"aria-label":t("removeLanguage"),children:(0,a.jsx)(T.Trash2,{className:"h-4 w-4"})})]},`${e.code}-${s}`))}),(0,a.jsxs)(i.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>{p(e=>
1({...e,supportedTargetLanguages:[...e.supportedTargetLanguages,{code:"",label:""}]}))},children:[(0,a.jsx)(z.Plus,{className:"mr-2 h-4 w-4"}),t("addLanguage")]})]}),(0,a.jsx)(aD,{id:"product-localisation-general-guidance",label:t("generalGuidance.label"),value:u.generalGuidancePrompt,onChange:e=>p(a=>({...a,generalGuidancePrompt:e})),placeholder:t("generalGuidance.placeholder")}),(0,a.jsx)(aD,{id:"product-localisation-title-guidance",label:t("titleGuidance.label"),value:u.titleGuidancePrompt,onChange:e=>p(a=>({...a,titleGuidancePrompt:e})),placeholder:t("titleGuidance.placeholder")}),(0,a.jsx)(aD,{id:"product-localisation-terminology-guidance",label:t("terminologyGuidance.label"),value:u.terminologyGuidancePrompt,onChange:e=>p(a=>({...a,terminologyGuidancePrompt:e})),placeholder:t("terminologyGuidance.placeholder")})]}),(0,a.jsxs)(n.DialogFooter,{className:"flex-col sm:flex-col",children:[j&&(0,a.jsx)(d.Notice,{tone:"blocker",title:j}),(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,a.jsx)("span",{role:"status","aria-live":"polite",className:"sr-only",children:v?t("saveSuccess"):""}),(0,a.jsxs)(i.Button,{type:"button",onClick:N,disabled:f,children:[f?(0,a.jsx)(B.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}):(0,a.jsx)(aC.Save,{className:"mr-2 h-4 w-4"}),t("save")]})]})]})]})}function aD({id:e,label:t,value:s,placeholder:l,onChange:r}){return(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(c.Label,{htmlFor:e,children:t}),(0,a.jsx)(e$.Textarea,{id:e,value:s,onChange:e=>r(e.target.value),placeholder:l,className:"min-h-[88px] resize-y"})]})}var aA=e.i(948907);function aL({actionId:e,href:t,focus:i}){let n=(0,l.useTranslations)(aA.PACKET_NAMESPACE),o=(0,y.useRouter)(),[c,d]=(0,s.useState)(void 0);return(0,s.useEffect)(()=>{i&&o.replace(t)},[i,t,o]),(0,s.useEffect)(()=>{let a=new AbortController;return fetch(`/api/organization/actions/${e}/supplier-packet-config?options=none`,{signal:a.signal}).then(async e=>{let t=e.ok?await e.json():null;a.signal.aborted||d(t?.config??null)}).catch(()=>{a.signal.aborted||d(null)}),()=>a.abort()},[e]),(0,a.jsx)(r.ManageRow,{title:n("title"),summary:void 0===c?(0,a.jsx)(k.Skeleton,{className:"h-3 w-48","aria-hidden":"true"}):null===c?n("loadError"):n("rowSummary",{locations:c.receivingLocations.length,instructions:c.instructions.length,files:c.attachments.length}),trailing:c?(0,a.jsx)(v.Badge,{tone:c.enabled?"progress":"neutral",children:n(c.enabled?"on":"off")}):void 0,href:t,"data-testid":"rules-supplier-packet"})}var aE=e.i(291382);function aM({orgSlug:e,section:t,alsoWorkspace:i}){let n=(0,l.useTranslations)("bridge.data.vendorsList"),o=(0,l.useTranslations)("bridge.data"),[c,d]=(0,s.useState)(void 0);(0,s.useEffect)(()=>{let e=new AbortController;return(0,aE.querySuppliers)({signal:e.signal}).then(a=>{e.signal.aborted||d(a)}).catch(()=>{e.signal.aborted||d(null)}),()=>e.abort()},[]);let u=c?.provider?aE.DESTINATION_LABELS[c.provider]??c.provider:null,m=void 0===c?void 0:c&&"ready"===c.state&&u?[n("rowSummary",{suppliers:c.counts.suppliers,total:c.counts.all,destination:u}),o("dataSet.alsoUsedBy",{phases:i})].join(" · "):n("unavailableSummary");return(0,a.jsx)(r.ManageRow,{title:n("rowTitle"),summary:m,href:`/${e}/manage/rules/${t}/vendors`,className:c&&c.counts.new>0?"shadow-lift-attention":void 0,trailing:c&&c.counts.new>0?(0,a.jsx)(v.Badge,{tone:"attention",children:n("newCount",{count:c.counts.new})}):void 0})}var aR=e.i(301015),aP=e.i(506632),aO=e.i(675797),aB=e.i(655155);async function aI(e,a,t){let s=await fetch(`/api/internal/manufacturing-info/${e}`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(a),signal:t}),l={};try{l=await s.json()}catch{}if(!s.ok||!0!==l.success||void 0===l.data)throw(0,h.serverMessageError)(l,`HTTP ${s.status}`);return l.data}async function az(e){let a=await (0,aB.uploadHelperAttachment)(e,{});return{fileId:a.attachmentId,fileName:a.fileName}}function a$(e){aI("query",{certificateFor:e}).then(e=>{window.open(e.url,"_blank","noopener")}).catch(()=>void 0)}let a_={complete:"progress","missing-certificate":"attention","missing-facts":"attention",expired:"blocker"};
1function aK({focus:e=!1}){let t=(0,l.useTranslations)("bridge.data.manufacturer"),o=(0,l.useTranslations)("components.manufacturers"),c=(0,m.useServerMessage)(),d=(0,aP.useCountryName)(),u=(0,eD.useNow)({updateInterval:36e5}).toISOString().slice(0,10),[h,p]=(0,s.useState)(void 0),[x,g]=(0,s.useState)(null),[f,y]=(0,s.useState)(e),[j,b]=(0,s.useState)(null),[S,k]=(0,s.useState)(0);(0,s.useEffect)(()=>{var e;let a=new AbortController;return(e={signal:a.signal},aI("query",{},e?.signal)).then(e=>{a.signal.aborted||(p(e),g(null))}).catch(e=>{a.signal.aborted||(p(null),g(c(e,{uncoded:"generic"})))}),()=>a.abort()},[S,c]);let w=(0,s.useCallback)(e=>(0,aO.facilityStatus)(e,u,h?.fields),[h?.fields,u]),C=(0,s.useMemo)(()=>{let e=(h?.sites??[]).map(w);return e.find(e=>"expired"===e)??e.find(e=>"complete"!==e)??null},[h?.sites,w]),T=void 0===h?void 0:h?.state==="ready"?[h.manufacturer.legalName??h.manufacturer.name,h.manufacturer.countryCode?d(h.manufacturer.countryCode):null,t("siteCount",{count:h.sites.length})].filter(Boolean).join(" · "):h?.state==="no-destination"?t("noDestination"):x??t("unavailable"),F=async e=>{if(!h)return t("saveFailed");try{var a;return await (a={siteKey:e.key,expectedRevision:h.revision,certificate:{...e.certificate?{certificate:e.certificate}:{},...e.certificateValidUntil?{certificateValidUntil:e.certificateValidUntil}:{},...e.certificateFile?{certificateFile:e.certificateFile}:{}}},aI("execute",{operation:"save-site",...a})),k(e=>e+1),null}catch(e){return c(e,{uncoded:"generic"})}},D=h?.manufacturer.legalName??h?.manufacturer.name??"";return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:t("rowTitle"),summary:T,onClick:h?.state==="ready"?()=>y(!0):void 0,className:C?"shadow-lift-attention":void 0,trailing:C?(0,a.jsx)(v.Badge,{tone:a_[C],children:o(`status.${C}`)}):void 0}),h?.state==="ready"?(0,a.jsx)(n.Dialog,{open:f,onOpenChange:y,children:(0,a.jsxs)(n.DialogContent,{size:"lg",scrollable:!0,children:[(0,a.jsx)(n.DialogHeader,{children:(0,a.jsx)(n.DialogTitle,{children:t("rowTitle")})}),(0,a.jsxs)(n.DialogBody,{className:"space-y-6",children:[(0,a.jsx)(r.ManageSection,{title:D||t("rowTitle"),trailing:h.provider?(0,a.jsx)("span",{className:"text-meta text-ink-muted",children:aE.DESTINATION_LABELS[h.provider]??h.provider}):void 0,children:(0,a.jsx)(aR.FactList,{facts:[{label:t("businessId"),value:h.manufacturer.businessId,empty:t("notSet")},{label:t("country"),value:h.manufacturer.countryCode?d(h.manufacturer.countryCode):null,empty:t("notSet")},{label:t("address"),value:h.manufacturer.address,empty:t("notSet")}]})}),(0,a.jsx)(r.ManageSection,{title:t("sites"),trailing:(0,a.jsx)("span",{className:"text-meta text-ink-muted",children:t("fromWorkOrderRules")}),children:0===h.sites.length?(0,a.jsx)(N.StatePanel,{title:t("noSites")}):(0,a.jsx)(r.ManageRowList,{children:h.sites.map(e=>{let t=w(e);return(0,a.jsx)(r.ManageRow,{title:e.name,summary:[e.address,e.countryCode?d(e.countryCode):null].filter(Boolean).join(" · ")||void 0,onClick:()=>b(e),className:"bg-canvas",trailing:(0,a.jsx)(v.Badge,{tone:a_[t],children:o(`status.${t}`)})},e.key)})})})]}),(0,a.jsx)(n.DialogFooter,{children:(0,a.jsx)(i.Button,{type:"button",variant:"quiet",onClick:()=>y(!1),children:t("close")})})]})}):null,h?.state==="ready"?(0,a.jsx)(aR.FacilityDialog,{kind:"site",open:null!==j,onOpenChange:e=>{e||b(null)},facility:j,existingKeys:h.sites.map(e=>e.key),fields:h.fields,ownerLabel:D,onSave:F,uploadCertificate:az,openCertificate:a$,destinationFacts:!0}):null]})}var aH=e.i(124254),aU=e.i(548463);let aq="/api/organization/actions/manage-catalogues/price-channels";function aV(){let e=(0,l.useTranslations)("bridge.data.channelPrices"),{orgRole:t}=(0,aH.useAuth)(),i="org:admin"===t,[n,o]=(0,s.useState)(null),[c,m]=(0,s.useState)(null),[h,p]=(0,s.use
1State)(!1);(0,s.useEffect)(()=>{let e=!1;return fetch(aq).then(async e=>e.ok?await e.json():null).then(a=>{e||o(Array.isArray(a?.channels)?a.channels:[])}).catch(()=>{e||o([])}),()=>{e=!0}},[]);let x=(0,s.useCallback)(async(e,a)=>{if(!n||c)return;let t="own"===a?null:a;p(!1),m(e),o(n.map(a=>{if(a.key!==e)return a;let{samePriceAsChannelKey:s,...l}=a;return t?{...l,samePriceAsChannelKey:t}:l}));try{let a=await fetch(aq,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({channelKey:e,samePriceAsChannelKey:t})}),s=a.ok?await a.json():null;if(!s||!Array.isArray(s.channels))throw Error("save-failed");o(s.channels)}catch{o(n),p(!0)}finally{m(null)}},[n,c]);if(null===n)return(0,a.jsx)(r.ManageSection,{title:e("title"),"data-testid":"channel-prices",children:(0,a.jsx)(k.Skeleton,{className:"h-14"})});let g=n.filter(e=>!1!==e.isActive);if(g.length<2)return null;let f=e=>n.find(a=>a.key===e)?.label??e;return(0,a.jsxs)(r.ManageSection,{title:e("title"),"data-testid":"channel-prices",children:[h?(0,a.jsx)(d.Notice,{tone:"blocker",title:e("saveFailed")}):null,(0,a.jsx)(r.ManageRowList,{children:g.map(t=>{let s=(0,aU.channelPriceSource)(t.key,n),l="own"===s.kind?"own":"same-as"===s.kind?s.channelKey:"",o=n.some(e=>
1e.samePriceAsChannelKey?.trim()===t.key)?[]:(0,aU.followableChannelKeys)(t.key,n),d="own"===s.kind?e("ownPrice"):"same-as"===s.kind?e("sameAs",{channel:f(s.channelKey)}):e("choose");return(0,a.jsx)(r.ManageRow,{title:t.label,"data-testid":`channel-price-${t.key}`,trailing:i?(0,a.jsxs)(a.Fragment,{children:[c===t.key?(0,a.jsx)(w.Spinner,{size:14}):null,(0,a.jsxs)(u.Select,{value:l,disabled:null!==c,onValueChange:e=>void x(t.key,e),children:[(0,a.jsx)(u.SelectTrigger,{"aria-label":e("priceOf",{channel:t.label}),className:"h-9 w-48 text-sm",children:(0,a.jsx)(u.SelectValue,{placeholder:e("choose"),children:d})}),(0,a.jsxs)(u.SelectContent,{children:[(0,a.jsx)(u.SelectItem,{value:"own",children:e("ownPrice")}),o.map(t=>(0,a.jsx)(u.SelectItem,{value:t,children:e("sameAs",{channel:f(t)})},t))]})]})]}):(0,a.jsx)("span",{className:"text-sm text-ink-muted",children:d})},t.key)})})]})}function aG({actionId:e,focus:t}){let o=(0,l.useTranslations)("bridge.data"),c=(0,l.useTranslations)("bridge.data.rulesPage"),u=(0,l.useTranslations)("bridge.data.catalogueSources"),h=(0,l.useTranslations)("bridge.account"),p=(0,m.useServerMessage)(),[x,g]=(0,s.useState)(t),[f,y]=(0,s.useState)(void 0),[j,C]=(0,s.useState)(null),[T,F]=(0,s.useState)(null),[D,A]=(0,s.useState)(0),L=null!==j;(0,s.useEffect)(()=>{let a=new AbortController;return y(void 0),F(null),fetch(`/api/organization/actions/${e}/catalogue-sources`,{signal:a.signal}).then(async e=>{let t=e.ok?await e.json():null;a.signal.aborted||y(Array.isArray(t?.sources)?t.sources:null)}).catch(()=>{a.signal.aborted||y(null)}),()=>a.abort()},[e,D]);let E=async a=>{if(!L){C(a),F(null);try{let t=await fetch(`/api/organization/actions/${e}/catalogue-sources`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({kind:a})}),s=await t.json().catch(()=>null);if(!t.ok||!Array.isArray(s?.sources))return void F(p(s));y(s.sources)}catch(e){F(p(e))}finally{C(null)}}},M=f?.find(e=>e.active),R=void 0===f?void 0:null===f?u("loadFailed"):M?u(`kinds.${M.kind}`):c("noCatalogueSource");return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageRow,{title:c("catalogueSource"),summary:void 0===f?(0,a.jsx)(k.Skeleton,{className:"h-3 w-32","aria-hidden":"true"}):R,"aria-busy":void 0===f||L||void 0,"aria-label":`${o("dataSet.manage")} ${c("catalogueSource")}`,onClick:()=>g(!0),"data-testid":"rules-catalogue-source"}),(0,a.jsx)(n.Dialog,{open:x,onOpenChange:g,children:(0,a.jsxs)(n.DialogContent,{size:"md",scrollable:!0,"aria-describedby":void 0,children:[(0,a.jsx)(n.DialogHeader,{className:"pr-8",children:(0,a.jsx)(n.DialogTitle,{children:u("title")})}),(0,a.jsxs)(n.DialogBody,{children:[T?(0,a.jsx)(d.Notice,{className:"mb-3",tone:"blocker",title:T}):null,void 0===f?(0,a.jsx)(r.ManageStateView,{state:{kind:"loading",layout:"rows",count:3}}):null===f?(0,a.jsx)(N.StatePanel,{tone:"blocker",title:u("loadFailed"),action:(0,a.jsx)(i.Button,{variant:"secondary",size:"sm",onClick:()=>A(e=>e+1),children:h("retry")})}):0===f.length?(0,a.jsx)(N.StatePanel,{title:u("empty")}):(0,a.jsx)(S.RowList,{role:"radiogroup","aria-label":u("title"),children:f.map(e=>(0,a.jsx)(S.Row,{role:"radio","aria-checked":e.active,"aria-disabled":!e.available||L||void 0,"aria-busy":j===e.kind||void 0,title:u(`kinds.${e.kind}`),description:e.account?u("connectedAs",{account:e.account}):void 0,selected:e.active,trailing:j===e.kind?(0,a.jsx)(w.Spinner,{}):e.active?(0,a.jsx)(b.Check,{className:"size-4","aria-hidden":"true"}):e.available?void 0:(0,a.jsx)(v.Badge,{tone:"neutral",children:u("notActive")}),onClick:e.available&&!e.active?()=>void E(e.kind):void 0,disabled:L,"data-testid":`catalogue-source-${e.kind}`},e.kind))})]}),(0,a.jsx)(n.DialogFooter,{children:(0,a.jsx)(i.Button,{type:"button",variant:"outline",onClick:()=>g(!1),children:u("close")})})]})})]})}e.s(["DataContent",0,function({section:e}){let{valueSets:i,connectedProviders:n,actions:o,isLoading:c,focusType:d,fetchAll:u}
1=function(){let[e,a]=(0,s.useState)([]),[t,l]=(0,s.useState)({}),[r,i]=(0,s.useState)([]),[n,o]=(0,s.useState)(!0),c=(0,y.useSearchParams)().get("focus"),d=(0,s.useCallback)(async()=>{try{let[e,t,s]=await Promise.all([fetch("/api/organization/value-sets"),fetch("/api/organization/connections"),fetch("/api/organization/actions?scope=shell")]);if(e.ok){let t=await e.json();Array.isArray(t)&&a(t)}if(t.ok){let e=await t.json(),a={};for(let t of aw.connectionsConfig){if(!t.statusCheck){a[t.id]=!1;continue}switch(t.statusCheck.type){case"oauth":default:a[t.id]=!1;break;case"team-chat":a[t.id]=!!e.teamChat?.enabled;break;case"credentials":a[t.id]=!!t.statusCheck.provider&&!!e.credentials?.[t.statusCheck.provider]?.connected}}l(a)}if(s.ok){let e=await s.json();i(e.actions??[])}}catch(e){console.error("Error fetching data:",e)}finally{o(!1)}},[]);(0,s.useEffect)(()=>{d()},[d]);let u=(0,s.useMemo)(()=>Object.keys(t).filter(e=>t[e]),[t]);return(0,s.useEffect)(()=>{if(c&&!n){let e=new URL(window.location.href);e.searchParams.delete("focus"),window.history.replaceState(null,"",e.toString())}},[c,n]),{valueSets:e,connectedProviders:u,actions:r,isLoading:n,focusType:c,fetchAll:d}}(),{orgSlug:m}=(0,y.useParams)(),h=(0,l.useTranslations)("bridge.data"),p=(0,l.useTranslations)("bridge.data.rulesPage"),x=(0,l.useTranslations)("bridge.data.phases"),f=(0,l.useTranslations)("states.delete"),[b,v]=(0,s.useState)(null),S="purchase"===e||"manufacture"===e,k=(0,s.useMemo)(()=>{if(!(0,av.isDestinationSection)(e))return[];
1let a=(0,av.listsForWorkspace)(e);return i.filter(e=>"*"===e.scope&&a.includes(e.type)&&!(S&&"vendors"===e.type)).sort((e,t)=>a.indexOf(e.type)-a.indexOf(t.type))},[e,S,i]),w=(0,s.useMemo)(()=>i.filter(e=>"*"===e.scope&&"workOrderRules"===e.type),[i]),N=(0,s.useMemo)(()=>(0,ak.findActionByWorkflow)(o,"create-sales-orders"),[o]),C=(0,s.useMemo)(()=>(0,ak.findActionByWorkflow)(o,"localise-product-assets"),[o]),[T]=(0,s.useState)("productLocalisation"===d),F=(0,s.useMemo)(()=>(0,ak.findActionByWorkflow)(o,"create-purchase-orders"),[o]),D=(0,s.useMemo)(()=>(0,ak.findActionByWorkflow)(o,"manage-catalogues"),[o]),A=b?(0,a.jsx)("span",{role:"status",className:"sr-only",children:f("done",{object:b})}):null;return c?(0,a.jsxs)(a.Fragment,{children:[A,(0,a.jsx)(r.ManagePage,{state:{kind:"loading",layout:"rows",count:"assortment"===e?1:6}})]}):(0,a.jsxs)(a.Fragment,{children:[A,(0,a.jsxs)(r.ManagePage,{children:["assortment"===e&&(0,a.jsx)(r.ManageSection,{state:D?void 0:{kind:"empty",title:h("rulesEmpty")},children:(0,a.jsx)(r.ManageRowList,{children:D?(0,a.jsx)(aG,{actionId:D.id,focus:"catalogueSource"===d}):null})}),"products"===e&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageSection,{children:(0,a.jsx)(j.ProductSetupRows,{})}),(0,a.jsx)(r.ManageSection,{children:(0,a.jsxs)(r.ManageRowList,{children:[(0,a.jsx)(e0,{}),(0,a.jsx)(e8,{}),(0,a.jsx)(as,{})]})}),C&&T?(0,a.jsx)(r.ManageSection,{children:(0,a.jsx)(r.ManageRowList,{children:(0,a.jsx)(aS.ActionBusinessConfigCard,{title:h("actionConfigs.productLocalisation.title"),description:h("actionConfigs.productLocalisation.description"),dialogTitle:h("actionConfigs.productLocalisation.dialogTitle"),manageLabel:h("dataSet.manage"),focus:"productLocalisation"===d,bodyManagedByChild:!0,children:(0,a.jsx)(aF,{actionId:C.id})})})}):null]}),(0,av.isDestinationSection)(e)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(r.ManageSection,{children:(0,a.jsxs)(r.ManageRowList,{children:[(0,a.jsx)(j.WorkspaceDestinationRow,{role:e}),(0,a.jsx)(t.ProductMatchRow,{target:{role:e}})]})}),(0,a.jsx)(g,{role:e}),"purchase"===e&&F?(0,a.jsx)(r.ManageSection,{title:p("suppliers"),children:(0,a.jsxs)(r.ManageRowList,{children:[(0,a.jsx)(aL,{actionId:F.id,href:`/${m}/manage/rules/purchase/supplier-packet`,focus:"supplierPackets"===d}),(0,a.jsx)(ez,{}),(0,a.jsx)(eO,{}),(0,a.jsx)(eP,{})]})}):null,"purchase"!==e?(0,a.jsx)(r.ManageSection,{children:(0,a.jsxs)(r.ManageRowList,{children:["manufacture"===e?w.map(e=>(0,a.jsx)(ee,{valueSet:e,onSaved:u,onDeleted:v,connectedProviders:n,focus:e.type===d},e.id)):null,"manufacture"===e?(0,a.jsx)(aK,{focus:"manufacturer"===d}):null,"manufacture"===e?(0,a.jsx)(eF,{}):null,"manufacture"===e?(0,a.jsx)(ai,{}):null,"manufacture"===e?(0,a.jsx)(ac,{}):null,"manufacture"===e?(0,a.jsx)(eE,{}):null,"manufacture"===e?(0,a.jsx)(ad,{}):null,"sell"===e?(0,a.jsxs)(a.Fragment,{children:[N?(0,a.jsx)(ax,{}):null,N?(0,a.jsx)(aj,{}):null,N?(0,a.jsx)(ab,{}):null,(0,a.jsx)(eb,{}),(0,a.jsx)(ei.CompanyFactsCard,{scope:{level:"org"},focus:"companyFacts"===d}),(0,a.jsx)(er,{}),N?(0,a.jsx)(aS.ActionBusinessConfigCard,{title:h("actionConfigs.customerSubmissions.title"),description:h("actionConfigs.customerSubmissions.description"),dialogTitle:h("actionConfigs.customerSubmissions.dialogTitle"),manageLabel:h("dataSet.manage"),focus:"customerSubmissions"===d,children:(0,a.jsx)(aN,{actionId:N.id})}):null]}):null]})}):null,"sell"===e?(0,a.jsx)(aV,{}):null,k.length>0||S?(0,a.jsx)(r.ManageSection,{title:p("lists"),children:(0,a.jsxs)(r.ManageRowList,{children:["purchase"===e||"manufacture"===e?(0,a.jsx)(aM,{orgSlug:m,section:e,alsoWorkspace:x("purchase"===e?"manufacture":"purchase")}):null,k.map(t=>{let s=(0,av.otherListWorkspaces)(t.type,e);return(0,a.jsx)(ee,{valueSet:t,onSaved:u,onDeleted:v,connectedProviders:n,focus:t.type===d,alsoUsedBy:s.length>0?s.map(e=>x(e)).join(" · "):void 0,showOrigin:!0},t.id)})]})}):null]})]})]})}],369330)}]);
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.