1import{u as z,r as i,j as e,a as C}from"./components-CQCvpWKF.js";import{d as k,E as V,a as Y,S as W}from"./constants-CGURA1jD.js";import{P as J,a as h,C as _,I as f,T as l,B as w,d as X,c as S,b as v}from"./Page-DsIpu0Ao.js";import{T as q}from"./Tabs-DakVcbRG.js";import{M as D}from"./Modal-sqBXvS0d.js";import{C as G}from"./Checkbox-Cz45Daib.js";import{B as O}from"./Banner-qU0fmZA7.js";import"./context-BPdKkLnc.js";import"./context-B-fA7jms.js";import"./InlineGrid-CrKCQlRG.js";const K={ORDER_DISPATCHED:"ð¦",IN_TRANSIT:"ð",OUT_FOR_DELIVERY:"ð ",DELIVERED:"â
",DELIVERY_ATTEMPTED:"ð",HELD_AT_POST_OFFICE:"ð¬",RETURNED_TO_SENDER:"â©ï¸",DELAYED:"â³",EXCEPTION:"â ï¸"},F=[{id:"EMAIL",content:"Email"},{id:"SMS",content:"SMS"},{id:"PUSH",content:"Push"}];function ce(){const{store:u,eventType:s}=z(),T=Object.fromEntries(u.templates.map(t=>t.channel==="EMAIL"&&t.body&&!t.body.trimStart().startsWith("<!DOCTYPE")?[t.channel,{...t,body:k(s,"EMAIL").body}]:[t.channel,t])),[o,g]=i.useState(0),[x,c]=i.useState(!1),[r,m]=i.useState(""),a=F[o].id,j=i.useCallback(t=>{m(t),c(!0)},[]),d=K[s]||"ð¦",p=V[s]||s,n=W[s];return e.jsxs(J,{title:`${d} ${p}`,backAction:{content:"Templates",url:`/app/stores/${u.id}/templates`},children:[e.jsxs(h,{gap:"500",children:[e.jsx(_,{children:e.jsxs(h,{gap:"200",children:[e.jsxs(f,{align:"space-between",blockAlign:"center",children:[e.jsx(l,{as:"h2",variant:"headingSm",children:"Available variables"}),e.jsx(w,{tone:"info",children:"Use in subject or HTML body"})]}),e.jsxs(l,{as:"p",tone:"subdued",variant:"bodySm",children:["These are replaced with live order data when the email is sent. ",e.jsx("strong",{children:"{{line_items_html}}"})," injects the full styled order items section."]}),e.jsx(f,{gap:"150",wrap:!0,children:Y.map(t=>e.jsx(w,{tone:t==="line_items_html"||t==="unsubscribe_url"?"success":"info",children:`{{${t}}}`},t))})]})}),e.jsx(_,{children:e.jsxs(h,{gap:"400",children:[e.jsxs(f,{gap:"200",blockAlign:"center",children:[e.jsx(l,{as:"span",variant:"headingLg",children:d}),e.jsx(l,{as:"h2",variant:"headingLg",children:p}),e.jsx(w,{tone:n,children:p})]}),e.jsx(q,{tabs:F,selected:o,onSelect:g}),e.jsx(Q,{eventType:s,channel:a,storeId:u.id,template:T[a]??{...k(s,a),isEnabled:!1},onPreview:j},`${s}:${a}`)]})})]}),e.jsx(D,{open:x,onClose:()=>c(!1),title:"Email preview",size:"large",children:e.jsx(D.Section,{flush:!0,children:e.jsx("div",{style:{height:"78vh"},children:r&&e.jsx("iframe",{srcDoc:r,style:{width:"100%",height:"100%",border:"none"},title:"Email preview"})})})})]})}function Q({eventType:u,channel:s,storeId:T,template:o,onPreview:g}){var L,P;const x=C(),c=C(),r=C(),m=i.useRef(null),[a,j]=i.useState(o.isEnabled??!1),[d,p]=i.useState(o.subject??""),[n,t]=i.useState(o.body??""),H=a!==(o.isEnabled??!1)||d!==(o.subject??"")||n!==(o.body??""),E=s==="EMAIL",B=s==="SMS",N=s==="PUSH",y=n.length,M=Math.ceil(y/160)||1;i.useEffect(()=>{var b;if((b=c.data)!=null&&b.ok){const R=k(u,s);j(!1),p(R.subject??""),t(R.body??"")}},[c.data,u,s]),i.useEffect(()=>{var b;(b=r.data)!=null&&b.html&&g(r.data.html)},[r.data,g]),i.useEffect(()=>{m.current&&E&&(m.current.style.height="auto",m.current.style.height=`${Math.max(400,m.current.scrollHeight)}px`)},[n,E]);const $=()=>{x.submit({intent:"save",channel:s,isEnabled:a?"on":"off",subject:d,body:n},{method:"post"})},U=()=>{c.submit({intent:"reset",channel:s},{method:"post"})},A=()=>{r.submit({storeId:T,eventType:u,subject:d,body:n},{method:"post",action:"/api/preview-email"})},I=x.state!=="idle"||c.state!=="idle";return e.jsxs(h,{gap:"400",children:[e.jsx(X,{background:a?"bg-surface-success":"bg-surface-secondary",padding:"400",borderRadius:"200",children:e.jsxs(f,{align:"space-between",blockAlign:"center",children:[e.jsxs(h,{gap:"100",children:[e.jsx(l,{as:"p",fontWeight:"semibold",children:a?`${s} notifications are ON`:`${s} notifications are OFF`}),e.jsx(l,{as:"p",tone:"subdued",variant:"bodySm",children:a?"Customers will receive this notification when this event occurs.":"Enable to start sending this notification to customers."})]}),e.jsx(G,{label:"Enable",labelHidden:!0,checked:a,onChange:j})]})}),E&&e.jsxs(h,{gap:"300",children:[e.jsx(S,{label:"Subject line",value:d,onChange:p,autoComplete:"off",helpText:"The email subject line. Supports {{variables}}."}),e.jsxs(h,{gap:"100",children:[e.jsx(l,{as:"p",variant:"bodySm",fontWeight:"medium",children:"Email HTML"}
1),e.jsxs(l,{as:"p",variant:"bodySm",tone:"subdued",children:["Full HTML email template. Edit anything â logo, colours, layout, content. Use ",e.jsx("code",{style:{background:"#f3f4f6",padding:"1px 4px",borderRadius:3},children:"{{variables}}"})," anywhere. Click ",e.jsx("strong",{children:"Preview email"})," to see it rendered with sample data."]}),e.jsxs("div",{style:{border:"1px solid #c9cccf",borderRadius:8,overflow:"hidden"},children:[e.jsxs("div",{style:{background:"#f6f6f7",borderBottom:"1px solid #c9cccf",padding:"8px 12px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(l,{as:"span",variant:"bodySm",tone:"subdued",children:"HTML editor"}),e.jsx(f,{gap:"200",children:e.jsx(v,{size:"slim",variant:"tertiary",onClick:A,loading:r.state!=="idle",children:"Preview email"})})]}),e.jsx("textarea",{ref:m,value:n,onChange:b=>t(b.target.value),spellCheck:!1,style:{display:"block",width:"100%",minHeight:400,padding:"16px",fontFamily:"'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', monospace",fontSize:12,lineHeight:1.6,color:"#1a1a1a",background:"#ffffff",border:"none",resize:"vertical",outline:"none",boxSizing:"border-box",tabSize:2}})]})]})]}),B&&e.jsx(S,{label:"SMS message",value:n,onChange:t,multiline:5,autoComplete:"off",helpText:`${y} characters â ${M} SMS part${M>1?"s":""}. Under 160 characters sends as a single message.`,error:y>160?"Over 160 characters â billed as multiple SMS messages.":void 0}),N&&e.jsxs(h,{gap:"400",children:[e.jsx(S,{label:"Notification title",value:d,onChange:p,autoComplete:"off",helpText:"Short title shown on the push notification banner."}),e.jsx(S,{label:"Push message",value:n,onChange:t,multiline:4,autoComplete:"off"})]}),((L=x.data)==null?void 0:L.ok)&&x.data.intent==="save"&&e.jsx(O,{tone:"success",children:"Template saved."}),((P=c.data)==null?void 0:P.ok)&&e.jsx(O,{tone:"info",children:"Reset to default template."}),e.jsxs(f,{gap:"300",children:[e.jsx(v,{variant:"primary",onClick:$,loading:I,disabled:!H,children:"Save template"}),E&&e.jsx(v,{variant:"secondary",onClick:A,loading:r.state!=="idle",children:"Preview email"}),e.jsx(v,{variant:"secondary",tone:"critical",onClick:U,loading:I,children:"Reset to default"})]})]})}export{ce as default};
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.