1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3844],{2082:(e,t,n)=>{"use strict";n.d(t,{A:()=>a});var l=n(95155);let s={received:"#9ca3af",dispatched:"#3b82f6",processed:"#10b981",failed:"#ef4444",skipped:"#a855f7",pending:"#f59e0b",in_progress:"#3b82f6",active:"#10b981",inactive:"#6b7280",cancelled:"#ef4444",completed:"#10b981",paid:"#10b981",refunded:"#a855f7",partially_refunded:"#a855f7",fulfilled:"#10b981",partially_fulfilled:"#f59e0b",unfulfilled:"#6b7280",unknown:"#6b7280"};function a(e){var t;let{status:n,colors:a,label:r,className:i="",style:o}=e,d=null!=(t=({...s,...null!=a?a:{}})[n])?t:"#6b7280";return(0,l.jsx)("span",{className:"inline-flex items-center rounded-full ".concat(i),style:{padding:"0 6px",height:18,lineHeight:"16px",fontSize:10,fontWeight:500,whiteSpace:"nowrap",backgroundColor:"".concat(d,"18"),color:d,border:"1px solid ".concat(d,"30"),...o},children:null!=r?r:n})}},3673:(e,t,n)=>{"use strict";n.d(t,{A:()=>s});var l=n(95155);function s(e){let{checked:t,onChange:n,disabled:s=!1,showLabel:a=!0,ariaLabel:r,className:i=""}=e;return(0,l.jsxs)("span",{className:"inline-flex items-center gap-2 ".concat(i),children:[a&&(0,l.jsx)("span",{className:"text-[11px] font-medium w-6 text-right ".concat(t?"text-brand":"text-ink-soft"),children:t?"On":"Off"}),(0,l.jsx)("button",{type:"button",onClick:()=>n(!t),disabled:s,role:"switch","aria-checked":t,"aria-label":r,className:"relative w-9 h-5 rounded-full transition-colors disabled:opacity-50 ".concat(t?"bg-brand":"bg-hovertint border border-line-strong opacity-70"),children:(0,l.jsx)("span",{className:"absolute left-0 top-0.5 w-4 h-4 rounded-full bg-white shadow-sm transition-transform ".concat(t?"translate-x-[18px]":"translate-x-0.5")})})]})}},22031:(e,t,n)=>{"use strict";n.d(t,{default:()=>r});var l=n(95155),s=n(88661),a=n.n(s);function r(e){let{label:t="LOADING",fullScreen:n=!1,durationSec:s=2.4,style:r}=e,i=(0,l.jsxs)("div",{style:{display:"inline-flex",flexDirection:"column",gap:"8px",fontFamily:"'VT323', 'Fragment Mono', monospace",color:"#ABA3FF",lineHeight:1,userSelect:"none",...r},className:"jsx-329afd70baec0ec1",children:[(0,l.jsx)("div",{style:{fontSize:"28px",letterSpacing:"2px",textShadow:"0 0 6px rgba(171, 163, 255, 0.5)"},className:"jsx-329afd70baec0ec1",children:t}),(0,l.jsxs)("div",{style:{position:"relative",width:"320px",height:"20px",overflow:"hidden"},className:"jsx-329afd70baec0ec1",children:[(0,l.jsx)("div",{style:{position:"absolute",inset:0,backgroundImage:"linear-gradient(to right, rgba(171,163,255,0.35) 0%, rgba(171,163,255,0.35) 60%, transparent 60%)",backgroundSize:"16px 3px",backgroundRepeat:"repeat-x",backgroundPosition:"0 50%"},className:"jsx-329afd70baec0ec1"}),(0,l.jsx)("div",{style:{position:"absolute",inset:0,backgroundImage:"linear-gradient(to right, #ABA3FF 0%, #ABA3FF 70%, transparent 70%)",backgroundSize:"16px 100%",backgroundRepeat:"repeat-x",boxShadow:"0 0 12px rgba(171, 163, 255, 0.4)",animation:"crt-loader-fill ".concat(s,"s steps(20, end) infinite"),width:0},className:"jsx-329afd70baec0ec1"})]}),(0,l.jsx)(a(),{id:"329afd70baec0ec1",children:"@keyframes crt-loader-fill{0%{width:0%}85%{width:100%}93%{width:100%}100%{width:0%}}"})]});return n?(0,l.jsx)("div",{style:{position:"fixed",inset:0,zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#000",backgroundImage:"radial-gradient(circle at 50% 50%, rgba(171, 163, 255, 0.04) 0%, transparent 70%)"},children:i}):i}},39276:(e,t,n)=>{"use strict";n.d(t,{RC:()=>d,Tn:()=>r,VX:()=>c,dG:()=>a});var l=n(12115);let s="rerere.draft.";function a(){let e=[];try{for(let t=0;t<window.localStorage.length;t++){let n=window.localStorage.key(t);if(!n||!n.startsWith(s))continue;let l=n.slice(s.length);try{let t=JSON.parse(window.localStorage.getItem(n)||"");e.push({key:n,storageKey:l,label:t.label||l.replace(/[.:]/g," \xb7 "),href:t.href||null,at:"number"==typeof t.at?t.at:null})}catch(t){e.push({key:n,storageKey:l,label:l,href:null,at:null})}}}catch(e){}return e.sort((e,t)=>{var n,l;return(null!=(n=t.at)?n:0)-(null!=(l=e.at)?l:0)})}function r(e){i(e)}function i(e){try{window.localStorage.removeItem(e)}catch(e){}}function o(e){let t=new WeakSet,n=e=>null===e||"object"!=typeof e?e:t.has(e)?"[circular]":(t.add(e),Array.isArray(e))?e.map(n):Object.keys(e).sort().reduce((t,l)=>(t[l]=n(e[l]),t),{});try{var l;return null!=(l=JSON.stringify(n(e)))?l:""}catch(e){return""}}function d(e){let{storageKey:t,value:n,baseline:a,enabled:r=!0,meta:d}=e,c=s+t,[u,h]=(0,l.useState)(!1),[p,m]=(0,l.useState)(null),x=(0,l.useRef)(null),f=(0,l.useMemo)(()=>o(n),[n]),b=(0,l.useMemo)(()=>null===a?null:o(a),[a]),g=r&&null!==b&&f!==b,v=(0,l.useRef)(null);(0,l.useEffect)(()=>
1{if(!r||null===b||v.current===c)return;v.current=c;let e=function(e){try{return window.localStorage.getItem(e)}catch(e){return null}}(c);if(e)try{let t=JSON.parse(e);if(o(t.v)===b)return void i(c);x.current=t,m("number"==typeof t.at?t.at:null),h(!0)}catch(e){i(c)}},[r,b,c]);let _=(0,l.useRef)(!1);(0,l.useEffect)(()=>{g&&(_.current=!0)},[g]),(0,l.useEffect)(()=>{if(!r||null===b)return;if(!g){_.current&&i(c);return}let e=null==d?void 0:d.label,t=null==d?void 0:d.href,l=setTimeout(()=>{var l=JSON.stringify({v:n,at:Date.now(),...e?{label:e,href:t}:{}});try{window.localStorage.setItem(c,l)}catch(e){}},600);return()=>clearTimeout(l)},[r,g,b,c,n,f,null==d?void 0:d.label,null==d?void 0:d.href]),(0,l.useEffect)(()=>{if(!r||!g)return;let e=e=>(e.preventDefault(),e.returnValue="","");return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[r,g]);let j=(0,l.useCallback)(()=>{let e=x.current;return h(!1),m(null),x.current=null,e?e.v:null},[]);return{isDirty:g,hasStoredDraft:u,storedDraftAt:p,restoreDraft:j,discardDraft:(0,l.useCallback)(()=>{i(c),x.current=null,h(!1),m(null)},[c]),markSaved:(0,l.useCallback)(()=>{i(c),x.current=null,h(!1),m(null)},[c])}}function c(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();if(!e)return"";let n=Math.max(0,Math.round((t-e)/1e3));if(n<60)return"moments ago";let l=Math.round(n/60);if(l<60)return"".concat(l," minute").concat(1===l?"":"s"," ago");let s=Math.round(l/60);if(s<24)return"".concat(s," hour").concat(1===s?"":"s"," ago");let a=Math.round(s/24);return"".concat(a," day").concat(1===a?"":"s"," ago")}},45255:(e,t,n)=>{"use strict";n.d(t,{A:()=>a});var l=n(95155),s=n(12115);function a(e){let{title:t,onClose:n,children:a}=e;return(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&n()};document.addEventListener("keydown",e);let t=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",e),document.body.style.overflow=t}},[n]),(0,l.jsxs)("div",{className:"fixed inset-0 z-50 flex justify-end",children:[(0,l.jsx)("div",{className:"absolute inset-0 bg-app/60 backdrop-blur-sm",onClick:n,"aria-hidden":!0}),(0,l.jsxs)("div",{className:"relative h-full w-full max-w-2xl overflow-y-auto border-l border-line bg-surface-100 shadow-2xl",children:[(0,l.jsxs)("div",{className:"sticky top-0 z-10 flex items-center justify-between border-b border-line bg-surface-100/95 px-4 py-2 backdrop-blur",children:[(0,l.jsx)("span",{className:"min-w-0 truncate text-xs font-medium text-ink-soft",children:t}),(0,l.jsx)("button",{type:"button",onClick:n,className:"shrink-0 text-xs text-ink-soft hover:text-ink","aria-label":"Close",children:"Esc â"})]}),(0,l.jsx)("div",{className:"p-5",children:a})]})]})}},45688:(e,t,n)=>{"use strict";var l=n(95704);n(86340);var s=n(12115),a=function(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}(s),r=void 0!==l&&l.env&&!0,i=function(e){return"[object String]"===Object.prototype.toString.call(e)},o=function(){function e(e){var t=void 0===e?{}:e,n=t.name,l=void 0===n?"stylesheet":n,s=t.optimizeForSpeed,a=void 0===s?r:s;d(i(l),"`name` must be a string"),this._name=l,this._deletedRulePlaceholder="#"+l+"-deleted-rule____{}",d("boolean"==typeof a,"`optimizeForSpeed` must be a boolean"),this._optimizeForSpeed=a,this._serverSheet=void 0,this._tags=[],this._injected=!1,this._rulesCount=0;var o="undefined"!=typeof window&&document.querySelector('meta[property="csp-nonce"]');this._nonce=o?o.getAttribute("content"):null}var t,n=e.prototype;return n.setOptimizeForSpeed=function(e){d("boolean"==typeof e,"`setOptimizeForSpeed` accepts a boolean"),d(0===this._rulesCount,"optimizeForSpeed cannot be when rules have already been inserted"),this.flush(),this._optimizeForSpeed=e,this.inject()},n.isOptimizeForSpeed=function(){return this._optimizeForSpeed},n.inject=function(){var e=this;if(d(!this._injected,"sheet already injected"),this._injected=!0,"undefined"!=typeof window&&this._optimizeForSpeed){this._tags[0]=this.makeStyleTag(this._name),this._optimizeForSpeed="insertRule"in this.get
1Sheet(),this._optimizeForSpeed||(r||console.warn("StyleSheet: optimizeForSpeed mode not supported falling back to standard mode."),this.flush(),this._injected=!0);return}this._serverSheet={cssRules:[],insertRule:function(t,n){return"number"==typeof n?e._serverSheet.cssRules[n]={cssText:t}:e._serverSheet.cssRules.push({cssText:t}),n},deleteRule:function(t){e._serverSheet.cssRules[t]=null}}},n.getSheetForTag=function(e){if(e.sheet)return e.sheet;for(var t=0;t<document.styleSheets.length;t++)if(document.styleSheets[t].ownerNode===e)return document.styleSheets[t]},n.getSheet=function(){return this.getSheetForTag(this._tags[this._tags.length-1])},n.insertRule=function(e,t){if(d(i(e),"`insertRule` accepts only strings"),"undefined"==typeof window)return"number"!=typeof t&&(t=this._serverSheet.cssRules.length),this._serverSheet.insertRule(e,t),this._rulesCount++;if(this._optimizeForSpeed){var n=this.getSheet();"number"!=typeof t&&(t=n.cssRules.length);try{n.insertRule(e,t)}catch(t){return r||console.warn("StyleSheet: illegal rule: \n\n"+e+"\n\nSee https://stackoverflow.com/q/20007992 for more info"),-1}}else{var l=this._tags[t];this._tags.push(this.makeStyleTag(this._name,e,l))}return this._rulesCount++},n.replaceRule=function(e,t){if(this._optimizeForSpeed||"undefined"==typeof window){var n="undefined"!=typeof window?this.getSheet():this._serverSheet;if(t.trim()||(t=this._deletedRulePlaceholder),!n.cssRules[e])return e;n.deleteRule(e);try{n.insertRule(t,e)}catch(l){r||console.warn("StyleSheet: illegal rule: \n\n"+t+"\n\nSee https://stackoverflow.com/q/20007992 for more info"),n.insertRule(this._deletedRulePlaceholder,e)}}else{var l=this._tags[e];d(l,"old rule at index `"+e+"` not found"),l.textContent=t}return e},n.deleteRule=function(e){if("undefined"==typeof window)return void this._serverSheet.deleteRule(e);if(this._optimizeForSpeed)this.replaceRule(e,"");else{var t=this._tags[e];d(t,"rule at index `"+e+"` not found"),t.parentNode.removeChild(t),this._tags[e]=null}},n.flush=function(){this._injected=!1,this._rulesCount=0,"undefined"!=typeof window?(this._tags.forEac
1h(function(e){return e&&e.parentNode.removeChild(e)}),this._tags=[]):this._serverSheet.cssRules=[]},n.cssRules=function(){var e=this;return"undefined"==typeof window?this._serverSheet.cssRules:this._tags.reduce(function(t,n){return n?t=t.concat(Array.prototype.map.call(e.getSheetForTag(n).cssRules,function(t){return t.cssText===e._deletedRulePlaceholder?null:t})):t.push(null),t},[])},n.makeStyleTag=function(e,t,n){t&&d(i(t),"makeStyleTag accepts only strings as second parameter");var l=document.createElement("style");this._nonce&&l.setAttribute("nonce",this._nonce),l.type="text/css",l.setAttribute("data-"+e,""),t&&l.appendChild(document.createTextNode(t));var s=document.head||document.getElementsByTagName("head")[0];return n?s.insertBefore(l,n):s.appendChild(l),l},t=[{key:"length",get:function(){return this._rulesCount}}],function(e,t){for(var n=0;n<t.length;n++){var l=t[n];l.enumerable=l.enumerable||!1,l.configurable=!0,"value"in l&&(l.writable=!0),Object.defineProperty(e,l.key,l)}}(e.prototype,t),e}();function d(e,t){if(!e)throw Error("StyleSheet: "+t+".")}var c=function(e){for(var t=5381,n=e.length;n;)t=33*t^e.charCodeAt(--n);return t>>>0},u={};function h(e,t){if(!t)return"jsx-"+e;var n=String(t),l=e+n;return u[l]||(u[l]="jsx-"+c(e+"-"+n)),u[l]}function p(e,t){"undefined"==typeof window&&(t=t.replace(/\/style/gi,"\\/style"));var n=e+t;return u[n]||(u[n]=t.replace(/__jsx-style-dynamic-selector/g,e)),u[n]}var m=function(){function e(e){var t=void 0===e?{}:e,n=t.styleSheet,l=void 0===n?null:n,s=t.optimizeForSpeed,a=void 0!==s&&s;this._sheet=l||new o({name:"styled-jsx",optimizeForSpeed:a}),this._sheet.inject(),l&&"boolean"==typeof a&&(this._sheet.setOptimizeForSpeed(a),this._optimizeForSpeed=this._sheet.isOptimizeForSpeed()),this._fromServer=void 0,this._indices={},this._instancesCounts={}}var t=e.prototype;return t.add=function(e){var t=this;void 0===this._optimizeForSpeed&&(this._optimizeForSpeed=Array.isArray(e.children),this._sheet.setOptimizeForSpeed(this._optimizeForSpeed),this._optimizeForSpeed=this._sheet.isOptimizeForSpeed()),"undefined"==typeof window||this._fromServer||(this._fromServer=this.selectFromServer(),this._instancesCounts=Object.keys(this._fromServer).reduce(function(e,t){return e[t]=0,e},{}));var n=this.getIdAndRules(e),l=n.styleId,s=n.rules;if(l in this._instancesCounts){this._instancesCounts[l]+=1;return}var a=s.map(function(e){return t._sheet.insertRule(e)}).filter(function(e){return -1!==e});this._indices[l]=a,this._instancesCounts[l]=1},t.remove=function(e){var t=this,n=this.getIdAndRules(e).styleId;if(function(e,t){if(!e)throw Error("StyleSheetRegistry: "+t+".")}(n in this._instancesCounts,"styleId: `"+n+"` not found"),this._instancesCounts[n]-=1,this._instancesCounts[n]<1){var l=this._fromServer&&this._fromServer[n];l?(l.parentNode.removeChild(l),delete this._fromServer[n]):(this._indices[n].forEach(function(e){return t._sheet.deleteRule(e)}),delete this._indices[n]),delete this._instancesCounts[n]}},t.update=function(e,t){this.add(t),this.remove(e)},t.flush=function(){this._sheet.flush(),this._sheet.inject(),this._fromServer=void 0,this._indices={},this._instancesCounts={}},t.cssRules=function(){var e=this,t=this._fromServer?Object.keys(this._fromServer).map(function(t){return[t,e._fromServer[t]]}):[],n=this._sheet.cssRules();return t.concat(Object.keys(this._indices).map(function(t){return[t,e._indices[t].map(function(e){return n[e].cssText}).join(e._optimizeForSpeed?"":"\n")]}).filter(function(e){return!!e[1]}))},t.styles=function(e){var t,n;return t=this.cssRules(),void 0===(n=e)&&(n={}),t.map(function(e){var t=e[0],l=e[1];return a.default.createElement("style",{id:"__"+t,key:"__"+t,nonce:n.nonce?n.nonce:void 0,dangerouslySetInnerHTML:{__html:l}})})},t.getIdAndRules=function(e){var t=e.children,n=e.dynamic,l=e.id;if(n){var s=h(l,n);return{styleId:s,rules:Array.isArray(t)?t.map(function(e){return p(s,e)}):[p(s,t)]}}return{styleId:h(l),rules:Array.isArray(t)?t:[t]}},t.selectFromServer=function(){return Array.prototype.slice.call(document.querySelectorAll('[id^="__jsx-"]')).reduce(function(e,t){return e[t.id.slice(2)]=t,e},{})},e}(),x=s.createContext(null);x.displayName="StyleSheetContext";var f=a.default.useInsertionEffect||a.default.useLayoutEffect,b="undefined"!=typeof window?new m:void 0;function g(e){var t=b||s.useContext(x);return t&&("undefined"==typeof window?t.add(e):f(function(){return t.add(e),function(){t.remove(e)}},[e.id,String(e.dynamic)])),null}g.dynamic=function(e){return e.map(function(e){return h(e[0],e[1])}).join(" ")},t.style=g},83844:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>eS});var l=n(95155),s=n(12115),a=n(90960),r=n(41091),i=n(39276),o=n(2082),d=n(81636);let c=["refund","exchange","store_credit","keep_item"],u={refund:"Refund",exchange:"Exchange",store_credit:"Store credit",keep_item:"Keep item"},h=[{id:"lookup",label:"Lookup",number:1},{id:"hub",label:"Hub menu",number:2},{id:"items",label:"Item selection",number:3},{id:"reason",label:"Return reasons",number:4},{id:"followup",label:"Follow-up tree",number:5},{id:"outcome",label:"Outcome matrix",number:6},{id:"photos",label:"Photo gate",number:7},{id:"review",label:"Review & pricing",number:8},{id:"done",label:"Confirmation",number:9}];function p(e){let{children:t}=e;return(0,l.jsx)("p",{className:"text-[11px] uppercase tracking-wide text-ink-faint font-semibold mb-2 mt-4 first:mt-0",children:t})}function m(e){let{label:t,value:n,placeholder:s,onChange:a}=e;return(0,l.jsxs)("label",{className:"block mb-3",children:[(0,l.jsx)("span",{className:"text-[11px] uppercase tracking-wide text-ink-faint block mb-1",children:t}),(0,l.jsx)(d.ks,{value:n,placeholder:s,onChange:e=>a(e.target.value),className:"w-full text-sm"})]})}function x(e){let{label:t,checked:n,onChange:s}=e;return(0,l.jsxs)("button",{onClick:()=>s(!n),className:"flex items-center gap-3 py-1.5",children:[(0,l.jsx)("div",{className:"w-9 h-5 rounded-full transition-colors relative flex-shrink-0 ".concat(n?"bg-brand":"bg-hovertint"),children:(0,l.jsx)("div",{className:"w-4 h-4 absolute top-0.5 rounded-full bg-white shadow transition-all ".concat(n?"left-[18px]":"left-0.5")})}),(0,l.jsx)("span",{className:"text-sm text-ink text-left",children:t})]})}function f(e){let{value:t,onChange:n}=e;return(0,l.jsx)("div",{className:"flex flex-wrap gap-1.5",children:c.filter(e=>"keep_item"!==e).map(e=>{let s=t.includes(e);return(0,l.jsx)("button",{onClick:()=>
1n(s?t.filter(t=>t!==e):[...t,e]),className:"px-2 py-0.5 rounded text-[11px] font-medium border transition-colors ".concat(s?"bg-brand/10 border-brand/30 text-brand":"bg-hovertint border-line text-ink-faint hover:text-ink-soft"),children:u[e]},e)})})}function b(e){var t,n,s,a,r,i;let{state:o,update:d}=e,c=null!=(t=o.portal_config.custom_copy.lookup)?t:{},u=e=>d({portal_config:{...o.portal_config,custom_copy:{...o.portal_config.custom_copy,lookup:{...c,...e}}}});return(0,l.jsxs)("div",{children:[(0,l.jsx)(p,{children:"Screen copy"}),(0,l.jsx)(m,{label:"Title",value:null!=(n=c.title)?n:"",placeholder:"How can we help?",onChange:e=>u({title:e})}),(0,l.jsx)(m,{label:"Subtitle",value:null!=(s=c.subtitle)?s:"",placeholder:"Enter your order details to get started.",onChange:e=>u({subtitle:e})}),(0,l.jsx)(m,{label:"Order-# label",value:null!=(a=c.field_order)?a:"",placeholder:"Order number",onChange:e=>u({field_order:e})}),(0,l.jsx)(m,{label:"Email label",value:null!=(r=c.field_email)?r:"",placeholder:"Email address",onChange:e=>u({field_email:e})}),(0,l.jsx)(m,{label:"CTA button",value:null!=(i=c.cta)?i:"",placeholder:"Find my order",onChange:e=>u({cta:e})}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mt-2",children:"Customer enters an order number + email. Hit â¥1 field to start the flow."})]})}function g(e){var t,n;let{state:s,update:a}=e,r=null!=(t=s.portal_config.custom_copy.hub)?t:{},i=s.portal_config.hub_cards,o=(e,t)=>a({portal_config:{...s.portal_config,hub_cards:{...i,[e]:{...i[e],...t}}}});return(0,l.jsxs)("div",{children:[(0,l.jsx)(p,{children:"Screen copy"}),(0,l.jsx)(m,{label:"Heading",value:null!=(n=r.title)?n:"",placeholder:"What can we help you with today?",onChange:e=>{let t;return t={title:e},a({portal_config:{...s.portal_config,custom_copy:{...s.portal_config.custom_copy,hub:{...r,...t}}}})}}),(0,l.jsx)(p,{children:"Action cards"}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mb-3",children:"Each card is a starting point for a different path through the portal. Turn off any you don't want to offer."}),(0,l.jsx)("div",{className:"space-y-3",children:["track","return","report","history"].map(e=>{var t,n;let s=i[e];return(0,l.jsxs)("div",{className:"rounded-lg border border-line bg-hovertint p-3",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsx)("span",{className:"text-xs uppercase tracking-wide text-ink-soft",children:e}),(0,l.jsx)(x,{label:"Show this card",checked:!1!==s.enabled,onChange:t=>o(e,{enabled:t})})]}),(0,l.jsx)(m,{label:"Card title",value:null!=(t=s.title)?t:"",onChange:t=>o(e,{title:t})}),(0,l.jsx)(m,{label:"Card subtitle",value:null!=(n=s.subtitle)?n:"",onChange:t=>o(e,{subtitle:t})})]},e)})})]})}function v(e){var t,n,s,a;let{state:r,update:i}=e,o=null!=(t=r.portal_config.custom_copy.items)?t:{},c=e=>i({portal_config:{...r.portal_config,custom_copy:{...r.portal_config.custom_copy,items:{...o,...e}}}});return(0,l.jsxs)("div",{children:[(0,l.jsx)(p,{children:"Screen copy"}),(0,l.jsx)(m,{label:"Title",value:null!=(n=o.title)?n:"",placeholder:"Select items to return or exchange",onChange:e=>c({title:e})}),(0,l.jsx)(m,{label:"Subtitle",value:null!=(s=o.subtitle)?s:"",placeholder:"Tap an item to select itâ¦",onChange:e=>c({subtitle:e})}),(0,l.jsx)(m,{label:"CTA",value:null!=(a=o.cta)?a:"",placeholder:"Continue",onChange:e=>c({cta:e})}),(0,l.jsx)(p,{children:"Return window"}),(0,l.jsxs)("label",{className:"block mb-3",children:[(0,l.jsx)("span",{className:"text-[11px] uppercase tracking-wide text-ink-faint block mb-1",children:"Window (days)"}),(0,l.jsx)(d.ks,{type:"number",value:r.return_window_days,onChange:e=>i({return_window_days:Number(e.target.value)}),className:"w-24 text-sm font-mono"})]}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint",children:"Items outside this window are filtered out on the hub screen."})]})}function _(e){let{state:t,update:n}=e,[a,r]=(0,s.useState)(null),i=t.return_reasons,o=e=>n({return_reasons:e}),c=(e,t)=>o(i.map(n=>n.id===e?{...n,...t}:n));return(0,l.jsxs)("div",{children:[(0,l.jsx)(p,{children:"Return reasons"}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mb-3",children:"Click any reason to configure resale eligibility, whether a photo is required, which outcomes are allowed, and a decision-tree follow-up."}),(0,l.jsxs)("div",{className:"space-y-2",children:[i.map(e=>{var t;let n=a===e.id;return(0,l.jsxs)("div",{className:"rounded-xl border transition-colors ".concat(n?"border-brand/40 bg-brand/[0.02]":"border-line bg-hovertint"),children:[(0,l.jsxs)("button",{onClick:()=>r(n?null:e.id),className:"w-full flex items-center gap-2 px-3 py-2.5 text-left",children:[(0,l.jsx)("span",{className:"text-sm font-medium ".concat(e.enabled?"text-ink":"text-ink-faint line-through"),children:e.label}),(0,l.jsxs)("span",{className:"flex items-center gap-1 ml-auto",children:[e.resale_eligible&&(0,l.jsx)("span",{className:"text-[9px] uppercase px-1.5 py-0.5 rounded bg-good-bg text-good",children:"Resale"}),e.photo_required&&(0,l.jsx)("span",{className:"text-[9px] uppercase px-1.5 py-0.5 rounded bg-warn-bg text-warn",children:"Photo"}),e.follow_up&&(0,l.jsx)("span",{className:"text-[9px] uppercase px-1.5 py-0.5 rounded bg-brand/10 text-brand",children:"Follow-up"})]})]}),n&&(0,l.jsxs)("div",{className:"px-3 pb-3 border-t border-line pt-3 space-y-3",children:[(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,l.jsxs)("label",{className:"block",children:[(0,l.jsx)("span",{className:"text-[10px] uppercase text-ink-faint block mb-1",children:"ID"}),(0,l.jsx)(d.ks,{value:e.id,onChange:t=>c(e.id,{id:t.target.value}),className:"w-full text-xs font-mono"})]}),(0,l.jsxs)("label",{className:"block",children:[(0,l.jsx)("span",{className:"text-[10px] uppercase text-ink-faint block mb-1",children:"Label"}),(0,l.jsx)(d.ks,{value:e.label,onChange:t=>c(e.id,{label:t.target.value}),className:"w-full text-xs"})]})]}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,l.jsx)(x,{label:"Enabled",checked:e.enabled,onChange:t=>c(e.id,{enabled:t})}),(0,l.jsx)(x,{label:"Resale eligible",checked:e.resale_eligible,onChange:t=>c(e.id,{resale_eligible:t})}),(0,l.jsx)(x,{label:"Require photos",checked:e.photo_required,onChange:t=>c(e.id,{photo_required:t})})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-[10px] uppercase text-ink-faint block mb-1.5",children:"Allowed outcomes (default)"}),(0,l.jsx)(f,{value:e.allowed_outcomes,onChange:t=>c(e.id,{allowed_outcomes:t})})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-[10px] uppercase text-ink-faint block mb-1",children:"Fee override (cents â empty = score-based)"}),(0,l.jsx)(d.ks,{type:"number",value:null!=(t=e.fee_override_cents)?t:"",placeholder:"empty = score-based",onChange:t=>c(e.id,{fee_override_cents:""===t.target.value?null:Number(t.target.value)}),className:"w-28 text-xs font-mono"})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between pt-2 border-t border-line",children:[(0,l.jsx)("span",{className:"text-[11px] text-ink-faint",children:"See Follow-up step to configure the decision tree for this reason."}),(0,l.jsx)("button",{onClick:()=>o(i.filter(t=>t.id!==e.id)),className:"text-[11px] text-ink-faint hover:text-bad",children:"Delete"})]})]})]},e.id)}),(0,l.jsx)("button",{onClick:()=>{let e="custom_".concat(Date.now());o([...i,{id:e,label:"New reason",enabled:!0,resale_eligible:!0,photo_required:!1,allowed_outcomes:["refund","exchange","store_credit"],follow_up:null,fee_override_cents:null}]),r(e)},className:"text-xs text-brand hover:text-brand/80 font-medium",children:"+ Add reason"})]})]})}function j(e){var t,n;let{state:a,update:r}
1=e,i=a.return_reasons,[o,c]=(0,s.useState)(null!=(n=null==(t=i[0])?void 0:t.id)?n:null),u=i.find(e=>e.id===o)||null,h=e=>{u&&r({return_reasons:i.map(t=>t.id===u.id?{...t,...e}:t)})},x=e=>{(null==u?void 0:u.follow_up)&&h({follow_up:{...u.follow_up,...e}})};return(0,l.jsxs)("div",{children:[(0,l.jsx)(p,{children:"Pick a reason to configure its follow-up tree"}),(0,l.jsx)("div",{className:"flex flex-wrap gap-1.5 mb-4",children:i.filter(e=>e.enabled).map(e=>{let t=e.id===o;return(0,l.jsxs)("button",{onClick:()=>c(e.id),className:"px-2.5 py-1 rounded text-xs font-medium border transition-colors ".concat(t?"bg-brand/15 border-brand text-brand":"bg-hovertint border-line text-ink-soft hover:text-ink"),children:[e.label,e.follow_up?" \xb7":""]},e.id)})}),!u&&(0,l.jsx)("p",{className:"text-[12px] text-ink-faint",children:"Create a reason first in the âReturn reasonsâ step."}),u&&!u.follow_up&&(0,l.jsxs)("div",{className:"rounded-lg border border-line bg-hovertint p-4",children:[(0,l.jsxs)("p",{className:"text-sm text-ink mb-2",children:["No follow-up for ",(0,l.jsx)("span",{className:"text-ink font-medium",children:u.label}),"."]}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mb-3",children:"Follow-up questions let you ask the customer one more question (e.g. âWhat went wrong?â) and narrow outcomes based on their answer."}),(0,l.jsx)("button",{onClick:()=>h({follow_up:{question:"Can you tell us more?",options:[{value:"option_a",label:"Option A",allowed_outcomes:u.allowed_outcomes},{value:"option_b",label:"Option B",allowed_outcomes:u.allowed_outcomes}]}}),className:"text-xs text-brand hover:text-brand/80 font-medium",children:"+ Add a follow-up question"})]}),(null==u?void 0:u.follow_up)&&(0,l.jsxs)("div",{className:"rounded-lg border border-line bg-hovertint p-4",children:[(0,l.jsx)(m,{label:"Question",value:u.follow_up.question,onChange:e=>x({question:e})}),(0,l.jsx)(p,{children:"Answers & per-branch outcomes"}),(0,l.jsxs)("div",{className:"space-y-2",children:[u.follow_up.options.map((e,t)=>(0,l.jsxs)("div",{className:"rounded-md border border-line bg-hovertint p-2.5",children:[(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[(0,l.jsx)(d.ks,{placeholder:"value",value:e.value,onChange:e=>{let n=[...u.follow_up.options];n[t]={...n[t],value:e.target.value},x({options:n})},className:"text-xs font-mono"}),(0,l.jsx)(d.ks,{placeholder:"Customer label",value:e.label,onChange:e=>{let n=[...u.follow_up.options];n[t]={...n[t],label:e.target.value},x({options:n})},className:"text-xs"})]}),(0,l.jsx)("span",{className:"text-[10px] uppercase text-ink-faint block mb-1",children:"Allowed outcomes if they pick this"}),(0,l.jsx)(f,{value:e.allowed_outcomes,onChange:e=>{let n=[...u.follow_up.options];n[t]={...n[t],allowed_outcomes:e},x({options:n})}}),(0,l.jsx)("div",{className:"flex justify-end mt-2",children:(0,l.jsx)("button",{onClick:()=>x({options:u.follow_up.options.filter((e,n)=>n!==t)}),className:"text-[11px] text-ink-faint hover:text-bad",children:"Remove"})})]},t)),(0,l.jsx)("button",{onClick:()=>x({options:[...u.follow_up.options,{value:"opt_".concat(u.follow_up.options.length+1),label:"New option",allowed_outcomes:u.allowed_outcomes}]}),className:"text-xs text-brand hover:text-brand/80 font-medium",children:"+ Add option"}),(0,l.jsx)("div",{className:"text-right",children:(0,l.jsx)("button",{onClick:()=>h({follow_up:null}),className:"text-[11px] text-ink-faint hover:text-bad",children:"Remove follow-up"})})]})]})]})}function y(e){var t,n,s;let{state:a,update:r}=e,i=null!=(t=a.portal_config.custom_copy.outcome)?t:{},o=e=>r({portal_config:{...a.portal_config,custom_copy:{...a.portal_config.custom_copy,outcome:{...i,...e}}}}),h=a.outcome_config,f=(e,t)=>r({outcome_config:{...h,[e]:{...h[e],...t}}});return(0,l.jsxs)("div",{children:[(0,l.jsx)(p,{children:"Screen copy"}),(0,l.jsx)(m,{label:"Title",value:null!=(n=i.title)?n:"",placeholder:"How would you like to resolve this?",onChange:e=>o({title:e})}),(0,l.jsx)(m,{label:"Subtitle",value:null!=(s=i.subtitle)?s:"",placeholder:"Choose what works best for you.",onChange:e=>o({subtitle:e})}),(0,l.jsx)(p,{children:"Outcome matrix"}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mb-3",children:"Fee override wins over the score-based fee. Bonus is extra value on top."}),(0,l.jsx)("div",{className:"space-y-2",children:c.map(e=>{let t=h[e];return(0,l.jsxs)("div",{className:"grid grid-cols-[1fr_auto_auto_auto] gap-2 items-center p-2.5 rounded-lg bg-hovertint border border-line",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"text-sm font-medium text-ink",children:u[e]}),(0,l.jsx)(d.ks,{value:t.label,onChange:t=>f(e,{label:t.target.value}),className:"mt-1 w-full text-xs",placeholder:"Customer-facing label"})]}),(0,l.jsxs)("div",{className:"flex items-center gap-1 justify-end",children:[(0,l.jsx)("span",{className:"text-ink-faint text-xs",children:"$"}),(0,l.jsx)(d.ks,{type:"number",step:"0.01",placeholder:"score-based",value:null==t.fee_cents_override?"":(t.fee_cents_override/100).toFixed(2),onChange:t=>f(e,{fee_cents_override:""===t.target.value?null:Math.round(100*Number(t.target.value))}),className:"w-20 text-xs font-mono text-right"})]}),(0,l.jsxs)("div",{className:"flex items-center gap-1 justify-end",children:[(0,l.jsx)("span",{className:"text-ink-faint text-xs",children:"+$"}),(0,l.jsx)(d.ks,{type:"number",step:"0.01",value:(t.bonus_cents/100).toFixed(2),onChange:t=>f(e,{bonus_cents:Math.round(100*Number(t.target.value))}),className:"w-16 text-xs font-mono text-right"})]}),(0,l.jsx)(x,{label:"",checked:t.enabled,onChange:t=>f(e,{enabled:t})})]},e)})})]})}function k(e){var t,n,s,a;let{state:r,update:i}=e,o=null!=(t=r.portal_config.custom_copy.photos)?t:{},d=e=>i({portal_config:{...r.portal_config,custom_copy:{...r.portal_config.custom_copy,photos:{...o,...e}}}});return(0,l.jsxs)("div",{children:[(0,l.jsx)(p,{children:"Photo gate position"}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mb-3",children:"Controls when the customer is asked to upload photos (for reasons where photo-required is on, or photo rules match)."}),(0,l.jsx)("div",{className:"space-y-2 mb-4",children:[{id:"with_reason",label:"With the reason step",help:"Photos requested inline on the review screen."},{id:"before_review",label:"Dedicated step before review",help:"Full-screen photo upload step between outcome and review."},{id:"after_confirm",label:"After the label is generated",help:"Customer can add photos anytime before shipping."},{id:"disabled",label:"Never ask for photos",help:"Photos never requested, regardless of reason config."}].map(e=>{let t=r.portal_config.photo_gate_position===e.id;return(0,l.jsxs)("button",{onClick:()=>i({portal_config:{...r.portal_config,photo_gate_position:e.id}}),className:"w-full text-left p-2.5 rounded-lg border transition-colors ".concat(t?"bg-brand/[0.06] border-brand/40":"bg-hovertint border-line hover:border-line-strong"),children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("span",{className:"w-3 h-3 rounded-full border ".concat(t?"bg-brand border-brand":"border-line-strong")}),(0,l.jsx)("span",{className:"text-sm font-medium text-ink",children:e.label})]}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mt-1 ml-5",children:e.help})]},e.id)})}),(0,l.jsx)(p,{children:"Dedicated photo step copy"}
1),(0,l.jsx)(m,{label:"Title",value:null!=(n=o.title)?n:"",onChange:e=>d({title:e})}),(0,l.jsx)(m,{label:"Subtitle",value:null!=(s=o.subtitle)?s:"",onChange:e=>d({subtitle:e})}),(0,l.jsx)(m,{label:"CTA",value:null!=(a=o.cta)?a:"",onChange:e=>d({cta:e})})]})}function w(e){var t,n,s,a;let{state:r,update:i}=e,o=null!=(t=r.portal_config.custom_copy.review)?t:{},d=r.portal_config,c=e=>i({portal_config:{...d,custom_copy:{...d.custom_copy,review:{...o,...e}}}});return(0,l.jsxs)("div",{children:[(0,l.jsx)(p,{children:"Screen copy"}),(0,l.jsx)(m,{label:"Title",value:null!=(n=o.title)?n:"",onChange:e=>c({title:e})}),(0,l.jsx)(m,{label:"Subtitle",value:null!=(s=o.subtitle)?s:"",onChange:e=>c({subtitle:e})}),(0,l.jsx)(m,{label:"CTA",value:null!=(a=o.cta)?a:"",onChange:e=>c({cta:e})}),(0,l.jsx)(p,{children:"Toggles"}),(0,l.jsx)(x,{label:"Show the customer their trust score",checked:d.show_customer_score,onChange:e=>i({portal_config:{...d,show_customer_score:e}})}),(0,l.jsx)(x,{label:"Show pre-sold messaging (not recommended â customer shouldn't know)",checked:d.show_presold_messaging,onChange:e=>i({portal_config:{...d,show_presold_messaging:e}})}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mt-2",children:"Fees and bonuses shown in the live calculator are pulled from the Outcome matrix."})]})}function N(e){var t,n,s,a,r;let{state:i,update:o}=e,d=null!=(t=i.portal_config.custom_copy.done)?t:{},c=i.portal_config,u=e=>o({portal_config:{...c,custom_copy:{...c.custom_copy,done:{...d,...e}}}});return(0,l.jsxs)("div",{children:[(0,l.jsx)(p,{children:"Screen copy (standard return)"}),(0,l.jsx)(m,{label:"Title",value:null!=(n=d.title_normal)?n:"",onChange:e=>u({title_normal:e})}),(0,l.jsx)(m,{label:"Subtitle",value:null!=(s=d.subtitle_normal)?s:"",onChange:e=>u({subtitle_normal:e})}),(0,l.jsx)(p,{children:"Screen copy (keep-item)"}),(0,l.jsx)(m,{label:"Title",value:null!=(a=d.title_keep)?a:"",onChange:e=>u({title_keep:e})}),(0,l.jsx)(m,{label:"Subtitle",value:null!=(r=d.subtitle_keep)?r:"",onChange:e=>u({subtitle_keep:e})}),(0,l.jsx)(p,{children:"Post-submission toggles"}),(0,l.jsx)(x,{label:"Ask for a satisfaction rating (CSAT)",checked:c.csat_enabled,onChange:e=>o({portal_config:{...c,csat_enabled:e}})}),(0,l.jsx)(x,{label:"Allow customer to cancel before carrier pickup",checked:c.cancel_before_ship_enabled,onChange:e=>o({portal_config:{...c,cancel_before_ship_enabled:e}})})]})}let S={pageBg:"#0a0a0a",cardBg:"#141414",cardBorder:"#252525",textPrimary:"#f1f5f9",textSecondary:"#94a3b8",textMuted:"#4b5563",inputBg:"#1a1a1a",inputBorder:"#2a2a2a",divider:"#1e1e1e",textLabel:"#d1d5db"},C="#ABA3FF";function R(e){let{children:t}=e;return(0,l.jsxs)("div",{className:"rounded-xl border border-line bg-app overflow-hidden shadow-xl",children:[(0,l.jsxs)("div",{className:"px-3 py-2 border-b border-line flex items-center gap-1.5",children:[(0,l.jsx)("span",{className:"w-2 h-2 rounded-full bg-hovertint"}),(0,l.jsx)("span",{className:"w-2 h-2 rounded-full bg-hovertint"}),(0,l.jsx)("span",{className:"w-2 h-2 rounded-full bg-hovertint"}),(0,l.jsx)("span",{className:"ml-auto text-[10px] uppercase tracking-wide text-ink-faint",children:"Customer preview"})]}),(0,l.jsx)("div",{className:"p-4 max-h-[560px] overflow-auto",style:{backgroundColor:S.pageBg,color:S.textPrimary,fontFamily:"'Inter', sans-serif"},children:t})]})}function A(e){var t;let{state:n}=e,s=null!=(t=n.portal_config.custom_copy.lookup)?t:{};return(0,l.jsxs)(R,{children:[(0,l.jsxs)("div",{style:{textAlign:"center",marginBottom:"1rem"},children:[(0,l.jsx)("div",{style:{fontSize:18,fontWeight:700,color:S.textPrimary,fontFamily:"'Figtree'"},children:s.title||"How can we help?"}),(0,l.jsx)("div",{style:{fontSize:12,color:S.textSecondary,marginTop:4},children:s.subtitle||"Enter your order details to get started."})]}),(0,l.jsxs)("div",{style:{background:S.cardBg,border:"1px solid ".concat(S.cardBorder),borderRadius:12,padding:"0.875rem"},children:[(0,l.jsx)("div",{style:{fontSize:11,color:S.textLabel,marginBottom:4},children:s.field_order||"Order number"}),(0,l.jsx)("div",{style:{background:S.inputBg,border:"1px solid ".concat(S.inputBorder),borderRadius:8,padding:"0.5rem 0.625rem",fontSize:12,color:S.textMuted,marginBottom:"0.625rem"},children:"e.g. 1007300"}),(0,l.jsx)("div",{style:{fontSize:11,color:S.textLabel,marginBottom:4},children:s.field_email||"Email address"}),(0,l.jsx)("div",{style:{background:S.inputBg,border:"1px solid ".concat(S.inputBorder),borderRadius:8,padding:"0.5rem 0.625rem",fontSize:12,color:S.textMuted,marginBottom:"0.75rem"},children:"[email protected]"}),(0,l.jsxs)("div",{style:{background:C,color:"#fff",borderRadius:8,padding:"0.5rem",textAlign:"center",fontSize:13,fontWeight:600},children:[s.cta||"Find my order"," â"]})]})]})}function F(e){var t;let{state:n}=e,s=null!=(t=n.portal_config.custom_copy.hub)?t:{},a=n.portal_config.hub_cards,r={track:"\uD83D\uDCE6",return:"\uD83D\uDD04",report:"\uD83D\uDEA8",history:"\uD83D\uDD50"};return(0,l.jsxs)(R,{children:[(0,l.jsx)("div",{style:{fontSize:15,fontWeight:600,color:S.textPrimary,fontFamily:"'Figtree'",marginBottom:"0.75rem"},children:s.title||"What can we help you with today?"}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:["track","return","report","history"].filter(e=>{var t;return(null==(t=a[e])?void 0:t.enabled)!==!1}).map(e=>{var t,n;return(0,l.jsxs)("div",{style:{background:S.cardBg,border:"1px solid ".concat(S.cardBorder),borderRadius:10,padding:"0.625rem 0.75rem",display:"flex",alignItems:"center",gap:10},children:[(0,l.jsx)("span",{style:{fontSize:18},children:r[e]}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsx)("div",{style:{fontSize:13,fontWeight:600,color:S.textPrimary}
1,children:(null==(t=a[e])?void 0:t.title)||e}),(0,l.jsx)("div",{style:{fontSize:11,color:S.textSecondary,marginTop:2},children:null==(n=a[e])?void 0:n.subtitle})]})]},e)})})]})}function z(e){var t;let{state:n}=e,s=null!=(t=n.portal_config.custom_copy.items)?t:{};return(0,l.jsxs)(R,{children:[(0,l.jsx)("div",{style:{fontSize:15,fontWeight:700,color:S.textPrimary,fontFamily:"'Figtree'",marginBottom:2},children:s.title||"Select items to return or exchange"}),(0,l.jsx)("div",{style:{fontSize:12,color:S.textSecondary,marginBottom:"0.75rem"},children:s.subtitle||"Tap an itemâ¦"}),[0,1].map(e=>(0,l.jsxs)("div",{style:{background:S.cardBg,border:"2px solid ".concat(0===e?C:S.cardBorder),borderRadius:10,padding:"0.625rem 0.75rem",marginBottom:8},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between"},children:[(0,l.jsxs)("div",{style:{fontSize:12,fontWeight:600,color:S.textPrimary},children:["Sample product #",e+1]}),(0,l.jsxs)("div",{style:{fontSize:12,fontWeight:600,color:S.textPrimary},children:["$",(49+30
1*e).toFixed(2)]})]}),(0,l.jsxs)("div",{style:{fontSize:10,color:S.textMuted,marginTop:2},children:["SKU: ABC-0",e+1]})]},e)),(0,l.jsxs)("div",{style:{background:C,color:"#fff",borderRadius:8,padding:"0.5rem",textAlign:"center",fontSize:12,fontWeight:600,marginTop:8},children:[s.cta||"Continue"," with 1 item â"]})]})}function D(e){var t,n;let{state:s}=e,a=s.return_reasons.filter(e=>e.enabled);return(0,l.jsxs)(R,{children:[(0,l.jsx)("div",{style:{fontSize:11,color:S.textSecondary,marginBottom:4},children:"Reason for return"}),(0,l.jsxs)("div",{style:{background:S.inputBg,border:"1px solid ".concat(S.inputBorder),borderRadius:8,padding:"0.5rem 0.625rem",fontSize:12,color:S.textPrimary,marginBottom:"0.75rem"},children:["â¼ ",null!=(n=null==(t=a[0])?void 0:t.label)?n:"â pick a reason â"]}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:a.slice(0,8).map(e=>{var t,n;return(0,l.jsxs)("div",{style:{fontSize:11,color:e.id===(null==(t=a[0])?void 0:t.id)?S.textPrimary:S.textSecondary,padding:"3px 8px",background:e.id===(null==(n=a[0])?void 0:n.id)?"".concat(C,"15"):"transparent",borderRadius:6},children:[e.label,e.follow_up&&(0,l.jsx)("span",{style:{marginLeft:8,fontSize:9,color:C,fontWeight:600},children:"has follow-up â"}),e.photo_required&&(0,l.jsx)("span",{style:{marginLeft:6,fontSize:9,color:"#fbbf24"},children:"\uD83D\uDCF7"})]},e.id)})})]})}function T(e){let{state:t}=e,n=t.return_reasons.filter(e=>e.enabled&&e.follow_up);if(0===n.length)return(0,l.jsx)(R,{children:(0,l.jsx)("div",{style:{fontSize:12,color:S.textSecondary,textAlign:"center",padding:"2rem 0"},children:"No reasons have a follow-up question yet. The customer will skip this step entirely."})});let s=n[0];return(0,l.jsxs)(R,{children:[(0,l.jsxs)("div",{style:{fontSize:10,color:S.textMuted,marginBottom:4},children:["If customer picked â",s.label,"â"]}),(0,l.jsx)("div",{style:{fontSize:15,fontWeight:700,color:S.textPrimary,fontFamily:"'Figtree'",marginBottom:"0.75rem"},children:s.follow_up.question}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:s.follow_up.options.map((e,t)=>(0,l.jsxs)("div",{style:{background:S.cardBg,border:"2px solid ".concat(0===t?C:S.cardBorder),borderRadius:10,padding:"0.625rem 0.75rem"},children:[(0,l.jsx)("div",{style:{fontSize:12,fontWeight:500,color:S.textPrimary},children:e.label}),(0,l.jsxs)("div",{style:{fontSize:10,color:S.textMuted,marginTop:2},children:["â ",e.allowed_outcomes.join(", ")]})]},e.value))})]})}function E(e){var t;let{state:n}=e,s=null!=(t=n.portal_config.custom_copy.outcome)?t:{},a=n.outcome_config,r=c.filter(e=>a[e].enabled&&"keep_item"!==e),i={exchange:"\uD83D\uDD04",store_credit:"\uD83D\uDCB3",refund:"â©ï¸",keep_item:"\uD83C\uDF81"};return(0,l.jsxs)(R,{children:[(0,l.jsx)("div",{style:{fontSize:15,fontWeight:700,color:S.textPrimary,fontFamily:"'Figtree'",marginBottom:2},children:s.title||"How would you like to resolve this?"}),(0,l.jsx)("div",{style:{fontSize:12,color:S.textSecondary,marginBottom:"0.75rem"},children:s.subtitle||"Choose what works best for you."}),(0,l.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:r.map(e=>{let t=a[e],n=t.bonus_cents>0;return(0,l.jsx)("div",{style:{background:n?"".concat(C,"12"):S.cardBg,border:"2px solid ".concat(n?C:S.cardBorder),borderRadius:10,padding:"0.625rem 0.75rem"},children:(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,l.jsx)("span",{style:{fontSize:18},children:i[e]}),(0,l.jsxs)("div",{style:{flex:1},children:[(0,l.jsxs)("div",{style:{fontSize:12,fontWeight:600,color:S.textPrimary},children:[t.label,n&&(0,l.jsxs)("span",{style:{marginLeft:6,fontSize:9,fontWeight:700,color:"#fff",background:C,padding:"1px 5px",borderRadius:10},children:["+$",(t.bonus_cents/100).toFixed(2)]})]}),(0,l.jsxs)("div",{style:{fontSize:10,color:S.textMuted,marginTop:2},children:[null!=t.fee_cents_override?"Fee: $".concat((t.fee_cents_override/100).toFixed(2)):"Score-based fee"," \xb7 ","refund"===e?"2â3 days after receipt":"store_credit"===e?"Instant on receipt":"Ships on receipt"]})]})]})},e)})})]})}function B(e){var t;let{state:n}=e,s=n.portal_config.photo_gate_position,a=null!=(t=n.portal_config.custom_copy.photos)?t:{};return(0,l.jsxs)(R,{children:[(0,l.jsxs)("div",{style:{fontSize:10,
1color:S.textMuted,marginBottom:4,textTransform:"uppercase",letterSpacing:"0.05em"},children:["Position: ",s]}),(0,l.jsx)("div",{style:{fontSize:12,color:S.textSecondary,marginBottom:"0.75rem",fontStyle:"italic"},children:{with_reason:"Inline on the review screen â photo slot appears next to the items.",before_review:"A dedicated full-screen photo step appears between outcome and review.",after_confirm:"Customer can upload photos anytime before the carrier picks up.",disabled:"Photos never requested â the customer won't see this step."}[s]}),"disabled"!==s&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{style:{fontSize:15,fontWeight:700,color:S.textPrimary,fontFamily:"'Figtree'",marginBottom:2},children:a.title||"Please add photos of your item"}),(0,l.jsx)("div",{style:{fontSize:12,color:S.textSecondary,marginBottom:"0.875rem"},children:a.subtitle||"Photos help us verify the condition quickly."}),(0,l.jsx)("div",{style:{border:"2px dashed ".concat(S.inputBorder),borderRadius:10,padding:"1.25rem",textAlign:"center",fontSize:13,color:S.textMuted},children:"\uD83D\uDCF7 \xa0 Tap to add photos"}),(0,l.jsxs)("div",{style:{background:C,color:"#fff",borderRadius:8,padding:"0.5rem",textAlign:"center",fontSize:12,fontWeight:600,marginTop:12},children:[a.cta||"Continue to review"," â"]})]})]})}function P(e){var t;let{state:n}=e,s=null!=(t=n.portal_config.custom_copy.review)?t:{},a=n.outcome_config.refund,r=null!=a.fee_cents_override?a.fee_cents_override/100:4.99;return(0,l.jsxs)(R,{children:[(0,l.jsx)("div",{style:{fontSize:15,fontWeight:700,color:S.textPrimary,fontFamily:"'Figtree'",marginBottom:2},children:s.title||"Review your return"}),(0,l.jsx)("div",{style:{fontSize:12,color:S.textSecondary,marginBottom:"0.75rem"},children:s.subtitle||"Everything look right?"}),(0,l.jsxs)("div",{style:{background:S.cardBg,border:"1px solid ".concat(S.cardBorder),borderRadius:10,padding:"0.75rem",marginBottom:8},children:[(0,l.jsx)("div",{style:{fontSize:10,color:S.textSecondary,textTransform:"uppercase",marginBottom:6},children:"Items"}),(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:12},children:[(0,l.jsx)("span",{style:{color:S.textPrimary},children:"Sample product"}),(0,l.jsxs)("span",{style:{color:S.textPrimary,fontWeight:600},children:["$","145.58"]})]})]}),(0,l.jsxs)("div",{style:{background:S.cardBg,border:"1px solid ".concat(S.cardBorder),borderRadius:10,padding:"0.75rem"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:12,color:S.textSecondary},children:[(0,l.jsx)("span",{children:"Resolution"}),(0,l.jsx)("span",{style:{color:S.textPrimary,fontWeight:600},children:a.label})]}),(0,l.jsxs)("div",{style:{borderTop:"1px dashed ".concat(S.divider),margin:"0.5rem 0",paddingTop:"0.5rem",display:"flex",flexDirection:"column",gap:3},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:11},children:[(0,l.jsx)("span",{style:{color:S.textSecondary},children:"Item total"}),(0,l.jsxs)("span",{style:{color:S.textLabel},children:["$","145.58"]})]}),(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:11},children:[(0,l.jsx)("span",{style:{color:S.textSecondary},children:"Return fee"}),(0,l.jsx)("span",{style:{color:0===r?"#34d399":"#fca5a5"},children:0===r?"FREE":"â $".concat(r.toFixed(2))})]}),a.bonus_cents>0&&(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:11},children:[(0,l.jsx)("span",{style:{color:S.textSecondary},children:"Bonus"}),(0,l.jsxs)("span",{style:{color:C,fontWeight:600},children:["+ $",(a.bonus_cents/100).toFixed(2)]})]}),(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",fontSize:13,marginTop:4},children:[(0,l.jsx)("span",{style:{color:S.textPrimary,fontWeight:600},children:"Net refund"}),(0,l.jsxs)("span",{style:{color:C,fontWeight:700,fontFamily:"'Figtree'"},children:["$",(145.58-r+a.bonus_cents/100).toFixed(2)]})]})]})]}),(0,l.jsxs)("div",{style:{background:C,color:"#fff",borderRadius:8,padding:"0.5rem",textAlign:"center",fontSize:12,fontWeight:600,marginTop:12},children:[s.cta||"Confirm & get my label"," â"]})]})}function O(e){var t;let{state:n}=e,s=null!=(t=n.portal_config.custom_copy.done)?t:{};return(0,l.jsxs)(R,{children:[(0,l.jsxs)("div",{style:{textAlign:"center",marginBottom:"0.875rem"},children:[(0,l.jsx)("div",{style:{width:44,height:44,borderRadius:"50%",background:"#0d2b1f",border:"1px solid #166534",margin:"0 auto 8px",display:"flex",alignItems:"center",justifyContent:"center"},children:"â"}),(0,l.jsx)("div",{style:{fontSize:16,fontWeight:700,color:S.textPrimary,fontFamily:"'Figtree'"},children:s.title_normal||"Return confirmed!"}),(0,l.jsx)("div",{style:{fontSize:12,color:S.textSecondary,marginTop:4},children:s.subtitle_normal||"Your label is ready. Drop off within 14 days."})]}),(0,l.jsx)("div",{style:{background:"#fff",padding:"0.75rem",borderRadius:10,margin:"0 auto 12px",width:120,height:120,display:"flex",alignItems:"center",justifyContent:"center",color:"#000",fontSize:32},children:"â£"}),n.portal_config.csat_enabled&&(0,l.jsxs)("div",{style:{background:S.cardBg,border:"1px solid ".concat(S.cardBorder),borderRadius:10,padding:"0.625rem"},children:[(0,l.jsx)("div",{style:{fontSize:12,fontWeight:600,color:S.textPrimary,marginBottom:4},children:"How was your return experience?"}),(0,l.jsx)("div",{style:{display:"flex",gap:4},children:[1,2,3,4,5].map(e=>(0,l.jsx)("span",{style:{fontSize:18,color:"#4b5563"},children:"â
"},e))})]})]})}
1function M(e){let{step:t,state:n}=e;switch(t){case"lookup":return(0,l.jsx)(A,{state:n});case"hub":return(0,l.jsx)(F,{state:n});case"items":return(0,l.jsx)(z,{state:n});case"reason":return(0,l.jsx)(D,{state:n});case"followup":return(0,l.jsx)(T,{state:n});case"outcome":return(0,l.jsx)(E,{state:n});case"photos":return(0,l.jsx)(B,{state:n});case"review":return(0,l.jsx)(P,{state:n});case"done":return(0,l.jsx)(O,{state:n})}}function I(e){let{step:t,state:n,update:s}=e;switch(t){case"lookup":return(0,l.jsx)(b,{state:n,update:s});case"hub":return(0,l.jsx)(g,{state:n,update:s});case"items":return(0,l.jsx)(v,{state:n,update:s});case"reason":return(0,l.jsx)(_,{state:n,update:s});case"followup":return(0,l.jsx)(j,{state:n,update:s});case"outcome":return(0,l.jsx)(y,{state:n,update:s});case"photos":return(0,l.jsx)(k,{state:n,update:s});case"review":return(0,l.jsx)(w,{state:n,update:s});case"done":return(0,l.jsx)(N,{state:n,update:s})}}function W(e){var t;let{initial:n,onSave:a,saving:d}=e,[c,u]=(0,s.useState)(n),[p,m]=(0,s.useState)("lookup"),{activeInstance:x}=(0,r.z8)(),f=(0,i.RC)({storageKey:"rules.portalBuilder.".concat(x||"default"),value:c,baseline:n,meta:{label:"Return Portal â ".concat(x||"client"),href:"/rules"}}),b=f.isDirty;return(0,l.jsxs)("div",{className:"space-y-4",children:[f.hasStoredDraft&&(0,l.jsxs)("div",{className:"p-3 rounded-xl bg-hovertint border border-line flex items-center justify-between gap-3 flex-wrap",children:[(0,l.jsxs)("span",{className:"text-xs text-ink",children:["You have unsaved portal changes from ",(0,i.VX)(f.storedDraftAt)," â they were never sent to the server. Restore them, or discard and keep what is saved."]}),(0,l.jsxs)("span",{className:"flex gap-2 shrink-0",children:[(0,l.jsx)("button",{onClick:()=>{let e=f.restoreDraft();e&&u(e)},className:"text-xs text-brand hover:text-brand/80 font-medium",children:"Restore draft"}),(0,l.jsx)("button",{onClick:f.discardDraft,className:"text-xs text-ink-faint hover:text-bad font-medium",children:"Discard"})]})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("div",{children:(0,l.jsx)("p",{className:"text-sm text-ink-soft",children:"Walk through the customer journey top-to-bottom. Everything a customer sees is controlled from this single view â copy, reasons, outcomes, photo gate, confirmation screen."})}),(0,l.jsxs)("span",{className:"flex items-center gap-3 shrink-0",children:[b&&(0,l.jsx)(o.A,{status:"unsaved",label:"Unsaved changes",colors:{unsaved:"#f59e0b"}}),(0,l.jsx)("button",{onClick:()=>a(c),disabled:!b||d,className:"px-5 py-2 rounded-lg bg-brand text-white text-sm font-semibold hover:bg-brand/80 disabled:opacity-40 transition-colors",children:d?"Saving...":b?"Save portal":"Saved"})]})]}),(0,l.jsxs)("div",{className:"grid grid-cols-[200px_1fr_340px] gap-4 items-start",children:[(0,l.jsx)("div",{className:"rounded-xl bg-surface-100 border border-line p-2 sticky top-4",children:h.map(e=>{let t=e.id===p;return(0,l.jsxs)("button",{onClick:()=>m(e.id),className:"w-full flex items-center gap-2 px-3 py-2 rounded-lg text-left transition-colors ".concat(t?"bg-brand/10 text-brand":"text-ink-soft hover:bg-hovertint"),children:[(0,l.jsx)("span",{className:"w-6 h-6 rounded-full flex items-center justify-center text-[11px] font-semibold flex-shrink-0 ".concat(t?"bg-brand text-white":"bg-hovertint text-ink-faint"),children:e.number}),(0,l.jsx)("span",{className:"text-[13px] font-medium",children:e.label})]},e.id)})}),(0,l.jsxs)("div",{className:"rounded-xl bg-surface-100 border border-line p-6 min-h-[560px]",children:[(0,l.jsx)("div",{className:"mb-4 pb-3 border-b border-line",children:(0,l.jsx)("h3",{className:"text-base font-semibold text-ink",children:null==(t=h.find(e=>e.id===p))?void 0:t.label})}),(0,l.jsx)(I,{step:p,state:c,update:e=>u(t=>({...t,...e}))})]}),(0,l.jsxs)("div",{className:"sticky top-4",children:[(0,l.jsx)(M,{step:p,state:c}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mt-2 text-center",children:"Live preview updates as you edit. Save to publish."})]})]})]})}var q=n(3673);let L=[{value:"A",label:"A â New / Open Box"},{value:"B",label:"B â Good, light wear"},{value:"C",label:"C â Fair, visible wear"},{value:"D",label:"D â Salvage"}],H=["defective","damaged_in_shipping","not_as_described","changed_mind","other","wrong_size","wrong_item"],U=["category","subcategory","category_path","brand","sku","upc","price","msrp","wholesale_cost","release_year","condition","attribute.color","attribute.size","attribute.material"],$=["is","is_not","in","not_in","contains","under_path","gt","gte","lt","lte","between"],K=["all","bigd","ebay","amazon","walmart","original_site"],G={all:"All channels",bigd:"Big D Outlet",ebay:"eBay",amazon:"Amazon",walmart:"Walmart",original_site:"Original site"},J=["receiving","processing","fulfilling","storage"],V={fulfillment_window_days:7,condition_grading:{default_grade:"A",reason_overrides:[],rules:[]},allowed_new_fulfillment_pct:5,eligibility_default_include:!0,eligibility_rules:[],pricing_default_factor:.6,pricing_rules:[],return_cost_model:{shipping_rate_per_kg:0,operational_default:{receiving:0,processing:0,fulfilling:0,storage:0},operational_rules:[],outbound_rate_per_kg:0,outbound_flat_default:0,marketplace_fees:{}},channels:[]},X=e=>
1Math.max(0,Math.min(100,Math.round(Number.isFinite(e)?e:0)));function Y(e){let{label:t,hint:n,checked:s,onChange:a,disabled:r}=e;return(0,l.jsxs)("div",{className:"flex items-start justify-between gap-4 rounded-lg border border-line p-3 ".concat(r?"opacity-70":""),children:[(0,l.jsxs)("div",{className:"min-w-0",children:[(0,l.jsx)("div",{className:"text-sm font-medium text-ink",children:t}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mt-0.5 leading-snug",children:n})]}),(0,l.jsx)("div",{className:"shrink-0 pt-0.5",children:(0,l.jsx)(q.A,{checked:s,onChange:a,disabled:r,ariaLabel:t})})]})}function Q(e){let{title:t,subtitle:n,children:s}=e;return(0,l.jsxs)("div",{className:"rounded-xl bg-surface-100 border border-line p-6",children:[(0,l.jsx)("h3",{className:"font-display text-sm font-semibold text-ink mb-1",children:t}),n&&(0,l.jsx)("p",{className:"text-xs text-ink-faint mb-4",children:n}),s]})}function Z(e){let{label:t,value:n,onChange:s,step:a="0.01",suffix:r,hint:i}=e;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:t}),(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[(0,l.jsx)(d.ks,{type:"number",step:a,value:n,onChange:e=>s(Number(e.target.value)),className:"w-full text-sm font-mono"}),r&&(0,l.jsx)("span",{className:"text-ink-faint text-sm",children:r})]}),i&&(0,l.jsx)("p",{className:"text-[10px] text-ink-faint mt-1",children:i})]})}function ee(e){let{value:t,onChange:n}=e;return(0,l.jsx)("div",{className:"flex flex-wrap gap-1.5",children:K.map(e=>{var s;return(0,l.jsx)("button",{type:"button",onClick:()=>(e=>{if("all"===e)return n(["all"]);let l=t.includes(e)?t.filter(t=>t!==e):[...t.filter(e=>"all"!==e),e];n(l.length?l:["all"])})(e),className:"px-2.5 py-1 rounded-md text-xs font-medium border transition-colors ".concat(t.includes(e)?"bg-brand/10 border-brand/30 text-brand":"bg-hovertint border-line text-ink-faint hover:text-ink-soft"),children:null!=(s=G[e])?s:e},e)})})}function et(e){let{conditions:t,onChange:n,fields:s=U}=e,a=(e,l)=>n(t.map((t,n)=>n===e?{...t,...l}:t));return(0,l.jsxs)("div",{className:"space-y-2",children:[t.map((e,r)=>{var i;return(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,l.jsx)(d.l6,{value:e.field,onChange:e=>a(r,{field:e.target.value}),className:"text-xs",children:s.map(e=>(0,l.jsx)("option",{value:e,children:e},e))}),(0,l.jsx)(d.l6,{value:e.op,onChange:e=>a(r,{op:e.target.value}),className:"text-xs",children:$.map(e=>(0,l.jsx)("option",{value:e,children:e},e))}),(0,l.jsx)(d.ks,{value:String(null!=(i=e.value)?i:""),onChange:e=>a(r,{value:e.target.value}),placeholder:["in","not_in","between"].includes(e.op)?"comma-separated":"value",list:"return_reason"===e.field?"rerere-return-reasons":void 0,className:"flex-1 min-w-[100px] text-xs"}),(0,l.jsx)("button",{type:"button",onClick:()=>n(t.filter((e,t)=>t!==r)),className:"px-2 py-1 text-ink-faint hover:text-bad text-xs",children:"â"})]},r)}),(0,l.jsx)("button",{type:"button",onClick:()=>{var e;return n([...t,{field:null!=(e=s[0])?e:"category",op:"is",value:""}])},className:"text-xs text-brand hover:underline",children:"+ Add condition"})]})}function en(e){var t,n,a,c,u,h,p,m,x;let{config:f,onSave:b,saving:g,presellEnabled:v,canToggleEnabled:_,onToggleEnabled:j,onToggleFeatureFlag:y}=e,k=f.predictive_listing_config||{},w=f.predictive_listing_config||{},N=f.engine_flags||{},S={...V,...k,return_cost_model:{...V.return_cost_model,...k.return_cost_model||{},operational_default:{...V.return_cost_model.operational_default,...(null==(t=k.return_cost_model)?void 0:t.operational_default)||{}}}},[C,R]=(0,s.useState)(S.fulfillment_window_days),A=S.error_budget||{},[F,z]=(0,s.useState)("number"==typeof A.default_pct?A.default_pct:"number"==typeof S.allowed_new_fulfillment_pct?S.allowed_new_fulfillment_pct:2),[D,T]=(0,s.useState)(null==(a=A.controller_enabled)||a),[E,B]=(0,s.useState)(null!=(c=A.lookback_days)?c:14),[P,O]=(0,s.useState)(null!=(u=A.explore_max_per_sweep)?u:2),[M,I]=(0,s.useState)(null!=(h=A.explore_open_below)?h:.8),[W,$]=(0,s.useState)(null!=(p=A.tighten_at_or_above)?p:1),[en,el]=(0,s.use
1State)(Object.entries(A.channels||{}).map(e=>{let[t,n]=e;return{channel:t,pct:null!=n.pct?String(n.pct):"",lookback_days:null!=n.lookback_days?String(n.lookback_days):"",explore_max_per_sweep:null!=n.explore_max_per_sweep?String(n.explore_max_per_sweep):"",explore_open_below:null!=n.explore_open_below?String(n.explore_open_below):"",tighten_at_or_above:null!=n.tighten_at_or_above?String(n.tighten_at_or_above):""}})),[es,ea]=(0,s.useState)(S.eligibility_default_include),[er,ei]=(0,s.useState)(S.eligibility_rules||[]),[eo,ed]=(0,s.useState)(S.pricing_default_factor),[ec,eu]=(0,s.useState)(S.pricing_rules||[]),[eh,ep]=(0,s.useState)(S.return_cost_model),[em,ex]=(0,s.useState)(S.channels||[]),[ef,eb]=(0,s.useState)(()=>{var e,t,n;let l=((null==(e=S.condition_grading)?void 0:e.reason_overrides)||[]).map(e=>({name:"Reason: ".concat(e.reason),grade:e.grade,conditions:[{field:"return_reason",op:"is",value:e.reason}]}));return{default_grade:(null==(t=S.condition_grading)?void 0:t.default_grade)||"A",reason_overrides:[],rules:[...l,...(null==(n=S.condition_grading)?void 0:n.rules)||[]]}}),[eg,ev]=(0,s.useState)(Number.isFinite(Number(k.presell_min_return_probability))?X(Number(k.presell_min_return_probability)):70),[e_,ej]=(0,s.useState)(Number.isFinite(Number(k.presell_price_floor_bps))?Math.round(Number(k.presell_price_floor_bps)/100):20),[ey,ek]=(0,s.useState)("string"==typeof k.presell_default_aggressiveness&&k.presell_default_aggressiveness?k.presell_default_aggressiveness:"standard"),{activeInstance:ew}=(0,r.z8)(),eN=(0,s.useMemo)(()=>({X:C,F,ctlOn:D,ebLookback:E,ebSlots:P,ebOpen:M,ebTighten:W,ebOverrides:en,defaultInclude:es,eligRules:er,defaultFactor:eo,priceRules:ec,rcm:eh,channels:em,grading:ef,minReturnProb:eg,globalFloorPct:e_,globalPace:ey}),[C,F,D,E,P,M,W,en,es,er,eo,ec,eh,em,ef,eg,e_,ey]),eS=(0,s.useMemo)(()=>{var e,t,n,l,s,a,r,i,o,d,c,u,h,p,m;return{X:S.fulfillment_window_days,F:"number"==typeof(null==(e=S.error_budget)?void 0:e.default_pct)?S.error_budget.default_pct:"number"==typeof S.allowed_new_fulfillment_pct?S.allowed_new_fulfillment_pct:2,ctlOn:null==(c=null==(t=S.error_budget)?void 0:t.controller_enabled)||c,ebLookback:null!=(u=null==(n=S.error_budget)?void 0:n.lookback_days)?u:14,ebSlots:null!=(h=null==(l=S.error_budget)?void 0:l.explore_max_per_sweep)?h:2,ebOpen:null!=(p=null==(s=S.error_budget)?void 0:s.explore_open_below)?p:.8,ebTighten:null!=(m=null==(a=S.error_budget)?void 0:a.tighten_at_or_above)?m:1,ebOverrides:Object.entries((null==(r=S.error_budget)?void 0:r.channels)||{}).map(e=>{let[t,n]=e;return{channel:t,pct:null!=n.pct?String(n.pct):"",lookback_days:null!=n.lookback_days?String(n.lookback_days):"",explore_max_per_sweep:null!=n.explore_max_per_sweep?String(n.explore_max_per_sweep):"",explore_open_below:null!=n.explore_open_below?String(n.explore_open_below):"",tighten_at_or_above:null!=n.tighten_at_or_above?String(n.tighten_at_or_above):""}}),defaultInclude:S.eligibility_default_include,eligRules:S.eligibility_rules||[],defaultFactor:S.pricing_default_factor,priceRules:S.pricing_rules||[],rcm:S.return_cost_model,channels:S.channels||[],grading:{default_grade:(null==(i=S.condition_grading)?void 0:i.default_grade)||"A",reason_overrides:[],rules:[...((null==(o=S.condition_grading)?void 0:o.reason_overrides)||[]).map(e=>({name:"Reason: ".concat(e.reason),grade:e.grade,conditions:[{field:"return_reason",op:"is",value:e.reason}]})),...(null==(d=S.condition_grading)?void 0:d.rules)||[]]},minReturnProb:Number.isFinite(Number(k.presell_min_return_probability))?X(Number(k.presell_min_return_probability)):70,globalFloorPct:Number.isFinite(Number(k.presell_price_floor_bps))?Math.round(Number(k.presell_price_floor_bps)/100):20,globalPace:"string"==typeof k.presell_default_aggressiveness&&k.presell_default_aggressiveness?k.presell_default_aggressiveness:"standard"}},[k]),eC=(0,i.RC)({storageKey:"listing-rules.".concat(ew||"default"),value:eN,baseline:eS,meta:{label:"Listing Rules â ".concat(ew||"client"),href:"/rules"}}),eR=(e,t)=>{let n=e+t;if(n<0||n>=ec.length)return;let l=[...ec];[l[e],l[n]]=[l[n],l[e]],eu(l)},eA=(e,t)=>
1ei(er.map((n,l)=>l===e?{...n,...t}:n)),eF=(e,t)=>eu(ec.map((n,l)=>l===e?{...n,...t}:n)),ez=(e,t)=>ep({...eh,operational_rules:eh.operational_rules.map((n,l)=>l===e?{...n,...t}:n)});return(0,l.jsxs)("div",{className:"space-y-6",children:[eC.hasStoredDraft&&(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-3 rounded-xl border border-brand/40 bg-brand/5 px-4 py-3",children:[(0,l.jsxs)("span",{className:"text-sm text-ink",children:["You have unsaved edits from ",(0,i.VX)(eC.storedDraftAt),"."]}),(0,l.jsx)("button",{type:"button",onClick:()=>{let e=eC.restoreDraft();e&&(R(e.X),z(e.F),ea(e.defaultInclude),"boolean"==typeof e.ctlOn&&T(e.ctlOn),"number"==typeof e.ebLookback&&B(e.ebLookback),"number"==typeof e.ebSlots&&O(e.ebSlots),"number"==typeof e.ebOpen&&I(e.ebOpen),"number"==typeof e.ebTighten&&$(e.ebTighten),Array.isArray(e.ebOverrides)&&el(e.ebOverrides),ei(e.eligRules),ed(e.defaultFactor),eu(e.priceRules),ep(e.rcm),ex(e.channels),eb(e.grading),ev(e.minReturnProb),"number"==typeof e.globalFloorPct&&ej(e.globalFloorPct),"string"==typeof e.globalPace&&ek(e.globalPace))},className:"text-sm text-brand hover:underline font-medium",children:"Restore draft"}),(0,l.jsx)("button",{type:"button",onClick:eC.discardDraft,className:"text-sm text-ink-faint hover:text-bad",children:"Discard"})]}),(0,l.jsxs)("div",{className:"flex items-start justify-between gap-4 rounded-xl bg-surface-100 border border-line p-6",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"font-display text-sm font-semibold text-ink mb-1",children:"Predictive listing engine"}),(0,l.jsxs)("p",{className:"text-xs text-ink-faint max-w-xl",children:["When on, rerere predicts which sold units will be returned and pre-lists them to your chosen channels using the rules below â pulling each listing when the item comes back or its return window closes."," ",_?"Flip it here; the rules take effect immediately.":"It's switched on per account by rerere during rollout â set your rules up here so you're ready, then ask your rerere contact to turn it on."]})]}),(0,l.jsx)("div",{className:"flex items-center gap-2 shrink-0 pt-0.5",children:_?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("span",{className:"text-xs font-semibold ".concat(v?"text-good":"text-ink-faint"),children:v?"On":"Off"}),(0,l.jsx)(q.A,{checked:v,onChange:j,ariaLabel:"Enable predictive listing engine"})]}):(0,l.jsx)("span",{className:"px-3 py-1 rounded-full text-xs font-medium border ".concat(v?"bg-good/10 border-good/30 text-good":"bg-hovertint border-line text-ink-faint"),children:v?"On":"Off"})})]}),(0,l.jsx)(Q,{title:"Marketplaces & channels",subtitle:"Where predicted listings are published. Individual rules below can target specific channels.",children:(0,l.jsx)(ee,{value:em,onChange:ex})}),(0,l.jsxs)(Q,{title:"Item rules",subtitle:"Which catalog items may be pre-sold. Rules are named (state the reason: MAP, recall, hazmatâ¦), channel-scoped, and evaluated top-to-bottom â the last matching rule wins. Non-returnable items are always excluded automatically.",children:[(0,l.jsxs)("div",{className:"mb-5",children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Minimum return probability to list (%)"}),(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)(d.Q6,{min:0,max:100,step:1,value:eg,onChange:e=>ev(X(Number(e.target.value))),className:"flex-1"}),(0,l.jsx)(d.ks,{type:"number",min:0,max:100,value:eg,onChange:e=>ev(X(Number(e.target.value))),"aria-label":"Minimum return probability to list, percent",className:"w-20 text-right font-mono"}),(0,l.jsx)("span",{className:"text-sm text-ink-faint",children:"%"})]}),(0,l.jsx)("p",{className:"text-[10px] text-ink-faint mt-1",children:"Only items the prediction engine scores at or above this return-probability are pre-listed. Lower lists more items (more speculative); higher lists fewer, safer bets. Default 70."})]}),(0,l.jsx)("div",{className:"mb-5 max-w-xs",children:(0,l.jsx)(Z,{label:"Fulfillment window (days)",value:C,onChange:R,step:"1",hint:"Only pre-sell items expected back within this many days â the return promise you can realistically keep."})}),(0,l.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,l.jsx)(q.A,{checked:es,onChange:ea,ariaLabel:"Default eligibility posture"}),(0,l.jsx)("span",{className:"text-sm text-ink-soft",children:es?"Include all items by default (exclude exceptions below)":"Exclude all by default (opt items in below)"})]}),(0,l.jsxs)("div",{className:"space-y-3",children:[er.map((e,t)=>(0,l.jsxs)("div",{className:"rounded-lg border border-line bg-hovertint/40 p-4 space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(d.ks,{value:e.name,onChange:e=>eA(t,{name:e.target.value}),placeholder:"Rule name (e.g. MAP â Nike)",className:"flex-1 text-sm font-medium"}),(0,l.jsx)("div",{className:"flex rounded-lg overflow-hidden border border-line",children:["include","exclude"].map(n=>(0,l.jsx)("button",{type:"button",onClick:()=>eA(t,{effect:n}),className:"px-3 py-1.5 text-xs font-medium ".concat(e.effect===n?"exclude"===n?"bg-bad/10 text-bad":"bg-good/10 text-good":"bg-hovertint text-ink-faint"),children:n},n))}),(0,l.jsx)("button",{type:"button",onClick:()=>
1ei(er.filter((e,n)=>n!==t)),className:"px-2 py-1 text-ink-faint hover:text-bad text-xs",children:"Remove"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Applies to channels"}),(0,l.jsx)(ee,{value:e.channels,onChange:e=>eA(t,{channels:e})})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Conditions (all must match)"}),(0,l.jsx)(et,{conditions:e.conditions,onChange:e=>eA(t,{conditions:e})})]})]},t)),(0,l.jsx)("button",{type:"button",onClick:()=>ei([...er,{name:"",effect:"exclude",channels:["all"],conditions:[]}]),className:"text-sm text-brand hover:underline",children:"+ Add eligibility rule"})]})]}),(0,l.jsxs)(Q,{title:"Assumed condition",subtitle:"Returned units aren't inspected before listing, so we assume a condition. It sets the listing's condition and which market comps we price against â the single biggest pricing input you control.",children:[(0,l.jsxs)("div",{className:"max-w-sm",children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Assume every return is"}),(0,l.jsx)(d.l6,{value:ef.default_grade,onChange:e=>eb({...ef,default_grade:e.target.value}),children:L.map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mt-2",children:"Today everything lists as New / Open Box, so A matches what buyers actually see. Grading happens when the unit is processed at R1 â until weâre integrated there, this setting is the condition."})]}),(0,l.jsx)("datalist",{id:"rerere-return-reasons",children:H.map(e=>(0,l.jsx)("option",{value:e},e))}),(0,l.jsxs)("div",{className:"mt-6 pt-5 border-t border-line",children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Refinements"}),(0,l.jsx)("p",{className:"text-[11px] text-ink-faint mb-3",children:"Optional. The default above applies to everything; each refinement overrides it for the units its conditions match â by return reason, category, brand, SKU, UPC, price point, or any combination (the same builder as Item rules and Pricing). Evaluated top to bottom, last match wins. Anything no refinement matches falls back to the default."}),0===(ef.rules||[]).length&&(0,l.jsxs)("p",{className:"text-[11px] text-ink-faint italic mb-3",children:["No refinements â every return is assumed"," ",(null==(n=L.find(e=>e.value===ef.default_grade))?void 0:n.label)||ef.default_grade,"."]}),(0,l.jsxs)("div",{className:"space-y-3",children:[(ef.rules||[]).map((e,t)=>(0,l.jsxs)("div",{className:"rounded-lg border border-line bg-hovertint/40 p-4 space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(d.ks,{value:e.name,onChange:e=>{let n=[...ef.rules||[]];n[t]={...n[t],name:e.target.value},eb({...ef,rules:n})},placeholder:"Rule name (e.g. Electronics come back B)",className:"flex-1 text-sm font-medium"}),(0,l.jsx)(d.l6,{value:e.grade,onChange:e=>{let n=[...ef.rules||[]];n[t]={...n[t],grade:e.target.value},eb({...ef,rules:n})},className:"text-xs","aria-label":"Assumed condition for matching items",children:L.map(e=>(0,l.jsx)("option",{value:e.value,children:e.label},e.value))}),(0,l.jsx)("button",{type:"button",onClick:()=>eb({...ef,rules:(ef.rules||[]).filter((e,n)=>n!==t)}),className:"px-2 py-1 text-ink-faint hover:text-bad text-xs",children:"Remove"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Conditions (all must match)"}),(0,l.jsx)(et,{conditions:e.conditions,fields:["return_reason",...U],onChange:e=>{let n=[...ef.rules||[]];n[t]={...n[t],conditions:e},eb({...ef,rules:n})}})]})]},t)),(0,l.jsx)("button",{type:"button",onClick:()=>eb({...ef,rules:[...ef.rules||[],{name:"",grade:ef.default_grade,conditions:[]}]}),className:"text-sm text-brand hover:underline",children:"+ Add refinement"})]})]})]}
1),(0,l.jsxs)(Q,{title:"Pricing & floor",subtitle:"How a pre-sell price is set: a percentage of the item's retail price, minus the logistics you save by pre-selling. A real market comp, when we have one, overrides the percentage.",children:[(0,l.jsxs)("div",{className:"flex flex-wrap gap-4 mb-4",children:[(0,l.jsx)("div",{className:"max-w-xs",children:(0,l.jsx)(Z,{label:"Default price (% of retail)",value:Math.round(100*eo),onChange:e=>ed(e/100),step:"1",suffix:"%",hint:"What an open-box unit typically fetches, as a share of retail."})}),(0,l.jsx)("div",{className:"max-w-xs",children:(0,l.jsx)(Z,{label:"Default floor â never below (% of retail)",value:e_,onChange:e=>ej(e),step:"1",suffix:"%",hint:"The client-wide floor every item inherits unless a rule below sets its own."})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Default markdown pace"}),(0,l.jsxs)(d.l6,{value:ey,onChange:e=>ek(e.target.value),className:"w-32 text-xs",children:[(0,l.jsx)("option",{value:"gentle",children:"gentle"}),(0,l.jsx)("option",{value:"standard",children:"standard"}),(0,l.jsx)("option",{value:"aggressive",children:"aggressive"})]})]})]}),(0,l.jsxs)("p",{className:"text-xs text-ink-faint mb-3",children:["Floors work at three levels: the default above applies to everything; add a rule with a category condition (or ",(0,l.jsx)("span",{className:"font-mono",children:"category_path"})," +",(0,l.jsx)("span",{className:"font-mono",children:" under_path"}),") for a category floor, or a",(0,l.jsx)("span",{className:"font-mono",children:" sku"}),"/",(0,l.jsx)("span",{className:"font-mono",children:"upc"})," condition for a single product. Rules are checked top to bottom and the ",(0,l.jsx)("span",{className:"font-medium text-ink-soft",children:"last match wins"})," â keep broad rules high and specific ones (SKU/UPC) low, using the arrows to reorder."]}),(0,l.jsxs)("div",{className:"space-y-3",children:[ec.map((e,t)=>{var n,s;return(0,l.jsxs)("div",{className:"rounded-lg border border-line bg-hovertint/40 p-4 space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsxs)("span",{className:"flex flex-col shrink-0",children:[(0,l.jsx)("button",{type:"button",onClick:()=>eR(t,-1),disabled:0===t,"aria-label":"Move rule up",className:"px-1 text-ink-faint hover:text-ink text-[10px] leading-tight disabled:opacity-30",children:"â²"}),(0,l.jsx)("button",{type:"button",onClick:()=>eR(t,1),disabled:t===ec.length-1,"aria-label":"Move rule down",className:"px-1 text-ink-faint hover:text-ink text-[10px] leading-tight disabled:opacity-30",children:"â¼"})]}),(0,l.jsx)(d.ks,{value:e.name,onChange:e=>eF(t,{name:e.target.value}),placeholder:"Rule name (e.g. Electronics 70%)",className:"flex-1 text-sm font-medium"}),(0,l.jsx)("button",{type:"button",onClick:()=>eu(ec.filter((e,n)=>n!==t)),className:"px-2 py-1 text-ink-faint hover:text-bad text-xs",children:"Remove"})]}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"% of retail"}),(0,l.jsx)(d.ks,{type:"number",step:"1",value:null!=e.factor?Math.round(100*e.factor):"",onChange:e=>eF(t,{factor:""===e.target.value?void 0:Number(e.target.value)/100,amount:void 0}),className:"w-28 text-xs font-mono"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"â¦or fixed $"}),(0,l.jsx)(d.ks,{type:"number",step:"0.01",value:null!=(n=e.amount)?n:"",onChange:e=>eF(t,{amount:""===e.target.value?void 0:Number(e.target.value),factor:void 0}),className:"w-28 text-xs font-mono"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",title:"The lowest we'll ever list an item this rule covers â the repricer can never mark down past it.",children:"Never below (% of retail)"}),(0,l.jsx)(d.ks,{type:"number",step:"1",min:"1",max:"100",value:null!=e.floor_bps?Math.round(e.floor_bps/100):"",onCh
1ange:e=>eF(t,{floor_bps:""===e.target.value?void 0:Math.round(100*Number(e.target.value))}),className:"w-28 text-xs font-mono"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",title:"How fast prices glide toward the floor as the sell-window burns: gentle holds price longer, aggressive marks down early.",children:"Markdown pace"}),(0,l.jsxs)(d.l6,{value:null!=(s=e.aggressiveness)?s:"",onChange:e=>eF(t,{aggressiveness:e.target.value||void 0}),className:"w-28 text-xs",children:[(0,l.jsx)("option",{value:"",children:"(default)"}),(0,l.jsx)("option",{value:"gentle",children:"gentle"}),(0,l.jsx)("option",{value:"standard",children:"standard"}),(0,l.jsx)("option",{value:"aggressive",children:"aggressive"})]})]})]}),e.seeded&&(0,l.jsx)("p",{className:"text-[10px] text-ink-faint",children:"Seeded default â this catch-all rule guarantees every listing has a floor. Edit it freely; nothing lists without one."}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Applies to channels"}),(0,l.jsx)(ee,{value:e.channels,onChange:e=>eF(t,{channels:e})})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Conditions (all must match)"}),(0,l.jsx)(et,{conditions:e.conditions,onChange:e=>eF(t,{conditions:e})})]})]},t)}),(0,l.jsx)("button",{type:"button",onClick:()=>
1eu([...ec,{name:"",channels:["all"],conditions:[],factor:.7}]),className:"text-sm text-brand hover:underline",children:"+ Add pricing rule"})]}),(0,l.jsxs)("div",{className:"mt-6 pt-6 border-t border-line",children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Return-cost model â logistics saved by pre-selling"}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mb-4",children:"These are the handling costs we cut by pre-selling; they're subtracted from the reference price. Shipping is estimated from item weight; operational costs are what you'd normally spend receiving and processing a return. Set a flat default or per-category overrides."}),(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4",children:[(0,l.jsx)(Z,{label:"Inbound return shipping ($ / kg)",value:eh.shipping_rate_per_kg,onChange:e=>ep({...eh,shipping_rate_per_kg:e}),hint:"The return leg we CUT by pre-selling â subtracted from the reference price as savings."}),(0,l.jsx)(Z,{label:"Outbound shipping ($ / kg)",value:null!=(m=eh.outbound_rate_per_kg)?m:0,onChange:e=>ep({...eh,outbound_rate_per_kg:e}),hint:"Shipping the unit from your facility to the new buyer â part of OUR cost on each resale (shown in net proceeds, doesn't change the customer price)."}),(0,l.jsx)(Z,{label:"Outbound flat fallback ($ / shipment)",value:null!=(x=eh.outbound_flat_default)?x:0,onChange:e=>ep({...eh,outbound_flat_default:e}),hint:"Used when an item has no weight on file."})]}),(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-2",children:"Marketplace fees (% of sale price â your estimates)"}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mb-2",children:"These are editable estimates per channel. The fee each item ACTUALLY pays is measured from real transactions and shown in the Catalog (and Data Explorer) beside your estimate."}),(0,l.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-4",children:["ebay","amazon","walmart","bigd"].map(e=>{var t,n;return(0,l.jsx)(Z,{label:e,suffix:"%",step:"0.5",value:null!=(n=(null!=(t=eh.marketplace_fees)?t:{})[e])?n:0,onChange:t=>{var n;return ep({...eh,marketplace_fees:{...null!=(n=eh.marketplace_fees)?n:{},[e]:t}})}},e)})}),(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-2",children:"Default operational cost ($ per unit)"}),(0,l.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-4",children:J.map(e=>(0,l.jsx)(Z,{label:e,value:eh.operational_default[e],onChange:t=>ep({...eh,operational_default:{...eh.operational_default,[e]:t}})},e))}),(0,l.jsxs)("div",{className:"space-y-3",children:[eh.operational_rules.map((e,t)=>(0,l.jsxs)("div",{className:"rounded-lg border border-line bg-hovertint/40 p-4 space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(d.ks,{value:e.name,onChange:e=>ez(t,{name:e.target.value}),placeholder:"Rule name (e.g. Category 1 ops)",className:"flex-1 text-sm font-medium"}),(0,l.jsx)("button",{type:"button",onClick:()=>ep({...eh,operational_rules:eh.operational_rules.filter((e,n)=>n!==t)}),className:"px-2 py-1 text-ink-faint hover:text-bad text-xs",children:"Remove"})]}),(0,l.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:J.map(n=>{var s;return(0,l.jsx)(Z,{label:n,value:null!=(s=e[n])?s:0,onChange:e=>ez(t,{[n]:e})},n)})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Applies to channels"}),(0,l.jsx)(ee,{value:e.channels,onChange:e=>ez(t,{channels:e})})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-1",children:"Conditions (all must match)"}),(0,l.jsx)(et,{conditions:e.conditions,onChange:e=>ez(t,{conditions:e})})]})]},t)),(0,l.jsx)("button",{type:"button",onClick:()=>ep({...eh,operational_rules:[...eh.operational_rules,{name:"",channels:["all"],
1conditions:[],receiving:0,processing:0,fulfilling:0,storage:0}]}),className:"text-sm text-brand hover:underline",children:"+ Add operational-cost rule"})]})]})]}),(0,l.jsxs)(Q,{title:"Error budget â the one dial",subtitle:"One number drives the whole engine: at 2% the system operates to 98% accuracy everywhere â quantity sizing, the trust ladder, the circuit-breaker floor, and the buy-new cap all derive from it. Nothing else in the code overrides it.",children:[(0,l.jsx)("div",{className:"max-w-md mb-5",children:(0,l.jsx)(Z,{label:"Allowed error rate (%)",value:F,onChange:z,step:"0.5",suffix:"%",hint:"The % of pre-sold orders we may miss and make whole by buying new from your inventory at replacement cost. Everything answers to this number: units committed per product (sizing at the matching success target), how fast a product earns bigger commitments (the trust ladder halves any product that fails above it), and the accuracy floor that pauses listing when live performance drops below (100 â this)%. Lower = fewer, safer listings; higher = more volume, more risk."})}),(0,l.jsxs)("div",{className:"rounded-lg border border-line bg-hovertint/40 p-4 mb-5 space-y-4",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)(q.A,{checked:D,onChange:T,ariaLabel:"Budget controller"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"text-sm text-ink",children:"Budget controller â learn toward the budget"}),(0,l.jsx)("p",{className:"text-[10px] text-ink-faint mt-0.5",children:"Each sweep measures actual error use from live order webhooks. Under budget â it trials products with no track record (1 unit each) so the book grows; at or over â exploration closes and the ladder/breaker tighten. The goal: sell as much as possible while staying under your %."})]})]}),D&&(0,l.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[(0,l.jsx)(Z,{label:"Measurement window (days)",value:E,onChange:B,step:"1",hint:"How far back the controller looks when measuring the live error rate. Shorter reacts faster; longer is steadier."}),(0,l.jsx)(Z,{label:"Trials per sweep",value:P,onChange:O,step:"1",hint:"Max unproven products admitted per 30-min sweep while under budget, 1 unit each. 0 disables trials without turning the controller off."}),(0,l.jsx)(Z,{label:"Open trials below",value:M,onChange:I,step:"0.05",suffix:"x budget",hint:"Trials open only while measured use is under this share of budget. 0.8 = explore while below 80% used."}),(0,l.jsx)(Z,{label:"Tighten at",value:W,onChange:$,step:"0.05",suffix:"x budget",hint:"At or above this share of budget the system tightens: trials close AND only products with their own proven track record may list at all â even when shadow/looser modes are on. 1.0 = exactly at budget."})]})]}),(0,l.jsxs)("div",{className:"mb-6",children:[(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-2",children:"Per-marketplace overrides"}),0===en.length&&(0,l.jsx)("p",{className:"text-xs text-ink-faint mb-2",children:"None â every marketplace uses the default budget above."}),(0,l.jsx)("div",{className:"space-y-2",children:en.map((e,t)=>{let n=e=>el(en.map((n,l)=>l===t?{...n,...e}:n));return(0,l.jsxs)("div",{className:"flex flex-wrap items-end gap-2 rounded-lg border border-line bg-hovertint/40 p-3",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] text-ink-faint block mb-1",children:"Marketplace"}),(0,l.jsxs)(d.l6,{value:e.channel,onChange:e=>n({channel:e.target.value}),className:"text-sm",children:[(0,l.jsx)("option",{value:"",children:"Chooseâ¦"}),K.filter(e=>"all"!==e).map(e=>(0,l.jsx)("option",{value:e,disabled:en.some((n,l)=>l!==t&&n.channel===e),children:G[e]||e},e))]})]}),[["pct","Error rate (%)"],["lookback_days","Window (days)"],["explore_max_per_sweep","Trials/sweep"],["explore_open_below","Open below"],["tighten_at_or_above","Tighten at"]].map(t=>{let[s,a]=t;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-[10px] text-ink-faint block mb-1",children:a}),(0,l.jsx)(d.ks,{type:"number",value:e[s],placeholder:"default",onChange:e=>n({[s]:e.target.value}),className:"w-24 text-right font-mono text-sm","aria-label":(e.channel||"override")+" "+a})]},s)}),(0,l.jsx)("button",{type:"button",onClick:()=>
1el(en.filter((e,n)=>n!==t)),className:"text-xs text-ink-faint hover:text-red-400 pb-2",children:"Remove"})]},t)})}),(0,l.jsx)("button",{type:"button",onClick:()=>el([...en,{channel:"",pct:"",lookback_days:"",explore_max_per_sweep:"",explore_open_below:"",tighten_at_or_above:""}]),className:"text-sm text-brand hover:underline mt-2",children:"+ Add marketplace override"}),(0,l.jsx)("p",{className:"text-[10px] text-ink-faint mt-1",children:"Blank fields inherit the defaults above â set only what differs for that marketplace. Because one shared pool of listings serves every enabled marketplace, the strictest (lowest) % among them governs sizing; a client selling only on their own site gets that marketplace's budget applied everywhere."})]}),(0,l.jsx)("label",{className:"text-[10px] uppercase tracking-wide text-ink-faint block mb-2",children:"Engine controls"}),(0,l.jsxs)("div",{className:"space-y-4 max-w-2xl",children:[(0,l.jsx)(Y,{label:"Shadow mode â assume 100% sell-through",hint:"While on (the default until real selling begins), the engine lists EVERY predicted unit 1:1 â quantity caps, the trust ladder, and the economic gate are bypassed, and flagging uses return probability + fulfillment feasibility only. Flip off to bring the caps and gates back for real selling.",checked:!!N.presell_assume_full_sellthrough,onChange:e=>b({predictive_listing_config:{...w,presell_assume_full_sellthrough:e}})}),(0,l.jsx)(Y,{label:"Dynamic repricing",hint:"Prices glide from the engine's original price toward your floor as each unit's sell-window burns â never below the floor, pushed live to the storefront, every change recorded. Manual price holds always win over the glide.",checked:!!N.presell_dynamic_pricing,onChange:e=>b({predictive_listing_config:{...w,presell_dynamic_pricing:e}})}),(0,l.jsx)(Y,{label:"Economic break-even gate",hint:"An item only lists when its return probability clears ITS OWN break-even â an item predicted to come back in rough condition must be more certain than a clean one. Only ever raises the bar above your listing threshold.",checked:!!N.presell_economic_gate,onChange:e=>b({predictive_listing_config:{...w,presell_economic_gate:e}})}),(0,l.jsx)(Y,{label:"Quantity caps (newsvendor + trust ladder)",hint:"Caps how many units of each product the engine will commit: what the forecast supports at your risk dial, bounded by the product's proven track record (new products start small and earn up).",checked:!!N.presell_quantity_caps,onChange:e=>b({predictive_listing_config:{...w,presell_quantity_caps:e}})}),(0,l.jsx)(Y,{label:"Auto-publish to channels",hint:"Predicted units flow to the connected storefront automatically. Rollout-controlled â flipped by the rerere team.",checked:!!N.presell_auto_publish,disabled:!_,onChange:e=>null==y?void 0:y("presell_auto_publish",e)})]})]}),(0,l.jsxs)("div",{className:"flex justify-end items-center gap-3",children:[eC.isDirty&&(0,l.jsx)(o.A,{status:"unsaved",label:"Unsaved changes",colors:{unsaved:"#f59e0b"}}),(0,l.jsx)("button",{onClick:()=>b({predictive_listing_config:{...k,fulfillment_window_days:C,allowed_new_fulfillment_pct:F,error_budget:{default_pct:F,controller_enabled:D,lookback_days:E,explore_max_per_sweep:P,explore_open_below:M,tighten_at_or_above:W,channels:Object.fromEntries(en.filter(e=>e.channel).map(e=>[e.channel,Object.fromEntries([["pct",e.pct],["lookback_days",e.lookback_days],["explore_max_per_sweep",e.explore_max_per_sweep],["explore_open_below",e.explore_open_below],["tighten_at_or_above",e.tighten_at_or_above]].filter(e=>{let[,t]=e;return""!==t}).map(e=>{let[t,n]=e;return[t,Number(n)]}))]))},eligibility_default_include:es,eligibility_rules:er,pricing_default_factor:eo,pricing_rules:ec,presell_price_floor_bps:Math.round(100*e_),presell_default_aggressiveness:ey,return_cost_model:eh,channels:em,condition_grading:ef,presell_min_return_probability:eg}}),disabled:g,className:"px-6 py-2 rounded-lg bg-brand text-white text-sm font-medium hover:bg-brand/80 disabled:opacity-50 transition-colors",children:g?"Saving...":"Save Changes"})]})]})}var el=n(47101),es=n(22031),ea=n(22408),er=n(45255);let ei={published:"#10b981",pending:"#f59e0b",issues:"#ef4444",delisted:"#6b7280",listed:"#10b981"},eo={shopify:"Shopify",ebay:"eBay",amazon:"Amazon",walmart:"Walmart",mercadolibre:"Mercado Libre"};function ed(e){var t,n;return[null!=(n=null!=(t=eo[e.channel_type])?t:e.display_name)?n:e.channel_type,e.env,e.status].filter(
1Boolean).join(" \xb7 ")}let ec=e=>null==e?"â":"$".concat((e/100).toFixed(2)),eu=[{id:"until_released",label:"Until I release it"},{id:"until_time",label:"Until a date/time"},{id:"until_inventory_zero",label:"Until it sells out"}],eh=[{id:"",label:"Every marketplace"},{id:"shopify",label:"Shopify"},{id:"ebay",label:"eBay"},{id:"amazon",label:"Amazon"},{id:"walmart",label:"Walmart"},{id:"mercadolibre",label:"Mercado Libre"}];function ep(e){let{slug:t}=e,[n,r]=(0,s.useState)([]),[i,c]=(0,s.useState)(!0),[u,h]=(0,s.useState)(null),[p,m]=(0,s.useState)(null),[x,f]=(0,s.useState)([]),[b,g]=(0,s.useState)(""),[v,_]=(0,s.useState)(!1),[j,y]=(0,s.useState)(""),k=async(e,n,l)=>{_(!0),y("");try{await (0,a.apiPost)("/api/v1/resale/listings/bulk-override?client_slug=".concat(t),{listing_ids:x.map(e=>e.id),field:e,value:n,hold_mode:"until_released",reason:l}),y("Applied to ".concat(x.length," listing(s)")),await w()}catch(e){y(e instanceof Error?e.message:"Bulk change failed â try again.")}_(!1)},w=(0,s.useCallback)(async()=>{c(!0);try{let n=0,l=1/0,s=[];for(let r=0;r<20&&n<l;r++){var e;let r=await (0,a.apiGet)("/api/v1/resale/listings?client_slug=".concat(t,"&limit=").concat(1e3,"&offset=").concat(n));if(s.push(...r.listings||[]),l=null!=(e=r.total)?e:s.length,n+=1e3,(r.listings||[]).length<1e3)break}r(s),h(null)}catch(e){r([]),h("The live listings didn't load â the server returned an error. Try refreshing; if it persists, contact engineering with the tag [LISTINGS LOAD].")}c(!1)},[t]);(0,s.useEffect)(()=>{w()},[w]);let N=(0,s.useMemo)(()=>[{field:"title",headerName:"Listing",flex:2,minWidth:220,valueGetter:e=>{var t,n;return(null==(t=e.data)?void 0:t.title)||(null==(n=e.data)?void 0:n.listing_sku)}},{field:"listing_sku",headerName:"SKU",flex:1,minWidth:150},{field:"quantity",headerName:"Qty",width:80,type:"numericColumn"},{field:"rule_price_cents",headerName:"Rule price",width:110,valueFormatter:e=>ec(e.value)},{field:"effective_price_cents",headerName:"Live price",width:110,cellRenderer:e=>{let t=e.data;if(!t)return"";let n=t.overridden&&t.effective_price_cents!==t.rule_price_cents;return(0,l.jsx)("span",{className:n?"text-amber-400 font-semibold":"text-ink",children:ec(t.effective_price_cents)})}},{field:"status",headerName:"Control",width:130,cellRenderer:e=>{let t=e.data;return t?t.paused?(0,l.jsx)(o.A,{status:"paused",label:"Paused"}):t.overridden?(0,l.jsx)(o.A,{status:"warning",label:"Held"}):(0,l.jsx)(o.A,{status:"active",label:"On rules"}):""}},{field:"channels",headerName:"Channels",flex:1.4,minWidth:220,valueGetter:e=>{var t;return((null==(t=e.data)?void 0:t.channel_states)||[]).map(ed).join(", ")},cellRenderer:e=>{var t;let n=(null==(t=e.data)?void 0:t.channel_states)||[];return n.length?(0,l.jsx)("span",{className:"inline-flex flex-wrap gap-1",children:n.map(e=>(0,l.jsx)(o.A,{status:e.status,colors:ei,label:ed(e)},e.channel_id))}):(0,l.jsx)("span",{className:"text-ink-faint",children:"â"})}}],[]);return i?(0,l.jsx)("div",{className:"flex justify-center py-16",children:(0,l.jsx)(es.default,{})}):(0,l.jsxs)("div",{children:[u&&(0,l.jsx)("div",{role:"alert",className:"mb-4 px-4 py-3 rounded border border-red-400/40 text-red-400 text-sm leading-relaxed",children:u}),(0,l.jsx)("p",{className:"text-ink-faint text-sm mb-4",children:"Every live listing follows your Listing Rules by default. Grab any one to hold its price, run a promo, or pause it â it stays held until you release it (or it sells out)."}),0===n.length?(0,l.jsx)("div",{className:"rounded-xl border border-line bg-surface-100 p-8 text-center text-ink-faint text-sm",children:"No active listings yet. Once the pipeline lists items, they appear here."}):(0,l.jsxs)(l.Fragment,{children:[x.length>0&&(0,l.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2 rounded-lg border border-accent/40 bg-accent/5 px-3 py-2",children:[(0,l.jsxs)("span",{className:"text-sm text-ink font-medium",children:[x.length," selected"]}),(0,l.jsx)(d.ks,{value:b,onChange:e=>g(e.target.value),placeholder:"Price ($)",className:"w-28"}),(0,l.jsxs)(el.A,{disabled:v,onClick:()=>{let e=Math.round(100*parseFloat(b));if(!Number.isFinite(e)||e<=0)return void y("Enter a valid price.");k("price",{cents:e},"bulk price hold")},children:["Set price for ",x.length]}),(0,l.jsxs)(el.A,{variant:"secondary",disabled:v,onClick:()=>void k("paused",{},"bulk pause"),children:["Pause ",x.length]}),j&&(0,l.jsx)("span",{className:"text-xs text-ink-faint",children:j})]}),(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1 mb-2 text-xs text-ink-soft",children:[(0,l.jsxs)("span",{children:[(0,l.jsx)("span",{className:"font-mono text-ink",children:n.length.toLocaleStr
1ing()})," listings"]}),(0,l.jsxs)("span",{children:[(0,l.jsx)("span",{className:"font-mono text-ink",children:n.reduce((e,t)=>e+(t.quantity||0),0).toLocaleString()})," units listed"]}),(0,l.jsxs)("span",{children:[(0,l.jsx)("span",{className:"font-mono text-ink",children:n.filter(e=>!e.quantity).length.toLocaleString()})," at qty 0",(0,l.jsx)("span",{className:"text-ink-faint",children:" (zeroed by the quota engine or a breaker â kept live so quantity can return without re-creating the listing)"})]})]}),(0,l.jsx)(ea.A,{rowData:n,columnDefs:N,height:"60vh",exportFileName:"listings",onRowClicked:e=>m(e),rowSelection:"multiple",onSelectionChanged:f,enableGrouping:!0,enablePivot:!0,enableCharts:!0})]}),p&&(0,l.jsx)(em,{listing:p,slug:t,onClose:()=>m(null),onChanged:async()=>{await w(),m(null)}})]})}function em(e){let{listing:t,slug:n,onClose:r,onChanged:i}=e,[c,u]=(0,s.useState)(null!=t.effective_price_cents?(t.effective_price_cents/100).toFixed(2):""),[h,p]=(0,s.useState)("until_released"),[m,x]=(0,s.useState)(""),[f,b]=(0,s.useState)(!1),[g,v]=(0,s.useState)(""),[_,j]=(0,s.useState)(""),[y,k]=(0,s.useState)(t.title||""),[w,N]=(0,s.useState)(""),[S,C]=(0,s.useState)(null),[R,A]=(0,s.useState)(!1);(0,s.useEffect)(()=>{A(!1),(0,a.apiGet)("/api/v1/resale/listings/".concat(t.id,"/events?client_slug=").concat(n)).then(e=>C(e.events)).catch(()=>{C([]),A(!0)})},[t.id,n]);let F=async(e,l)=>{b(!0),v("");try{await (0,a.apiPost)("/api/v1/resale/listings/".concat(t.id,"/").concat(e,"?client_slug=").concat(n),l),await i()}catch(e){v(e instanceof Error?e.message:"Something went wrong â try again."),b(!1)}},z=async(e,t)=>{await F("override",{field:e,value:t,channel_type:_||null,hold_mode:"until_released",reason:"manual ".concat(e," edit")})};return(0,l.jsx)(er.A,{title:(0,l.jsx)(l.Fragment,{children:t.title||t.listing_sku}),onClose:r,children:(0,l.jsxs)("div",{className:"space-y-5 text-sm",children:[(0,l.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,l.jsx)(ex,{label:"SKU",value:t.listing_sku}),(0,l.jsx)(ex,{label:"Condition",value:t.condition}),(0,l.jsx)(ex,{label:"In stock",value:String(t.quantity)}),(0,l.jsx)(ex,{label:"Rule price",value:ec(t.rule_price_cents)})]}),t.channel_states.length>0&&(0,l.jsxs)("div",{className:"rounded-lg border border-line p-3 space-y-2",children:[(0,l.jsx)("div",{className:"text-xs font-semibold text-ink",children:"On channels"}),t.channel_states.map(e=>(0,l.jsxs)("div",{className:"space-y-1",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(o.A,{status:e.status,colors:ei,label:ed(e)}),e.url&&(0,l.jsx)("a",{href:e.url,target:"_blank",rel:"noreferrer",className:"text-[12px] text-accent underline",children:"open"})]}),"pending"===e.status&&(0,l.jsx)("div",{className:"text-[12px] text-ink-faint",children:"The marketplace is still processing this item â the next sweep re-checks it."}),e.issues.length>0&&(0,l.jsx)("ul",{className:"text-[12px] text-bad list-disc pl-4 space-y-0.5",role:"alert",children:e.issues.map((e,t)=>(0,l.jsx)("li",{children:e},t))})]},e.channel_id))]}),t.overrides.length>0&&(0,l.jsxs)("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 p-3",children:[(0,l.jsx)("div",{className:"text-xs font-semibold text-amber-400 mb-1",children:"Active holds"}),t.overrides.map(e=>(0,l.jsxs)("div",{className:"text-[12px] text-ink-soft",children:[e.field,e.channel_type?" (".concat(e.channel_type,")"):""," \xb7 ",e.hold_mode.replace(/_/g," "),e.hold_until_at?" â ".concat(new Date(e.hold_until_at).toLocaleString()):""]},e.id))]}),(0,l.jsxs)("div",{className:"rounded-lg border border-line p-4 space-y-3",children:[(0,l.jsx)("div",{className:"font-semibold text-ink",children:"Hold a price"}),(0,l.jsx)("p",{className:"text-[12px] text-ink-faint",children:"Overrides the rule price (a promo may go below the floor). Rules wonât move it while held."}),(0,l.jsx)(d.D0,{label:"Price ($)",children:(0,l.jsx)(d.ks,{value:c,onChange:e=>u(e.target.value),placeholder:"0.00"})}),(0,l.jsx)(d.D0,{label:"Hold",children:(0,l.jsx)(d.l6,{value:h,onChange:e=>p(e.target.value),className:"w-full",children:eu.map(e=>(0,l.jsx)("option",{value:e.id,children:e.label},e.id))})}),"until_time"===h&&(0,l.jsx)(d.D0,{label:"Until",children:(0,l.jsx)(d.ks,{type:"datetime-local",value:m,onChange:e=>x(e.target.value)})}),g&&(0,l.jsx)("div",{className:"text-red-400 text-[12px]",children:g}),(0,l.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[(0,l.jsx)(el.A,{onClick:()=>{let e=Math.round(100*parseFloat(c));return!Number.isFinite(e)||e<=0?void v("Enter a valid price."):"until_time"!==h||m?void F("override",{field:"price",value:{cents:e},hold_mode:h,hold_until_at:"until_time"===h?new Date(m).toISOString():null,reason:"manual price hold"}):void v("Pick a date/time for a timed hold.")},disabled:f,children:"Hold price"}),(0,l.jsx)(el.A,{variant:"secondary",onClick:()=>F("override",{field:"paused",value:{},hold_mode:"until_released",reason:"manually paused"}),disabled:f,children:t.paused?"Re-pause":"Pause listing"}),t.overridden&&(0,l.jsx)(el.A,{variant:"secondary",onClick:()=>F("release"),disabled:f,children:"Release to rules"})]})]}),(0,l.jsxs)("div",{className:"rounded-lg border border-line p-4 space-y-3",children:[(0,l.jsx)("div",{className:"font-semibold text-ink",children:"Edit content"}),(0,l.jsx)("p",{className:"text-[12px] text-ink-faint",children:"Override the listingâs title or description â for one marketplace or all of them. Held until you release it."}),(0,l.jsx)(d.D0,{label:"Marketplace",children:(0,l.jsx)(d.l6,{value:_,onCh
1ange:e=>j(e.target.value),className:"w-full",children:eh.map(e=>(0,l.jsx)("option",{value:e.id,children:e.label},e.id))})}),(0,l.jsx)(d.D0,{label:"Title",children:(0,l.jsx)(d.ks,{value:y,onChange:e=>k(e.target.value)})}),(0,l.jsx)("div",{className:"flex justify-end",children:(0,l.jsx)(el.A,{variant:"secondary",onClick:()=>z("title",{text:y}),disabled:f||!y.trim(),children:"Hold title"})}),(0,l.jsx)(d.D0,{label:"Description (HTML)",children:(0,l.jsx)(d.fs,{value:w,onChange:e=>N(e.target.value),rows:4,placeholder:"<p>â¦</p>"})}),(0,l.jsx)("div",{className:"flex justify-end",children:(0,l.jsx)(el.A,{variant:"secondary",onClick:()=>z("description",{html:w}),disabled:f||!w.trim(),children:"Hold description"})})]}),(0,l.jsxs)("div",{className:"rounded-lg border border-line p-4",children:[(0,l.jsx)("div",{className:"font-semibold text-ink mb-2",children:"Pricing history"}),R?(0,l.jsx)("p",{role:"alert",className:"text-[12px] text-red-400 leading-relaxed",children:"The pricing history didn't load â the server returned an error. Close and reopen this listing to retry; if it persists, contact engineering with the tag [LISTINGS LEDGER]."}):null===S?(0,l.jsx)("p",{className:"text-[12px] text-ink-faint",children:"Loading historyâ¦"}):0===S.length?(0,l.jsx)("p",{className:"text-[12px] text-ink-faint",children:"No recorded events yet â the ledger began capturing on Aug 3, 2026; every publish, price change, and take-down lands here from now on."}):(0,l.jsx)("div",{className:"space-y-1.5 max-h-64 overflow-y-auto pr-1",children:S.map((e,t)=>{var n,s;return(0,l.jsxs)("div",{className:"flex items-baseline justify-between gap-3 text-[12px] border-b border-line/50 pb-1.5",children:[(0,l.jsxs)("div",{className:"min-w-0",children:[(0,l.jsx)("span",{className:"text-ink font-medium",children:e.event_type.replace(/_/g," ")}),"price_changed"===e.event_type&&null!=e.previous_price_cents&&(0,l.jsxs)("span",{className:"text-ink-soft ml-2",children:[ec(e.previous_price_cents)," â ",ec(e.price_cents),"number"==typeof(null==(n=e.meta)?void 0:n.urgency)&&(0,l.jsxs)("span",{className:"text-ink-faint",children:[" \xb7 window ",(100*Number(e.meta.urgency)).toFixed(0),"% elapsed"]})]}),"published"===e.event_type&&null!=e.price_cents&&(0,l.jsxs)("span",{className:"text-ink-soft ml-2",children:["at ",ec(e.price_cents),e.quantity?" \xb7 qty ".concat(e.quantity):""]}),"delisted"===e.event_type&&"string"==typeof(null==(s=e.meta)?void 0:s.reason)&&(0,l.jsx)("span",{className:"text-ink-faint ml-2 truncate",children:String(e.meta.reason).slice(0,80)})]}),(0,l.jsx)("span",{className:"text-ink-faint shrink-0",children:e.occurred_at?new Date(e.occurred_at).toLocaleString():""})]},t)})})]})]})})}function ex(e){let{label:t,value:n}=e;return(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-ink-faint",children:t}),(0,l.jsx)("div",{className:"text-ink",children:n})]})}var ef=n(52619),eb=n.n(ef);function eg(){let[e,t]=(0,s.useState)([]),[n,a]=(0,s.useState)(new Set),r=(0,s.useCallback)(()=>{t((0,i.dG)()),a(new Set)},[]);(0,s.useEffect)(()=>{r()},[r]);let o=e=>{Array.from(e).forEach(i.Tn),r()};return(0,l.jsxs)("div",{className:"rounded-xl bg-surface-100 border border-line p-6",children:[(0,l.jsx)("h3",{className:"font-display text-sm font-semibold text-ink mb-1",children:"Drafts"}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mb-4 max-w-2xl",children:"Unsaved edits autosaved from any form in the app â open one to pick up where you left off, or delete what you no longer need. Drafts live in this browser only (they are never sent to the server until you Save), so edits started on another device appear there, not here."}),0===e.length?(0,l.jsx)("p",{className:"text-sm text-ink-faint italic",children:"No drafts â everything you've edited has been saved or discarded."}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,l.jsxs)(el.A,{variant:"secondary",disabled:0===n.size,onClick:()=>o(n),children:["Delete selected (",n.size,")"]}),(0,l.jsxs)(el.A,{variant:"secondary",onClick:()=>o(e.map(e=>e.key)),children:["Delete all (",e.length,")"]})]}),(0,l.jsx)("div",{className:"rounded-lg border border-line divide-y divide-line",children:e.map(e=>(0,l.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3",children:[(0,l.jsx)("input",{type:"checkbox",checked:n.has(e.key),onChange:()=>{let t;return t=e.key,a(e=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n})},"aria-label":"Select draft ".concat(e.label),className:"accent-[var(--brand)]"}),(0,l.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,l.jsx)("div",{className:"text-sm text-ink truncate",children:e.label}),(0,l.jsx)("div",{className:"text-[11px] text-ink-faint",children:e.at?"Last edited ".concat((0,i.VX)(e.at)):"Age unknown"})]}),e.href?(0,l.jsx)(eb(),{href:e.href,className:"text-xs text-brand hover:underline shrink-0",children:"Open â"}):(0,l.jsx)("span",{className:"text-[11px] text-ink-faint shrink-0",children:"open its page to resume"}),(0,l.jsx)("button",{type:"button",onClick:()=>o([e.key]),className:"text-xs text-ink-faint hover:text-bad shrink-0 px-1",children:"Delete"})]},e.key))})]})]})}let ev={approve:"Auto-approve (label right away)",review:"Hold for a manager (Needs approval)",decline:"Auto-decline"},e_={number:[{op:">",label:"is above"},{op:"<",label:"is below"},{op:">=",label:"is at least"},{op:"<=",label:"is at most"},{op:"==",label:"is exactly"},{op:"!=",label:"is not"}],enum:[{op:"in",label:"is one of"},{op:"not_in",label:"is none of"}],bool:[{op:"==",label:"is"}],text:[{op:"==",label:"is"},{op:"!=",label:"is not"},{op:"in",label:"is one of"}]};function ej(e){return"string"==typeof e?e:e.value}function ey(e){var t;let{config:n,fields:a,onSave:r,saving:i}
1=e,[o,c]=(0,s.useState)(n.rules),[u,h]=(0,s.useState)(n.default_action),[p,m]=(0,s.useState)(null!=(t=n.notify_email)?t:""),[x,f]=(0,s.useState)([]);(0,s.useEffect)(()=>{var e;c(n.rules),h(n.default_action),m(null!=(e=n.notify_email)?e:""),f([])},[n]);let b=(0,s.useMemo)(()=>{var e;return JSON.stringify({rules:o,defaultAction:u,notifyEmail:p})!==JSON.stringify({rules:n.rules,defaultAction:n.default_action,notifyEmail:null!=(e=n.notify_email)?e:""})},[o,u,p,n]),g=e=>a.find(t=>t.field===e),v=(e,t)=>c(n=>n.map((n,l)=>l===e?{...n,...t}:n)),_=(e,t,n)=>c(l=>l.map((l,s)=>s===e?{...l,conditions:l.conditions.map((e,l)=>l===t?{...e,...n}:e)}:l)),j=(e,t)=>c(n=>{let l=[...n],s=e+t;return s<0||s>=l.length?n:([l[e],l[s]]=[l[s],l[e]],l)}),y=o.some(e=>e.enabled&&e.conditions.some(e=>"photo_verdict"===e.field)),k={approve:"auto-approve",review:"hold for a manager",decline:"auto-decline"};return(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("div",{className:"rounded-xl bg-surface-100 border border-line p-4 space-y-1",children:[(0,l.jsx)("p",{className:"text-xs text-ink-faint m-0",children:"Every return the portal confirms runs through these rules, top to bottom â the first rule whose conditions all match decides. A return that matches nothing takes the default action below. There is no hidden policy: what you see here is exactly what happens."}),(0,l.jsxs)("p",{className:"text-xs text-ink-faint m-0",children:[(0,l.jsx)("span",{className:"text-ink font-medium",children:"Approve"})," = the shipper gets the label right away \xb7"," ",(0,l.jsx)("span",{className:"text-ink font-medium",children:"Hold for a manager"})," = it lands in Returns â Needs approval (the shopper is told the label follows by email) \xb7"," ",(0,l.jsx)("span",{className:"text-ink font-medium",children:"Decline"})," = the shopper is told to contact the store."]})]}),(0,l.jsxs)("div",{className:"rounded-xl border border-brand/30 bg-brand/5 p-4",children:[(0,l.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-ink-soft font-medium mb-1",children:"In plain words"}),(0,l.jsx)("p",{className:"text-sm text-ink m-0",children:0===o.filter(e=>e.enabled).length?"Every return will ".concat(k[u],"."):"Returns will "+o.filter(e=>e.enabled).map(e=>"".concat(k[e.action]," when ").concat(e.conditions.map(e=>(function(e,t){var n,l,s;let a=t.find(t=>t.field===e.field),r=null!=(l=null==(n=(a?e_[a.kind]:[]).find(t=>t.op===e.operator))?void 0:n.label)?l:e.operator,i=Array.isArray(e.value)?e.value.map(String).join(", "):String(e.value);return"".concat(null!=(s=null==a?void 0:a.label)?s:e.field," ").concat(r," ").concat(i)})(e,a)).join(" and "))).join("; ")+"; everything else will ".concat(k[u],".")}),y&&(0,l.jsx)("p",{className:"text-xs text-ink-faint mt-2 mb-0",children:"Because a rule looks at the photo check, a return with uploaded photos waits for the check (usually under a minute) before its label is released â the shopper is told that on screen and gets the label by email."})]}),x.length>0&&(0,l.jsxs)("div",{role:"alert",className:"rounded-xl border border-bad/40 bg-bad/10 p-4",children:[(0,l.jsx)("p",{className:"text-sm font-medium text-bad mb-1",children:"These rules can't be saved yet:"}),(0,l.jsx)("ul",{className:"list-disc pl-5 space-y-0.5",children:x.map((e,t)=>(0,l.jsx)("li",{className:"text-xs text-bad",children:e},t))})]}),o.map((e,t)=>(0,l.jsxs)("div",{className:"rounded-xl bg-surface-100 border border-line p-5 ".concat(e.enabled?"":"opacity-60"),children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-3 mb-4",children:[(0,l.jsxs)("span",{className:"text-xs font-mono text-ink-faint w-6",children:["#",t+1]}),(0,l.jsx)(d.ks,{value:e.name,placeholder:"Name this rule (shown to reviewers as the reason)",onChange:e=>v(t,{name:e.target.value}),className:"flex-1 min-w-[220px] text-sm"}),(0,l.jsx)(q.A,{checked:e.enabled,onChange:e=>v(t,{enabled:e}),ariaLabel:"Rule ".concat(t+1," on or off")}),(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[(0,l.jsx)(el.A,{size:"sm",variant:"ghost",onClick:()=>j(t,-1),disabled:0===t,"aria-label":"Move up",children:"â"}),(0,l.jsx)(el.A,{size:"sm",variant:"ghost",onClick:()=>j(t,1),disabled:t===o.length-1,"aria-label":"Move down",children:"â"}),(0,l.jsx)(el.A,{size:"sm",variant:"danger",onClick:()=>c(e=>
1e.filter((e,n)=>n!==t)),children:"Remove"})]})]}),(0,l.jsxs)("div",{className:"space-y-2 mb-4",children:[e.conditions.map((n,s)=>{var r,i,o,c;let u=g(n.field),h=u?e_[u.kind]:[];return(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,l.jsx)("span",{className:"text-xs text-ink-faint w-10",children:0===s?"When":"and"}),(0,l.jsx)(d.l6,{value:n.field,onChange:e=>((e,t,n)=>{let l=g(n);if(!l)return;let s=e_[l.kind][0].op,a="";"number"===l.kind&&(a=0),"bool"===l.kind&&(a=!0),"enum"===l.kind&&(a=l.options&&l.options.length?[ej(l.options[0])]:[]),_(e,t,{field:n,operator:s,value:a})})(t,s,e.target.value),className:"text-sm min-w-[220px]",children:a.map(e=>(0,l.jsx)("option",{value:e.field,children:e.label},e.field))}),(0,l.jsx)(d.l6,{value:n.operator,onChange:e=>_(t,s,{operator:e.target.value}),className:"text-sm",children:h.map(e=>(0,l.jsx)("option",{value:e.op,children:e.label},e.op))}),(null==u?void 0:u.kind)==="number"&&(0,l.jsx)(d.ks,{type:"number",step:"any",value:String(null!=(r=n.value)?r:""),onChange:e=>_(t,s,{value:e.target.value}),className:"w-28 text-sm font-mono"}),(null==u?void 0:u.kind)==="bool"&&(0,l.jsxs)(d.l6,{value:String(n.value),onChange:e=>_(t,s,{value:"true"===e.target.value}),className:"text-sm",children:[(0,l.jsx)("option",{value:"true",children:"yes"}),(0,l.jsx)("option",{value:"false",children:"no"})]}),(null==u?void 0:u.kind)==="text"&&(0,l.jsx)(d.ks,{value:Array.isArray(n.value)?n.value.join(", "):String(null!=(i=n.value)?i:""),placeholder:"in"===n.operator?"Electronics, Jewelry":"Electronics",onChange:e=>_(t,s,{value:e.target.value}),className:"flex-1 min-w-[160px] text-sm"}),(null==u?void 0:u.kind)==="enum"&&(0,l.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[0===(null!=(o=u.options)?o:[]).length&&(0,l.jsx)("span",{className:"text-xs text-ink-faint",children:"No options configured for this client yet."}),(null!=(c=u.options)?c:[]).map(e=>{let a=ej(e),r=Array.isArray(n.value)&&n.value.includes(a);return(0,l.jsx)("button",{type:"button",onClick:()=>{let e=Array.isArray(n.value)?[...n.value]:[];_(t,s,{value:r?e.filter(e=>e!==a):[...e,a]})},className:"px-2 py-0.5 rounded-full text-xs border ".concat(r?"bg-brand text-white border-brand":"bg-hovertint text-ink-soft border-line hover:border-brand/50"),children:"string"==typeof e?e.replace(/_/g," "):e.label},a)})]}),(0,l.jsx)(el.A,{size:"sm",variant:"ghost",disabled:1===e.conditions.length,onClick:()=>v(t,{conditions:e.conditions.filter((e,t)=>t!==s)}),"aria-label":"Remove condition",children:"\xd7"})]},s)}),(0,l.jsx)(el.A,{size:"sm",variant:"secondary",onClick:()=>v(t,{conditions:[...e.conditions,{field:"return_value",operator:">",value:100}]}),children:"+ andâ¦"})]}),(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,l.jsx)("span",{className:"text-xs text-ink-faint w-10",children:"Then"}),(0,l.jsx)(d.l6,{value:e.action,onChange:e=>v(t,{action:e.target.value}),className:"text-sm",children:Object.keys(ev).map(e=>(0,l.jsx)("option",{value:e,children:ev[e]},e))})]})]},e.id)),(0,l.jsx)(el.A,{variant:"secondary",onClick:()=>c(e=>{var t;return[...e,(t=e.length+1,{id:"rule_".concat(Date.now().toString(36)),name:"Rule ".concat(t),enabled:!0,action:"review",conditions:[{field:"return_value",operator:">",value:300}]})]}),children:"+ Add a rule"}),(0,l.jsxs)("div",{className:"rounded-xl bg-surface-100 border border-line p-5 grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"If no rule matches"}),(0,l.jsx)(d.l6,{value:u,onChange:e=>h(e.target.value),className:"w-full text-sm",children:Object.keys(ev).map(e=>(0,l.jsx)("option",{value:e,children:ev[e]},e))})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Email a reviewer when a return is held or declined (optional)"}),(0,l.jsx)(d.ks,{type:"email",value:p,placeholder:"[email protected]",onChange:e=>m(e.target.value),className:"w-full text-sm"})]})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)(el.A,{variant:"ghost",onClick:()=>{var e;c(n.rules),h(n.default_action),m(null!=(e=n.notify_email)?e:""),f([])},disabled:!b||i,children:"Discard changes"}),(0,l.jsx)(el.A,{onClick:()=>{let e=(()=>{let e=[];return o.forEach((t,n)=>{let l=t.name.trim()||"Rule ".concat(n+1);t.name.trim()||e.push("Rule ".concat(n+1,": give it a name.")),0===t.conditions.length&&e.push("".concat(l,": add at least one condition.")),t.conditions.forEach(t=>{var n;let s=g(t.field);s?"number"===s.kind&&(""===t.value||Number.isNaN(Number(t.value)))?e.push("".concat(l,': "').concat(s.label,'" needs a number.')):"enum"!==s.kind||Array.isArray(t.value)&&0!==t.value.length?"text"===s.kind&&""===String(null!=(n=t.value)?n:"").trim()&&e.push("".concat(l,': "').concat(s.label,'" needs a value.')):e.push("".concat(l,': pick at least one value for "').concat(s.label,'".')):e.push("".concat(l,": a condition uses an unknown field."))})}),p.trim()&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p.trim())&&e.push("The notification email doesn't look like an email address."),e})();if(f(e),e.length)return;let t=o.map(e=>({...e,name:e.name.trim(),conditions:e.conditions.map(e=>{let t=g(e.field),n=e.value;return(null==t?void 0:t.kind)==="number"&&(n=Number(e.value)),(null==t?void 0:t.kind)==="text"&&"in"===e.operator&&(n=String(e.value).split(",").map(e=>
1e.trim()).filter(Boolean)),{field:e.field,operator:e.operator,value:n}})}));r({decision_config:{version:2,default_action:u,notify_email:p.trim()||null,rules:t}})},disabled:i,children:i?"Savingâ¦":"Save changes"})]})]})}let ek={track:{enabled:!0,title:"Track my order",subtitle:"See your delivery status and shipment updates"},return:{enabled:!0,title:"Return or exchange",subtitle:"Start a return, swap for a different size, or exchange for store credit"},report:{enabled:!0,title:"Report a problem",subtitle:"Wrong item, damaged goods, missing package, or anything else"},history:{enabled:!0,title:"Return history",subtitle:"View the status of past returns and exchanges"}},ew=(0,s.createContext)(null),eN=[{id:"builder",label:"Return Portal"},{id:"branding",label:"Branding"},{id:"fees",label:"Return Fees"},{id:"keep",label:"Keep-the-Item"},{id:"decisions",label:"Return Decisions"},{id:"guardrails",label:"Resolution Options"},{id:"photos",label:"Photo Requirements"},{id:"reminders",label:"Return Reminders"},{id:"presell",label:"Listing Rules"},{id:"listings",label:"Live Listings"},{id:"drafts",label:"Drafts"}];function eS(){let{activeInstance:e}=(0,r.z8)(),[t,n]=(0,s.useState)(null),[i,o]=(0,s.useState)(!0),[d,c]=(0,s.useState)("builder"),[u,h]=(0,s.useState)(!1),[p,m]=(0,s.useState)(""),[x,f]=(0,s.useState)(0),b=(0,s.useCallback)(()=>{try{let e=[];for(let t=0;t<window.localStorage.length;t++){let n=window.localStorage.key(t);n&&n.startsWith("rerere.draft.rules.")&&e.push(n)}e.forEach(e=>window.localStorage.removeItem(e))}catch(e){}f(e=>e+1),m("Changes discarded"),setTimeout(()=>m(""),2e3)},[]),g=(0,s.useCallback)(async()=>{if(!e)return void o(!1);o(!0);try{n(await (0,a.apiGet)("/api/v1/rules/config?client_slug=".concat(e)))}catch(e){console.error("Failed to fetch rules config:",e)}o(!1)},[e]);(0,s.useEffect)(()=>{g()},[g]);let v=async n=>{if(t&&e){h(!0),m("");try{await (0,a.apiPut)("/api/v1/rules/config?client_slug=".concat(e),n),m("Saved"),setTimeout(()=>m(""),2e3),g()}catch(e){m("Error saving")}h(!1)}},_=async t=>{if(e){m("");try{await (0,a.apiPut)("/api/v1/rules/presell-enabled?client_slug=".concat(e),{enabled:t}),m("Saved"),setTimeout(()=>m(""),2e3),g()}catch(e){m("Error saving")}}},j=async(t,n)=>{if(e){m("");try{await (0,a.apiPut)("/api/v1/rules/engine-flag?client_slug=".concat(e),{flag:t,enabled:n}),m("Saved"),setTimeout(()=>m(""),2e3),g()}catch(e){m("Error saving")}}};return e?i||!t?(0,l.jsx)("div",{className:"flex items-center justify-center py-20",children:(0,l.jsx)(es.default,{})}):(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h1",{className:"font-display text-2xl font-semibold text-ink mb-1",children:"Rules & Workflows"}),(0,l.jsxs)("p",{className:"text-ink-faint text-sm",children:["Configure prediction, pricing, and policy rules for ",t.client_name]})]}),p&&(0,l.jsx)("span",{className:"text-sm font-medium ".concat("Error saving"===p?"text-bad":"text-good"),children:p})]}),(0,l.jsx)("div",{className:"flex gap-1 mb-6 border-b border-line overflow-x-auto",children:eN.map(e=>(0,l.jsx)("button",{onClick:()=>c(e.id),className:"px-4 py-2.5 text-sm font-medium whitespace-nowrap transition-colors border-b-2 -mb-px ".concat(d===e.id?"text-brand border-brand":"text-ink-faint border-transparent hover:text-ink-soft"),children:e.label},e.id))}),(0,l.jsx)(ew.Provider,{value:b,children:(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{className:"builder"===d?"":"hidden",children:(0,l.jsx)(W,{initial:function(e){var t,n,l,s,a,r,i,o,d,c,u,h,p,m,x,f,b,g,v,_,j,y,k,w,N,S,C,R,A,F,z,D,T,E,B,P,O,M,I,W,q,L,H,U;let $=e.portal_config||{},K=e.outcome_config||{},G=(e.return_policy.return_reasons||[]).map(e=>"string"==typeof e?{id:e,label:e.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase()),enabled:!0,resale_eligible:!0,photo_required:!1,allowed_outcomes:["refund","exchange","store_credit"],follow_up:null,fee_override_cents:null}:e),J={refund:{enabled:null==(j=null==(t=K.refund)?void 0:t.enabled)||j,fee_cents_override:null!=(y=null==(n=K.refund)?void 0:n.fee_cents_override)?y:null,bonus_cents:null!=(k=null==(l=K.refund)?void 0:l.bonus_cents)?k:0,label:null!=(w=null==(s=K.refund)?void 0:s.label)?w:"Refund to original payment"},exchange:{enabled:null==(N=null==(a=K.exchange)?void 0:a.enabled)||N,fee_cents_override:null!=(S=null==(r=K.exchange)?void 0:r.fee_cents_override)?S:0,bonus_cents:null!=(C=null==(i=K.exchange)?void 0:i.bonus_cents)?C:0,label:null!=(R=null==(o=K.exchange)?void 0:o.label)?R:"Exchange for a different size or color"},store_credit:{enabled:null==(A=null==(d=K.store_credit)?void 0:d.enabled)||A,fee_cents_override:null!=(F=null==(c=K.store_credit)?void 0:c.fee_cents_override)?F:0,bonus_cents:null!=(z=null==(u=K.store_credit)?void 0:u.bonus_cents)?z:500,label:null!=(D=null==(h=K.store_credit)?void 0:h.label)?D:"Store credit + $5 bonus"},keep_item:{enabled:null==(T=null==(p=K.keep_item)?void 0:p.enabled)||T,fee_cents_override:null!=(E=null==(m=K.keep_item)?void 0:m.fee_cents_override)?E:0,bonus_cents:null!=(B=null==(x=K.keep_item)?void 0:x.bonus_cents)?B:0,label:null!=(P=null==(f=K.keep_item)?void 0:f.label)?P:"Keep the item"}},V={photo_gate_position:null!=(O=$.photo_gate_position)?O:"with_reason",screen_order:null!=(M=$.screen_order)?M:["lookup","hub","items","outcome","review","done"],show_customer_score:null!=(I=$.show_customer_score)&&I,show_presold_messaging:null!=(W=$.show_presold_messaging)&&W,csat_enabled:null==(q=$.csat_enabled)||q,cancel_before_ship_enabled:null==(L=$.cancel_before_ship_enabled)||L,custom_copy:null!=(H=$.custom_copy)?H:{},hub_cards:{track:{...ek.track,...(null==(b=$.hub_cards)?void 0:b.track)||{}},return:{...ek.return,...(null==(g=$.hub_cards)?void 0:g.return)||{}},report:{...ek.report,...(null==(v=$.hub_cards)?void 0:v.report)||{}},history:{...ek.history,...(null==(_=$.hub_cards)?void 0:_.history)||{}}}};return{return_window_days:null!=(U=e.return_policy.return_window_days)?U:30,return_reasons:G,outcome_config:J,portal_config:V,branding:e.branding||{}}}(t),onSave:e=>v({return_policy:{...t.return_policy,return_window_days:e.return_window_days,return_reasons:e.return_reasons},outcome_config:e.outcome_config,portal_config:e.portal_config}),saving:u},"".concat(t.client_slug,"-").concat(JSON.stringify(t.portal_config).length))}),(0,l.jsx)("div",{className:"fees"===d?"":"hidden",children:(0,l.jsx)(eD,{config:t,onSave:v,saving:u})}),(0,l.jsx)("div",{className:"keep"===d?"":"hidden",children:(0,l.jsx)(eE,{config:t,onSave:v,saving:u})}),(0,l.jsx)("div",{className:"decisions"===d?"":"hidden",children:(0,l.jsx)(ey,{config:t.decision_config,fields:t.decision_fields,onSave:v,saving:u})}),(0,l.jsx)("div",{className:"guardrails"===d?"":"hidden",children:(0,l.jsx)(eO,{config:t,onSave:v,saving:u})}),(0,l.jsx)("div",{className:"photos"===d?"":"hidden",children:(0,l.jsx)(eM,{config:t,onSave:v,saving:u})}),(0,l.jsx)("div",{className:"reminders"===d?"":"hidden",children:(0,l.jsx)(eT,{config:t,onSave:v,saving:u})}),(0,l.jsx)("div",{className:"presell"===d?"":"hidden",children:(0,l.jsx)(en,{config:t,onSave:v,saving:u,presellEnabled:t.presell_enabled,canToggleEnabled:t.presell_can_toggle,onToggleEnabled:_,onToggleFeatureFlag:j})}),(0,l.jsx)("div",{className:"listings"===d?"":"hidden",children:(0,l.jsx)(ep,{slug:e})}),(0,l.jsx)("div",{className:"branding"===d?"":"hidden",children:(0,l.jsx)(eI,{config:t,onSave:v,saving:u})}),"drafts"===d&&(0,l.jsx)("div",{children:(0,l.jsx)(eg,{})})]},x)})]}):(0,l.jsx)("p",{className:"text-sm text-ink-soft px-6 py-20 text-center",children:"Select a client instance (top bar) to edit its rules."})}function eC(e){let{title:t,children:n}=e;return(0,l.jsxs)("div",{className:"rounded-xl bg-surface-100 border border-line p-6",children:[(0,l.jsx)("h3",{className:"font-display text-sm font-semibold text-ink mb-4",children:t}),n]})}function eR(e){let{label:t,checked:n,onChange:s}=e;return(0,l.jsxs)("button",{onClick:()=>s(!n),className:"flex items-center gap-3",children:[(0,l.jsx)("div",{className:"w-9 h-5 rounded-full transition-colors relative ".concat(n?"bg-brand":"bg-hovertint"),children:(0,l.jsx)("div",{className:"w-4 h-4 absolute top-0.5 rounded-full bg-white shadow transition-all ".concat(n?"left-[18px]":"left-0.5")})}),(0,l.jsx)("span",{className:"text-sm text-ink-soft",children:t})]})}function eA(e){let{label:t,value:n,onChange:s,prefix:a,type:r="number",step:i}=e;return(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:t}),(0,l.jsxs)("div",{className:"flex items-center gap-1",children:[a&&(0,l.jsx)("span",{className:"text-ink-faint text-sm",children:a}),(0,l.jsx)(d.ks,{type:r,step:i||"0.01",value:n,onChange:e=>s(Number(e.target.value)),className:"w-full text-sm font-mono"})]})]})}function eF(e){let{onClick:t,saving:n,dirty:a}=e,r=(0,s.useContext)(ew);return(0,l.jsxs)("div",{className:"flex justify-between items-center gap-3",children:[(0,l.jsx)("div",{children:r&&(0,l.jsx)("button",{onClick:r,disabled:n||!1===a,title:!1===a?"Nothing to discard":"Throw away the edits on this page and go back to the last saved settings",className:"px-4 py-2 rounded-lg border border-line text-ink-soft text-sm font-medium hover:text-bad hover:border-bad/50 disabled:opacity-40 transition-colors",children:"Discard changes"})}),(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[a&&(0,l.jsx)(o.A,{status:"unsaved",label:"Unsaved changes",colors:{unsaved:"#f59e0b"}}),(0,l.jsx)("button",{onClick:t,disabled:n,className:"px-6 py-2 rounded-lg bg-brand text-white text-sm font-medium hover:bg-brand/80 disabled:opacity-50 transition-colors",children:n?"Saving...":"Save Changes"})]})]})}function ez(e){let{at:t,onRestore:n,onDiscard:s}=e;return(0,l.jsxs)("div",{className:"p-3 rounded-xl bg-hovertint border border-line flex items-center justify-between gap-3 flex-wrap",children:[(0,l.jsxs)("span",{className:"text-xs text-ink",children:["You have unsaved changes from ",(0,i.VX)(t)," â they were never sent to the server. Restore them, or discard and keep what is saved."]}),(0,l.jsxs)("span",{className:"flex gap-2 shrink-0",children:[(0,l.jsx)("button",{onClick:n,className:"text-xs text-brand hover:text-brand/80 font-medium",children:"Restore draft"}),(0,l.jsx)("button",{onClick:s,className:"text-xs text-ink-faint hover:text-bad font-medium",children:"Discard"})]})]})}
1function eD(e){let{config:t,onSave:n,saving:a}=e,o=t.fee_config,[c,u]=(0,s.useState)(o.score_bands||[]),[h,p]=(0,s.useState)(o.min_fee),[m,x]=(0,s.useState)(o.max_fee),[f,b]=(0,s.useState)(o.free_return_threshold),[g,v]=(0,s.useState)(o.fee_waive_reasons||[]),{activeInstance:_}=(0,r.z8)(),j=(0,s.useMemo)(()=>({bands:c,minFee:h,maxFee:m,freeThreshold:f,waiveReasons:g}),[c,h,m,f,g]),y=(0,s.useMemo)(()=>({bands:o.score_bands||[],minFee:o.min_fee,maxFee:o.max_fee,freeThreshold:o.free_return_threshold,waiveReasons:o.fee_waive_reasons||[]}),[o]),k=(0,i.RC)({storageKey:"rules.fees.".concat(_||"default"),value:j,baseline:y,meta:{label:"Return Fees â ".concat(_||"client"),href:"/rules"}});return(0,l.jsxs)("div",{className:"space-y-6",children:[k.hasStoredDraft&&(0,l.jsx)(ez,{at:k.storedDraftAt,onRestore:()=>{let e=k.restoreDraft();e&&(u(e.bands),p(e.minFee),x(e.maxFee),b(e.freeThreshold),v(e.waiveReasons))},onDiscard:k.discardDraft}),(0,l.jsx)(eC,{title:"Fee Range",children:(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,l.jsx)(eA,{label:"Minimum Fee",value:h,onChange:p,prefix:"$"}),(0,l.jsx)(eA,{label:"Maximum Fee",value:m,onChange:x,prefix:"$"}),(0,l.jsx)(eA,{label:"Free Return Threshold (score)",value:f,onChange:b})]})}),(0,l.jsxs)(eC,{title:"Score-Based Fee Bands",children:[(0,l.jsx)("p",{className:"text-xs text-ink-faint mb-4",children:"Customers with scores at or above the threshold pay the listed fee."}),(0,l.jsxs)("div",{className:"space-y-2",children:[c.map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-hovertint border border-line",children:[(0,l.jsx)("span",{className:"text-xs text-ink-faint w-16",children:"Score â¥"}),(0,l.jsx)(d.ks,{type:"number",step:"0.5",value:e.min_score,onChange:e=>{let n=[...c];n[t]={...n[t],min_score:Number(e.target.value)},u(n)},className:"w-20 text-sm font-mono"}),(0,l.jsx)("span",{className:"text-xs text-ink-faint",children:"Fee: $"}),(0,l.jsx)(d.ks,{type:"number",step:"0.01",value:e.fee,onChange:e=>{let n=[...c];n[t]={...n[t],fee:Number(e.target.value)},u(n)},className:"w-20 text-sm font-mono"}),(0,l.jsx)("button",{onClick:()=>u(c.filter((e,n)=>n!==t)),className:"ml-auto text-ink-faint hover:text-bad text-xs",children:"Remove"})]},t)),(0,l.jsx)("button",{onClick:()=>u([...c,{min_score:0,fee:9.99}]),className:"text-xs text-brand hover:text-brand/80 font-medium",children:"+ Add Band"})]})]}),(0,l.jsx)(eC,{title:"Fee Waiver Reasons",children:(0,l.jsx)("div",{className:"flex gap-3",children:["defective","wrong_item","damaged_in_shipping"].map(e=>{let t=g.includes(e);return(0,l.jsx)("button",{onClick:()=>v(t?g.filter(t=>t!==e):[...g,e]),className:"px-3 py-2 rounded-lg text-xs font-medium border transition-colors ".concat(t?"bg-good-bg border-good text-good":"bg-hovertint border-line text-ink-faint hover:text-ink-soft"),children:e.replace(/_/g," ")},e)})})}),(0,l.jsx)(eF,{onClick:()=>n({fee_config:{...o,min_fee:h,max_fee:m,free_return_threshold:f,fee_waive_reasons:g,score_bands:c.sort((e,t)=>t.min_score-e.min_score)}}),saving:a,dirty:k.isDirty})]})}function eT(e){var t,n;let{config:a,onSave:o,saving:c}
1=e,u=a.return_policy,[h,p]=(0,s.useState)(!!u.reminder_enabled),[m,x]=(0,s.useState)(null!=(t=u.rma_valid_days)?t:30),[f,b]=(0,s.useState)(null!=(n=u.reminder_days)?n:[]),{activeInstance:g}=(0,r.z8)(),v=(0,s.useMemo)(()=>({enabled:h,validDays:m,days:f}),[h,m,f]),_=(0,s.useMemo)(()=>{var e,t;return{enabled:!!u.reminder_enabled,validDays:null!=(e=u.rma_valid_days)?e:30,days:null!=(t=u.reminder_days)?t:[]}},[u]),j=(0,i.RC)({storageKey:"rules.reminders.".concat(g||"default"),value:v,baseline:_,meta:{label:"Return Reminders â ".concat(g||"client"),href:"/rules"}}),y=[...f].sort((e,t)=>e-t),k=y.filter(e=>e>=m),w=y.filter(e=>e>0&&e<m);return(0,l.jsxs)("div",{className:"space-y-6",children:[j.hasStoredDraft&&(0,l.jsx)(ez,{at:j.storedDraftAt,onRestore:()=>{let e=j.restoreDraft();e&&(p(e.enabled),x(e.validDays),b(e.days))},onDiscard:j.discardDraft}),(0,l.jsxs)(eC,{title:"Return Reminders",children:[(0,l.jsx)(eR,{label:"Send return reminders",checked:h,onChange:p}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mt-2 mb-4",children:"Nudges a shopper who started a return but hasn't posted it back yet. Off by default â nothing is sent until you turn this on and add at least one nudge day."}),(0,l.jsxs)("div",{className:"mb-5",children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-ink-soft mb-1",children:"How long is an RMA valid once started?"}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(d.ks,{type:"number",min:"1",step:"1",value:m,onChange:e=>x(Math.max(1,Number(e.target.value)||1)),className:"w-24 text-xs font-mono"}),(0,l.jsx)("span",{className:"text-xs text-ink-faint",children:"days from when the return is started"})]}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mt-1",children:"After this, the shopper has to contact support for a new RMA â so we stop nudging them."})]}),h&&(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-xs font-medium text-ink-soft mb-2",children:"Nudge the shopper on these days"}),(0,l.jsx)("div",{className:"space-y-2",children:f.map((e,t)=>(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("span",{className:"text-[10px] text-ink-faint font-mono w-12",children:"Day"}),(0,l.jsx)(d.ks,{type:"number",min:"1",step:"1",value:e,onChange:e=>{let n=[...f];n[t]=Math.max(1,Number(e.target.value)||1),b(n)},className:"w-24 text-xs font-mono"}),e>=m&&(0,l.jsx)("span",{className:"text-[11px] text-bad",children:"after the RMA expires â won't send"}),(0,l.jsx)("button",{onClick:()=>b(f.filter((e,n)=>n!==t)),className:"text-ink-faint hover:text-bad text-xs",children:"x"})]},t))}),(0,l.jsx)("button",{onClick:()=>b([...f,Math.min(m-1,(f.length?Math.max(...f):0)+7)||7]),className:"text-[10px] text-brand hover:text-brand/80 font-medium mt-2",children:"+ Add another nudge"}),(0,l.jsxs)("p",{className:"text-xs text-ink-faint mt-4",children:[0===w.length?"No nudges will send â add at least one day inside the RMA window.":"Sends on day ".concat(w.join(", ")," â ").concat(w.length," nudge").concat(1===w.length?"":"s",", then the window closes on day ").concat(m,"."),k.length>0&&" Day ".concat(k.join(", ")," will be ignored (at or past expiry).")]}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mt-1",children:"If several are overdue at once we send only the most recent one, never a burst."})]})]}),(0,l.jsx)(eF,{onClick:()=>o({return_policy:{...a.return_policy,reminder_enabled:h,rma_valid_days:m,reminder_days:w}}),saving:c,dirty:j.isDirty})]})}function eE(e){let{config:t,onSave:n,saving:a}=e,{activeInstance:c}
1=(0,r.z8)(),u=t.keep_item_rules,[h,p]=(0,s.useState)(u.enabled),[m,x]=(0,s.useState)(u.rules||[]),f=(0,s.useMemo)(()=>({enabled:h,rules:m}),[h,m]),b=(0,s.useMemo)(()=>({enabled:u.enabled,rules:u.rules||[]}),[u]),g=(0,i.RC)({storageKey:"rules.keepItem.".concat(c||"default"),value:f,baseline:b,meta:{label:"Keep-the-Item â ".concat(c||"client"),href:"/rules"}}),v=["customer_score","item_cost","return_shipping_ratio","estimated_shipping_cost"],_=[">","<",">=","<=","==","!="];return(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)(eC,{title:"Keep-Item Policy",children:[g.hasStoredDraft&&(0,l.jsxs)("div",{className:"mb-4 p-3 rounded-xl bg-hovertint border border-line flex items-center justify-between gap-3 flex-wrap",children:[(0,l.jsxs)("span",{className:"text-xs text-ink",children:["You have unsaved keep-item changes from ",(0,i.VX)(g.storedDraftAt),". They were never sent to the server â restore them, or discard and keep what is saved."]}),(0,l.jsxs)("span",{className:"flex gap-2 shrink-0",children:[(0,l.jsx)("button",{onClick:()=>{let e=g.restoreDraft();e&&(p(e.enabled),x(e.rules))},className:"text-xs text-brand hover:text-brand/80 font-medium",children:"Restore draft"}),(0,l.jsx)("button",{onClick:g.discardDraft,className:"text-xs text-ink-faint hover:text-bad font-medium",children:"Discard"})]})]}),g.isDirty&&(0,l.jsx)("div",{className:"mb-3",children:(0,l.jsx)(o.A,{status:"unsaved",label:"Unsaved changes",colors:{unsaved:"#f59e0b"}})}),(0,l.jsx)(eR,{label:"Enable Keep-Item Rules",checked:h,onChange:p}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mt-2 mb-4",children:"When enabled, qualifying items are kept by the customer instead of returned. Rules use OR logic; conditions within a rule use AND."}),h&&(0,l.jsxs)("div",{className:"space-y-4",children:[m.map((e,t)=>(0,l.jsxs)("div",{className:"p-4 rounded-xl bg-hovertint border border-line",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,l.jsx)(d.ks,{value:e.name,onChange:e=>{let n=[...m];n[t]={...n[t],name:e.target.value},x(n)},className:"text-sm font-medium"}),(0,l.jsx)("button",{onClick:()=>x(m.filter((e,n)=>n!==t)),className:"text-xs text-ink-faint hover:text-bad",children:"Remove Rule"})]}),e.conditions.map((e,n)=>(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[n>0?(0,l.jsx)("span",{className:"text-[10px] text-ink-faint font-mono w-8",children:"AND"}):(0,l.jsx)("span",{className:"w-8"}),(0,l.jsx)(d.l6,{value:e.field,onChange:l=>{let s=[...m];s[t].conditions[n]={...e,field:l.target.value},x(s)},className:"text-xs",children:v.map(e=>(0,l.jsx)("option",{value:e,children:e},e))}),(0,l.jsx)(d.l6,{value:e.operator,onChange:l=>{let s=[...m];s[t].conditions[n]={...e,operator:l.target.value},x(s)},className:"text-xs font-mono",children:_.map(e=>(0,l.jsx)("option",{value:e,children:e},e))}),(0,l.jsx)(d.ks,{type:"number",step:"0.01",value:e.value,onChange:l=>{let s=[...m];s[t].conditions[n]={...e,value:Number(l.target.value)},x(s)},className:"w-24 text-xs font-mono"}),(0,l.jsx)("button",{onClick:()=>{let e=[...m];e[t].conditions=e[t].conditions.filter((e,t)=>t!==n),x(e)},className:"text-ink-faint hover:text-bad text-xs",children:"x"})]},n)),(0,l.jsx)("button",{onClick:()=>{let e=[...m];e[t].conditions.push({field:"customer_score",operator:">=",value:5}),x(e)},className:"text-[10px] text-brand hover:text-brand/80 font-medium mt-1",children:"+ Add Condition"})]},e.id)),(0,l.jsx)("button",{onClick:()=>x([...m,{id:"rule_".concat(Date.now()),name:"New Rule",conditions:[{field:"customer_score",operator:">=",value:7.5}]}]),className:"text-xs text-brand hover:text-brand/80 font-medium",children:"+ Add Rule"})]})]}),(0,l.jsx)(eF,{onClick:()=>n({keep_item_rules:{enabled:h,rules:m}}),saving:a})]})}let eB=[{key:"exchange",label:"Exchange",showStock:!0},{key:"store_credit",label:"Store Credit",showStock:!1}];function eP(e){return e.split(",").map(e=>e.trim()).filter(Boolean)}function eO(e){let{config:t,onSave:n,saving:a}=e,o=t.return_policy.outcome_rules||{},[c,u]=(0,s.useState)(JSON.parse(JSON.stringify(o))),{activeInstance:h}=(0,r.z8)(),p=(0,s.useMemo)(()=>({rules:c}),[c]),m=(0,s.useMemo)(()=>({rules:o}),[o]),x=(0,i.RC)({storageKey:"rules.guardrails.".concat(h||"default"),value:p,baseline:m,meta:{label:"Resolution Options â ".concat(h||"client"),href:"/rules"}}),f=(e,t)=>u(n=>({...n,[e]:{...n[e]||{},...t}})),b=e=>""===e.trim()?null:Number(e),g=(e,t,n)=>(0,l.jsx)(d.ks,{type:"text",value:e,placeholder:n,onChange:e=>t(e.target.value),className:"w-full text-sm"});return(0,l.jsxs)("div",{className:"space-y-6",children:[x.hasStoredDraft&&(0,l.jsx)(ez,{at:
1x.storedDraftAt,onRestore:()=>{let e=x.restoreDraft();e&&u(e.rules)},onDiscard:x.discardDraft}),(0,l.jsx)("div",{className:"rounded-xl bg-surface-100 border border-line p-4",children:(0,l.jsx)("p",{className:"text-xs text-ink-faint m-0",children:"Guardrails narrow WHEN each resolution is offered to shoppers. Leave a field empty for no restriction â an unconfigured outcome behaves exactly as today. The removal reason is kept on the server for your audit trail; shoppers simply don't see the option."})}),eB.map(e=>{var t,n;let{key:s,label:a,showStock:r}=e,i=c[s]||{};return(0,l.jsx)(eC,{title:"".concat(a," guardrails"),children:(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Window (days) â empty = same as return window"}),(0,l.jsx)(d.ks,{type:"number",value:null!=(t=i.window_days)?t:"",placeholder:"e.g. 15",onChange:e=>f(s,{window_days:b(e.target.value)}),className:"w-full text-sm font-mono"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Minimum customer score (1â10) â empty = any"}),(0,l.jsx)(d.ks,{type:"number",step:"0.5",value:null!=(n=i.min_customer_score)?n:"",placeholder:"e.g. 5.0",onChange:e=>f(s,{min_customer_score:b(e.target.value)}),className:"w-full text-sm font-mono"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Only these categories (comma-separated) â empty = all"}),g((i.allowed_categories||[]).join(", "),e=>f(s,{allowed_categories:eP(e)}),"Apparel, Footwear")]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Blocked categories"}),g((i.blocked_categories||[]).join(", "),e=>f(s,{blocked_categories:eP(e)}),"Electronics")]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Blocked product tags"}),g((i.blocked_tags||[]).join(", "),e=>f(s,{blocked_tags:eP(e)}
1),"final-sale, clearance")]}),r&&(0,l.jsx)("div",{className:"flex items-end pb-1",children:(0,l.jsx)(eR,{label:"Require replacement in stock",checked:!0===i.require_in_stock,onChange:e=>f(s,{require_in_stock:e})})})]})},s)}),(0,l.jsx)(eF,{onClick:()=>{let e={};for(let[t,n]of Object.entries(c)){var l,s,a,r,i,o;(null!=n.window_days||(null!=(r=null==(l=n.allowed_categories)?void 0:l.length)?r:0)>0||(null!=(i=null==(s=n.blocked_categories)?void 0:s.length)?i:0)>0||(null!=(o=null==(a=n.blocked_tags)?void 0:a.length)?o:0)>0||null!=n.min_customer_score||!0===n.require_in_stock)&&(e[t]=n)}n({return_policy:{...t.return_policy,outcome_rules:e}})},saving:a,dirty:x.isDirty})]})}function eM(e){var t,n,a,o;let{config:d,onSave:c,saving:u}=e,h=d.photo_policy_rules,[p,m]=(0,s.useState)(null!=(a=null==(t=h.require_photos_rules)?void 0:t.enabled)&&a),[x,f]=(0,s.useState)(null!=(o=null==(n=h.photo_incentive_rules)?void 0:n.enabled)&&o),{activeInstance:b}=(0,r.z8)(),g=(0,s.useMemo)(()=>({reqEnabled:p,incEnabled:x}),[p,x]),v=(0,s.useMemo)(()=>{var e,t,n,l;return{reqEnabled:null!=(n=null==(e=h.require_photos_rules)?void 0:e.enabled)&&n,incEnabled:null!=(l=null==(t=h.photo_incentive_rules)?void 0:t.enabled)&&l}},[h]),_=(0,i.RC)({storageKey:"rules.photos.".concat(b||"default"),value:g,baseline:v,meta:{label:"Photo Requirements â ".concat(b||"client"),href:"/rules"}});return(0,l.jsxs)("div",{className:"space-y-6",children:[_.hasStoredDraft&&(0,l.jsx)(ez,{at:_.storedDraftAt,onRestore:()=>{let e=_.restoreDraft();e&&(m(e.reqEnabled),f(e.incEnabled))},onDiscard:_.discardDraft}),(0,l.jsxs)(eC,{title:"Required Photos",children:[(0,l.jsx)(eR,{label:"Enable Photo Requirements",checked:p,onChange:m}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mt-2",children:"Customers matching these rules must upload photos before their return is accepted"})]}),(0,l.jsxs)(eC,{title:"Photo Incentives",children:[(0,l.jsx)(eR,{label:"Enable Photo Incentives",checked:x,onChange:f}),(0,l.jsx)("p",{className:"text-xs text-ink-faint mt-2",children:"Offer customers bonuses for uploading photos with their return"})]}),(0,l.jsx)(eF,{onClick:()=>c({photo_policy_rules:{require_photos_rules:{...h.require_photos_rules,enabled:p},photo_incentive_rules:{...h.photo_incentive_rules,enabled:x}}}),saving:u,dirty:_.isDirty})]})}function eI(e){let{config:t,onSave:n,saving:a}=e,o=t.branding||{}
1,[c,u]=(0,s.useState)(o.portal_name||""),[h,p]=(0,s.useState)(o.welcome_message||""),[m,x]=(0,s.useState)(o.primary_color||"#ABA3FF"),[f,b]=(0,s.useState)(o.logo_url||""),[g,v]=(0,s.useState)(o.support_email||""),[_,j]=(0,s.useState)(o.custom_css||""),{activeInstance:y}=(0,r.z8)(),k=(0,s.useMemo)(()=>({portalName:c,welcomeMsg:h,primaryColor:m,logoUrl:f,supportEmail:g,customCss:_}),[c,h,m,f,g,_]),w=(0,s.useMemo)(()=>({portalName:o.portal_name||"",welcomeMsg:o.welcome_message||"",primaryColor:o.primary_color||"#ABA3FF",logoUrl:o.logo_url||"",supportEmail:o.support_email||"",customCss:o.custom_css||""}),[o]),N=(0,i.RC)({storageKey:"rules.branding.".concat(y||"default"),value:k,baseline:w,meta:{label:"Branding â ".concat(y||"client"),href:"/rules"}});return(0,l.jsxs)("div",{className:"space-y-6",children:[N.hasStoredDraft&&(0,l.jsx)(ez,{at:N.storedDraftAt,onRestore:()=>{let e=N.restoreDraft();e&&(u(e.portalName),p(e.welcomeMsg),x(e.primaryColor),b(e.logoUrl),v(e.supportEmail),j(e.customCss))},onDiscard:N.discardDraft}),(0,l.jsxs)(eC,{title:"Portal Appearance",children:[(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Portal Name"}),(0,l.jsx)(d.ks,{value:c,onChange:e=>u(e.target.value),placeholder:"e.g. Returns Center",className:"w-full text-sm"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Support Email"}),(0,l.jsx)(d.ks,{value:g,onChange:e=>v(e.target.value),placeholder:"[email protected]",className:"w-full text-sm"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Primary Color"}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("input",{type:"color",value:m,onChange:e=>x(e.target.value),className:"w-8 h-8 rounded border-0 cursor-pointer"}),(0,l.jsx)(d.ks,{value:m,onChange:e=>x(e.target.value),className:"flex-1 text-sm font-mono"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Logo URL"}),(0,l.jsx)(d.ks,{value:f,onChange:e=>b(e.target.value),placeholder:"https://...",className:"w-full text-sm"})]})]}),(0,l.jsxs)("div",{className:"mt-4",children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Welcome Message"}),(0,l.jsx)(d.fs,{value:h,onChange:e=>p(e.target.value),rows:2,placeholder:"Start a return or exchange...",className:"w-full text-sm resize-none"})]}),(0,l.jsxs)("div",{className:"mt-4",children:[(0,l.jsx)("label",{className:"text-xs text-ink-faint block mb-1",children:"Custom CSS (advanced)"}),(0,l.jsx)(d.fs,{value:_,onChange:e=>j(e.target.value),rows:3,placeholder:".portal-header { ... }",className:"w-full text-xs font-mono resize-none"})]})]}),(0,l.jsx)(eF,{onClick:()=>n({branding:{portal_name:c,welcome_message:h,primary_color:m,logo_url:f,support_email:g,custom_css:_}}),saving:a,dirty:N.isDirty})]})}},86340:()=>{},88661:(e,t,n)=>{"use strict";e.exports=n(45688).style}}]);
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.