(()=>{"use strict";const e=window.React,t=window.wp.element,a=window.wp.i18n,n=window.SuiteMkt3k||{},l=document.getElementById("suitemkt3k-newsletter-designer");if(l&&l.dataset.campaign){const c=JSON.parse(l.dataset.campaign||"{}"),m=l.dataset.listUrl||"#";(0,t.createRoot)(l).render((0,e.createElement)(function({initial:l,listUrl:c}){const[m,s]=(0,t.useState)(l),[i,r]=(0,t.useState)(!1);function o(e){s(t=>({...t,...e}))}function u(e){s(t=>({...t,content:{...t.content,...e}}))}return(0,e.createElement)("div",{className:"wmk-designer"},(0,e.createElement)("aside",{className:"wmk-designer-left"},(0,e.createElement)("label",{className:"wmk-field"},(0,e.createElement)("span",null,(0,a.__)("Campaign name","suitemkt3k")),(0,e.createElement)("input",{className:"wmk-input",value:m.name||"",onChange:e=>o({name:e.target.value})})),(0,e.createElement)("label",{className:"wmk-field"},(0,e.createElement)("span",null,(0,a.__)("Subject","suitemkt3k")),(0,e.createElement)("input",{className:"wmk-input",value:m.subject||"",onChange:e=>o({subject:e.target.value})})),(0,e.createElement)("label",{className:"wmk-field"},(0,e.createElement)("span",null,(0,a.__)("Template","suitemkt3k")),(0,e.createElement)("select",{className:"wmk-input",value:m.template_key,onChange:e=>o({template_key:e.target.value})},(0,e.createElement)("option",{value:"classic"},(0,a.__)("Classic promo","suitemkt3k")),(0,e.createElement)("option",{value:"welcome"},(0,a.__)("Welcome","suitemkt3k")),(0,e.createElement)("option",{value:"reminder"},(0,a.__)("Reminder","suitemkt3k")),(0,e.createElement)("option",{value:"announce"},(0,a.__)("Announcement","suitemkt3k")))),(0,e.createElement)("label",{className:"wmk-field"},(0,e.createElement)("span",null,(0,a.__)("Heading","suitemkt3k")),(0,e.createElement)("input",{className:"wmk-input",value:m.content.heading||"",onChange:e=>u({heading:e.target.value})})),(0,e.createElement)("label",{className:"wmk-field"},(0,e.createElement)("span",null,(0,a.__)("Preheader","suitemkt3k")),(0,e.createElement)("input",{className:"wmk-input",value:m.content.preheader||"",onChange:e=>u({preheader:e.target.value})})),(0,e.createElement)("label",{className:"wmk-field"},(0,e.createElement)("span",null,(0,a.__)("Body","suitemkt3k")),(0,e.createElement)("textarea",{className:"wmk-input",rows:"6",value:m.content.body||"",onChange:e=>u({body:e.target.value})})),(0,e.createElement)("label",{className:"wmk-field"},(0,e.createElement)("span",null,(0,a.__)("CTA label","suitemkt3k")),(0,e.createElement)("input",{className:"wmk-input",value:m.content.cta_label||"",onChange:e=>u({cta_label:e.target.value})})),(0,e.createElement)("label",{className:"wmk-field"},(0,e.createElement)("span",null,(0,a.__)("CTA URL","suitemkt3k")),(0,e.createElement)("input",{className:"wmk-input",type:"url",value:m.content.cta_url||"",onChange:e=>u({cta_url:e.target.value})})),(0,e.createElement)("label",{className:"wmk-field"},(0,e.createElement)("span",null,(0,a.__)("Accent","suitemkt3k")),(0,e.createElement)("input",{type:"color",value:m.content.accent||"#6366F1",onChange:e=>u({accent:e.target.value})})),(0,e.createElement)("div",{className:"wmk-form-actions"},(0,e.createElement)("a",{className:"wmk-btn wmk-btn-ghost",href:c},(0,a.__)("Back","suitemkt3k")),(0,e.createElement)("button",{className:"wmk-btn wmk-btn-primary",disabled:i,onClick:async function(){r(!0);const e=await(t=m,fetch(n.restUrl+"newsletters".replace(/^\/+/,""),{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","X-WP-Nonce":n.nonce},body:t?JSON.stringify(t):void 0}).then(e=>e.json()));var t;r(!1),e&&e.id&&s(e)}},i?(0,a.__)("Saving…","suitemkt3k"):(0,a.__)("Save","suitemkt3k")))),(0,e.createElement)("section",{className:"wmk-designer-right"},(0,e.createElement)("div",{className:"wmk-card",style:{background:"#F4F4F7",padding:16}},(0,e.createElement)("div",{style:{background:"#fff",padding:24,borderRadius:12,maxWidth:600,margin:"0 auto",boxShadow:"0 1px 3px rgba(0,0,0,0.05)"}},(0,e.createElement)("div",{style:{background:m.content.accent,color:"#fff",padding:20,borderRadius:"8px 8px 0 0",marginBottom:16}},(0,e.createElement)("strong",null,m.content.heading)),(0,e.createElement)("div",{style:{color:"#475569",whiteSpace:"pre-wrap"}},m.content.body),(0,e.createElement)("div",{style:{marginTop:24}},(0,e.createElement)("a",{style:{background:m.content.accent,color:"#fff",padding:"12px 24px",borderRadius:8,textDecoration:"none",display:"inline-block"}},m.content.cta_label))))))},{initial:c,listUrl:m}))}})();