1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4156],{54156:(e,t,s)=>{s.r(t),s.d(t,{default:()=>et});var n=s(95155),a=s(34794),l=s(12115),i=s(10639),r=s(75936),o=s(88459);function c(e){return e.flatMap(e=>"columns"===e.type?e.columns.flatMap(e=>e.blocks):[e])}let d="{{eventLink}}";function u(e){let t=e.trim();return/^https?:\/\/[^\s<>"']+$/i.test(t)||/^mailto:[^\s<>"']+$/i.test(t)||t===d?t:null}function m(e){return c(e).length+e.filter(e=>"columns"===e.type).length}function x(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{let s=new URL(e);return!s.username&&!s.password&&(t?"https:"===s.protocol:["https:","http:","mailto:"].includes(s.protocol))&&("mailto:"!==s.protocol||/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s.pathname))}catch(e){return!1}}var h=s(90695),p=s(18703),b=s(11901);let g="w-full border border-[#d7d7de] rounded-lg p-2 text-sm bg-white-fixed text-[#1a1a1e]";function v(e){let{value:t,onChange:s,remaining:a,events:l,communityId:i}=e,r=(e,n)=>s({...t,columns:t.columns.map((t,s)=>s===e?{blocks:n}:t)});return(0,n.jsxs)("fieldset",{className:"min-w-0 border border-[#d7d7de] rounded-xl p-3 space-y-3 text-[#1a1a1e] bg-[#f7f7f9]",children:[(0,n.jsx)("legend",{className:"px-1 text-sm font-semibold",children:"Two columns"}),(0,n.jsx)("p",{className:"text-xs text-[#62626c]",children:"Side by side on wider screens. Left column comes first when stacked on a phone."}),(0,n.jsx)("div",{className:"grid sm:grid-cols-2 gap-4",children:t.columns.map((e,t)=>{let{blocks:s}=e;return(0,n.jsxs)("section",{"aria-label":"".concat(0===t?"Left":"Right"," email column"),className:"min-w-0 space-y-3",children:[(0,n.jsxs)("h4",{className:"text-xs font-semibold",children:[0===t?"Left":"Right"," column"]}),s.map((e,a)=>{let i=e=>r(t,s.map((t,s)=>s===a?{...t,...e}:t));return(0,n.jsxs)("div",{className:"space-y-2 border border-[#d7d7de] rounded-lg p-2 bg-white-fixed",children:[(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 justify-between text-xs",children:[(0,n.jsx)("span",{children:{heading:"Heading",text:"Text",button:"Button",image:"Image",divider:"Divider",event:"Event card",community:"Community card"}[e.type]||"Block"}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{"aria-label":"Move ".concat(0===t?"left":"right"," column block ").concat(a+1," up"),disabled:!a,onClick:()=>{let e=[...s];[e[a-1],e[a]]=[e[a],e[a-1]],r(t,e)},children:"â"}),(0,n.jsx)("button",{"aria-label":"Move ".concat(0===t?"left":"right"," column block ").concat(a+1," down"),disabled:a===s.length-1,onClick:()=>{let e=[...s];[e[a+1],e[a]]=[e[a],e[a+1]],r(t,e)},children:"â"}),(0,n.jsx)("button",{"aria-label":"Remove ".concat(0===t?"left":"right"," column block ").concat(a+1),onClick:()=>r(t,s.filter((e,t)=>t!==a)),children:"Remove"})]})]}),["text","heading","button","image"].includes(e.type)&&"content"in e&&(0,n.jsxs)("label",{className:"block text-xs",children:["image"===e.type?"Image description":"button"===e.type?"Button label":"Content",(0,n.jsx)("textarea",{className:g,rows:"text"===e.type?4:2,maxLength:"image"===e.type?300:2e4,value:e.content,onChange:e=>i({content:e.target.value})})]}),"image"===e.type&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(p.A,{onUploaded:e=>i({src:e})}),(0,n.jsx)(b.A,{onSelect:e=>i({src:e.url,content:e.alt||e.name})}),(0,n.jsxs)("label",{className:"block text-xs",children:["Image link",(0,n.jsx)("input",{className:g,value:e.src,onChange:e=>i({src:e.target.value}),placeholder:"https://â¦"})]})]}),("button"===e.type||"image"===e.type)&&(0,n.jsxs)("label",{className:"block text-xs",children:["image"===e.type?"Link (optional)":"Button link",(0,n.jsx)("input",{className:g,value:e.href||"",onChange:e=>i({href:e.target.value}),placeholder:"https://â¦"})]}),"event"===e.type&&(0,n.jsxs)("label",{className:"block text-xs",children:["Event",(0,n.jsxs)("select",{className:g,value:e.entityId,onChange:e=>i({entityId:e.target.value}),children:[!l.some(t=>t.eventId===e.entityId)&&(0,n.jsx)("option",{value:e.entityId,children:"Selected event"}),l.map(e=>(0,n.jsx)("option",{value:e.eventId,children:e.eventName},e.eventId))]})]}),"community"===e.type&&(0,n.jsx)("p",{className:"text-xs",children:"Card details show in the final preview."}
1),"divider"===e.type&&(0,n.jsx)("hr",{})]},a)}),(0,n.jsxs)("label",{className:"block text-xs",children:["Add to ",0===t?"left":"right"," column",(0,n.jsxs)("select",{className:g,value:"",disabled:a<=0,onChange:e=>{let n=e.target.value;r(t,[...s,"divider"===n?{type:n}:"button"===n?{type:n,content:"Learn more",href:""}:"image"===n?{type:n,content:"",src:""}:"event"===n?{type:n,content:"Event",entityId:l[0].eventId}:"community"===n?{type:n,content:"Community",entityId:i}:{type:n,content:""}])},children:[(0,n.jsx)("option",{value:"",children:"Choose a block"}),(0,n.jsx)("option",{value:"heading",children:"Heading"}),(0,n.jsx)("option",{value:"text",children:"Text"}),(0,n.jsx)("option",{value:"button",children:"Button"}),(0,n.jsx)("option",{value:"image",children:"Image"}),(0,n.jsx)("option",{value:"divider",children:"Divider"}),!!l.length&&(0,n.jsx)("option",{value:"event",children:"Event card"}),i&&(0,n.jsx)("option",{value:"community",children:"Community card"})]})]})]},t)})})]})}var f=s(98155);function y(e){let{content:t,color:s}=e;return(0,n.jsx)(n.Fragment,{children:(function(e){let t=[],s=e,n=/\[([^\]]+)\]\(([^)\s]+)\)|\*\*([^*]+)\*\*|\*([^*]+)\*/;for(;s.length>0;){let e=n.exec(s);if(!e){t.push({kind:"text",text:s});break}if(e.index>0&&t.push({kind:"text",text:s.slice(0,e.index)}),void 0!==e[1]){let s=u(e[2]);s?t.push({kind:"link",text:e[1],href:s}):t.push({kind:"text",text:e[1]})}else void 0!==e[3]?t.push({kind:"bold",text:e[3]}):void 0!==e[4]&&t.push({kind:"italic",text:e[4]});s=s.slice(e.index+e[0].length)}return t})(t).map((e,t)=>"bold"===e.kind?(0,n.jsx)("strong",{children:e.text},t):"italic"===e.kind?(0,n.jsx)("em",{children:e.text},t):"link"===e.kind?(0,n.jsx)("span",{title:e.href,className:"underline",style:{color:s},children:e.text},t):(0,n.jsx)("span",{children:e.text},t))})}function j(e){let{blocks:t,design:s,mobile:a}=e,l=(0,f.OR)(s);return(0,n.jsx)(n.Fragment,{children:t.map((e,t)=>"columns"===e.type?(0,n.jsx)("div",{className:"grid gap-3",style:{gridTemplateColumns:a?"1fr":"minmax(0,1fr) minmax(0,1fr)"},children:e.columns.map((e,t)=>(0,n.jsx)("div",{className:"min-w-0 space-y-2",children:(0,n.jsx)(j,{blocks:e.blocks,design:s,mobile:a})},t))},t):"divider"===e.type?(0,n.jsx)("hr",{className:"border-t border-[#d7d7de] my-3"},t):"image"===e.type?/^https:\/\//i.test(e.src)?(0,n.jsx)("img",{src:e.src,alt:e.content,className:"w-full h-auto rounded-lg"},t):(0,n.jsx)("p",{className:"text-xs",children:"Add an image"},t):"event"===e.type||"community"===e.type?(0,n.jsxs)("div",{className:"border border-current/20 rounded-lg p-3 text-xs",children:["event"===e.type?"Event card":"Community card"," \xb7 Card details show in the final preview."]},t):"button"===e.type?(0,n.jsx)("span",{className:"inline-block text-xs font-semibold px-4 py-2",style:{backgroundColor:l.buttonBg,color:l.buttonText,borderRadius:l.buttonRadius},children:e.content||"Button"},t):"heading"===e.type?(0,n.jsx)("p",{className:"text-base font-bold leading-snug",children:(0,n.jsx)(y,{content:e.content,color:l.linkColor})},t):(0,n.jsx)("p",{className:"text-xs leading-relaxed whitespace-pre-wrap",children:(0,n.jsx)(y,{content:e.content,color:l.linkColor})},t))})}var N=s(73445),w=s(18780),k=s(320),S=s(14585);function C(e){let{checked:t,replyDomain:s,onDomainChange:a,onChange:r}=e,o=(0,i.G_)("emailReplies",S.functions),[c,d]=(0,l.useState)(null),[u,m]=(0,l.useState)("");return(0,l.useEffect)(()=>{let e=!0;return d(null),m(""),o({action:"settings",...t&&{legacy:!s},...s&&{replyDomain:s}}).then(t=>{e&&d(t)}).catch(()=>{e&&m("Could not check reply collection. You can still use your reply email address.")}),()=>{e=!1}},[o,t,s]),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("label",{className:"flex items-start gap-2 text-sm text-t2",children:[(0,n.jsx)("input",{type:"checkbox",checked:t,disabled:!t&&!(null==c?void 0:c.ready),onChange:e=>{null==a||a(e.target.checked&&(null==c?void 0:c.branded)?c.domain:void 0),r(e.target.checked)},className:"mt-1"}),(0,n.jsxs)("span",{children:["Collect replies in Email Campaigns",(0,n.jsx)("span",{className:"block text-xs mt-1",children:"Replies are retained for 180 days. Review and respond from the Replies tab when the person still permits messages from you."})]})]}),(0,n.jsx)("p",{className:"text-xs text-t2",role:u?"status":void 0,children:u||(null==c?void 0:c.note)||"Checking reply collectionâ¦"})]})}var I=s(83073);let A={orders:"Completed purchases",surveyAnswered:"Answered a survey",surveyAnswer:"Survey answer",externalVisits:"Visits to your connected website",externalOrders:"Orders on your connected website",externalSpend:"Amount spent on your connected website",attended:"Times attended",rsvp:"RSVPs",tickets:"Tickets bought",netSpend:"Amount spent",memberDays:"Days as a member",upgrades:"Membership upgrades",pageViews:"Event page visits in 90 days",checkoutAttempts:"Checkouts started in 90 days",checkoutCompleted:"Checkouts completed in 90 days",checkoutFailed:"Checkouts that failed in 90 days",checkoutAbandoned:"Checkouts left unfinished in 90 days",checkoutIncomplete:"Started checkout but didnât buy",lastActivityDays:"Days since last visit",emailAccepted:"Was sent the email",emailDelivered:"Got the email",emailClicked:"Clicked a link",emailReplied:"Replied"},R=new Set(["checkoutIncomplete","emailAccepted","emailDelivered","emailClicked","emailReplied"]);var T=s(5780),L=s(29085),E=s(55619),D=s(60724);function B(e){let{inspection:t}=e;return(0,n.jsxs)("section",{className:"space-y-3 text-sm",children:[(0,n.jsx)("h3",{className:"font-semibold",children:"Content and links"}),t.notes.length?(0,n.jsx)("ul",{className:"space-y-2",children:t.notes.map((e,t)=>(0,n.jsxs)("li",{className:"text-t2",children:[(0,n.jsxs)("strong",{children:["fix"===e.kind?"Fix before sending":"Suggestion",":"]}
1)," ",e.message]},t))}):(0,n.jsx)("p",{className:"text-t2",children:"No problems found."}),!!t.substitutions.length&&(0,n.jsxs)("div",{children:[(0,n.jsx)("h4",{className:"font-medium",children:"When a detail is missing"}),(0,n.jsx)("ul",{className:"mt-2 space-y-1 text-t2",children:t.substitutions.map(e=>(0,n.jsxs)("li",{children:["{{".concat(e.token,"}}")," â ",e.replacement?"â".concat(e.replacement,"â"):"left out"]},e.token))})]}),(0,n.jsxs)("details",{children:[(0,n.jsxs)("summary",{className:"cursor-pointer",children:["Check the links (",t.totalLinks.toLocaleString(),")"]}),(0,n.jsx)("ul",{className:"mt-3 space-y-2",children:t.links.map((e,t)=>(0,n.jsxs)("li",{className:"break-all text-t2",children:[e.destination,(0,n.jsx)("span",{className:"block text-xs mt-1 ".concat(e.syntaxValid?"":"text-negative-ink"),children:e.syntaxValid?"Link format looks right (we donât open it)":"This link isnât valid"})]},t))}),t.totalLinks>t.links.length&&(0,n.jsxs)("p",{className:"text-t2 mt-2",children:["Showing the first ",t.links.length," links."]}),(0,n.jsxs)("p",{className:"text-xs text-t2 mt-3",children:["Email size: ",Math.ceil(t.htmlBytes/1024).toLocaleString()," KB"]}),(0,n.jsx)("p",{className:"text-xs text-t2 leading-5 mt-2",children:t.scope})]})]})}function M(e){let t=/alternative (\d+)/i.exec(e);if(t)return"Matches condition group ".concat(t[1]);if(/^[a-z0-9_]+$/.test(e)){let t=e.replaceAll("_"," ");return t.charAt(0).toUpperCase()+t.slice(1)}return e}function P(e){let{campaignId:t,preparedAtMs:s,revision:a}=e,r=(0,i.Kg)(),[o,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(null),[m,x]=(0,l.useState)(!1),[h,p]=(0,l.useState)(!1),[b,g]=(0,l.useState)(""),[v,f]=(0,l.useState)(null),[y,j]=(0,l.useState)("desktop"),N=(0,l.useRef)(0);(0,l.useEffect)(()=>()=>{N.current++},[t,a]);let w=async e=>{let s=++N.current;p(!0),g("");try{let n=await r("recipientPreview",{campaignId:t,expectedRevision:a,memberId:e});s===N.current&&f(n)}catch(e){s===N.current&&g(e.message)}finally{s===N.current&&p(!1)}},k=async e=>{p(!0),g("");
1try{let s=await r("sample",{campaignId:t,...e&&{cursor:e}});c(t=>e?[...t,...s.recipients]:s.recipients),u(s.nextCursor),x(!0)}catch(e){g(e.message)}finally{p(!1)}};return(0,n.jsxs)("details",{className:"[--text-tertiary:var(--text-secondary)] border border-white/10 rounded-xl p-4",children:[(0,n.jsx)("summary",{className:"cursor-pointer text-sm font-medium",onClick:()=>{m||h||k()},children:"Who is included, and why?"}),(0,n.jsxs)("p",{className:"studio-caption mt-3",children:["People included when the audience was prepared",s?" on ".concat(new Date(s).toLocaleString()):"",". Permission and your conditions are checked again before each email goes out."]}),b&&(0,n.jsxs)("p",{role:"alert",className:"text-sm text-negative-ink mt-3",children:[b,(0,n.jsx)("button",{onClick:()=>void k(),className:"underline ml-2",children:"Try again"})]}),(0,n.jsx)("ul",{className:"mt-4 space-y-3",children:o.map(e=>{var t;return(0,n.jsxs)("li",{className:"text-sm break-words",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[(0,n.jsx)("p",{children:e.email}),(0,n.jsx)("button",{className:"text-xs underline",disabled:h,onClick:()=>void w(e.id),children:"Preview this personâs email"})]}),(0,n.jsxs)("p",{className:"text-xs text-t2 mt-1",children:["community_opt_in"===e.permissionBasis?"Opted in to your communityâs emails":"Opted in to your emails",(null==(t=e.ruleReasons)?void 0:t.length)?" \xb7 ".concat([...new Set(e.ruleReasons.map(M))].join(" \xb7 ")):""]})]},e.id)})}),h&&(0,n.jsx)("p",{role:"status",className:"studio-caption mt-3",children:"Loading prepared recipientsâ¦"}),m&&!o.length&&(0,n.jsx)("p",{className:"studio-caption mt-3",children:"Nobody to show here."}),d&&(0,n.jsx)("button",{disabled:h,onClick:()=>void k(d),className:"text-sm underline mt-4",children:"Load more recipients"}),v&&(0,n.jsx)(E.A,{title:"Recipient email preview",onClose:()=>{N.current++,f(null)},children:(0,n.jsxs)("div",{className:"[--text-tertiary:var(--text-secondary)] space-y-5",children:[(0,n.jsxs)("p",{className:"text-sm",children:["To: ",v.recipientEmail]}),(0,n.jsx)("p",{className:"font-medium",children:v.subject}),(0,n.jsx)("div",{role:"group","aria-label":"Recipient preview format",className:"flex gap-3",children:["desktop","mobile","text"].map(e=>(0,n.jsx)("button",{className:"text-sm border border-white/15 rounded-lg px-3 py-2","aria-pressed":y===e,onClick:()=>j(e),children:"text"===e?"Plain text":"mobile"===e?"Mobile width":"Desktop width"},e))}),"text"===y?(0,n.jsx)("pre",{className:"whitespace-pre-wrap break-words text-sm max-h-[50dvh] overflow-auto",children:v.text}):(0,n.jsx)("iframe",{title:"Personalized email preview",sandbox:"",srcDoc:v.html,className:"block bg-white-fixed rounded-lg h-[50dvh] ".concat("mobile"===y?"w-[320px] max-w-full mx-auto":"w-full")}),(0,n.jsx)("p",{className:"text-xs text-t2",children:v.note}),(0,n.jsx)(B,{inspection:v.inspection})]})})]})}var F=s(39390),O=s(29213),U=s(37401),W=s(91710),V=s(31039);function _(e){let{blockCount:t,onInsert:s}=e,a=(0,i.Kg)(),[r,o]=(0,l.useState)(!1),[c,d]=(0,l.useState)([]),[u,x]=(0,l.useState)(null),[h,p]=(0,l.useState)(!1),[b,g]=(0,l.useState)(""),v=async e=>{p(!0),g("");try{let t=await a("libraryList",{kind:"section",...e&&{cursor:e}});d(s=>e?[...s,...t.items]:t.items),x(t.nextCursor)}catch(e){g((0,T.Q)(e))}finally{p(!1)}},f=async e=>{p(!0),g("");try{var n;let l=await a("libraryGet",{libraryId:e});if("section"!==l.kind||!Array.isArray(null==(n=l.draft)?void 0:n.bodyBlocks))throw Error("This saved section is unavailable.");if(t+m(l.draft.bodyBlocks)>60)throw Error("This email would exceed 60 blocks. Remove some blocks first.");s(l.draft.bodyBlocks),o(!1)}catch(e){g((0,T.Q)(e))}finally{p(!1)}};return(0,n.jsxs)("section",{className:"text-sm text-t2 space-y-3",children:[(0,n.jsx)("button",{"aria-expanded":r,onClick:()=>{o(!r),r||v()},className:"underline",children:"Insert a saved section"}),r&&(0,n.jsxs)("div",{className:"rounded-xl border border-white/15 p-4 space-y-3",children:[(0,n.jsx)("p",{children:"Reuse a header, introduction or lineup. Your subject, sender and audience stay as they are. Undo removes the inserted section."}),b&&(0,n.jsx)("p",{role:"alert",children:b}),!c.length&&(0,n.jsx)("p",{children:h?"Loading saved sectionsâ¦":"To create one, choose âSave to libraryâ, then âReusable sectionâ and select its blocks."}),(0,n.jsx)("ul",{className:"space-y-2",children:c.map(e=>(0,n.jsx)("li",{children:(0,n.jsxs)("button",{disabled:h,onClick:()=>void f(e.id),className:"underline disabled:opacity-40",children:["Insert ",e.name]})},e.id))}),u&&(0,n.jsx)("button",{disabled:h,onClick:()=>void v(u),className:"underline",children:"Load more sections"})]})]})}let Y=(0,l.lazy)(()=>s.e(2870).then(s.bind(s,12870))),q={lists:"lists",communities:"communities",segments:"saved segments",audiences:"saved audiences"},z=["Setup","Audience","Content","Review & send"],H=[{key:"newsletter",label:"Newsletter",hint:"Share updates and news"},{key:"event_promotion",label:"Event promotion",hint:"Promote an event"},{key:"product_promotion",label:"Product or offer",hint:"Promote a product, service or membership upgrade"},{key:"announcement",label:"Announcement",hint:"Share important news"},{key:"custom",label:"Custom",hint:"Start from scratch, your brand"}],K={newsletter:[{type:"heading",content:"The latest"},{type:"text",content:"Hi {{firstName}},\n\n"},{type:"divider"},{type:"text",content:""}],event_promotion:[{type:"heading",content:""},{type:"text",content:"Hi {{firstName}},\n\n"},{type:"button",content:"Get tickets",href:d}],announcement:[{type:"heading",content:""},{type:"text",content:"Hi {{firstName}},\n\n"}],product_promotion:[{type:"heading",content:""},{type:"text",content:"Hi {{firstName}},\n\n"},{type:"button",content:"Explore the offer",href:""}],custom:[{type:"text",content:""}]},G=["{{firstName}}","{{lastName}}","{{city}}"],$=["{{eventName}}","{{eventDate}}"];function Z(e){if("UTC"===e)return"UTC";let t=(e.split("/").pop()||e).replaceAll("_"," ");try{var s;let n=null==(s=new Intl.DateTimeFormat("en-US",{timeZone:e,timeZoneName:"short"}).formatToParts(new Date).find(e=>"timeZoneName"===e.type))?void 0:s.value;return n?"".concat(t," (").concat(n,")"):t}catch(e){return t}}let J=e=>"px-3.5 py-1.5 text-xs rounded-full border transition-colors ".concat(e?"bg-white text-surface-base border-white":"bg-white/[0.04] text-t2 border-white/[0.08] hover:border-white/[0.2]"),Q="w-full bg-white/[0.05] border border-white/[0.08] rounded-lg px-3 py-2.5 text-sm text-t1 placeholder:text-t3 outline-none focus:border-white/[0.22] transition-colors";function X(e){let{blocks:t,senderLabel:s,mobile:a,emailDesign:l}=e,i=l||f.eG;return(0,n.jsx)("div",{style:{fontFamily:f.gW[i.font]},className:"mx-auto transition-all ".concat(a?"max-w-[300px]":"max-w-full"),children:(0,n.jsxs)("div",{className:"bg-[#f4f4f6] rounded-xl p-3",style:{backgroundColor:i.backgroundColor},children:[(0,n.jsxs)("div",{className:"bg-[#ffffff] rounded-lg p-4 space-y-2 [color-scheme:light]",style:{backgroundColor:i.paperColor,color:i.textColor,borderRadius:8*("letter"!==i.layout)},children:[i.logoUrl&&(0,n.jsx)("img",{src:i.logoUrl,alt:i.logoAlt,style:{width:i.logoWidth,maxWidth:"100%",height:"auto",marginBottom:16}}),(0,n.jsx)(j,{blocks:t,design:i,mobile:a}),!c(t).some(e=>
1"content"in e&&e.content.trim())&&(0,n.jsx)("p",{className:"text-xs",children:"Your email appears here as you writeâ¦"})]}),(0,n.jsxs)("p",{className:"text-[8.5px] text-[#62626c] text-center mt-2",style:{color:(0,f.TO)(i.backgroundColor)},children:[s," \xb7 Unsubscribe"]})]})})}function ee(e){let{onChoose:t}=e,s=(0,i.Kg)(),a=(0,l.useRef)(0),[r,o]=(0,l.useState)([]),[c,d]=(0,l.useState)(null),[u,m]=(0,l.useState)(!0),[x,h]=(0,l.useState)(""),p=(0,l.useCallback)(async e=>{let t=++a.current;m(!0),h("");try{let n=await s("libraryList",{kind:"template",...e&&{cursor:e}});if(t!==a.current)return;o(t=>e?[...t,...n.items]:n.items),d(n.nextCursor)}catch(e){t===a.current&&h((0,T.Q)(e))}finally{t===a.current&&m(!1)}},[s]);return(0,l.useEffect)(()=>(p(),()=>{a.current++}),[p]),(0,n.jsxs)("div",{className:"space-y-3",children:[r.map(e=>(0,n.jsxs)("button",{onClick:()=>t(e.id),className:"block w-full text-left rounded-xl border border-card p-4 hover:bg-white/[0.04]",children:[(0,n.jsx)("span",{className:"block text-sm font-medium text-t1",children:e.name}),e.description&&(0,n.jsx)("span",{className:"block text-xs text-t2 mt-1",children:e.description})]},e.id)),u&&(0,n.jsx)("p",{role:"status",className:"text-sm text-t2",children:"Loading templatesâ¦"}),!u&&!x&&!r.length&&(0,n.jsx)("p",{className:"text-sm text-t2",children:"No templates yet. Save a design with âSave to libraryâ in any email to reuse it here."}),x&&(0,n.jsxs)("p",{role:"alert",className:"text-sm text-negative-ink",children:[x," ",(0,n.jsx)("button",{className:"underline",onClick:()=>void p(),children:"Try again"})]}),c&&(0,n.jsx)("button",{disabled:u,onClick:()=>void p(c),className:"text-sm underline text-t2",children:"Load more templates"})]})}function et(e){var t,s,g,y,j,T,M,et,es,en,ea,el,ei,er,eo,ec,ed,eu,em;let{campaignId:ex,duplicateFromId:eh,libraryId:ep,initialGoal:eb,initialLibraryKind:eg,onClose:ev,onSaved:ef,sequenceMode:ey=!1,contentOnlyTitle:ej,context:eN}=e,ew=(0,i.Kg)(),{workspaceId:ek,canPublish:eS}=(0,i.y$)(),eC=(0,i.G_)("iterateEmailCampaign",S.functions),eI=(0,i.G_)("getPromotableEvents",S.functions),eA=async e=>({data:await eC(e)}),eR=async e=>({data:await eI(e)}),{user:eT,userProfile:eL,notify:eE}=(0,U.Y)(),eD=(0,l.useRef)(null),eB=z.map((e,t)=>({label:e,index:t})).filter(e=>!ey||0===e.index||2===e.index),[eM,eP]=(0,l.useState)(!1),[eF,eO]=(0,l.useState)(!1),[eU,eW]=(0,l.useState)(!eb),[eV,e_]=(0,l.useState)(0),eY=(0,l.useRef)(null),eq=(0,l.useRef)(!1),ez=e=>{var t;eq.current=!0,e===eV?null==(t=eY.current)||t.focus():e_(e)};(0,l.useLayoutEffect)(()=>{if(eq.current){var e;null==(e=eY.current)||e.focus(),eq.current=!1}},[eV]);let[eH,eK]=(0,l.useState)(null),[eG,e$]=(0,l.useState)({}),[eZ,eJ]=(0,l.useState)(""),eQ=(0,L.T)({emailType:eb||((null==eN?void 0:eN.eventId)?"event_promotion":"custom"),rules:[],subject:"",preheader:"",blocks:eb&&K[eb]?K[eb].map(e=>({...e})):[{type:"text",content:""}]}),{subject:eX,preheader:e0,blocks:e1,emailType:e2,rules:e3,emailDesign:e5,brandVoice:e4,brandSource:e6,externalSiteId:e9}=eQ.value,[e7,e8]=(0,l.useState)(null),te=e5||f.eG,tt=(0,f.OR)(te),ts=(0,f.tz)(e5),tn=(0,l.useRef)(ts?f.eG:te);ts||(tn.current=te);let ta=ts?{...te,logoUrl:tn.current.logoUrl,logoAlt:tn.current.logoAlt}:te,tl=e=>eQ.change(t=>({...t,emailType:e})),ti=e=>eQ.change(t=>({...t,rules:e})),tr=e=>eQ.change(t=>({...t,subject:"function"==typeof e?e(t.subject):e}),"subject"),to=(e,t)=>eQ.change(t=>({...t,blocks:"function"==typeof e?e(t.blocks):e}),t),[tc,td]=(0,l.useState)(null),[tu,tm]=(0,l.useState)(!1),tx=ex||(eh?"copy-".concat(eh):ep?"library-".concat(ep):"new-".concat((null==eN?void 0:eN.eventId)||"","-").concat((null==eN?void 0:eN.communityId)||"")),th=eT?(em=ek?"".concat(eT.uid,":").concat(ek):eT.uid,"email-draft:v1:".concat(em,":").concat(tx)):null,[tp,tb]=(0,l.useState)(""),[tg,tv]=(0,l.useState)(ex),[tf,ty]=(0,l.useState)(ep),[tj,tN]=(0,l.useState)(!!(ex||eh||ep)),[tw,tk]=(0,l.useState)(""),[tS,tC]=(0,l.useState)(0),tI=(0,l.useRef)(!1);tI.current=!tj&&!tw;let tA=(0,l.useRef)(0),tR=(0,l.useRef)(ex),tT=(0,l.useRef)(Promise.resolve()),tL=(0,l.useRef)(""),tE=(0,l.useRef)(!1),tD=(0,l.useRef)(""),[tB,tM]=(0,l.useState)("Draft not saved yet"),[tP,tF]=(0,l.useState)(null),[tO,tU]=(0,l.useState)(null),[tW,tV]=(0,l.useState)(!1),[t_,tY]=(0,l.useState)(""),[tq,tz]=(0,l.useState)(!1),[tH,tK]=(0,l.useState)(""),[tG,t$]=(0,l.useState)(""),tZ=(0,l.useRef)(""),[tJ,tQ]=(0,l.useState)((null==eN?void 0:eN.communityId)||""),tX=function(e){let t=(0,i.Kg)(),[s,n]=(0,l.useState)(0),[a,r]=(0,l.useState)(null);(0,l.useEffect)(()=>{let s=!1;return r(null),e&&t("brandGet",{communityId:e}).then(t=>{s||r({id:e,brand:t,error:""})}).catch(t=>{s||r({id:e,brand:null,error:t.message})}),()=>{s=!0}},[t,e,s]);let o=(null==a?void 0:a.id)===e?a:null;return{brand:(null==o?void 0:o.brand)||null,error:(null==o?void 0:o.error)||"",pending:!!e&&!o,reload:()=>n(e=>e+1)}}(tJ),[t0,t1]=(0,l.useState)(!!(null==eN?void 0:eN.communityId)&&!ex&&!eh&&!ep),t2=(0,l.useRef)(eQ.change);t2.current=eQ.change,(0,l.useEffect)(()=>
1{if(!t0||tj||!tu||tc)return;if(tJ!==(null==eN?void 0:eN.communityId))return void t1(!1);if(tX.pending||tX.error)return;let e=tX.brand;(null==e?void 0:e.design)&&t2.current(t=>t.emailDesign||t.brandVoice?t:{...t,emailDesign:e.design,...e.voice&&{brandVoice:e.voice},brandSource:(0,a.Uc)(e)||void 0}),t1(!1)},[t0,tj,tu,tc,tJ,null==eN?void 0:eN.communityId,tX.pending,tX.error,tX.brand]);let[t3,t5]=(0,l.useState)(""),[t4,t6]=(0,l.useState)(!1),[t9,t7]=(0,l.useState)(),[t8,se]=(0,l.useState)(""),[st,ss]=(0,l.useState)(""),[sn,sa]=(0,l.useState)(24),[sl,si]=(0,l.useState)(null),[sr,so]=(0,l.useState)(Intl.DateTimeFormat().resolvedOptions().timeZone),sc=(0,l.useMemo)(()=>{var e,t;return[...new Set([sr,"UTC",...(null==(e=(t=Intl).supportedValuesOf)?void 0:e.call(t,"timeZone"))||[]])]},[sr]),sd=(0,l.useMemo)(()=>sc.map(e=>[e,Z(e)]),[sc]),[su,sm]=(0,l.useState)(null),[sx,sh]=(0,l.useState)(""),[sp,sb]=(0,l.useState)(!1),[sg,sv]=(0,l.useState)(!1),[sf,sy]=(0,l.useState)(""),[sj,sN]=(0,l.useState)(eg||"template"),[sw,sk]=(0,l.useState)([]),[sS,sC]=(0,l.useState)(!1),[sI,sA]=(0,l.useState)([]),[sR,sT]=(0,l.useState)(null),[sL,sE]=(0,l.useState)(null),[sD,sB]=(0,l.useState)([]),[sM,sP]=(0,l.useState)(null),[sF,sO]=(0,l.useState)({}),[sU,sW]=(0,l.useState)({}),sV=(0,l.useRef)({lists:0,communities:0,segments:0,audiences:0}),s_=(0,l.useRef)(0),[sY,sq]=(0,l.useState)(""),[sz,sH]=(0,l.useState)(!1),[sK,sG]=(0,l.useState)(""),[s$,sZ]=(0,l.useState)(null),sJ=e=>{s_.current++,sq(""),sH(!1),sG(""),e()},[sQ,sX]=(0,l.useState)(null),[s0,s1]=(0,l.useState)(""),[s2,s3]=(0,l.useState)({listIds:null}),[s5,s4]=(0,l.useState)([]),[s6,s9]=(0,l.useState)(null),[s7,s8]=(0,l.useState)(null),[ne,nt]=(0,l.useState)([]),[ns,nn]=(0,l.useState)(null),[na,nl]=(0,l.useState)(!1);(0,l.useRef)(0);let[ni,nr]=(0,l.useState)(null),[no,nc]=(0,l.useState)(null),[nd,nu]=(0,l.useState)(null),[nm,nx]=(0,l.useState)(null),[nh,np]=(0,l.useState)("now"),[nb,ng]=(0,l.useState)(""),[nv,nf]=(0,l.useState)(""),[ny,nj]=(0,l.useState)(!1),[nN,nw]=(0,l.useState)(!1),[nk,nS]=(0,l.useState)(null),[nC,nI]=(0,l.useState)(null),[nA,nR]=(0,l.useState)(""),[nT,nL]=(0,l.useState)(""),[nE,nD]=(0,l.useState)(""),[nB,nM]=(0,l.useState)("desktop"),[nP,nF]=(0,l.useState)(!1);(0,l.useEffect)(()=>{let e=eD.current;return tj||tw||!e||e.open||e.showModal(),()=>{null==e||e.close()}},[tj,tw]),(0,l.useEffect)(()=>{let e=ex||eh;if(!e&&!tf)return;let t=!1,s=null;return tN(!0),tk(""),e8(null),(tf?ew("libraryGet",{libraryId:tf}).then(e=>({schemaVersion:2,draft:{...e.draft,name:"newsletter"===e.kind?"".concat(e.name," \xb7 New issue"):"New campaign"}})):ew("get",{campaignId:e}).then(e=>(s=eh?null:e.brandKitUpdate,e.campaign))).then(n=>{if(t)return;let l=n.draft||n,i=2!==n.schemaVersion;if(tA.current=tf||eh||i?0:Number(n.revision||0),tR.current=tf||eh||i?null:e||null,i&&tv(null),e$({excludeListIds:Array.isArray(l.excludeListIds)?l.excludeListIds:[],excludeRules:Array.isArray(l.excludeRules)?l.excludeRules:[]}),tQ("string"==typeof l.collectiveId?l.collectiveId:""),t5("string"==typeof l.replyTo?l.replyTo:""),t6("inbox"===l.replyMode),t7("string"==typeof l.replyDomain?l.replyDomain:void 0),se("string"==typeof l.fromName?l.fromName:""),sa(Number(l.frequencyHours||24)),si("string"==typeof l.newsletterId?l.newsletterId:null),eJ(eh?"".concat(l.name||"Campaign"," (Copy)"):l.name||""),eQ.reset({externalSiteId:"string"==typeof l.externalSiteId?l.externalSiteId:void 0,...l.brandVoice?{brandVoice:l.brandVoice}:{},...(0,a.pl)(l.brandSource)?{brandSource:l.brandSource}:{},...l.emailDesign?{emailDesign:l.emailDesign}:{},emailType:l.emailType||"newsletter",rules:Array.isArray(l.rules)?l.rules:[],subject:l.subject||"",preheader:l.preheaderText||"",blocks:Array.isArray(l.bodyBlocks)?l.bodyBlocks:l.body?function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],s=[];for(let n of e.split(/\n{2,}/)){let e=n.trim();if(!e)continue;let a=/^\[\[KEEP_BLOCK:(\d+)\]\]$/.exec(e);if(a&&t[Number(a[1])]){s.push(t[Number(a[1])]);continue}if("---"===e){s.push({type:"divider"});continue}let l=/^##\s+([\s\S]+)$/.exec(e);if(l){s.push({type:"heading",content:l[1].trim()});continue}let i=/^\[\[BUTTON:\s*([^\]]+)\]\]\(([^)\s]+)\)$/.exec(e);if(i){let e=u(i[2]);e&&s.push({type:"button",content:i[1].trim(),href:e});continue}s.push({type:"text",content:e})}return s}
1(String(l.body)):[{type:"text",content:""}]}),"string"==typeof l.timezone&&so(l.timezone),"number"==typeof l.expiresAtMs){let e=Object.fromEntries(new Intl.DateTimeFormat("en-CA",{timeZone:"string"==typeof l.timezone?l.timezone:sr,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(l.expiresAtMs).map(e=>[e.type,e.value]));ss("".concat(e.year,"-").concat(e.month,"-").concat(e.day))}l.networkFilters&&"object"==typeof l.networkFilters&&s3(l.networkFilters),"string"==typeof l.attachedPromoCode&&nu(l.attachedPromoCode),"string"==typeof l.eventId&&l.eventId&&nc({eventId:l.eventId,eventName:l.eventName||"Event",eventDateMs:null,role:"host",codes:[]}),eh&&tv(null);let r=s,o=r&&(0,a.pl)({kitId:r.kitId,kitRevision:r.kitRevision})&&r.design&&"object"==typeof r.design;r&&o&&e8({kitId:r.kitId,kitRevision:r.kitRevision,name:"string"==typeof r.name&&r.name?r.name:"Brand kit",design:r.design,...r.voice&&"object"==typeof r.voice?{voice:r.voice}:{}}),tE.current=!tf&&!eh&&!i,tN(!1)}).catch(e=>{t||(tk(e.message),tN(!1))}),()=>{t=!0}},[ex,eh,tf,ew,tS]);let nO=async(e,t)=>{let s=++sV.current[e];sW(t=>({...t,[e]:!0})),sO(t=>({...t,[e]:""}));try{let n=await ew("audiences"===e?"libraryList":"sources",{kind:"audiences"===e?"segment":e,...t?{cursor:t}:{}});if(s!==sV.current[e])return;"lists"===e?(nt(e=>t?[...e,...n.items.filter(t=>!e.some(e=>e.id===t.id))]:n.items),sE(n.nextCursor)):"communities"===e?(sA(e=>[...new Map([...t?e:[],...n.items].map(e=>[e.id,e])).values()]),sT(n.nextCursor)):"segments"===e?(s4(e=>t?[...e,...n.items.filter(t=>!e.some(e=>e.id===t.id))]:n.items),s9(n.nextCursor)):(sB(e=>t?[...e,...n.items.filter(t=>!e.some(e=>e.id===t.id))]:n.items),sP(n.nextCursor))}catch(t){s===sV.current[e]&&sO(s=>({...s,[e]:t.message}))}finally{s===sV.current[e]&&sW(t=>({...t,[e]:!1}))}},nU=(e,t)=>nO(e,t),nW=e=>nO("segments",e),nV=e=>nO("audiences",e),n_=async e=>{let t=++s_.current;sq(e),sH(!0),sG("");try{let{draft:s}=await ew("libraryGet",{libraryId:e});if(t!==s_.current)return;s3(s.networkFilters||{listIds:null}),ti(s.rules||[]),e$({excludeListIds:s.excludeListIds,excludeRules:s.excludeRules}),tQ(s.collectiveId||""),s8(null)}catch(e){t===s_.current&&sG(e.message)}finally{t===s_.current&&sH(!1)}},nY=async()=>{if(sf.trim()){sC(!0);try{let e=await n8.current(),t=await ew("librarySave",{campaignId:e,campaignRevision:tA.current,name:sf,kind:sj,..."section"===sj&&{blockIndexes:sw}});"newsletter"===sj&&si(t.id),"segment"===sj&&nV(),sv(!1),sy(""),eE({type:"success",message:"Saved to your email library."})}catch(e){tF(e.message)}finally{sC(!1)}}};(0,l.useEffect)(()=>{if(!eT)return;nW(),nU("lists"),nU("communities"),nV();let e=ek?(ew("sources",{kind:"domains"}).then(e=>nx(e.items)).catch(()=>nx([])),()=>{}):(0,F.onSnapshot)((0,F.collection)(S.db,"users/".concat(eT.uid,"/emailDomains")),e=>nx(e.docs.map(e=>({id:e.id,...e.data()}))),()=>nx([]));return eR({}).then(e=>nr(e.data.events||[])).catch(()=>nr([])),()=>{for(let t of(e(),s_.current++,Object.keys(sV.current)))sV.current[t]++}},[eT,ek]),(0,l.useEffect)(()=>{if(!tW||!tg)return;let e=!1,t=async()=>{try{var t,s,n;let a=await ew("get",{campaignId:tg});if(e)return;if(tU(a.snapshot),(null==(t=a.snapshot)?void 0:t.status)!=="preparing"){if((null==(s=a.snapshot)?void 0:s.status)==="ready"){let t=await ew("review",{campaignId:tg,expectedRevision:a.snapshot.revision});if(e)return;sX(t),tK(t.html),s1(t.text),nn({matched:a.snapshot.scanned,sendable:a.snapshot.count,suppressed:a.snapshot.permissionExcluded||0,missingListIds:a.snapshot.missingLists||[]}),t$(tZ.current)}else tY((null==(n=a.snapshot)?void 0:n.status)==="superseded"?"The draft changed while the audience was being prepared. Prepare it again.":"The audience couldnât be prepared. Try again.");tV(!1)}}catch(t){e||(tY(t.message),tV(!1))}};t();let s=setInterval(t,2e3);return()=>{e=!0,clearInterval(s)}},[tW,tg]);let nq=(0,l.useMemo)(()=>{var e,t;let s=(null!=nm?nm:[]).filter(e=>"verified"===e.status);return null!=(t=null!=(e=s.find(e=>e.isDefault))?e:s[0])?t:null},[nm]),nz=(0,l.useMemo)(()=>nq?"".concat(nq.fromLocalPart||"events","@").concat(nq.domain):(null==eL?void 0:eL.firstName)?"".concat(eL.firstName).concat(eL.lastName?" ".concat(eL.lastName):""):"You",[nq,eL]),nH=(0,l.useCallback)(async(e,t)=>{let s=e.trim();if(s&&!nk){nS(t),nI(null),nR("");try{let e=await n8.current();sh(tL.current);let n=await eA({instruction:s,campaignId:e,expectedRevision:tA.current,editTarget:"subject"===t||"plan"===t||/^block\d+$/.test(t)?t:"all"});sm(n.data),nI(n.data.note||"Suggestion ready to review.")}catch(e){nR(e.message||"That didnât work â try again.")}finally{nS(null)}}},[eX,e0,e1,no,nk]),nK=(e,t)=>to(s=>s.map((s,n)=>n===e?{...s,...t}:s),"block-".concat(e)),nG=(e,t)=>
1to(s=>{let n=e+t;if(n<0||n>=s.length)return s;let a=[...s];return[a[e],a[n]]=[a[n],a[e]],a}),n$=e=>to(t=>60>=m([...t,e])?[...t,e]:t),nZ=null,nJ="";if(st)try{nZ=(0,D.e)(st,"23:59",sr)+59999}catch(e){nJ=e.message}let nQ=t8.trim()||(ek?null==nq||null==(t=nq.companyName)?void 0:t.trim():"")||[null==eL?void 0:eL.firstName,null==eL?void 0:eL.lastName].filter(Boolean).join(" "),nX=()=>{var e,t;return{name:eZ.trim()||eX.trim()||"Untitled campaign",emailType:e2||"newsletter",subject:eX.trim(),preheaderText:e0.trim(),bodyBlocks:e1,...e4&&{brandVoice:e4},...e5&&{emailDesign:e5},...e6&&{brandSource:e6},fromName:nQ||"Your host",replyTo:t3,...!tJ&&e9&&{externalSiteId:e9},...t4&&{replyMode:"inbox",...t9&&{replyDomain:t9}},audienceType:tJ?"community_members":"network_segment",collectiveId:tJ||null,networkFilters:s2,rules:e3,...(null==(e=eG.excludeListIds)?void 0:e.length)&&{excludeListIds:eG.excludeListIds},...(null==(t=eG.excludeRules)?void 0:t.length)&&{excludeRules:eG.excludeRules},eventId:(null==no?void 0:no.eventId)||(null==eN?void 0:eN.eventId)||null,newsletterId:sl,timezone:sr,frequencyHours:sn,attachedPromoCode:nd,expiresAtMs:nZ}},n0=JSON.stringify(nX());tD.current=n0;let n1=(0,l.useRef)(null);null!==n1.current||tj||tw||(n1.current=n0);let n2=!eX.trim()&&!eZ.trim()&&!e0.trim()&&c(e1).every(e=>"divider"===e.type||!("content"in e)||!e.content.trim()||"Hi {{firstName}},"===e.content.trim()),n3=!tR.current&&!tg&&(n0===n1.current||n2),n5=n3&&!ex&&!eh&&!tf&&!ey&&!eg;(0,l.useEffect)(()=>{!tj&&tE.current&&(tL.current=n0,tM("All changes saved"),tE.current=!1)},[tj,n0]),(0,l.useEffect)(()=>{if(!tj&&!tw&&!tu&&th){try{let e=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Date.now();try{let n=JSON.parse(e.getItem(t)||"null");if(!n)return null;if(1!==n.version||!Number.isSafeInteger(n.revision)||!Number.isFinite(n.atMs)||s-n.atMs>6048e5||!n.draft||"object"!=typeof n.draft||JSON.stringify(n.draft).length>15e4)return e.removeItem(t),null;return n}catch(e){return null}}(window.localStorage,th);e&&JSON.stringify(e.draft)!==n0&&td(e)}catch(e){tb("This browser could not read a recovery copy. Keep this window open until your draft is saved.")}tm(!0)}},[tj,tw,tu,th,n0]);let n4=e=>{if(th)try{window.localStorage.setItem(th,JSON.stringify({version:1,campaignId:tR.current,revision:tA.current,draft:e,atMs:Date.now()}))}catch(e){tb("This browser could not keep a recovery copy. Keep this window open until your draft is saved.")}};(0,l.useEffect)(()=>{tj||tw||!tu||tc||n3||n0===tL.current||n4(JSON.parse(n0))},[n0,tj,tw,tu,tc,th]);let n6=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(tc){nj(!0);try{if(!e&&tc.campaignId){let{campaign:e}=await ew("get",{campaignId:tc.campaignId});if(e.revision!==tc.revision||!["draft","ready","preparing"].includes(e.status))throw Error("The server version changed. Restore your edits as a new draft to keep both versions.")}let t=tc.draft;t1(!1),e$({excludeListIds:Array.isArray(t.excludeListIds)?t.excludeListIds:[],excludeRules:Array.isArray(t.excludeRules)?t.excludeRules:[]}),tR.current=e?null:tc.campaignId,tA.current=e?0:tc.revision,tv(tR.current),tL.current="",eQ.reset({externalSiteId:"string"==typeof t.externalSiteId?t.externalSiteId:void 0,...t.brandVoice?{brandVoice:t.brandVoice}:{},...(0,a.pl)(t.brandSource)?{brandSource:t.brandSource}:{},...t.emailDesign?{emailDesign:t.emailDesign}:{},emailType:t.emailType||"newsletter",rules:Array.isArray(t.rules)?t.rules:[],subject:String(t.subject||""),preheader:String(t.preheaderText||""),blocks:Array.isArray(t.bodyBlocks)?t.bodyBlocks:[]}),eJ(String(t.name||"")),tl(t.emailType||"custom"),se(String(t.fromName||"")),t5(String(t.replyTo||"")),t6("inbox"===t.replyMode),t7("string"==typeof t.replyDomain?t.replyDomain:void 0),s3(t.networkFilters||{listIds:null}),ti(t.rules||[]),tQ(String(t.collectiveId||"")),si(t.newsletterId||null),nu(t.attachedPromoCode||null),sa(Number(t.frequencyHours||24));let s=String(t.timezone||"UTC");if(so(s),"number"==typeof t.expiresAtMs){let e=Object.fromEntries(new Intl.DateTimeFormat("en-CA",{timeZone:s,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(t.expiresAtMs).map(e=>[e.type,e.value]));ss("".concat(e.year,"-").concat(e.month,"-").concat(e.day))}else ss("");nc("string"==typeof t.eventId&&t.eventId?{eventId:t.eventId,eventName:"Selected event",eventDateMs:null,role:"host",codes:[]}:null),tF(null),td(null),tU(null),t$(""),tM("Recovered edits. Savingâ¦")}catch(e){tF(e.message)}finally{nj(!1)}}},n9=(0,l.useRef)(null),n7=()=>
1{if(!tI.current)return Promise.reject(Error("Open the original draft before saving."));if(sz||sK)return Promise.reject(Error("Finish choosing your saved audience before saving."));if(t0)return Promise.reject(Error("Wait for the community brand, or choose to keep your current style."));if(tc||!tu)return Promise.reject(Error("Choose which recovered draft to keep before saving."));if(nJ)return Promise.reject(Error(nJ));if(ts)return Promise.reject(Error(ts));let e=nX(),t=JSON.stringify(e),s=tT.current.catch(()=>void 0).then(async()=>{var s;if(t===tL.current&&tR.current)return tR.current;tR.current||(tR.current=(0,O.k)()),(null==(s=n9.current)?void 0:s.key)!==t&&(n9.current={key:t,requestId:(0,O.k)()}),n4(e),tM("Savingâ¦");let n=await ew("save",{campaignId:tR.current,expectedRevision:tA.current,saveRequestId:n9.current.requestId,draft:e});if(tR.current=n.campaignId,tA.current=n.revision,tL.current=t,null==ef||ef(n.campaignId,{name:String(e.name||""),subject:String(e.subject||"")}),tv(n.campaignId),tM(tD.current===t?"All changes saved":"Unsaved changes"),tF(null),tU(null),nn(null),t$(""),tD.current===t)try{th&&window.localStorage.removeItem(th)}catch(e){}return n.campaignId});return tT.current=s,s},n8=(0,l.useRef)(n7);n8.current=n7,(0,l.useEffect)(()=>{if(tj||tw||sz||sK||t0||!tu||tc||tP||tW||nN||n0===tL.current||(tM(tR.current?"Unsaved changes":"Draft not saved yet"),n3||ts))return;let e=setTimeout(()=>{n8.current().catch(e=>{tF(e.message),tM("Changes need attention")})},1e3);return()=>clearTimeout(e)},[n0,tj,tw,sz,sK,t0,tu,tc,n3,ts,tW,nN,tP]),(0,l.useEffect)(()=>{let e=e=>{tI.current&&tD.current!==tL.current&&(e.preventDefault(),e.returnValue="")};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]);let ae=async()=>{if(!ny&&!nN){nj(!0);try{await n7(),eE({type:"neutral",message:"Draft saved."})}catch(e){tF(e.message)}finally{nj(!1)}}},at=async()=>{if(n3)return void ev();nj(!0);try{await n7(),ev()}catch(e){tF(e.message)}finally{nj(!1)}},as=async()=>{tY(""),nj(!0);try{let e=await n7();tZ.current=tL.current,await ew("prepare",{campaignId:e,expectedRevision:tA.current});let t=await ew("preview",{campaignId:e});tK(t.html),tV(!0),3!==eV&&ez(3)}catch(e){tY(e.message)}finally{nj(!1)}},an=async()=>{tY(""),nj(!0);try{if(!eT)throw Error("Sign in to send yourself a preview.");await (0,o.cD)(eT);let e=await n7();await ew("test",{campaignId:e,requestId:(0,O.k)()}),eE({type:"success",message:eT.email?"Test sent to ".concat(eT.email,"."):"Test sent to your verified inbox."})}catch(e){tY(e.message)}finally{nj(!1)}},[aa,al]=(0,l.useState)(!1),ai=(0,l.useRef)(null),ar=()=>{var e;let t=JSON.stringify([tg,tA.current,tD.current,nh,"later"===nh?[nb,nv,sr]:null]);return(null==(e=ai.current)?void 0:e.key)!==t&&(ai.current={key:t,requestId:(0,O.k)()}),ai.current.requestId},ao=async()=>{if(!nN&&!ny&&tg&&ay){tY(""),nw(!0);try{if("later"===nh&&(!nb||!nv))throw Error("Choose the date and time.");await ew("approve",{campaignId:tg,expectedRevision:tA.current,requestId:ar(),..."later"===nh&&{scheduledAtMs:(0,D.e)(nb,nv,sr)}}),eE({type:"success",message:"later"===nh?"Scheduled for ".concat(av,"."):"Approved. Sending starts shortly."}),al(!1),ev()}catch(e){tY(e.message),al(!1)}finally{nw(!1)}}},ac=null===s7&&null===s2.listIds&&!s2.sources&&!s2.eventIds&&!s2.consentBasis&&!s2.tags,ad=tJ?(null==(s=sI.find(e=>e.id===tJ))?void 0:s.name)||"Selected community":ac?"All my contacts".concat(ns?" (".concat(ns.sendable.toLocaleString(),")"):""):s7?"".concat((null==(g=s5.find(e=>e.id===s7))?void 0:g.name)||"Segment").concat(ns?" (".concat(ns.sendable.toLocaleString(),")"):""):"".concat((null!=(ec=s2.listIds)?ec:[]).length," list").concat(1===(null!=(ed=s2.listIds)?ed:[]).length?"":"s").concat(ns?" (".concat(ns.sendable.toLocaleString(),")"):""),au="".concat(ad).concat(e3.length?" \xb7 ".concat(e3.length," condition").concat(1===e3.length?"":"s"):""),am=function(e,t){let s=c(e);if(!s.some(e=>"divider"!==e.type))return"Write your email or add an image or card.";for(let[e,n]of s.entries()){let s="Block ".concat(e+1);if("divider"!==n.type){if("event"===n.type||"community"===n.type){if(!n.entity
1Id)return"".concat(s,": choose the ").concat(n.type," for this card.");continue}if(!n.content.trim())return"".concat(s,": add ").concat("image"===n.type?"an image description":"text",", or remove this block.");if("image"===n.type&&!x(n.src,!0))return"".concat(s,": upload an image with an HTTPS address.");if("button"===n.type&&!n.href)return"".concat(s,": add the buttonâs destination.");for(let e of[..."href"in n&&n.href?[n.href]:[],...Array.from(n.content.matchAll(/\[[^\]]+\]\(([^)\s]+)\)/g),e=>e[1])])if(e===d){if(!t)return"".concat(s,": choose an event in Setup or replace the event link.")}else if(!x(e))return"".concat(s,": use a valid HTTPS, HTTP or email link without a username or password.")}}return null}(e1,(null==no?void 0:no.eventId)||(null==eN?void 0:eN.eventId)),ax=!sz&&!sK&&(!!tJ||null===s2.listIds||s2.listIds.length>0),ah=!!(null==nq||null==(y=nq.physicalAddress)?void 0:y.trim())&&!!(null==nq||null==(j=nq.companyName)?void 0:j.trim()),ap=tG===n0&&(null==tO?void 0:tO.status)==="ready"&&!!sQ,ab=nJ,ag=!1,av="";if(!ab)try{if(new Intl.DateTimeFormat("en",{timeZone:sr}),!Number.isInteger(sn)||sn<24||sn>720)ab="Choose between 24 and 720 hours.";else if(null!==nZ&&nZ<=Date.now())ab="Choose a last send date in the future.";else if("later"===nh)if(nb&&nv){let e=(0,D.e)(nb,nv,sr);av="".concat(new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short",timeZone:sr}).format(e)," \xb7 ").concat(Z(sr)),e<=Date.now()?ab="Choose a send date and time in the future.":null!==nZ&&e>nZ&&(ab="Schedule the email before its last send date.")}else ag=!0}catch(e){ab=e.message}let af=!!eX.trim()&&!am&&!ts&&ax&&!!nQ,ay=eS&&af&&ah&&ap&&((null==tO?void 0:tO.count)||0)>0&&!!(null==sQ?void 0:sQ.allowance.allowed)&&!ab&&!ag,aj=[{label:"Subject",ready:!!eX.trim(),note:eX.trim()||"Add the subject people will see in their inbox.",action:"Add subject",run:()=>ez(0)},{label:"Content",ready:!am&&!ts,note:am||ts||"Content is filled in. Check the preview before approval.",action:"Edit content",run:()=>ez(2)},{label:"Audience",ready:ax,note:sz?"Your selected saved audience is still loading.":sK?"The saved audience was not applied. Retry it or keep your current audience.":ax?au:"Choose a list, all your contacts or a community.",action:"Choose audience",run:()=>ez(1)},nQ?{label:"Sender",ready:ah,note:ah?nz:ek?"The workspace owner needs to verify a domain and save the business name and mailing address.":"Verify your domain and save your business name and mailing address.",action:ek?void 0:"Set up sender",run:()=>tz(!0)}:{label:"Sender",ready:!1,note:"Add the sender name people will see in their inbox.",action:"Add sender name",run:()=>ez(0)},{label:"Audience review",ready:ap&&((null==tO?void 0:tO.count)||0)>0,note:ap?(null==tO?void 0:tO.count)?"".concat(tO.count.toLocaleString()," people can receive it. Permission is checked again when it sends."):"Nobody is eligible. Check your lists and conditions; people without current permission stay excluded.":tW?"Checking permission and counting peopleâ¦":"Prepare the audience below to check permission and see the exact email.",action:!ap||(null==tO?void 0:tO.count)?void 0:"Adjust audience",run:()=>ez(1)}],aN=(0,l.useRef)({armed:!1,key:""});(0,l.useEffect)(()=>{aN.current.armed=3===eV&&!ey},[eV,ey]),(0,l.useEffect)(()=>{let e=aN.current;!e.armed||ap||tW||ny||nN||!af||tP||!tu||tc||t0||!tI.current||(e.armed=!1,e.key!==n0&&(e.key=n0,as()))});let aw=(e,t,s)=>(0,n.jsx)("button",{onClick:()=>nH(t,s),disabled:!!nk,className:"px-2.5 py-1 text-[10.5px] text-t2 bg-white/[0.05] hover:bg-white/[0.09] rounded-full disabled:opacity-40 transition-colors",children:nk===s?"â¦":e},e),ak=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"bg-card border border-card rounded-xl p-3.5 space-y-2.5",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("input",{"aria-label":"Ask AI to revise this email",value:nT,onChange:e=>nL(e.target.value),onKeyDown:e=>{"Enter"===e.key&&nT.trim()&&(nH(nT,sp?"plan":"command"),nL(""))},placeholder:"⦠Tell AI what to write or change â âdraft a casual inviteâ, âadd a section about parkingâ, âmake it shorterââ¦",disabled:!!nk,className:Q}),(0,n.jsx)("button",{onClick:()=>{nT.trim()&&(nH(nT,sp?"plan":"command"),nL(""))},disabled:!!nk||!nT.trim(),className:"shrink-0 px-4 py-2 text-xs font-medium bg-white text-surface-base rounded-lg hover:bg-white/90 disabled:opacity-40 transition-colors",children:["command","plan"].includes(nk||"")?"Writingâ¦":"Go"})]}
1),!ey&&(0,n.jsxs)("label",{className:"flex justify-end items-center gap-2 text-xs text-t2 -mt-1",children:[(0,n.jsx)("input",{type:"checkbox",checked:sp,disabled:!!nk,onChange:e=>sb(e.target.checked)}),"With Go, also suggest an audience, goal and timing"]}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5",children:[aw("Draft it for me","Draft the full email from what you know â subject, preheader and body.","chip"),aw("Shorter","Make the whole email meaningfully shorter without losing the essentials.","chip"),aw("Warmer","Make the tone warmer and more personal.","chip"),aw("More detail","Expand with more concrete detail where it feels thin.","chip"),aw("Fix grammar","Fix grammar, spelling and awkward phrasing only â change nothing else.","chip"),nC&&(0,n.jsx)("span",{role:"status",className:"text-xs text-t2 ml-auto flex items-center gap-2",children:nC})]}),nA&&(0,n.jsx)("p",{role:"alert",className:"text-sm text-negative-ink",children:nA})]}),su&&(0,n.jsxs)("section",{className:"bg-card border border-card rounded-xl p-4 space-y-3","aria-label":"Review AI suggestion",children:[(0,n.jsx)("h3",{className:"studio-body-strong",children:"Review suggested changes"}),su.provenance&&(0,n.jsxs)("p",{className:"studio-caption",children:["Based on: ",su.provenance.join(" \xb7 ")]}),sx!==n0&&(0,n.jsx)("p",{className:"text-xs text-attention-ink",children:"Your draft changed while this suggestion was being written. Copy useful parts or request a fresh suggestion."}),su.plan&&(0,n.jsx)("div",{className:"space-y-3 text-sm text-t2",children:su.plan.clarification?(0,n.jsx)("p",{role:"status",children:su.plan.clarification}):(0,n.jsxs)(n.Fragment,{children:[su.plan.goal&&(0,n.jsxs)("p",{children:["Suggested type: ",(null==(T=H.find(e=>{var t;return e.key===(null==(t=su.plan)?void 0:t.goal)}))?void 0:T.label)||"Custom"]}),su.plan.audienceSummary&&(0,n.jsx)("p",{children:su.plan.audienceSummary}),su.plan.rules&&(0,n.jsx)("ul",{className:"space-y-2",children:su.plan.rules.map((e,t)=>(0,n.jsx)("li",{children:function(e){var t,s,n;let a=R.has(e.field)&&"eq"===e.op,l=a?":":({gte:"at least",lte:"at most",eq:"exactly",contains:"includes",known:"is known",unknown:"is unknown"})[e.op],i=["known","unknown"].includes(e.op)?"":a?Number(null!=(t=e.value)?t:1)?"yes":"no":["netSpend","externalSpend"].includes(e.field)?(0,I.c)(Number(e.value)||0,e.currency||"USD"):String(null!=(s=e.value)?s:0);return"Group ".concat((null!=(n=e.group)?n:0)+1,": ").concat(A[e.field]).concat(":"===l?":":" ".concat(l)).concat(i?" ".concat(i):"").concat(e.campaignId?" for the selected campaign":"").concat(e.emailStepId?" for the selected earlier email step":"").concat(e.surveyId?" for the selected survey":"").concat(e.siteId?" for the selected website":"").concat(e.eventId?" for the selected event":"").concat(e.communityId?" in the selected community":"")}(e)},t))}),su.plan.timing&&(0,n.jsxs)("p",{children:["Suggested timing: ",new Date(su.plan.timing.suggestedAtMs).toLocaleString(void 0,{timeZone:su.plan.timing.timezone})," \xb7 ",Z(su.plan.timing.timezone),". ",su.plan.timing.reason," Choose the actual send time at final review; this suggestion does not schedule anything."]})]})}),(0,n.jsx)("p",{className:"text-sm text-t1",children:su.subject}),(0,n.jsx)("p",{className:"text-xs text-t2 whitespace-pre-wrap max-h-48 overflow-auto",children:function(e){let t=[];for(let s of c(e))"divider"===s.type?t.push("---"):"button"===s.type?t.push("".concat(s.content,": ").concat(s.href)):"image"===s.type||"event"===s.type||"community"===s.type||"heading"===s.type?t.push(s.content):t.push(s.content.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,"$1 ($2)")),t.push("");return t.join("\n").trim()}(su.blocks)}),(0,n.jsxs)("div",{className:"flex gap-3",children:[(0,n.jsx)("button",{disabled:sx!==n0||!!(null==(M=su.plan)?void 0:M.clarification),className:"px-4 py-2 rounded-lg bg-white text-[rgb(var(--surface-base))] text-sm disabled:opacity-40",onClick:()=>{sJ(()=>{}),eQ.change(e=>{var t,s;return{...e,subject:su.subject,preheader:su.preheaderText,blocks:su.blocks,...(null==(t=su.plan)?void 0:t.goal)&&{emailType:su.plan.goal},...(null==(s=su.plan)?void 0:s.rules)&&{rules:su.plan.rules}}}),sm(null)},children:"Apply suggestion"}),(0,n.jsx)("button",{className:"text-sm text-t2",onClick:()=>sm(null),children:"Keep my draft"})]})]}),(0,n.jsx)(N.A,{value:e5,voice:e4,onChange:(e,t,s)=>eQ.change(n=>({...n,emailDesign:e,...t&&{brandVoice:t},...void 0!==s&&{brandSource:s||void 0}}))}),(0,n.jsx)("div",{className:"rounded-xl overflow-hidden border border-white/[0.08]",children:(0,n.jsxs)("div",{className:"bg-[#f4f4f6] p-4 sm:p-6",style:{backgroundColor:te.backgroundColor},children:[(0,n.jsxs)("div",{className:"bg-[#ffffff] rounded-xl p-5 sm:p-7 space-y-1 [color-scheme:light]",style:{backgroundColor:te.paperColor,color:te.textColor,fontFamily:f.gW[te.font],borderRadius:12*("letter"!==te.layout),padding:"compact"===te.density?20:void 0},children:[ta.logoUrl&&(0,n.jsx)("img",{src:ta.logoUrl,alt:ta.logoAlt,style:{width:ta.logoWidth,maxWidth:"100%",height:"auto",marginBottom:24}}),e1.map((e,t)=>(0,n.jsxs)("div",{className:"group relative",children:[(0,n.jsxs)("div",{className:"ml-auto mb-1 w-fit sm:mb-0 sm:absolute sm:-right-1 sm:top-0 sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100 transition-opacity flex gap-0.5 bg-[#ffffff] shadow-sm border border-[#e5e5ea] rounded-md px-1 py-0.5 z-10",children:[["text","heading","button"].includes(e.type)&&"content"in e&&e.content.trim()&&(0,n.jsx)("button",{onClick:()=>nH("Rewrite ONLY this ".concat("heading"===e.type?"heading":"paragraph",', keep everything else exactly as is: "').concat(e.content.slice(0,500),'"'),"block".concat(t)),className:"min-w-8 min-h-8 sm:min-w-0 sm:min-h-0 text-sm sm:text-[10px] text-[#62626c] hover:text-[#1a1a1e] px-1",title:"AI: rewrite this block","aria-label":"Ask AI to rewrite block ".concat(t+1),children:nk==="block".concat(t)?"â¦":"â¦"}),(0,n.jsx)("button",{"aria-label":"Move block ".concat(t+1," up"),disabled:0===t,onClick:()=>nG(t,-1),className:"min-w-8 min-h-8 sm:min-w-0 sm:min-h-0 text-sm sm:text-[10px] text-[#62626c] hover:text-[#1a1a1e] px-1",title:"Move up",children:"â"}),(0,n.jsx)("button",{"aria-label":"Move block ".concat(t+1," down"),disabled:t===e1.length-1,onClick:()=>nG(t,1),className:"min-w-8 min-h-8 sm:min-w-0 sm:min-h-0 text-sm sm:text-[10px] text-[#62626c] hover:text-[#1a1a1e] px-1",title:"Move down",children:"â"}),(0,n.jsx)("button",{"aria-label":"Remove block ".concat(t+1),onClick:()=>to(e=>e.filter((e,s)=>s!==t)),className:"min-w-8 min-h-8 sm:min-w-0 sm:min-h-0 text-sm sm:text-[10px] text-[#62626c] hover:text-[#b00020] px-1",title:"Remove",children:"â"})]}
1),"columns"===e.type&&(0,n.jsx)(v,{value:e,onChange:e=>nK(t,e),remaining:60-m(e1),events:ni||[],communityId:tJ||void 0}),"heading"===e.type&&(0,n.jsx)("input",{style:{color:te.textColor},"aria-label":"Heading block ".concat(t+1),value:e.content,onChange:e=>nK(t,{content:e.target.value}),placeholder:"Heading",className:"w-full bg-transparent border-none outline-none text-[21px] font-bold text-[#0a0a0c] placeholder:text-[#73737b] leading-snug"}),"text"===e.type&&(0,n.jsx)("textarea",{style:{color:te.textColor},"aria-label":"Text block ".concat(t+1),value:e.content,onChange:e=>{nK(t,{content:e.target.value}),e.target.style.height="auto",e.target.style.height="".concat(e.target.scrollHeight,"px")},ref:e=>{e&&(e.style.height="auto",e.style.height="".concat(e.scrollHeight,"px"))},placeholder:"Write⦠(**bold**, *italic*, [link](https://â¦))",className:"w-full bg-transparent border-none outline-none resize-none text-[15px] text-[#1a1a1e] placeholder:text-[#73737b] leading-relaxed",rows:1}),"button"===e.type&&(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[(0,n.jsx)("span",{className:"inline-flex rounded-[10px] bg-[#0a0a0c]",style:{backgroundColor:te.accentColor,borderRadius:tt.buttonRadius},children:(0,n.jsx)("input",{style:{color:tt.buttonText},"aria-label":"Button label ".concat(t+1),value:e.content,onChange:e=>nK(t,{content:e.target.value}),placeholder:"Button text",className:"bg-transparent border-none outline-none text-center text-[14px] font-semibold text-[#ffffff] placeholder:text-[#ffffff]/70 px-6 py-2.5 w-40"})}),e.href===d?(0,n.jsxs)("span",{className:"text-[10px] text-[#62626c] bg-[#f4f4f6] rounded-full px-2.5 py-1",children:["â event page (tracked",nd?" \xb7 ".concat(nd," auto-applies"):"",")"]}):(0,n.jsx)("input",{"aria-label":"Button link ".concat(t+1),value:e.href,onChange:e=>nK(t,{href:e.target.value}),placeholder:"Button link, e.g. https://â¦","aria-invalid":!!e.href&&!u(e.href)||void 0,className:"flex-1 min-w-[140px] bg-[#f4f4f6] rounded-lg px-2.5 py-1.5 text-[11px] outline-none border ".concat(!e.href||u(e.href)?"text-[#1a1a1e] border-transparent":"text-[#b00020] border-[#b00020]/40")})]}),"image"===e.type&&(0,n.jsxs)("div",{className:"rounded-lg bg-[#f4f4f6] p-3 space-y-2 text-[#1a1a1e] text-sm",children:[(0,n.jsx)(p.A,{onUploaded:e=>nK(t,{src:e})}),(0,n.jsx)(b.A,{onSelect:e=>nK(t,{src:e.url,content:e.alt||e.name})}),(0,n.jsxs)("label",{className:"block",children:["Image link",(0,n.jsx)("input",{value:e.src,onChange:e=>nK(t,{src:e.target.value}),placeholder:"https://â¦",className:"block w-full p-2 rounded bg-[#ffffff] mt-1"})]}),(0,n.jsxs)("label",{className:"block",children:["Image description",(0,n.jsx)("input",{value:e.content,maxLength:300,onChange:e=>nK(t,{content:e.target.value}),placeholder:"Describe the image for people who cannot see it",className:"block w-full p-2 rounded bg-[#ffffff] mt-1"})]}),(0,n.jsxs)("label",{className:"block",children:["Link (optional)",(0,n.jsx)("input",{value:e.href||"",onChange:e=>nK(t,{href:e.target.value}),placeholder:"https://â¦",className:"block w-full p-2 rounded bg-[#ffffff] mt-1"})]})]}),("event"===e.type||"community"===e.type)&&(0,n.jsxs)("div",{className:"rounded-lg border border-[#e5e5ea] p-4 text-[#1a1a1e] text-sm",children:[(0,n.jsx)("p",{className:"font-semibold",children:"event"===e.type?"Event card":"Community card"}),(0,n.jsx)("p",{className:"text-xs text-[#62626c] mt-1",children:"Card details show in the final preview."}),"event"===e.type&&(0,n.jsxs)("select",{"aria-label":"Event for this card",value:e.entityId,onChange:e=>nK(t,{entityId:e.target.value}),className:"mt-2 w-full p-2 rounded bg-[#f4f4f6]",children:[!(ni||[]).some(t=>t.eventId===e.entityId)&&(0,n.jsx)("option",{value:e.entityId,children:e.content||"Selected event"}),(ni||[]).map(e=>(0,n.jsx)("option",{value:e.eventId,children:e.eventName},e.eventId))]})]}),"divider"===e.type&&(0,n.jsx)("hr",{className:"border-none border-t border-[#e5e5ea] my-3",style:{borderTopWidth:1}})]},t)),(0,n.jsx)("div",{className:"flex flex-wrap gap-1.5 pt-3",children:[["+ Two columns",()=>n$({type:"columns",columns:[{blocks:[{type:"text",content:""}]},{blocks:[{type:"text",content:""}]}]})],["+ Text",()=>n$({type:"text",content:""})],["+ Heading",()=>n$({type:"heading",content:""})],["+ Button",()=>n$({type:"button",content:"Learn more",href:""})],["+ Divider",()=>n$({type:"divider"})],["+ Image",()=>n$({type:"image",content:"",src:""})],["+ Survey",()=>eP(!0)],...no||(null==eN?void 0:eN.eventId)?[["+ Event card",()=>n$({type:"event",content:"Event",entityId:(null==no?void 0:no.eventId)||eN.eventId})]]:[],...tJ?[["+ Community card",()=>n$({type:"community",content:"Community",entityId:tJ})]]:[]].map(e=>{let[t,s]=e;return(0,n.jsx)("button",{disabled:m(e1)+("+ Two columns"===t?3:1)>60,onClick:s,className:"px-2.5 py-1 text-[11px] text-[#62626c] hover:text-[#1a1a1e] bg-[#f4f4f6] hover:bg-[#ececf0] rounded-md transition-colors",children:t},t)})})]}),(0,n.jsx)("p",{className:"text-[9.5px] text-[#62626c] text-center mt-3",style:{color:(0,f.TO)(te.backgroundColor)},children:"".concat(nz," \xb7 unsubscribe footer added automatically")})]})}),(0,n.jsx)(_,{blockCount:m(e1),onInsert:e=>to(t=>[...t,...e])}),(0,n.jsxs)("p",{className:"text-[10.5px] text-t3",children:["Personalization: ","{{firstName}}"," ","{{lastName}}"," ","{{city}}",no||(null==eN?void 0:eN.eventId)?" \xb7 {{eventName}} {{eventDate}}
1":""," â filled in for each person when it sends."]}),c(e1).some(e=>"image"===e.type)&&(0,n.jsx)("p",{className:"text-[10.5px] text-t3",children:"Images in emails are public. Use artwork you have permission to share."})]});return tj?(0,n.jsx)(E.A,{title:"Opening email",onClose:ev,compact:!0,children:(0,n.jsx)("p",{role:"status",className:"studio-caption",children:"Opening the studioâ¦"})}):tw?(0,n.jsx)(E.A,{title:"Couldnât open this email",onClose:ev,compact:!0,children:(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsx)("p",{role:"alert",className:"text-sm text-t2",children:tw}),(0,n.jsx)("p",{className:"text-sm text-t2",children:"Your original email and any saved recovery copy are unchanged."}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,n.jsx)("button",{className:"px-4 py-2 rounded-lg bg-white text-[rgb(var(--surface-base))] text-sm",onClick:()=>tC(e=>e+1),children:"Retry opening"}),(0,n.jsx)("button",{className:"px-4 py-2 rounded-lg border border-card text-sm",onClick:ev,children:"Back to campaigns"})]})]})}):(0,n.jsxs)("dialog",{ref:eD,"aria-label":"Email campaign editor",onCancel:e=>{e.preventDefault(),at()},className:"fixed inset-0 z-50 m-0 h-[100dvh] max-h-none w-screen max-w-none border-0 p-0 [--text-tertiary:var(--text-secondary)] bg-surface-base text-t1 overflow-y-auto",children:[eH&&(0,n.jsx)(E.A,{title:"Compare two email versions",onClose:()=>eK(null),children:(0,n.jsx)(l.Suspense,{fallback:(0,n.jsx)("p",{children:"Opening A/B testâ¦"}),children:(0,n.jsx)(Y,{initialCampaignId:eH})})}),eF&&(0,n.jsx)(E.A,{title:"Start from a template",onClose:()=>eO(!1),children:(0,n.jsx)(ee,{onChoose:e=>{eO(!1),t1(!1),ty(e)}})}),aa&&(0,n.jsx)(E.A,{compact:!0,title:"later"===nh?"Schedule this email?":"Send this email now?",dismissible:!nN,onClose:()=>al(!1),children:(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("p",{className:"text-sm text-t1",children:["â",eX.trim(),"â goes to ",(0,n.jsxs)("strong",{children:[((null==tO?void 0:tO.count)||0).toLocaleString()," ",(null==tO?void 0:tO.count)===1?"person":"people"]}),"."]}),(0,n.jsxs)("dl",{className:"grid grid-cols-[auto,1fr] gap-x-4 gap-y-2 text-sm",children:[(0,n.jsx)("dt",{className:"text-t2",children:"From"}),(0,n.jsx)("dd",{className:"text-t1 break-words",children:(null==sQ||null==(et=sQ.sender)?void 0:et.from)||nz}),(0,n.jsx)("dt",{className:"text-t2",children:"When"}),(0,n.jsx)("dd",{className:"text-t1",children:"later"===nh?av:"Now, right after you confirm"})]}),(0,n.jsx)("p",{className:"text-xs text-t2",children:"later"===nh?"You can stop it from the campaign list until it starts sending.":"Emails that have gone out canât be recalled."}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,n.jsx)("button",{disabled:nN,onClick:()=>void ao(),className:"px-4 py-2 rounded-lg bg-white text-[rgb(var(--surface-base))] text-sm font-medium disabled:opacity-50",children:nN?"later"===nh?"Schedulingâ¦":"Sendingâ¦":"later"===nh?"Schedule":"Send now"}),(0,n.jsx)("button",{disabled:nN,onClick:()=>al(!1),className:"px-4 py-2 rounded-lg border border-card text-sm",children:"Keep editing"})]})]})}),eM&&(0,n.jsx)(E.A,{title:"Add a survey",onClose:()=>eP(!1),children:(0,n.jsx)(h.A,{communityId:tJ||void 0,onSelect:e=>{n$({type:"button",content:"Share your thoughts",href:e.url}),eP(!1)}})}),tc&&(0,n.jsx)(E.A,{title:"Your unsaved edits are here",onClose:()=>{td(null),tF(null)},children:(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("p",{className:"text-sm text-t2",children:["This browser kept a recovery copy from ",new Date(tc.atMs).toLocaleString(),". Restore it, or keep the current server draft. Restoring never approves or sends an email."]}),tP&&(0,n.jsx)("p",{role:"alert",className:"text-sm text-negative-ink",children:tP}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,n.jsx)("button",{disabled:ny,onClick:()=>void n6(),className:"rounded-lg bg-white text-[rgb(var(--surface-base))] px-4 py-2 text-sm",children:"Restore edits"}),(0,n.jsx)("button",{disabled:ny,onClick:()=>void n6(!0),className:"rounded-lg border border-white/20 px-4 py-2 text-sm",children:"Restore as new draft"}),(0,n.jsx)("button",{disabled:ny,onClick:()=>{try{th&&window.localStorage.removeItem(th)}catch(e){}td(null),tF(null)},className:"text-sm text-t2 underline",children:"Keep current draft"})]})]})}),(0,n.jsxs)("div",{className:"max-w-6xl mx-auto px-4 py-5",children:[tp&&(0,n.jsx)("p",{role:"status",className:"mb-4 text-sm text-attention-ink",children:tp}),e7&&(null==e6?void 0:e6.kitId)===e7.kitId&&e6.kitRevision<e7.kitRevision&&(0,n.jsxs)("div",{role:"status",className:"mb-4 rounded-xl border border-white/15 p-3 text-sm text-t2 flex flex-wrap items-center gap-3",children:[(0,n.jsxs)("p",{children:["Your brand kit â",e7.name,"â changed."]}),(0,n.jsx)("button",{className:"underline",onClick:()=>{eQ.change(e=>({...e,emailDesign:e7.design,...e7.voice&&{brandVoice:e7.voice},brandSource:{kitId:e7.kitId,kitRevision:e7.kitRevision}}))},children:"Apply the update"})]}),tJ&&(0,n.jsx)("div",{className:"mb-4 rounded-xl border border-white/15 p-3 text-sm text-t2",children:tX.pending?(0,n.jsx)("p",{role:"status",children:"Loading community brandâ¦"}):tX.error?(0,n.jsxs)("p",{role:"alert",children:[tX.error," ",(0,n.jsx)("button",{className:"underline",onClick:tX.reload,children:"Retry community brand"}),t0&&(0,n.jsx)("button",{className:"underline ml-3",onClick:()=>{t1(!1),tF(null)},children:"Keep my current style"})]}):(null==(es=tX.brand)?void 0:es.design)?(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,n.jsxs)("p",{children:["Community brand: ",tX.brand.name||"Saved brand"]}),(0,n.jsx)("button",{className:"underline",onClick:()=>{let e=tX.brand;eQ.change(t=>({...t,emailDesign:e.design,...e.voice&&{brandVoice:e.voice},brandSource:(0,a.Uc)(e)||void 0})),t1(!1),tF(null)},children:"Apply community brand"}),(0,n.jsx)("span",{className:"text-xs",children:"Applies logo, colors and voice. You can undo."})]}):(0,n.jsx)("p",{children:"No brand assigned to this community. Choose one in Brand & Assets."})}),(0,n.jsxs)("div",{className:"flex items-start justify-between gap-3 flex-wrap mb-5",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("button",{onClick:()=>void at(),disabled:ny,className:"text-xs text-t3 hover:text-t1 transition-colors",children:ey?ej?"â Back to A/B test":"â Back to sequence":"newsletter"===eg?"â Back to Newsletters":eg?"â Back to Templates":"â Back to Campaigns"}),(0,n.jsx)("h1",{className:"text-xl font-semibold text-t1 mt-1.5",children:ey?ej||"Write your sequence email":"newsletter"===eg?"Create newsletter series":"template"===eg?"Create template":"section"===eg?"Create reusable section":ex?"Edit email":"Create email"}),(0,n.jsx)("p",{className:"studio-caption mt-0.5",children:ey?ej?"Edit this versionâs content. The A/B test controls its audience and launch.":"Write and preview this
1step. Audience, timing and launch are managed in your sequence.":"newsletter"===eg?"Build a consistent starting point for every edition.":eg?"Save a design you can reuse in future emails.":"Design your email, choose your audience, and review before sending."})]}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("button",{onClick:()=>sJ(eQ.undo),disabled:!eQ.canUndo,className:"px-3 py-2 text-xs text-t2 disabled:opacity-30",children:"Undo"}),(0,n.jsx)("button",{onClick:()=>sJ(eQ.redo),disabled:!eQ.canRedo,className:"px-3 py-2 text-xs text-t2 disabled:opacity-30",children:"Redo"}),(0,n.jsx)("button",{onClick:()=>sv(e=>!e),className:"px-3 py-2 text-xs border border-white/15 rounded-lg text-t2",children:"newsletter"===eg?"Save newsletter series":"template"===eg?"Save template":"section"===eg?"Save reusable section":"Save to library"}),ey&&(0,n.jsx)("button",{onClick:()=>void at(),disabled:ny,className:"px-3.5 py-2 text-xs bg-white/[0.06] text-t1 rounded-lg hover:bg-white/[0.1] disabled:opacity-50 transition-colors",children:ny?"Savingâ¦":ej?"Save version":"Save to sequence"}),!ey&&(0,n.jsx)("button",{onClick:()=>ez(3),className:"px-4 py-2 text-xs font-medium bg-white text-surface-base rounded-lg hover:bg-white/90 transition-colors",children:"Review email â"})]})]}),"newsletter"===eg&&(0,n.jsx)("p",{className:"text-sm text-t2 mb-4",children:"Write your first edition and choose its audience, then save your newsletter series. Set the recurring schedule from Newsletters â Manage series. Saving a series does not send it."}),sg&&(0,n.jsxs)("section",{className:"border border-white/15 rounded-xl p-4 mb-5 flex flex-wrap items-end gap-3",children:[(0,n.jsxs)("label",{className:"text-xs text-t2",children:["Save as",(0,n.jsxs)("select",{value:sj,onChange:e=>sN(e.target.value),className:Q,children:[(0,n.jsx)("option",{value:"template",children:"Reusable template"}),(0,n.jsx)("option",{value:"newsletter",children:"Newsletter series"}),(0,n.jsx)("option",{value:"segment",children:"Audience conditions"}),(0,n.jsx)("option",{value:"section",children:"Reusable section"})]})]}),(0,n.jsxs)("label",{className:"text-xs text-t2 flex-1",children:["Name",(0,n.jsx)("input",{value:sf,maxLength:120,onChange:e=>sy(e.target.value),placeholder:"For example: Sunday community notes",className:Q})]}),(0,n.jsx)("button",{disabled:sS||!sf.trim()||"section"===sj&&(!sw.length||sw.length>20),onClick:()=>void nY(),className:"px-4 py-2 bg-white text-[rgb(var(--surface-base))] rounded-lg text-sm disabled:opacity-40",children:sS?"Savingâ¦":"Save"}),(0,n.jsx)("button",{onClick:()=>sv(!1),className:"text-xs text-t2",children:"Cancel"}),"section"===sj&&(0,n.jsxs)("fieldset",{className:"basis-full space-y-2 text-xs text-t2",children:[(0,n.jsx)("legend",{className:"mb-2",children:"Choose up to 20 blocks. The section saves content only."}),e1.map((e,t)=>(0,n.jsxs)("label",{className:"flex gap-2 items-center",children:[(0,n.jsx)("input",{type:"checkbox",checked:sw.includes(t),onChange:e=>sk(s=>e.target.checked?[...s,t]:s.filter(e=>e!==t))}),t+1,". ",e.type,"content"in e&&e.content?" \xb7 ".concat(e.content.slice(0,70)):""]},t))]})]}),(0,n.jsx)("div",{className:"grid grid-cols-2 sm:flex items-center gap-2 mb-5 max-w-xl",children:eB.map((e,t)=>{let{label:s,index:a}=e;return(0,n.jsxs)("div",{className:"flex items-center ".concat(t<eB.length-1?"flex-1 min-w-0":""),children:[(0,n.jsxs)("button",{"aria-current":eV===a?"step":void 0,onClick:()=>ez(a),className:"flex items-center gap-1.5 shrink-0 group",children:[(0,n.jsx)("span",{className:"w-5.5 h-5.5 w-[22px] h-[22px] rounded-full flex items-center justify-center text-[10px] font-semibold border transition-colors ".concat(eV===a?"bg-white text-surface-base border-white":eV>a?"bg-white/[0.1] text-t1 border-white/[0.2]":"bg-transparent text-t3 border-white/[0.12] group-hover:border-white/[0.3]"),children:t+1}),(0,n.jsx)("span",{className:"text-[11px] whitespace-nowrap ".concat(eV===a?"text-t1 font-medium":"text-t3"),children:s})]}),t<eB.length-1&&(0,n.jsx)("div",{className:"hidden sm:block flex-1 h-px mx-2 ".concat(eV>a?"bg-white/[0.25]":"bg-white/[0.08]")})]},s)})}),(0,n.jsxs)("div",{className:"flex flex-col xl:flex-row gap-5 items-start",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0
1w-full space-y-4",children:[0===eV&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"bg-card border border-card rounded-xl p-4 sm:p-5",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3",children:[(0,n.jsx)("h2",{ref:eY,tabIndex:-1,className:"studio-body-strong",children:"Email type"}),n5&&(0,n.jsx)("button",{onClick:()=>eO(!0),className:"text-xs underline text-t2 hover:text-t1",children:"Start from a template"})]}),eU?(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-2.5",children:H.map(e=>(0,n.jsxs)("button",{"aria-pressed":e2===e.key,onClick:()=>{var t;tl(t=e.key),c(e1).every(e=>"divider"===e.type||!("content"in e)||!e.content.trim()||"Hi {{firstName}},"===e.content.trim())&&to(K[t].map(e=>({...e})))},className:"text-left rounded-xl border px-3.5 py-3 transition-colors ".concat(e2===e.key?"border-white bg-white/[0.07]":"border-white/[0.08] bg-white/[0.02] hover:border-white/[0.2]"),children:[(0,n.jsxs)("p",{className:"text-[13px] font-semibold text-t1 flex items-center justify-between",children:[e.label,e2===e.key&&(0,n.jsx)("span",{className:"text-[10px]",children:"â"})]}),(0,n.jsx)("p",{className:"text-[11px] text-t3 mt-0.5",children:e.hint})]},e.key))}):(0,n.jsxs)("p",{className:"text-sm text-t1",children:[(null==(en=H.find(e=>e.key===e2))?void 0:en.label)||"Custom",(0,n.jsx)("button",{onClick:()=>eW(!0),className:"ml-3 text-xs underline text-t2",children:"Change type"})]})]}),(0,n.jsxs)("div",{className:"bg-card border border-card rounded-xl p-4 sm:p-5 grid grid-cols-1 lg:grid-cols-2 gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"studio-label mb-1.5",children:"Campaign name"}),(0,n.jsx)("input",{"aria-label":"Campaign name",value:eZ,onChange:e=>eJ(e.target.value),placeholder:"Internal name â recipients donât see this",className:Q})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("p",{className:"studio-label",children:"Subject line"}),(0,n.jsxs)("div",{className:"relative flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:()=>nF(e=>!e),className:"text-[10.5px] text-t3 hover:text-t1 transition-colors",children:"Insert variable â¾"}),nP&&(0,n.jsx)("div",{className:"absolute right-0 top-6 z-20 bg-modal-glass backdrop-blur-xl border border-card rounded-lg shadow-xl overflow-hidden",children:[...G,...no||(null==eN?void 0:eN.eventId)?$:[]].map(e=>(0,n.jsx)("button",{onClick:()=>{tr(t=>"".concat(t).concat(t.endsWith(" ")||!t?"":" ").concat(e)),nF(!1)},className:"block w-full text-left px-3 py-1.5 text-[11px] text-t2 hover:bg-white/[0.06] hover:text-t1 font-mono",children:e},e))})]})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("input",{"aria-label":"Subject line",value:eX,onChange:e=>tr(e.target.value),placeholder:"The first thing recipients see",className:Q}),(0,n.jsx)("button",{onClick:()=>nH(eX.trim()?"Improve the subject line â specific beats clever, 30-60 chars. Change ONLY the subject and preheader.":"Write a subject line and preheader for this email. Change ONLY the subject and preheader.","subject"),disabled:!!nk,title:"AI: improve subject","aria-label":"Ask AI to improve the subject",className:"shrink-0 px-3 py-2 text-xs bg-white/[0.06] text-t1 rounded-lg hover:bg-white/[0.1] disabled:opacity-40 transition-colors",children:"subject"===nk?"â¦":"â¦"})]}),(0,n.jsx)("input",{"aria-label":"Preview text",value:e0,onChange:e=>{let t;return t=e.target.value,eQ.change(e=>({...e,preheader:t}),"preheader")},placeholder:"Preview text (next to the subject in the inbox)",className:"".concat(Q," mt-2 text-xs")})]})]}),"event_promotion"===e2&&(0,n.jsxs)("div",{className:"bg-card border border-card rounded-xl p-4 sm:p-5",children:[(0,n.jsx)("h2",{className:"studio-body-strong",children:"Which event?"}),(0,n.jsx)("p",{className:"studio-caption mt-0.5 mb-3",children:"The email links to your ticket page, and its report shows the visits and sales it brings."}),null===ni?(0,n.jsx)("p",{className:"studio-caption",children:"Loading your eventsâ¦"}):(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[ni.map(e=>(0,n.jsx)("button",{"aria-pressed":(null==no?void 0:no.eventId)===e.eventId,onClick:()=>{nc(e),nu(null),to(e=>e.some(e=>"button"===e.type&&e.href===d)?e:[...e,{type:"button",content:"Get tickets",href:d}])},className:J((null==no?void 0:no.eventId)===e.eventId),children:e.eventName},e.eventId)),0===ni.length&&(0,n.jsxs)("p",{className:"studio-caption",children:["No upcoming events yet. ",(0,n.jsx)("a",{href:"/producer-center?tab=create-event",target:"_blank",rel:"noopener noreferrer",className:"underline text-t1",children:"Create an event"}),(0,n.jsx)("button",{onClick:()=>eW(!0),className:"underline text-t1 ml-3",children:"Choose another type"})]})]}),no&&no.codes.length>0&&(0,n.jsxs)("div",{className:"mt-3",children:[(0,n.jsx)("p",{className:"studio-label mb-1.5",children:"Attach a promo code (auto-applies from the link)"}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,n.jsx)("button",{"aria-pressed":null===nd,onClick:()=>nu(null),className:J(null===nd),children:"No code"}),no.codes.map(e=>(0,n.jsxs)("button",{"aria-pressed":nd===e.code,onClick:()=>nu(e.code),className:J(nd===e.code),children:[e.code," \xb7 ","$"===e.discountType?"$".concat(e.discountValue," off"):"".concat(e.discountValue,"% off")]},e.code))]})]})]}),(0,n.jsxs)("div",{className:"bg-card border border-card rounded-xl p-4 space-y-3",children:[(0,n.jsxs)("label",{className:"block text-xs text-t2",children:["Sender name",(0,n.jsx)("input",{value:t8,onChange:e=>se(e.target.value),placeholder:nQ||"Your name or business name, as people will see it",className:Q})]}),(0,n.jsxs)("details",{className:"text-sm text-t2",open:t4||!!t3||!!e9,children:[(0,n.jsx)("summary",{className:"cursor-pointer",children:"Replies & website visits \xb7 optional"}),(0,n.jsxs)("div",{className:"space-y-3 mt-3",children:[!tJ&&(0,n.jsxs)("section",{className:"space-y-2",children:[(0,n.jsx)("h3",{className:"text-xs text-t2",children:"Track visits on your website"}),(0,n.jsx)(k.WebsiteChooser,{value:e9,onChange:e=>{let t;return t=e||void 0,eQ.change(e=>({...e,externalSiteId:t}))},label:"Website for this email"}),(0,n.jsx)("p",{className:"text-xs text-t2",children:"Links to this website carry a campaign tag, so visits can show in this emailâs report."})]}),(0,n.jsx)(C,{checked:t4,replyDomain:t9,onDomainChange:t7,onChange:t6}),(0,n.jsxs)("label",{className:"block text-xs text-t2",children:["Reply-to address",(0,n.jsx)("input",{type:"email",value:t3,onChange:e=>t5(e.target.value),placeholder:t4?"Used for test emails; replies to this email go to your inbox here":"Defaults to your sending address",className:Q})]})]})]})]}),(0,n.jsx)("div",{className:"flex justify-end",children:(0,n.jsx)("button",{onClick:()=>ez(ey?2:1),className:"px-4 py-2 text-xs font-medium bg-white text-surface-base rounded-lg hover:bg-white/90 transition-colors",children:ey?"Next: Content â":"Next: Audience â"})})]}),tP?(0,n.jsxs)("div",{role:"alert",className:"p-3 rounded-lg border border-red-400/30 text-sm text-t1",children:[tP,(0,n.jsx)("p",{className:"text-xs text-t2 mt-2",children:"Your local text is still here. Copy it before reloading a conflicting draft."}),(0,n.jsx)("button",{className:"underline mt-2",onClick:()=>{tF(null),ae()},children:"Retry save"})]}):(0,n.jsx)("p",{role:"status",className:"studio-caption",children:tB}),!ey&&1===eV&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"bg-card border border-card rounded-xl p-4 sm:p-5 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{ref:eY,tabIndex:-1,
1className:"studio-body-strong",children:"Audience"}),(0,n.jsx)("p",{className:"studio-caption mt-0.5",children:"Choose your contacts or a community you manage. Only people who opted in can receive it."})]}),(0,n.jsxs)("label",{className:"block text-xs text-t2",children:["Send on behalf of",(0,n.jsxs)("select",{className:Q,value:tJ,onChange:e=>{let t={communityId:tJ,rules:e3,activeSegment:s7};sJ(()=>{tQ(e.target.value),ti([]),s8(null)}),sZ(t.rules.length?t:null)},children:[(0,n.jsx)("option",{value:"",children:"My contacts"}),tJ&&!sI.some(e=>e.id===tJ)&&(0,n.jsx)("option",{value:tJ,children:"Selected community"}),sI.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),s$&&(0,n.jsxs)("p",{role:"status",className:"text-xs text-t2",children:[1===s$.rules.length?"Your condition was":"Your ".concat(s$.rules.length," conditions were")," cleared because they belong to the previous sender. ",(0,n.jsx)("button",{className:"underline text-t1",onClick:()=>{sJ(()=>{tQ(s$.communityId),ti(s$.rules),s8(s$.activeSegment)}),sZ(null)},children:"Undo"})]}),Object.values(sU).some(Boolean)&&(0,n.jsx)("p",{role:"status",className:"text-xs text-t2",children:"Loading audience optionsâ¦"}),Object.keys(sF).filter(e=>sF[e]).map(e=>(0,n.jsxs)("p",{role:"alert",className:"text-sm text-t2",children:["Couldnât load your ",q[e],". ",sF[e]," ",(0,n.jsxs)("button",{disabled:sU[e],className:"underline",onClick:()=>void nO(e),children:["Retry ",q[e]]})]},e)),!!sR&&(0,n.jsx)("button",{disabled:sU.communities,onClick:()=>void nU("communities",sR),className:"text-xs underline text-t2",children:"Load more communities"}),sD.length>0&&(0,n.jsxs)("label",{className:"block text-xs text-t2",children:["Saved audience",(0,n.jsxs)("select",{value:sY,className:Q,"aria-busy":sz,onChange:e=>{e.target.value?n_(e.target.value):sJ(()=>{})},children:[(0,n.jsx)("option",{value:"",children:"Choose saved conditions"}),sD.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),sz&&(0,n.jsx)("p",{role:"status",className:"text-sm text-t2",children:"Loading selected audienceâ¦"}),sK&&(0,n.jsxs)("p",{role:"alert",className:"text-sm text-t2",children:["The saved audience was not applied. ",sK," ",(0,n.jsx)("button",{className:"underline",onClick:()=>void n_(sY),children:"Retry selected audience"})," ",(0,n.jsx)("button",{className:"underline",onClick:()=>sJ(()=>{}),children:"Keep current audience"})]}),sM&&(0,n.jsx)("button",{disabled:sU.audiences,onClick:()=>void nV(sM),className:"text-xs underline text-t2",children:"Load more saved audiences"}),!tJ&&(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,n.jsx)("button",{"aria-pressed":ac,onClick:()=>sJ(()=>{s8(null),s3({listIds:null})}),className:J(ac),children:"All my contacts"}),s5.map(e=>(0,n.jsx)("button",{"aria-pressed":s7===e.id,onClick:()=>sJ(()=>{var t;s8(e.id),s3({...e.filters,listIds:null!=(t=e.filters.listIds)?t:null})}),className:J(s7===e.id),children:e.name},e.id))]}),!tJ&&s6&&(0,n.jsx)("button",{disabled:sU.segments,onClick:()=>void nW(s6),className:"text-xs underline text-t2",children:"Load more saved segments"}),!tJ&&ne.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"studio-label mb-1.5",children:"Or pick lists"}),(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:ne.map(e=>{var t;let s=(null!=(t=s2.listIds)?t:[]).includes(e.id);return(0,n.jsxs)("button",{"aria-pressed":s,onClick:()=>sJ(()=>{var t;s8(null);let n=null!=(t=s2.listIds)?t:[];s3({listIds:s?n.filter(t=>
1t!==e.id):[...n,e.id]})}),className:J(s),children:[e.name," \xb7 ",e.count.toLocaleString()]},e.id)})})]}),!tJ&&sL&&(0,n.jsx)("button",{disabled:sU.lists,onClick:()=>void nU("lists",sL),className:"text-xs underline text-t2",children:"Load more lists"}),(0,n.jsx)("p",{className:"text-xs text-t2",children:na&&!ns?"Countingâ¦":ns?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-t1 font-semibold",children:[ns.sendable.toLocaleString()," ",1===ns.sendable?"person":"people"]})," can receive it; permission is checked again when it sends",ns.suppressed>0&&(0,n.jsxs)("span",{className:"text-t3",children:[" \xb7 ",ns.suppressed.toLocaleString()," without permission are skipped"]})]}):"The exact count appears when you review the email."})]}),(0,n.jsx)(V.A,{rules:e3,onChange:e=>{sZ(null),sJ(()=>ti(e))},eventId:(null==no?void 0:no.eventId)||(null==eN?void 0:eN.eventId),communityId:tJ||void 0,communities:sI,events:(ni||[]).filter(e=>"host"===e.role)}),(null==(ea=s2.listIds)?void 0:ea.length)===0&&!tJ&&(0,n.jsx)("p",{className:"text-sm text-t2",children:"No lists selected. Nobody will receive this email until you choose a list or All my contacts."}),(0,n.jsx)(W.A,{value:eG,onChange:e=>sJ(()=>e$(e)),lists:ne,eventId:(null==no?void 0:no.eventId)||(null==eN?void 0:eN.eventId),communityId:tJ||void 0,communities:sI,events:(ni||[]).filter(e=>"host"===e.role)}),(0,n.jsxs)("div",{className:"flex justify-between",children:[(0,n.jsx)("button",{onClick:()=>ez(0),className:"px-3.5 py-2 text-xs bg-white/[0.06] text-t1 rounded-lg hover:bg-white/[0.1] transition-colors",children:"â Back"}),(0,n.jsx)("button",{onClick:()=>ez(2),className:"px-4 py-2 text-xs font-medium bg-white text-surface-base rounded-lg hover:bg-white/90 transition-colors",children:"Next: Content â"})]})]}),2===eV&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("h2",{ref:eY,tabIndex:-1,className:"studio-body-strong",children:"Email content"}),ak,!ey&&(0,n.jsxs)("details",{className:"text-sm text-t2",children:[(0,n.jsx)("summary",{className:"cursor-pointer",children:"Optional: compare two versions"}),(0,n.jsx)("p",{className:"text-xs mt-2",children:"An A/B test sends different versions to separate groups so you can compare the results."}),(0,n.jsx)("button",{className:"text-sm underline mt-2",disabled:ny||nN,onClick:()=>{n7().then(e=>eK(e)).catch(e=>tF(e.message))},children:"Compare another version with an A/B test"})]}),(0,n.jsxs)("div",{className:"flex justify-between",children:[(0,n.jsx)("button",{onClick:()=>ez(+!ey),className:"px-3.5 py-2 text-xs bg-white/[0.06] text-t1 rounded-lg hover:bg-white/[0.1] transition-colors",children:"â Back"}),(0,n.jsx)("button",{onClick:()=>ey?void at():ez(3),disabled:ny,className:"px-4 py-2 text-xs font-medium bg-white text-surface-base rounded-lg hover:bg-white/90 transition-colors",children:ey?ej?"Save version":"Save to sequence":"Next: Review & send â"})]})]}),!ey&&3===eV&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("section",{"aria-label":"Ready to send checklist",className:"bg-card border border-card rounded-xl p-4 sm:p-5 space-y-4",children:[(0,n.jsx)("h2",{ref:eY,tabIndex:-1,className:"studio-body-strong",children:"Before you send"}),(0,n.jsx)("ul",{className:"space-y-3",children:aj.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-3 text-sm",children:[(0,n.jsxs)("span",{className:"shrink-0 text-t2",children:[(0,n.jsx)("span",{"aria-hidden":"true",children:e.ready?"â":"â"}),(0,n.jsx)("span",{className:"sr-only",children:e.ready?"Complete:":"To do:"})]}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("p",{className:"font-medium text-t1",children:e.label}),(0,n.jsx)("p",{className:"text-xs text-t2 mt-1 break-words",children:e.note})]}),!e.ready&&e.action&&(0,n.jsx)("button",{className:"shrink-0 text-xs underline text-t1",onClick:e.run,children:e.action})]},e.label))}),tq&&!ek&&(0,n.jsx)("div",{className:"border-t border-card pt-4",children:(0,n.jsx)(r.A,{initiallyExpanded:!0,onDone:()=>tz(!1),doneLabel:"Back to email review"})}),!eS&&(0,n.jsx)("p",{className:"text-sm text-t2",children:"Only a publisher can send this email. Once the audience is prepared, use Request team review to ask one."})]}),(0,n.jsxs)("div",{className:"bg-card border border-card rounded-xl p-4 sm:p-5 space-y-3",children:[(0,n.jsx)("h2",{className:"studio-body-strong",children:"When"}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,n.jsx)("button",{"aria-pressed":"now"===nh,onClick:()=>np("now"),className:J("now"===nh),children:"Send now"}),(0,n.jsx)("button",{"aria-pressed":"later"===nh,onClick:()=>np("later"),className:J("later"===nh),children:"Schedule"}),"later"===nh&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{"aria-label":"Scheduled date",type:"date",value:nb,onChange:e=>ng(e.target.value),className:"bg-white/[0.06] border border-white/[0.08] rounded-lg px-2.5 py-1.5 text-xs text-t1 outline-none"}),(0,n.jsx)("input",{"aria-label":"Scheduled time",type:"time",value:nv,onChange:e=>nf(e.target.value),className:"bg-white/[0.06] border border-white/[0.08] rounded-lg px-2.5 py-1.5 text-xs text-t1 outline-none"})]})]}),ag&&(0,n.jsx)("p",{className:"studio-caption",children:"Choose a date and time to schedule."}),(0,n.jsxs)("label",{className:"block text-xs text-t2",children:["Timezone",(0,n.jsx)("select",{value:sr,onChange:e=>so(e.target.value),className:Q,children:sd.map(e=>{let[t,s]=e;return(0,n.jsx)("option",{value:t,children:s},t)})})]}),(0,n.jsxs)("details",{className:"text-sm text-t2",open:!!st||24!==sn||void 0,children:[(0,n.jsx)("summary",{className:"cursor-pointer text-xs",children:"More timing options"}),(0,n.jsxs)("div",{className:"space-y-3 mt-3",children:[(0,n.jsx)("p",{className:"studio-caption",children:"Both can leave people out: anyone not reached by the date, or emailed by you too recently, is skipped."}),(0,n.jsxs)("label",{className:"block text-xs text-t2",children:["Stop sending after this date (optional)",(0,n.jsx)("input",{type:"date",value:st,onChange:e=>ss(e.target.value),className:Q})]}),(0,n.jsxs)("label",{className:"block text-xs text-t2",children:["Skip peo
1ple you emailed in the last (hours)",(0,n.jsx)("input",{type:"number",min:24,max:720,value:sn,onChange:e=>sa(Number(e.target.value)),className:Q})]})]})]}),ab&&(0,n.jsx)("p",{role:"alert",className:"text-sm text-negative-ink",children:ab})]}),t_&&(0,n.jsxs)("div",{role:"alert",className:"border border-red-400/30 rounded-xl p-4 text-sm text-t1",children:[(0,n.jsx)("p",{children:t_}),(0,n.jsx)("p",{className:"text-xs text-t2 mt-2",children:"Your draft is still here. Fix the issue above, then try the action again."})]}),(0,n.jsxs)("section",{className:"bg-card border border-card rounded-xl p-4 space-y-3",children:[(0,n.jsx)("h2",{className:"studio-body-strong",children:"Review this version"}),(0,n.jsx)("p",{className:"studio-caption",children:"We count who can receive it and show the exact email. Only people who gave you permission are counted."}),(0,n.jsx)("button",{onClick:as,disabled:ny||tW||!af,className:"px-4 py-2 rounded-lg bg-white text-[rgb(var(--surface-base))] text-sm disabled:opacity-50",children:tW?"Preparing audienceâ¦":"Prepare audience & preview"}),tO&&(0,n.jsxs)("details",{className:"text-sm text-t2",children:[(0,n.jsxs)("summary",{className:"cursor-pointer",children:[(0,n.jsxs)("span",{className:"text-t1 font-medium",children:[tO.count.toLocaleString()," ",1===tO.count?"person":"people"]})," can receive it \xb7 how we counted"]}),(0,n.jsxs)("dl",{className:"grid grid-cols-2 gap-2 mt-3",children:[(0,n.jsx)("dt",{children:"No permission from them"}),(0,n.jsx)("dd",{children:(tO.permissionExcluded||0).toLocaleString()}),(0,n.jsx)("dt",{children:"Donât match your conditions"}),(0,n.jsx)("dd",{children:(tO.conditionExcluded||0).toLocaleString()}),(0,n.jsx)("dt",{children:"Left out by you"}),(0,n.jsx)("dd",{children:(tO.audienceExcluded||0).toLocaleString()}),(0,n.jsx)("dt",{children:"Duplicates removed"}),(0,n.jsx)("dd",{children:(tO.duplicates||0).toLocaleString()})]})]}),!!(null==ns?void 0:ns.missingListIds.length)&&tG===n0&&(0,n.jsxs)("p",{role:"status",className:"text-sm text-attention-ink",children:[1===ns.missingListIds.length?"A list you chose is":"".concat(ns.missingListIds.length," lists you chose are")," no longer available",ns.missingListIds.some(e=>ne.some(t=>t.id===e))?": ".concat(ns.missingListIds.map(e=>{var t;return null==(t=ne.find(t=>t.id===e))?void 0:t.name}).filter(Boolean).join(", ")):"",". Nobody from ",1===ns.missingListIds.length?"it":"them"," is included. ",(0,n.jsx)("button",{className:"underline",onClick:()=>ez(1),children:"Choose lists"})]}),(null==tO?void 0:tO.status)==="ready"&&tg&&tG===n0&&(0,n.jsx)(P,{campaignId:tg,revision:tO.revision,preparedAtMs:null==sQ?void 0:sQ.preparedAtMs},"".concat(tg,"_").concat(tG)),(null==sQ?void 0:sQ.delivery)&&tG===n0&&(0,n.jsxs)("div",{className:"border-t border-white/10 pt-3 space-y-2 text-sm text-t2",children:[(0,n.jsx)("p",{className:"font-medium text-t1",children:"Delivery timing"}),sQ.delivery.minimumDurationSeconds>=60&&(0,n.jsxs)("p",{children:["This audience needs at least ",Math.ceil(sQ.delivery.minimumDurationSeconds/60).toLocaleString()," minutes of sending time. This is a minimum, not an estimated finish time."]}),(0,n.jsx)("p",{role:"limited"===sQ.delivery.state?"status":void 0,children:sQ.delivery.note})]}),sQ&&tG===n0&&(0,n.jsxs)("div",{className:"border-t border-white/10 pt-3 space-y-2 text-sm text-t2",children:[(0,n.jsxs)("p",{children:[(0,n.jsx)("strong",{className:"text-t1",children:"From:"})," ",(null==(el=sQ.sender)?void 0:el.from)||"Sending domain not set up yet"]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("strong",{className:"text-t1",children:"Reply to:"})," ",(null==(ei=sQ.sender)?void 0:ei.replyTo)||"Not set â replies go to your sending address"]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("strong",{className:"text-t1",children:"Business address:"})," ",(null==(er=sQ.sender)?void 0:er.postalAddress)||"Add a postal address before approval"]}),(0,n.jsxs)("p",{children:["Uses ",sQ.allowance.campaignEmails.toLocaleString()," ",1===sQ.allowance.campaignEmails?"email":"emails"," \xb7 ",sQ.allowance.used.toLocaleString()," sent this month \xb7 ",sQ.allowance.limit<0?"no monthly limit on your plan":"".concat(sQ.allowance.limit.toLocaleStr
1ing()," a month on your plan")]}),!sQ.allowance.allowed&&(0,n.jsx)("p",{role:"alert",className:"text-attention-ink",children:"This audience exceeds your current allowance. Reduce the audience or review your plan before sending."}),(0,n.jsx)("p",{className:"studio-caption",children:sQ.allowance.note})]}),(null==sQ?void 0:sQ.inspection)&&tG===n0&&(0,n.jsx)(B,{inspection:sQ.inspection}),(null==tO?void 0:tO.watermark)&&(0,n.jsx)("p",{className:"studio-caption",children:tO.watermark}),tG&&tG!==n0&&(0,n.jsx)("p",{role:"status",className:"text-sm text-attention-ink",children:"Your draft changed. Prepare the audience again."}),eT&&(0,n.jsx)("div",{className:"border-t border-card pt-3",children:(0,n.jsx)(o.Ay,{user:eT})}),(0,n.jsx)("button",{onClick:an,disabled:ny||!ah||!af,className:"block text-sm underline text-t2 disabled:opacity-50",children:"Send a test to my verified inbox"}),!ny&&(!ah||!af)&&(0,n.jsx)("p",{className:"studio-caption",children:af?"Set up your sender to send yourself a test.":"Finish the items above to send yourself a test."})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-3 justify-between",children:[(0,n.jsx)("button",{onClick:()=>ez(2),className:"px-3.5 py-2 text-xs bg-white/[0.06] text-t1 rounded-lg hover:bg-white/[0.1] transition-colors",children:"â Back"}),tg&&(null==tO?void 0:tO.status)==="ready"&&(0,n.jsx)(w.QS,{target:{kind:"campaign",campaignId:tg,expectedRevision:tA.current}}),(0,n.jsx)("button",{onClick:()=>{ay&&(ar(),al(!0))},disabled:!ay||ny||nN||tW,className:"px-5 py-2 text-xs font-medium bg-white text-surface-base rounded-lg hover:bg-white/90 disabled:opacity-50 transition-colors",children:nN?"Workingâ¦":"later"===nh?"Approve & schedule":"Approve & send"})]})]})]}),(0,n.jsxs)("div",{className:"w-full xl:w-[340px] shrink-0 space-y-4",children:[(0,n.jsxs)("div",{className:"bg-card border border-card rounded-xl p-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,n.jsx)("h2",{className:"studio-body-strong",children:"Email preview"}),(0,n.jsx)("div",{className:"flex gap-1",children:["desktop","mobile","text"].map(e=>(0,n.jsx)("button",{"aria-pressed":nB===e,onClick:()=>nM(e),className:"px-2.5 py-1 text-[10.5px] rounded-md capitalize transition-colors ".concat(nB===e?"bg-white text-surface-base font-medium":"text-t3 hover:text-t1"),children:e},e))})]}),eX.trim()&&(0,n.jsxs)("p",{className:"text-[11px] text-t2 mb-2 truncate",children:[(0,n.jsx)("span",{className:"text-t3",children:"Subject:"})," ",eX]}),tH&&tG===n0?"text"===nB?(0,n.jsx)("pre",{className:"whitespace-pre-wrap break-words text-sm bg-[#ffffff] text-[#000000] p-4 rounded-lg max-h-[560px] overflow-auto",children:s0}):(0,n.jsx)("iframe",{title:"Server-rendered email preview",sandbox:"",srcDoc:tH,className:"bg-white-fixed rounded-lg h-[560px] ".concat("mobile"===nB?"w-[280px] max-w-full mx-auto":"w-full")}):"text"===nB?(0,n.jsx)("p",{role:"status",className:"text-sm text-t2 p-4 border border-card rounded-lg",children:"Prepare the audience in Review & send to see the exact plain-text email."}):(0,n.jsx)(X,{emailDesign:ta,blocks:e1,senderLabel:nz,mobile:"mobile"===nB})]}),(0,n.jsxs)("div",{className:"bg-card border border-card rounded-xl p-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("h2",{className:"studio-body-strong",children:"Summary"}),(0,n.jsx)("button",{onClick:()=>ez(0),className:"text-[11px] text-t3 hover:text-t1 transition-colors",children:"Edit"})]}),(0,n.jsx)("div",{className:"space-y-1.5 text-[11.5px]",children:[["Email type",e2&&null!=(eu=null==(eo=H.find(e=>e.key===e2))?void 0:eo.label)?eu:"â"],["Audience",ey?ej?"Managed in the A/B test":"Managed in the sequence":au],["Subject line",eX.trim()||"â"],["Send time",ey?ej?"Follows the A/B test plan":"Follows the sequence timing":"now"===nh?"After your approval":av||"Choose a date and time"],["From",nq?"".concat(nz):"No verified domain yet"],...no?[["Promoting","".concat(no.eventName).concat(nd?" \xb7 ".concat(nd):"")]]:[]].map(e=>{let[t,s]=e;return(0,n.jsxs)("div",{className:"flex justify-between gap-3",children:[(0,n.jsx)("span",{className:"text-t3 shrink-0",children:t}),(0,n.jsx)("span",{className:"text-t1 text-right break-words min-w-0",children:s})]},t)})})]})]})]})]})]})}}}]);
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.