1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5252a277-fb1b-57b4-a21e-48889e782f25")}catch(e){}}(); 2import{dp as ke,dq as fe,dr as we,h as Z,f as Le,cD as H,k as v,j as e,e as F,T as A,I as de,B as $,o as z,M as P,bc as Ie,ab as Ce,N as W,q as re,r as d,l as ce,n as L,a1 as ye,a0 as Ee,bm as Se,bn as Re,ds as ze,bg as ge,bi as B,be as G,bk as Ne,F as he,av as qe,b8 as Fe,aG as S,bl as De,ax as Me,u as Oe,A as w,as as ie,b4 as be,p as je,bN as $e,ao as Pe,aa as We,dt as Ve,_ as Ke,aN as oe,P as ve}from"./index-DmqEQZ_1.js";import{S as Ge}from"./SettingsHeading-DpmVD0Jv.js";import{S as He}from"./SkeletonListItem-DOuAXuJc.js";import{O as _e}from"./bucket-10-B1mB5QUF.js";import"./SkeletonBodyText-DISN5OIt.js";import"./SkeletonDisplayText-6JVwGM8Z.js";var se=function(){return ke.Date.now()},Ue="Expected a function",Be=Math.max,Qe=Math.min;function Ze(t,i,o){var a,n,s,c,r,m,C=0,g=!1,h=!1,y=!0;if(typeof t!="function")throw new TypeError(Ue);i=fe(i)||0,we(o)&&(g=!!o.leading,h="maxWait"in o,s=h?Be(fe(o.maxWait)||0,i):s,y="trailing"in o?!!o.trailing:y);function N(u){var b=a,x=n;return a=n=void 0,C=u,c=t.apply(x,b),c}function T(u){return C=u,r=setTimeout(I,i),g?N(u):c}function O(u){var b=u-m,x=u-C,j=i-b;return h?Qe(j,s-x):j}function M(u){var b=u-m,x=u-C;return m===void 0||b>=i||b<0||h&&x>=s}function I(){var u=se();if(M(u))return k(u);r=setTimeout(I,O(u))}function k(u){return r=void 0,y&&a?N(u):(a=n=void 0,c)}function D(){r!==void 0&&clearTimeout(r),C=0,a=m=n=r=void 0}function R(){return r===void 0?c:k(se())}function p(){var u=se(),b=M(u);if(a=arguments,n=this,m=u,b){if(r===void 0)return T(m);if(h)return clearTimeout(r),r=setTimeout(I,i),N(m)}return r===void 0&&(r=setTimeout(I,i)),c}return p.cancel=D,p.flush=R,p}const ae={pending:"pending",preparing:"preparing",fulfilled:"fulfilled",in_transit:"in_transit",arrived_destination:"arrived_destination",attempt_failed:"attempt_failed",delivered:"delivered",exception:"exception",expired:"expired"},Q={email_to_receiver:"email_to_receiver",email_to_merchant:"email_to_merchant"},ue={is_any_of:"is_any_of",is_none_of:"is_none_of"},V={delivery_status:"delivery_status"},Xe=(t,i)=>H({url:`/v1/org/${t}/notification-rules/send-test-email`,method:"POST"},i),Je=t=>{const{mutation:i,request:o}={};return{mutationFn:n=>{const{orgId:s}=n??{};return Xe(s,o)},...i}},Ye=t=>{const i=Je();return Z(i)},et=(t,i,o)=>H({url:`/v1/org/${t}/notification-rules`,method:"GET",signal:o},i),Te=t=>[`/v1/org/${t}/notification-rules`],tt=(t,i)=>{const{query:o,request:a}={};return{queryKey:(o==null?void 0:o.queryKey)??Te(t),queryFn:({signal:c})=>et(t,a,c),enabled:!!t,retry:!1,...o}},nt=(t,i)=>{const o=tt(t),a=Le(o);return a.queryKey=o.queryKey,a},it=(t,i,o)=>H({url:`/v1/org/${t}/notification-rules`,method:"POST",headers:{"Content-Type":"application/json"},data:i},o),ot=t=>{const{mutation:i,request:o}={};return{mutationFn:n=>{const{orgId:s,data:c}=n??{};return it(s,c,o)},...i}},at=t=>{const i=ot();return Z(i)},st=(t,i,o,a)=>H({url:`/v1/org/${t}/notification-rules/${i}`,method:"PUT",headers:{"Content-Type":"application/json"},data:o},a),rt=t=>{const{mutation:i,request:o}={};return{mutationFn:n=>{const{orgId:s,id:c,data:r}=n??{};return st(s,c,r,o)},...i}},ct=t=>{const i=rt();return Z(i)},lt=(t,i,o)=>H({url:`/v1/org/${t}/notification-rules/${i}`,method:"DELETE"},o),dt=t=>{const{mutation:i,request:o}={};return{mutationFn:n=>{const{orgId:s,id:c}=n??{};return lt(s,c,o)},...i}},ut=t=>{const i=dt();return Z(i)},mt=(t,i,o)=>H({url:`/v1/org/${t}/notification-rules/${i}/enable`,method:"POST"},o),pt=t=>{const{mutation:i,request:o}={};return{mutationFn:n=>{const{orgId:s,id:c}=n??{};return mt(s,c,o)},...i}},ft=t=>{const i=pt();return Z(i)},gt=(t,i,o)=>H({url:`/v1/org/${t}/notification-rules/${i}/disable`,method:"POST"},o),ht=t=>{const{mutation:i,request:o}={};return{mutationFn:n=>{const{orgId:s,id:c}=n??{};return gt(s,c,o)},...i}},bt=t=>{const i=ht();return Z(i)},vt=t=>v("svg",{width:"120",height:"120",viewBox:"0 0 120 120",fill:"none",xmlns:"http://www.w3.org/2000/svg",...t,children:[e("path",{d:"M60 102.5C66.9036 102.5 72.5 96.9036 72.5 90H47.5C47.5 96.9036 53.0964 102.5 60 102.5Z",fill:"#00D084"}),e("path",{d:"M87.5 77.5V52.5C87.5 37.3122 75.1878 25 60 25C44.8122 25 32.5 37.3122 32.5 52.5V77.5L25 85V90H95V85L87.5 77.5Z",stroke:"#1C1C1C",strokeWidth:"5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),e("path",{d:"M48.75 53.75L56.25 61.25L71.25 46.25",stroke:"#1C1C1C",strokeWidth:"5",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M97.5 37.5C102.5 42.5 105 48.75 105 55",stroke:"#00D084",strokeWidth:"5",strokeLinecap:"round",strokeLinejoin:"round"}),e("path",{d:"M22.5 37.5C17.5 42.5 15 48.75 15 55",stroke:"#00D084",strokeWidth:"5",strokeLinecap:"round",strokeLinejoin:"round"})]}),Ct=z("div",{target:"e1bh3u9b3"})({name:"14omwuh",styles:"padding:40px 0;display:flex;flex-direction:column;align-items:center;justify-content:center"}),yt=z("div",{target:"e1bh3u9b2"})({name:"1fgdcyd",styles:"margin-bottom:24px"}),Et=z("div",{target:"e1bh3u9b1"})({name:"cn3xcj",styles:"margin-bottom:12px"}),St=z("div",{target:"e1bh3u9b0"})({name:"l31826",styles:"max-width:400px;text-align:center;margin-bottom:24px"}),Rt=({onAction:t})=>{const{t:i}=F();return v(Ct,{children:[e(yt,{children:e(vt,{style:{width:64,height:64}})}),e(Et,{children:e(A,{variant:"headingLg",as:"h3",children:i("pages.settings.tabs.notificationCenter.emptyState.title")})}),e(St,{children:e(A,{variant:"bodyMd",as:"p",color:"subdued",children:i("pages.settings.tabs.notificationCenter.emptyState.description")})}),e($,{size:"slim",primary:!0,icon:e(de,{size:20}),onClick:t,children:i("pages.settings.tabs.notificationCenter.emptyState.button")})]})},Nt=({open:t,onClose:i,onConfirm:o,ruleName:a,isDeleting:n=!1})=>{const{t:s}=F();return e(P,{open:t,onClose:i,title:s("pages.settings.tabs.notificationCenter.deleteModal.title"),primaryAction:{content:s("pages.settings.tabs.notificationCenter.deleteModal.confirm"),onAction:o,destructive:!0,loading:n},secondaryActions:[{content:s("common.cancel"),onAction:i,disabled:n}],children:e(P.Section,{children:e(Ie,{children:e("p",{children:s("pages.settings.tabs.notificationCenter.deleteModal.description",{ruleName:a})})})})})},xe=(t,i)=>i(`pages.shipments.deliveryStatus.${Ce(t)}`,{defaultValue:t.replace(/_/g," ").replace(/\b\w/g,o=>o.toUpperCase())}),Mt=(t,i)=>{const o=W(t.type).with(V.delivery_status,()=>i("pages.settings.tabs.notificationCenter.form.conditions.deliveryStatus.label")).otherwise(()=>t.type),a=W(t.operator).with("is_any_of",()=>i("pages.settings.tabs.notificationCenter.form.conditions.operator.isAnyOf")).with("is_none_of",()=>i("pages.settings.tabs.notificationCenter.form.conditions.operator.isNoneOf")).otherwise(()=>t.operator),n=t.value.map(s=>xe(s,i)).join(", ");return{typeLabel:o,operatorLabel:a,valuesLabel:n}},Ot=(t,i)=>{var s,c;const o=[],a=t.find(r=>r.type===Q.email_to_receiver),n=t.find(r=>r.type===Q.email_to_merchant);if(a&&o.push(i("pages.settings.tabs.notificationCenter.form.recipients.receiver
2Email")),n){const r=(c=(s=n.config)==null?void 0:s.merchantEmails)==null?void 0:c[0];r?o.push(r):o.push(i("pages.settings.tabs.notificationCenter.form.recipients.merchantEmail"))}return o},_t=z("div",{target:"eibejzy0"})({name:"niml4g",styles:"padding:var(--p-space-4);padding-left:0"}),Tt=({condition:t,index:i,onEdit:o,onDelete:a})=>{const{t:n}=F(),{value:s,setTrue:c,setFalse:r}=re(!1),{value:m,setTrue:C,setFalse:g}=re(!1),h=d.useMemo(()=>[{content:n("common.edit"),onAction:()=>{r(),o(i)}},{content:n("common.delete"),destructive:!0,onAction:()=>{r(),C()}}],[r,i,o,C,n]),y=d.useMemo(()=>W(t.type).with(V.delivery_status,()=>n("pages.settings.tabs.notificationCenter.form.conditions.deliveryStatus.label")).otherwise(()=>t.type),[t.type,n]),N=d.useMemo(()=>W(t).with({type:V.delivery_status},T=>{const O=T.value.map(M=>xe(M,n)).join(", ");return e(A,{as:"p",variant:"bodySm",color:"subdued",children:e(ce,{i18nKey:"pages.settings.tabs.notificationCenter.form.conditions.deliveryStatus.description",values:{status:O},components:[e(A,{as:"span",variant:"bodySm",fontWeight:"semibold",children:null},"status")]})})}).otherwise(()=>null),[t,n]);return v(_t,{children:[v(L,{distribution:"equalSpacing",alignment:"leading",wrap:!1,children:[e(L.Item,{fill:!0,children:v(L,{vertical:!0,spacing:"extraTight",alignment:"leading",children:[e(A,{variant:"headingSm",as:"h6",children:y}),N]})}),e(Ee,{active:s,activator:e($,{onClick:c,plain:!0,icon:e(_e,{size:20})}),onClose:r,children:e(ye,{items:h})})]}),e(P,{open:m,title:n("pages.settings.tabs.notificationCenter.form.conditions.modal.delete.title"),onClose:g,primaryAction:{content:n("pages.settings.tabs.notificationCenter.form.conditions.modal.delete.confirm"),destructive:!0,onAction:()=>{a(i),g()}},secondaryActions:[{content:n("common.cancel"),onAction:g}],children:e(P.Section,{children:e(A,{as:"p",variant:"bodyMd",children:e(ce,{i18nKey:"pages.settings.tabs.notificationCenter.form.conditions.modal.delete.description",values:{conditionName:y},components:[e("strong",{},0)]})})})})]})},xt=z("div",{target:"e1i1j5ub0"})({name:"12a04nj",styles:"display:flex;align-items:center;justify-content:center;height:100%"}),At=()=>{const{t}=F();return d.useMemo(()=>S.object({operator:S.nativeEnum(ue),statuses:S.array(S.nativeEnum(ae)).min(1,{message:t("form.validation.required",{fieldName:t("pages.settings.tabs.notificationCenter.form.conditions.deliveryStatus.label")})})}),[t])},kt=({mode:t,conditionSelector:i,condition:o,onSubmit:a})=>{const{t:n}=F(),s=At(),{control:c,handleSubmit:r,setValue:m,watch:C}=Se({resolver:Re(s),defaultValues:(o==null?void 0:o.type)===V.delivery_status?{operator:o.operator,statuses:o.value}:{operator:ue.is_any_of,statuses:[]}}),g=C("statuses"),h=d.useMemo(()=>Object.values(ae).map(p=>({value:p,label:n(`pages.shipments.deliveryStatus.${Ce(p)}`)})),[n]),[y,N]=d.useState(""),[T,O]=d.useState(h),M=d.useCallback(p=>{if(N(p),p===""){O(h);return}const u=new RegExp(p,"i"),b=h.filter(x=>x.label.match(u));O(b)},[h]),I=d.useCallback(p=>{const u=h.filter(b=>p.includes(b.value)).map(b=>b.value);m("statuses",u,{shouldValidate:!0}),N("")},[m,h]),k=d.useCallback(p=>{const u=g.filter(b=>b!==p);m("statuses",u,{shouldValidate:!0})},[g,m]),D=p=>{a({type:V.delivery_status,operator:p.operator,value:p.statuses})},R=e(ge.TextField,{onChange:M,label:n("pages.settings.tabs.notificationCenter.form.conditions.deliveryStatus.label"),value:y,prefix:e(xt,{children:e(ze,{size:20})}),autoComplete:"off"});return v(he,{children:[e(P.Section,{children:v(B,{children:[i,e(G,{control:c,name:"operator",render:({field:p})=>{const{ref:u,...b}=p;return e(Ne,{label:n("pages.settings.tabs.notificationCenter.form.conditions.operator.label"),disabled:!0,options:[{label:n("pages.settings.tabs.notificationCenter.form.conditions.operator.isAnyOf"),value:"is_any_of"}],...b})}}),e(G,{control:c,name:"statuses",render:({fieldState:{error:p}})=>v(he,{children:[e(ge,{allowMultiple:!0,options:T,selected:g,onSelect:I,textField:R}),e(qe,{heightSpace:"2"}),g.length>0&&e(L,{spacing:"tight",children:g.map(u=>{var x;const b=(x=h.find(j=>j.value===u))==null?void 0:x.label;return e(Fe,{onRemove:()=>k(u),children:b},`option-${u}`)})}),p&&e(A,{as:"span",variant:"bodyMd",color:"critical",children:p.message})]})})]})}),e(P.Section,{children:e(L,{distribution:"trailing",children:e($,{primary:!0,onClick:r(D),children:n(`pages.settings.tabs.notificationCenter.form.conditions.button.${t}`)})})})]})},wt=({conditionSelector:t})=>e(P.Section,{children:t}),Lt=({conditions:t,index:i,onClose:o,onSubmit:a})=>{const{t:n}=F(),s=i!==void 0&&i>=0?t[i]:void 0,c=s?"update":"add",[r,m]=d.useState(s==null?void 0:s.type),C=d.useMemo(()=>[{value:V.delivery_status,label:n("pages.settings.tabs.notificationCenter.form.conditions.deliveryStatus.label")}],[n]),g=d.useCallback(N=>{const T=C.find(O=>O.value===N);T&&m(T.value)},[C]),h=e(Ne,{label:n("pages.settings.tabs.notificationCenter.form.conditions.selector.label"),options:C,onChange:g,value:r,placeholder:n("form.placeholder.select")}),y=d.useMemo(()=>W(r).with(V.delivery_status,()=>kt).otherwise(()=>wt),[r]);return v(P,{open:!0,large:!0,titleHidden:!0,title:"",onClose:o,children:[e(De,{title:n(`pages.settings.tabs.notificationCenter.form.conditions.modal.title.${c}`),onClose:o}),e(y,{mode:c,conditionSelector:h,condition:s,onSubmit:a,onClose:o})]})},le=50,Ae=100,It=z("div",{target:"eab9k290"})({name:"akdqam",styles:"margin-top:1rem"}),zt=()=>{const{t}=F();return d.useMemo(()=>{const i=S.object({type:S.nativeEnum(V),operator:S.nativeEnum(ue),value:S.array(S.nativeEnum(ae)).min(1,{message:t("form.validation.required")})});return S.object({name:S.string().trim().min(1,{message:t("form.validation.required",{fieldName:t("pages.settings.tabs.notificationCenter.form.name.label")})}).max(le,{message:t("form.validation.invalidMaxLength",{fieldName:t("pages.settings.tabs.notificationCenter.form.name.label"),maxLength:le})}),description:S.string().trim().max(Ae).optional(),conditions:S.array(i).min(1,{message:t("form.validation.required")}
2),receiverEmail:S.boolean().default(!0),merchantEmail:S.boolean().default(!1),merchantEmailAddress:S.string().optional()}).superRefine((o,a)=>{if(o.merchantEmail){if(!o.merchantEmailAddress||o.merchantEmailAddress.trim()===""){a.addIssue({code:S.ZodIssueCode.custom,message:t("form.validation.required",{fieldName:t("pages.settings.tabs.notificationCenter.form.recipients.merchantEmailPlaceholder")}),path:["merchantEmailAddress"]});return}S.string().email().safeParse(o.merchantEmailAddress).success||a.addIssue({code:S.ZodIssueCode.custom,message:t("form.validation.invalidEmail"),path:["merchantEmailAddress"]})}})},[t])},qt=({onCancel:t,onSubmit:i,isLoading:o=!1,initialValues:a})=>{const{t:n}=F(),{showToast:s}=Me(),{userSession:c,userOrganization:r}=Oe(),m=zt(),{mutateAsync:C,isLoading:g}=Ye(),h=(c==null?void 0:c.email)||"",{control:y,handleSubmit:N,watch:T,setValue:O}=Se({resolver:Re(m),defaultValues:{name:"",description:"",receiverEmail:!0,merchantEmail:!1,merchantEmailAddress:(a==null?void 0:a.merchantEmailAddress)||h,...a,conditions:(a==null?void 0:a.conditions)||[]}}),M=T("conditions"),I=T("merchantEmail"),{value:k,setTrue:D,setFalse:R}=re(!1),[p,u]=d.useState(void 0),b=()=>{u(void 0),D()},x=f=>{u(f),D()},j=f=>{const _=[...M];_.splice(f,1),O("conditions",_,{shouldValidate:!0})},te=f=>{const _=[...M];p!==void 0?_[p]=f:_.push(f),O("conditions",_,{shouldValidate:!0}),R()},X=d.useRef(r);X.current=r;const ne=d.useMemo(()=>Ze(async()=>{const f=X.current;if(f!=null&&f.id)try{await C({orgId:f.id})}catch{s({content:n("pages.settings.tabs.notificationCenter.toast.sendTestEmailFailed")})}},500),[C,s,n]);return v(Pe,{onSubmit:N(i),children:[v(B,{children:[e(w,{children:e(w.Section,{title:n("pages.settings.tabs.notificationCenter.form.sections.rule.title"),children:v(B,{children:[e(G,{control:y,name:"name",render:({field:f,fieldState:_})=>{var l;const{ref:J,...Y}=f;return e(ie,{label:n("pages.settings.tabs.notificationCenter.form.name.label"),...Y,error:(l=_.error)==null?void 0:l.message,requiredIndicator:!0,autoComplete:"off",placeholder:n("pages.settings.tabs.notificationCenter.form.name.placeholder"),suffix:`${f.value.length}/${le}`})}}),e(G,{control:y,name:"description",render:({field:f})=>{const{ref:_,...J}=f;return e(ie,{label:n("pages.settings.tabs.notificationCenter.form.description.label"),...J,autoComplete:"off",helpText:n("pages.settings.tabs.notificationCenter.form.description.helpText"),suffix:`${(f.value||"").length}/${Ae}`})}})]})})}),e(w,{children:e(w.Section,{title:n("pages.settings.tabs.notificationCenter.form.sections.conditions.title"),children:v(B,{children:[e(A,{variant:"bodyMd",as:"p",color:"subdued",children:n("pages.settings.tabs.notificationCenter.form.sections.conditions.description")}),e(L,{vertical:!0,spacing:"tight",children:M.map((f,_)=>e(Tt,{condition:f,index:_,onEdit:x,onDelete:j},_))}),e($,{size:"slim",icon:e(de,{size:20}),onClick:b,children:n("pages.settings.tabs.notificationCenter.form.conditions.addCondition")})]})})}),e(w,{children:e(w.Section,{title:n("pages.settings.tabs.notificationCenter.form.sections.recipients.title"),children:v(B,{children:[e(A,{variant:"bodyMd",as:"p",color:"subdued",children:n("pages.settings.tabs.notificationCenter.form.sections.recipients.description")}),e(G,{control:y,name:"receiverEmail",render:({field:f})=>e(be,{label:n("pages.settings.tabs.notificationCenter.form.recipients.receiverEmail"),checked:f.value,onChange:f.onChange})}),e(G,{control:y,name:"merchantEmail",render:({field:f})=>e(be,{label:n("pages.settings.tabs.notificationCenter.form.recipients.merchantEmail"),checked:f.value,onChange:f.onChange})}),I&&e(G,{control:y,name:"merchantEmailAddress",render:({field:f,fieldState:_})=>{var l;const{ref:J,...Y}=f;return e(ie,{labelHidden:!0,label:n("pages.settings.tabs.notificationCenter.form.recipients.merchantEmailPlaceholder"),placeholder:n("pages.settings.tabs.notificationCenter.form.recipients.merchantEmailPlaceholder"),...Y,error:(l=_.error)==null?void 0:l.message,autoComplete:"email"})}})]})})}),e(w,{children:e(w.Section,{title:n("pages.settings.tabs.notificationCenter.form.sections.emailPreview.title"),children:v(B,{children:[e(A,{variant:"bodyMd",as:"p",color:"subdued",children:n("pages.settings.tabs.notificationCenter.form.sections.emailPreview.description")}),e(ie,{label:n("pages.settings.tabs.notificationCenter.form.emailPreview.merchantEmail.label"),value:h,onChange:je,readOnly:!0,autoComplete:"off"}),e(It,{children:e($,{onClick:ne,loading:g,disabled:!h,children:n("pages.settings.tabs.notificationCenter.form.emailPreview.sendTestEmail")})})]})})})]}),e($e,{primaryAction:{content:n(a?"common.change":"common.submit"),onAction:N(i),loading:o},secondaryActions:[{content:n("common.cancel"),onAction:t}]}),k&&e(Lt,{conditions:M,index:p,onClose:R,onSubmit:te})]})},Ft=z("span",{target:"e1rcmk5j1"})({name:"16ceglb",styles:"font-weight:600"}),Dt=z("div",{target:"e1rcmk5j0"})({name:"v6v1ib",styles:"display:grid;grid-template-columns:1.5fr 1fr auto;gap:16px;width:100%"}),jt=({rule:t,onToggleActive:i,onEdit:o,onDelete:a})=>{const{t:n}
2=F(),[s,c]=d.useState(!1),r=()=>c(g=>!g),m=d.useMemo(()=>t.conditions.map((g,h)=>{const{typeLabel:y,operatorLabel:N,valuesLabel:T}=Mt(g,n);return v(A,{as:"p",variant:"bodyMd",children:[y," ",e(Ft,{children:N})," ",n("pages.settings.tabs.notificationCenter.form.conditions.these"),": ",T]},h)}),[t.conditions,n]),C=d.useMemo(()=>Ot(t.channels,n),[t.channels,n]);return v(w,{children:[e(w.Section,{children:v(L,{alignment:"center",children:[e(L.Item,{fill:!0,children:v(L,{alignment:"center",spacing:"tight",children:[e(A,{as:"h3",variant:"headingSm",children:t.name}),e(We,{status:t.isEnabled?"success":void 0,children:t.isEnabled?n("common.enabled","Enabled"):n("common.disabled")})]})}),e(L.Item,{children:e($,{onClick:()=>i(t.id,!t.isEnabled),size:"slim",primary:!t.isEnabled,outline:t.isEnabled,children:t.isEnabled?n("common.disable","Disable"):n("common.enable")})})]})}),e(w.Section,{children:v(Dt,{children:[v(L,{vertical:!0,spacing:"tight",children:[e(A,{as:"h4",variant:"bodyMd",color:"subdued",children:n("pages.settings.tabs.notificationCenter.form.sections.conditions.title")}),m]}),v(L,{vertical:!0,spacing:"tight",children:[e(A,{as:"h4",variant:"bodyMd",color:"subdued",children:n("pages.settings.tabs.notificationCenter.form.sections.recipients.title")}),C.map((g,h)=>e(A,{as:"p",variant:"bodyMd",children:g},h))]}),e(Ee,{active:s,activator:e($,{plain:!0,monochrome:!0,icon:e(_e,{size:20}),onClick:r}),onClose:r,children:e(ye,{items:[{content:n("common.edit"),onAction:()=>{o(t.id),r()}},{content:n("common.delete"),destructive:!0,onAction:()=>{a(t.id),r()}}]})})]})})]})},$t=({rules:t,onToggleActive:i,onEdit:o,onDelete:a})=>e(L,{vertical:!0,spacing:"loose",children:t.map(n=>e(jt,{rule:n,onToggleActive:i,onEdit:o,onDelete:a},n.id))}),Pt=t=>({operator:t.operator,type:t.type,value:t.value.filter(i=>Object.values(ae).includes(i))}),Wt=()=>{const{t}=F(),i=Ve(),{showToast:o}=Me(),{userOrganization:a}=Oe(),n=(a==null?void 0:a.id)??"",{mutateAsync:s}=ft(),{mutateAsync:c}=bt(),{mutateAsync:r}=ut(),{mutateAsync:m,isLoading:C}=at(),{mutateAsync:g,isLoading:h}=ct(),{data:y,isLoading:N}=nt(n),[T,O]=d.useState(!1),[M,I]=d.useState(null),[k,D]=d.useState(null),[R,p]=d.useState([]);d.useEffect(()=>{if(!y)return;const l=y.map(E=>({id:String(E.id),orgId:E.orgId,name:E.name,description:E.description??void 0,conditions:E.conditions,channels:E.channels,isEnabled:E.isEnabled}));p(l)},[y]);const u=d.useCallback(()=>{O(!0)},[]),b=d.useCallback(()=>{O(!1),I(null)},[]),x=d.useCallback(async l=>{const E=[];l.receiverEmail&&E.push({type:Q.email_to_receiver}),l.merchantEmail&&E.push({type:Q.email_to_merchant,config:{merchantEmails:[l.merchantEmailAddress||""]}});try{await W(M).with(Ke.string,async q=>{var U;await g({orgId:n,id:q,data:{name:l.name,description:l.description,conditions:l.conditions,channels:E,isEnabled:((U=R.find(K=>K.id===q))==null?void 0:U.isEnabled)??!0}})}).otherwise(async()=>{await m({orgId:n,data:{name:l.name,description:l.description,conditions:l.conditions,channels:E,isEnabled:!0}})})}catch{o({content:t("pages.settings.tabs.notificationCenter.toast.saveFailed")});return}await i.invalidateQueries({queryKey:Te(n)}),O(!1),I(null)},[R,m,M,n,i,g,o,t]),j=d.useCallback(async(l,E)=>{const q=R;p(U=>U.map(K=>K.id===l?{...K,isEnabled:E}:K));try{n&&await W(E).with(!0,()=>s({orgId:n,id:l})).with(!1,()=>c({orgId:n,id:l})).exhaustive()}catch{p(q),o({content:t("pages.settings.tabs.notificationCenter.toast.updateFailed")})}},[R,c,s,n,o,t]),te=d.useCallback(l=>{I(l),O(!0)},[]),X=d.useCallback(l=>{D(l)},[]),ne=d.useCallback(async()=>{if(k){const l=R;p(E=>E.filter(q=>q.id!==k)),D(null);try{n&&await r({orgId:n,id:k})}catch{p(l),o({content:t("pages.settings.tabs.notificationCenter.toast.deleteFailed")})}}},[R,r,k,n,o,t]),f=d.useCallback(()=>{D(null)},[]),_=d.useMemo(()=>{var me,pe;if(!M)return;const l=R.find(ee=>ee.id===M);if(!l)return;const E=l.channels.some(ee=>ee.type===Q.email_to_receiver),q=l.channels.find(ee=>ee.type===Q.email_to_merchant),U=!!q,K=((pe=(me=q==null?void 0:q.config)==null?void 0:me.merchantEmails)==null?void 0:pe[0])||"";return{name:l.name,description:l.description??void 0,conditions:l.conditions.map(Pt),receiver
2Email:E,merchantEmail:U,merchantEmailAddress:K}},[R,M]),J=d.useMemo(()=>{var l;return((l=R.find(E=>E.id===k))==null?void 0:l.name)||""},[R,k]),Y=d.useMemo(()=>({add:u,cancel:b,submit:x,toggleEnable:j,edit:te,delete:X,confirmDelete:ne,closeDeleteModal:f}),[u,b,x,j,te,X,ne,f]);return{rules:R,isLoading:N,isCreating:T,isSubmitting:C||h,deletingRuleId:k,deletingRuleName:J,formInitialValues:_,handlers:Y}},Vt=z("span",{target:"e1ldzn7m2"})({name:"mmdt3g",styles:"font-size:14px"}),Kt=z("div",{target:"e1ldzn7m1"})({name:"yz1nei",styles:"margin-top:16px"}),Gt=z("div",{target:"e1ldzn7m0"})({name:"xh0ihz",styles:"& .Polaris-Button__Icon{line-height:0;}"}),Jt=()=>{const{t}=F(),{rules:i,isLoading:o,isCreating:a,isSubmitting:n,deletingRuleId:s,deletingRuleName:c,formInitialValues:r,handlers:m}=Wt();return a?e(ve,{children:e(oe,{children:e(oe.Section,{children:e(qt,{onCancel:m.cancel,onSubmit:m.submit,initialValues:r,isLoading:n})})})}):e(ve,{children:e(oe,{children:v(oe.Section,{children:[e(Ge,{title:t("pages.settings.tabs.notificationCenter.title"),description:e(Vt,{children:e(ce,{i18nKey:"pages.settings.tabs.notificationCenter.description",components:{br:e("br",{})}})}),cta:e(Gt,{children:e($,{size:"slim",primary:!0,icon:e(de,{size:20}),onClick:m.add,children:t("pages.settings.tabs.notificationCenter.addRule")})})}),e(Kt,{children:W({isLoading:o,rules:i}).with({isLoading:!0},()=>e(w,{children:Array.from({length:3}).map((C,g)=>e(He,{lines:2},g))})).with({rules:[]},()=>e(w,{children:e(w.Section,{children:e(Rt,{onAction:m.add})})})).otherwise(()=>e($t,{rules:i,onToggleActive:m.toggleEnable,onEdit:m.edit,onDelete:m.delete}))}),e(Nt,{open:!!s,onClose:m.closeDeleteModal,onConfirm:m.confirmDelete,ruleName:c})]})})})};export{Jt as default}; 3//# debugId=5252a277-fb1b-57b4-a21e-48889e782f25 4//# sourceMappingURL=index-036R9xft.js.map
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.