PageSourceSearch

https://onepe.ai/build/assets/CampaignForm-BuWXyk0Q.js

js onepe.ai collected 2026-10-05 14:39:37 UTC 97,623 bytes, 105 lines download raw bytes

1import{r as p,f as Me,j as e,c as K,u as Ke,a as Ye}from"./app-D4IBpXEE.js";import{c as Q,t as Z,u as Je,f as le}from"./datetime-BfxD2VX1.js";import{C as xe}from"./BrandIcons-DMEfIFxP.js";import{c as D}from"./createLucideIcon-CNbh77gd.js";import{T as Xe}from"./type-zlYwDCPS.js";import{M as Qe,S as Ze}from"./save-BIHJqQ3m.js";import{I as Ae}from"./image-XLVZUHN1.js";import{M as et}from"./minus-D6ptT7J6.js";import{M as tt}from"./MediaUpload-CRw5OdeV.js";import{u as L}from"./useTranslation-mV-gvqqz.js";import{X as at}from"./x-Bdl9lUlz.js";import{L as nt}from"./link-2-CoTuHk7B.js";import{P as _e}from"./plus-BtmR7ya-.js";import{G as rt}from"./grip-vertical-CkVw2VBg.js";import{S as st,C as lt}from"./settings-2-CidtY0xb.js";import{C as it}from"./copy-tFkIONE-.js";import{T as ot}from"./trash-2-BoxiPtFH.js";import{C as te}from"./circle-check-PZsi8p9w.js";import{L as dt}from"./layers-YtkC_1qB.js";import{S as ee}from"./sparkles-DSWEk3Bi.js";import{E as ie}from"./eye--y4uUAE3.js";import{L as q}from"./loader-circle-D9S0CuXo.js";import{C as U}from"./circle-alert-Bi1aHXZv.js";import{T as ct}from"./TimezonePicker-DmLgn4uO.js";import"./Tabs-CO9UBWDc.js";import{D as ut}from"./DatePicker-CZIKWNeY.js";import"./Modal-BG2UZmBH.js";import{A as mt}from"./arrow-left-BfMoYKHZ.js";import{A as pt}from"./arrow-right-DC5t6DfC.js";import{S as Ie}from"./send-B_1MxWjZ.js";import{U as xt}from"./users-CkbR-kb7.js";import{T as Re}from"./Trans-Z-pFVM8q.js";import{S as ht}from"./search-DEcyoQmh.js";import{U as ke}from"./upload--3DH9MyM.js";import{L as ft}from"./link-CvNe-7dY.js";import"./file-text-Bmh95Nys.js";import"./clock-CjNziwQQ.js";import"./chevron-down-BD_xrt_b.js";import"./calendar-CvLnF-Lb.js";import"./chevron-left-CWeHfR8G.js";import"./chevron-right-TmvN6Wf9.js";/**
2 * @license lucide-react v0.575.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const gt=[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]],bt=D("bold",gt);/**
7 * @license lucide-react v0.575.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const yt=[["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M6 20V4",key:"1w1bmo"}],["path",{d:"M18 20V4",key:"o2hl4u"}]],_t=D("heading",yt);/**
12 * @license lucide-react v0.575.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const jt=[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]],vt=D("italic",jt);/**
17 * @license lucide-react v0.575.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const kt=[["path",{d:"m14.622 17.897-10.68-2.913",key:"vj2p1u"}],["path",{d:"M18.376 2.622a1 1 0 1 1 3.002 3.002L17.36 9.643a.5.5 0 0 0 0 .707l.944.944a2.41 2.41 0 0 1 0 3.408l-.944.944a.5.5 0 0 1-.707 0L8.354 7.348a.5.5 0 0 1 0-.707l.944-.944a2.41 2.41 0 0 1 3.408 0l.944.944a.5.5 0 0 0 .707 0z",key:"18tc5c"}],["path",{d:"M9 8c-1.804 2.71-3.97 3.46-6.583 3.948a.507.507 0 0 0-.302.819l7.32 8.883a1 1 0 0 0 1.185.204C12.735 20.405 16 16.792 16 15",key:"ytzfxy"}]],Nt=D("paintbrush",kt);/**
22 * @license lucide-react v0.575.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const wt=[["path",{d:"M4 7V4h16v3",key:"9msm58"}],["path",{d:"M5 20h6",key:"1h6pxn"}],["path",{d:"M13 4 8 20",key:"kqq6aj"}],["path",{d:"m15 15 5 5",key:"me55sn"}],["path",{d:"m20 15-5 5",key:"11p7ol"}]],Ct=D("remove-formatting",wt);/**
27 * @license lucide-react v0.575.0 - ISC
28 *
29 * This source code is licensed under the ISC license.
30 * See the LICENSE file in the root directory of this source tree.
31 */const St=[["rect",{width:"6",height:"20",x:"4",y:"2",rx:"2",key:"19qu7m"}],["rect",{width:"6",height:"20",x:"14",y:"2",rx:"2",key:"24v0nk"}
31]],$t=D("stretch-vertical",St);/**
32 * @license lucide-react v0.575.0 - ISC
33 *
34 * This source code is licensed under the ISC license.
35 * See the LICENSE file in the root directory of this source tree.
36 */const zt=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 19H5",key:"vjpgq2"}]],Lt=D("text-align-center",zt);/**
37 * @license lucide-react v0.575.0 - ISC
38 *
39 * This source code is licensed under the ISC license.
40 * See the LICENSE file in the root directory of this source tree.
41 */const Et=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 19H7",key:"4cu937"}]],Tt=D("text-align-end",Et);/**
42 * @license lucide-react v0.575.0 - ISC
43 *
44 * This source code is licensed under the ISC license.
45 * See the LICENSE file in the root directory of this source tree.
46 */const Mt=[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 19H3",key:"z6ezky"}]],At=D("text-align-start",Mt);/**
47 * @license lucide-react v0.575.0 - ISC
48 *
49 * This source code is licensed under the ISC license.
50 * See the LICENSE file in the root directory of this source tree.
51 */const It=[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]],Rt=D("underline",It);/**
52 * @license lucide-react v0.575.0 - ISC
53 *
54 * This source code is licensed under the ISC license.
55 * See the LICENSE file in the root directory of this source tree.
56 */const Dt=[["path",{d:"M8 21s-4-3-4-9 4-9 4-9",key:"uto9ud"}],["path",{d:"M16 3s4 3 4 9-4 9-4 9",key:"4w2vsq"}],["line",{x1:"15",x2:"9",y1:"9",y2:"15",key:"f7djnv"}],["line",{x1:"9",x2:"15",y1:"9",y2:"15",key:"1shsy8"}]],de=D("variable",Dt);function E(){return Math.random().toString(36).slice(2,9)}const De=[{type:"heading",label:"Heading",Icon:_t},{type:"paragraph",label:"Text",Icon:Xe},{type:"button",label:"Button",Icon:Qe},{type:"image",label:"Image",Icon:Ae},{type:"divider",label:"Divider",Icon:et},{type:"spacer",label:"Spacer",Icon:$t}];function Ht(t){switch(t){case"heading":return{id:E(),type:"heading",level:2,text:"",align:"left",color:"#111111"};case"paragraph":return{id:E(),type:"paragraph",text:"",align:"left"};case"button":return{id:E(),type:"button",text:"Click Here",url:"#",align:"center",color:"#2563eb",textColor:"#ffffff"};case"image":return{id:E(),type:"image",src:"",alt:"",align:"center",width:"",url:""};case"divider":return{id:E(),type:"divider",color:"#e5e7eb"};case"spacer":return{id:E(),type:"spacer",height:24};default:return{id:E(),type:"paragraph",text:"",align:"left"}}}function Pt(t){return t==="heading"||t==="paragraph"||t==="button"}function Bt(t){return t.map(a=>{switch(a.type){case"heading":{const n=a.align&&a.align!=="left"?`text-align:${a.align};`:"",r=a.color||"#111";return`<h${a.level} style="margin:0 0 12px;font-family:sans-serif;color:${r};${n}">${a.text}</h${a.level}>`}case"paragraph":return`<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;${a.align&&a.align!=="left"?`text-align:${a.align};`:""}">${a.text}</p>`;case"button":{const n=a.align??"center",r=a.color??"#2563eb",s=a.textColor??"#ffffff";return`<div style="text-align:${n};margin:16px 0;"><a href="${a.url||"#"}" style="display:inline-block;padding:12px 24px;background:${r};color:${s};text-decoration:none;border-radius:6px;font-family:sans-serif;font-size:15px;font-weight:600;">${a.text}</a></div>`}case"divider":return`<hr style="border:none;border-top:1px solid ${a.color||"#e5e7eb"};margin:20px 0;" />`;case"spacer":{const n=a.height??20;return`<div style="height:${n}px;line-height:${n}px;font-size:1px;">&nbsp;</div>`}case"image":{if(!a.src)return"";const n=a.align??"center",r=a.width?`width:${a.width};`:"",s=`<img src="${a.src}" alt="${a.alt??""}" style="${r}max-width:100%;border-radius:4px;display:inline-block;" />`,i=a.url?`<a href="${a.url}" style="text-decoration:none;">${s}</a>`:s;return`<div style="text-align:${n};margin:12px 0;">${i}</div>`}default:return""}}).join(`
57`)}const Ft=new Set(["span","b","strong","i","em","u","s","strike","del","ins","small","mark","code","sub","sup","font","label","t
57ime","abbr","q","cite","big","tt","var","kbd","samp","wbr"]);function ce(t,a){const n=(t||"").match(new RegExp(`(?:^|[;\\s])${a}\\s*:\\s*([^;]+)`,"i"));return n?n[1].trim():""}function Y(t,a){const n=ce(t,a);if(!n)return"";const r=n.match(/#[0-9a-f]{3,8}|rgba?\([^)]*\)|hsla?\([^)]*\)/i);return r?r[0]:/^[a-z]+$/i.test(n)?n:""}function V(t){const a=ce(t,"text-align").toLowerCase();return a==="center"||a==="right"?a:"left"}function Ne(t){const a=(t.getAttribute("style")||"").toLowerCase();return/background(-color)?\s*:/.test(a)||/padding\s*:/.test(a)||/display\s*:\s*(inline-)?block/.test(a)}function Ot(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function we(t,a){const n=t.getAttribute("style")||"";return{id:E(),type:"button",text:t.innerHTML.trim()||"Button",url:t.getAttribute("href")||"#",align:a||"center",color:Y(n,"background-color")||Y(n,"background")||"#2563eb",textColor:Y(n,"color")||"#ffffff"}}function he(t,a,n){const r=t.getAttribute("style")||"",s=ce(r,"width");return{id:E(),type:"image",src:t.getAttribute("src")||"",alt:t.getAttribute("alt")||"",align:n||V(r),width:s||(t.getAttribute("width")?`${t.getAttribute("width")}px`:""),url:a||""}}function He(t,a){let n=[];const r=()=>{if(!n.length)return;const s=n.map(i=>i.nodeType===3?Ot(i.textContent):i.outerHTML).join("").trim();n=[],s&&a.push({id:E(),type:"paragraph",text:s,align:"left"})};t.childNodes.forEach(s=>{var d;if(s.nodeType===3){s.textContent.trim()&&n.push(s);return}if(s.nodeType!==1)return;const i=s.tagName.toLowerCase(),l=s.getAttribute("style")||"";if(/^h[1-6]$/.test(i))r(),a.push({id:E(),type:"heading",level:Math.min(3,parseInt(i[1],10)),text:s.innerHTML.trim(),align:V(l),color:Y(l,"color")||"#111111"});else if(i==="p"){r();const c=s.innerHTML.trim();c&&a.push({id:E(),type:"paragraph",text:c,align:V(l)})}else if(i==="hr")r(),a.push({id:E(),type:"divider",color:Y(l,"border-top")||Y(l,"border")||"#e5e7eb"});else if(i==="ul"||i==="ol")r(),s.querySelectorAll(":scope > li").forEach(c=>{const o=c.innerHTML.trim();o&&a.push({id:E(),type:"paragraph",text:`• ${o}`,align:"left"})});else if(i==="img")r(),a.push(he(s,"",V(l)));else if(i==="br")r();else if(i==="a"){const c=s.querySelector("img");c?(r(),a.push(he(c,s.getAttribute("href"),"center"))):Ne(s)?(r(),a.push(we(s,"left"))):n.push(s)}else if(Ft.has(i))n.push(s);else{r();const c=ce(l,"height"),o=s.querySelector("img,a,h1,h2,h3,h4,h5,h6,p,ul,ol,hr");if(c&&!s.textContent.trim()&&!o){a.push({id:E(),type:"spacer",height:parseInt(c,10)||20});return}const x=s.querySelectorAll("img"),f=[...s.querySelectorAll("a")].find(y=>Ne(y)),u=s.textContent.replace(/\s+/g,"");x.length===1&&!u?a.push(he(x[0],(d=s.querySelector("a"))==null?void 0:d.getAttribute("href"),V(l))):f&&s.textContent.trim()===f.textContent.trim()?a.push(we(f,V(l))):He(s,a)}}),r()}function ae(t){if(!t||!t.trim())return[];if(typeof DOMParser>"u")return[{id:E(),type:"paragraph",text:t,align:"left"}];const a=new DOMParser().parseFromString(`<body>${t}</body>`,"text/html"),n=[];return He(a.body,n),n.length===0&&n.push({id:E(),type:"paragraph",text:t,align:"left"}),n}const fe=[{id:"welcome",name:"Welcome Email",category:"Onboarding",subject:"Welcome to {{company_name}}, {{contact.first_name}}!",body:`<h2 style="margin:0 0 12px;font-family:sans-serif;color:#111;">Welcome aboard, {{contact.first_name}}! 🎉</h2>
58<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">We're thrilled to have you join us. Your account is all set and ready to go.</p>
59<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">Here's what you can do next:</p>
60<p style="margin:0 0 8px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">✅ Complete your profile</p>
61<p style="margin:0 0 8px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">✅ Explore our features</p>
62<p style="margin:0 0 16px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">✅ Reach out if you need any help</p>
63<div style="text-align:center;margin:16px 0;"><a href="#" style="display:inline-block;padding:12px 24px;background:#2563eb;
63color:#fff;text-decoration:none;border-radius:6px;font-family:sans-serif;font-size:15px;font-weight:600;">Get Started</a></div>
64<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">If you have any questions, just reply to this email — we're always happy to help.</p>`},{id:"promo",name:"Promotional Offer",category:"Marketing",subject:"🔥 Exclusive offer just for you, {{contact.first_name}}",body:`<h2 style="margin:0 0 12px;font-family:sans-serif;color:#111;">A special offer, just for you</h2>
65<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">Hi {{contact.first_name}}, we wanted to reward our loyal customers with something special.</p>
66<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">Use code <strong>SAVE20</strong> for 20% off your next order!</p>
67<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">This offer expires in 48 hours, so don't miss out.</p>
68<div style="text-align:center;margin:16px 0;"><a href="#" style="display:inline-block;padding:12px 24px;background:#f59e0b;color:#fff;text-decoration:none;border-radius:6px;font-family:sans-serif;font-size:15px;font-weight:600;">Claim Your Discount</a></div>`},{id:"newsletter",name:"Newsletter",category:"Content",subject:"Your monthly update — {{month}} edition",body:`<h2 style="margin:0 0 4px;font-family:sans-serif;color:#111;">Monthly Newsletter</h2>
69<p style="margin:0 0 20px;font-family:sans-serif;font-size:13px;color:#6b7280;">The latest updates, tips, and news</p>
70<hr style="border:none;border-top:1px solid #e5e7eb;margin:20px 0;" />
71<h3 style="margin:0 0 8px;font-family:sans-serif;color:#111;">What's new this month</h3>
72<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">We've been busy building exciting new features and improvements. Here's a quick roundup of everything that's new.</p>
73<h3 style="margin:0 0 8px;font-family:sans-serif;color:#111;">Featured article</h3>
74<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">Check out our latest guide on getting the most out of your account. It covers tips and tricks our power users swear by.</p>
75<div style="text-align:center;margin:16px 0;"><a href="#" style="display:inline-block;padding:12px 24px;background:#2563eb;color:#fff;text-decoration:none;border-radius:6px;font-family:sans-serif;font-size:15px;font-weight:600;">Read the Guide</a></div>
76<hr style="border:none;border-top:1px solid #e5e7eb;margin:20px 0;" />
77<p style="margin:0;font-family:sans-serif;font-size:13px;color:#9ca3af;text-align:center;">You're receiving this because you subscribed to our newsletter.</p>`},{id:"announcement",name:"Product Announcement",category:"Marketing",subject:"Introducing [Feature Name] — Now available",body:`<h2 style="margin:0 0 12px;font-family:sans-serif;color:#111;">We're launching something new 🚀</h2>
78<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">Hi {{contact.first_name}}, today is an exciting day. We've been working hard on something we think you're going to love.</p>
79<h3 style="margin:0 0 8px;font-family:sans-serif;color:#111;">Introducing [Feature Name]</h3>
80<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">A brief description of what it does and why it's amazing for users like you.</p>
81<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">Here's why you'll love it:</p>
82<p style="margin:0 0 8px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">⚡ Benefit one — saves you time</p>
83<p style="margin:0 0 8px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">🎯 Benefit two — improves results</p>
84<p style="margin:0 0 16px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">🔒 Benefit three — keeps things secure</p>
85<div style="text-align:center;margin:16px 0;"><a href="#" style="display:inline-block;padding:12px 24px;background:#2563eb;
85color:#fff;text-decoration:none;border-radius:6px;font-family:sans-serif;font-size:15px;font-weight:600;">Try It Now</a></div>`},{id:"reengagement",name:"Re-engagement",category:"Retention",subject:"We miss you, {{contact.first_name}} 👋",body:`<h2 style="margin:0 0 12px;font-family:sans-serif;color:#111;">It's been a while, {{contact.first_name}}</h2>
86<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">We noticed you haven't been around lately and wanted to check in. Is everything okay? We'd love to have you back.</p>
87<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">Since your last visit, we've added some great new features we think you'll enjoy:</p>
88<p style="margin:0 0 8px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">✨ New feature 1</p>
89<p style="margin:0 0 8px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">✨ New feature 2</p>
90<p style="margin:0 0 16px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">✨ New feature 3</p>
91<div style="text-align:center;margin:16px 0;"><a href="#" style="display:inline-block;padding:12px 24px;background:#10b981;color:#fff;text-decoration:none;border-radius:6px;font-family:sans-serif;font-size:15px;font-weight:600;">Come Back & Explore</a></div>
92<p style="margin:0 0 12px;font-family:sans-serif;font-size:13px;color:#6b7280;text-align:center;">Don't want to hear from us? <a href="#" style="color:#6b7280;">Unsubscribe</a></p>`},{id:"event",name:"Event Invitation",category:"Events",subject:"You're invited: [Event Name] on [Date]",body:`<h2 style="margin:0 0 4px;font-family:sans-serif;color:#111;">You're Invited!</h2>
93<p style="margin:0 0 20px;font-family:sans-serif;font-size:13px;color:#6b7280;">A special event just for you, {{contact.first_name}}</p>
94<h3 style="margin:0 0 8px;font-family:sans-serif;color:#111;">[Event Name]</h3>
95<p style="margin:0 0 4px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">📅 [Date] at [Time]</p>
96<p style="margin:0 0 16px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">📍 [Location / Online link]</p>
97<p style="margin:0 0 12px;font-family:sans-serif;font-size:15px;line-height:1.6;color:#333;">We'd love to see you there. This event is a great opportunity to [reason to attend].</p>
98<div style="text-align:center;margin:16px 0;"><a href="#" style="display:inline-block;padding:12px 24px;background:#7c3aed;color:#fff;text-decoration:none;border-radius:6px;font-family:sans-serif;font-size:15px;font-weight:600;">RSVP Now</a></div>
99<p style="margin:0;font-family:sans-serif;font-size:13px;color:#6b7280;">Spots are limited — secure yours today.</p>`}],qt=`
100[data-ee-text] { outline: none; min-height: 1em; word-break: break-word; }
101[data-ee-text]:empty:before { content: attr(data-placeholder); color: #9ca3af; pointer-events: none; }
102.dark [data-ee-text]:empty:before { color: #6b7280; }
103[data-ee-text] a { color: #2563eb; text-decoration: underline; }
104[data-ee-canvas] [data-ee-block] { transition: box-shadow .15s, border-color .15s; }
105`;function Ut(t){t.focus();const a=document.createRange();a.selectNodeContents(t),a.collapse(!1);const n=window.getSelection();n.removeAllRanges(),n.addRange(a)}function ge({as:t="div",html:a="",onChange:n,placeholder:r="",singleLine:s=!1,autoFocus:i=!1,className:l="",style:d,onFocus:c,onBlur:o,...x}){const f=p.useRef(null),u=p.useRef(a);p.useEffect(()=>{const w=f.current;w&&document.activeElement!==w&&w.innerHTML!==(a??"")&&(w.innerHTML=a??"",u.current=a??"")},[a]),p.useEffect(()=>{i&&f.current&&Ut(f.current)},[]);const y=p.useCallback(()=>{const w=f.current;if(!w)return;const S=w.innerHTML;S!==u.current&&(u.current=S,n==null||n(S))},[n]);function _(w){var S;w.key==="Enter"&&(s?(w.preventDefault(),(S=f.current)==null||S.blur()):w.shiftKey||(w.preventDefault(),document.execCommand("insertLineBreak"),y()))}function b(w){w.preventDefault();const S=(w.clipboardData||window.clipboardData).getData("text/plain");document.execCommand("insertText",!1,S),y()}return e.jsx(t,{ref:f,"data-ee-text":"",role:"textbox",contentEditable:!0,suppressContentEditableWarning:!0,spellCheck:!0,"data-placeholder":r,className:l,style:d,onInput:y,onBlur:w=>{y(),o==null||o(w)},onFocus:c,onKeyDown:_,onPaste:b,...x})}function W({active:t,onClick:a,title:n,children:r}){return e.jsx("button",{type:"button",title:n,onClick:a,className:`inline-flex h-7 w-7 items-center justify-center rounded-md transition ${t?"bg-brand-100 text-brand-700 dark:bg-brand-900/40 dark:text-brand-300":"text-neutral-600 hover:bg-neutral-100 dar
105k:text-neutral-300 dark:hover:bg-neutral-700"}`,children:r})}function Wt({canvasRef:t,tokens:a=[]}){var B;const{t:n}=L(),[r,s]=p.useState(null),[i,l]=p.useState({top:0,left:0,below:!1}),[d,c]=p.useState({bold:!1,italic:!1,underline:!1}),[o,x]=p.useState(!1),[f,u]=p.useState(""),[y,_]=p.useState(!1),b=p.useRef(null),w=p.useRef(null),S=p.useCallback(g=>{if(!g)return;const h=g.getBoundingClientRect(),k=h.top<64;l({top:k?h.bottom:h.top,left:h.left+Math.min(h.width/2,160),below:k})},[]),T=p.useCallback(()=>{try{c({bold:document.queryCommandState("bold"),italic:document.queryCommandState("italic"),underline:document.queryCommandState("underline")})}catch{}},[]);if(p.useEffect(()=>{const g=t.current;if(!g)return;function h(C){var I,J;const z=(J=(I=C.target).closest)==null?void 0:J.call(I,"[data-ee-text]");z&&g.contains(z)&&(s(z),S(z),x(!1),_(!1))}function k(){setTimeout(()=>{var z;const C=document.activeElement;b.current&&b.current.contains(C)||C&&((z=C.closest)!=null&&z.call(C,"[data-ee-text]"))&&g.contains(C)||(s(null),x(!1),_(!1))},0)}return g.addEventListener("focusin",h),g.addEventListener("focusout",k),()=>{g.removeEventListener("focusin",h),g.removeEventListener("focusout",k)}},[t,S]),p.useEffect(()=>{function g(){if(!r)return;const h=window.getSelection();h&&h.rangeCount&&r.contains(h.anchorNode)&&(w.current=h.getRangeAt(0).cloneRange()),T(),S(r)}return document.addEventListener("selectionchange",g),()=>document.removeEventListener("selectionchange",g)},[r,S,T]),p.useEffect(()=>{if(!r)return;const g=()=>S(r);return window.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{window.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g)}},[r,S]),!r)return null;const m=((B=r.closest("[data-ee-block]"))==null?void 0:B.dataset.eeBlock)!=="button";function v(){const g=w.current;if(!g)return;r.focus();const h=window.getSelection();h.removeAllRanges(),h.addRange(g)}function $(g,h=null){v();try{document.execCommand("styleWithCSS",!1,!1)}catch{}document.execCommand(g,!1,h),r.dispatchEvent(new Event("input",{bubbles:!0})),T()}function R(){let g=f.trim();if(!g){x(!1);return}/^(https?:|mailto:|tel:|#|\{\{)/i.test(g)||(g="https://"+g),$("createLink",g),x(!1),u("")}return Me.createPortal(e.jsx("div",{ref:b,"data-ee-toolbar":"",onMouseDown:g=>{g.target.tagName!=="INPUT"&&g.preventDefault()},style:{position:"fixed",top:i.top,left:i.left,transform:i.below?"translate(-50%, 8px)":"translate(-50%, calc(-100% - 8px))"},className:"z-[60] flex items-center gap-0.5 rounded-lg border border-neutral-200 bg-white px-1 py-1 shadow-soft-lg dark:border-neutral-700 dark:bg-neutral-800",children:o?e.jsxs("div",{className:"flex items-center gap-1 px-1",children:[e.jsx("input",{autoFocus:!0,t
105ype:"text",value:f,onChange:g=>u(g.target.value),onKeyDown:g=>{g.key==="Enter"?(g.preventDefault(),R()):g.key==="Escape"&&x(!1)},placeholder:n("email_editor.link_placeholder"),className:"w-52 rounded-md border border-neutral-300 bg-white px-2 py-1 text-xs focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500 dark:border-neutral-600 dark:bg-neutral-900"}),e.jsx("button",{type:"button",onClick:R,className:"rounded-md bg-brand-600 px-2 py-1 text-xs font-medium text-white hover:bg-brand-700",children:n("email_editor.apply")}),e.jsx("button",{type:"button",onClick:()=>x(!1),className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-neutral-500 hover:bg-neutral-100 dark:hover:bg-neutral-700",children:e.jsx(at,{className:"h-3.5 w-3.5"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(W,{active:d.bold,onClick:()=>$("bold"),title:n("email_editor.bold"),children:e.jsx(bt,{className:"h-3.5 w-3.5"})}),e.jsx(W,{active:d.italic,onClick:()=>$("italic"),title:n("email_editor.italic"),children:e.jsx(vt,{className:"h-3.5 w-3.5"})}),e.jsx(W,{active:d.underline,onClick:()=>$("underline"),title:n("email_editor.underline"),children:e.jsx(Rt,{className:"h-3.5 w-3.5"})}),e.jsx("span",{className:"mx-0.5 h-5 w-px bg-neutral-200 dark:bg-neutral-700"}),m&&e.jsx(W,{onClick:()=>x(!0),title:n("email_editor.insert_link"),children:e.jsx(nt,{className:"h-3.5 w-3.5"})}),e.jsx(W,{onClick:()=>$("removeFormat"),title:n("email_editor.clear_formatting"),children:e.jsx(Ct,{className:"h-3.5 w-3.5"})}),a.length>0&&e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"mx-0.5 inline-block h-5 w-px bg-neutral-200 align-middle dark:bg-neutral-700"}),e.jsx(W,{onClick:()=>_(g=>!g),title:n("email_editor.insert_variable"),children:e.jsx(de,{className:"h-3.5 w-3.5"})}),y&&e.jsx("div",{className:"absolute left-1/2 top-full z-10 mt-1 w-56 -translate-x-1/2 rounded-lg border border-neutral-200 bg-white py-1 shadow-soft-lg dark:border-neutral-700 dark:bg-neutral-800",children:a.map(g=>e.jsxs("button",{type:"button",onClick:()=>{$("insertText",g.key),_(!1)},className:"flex w-full items-center justify-between px-3 py-1.5 text-left text-xs hover:bg-neutral-50 dark:hover:bg-neutral-700",children:[e.jsx("span",{className:"text-neutral-700 dark:text-neutral-200",children:g.label}),e.jsx("span",{className:"font-mono text-[10px] text-neutral-400",children:g.key})]},g.key))})]})]})}),document.body)}const G="w-full rounded-lg border border-neutral-300 bg-white px-2.5 py-1.5 text-sm focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500 dark:border-neutral-600 dar
105k:bg-neutral-800",O="mb-1 block text-xs font-medium text-neutral-500 dark:text-neutral-400",Ce={1:"text-3xl font-bold leading-tight",2:"text-2xl font-bold leading-tight",3:"text-xl font-semibold leading-snug"},je={heading:"email_editor.block_heading",paragraph:"email_editor.block_text",button:"email_editor.block_button",image:"email_editor.block_image",divider:"email_editor.block_divider",spacer:"email_editor.block_spacer"};function Vt({blocks:t,onChange:a,tokens:n=[]}){const{t:r}=L(),s=p.useRef(null),[i,l]=p.useState(null),[d,c]=p.useState(null),[o,x]=p.useState(null),[f,u]=p.useState(null),[y,_]=p.useState(null),b=p.useCallback((h,k)=>a(t.map(C=>C.id===h?{...C,...k}:C)),[t,a]),w=p.useCallback(h=>{a(t.filter(k=>k.id!==h)),l(k=>k===h?null:k),x(k=>k&&k.id===h?null:k)},[t,a]),S=p.useCallback(h=>{const k=t.findIndex(I=>I.id===h);if(k<0)return;const C={...t[k],id:E()},z=[...t];z.splice(k+1,0,C),a(z),l(C.id)},[t,a]),T=p.useCallback((h,k)=>{const C=Ht(h),z=[...t];z.splice(k,0,C),a(z),l(C.id),Pt(h)&&c(C.id)},[t,a]),P=p.useCallback((h,k)=>{if(h==null||k==null)return;const C=[...t],[z]=C.splice(h,1),I=h<k?k-1:k;C.splice(Math.max(0,Math.min(I,C.length)),0,z),a(C)},[t,a]);function m(h,k,C){u(k),h.dataTransfer.effectAllowed="move",h.dataTransfer.setData("text/plain",String(k)),C.current&&h.dataTransfer.setDragImage(C.current,24,16)}function v(h,k,C){if(f==null)return;h.preventDefault(),h.dataTransfer.dropEffect="move";const z=C.current.getBoundingClientRect(),I=h.clientY>z.top+z.height/2;_(I?k+1:k)}function $(){u(null),_(null)}function R(h){h.preventDefault(),f!=null&&y!=null&&P(f,y),$()}const B=p.useCallback((h,k)=>{l(h),x({id:h,anchorEl:k})},[]),g=o?t.find(h=>h.id===o.id):null;return e.jsxs("div",{children:[e.jsx("style",{children:qt}),e.jsxs("div",{ref:s,"data-ee-canvas":"",onDragOver:h=>f!=null&&h.preventDefault(),onDrop:R,onClick:h=>{h.target===h.currentTarget&&l(null)},className:"mx-auto max-w-[640px] rounded-xl border border-neutral-200 bg-white p-4 text-neutral-900 shadow-soft dark:border-neutral-700 sm:p-6",children:[t.length===0&&e.jsx("div",{className:"rounded-lg border-2 border-dashed border-neutral-300 p-10 text-center text-sm text-neutral-400",children:r("email_editor.empty_canvas")}),t.map((h,k)=>e.jsxs("div",{children:[e.jsx(Yt,{onPick:C=>T(C,k)}),f!=null&&y===k&&e.jsx(Se,{}),e.jsx(Gt,{block:h,index:k,selected:i===h.id,dragging:f===k,autoFocus:d===h.id,onSelect:l,onUpdate:b,onRemove:w,onDuplicate:S,onOpenSettings:B,onDragStart:m,onDragOver:v,onDragEnd:$})]},h.id)),f!=null&&y===t.length&&e.jsx(Se,{}),e.jsx(Jt,{onAdd:h=>T(h,t.length),onDragOver:h=>{f!=null&&(h.preventDefault(),_(t.length))}})]}),e.jsx(Wt,{canvasRef:s,tokens:n}),o&&g&&e.jsxs(Xt,{anchorEl:o.anchorEl,onClose:()=>x(null),children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-neutral-400",children:r("email_editor.block_settings",{block:r(je[g.type]??"",g.type)})}),e.jsx("button",{type:"button",onClick:()=>
105x(null),className:"text-neutral-400 hover:text-neutral-600 dark:hover:text-neutral-300",children:e.jsx(_e,{className:"h-4 w-4 rotate-45"})})]}),e.jsx(Qt,{block:g,onChange:h=>b(g.id,h)})]})]})}function Gt({block:t,index:a,selected:n,dragging:r,autoFocus:s,onSelect:i,onUpdate:l,onRemove:d,onDuplicate:c,onOpenSettings:o,onDragStart:x,onDragOver:f,onDragEnd:u}){const{t:y}=L(),_=p.useRef(null);return e.jsxs("div",{ref:_,"data-ee-block":t.type,onDragOver:b=>f(b,a,_),onClick:b=>{b.stopPropagation(),i(t.id)},className:`group relative my-0.5 rounded-lg border px-3 py-1.5 transition ${r?"opacity-40":""} ${n?"border-brand-500 ring-1 ring-brand-500":"border-transparent hover:border-brand-200"}`,children:[e.jsxs("div",{className:`absolute -top-3 right-2 z-20 flex items-center gap-0.5 rounded-lg border border-neutral-200 bg-white px-0.5 py-0.5 shadow-soft-md transition dark:border-neutral-700 dark:bg-neutral-800 ${n?"opacity-100":"pointer-events-none opacity-0 group-hover:pointer-events-auto group-hover:opacity-100"}`,children:[e.jsx("button",{type:"button",draggable:!0,onDragStart:b=>x(b,a,_),onDragEnd:u,onClick:b=>b.stopPropagation(),title:y("email_editor.drag_to_reorder"),className:"flex h-6 w-6 cursor-grab items-center justify-center rounded text-neutral-400 hover:bg-neutral-100 hover:text-neutral-700 active:cursor-grabbing dark:hover:bg-neutral-700",children:e.jsx(rt,{className:"h-3.5 w-3.5"})}),e.jsx(be,{title:y("email_editor.settings"),onClick:b=>o(t.id,b.currentTarget),children:e.jsx(st,{className:"h-3.5 w-3.5"})}),e.jsx(be,{title:y("email_editor.duplicate"),onClick:()=>c(t.id),children:e.jsx(it,{className:"h-3.5 w-3.5"})}),e.jsx(be,{title:y("common.delete"),danger:!0,onClick:()=>d(t.id),children:e.jsx(ot,{className:"h-3.5 w-3.5"})})]}),e.jsx(Kt,{block:t,autoFocus:s,onChange:b=>l(t.id,b),onRequestSettings:b=>o(t.id,b)})]})}function be({title:t,danger:a,onClick:n,children:r}){return e.jsx("button",{type:"button",title:t,onClick:s=>{s.stopPropagation(),n(s)},className:`flex h-6 w-6 items-center justify-center rounded transition ${a?"text-neutral-400 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-950/40":"text-neutral-400 hover:bg-neutral-100 hover:text-neutral-700 dark:hover:bg-neutral-700 dark:hover:text-neutral-200"}`,children:r})}function Kt({block:t,autoFocus:a,onChange:n,onRequestSettings:r}){const{t:s}=L();switch(t.type){case"heading":{const i=`h${t.level||2}`;return e.jsx(ge,{as:i,singleLine:!0,autoFocus:a,html:t.text,placeholder:s("email_editor.block_heading"),onChange:l=>n({text:l}),className:Ce[t.level]||Ce[2],style:{margin:0,textAlign:t.align,color:t.color||"#111111"}})}case"paragraph":return e.jsx(ge,{as:"div",autoFocus:a,html:t.text,placeholder:s("email_editor.text_placeholder"),onChange:i=>n({text:i}),className:"text-[15px] leading-relaxed text-neutral-700",style:{textAlign:t.align}});case"button":return e.jsx("div",{style:{textAlign:t.align||"center"},children:e.jsx("span",{className:"inline-flex items-center rounded-md px-5 py-2.5 text-sm font-semibold shadow-sm",style:{background:t.color||"#2563eb",color:t.textColor||"#ffffff"},children:e.jsx(ge,{as:"span",singleLine:!0,autoFocus:a,html:t.text,placeholder:s("email_editor.block_button"),onChange:i=>n({text:i}),style:{minWidth:"3ch",textAlign:"center"}})})});case"image":return t.src?e.jsx("div",{style:{textAlign:t.align||"center"},children:e.jsx("img",{src:t.src,alt:t.alt||"",style:{width:t.width||void 0,maxWidth:"100%"},className:"inline-block rounded"})}):e.jsxs("button",{type:"button",onClick:i=>{i.stopPropagation(),r(i.currentTarget)},className:"flex w-full items-center justify-center gap-2 rounded-lg border-2 border-dashed border-neutral-300 py-8 text-sm text-neutral-400 transition hover:border-brand-400 hover:text-brand-600",children:[e.jsx(Ae,{className:"h-5 w-5"})," ",s("email_editor.click_add_image")]});case"divider":return e.jsx("hr",{className:"border-0 border-t",style:{borderTopColor:t.color||"#e5e7eb",borderTopWidth:1}});case"spacer":return e.jsx("div",{className:"flex items-center justify-center rounded border border-dashed border-neutral-200 text-[10px] uppercase tracking-wide text-neutral-300",style:{height:Math.max(16,Math.min(t.height??24,120))},children:s("email_editor.spacer_label",{height:t.height??24})});default:return null}}function Se(){return e.jsx("div",{className:"pointer-events-none mx-1 my-0.5 h-0.5 rounded-full bg-brand-500"})}function Yt({onPick:t}){const{t:a}=L(),[n,r]=p.useState(!1);return e.jsxs("div",{className:"group/iz relative h-2",onMouseLeave:()=>r(!1),children:[e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-1/2 h-px -translate-y-1/2 bg-brand-300 opacity-0 transition group-hover/iz:opacity-100"}),e.jsx("button",{type:"button",onClick:s=>{s.stopPropagation(),r(i=>!i)},title:a("email_editor.insert_block_here"),className:"absolute left-1/2 top-1/2 z-10 flex h-5 w-5 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-brand-500 text-white opacity-0 shadow transition hover:bg-brand-600 group-hover/iz:opacity-100",children:e.jsx(_e,{className:"h-3 w-3"})}),n&&e.jsx("div",{onClick:s=>s.stopPropagation(),className:"absolute left-1/2 top-full z-30 mt-1 flex -translate-x-1/2 gap-0.5 rounded-lg border border-neutral-200 bg-white p-1 shadow-soft-lg dark:border-neutral-700 dark:bg-neutral-800",children:De.map(({type:s,Icon:i})=>e.jsx("button",{type:"button",title:a(je[s]??"",s),onClick:()=>{t(s),r(!1)},className:"flex h-8 w-8 items-center justify-center rounded-md text-neutral-600 transition hover:bg-brand-50 hover:text-brand-600 dark:text-neutral-300 dark:hover:bg-neutral-700",children:e.jsx(i,{className:"h-4 w-4"})},s))})]})}function Jt({onAdd:t,onDragOver:a}){const{t:n}=L();return e.jsx("div",{onDragOver:a,className:"mt-3 flex flex-wrap gap-2 border-t border-dashed border-neutral-200 pt-3",children:De.map(({type:r,Icon:s})=>e.jsxs("button",{type:"button",onClick:()=>t(r),className:"inline-flex items-center gap-1.5 rounded-lg border border-dashed border-neutral-300 px-3 py-1.5 text-xs font-medium text-neutral-600 transition hover:border-brand-400 hover:text-brand-600",children:[e.jsx(_e,{className:"h-3.5 w-3.5"}),e.jsx(s,{className:"h-3.5 w-3.5"}),n(je[r]??"",r)]},r))})}function Xt({anchorEl:t,onClose:a,children:n,width:r=300}){const s=p.useRef(null),[i,l]=p.useState(null);return p.useLayoutEffect(()=>{function d(){if(!t)return;const c=t.getBoundingClientRect(),o=window.innerHeight-c.bottom-16,x=c.top-16,f=o>=260||o>=x;let u=c.right-r;u=Math.max(8,Math.min(u,window.innerWidth-r-8)),l({left:u,top:f?c.bottom+6:c.top-6,placeBelow:f,maxHeight:(f?o:x)-8})}return d(),window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[t,r]),p.useEffect(()=>{function d(o){var x;(x=s.current)!=null&&x.contains(o.target)||t!=null&&t.contains(o.target)||a()}function c(o){o.key==="Escape"&&a()}return document.addEventListener("mousedown",d),document.addEventListener("keydown",c),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",c)}},[t,a]),i?Me.createPortal(e.jsx("div",{ref:s,style:{position:"fixed",top:i.top,left
105:i.left,width:r,maxHeight:i.maxHeight,transform:i.placeBelow?"none":"translateY(-100%)",overflowY:"auto"},className:"z-[55] rounded-xl border border-neutral-200 bg-white p-3 shadow-soft-xl dark:border-neutral-700 dark:bg-neutral-800",children:n}),document.body):null}function ne({value:t="left",onChange:a}){const n=[["left",At],["center",Lt],["right",Tt]];return e.jsx("div",{className:"inline-flex rounded-lg border border-neutral-300 p-0.5 dark:border-neutral-600",children:n.map(([r,s])=>e.jsx("button",{type:"button",onClick:()=>a(r),className:`flex h-7 w-7 items-center justify-center rounded-md transition ${t===r?"bg-brand-100 text-brand-700 dark:bg-brand-900/40 dark:text-brand-300":"text-neutral-500 hover:bg-neutral-100 dark:hover:bg-neutral-700"}`,children:e.jsx(s,{className:"h-3.5 w-3.5"})},r))})}function re({label:t,value:a,onChange:n}){return e.jsxs("div",{children:[e.jsx("label",{className:O,children:t}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:a||"#000000",onChange:r=>n(r.target.value),className:"h-8 w-10 shrink-0 cursor-pointer rounded border border-neutral-300 p-0.5 dark:border-neutral-600"}),e.jsx("input",{type:"text",value:a||"",onChange:r=>n(r.target.value),className:G})]})]})}function ye({label:t,children:a}){return e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:`${O} mb-0`,children:t}),a]})}function Qt({block:t,onChange:a}){const{t:n}=L();switch(t.type){case"heading":return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:O,children:n("email_editor.field_level")}),e.jsx("div",{className:"flex gap-1",children:[1,2,3].map(r=>e.jsxs("button",{type:"button",onClick:()=>a({level:r}),className:`flex-1 rounded-md py-1 text-xs font-bold transition ${t.level===r?"bg-brand-100 text-brand-700 dark:bg-brand-900/40 dark:text-brand-300":"border border-neutral-300 text-neutral-500 hover:bg-neutral-100 dark:border-neutral-600 dar
105k:hover:bg-neutral-700"}`,children:["H",r]},r))})]}),e.jsx(ye,{label:n("email_editor.field_alignment"),children:e.jsx(ne,{value:t.align,onChange:r=>a({align:r})})}),e.jsx(re,{label:n("email_editor.field_text_color"),value:t.color,onChange:r=>a({color:r})})]});case"paragraph":return e.jsx(ye,{label:n("email_editor.field_alignment"),children:e.jsx(ne,{value:t.align,onChange:r=>a({align:r})})});case"button":return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:O,children:n("email_editor.field_link_url")}),e.jsx("input",{type:"text",value:t.url||"",onChange:r=>a({url:r.target.value}),placeholder:"https://example.com",className:G})]}),e.jsx(ye,{label:n("email_editor.field_alignment"),children:e.jsx(ne,{value:t.align,onChange:r=>a({align:r})})}),e.jsx(re,{label:n("email_editor.field_background"),value:t.color,onChange:r=>a({color:r})}),e.jsx(re,{label:n("email_editor.field_text_color"),value:t.textColor,onChange:r=>a({textColor:r})})]});case"image":return e.jsxs("div",{className:"space-y-3",children:[e.jsx(tt,{value:t.src,onChange:r=>a({src:r}),accept:"image/*",collection:"email",placeholder:"https://…/image.jpg"}),e.jsxs("div",{children:[e.jsx("label",{className:O,children:n("email_editor.field_alt_text")}),e.jsx("input",{type:"text",value:t.alt||"",onChange:r=>a({alt:r.target.value}),placeholder:n("email_editor.field_alt_placeholder"),className:G})]}),e.jsxs("div",{children:[e.jsx("label",{className:O,children:n("email_editor.field_link_url_optional")}),e.jsx("input",{type:"text",value:t.url||"",onChange:r=>a({url:r.target.value}),placeholder:"https://example.com",className:G})]}),e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:O,children:n("email_editor.field_width")}),e.jsx("input",{type:"text",value:t.width||"",onChange:r=>a({width:r.target.value}),placeholder:n("email_editor.field_width_placeholder"),className:G})]}),e.jsx(ne,{value:t.align,onChange:r=>a({align:r})})]})]});case"divider":return e.jsx(re,{label:n("email_editor.field_line_color"),value:t.color,onChange:r=>a({color:r})});case"spacer":return e.jsxs("div",{children:[e.jsx("label",{className:O,children:n("email_editor.field_height",{height:t.height??24})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"range",min:8,max:120,value:t.height??24,onChange:r=>a({height:parseInt(r.target.value)}),className:"flex-1 accent-brand-500"}),e.jsx("input",{type:"number",min:8,max:200,value:t.height??24,onChange:r=>a({height:parseInt(r.target.value)||24}),className:`${G} w-20`})]})]});default:return null}}const oe="w-full rounded-lg border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-800 px-3 py-2 text-sm focus:outline-none focus:border-brand-500 focus:ring-1 focus:ring-brand-500",Zt="inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-sm font-medium transition disabled:opacity-50",ea=[{id:"templates",labelKey:"email_editor.tab_templates",Icon:Nt},{id:"visual",labelKey:"email_editor.tab_visual",Icon:dt},{id:"html",labelKey:"email_editor.tab_html",Icon:lt},{id:"ai",labelKey:"email_editor.tab_ai",Icon:ee}];function ta({subject:t,body:a,onSubjectChange:n,onBodyChange:r,contactTokens:s=[],campaignName:i=""}){const{t:l}=L(),[d,c]=p.useState("templates"),[o,x]=p.useState(()=>ae(a)),[f,u]=p.useState(!1),[y,_]=p.useState(!1),b=p.useRef(null),w=p.useRef(a);p.useEffect(()=>{if(d!=="visual")return;const v=Bt(o);v!==w.current&&(w.current=v,r(v))},[o,d,r]);function S(v){v==="visual"&&d!=="visual"&&(x(ae(a)),w.current=a),c(v),_(!1)}function T(v){n(v.subject),r(v.body),x(ae(v.body)),w.current=v.body,c("visual")}function P({subject:v,body:$}){n(v),r($),x(ae($)),w.current=$,_(!0),c("visual")}function m(v){const $=b.current;if(!$)return;const R=$.selectionStart,B=$.selectionEnd,g=a.slice(0,R)+v+a.slice(B);r(g),requestAnimationFrame(()=>{$.selectionStart=$.selectionEnd=R+v.length,$.focus()})}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:l("email_editor.subject")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ra,{subject:t,body:a,onPick:n}),e.jsx($e,{tokens:s,onPick:v=>n(t+v)})]})]}),e.jsx("input",{type:"text",value:t,onChange:v=>n(v.target.value),className:oe,placeholder:"Welcome, {{contact.first_name}}"})]}),y&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-700 dark:border-emerald-800 dark:bg-emerald-950/30 dark:text-emerald-300",children:[e.jsx(te,{className:"h-4 w-4 shrink-0"}),l("email_editor.ai_applied")]}),e.jsxs("div",{className:"flex items-center gap-1 border-b border-neutral-200 dark:border-neutral-700",children:[ea.map(({id:v,labelKey:$,Icon:R})=>e.jsxs("button",{type:"button",onClick:()=>S(v),className:`-mb-px inline-flex items-center gap-1.5 border-b-2 px-3 py-2 text-sm font-medium transition ${d===v?"border-brand-600 text-brand-600 dark:text-brand-400":"border-transparent text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300"}`,children:[e.jsx(R,{className:"h-3.5 w-3.5"}),l($)]},v)),(d==="html"||d==="visual")&&e.jsxs("button",{type:"button",onClick:()=>u(v=>!v),className:`mb-1 ml-auto inline-flex items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition ${f?"bg-brand-50 text-brand-600 dark:bg-brand-900/20 dark:text-brand-400":"text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300"}`,children:[e.jsx(ie,{className:"h-3.5 w-3.5"}),l("email_editor.preview")]})]}),e.jsxs("div",{className:f&&(d==="html"||d==="visual")?"grid grid-cols-2 gap-4":"",children:[e.jsxs("div",{children:[d==="templates"&&e.jsx(aa,{onSelect:T}),d==="visual"&&e.jsx(Vt,{blocks:o,onChange:x,tokens:s}),d==="html"&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsxs("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:[l("email_editor.email_body")," ",e.jsx("span",{className:"font-normal text-neutral-400",children:"(HTML)"})]}),e.jsx($e,{tokens:s,onPick:m})]}),e.jsx("textarea",{ref:b,rows:14,value:a,onChange:v=>r(v.target.value),placeholder:"<p>Hi {{contact.first_name}},</p>",className:`${oe} resize-y font-mono text-xs`})]}),d==="ai"&&e.jsx(na,{campaignName:i,onGenerated:P})]}),f&&(d==="html"||d==="visual")&&e.jsxs("div",{className:"overflow-hidden rounded-xl border border-neutral-200 bg-white dark:border-neutral-700 dark:bg-neutral-900",children:[e.jsxs("div",{className:"flex items-center gap-1.5 border-b border-neutral-200 px-3 py-2 text-xs font-medium text-neutral-500 dark:border-neutral-700 dark:text-neutral-400",children:[e.jsx(ie,{className:"h-3.5 w-3.5"})," ",l("email_editor.rendered_preview")]}),e.jsx("div",{className:"prose prose-sm max-h-[500px] max-w-none overflow-auto p-4 dark:prose-invert",dangerouslySetInnerHTML:{__html:a||`<p class="text-neutral-400">${l("email_editor.nothing_to_preview")}</p>`}})]})]})]})}function aa({onSelect:t}){const{t:a}=L(),n=[...new Set(fe.map(l=>l.category))],[r,s]=p.useState("all"),i=r==="all"?fe:fe.filter(l=>l.category===r);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:()=>s("all"),className:`rounded-full px-3 py-1 text-xs font-medium transition ${r==="all"?"bg-brand-600 text-white":"border border-neutral-300 text-neutral-600 hover:border-brand-400 dark:border-neutral-600 dar
105k:text-neutral-400"}`,children:a("email_editor.category_all")}),n.map(l=>e.jsx("button",{type:"button",onClick:()=>s(l),className:`rounded-full px-3 py-1 text-xs font-medium transition ${r===l?"bg-brand-600 text-white":"border border-neutral-300 text-neutral-600 hover:border-brand-400 dark:border-neutral-600 dark:text-neutral-400"}`,children:l},l))]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:i.map(l=>e.jsxs("div",{className:"group cursor-pointer overflow-hidden rounded-xl border border-neutral-200 transition hover:border-brand-400 dark:border-neutral-700",onClick:()=>t(l),children:[e.jsxs("div",{className:"relative h-32 overflow-hidden bg-neutral-50 p-3 dark:bg-neutral-800/50",children:[e.jsx("div",{className:"pointer-events-none w-[182%] origin-top-left scale-[0.55]",dangerouslySetInnerHTML:{__html:l.body}}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-transparent to-neutral-50 dark:to-neutral-800/80"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-neutral-800 dark:text-neutral-200",children:l.name}),e.jsx("div",{className:"text-xs text-neutral-500",children:l.category})]}),e.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),t(l)},className:"rounded-lg bg-brand-600 px-3 py-1.5 text-xs font-medium text-white opacity-0 transition group-hover:opacity-100",children:a("email_editor.use")})]})]},l.id))})]})}function na({campaignName:t,onGenerated:a}){const{t:n}=L(),[r,s]=p.useState(""),[i,l]=p.useState("professional"),[d,c]=p.useState(!1),[o,x]=p.useState(null);async function f(){var u,y;if(r.trim()){c(!0),x(null);try{const{data:_}=await K.post(route("client.campaigns.generate-email"),{prompt:r,tone:i,campaign_name:t});a(_)}catch(_){x(((y=(u=_.response)==null?void 0:u.data)==null?void 0:y.error)??n("email_editor.generation_failed"))}finally{c(!1)}}}return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-brand-200 bg-brand-50 p-4 dark:border-brand-800 dark:bg-brand-950/30",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2 text-sm font-semibold text-brand-700 dark:text-brand-300",children:[e.jsx(ee,{className:"h-4 w-4"})," ",n("email_editor.ai_generator")]}),e.jsx("p",{className:"text-xs text-brand-600 dark:text-brand-400",children:n("email_editor.ai_generator_desc")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:n("email_editor.ai_prompt_label")}),e.jsx("textarea",{rows:4,value:r,onChange:u=>s(u.target.value),placeholder:n("email_editor.ai_prompt_placeholder"),className:`${oe} resize-none`})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:n("email_editor.tone")}),e.jsxs("select",{value:i,onChange:u=>l(u.target.value),className:oe,children:[e.jsx("option",{value:"professional",children:n("email_editor.tone_professional")}),e.jsx("option",{value:"friendly",children:n("email_editor.tone_friendly")}),e.jsx("option",{value:"urgent",children:n("email_editor.tone_urgent")}),e.jsx("option",{value:"informative",children:n("email_editor.tone_informative")})]})]}),o&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-700 dark:border-red-800 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(U,{className:"mt-0.5 h-4 w-4 shrink-0"}),o]}),e.jsxs("button",{type:"button",disabled:d||!r.trim(),onClick:f,className:`${Zt} ai-glow w-full justify-center bg-brand-600 text-white hover:bg-brand-700`,children:[d?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ee,{className:"h-4 w-4"}),n(d?"email_editor.generating":"email_editor.generate_email")]}),e.jsx("p",{className:"text-center text-xs text-neutral-400",children:n("email_editor.ai_footer_note")})]})}function ra({subject:t,body:a,onPick:n}){const{t:r}=L(),[s,i]=p.useState(!1),[l,d]=p.useState(!1),[c,o]=p.useState([]),[x,f]=p.useState(null);async function u(){var _,b;if(t.trim()){d(!0),f(null),o([]),i(!0);try{const{data:w}=await K.post(route("client.campaigns.improve-subject"),{subject:t,body:a});o(w.suggestions??[])}catch(w){f(((b=(_=w.response)==null?void 0:_.data)==null?void 0:b.error)??r("email_editor.suggestions_failed"))}finally{d(!1)}}}function y(_){n(_),i(!1),o([])}return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",disabled:!t.trim(),onClick:u,title:r("email_editor.improve_title"),className:"ai-glow inline-flex items-center gap-1 rounded-md border border-brand-300 bg-brand-50 px-2 py-1 text-xs font-medium text-brand-700 transition hover:bg-brand-100 disabled:opacity-40 dark:border-brand-700 dark:bg-brand-950/40 dark:text-brand-300 dark:hover:bg-brand-900/50",children:[l?e.jsx(q,{className:"h-3 w-3 animate-spin"}):e.jsx(ee,{className:"h-3 w-3"}),r("email_editor.improve")]}),s&&e.jsxs("div",{className:"absolute right-0 z-40 mt-1 w-96 rounded-xl border border-neutral-200 bg-white shadow-xl dark:border-neutral-700 dark:bg-neutral-900",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-neutral-100 px-4 py-3 dark:border-neutral-800",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-neutral-800 dark:text-neutral-200",children:[e.jsx(ee,{className:"h-4 w-4 text-brand-500"}),r("email_editor.subject_suggestions")]}),e.jsx("button",{type:"button",onClick:()=>i(!1),className:"text-lg leading-none text-neutral-400 hover:text-neutral-600 dar
105k:hover:text-neutral-300",children:"×"})]}),e.jsxs("div",{className:"space-y-2 p-3",children:[l&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-neutral-400",children:[e.jsx(q,{className:"h-4 w-4 animate-spin"}),r("email_editor.generating_suggestions")]}),x&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-red-200 bg-red-50 p-3 text-xs text-red-700 dark:border-red-800 dark:bg-red-950/30 dark:text-red-300",children:[e.jsx(U,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),x]}),c.map((_,b)=>e.jsxs("button",{type:"button",onClick:()=>y(_),className:"group w-full rounded-lg border border-neutral-200 px-3 py-2.5 text-left text-sm text-neutral-800 transition hover:border-brand-400 hover:bg-brand-50 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-brand-900/20",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{children:_}),e.jsxs("span",{className:"mt-0.5 shrink-0 text-xs text-brand-600 opacity-0 transition group-hover:opacity-100 dark:text-brand-400",children:[r("email_editor.use")," →"]})]}),e.jsx("div",{className:"mt-1 text-xs text-neutral-400",children:r("email_editor.char_count",{count:_.length})})]},b))]})]})]})}function $e({tokens:t,onPick:a}){const{t:n}=L(),[r,s]=p.useState(!1);return!t||t.length===0?null:e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>s(i=>!i),className:"inline-flex items-center gap-1 rounded-md border border-neutral-300 px-2 py-1 text-xs font-medium text-neutral-700 hover:bg-neutral-50 dark:border-neutral-600 dar
105k:text-neutral-300 dark:hover:bg-neutral-800",children:[e.jsx(de,{className:"h-3 w-3"})," ",n("email_editor.insert_variable")]}),r&&e.jsx("div",{className:"absolute right-0 z-30 mt-1 w-56 rounded-lg border border-neutral-200 bg-white shadow-lg dark:border-neutral-700 dark:bg-neutral-800",onMouseLeave:()=>s(!1),children:t.map(i=>e.jsxs("button",{type:"button",onClick:()=>{a(i.key),s(!1)},className:"flex w-full items-center justify-between px-3 py-1.5 text-left text-xs hover:bg-neutral-50 dark:hover:bg-neutral-700",children:[e.jsx("span",{children:i.label}),e.jsx("span",{className:"font-mono text-neutral-400",children:i.key})]},i.key))})]})}const se=[{key:"channel",labelKey:"campaign.step_channel"},{key:"audience",labelKey:"campaign.step_audience"},{key:"content",labelKey:"campaign.step_content"},{key:"schedule",labelKey:"campaign.step_schedule"},{key:"review",labelKey:"campaign.step_review"}],ue={whatsapp:{label:"WhatsApp",Icon:t=>e.jsx(xe,{channel:"whatsapp",...t})},sms:{label:"SMS",Icon:t=>e.jsx(xe,{channel:"sms",...t})},email:{label:"Email",Icon:t=>e.jsx(xe,{channel:"email",...t})}},A="mt-1 w-full rounded-lg border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-800 px-3 py-2 text-sm focus:outline-none focus:border-brand-500 focus:ring-1 focus:ring-brand-500";function H({message:t}){return t?e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-xs text-red-600 dark:text-red-400",children:[e.jsx(U,{className:"h-3.5 w-3.5"}),t]}):null}function sa(t,a){var r,s,i,l,d,c,o,x,f,u;const n=a||Q()||"Asia/Dhaka";if(t){const y=t.timezone||n;return{name:t.name??"",channel:t.channel??"whatsapp",whatsapp_phone_number_id:t.whatsapp_phone_number_id??"",audience_type:t.audience_type??"segment",audience_ref:t.audience_ref??"",template_ref:{name:((r=t.template_ref)==null?void 0:r.name)??"",language:((s=t.template_ref)==null?void 0:s.language)??"en",components:((i=t.template_ref)==null?void 0:i.components)??[]},payload_json:{subject:((l=t.payload_json)==null?void 0:l.subject)??"",body:((d=t.payload_json)==null?void 0:d.body)??"",from_email:((c=t.payload_json)==null?void 0:c.from_email)??"",from_name:((o=t.payload_json)==null?void 0:o.from_name)??"",reply_to:((x=t.payload_json)==null?void 0:x.reply_to)??"",track_opens:((f=t.payload_json)==null?void 0:f.track_opens)??!0,track_clicks:((u=t.payload_json)==null?void 0:u.track_clicks)??!1},schedule_at:t.schedule_at?Je(t.schedule_at,y):"",timezone:y}}return{name:"",channel:"whatsapp",whatsapp_phone_number_id:"",audience_type:"segment",audience_ref:"",template_ref:{name:"",language:"en",components:[]},payload_json:{subject:"",body:"",from_email:"",from_name:"",reply_to:"",track_opens:!0,track_clicks:!1},schedule_at:"",timezone:n}}function ze(t=[]){const a=[];return t.forEach(n=>{if(!n||typeof n!="object")return;const r=(n.type||"").toLowerCase();if(r==="header"){const s=(n.format||"").toUpperCase();if(s==="TEXT"){const i=Le(n.text||"");i.length&&a.push({section:"header",sub_type:"text",slots:i})}else["IMAGE","VIDEO","DOCUMENT"].includes(s)&&a.push({section:"header",sub_type:s.toLowerCase(),slots:[{kind:"static",value:"",label:`${s.toLowerCase()} URL`,mediaKind:s.toLowerCase()}]})}else if(r==="body"){const s=Le(n.text||"");s.length&&a.push({section:"body",sub_type:"text",slots:s})}else r==="buttons"&&Array.isArray(n.buttons)&&n.buttons.forEach((s,i)=>{if(!s)return;const l=(s.type||"").toLowerCase();l==="url"&&typeof s.url=="string"&&s.url.includes("{{")&&a.push({section:"button",sub_type:"url",button_index:i,slots:[{kind:"static",value:"",label:`Button ${i+1} URL parameter`}]}),l==="copy_code"&&a.push({section:"button",sub_type:"copy_code",button_index:i,slots:[{kind:"static",value:"",label:`Button ${i+1} copy code`}]})})}),a}function Le(t){return((t||"").match(/\{\{\s*\d+\s*\}\}/g)||[]).map((n,r)=>({kind:"static",value:"",label:`Variable ${n.replace(/\s+/g,"")} (slot ${r+1})`}))}function la(t){return t.filter(a=>a.slots&&a.slots.length).map(a=>{if(a.section==="header"&&a.sub_type==="text")return{type:"header",parameters:a.slots.map(n=>({type:"text",text:(n.kind==="variable",n.value)}))};if(a.section==="header"&&["image","video","document"].includes(a.sub_type)){const n=a.slots[0],r=a.sub_type,s={type:r,[r]:{link:n.value}};return r==="document"&&n.filename&&(s.document.filename=n.filename),{type:"header",parameters:[s]}}return a.section==="body"?{type:"body",parameters:a.slots.map(n=>({type:"text",text:n.value}))}:a.section==="button"?{type:"button",sub_type:a.sub_type,index:String(a.button_index),parameters:a.slots.map(n=>({type:a.sub_type==="copy_code"?"coupon_code":"text",text:n.value}))}:null}
105).filter(Boolean)}function ia(t){if(!Array.isArray(t))return"";const a=t.find(n=>n&&(n.type||"").toLowerCase()==="body");return(a==null?void 0:a.text)||""}function oa(t,a,n){if(!t)return"";let r=0;return t.replace(/\{\{\s*(\d+)\s*\}\}/g,()=>{const i=a.flatMap(l=>l.section==="body"?l.slots:[])[r++];if(!i||!i.value)return"___";if(i.value.startsWith("{{")){const l=n.find(d=>d.key===i.value);return l?`[${l.label}]`:i.value}return i.value})}function ln({campaign:t=null,mode:a="create",whatsappTemplates:n=[],whatsappPhoneNumbers:r=[],segments:s=[],tags:i=[],contactTokens:l=[]}){const{t:d}=L(),[c,o]=p.useState(0),[x,f]=p.useState((t==null?void 0:t.uuid)??null),[u,y]=p.useState(null),[_,b]=p.useState({loading:!1,matched:0,deliverable:0,sample:[],error:null}),[w,S]=p.useState({phone_e164:"",email:"",sending:!1,result:null}),T=Ke().props.timezone||Q()||"Asia/Dhaka",P=p.useMemo(()=>sa(t,T),[t==null?void 0:t.id]),{data:m,setData:v,post:$,patch:R,processing:B,errors:g,transform:h}=Ye(P),k=p.useMemo(()=>{if(m.channel!=="whatsapp"||!m.whatsapp_phone_number_id)return n;const j=r.find(N=>N.phone_number_id===m.whatsapp_phone_number_id);return j!=null&&j.waba_id?n.filter(N=>N.waba_id===j.waba_id):n},[n,r,m.channel,m.whatsapp_phone_number_id]),C=p.useMemo(()=>{var j;return m.channel!=="whatsapp"||!((j=m.template_ref)!=null&&j.name)?null:k.find(N=>N.name===m.template_ref.name&&N.language===m.template_ref.language)??null},[k,m.channel,m.template_ref.name,m.template_ref.language]),[z,I]=p.useState(()=>ze((C==null?void 0:C.components)??[]));p.useEffect(()=>{m.channel==="whatsapp"&&r.length===1&&!m.whatsapp_phone_number_id&&v("whatsapp_phone_number_id",r[0].phone_number_id),m.channel!=="whatsapp"&&m.whatsapp_phone_number_id&&v("whatsapp_phone_number_id","")},[m.channel]);const J=p.useRef(m.whatsapp_phone_number_id);p.useEffect(()=>{J.current!==m.whatsapp_phone_number_id&&(J.current=m.whatsapp_phone_number_id,v("template_ref",{name:"",language:"en",components:[]}))},[m.whatsapp_phone_number_id]),p.useEffect(()=>{if(m.channel==="whatsapp"&&C){const j=ze(C.components??[]);I(N=>N.length===j.length&&N.every((M,F)=>M.section===j[F].section&&M.sub_type===j[F].sub_type&&M.slots.length===j[F].slots.length)?N:j)}else m.channel!=="whatsapp"&&I([])},[C,m.channel]),p.useEffect(()=>{if(m.channel!=="whatsapp")return;const j=la(z);JSON.stringify(m.template_ref.components)===JSON.stringify(j)||v("template_ref",{...m.template_ref,components:j})},[z,m.channel]);const X=p.useRef(null);p.useEffect(()=>{if(X.current&&clearTimeout(X.current),m.audience_type==="csv"){b({loading:!1,matched:0,deliverable:0,sample:[],error:null});return}return X.current=setTimeout(()=>{b(j=>({...j,loading:!0,error:null})),K.post(route("client.campaigns.audience-preview"),{audience_type:m.audience_type,audience_ref:m.audience_ref,channel:m.channel}).then(j=>b({loading:!1,matched:j.data.matched??0,deliverable:j.data.deliverable??0,sample:j.data.sample??[],error:null})).catch(j=>{var N,M;return b({loading:!1,matched:0,deliverable:0,sample:[],error:((M=(N=j==null?void 0:j.response)==null?void 0:N.data)==null?void 0:M.message)??d("campaign.preview_error")})})},350),()=>X.current&&clearTimeout(X.current)},[m.audience_type,m.audience_ref,m.channel]);const me=async()=>{y("saving");try{const j={uuid:x,name:m.name,channel:m.channel,whatsapp_phone_number_id:m.whatsapp_phone_number_id||null,audience_type:m.audience_type,audience_ref:m.audience_ref||null,template_ref:m.template_ref,payload_json:m.payload_json,timezone:m.timezone,schedule_at:m.schedule_at?Z(m.schedule_at,m.timezone||"UTC"):null},N=await K.post(route("client.campaigns.store-draft"),j);return f(N.data.uuid),y("saved"),setTimeout(()=>y(null),3e3),!0}catch{return y("error"),setTimeout(()=>y(null),4e3),!1}},Pe=async()=>{await me()&&o(N=>Math.min(N+1,se.length-1))},Be=()=>o(j=>Math.max(j-1,0)),Fe=p.useMemo(()=>{if(c===0)return!(!m.name.trim()||!m.channel||m.channel==="whatsapp"&&r.length>1&&!m.whatsapp_phone_number_id);if(c===1)return m.audience_type==="segment"||m.audience_type==="tag"?!!m.audience_ref:!0;if(c===2){if(m.channel==="whatsapp")return!!m.template_ref.name;if(m.channel==="sms")return(m.payload_json.body||"").trim().length>0;if(m.channel==="email")return(m.payload_json.subject||"").trim().length>0&&(m.payload_json.body||"").trim().length>0}return!0},[c,m]),Oe=j=>{j.preventDefault(),h(N=>({...N,schedule_at:N.schedule_at?Z(N.schedule_at,N.timezone||"UTC"):null,audie
105nce_ref:N.audience_ref?String(N.audience_ref):null})),x?R(route("client.campaigns.update",x)):$(route("client.campaigns.store"))},qe=()=>{t!=null&&t.uuid&&(S(j=>({...j,sending:!0,result:null})),K.post(route("client.campaigns.test-send",t.uuid),{phone_e164:w.phone_e164||null,email:w.email||null}).then(j=>S(N=>({...N,sending:!1,result:{ok:!0,message:d("campaign.test_sent",{id:j.data.message_id||"OK"})}}))).catch(j=>S(N=>{var M,F;return{...N,sending:!1,result:{ok:!1,message:((F=(M=j==null?void 0:j.response)==null?void 0:M.data)==null?void 0:F.error)??d("campaign.test_failed")}}})))},Ue=(j,N,M)=>{I(F=>F.map((pe,Ve)=>Ve===j?{...pe,slots:pe.slots.map((ve,Ge)=>Ge===N?{...ve,...M}:ve)}:pe))},We=(j,N)=>{const M=m.payload_json[j]||"";v("payload_json",{...m.payload_json,[j]:M+N})};return e.jsx("form",{onSubmit:Oe,children:e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-[1fr_22rem]",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:se.map((j,N)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:async()=>{await me(),o(N)},className:`h-7 w-7 rounded-full flex items-center justify-center text-xs font-semibold transition cursor-pointer hover:ring-2 hover:ring-offset-1 hover:ring-brand-400 ${N===c?"bg-brand-600 text-white ring-2 ring-brand-400 ring-offset-1":N<c?"bg-brand-500 text-white":"bg-neutral-200 dark:bg-neutral-700 text-neutral-500 hover:bg-neutral-300 dark:hover:bg-neutral-600"}`,children:N<c?e.jsx(te,{className:"h-4 w-4"}):N+1}),e.jsx("button",{type:"button",onClick:async()=>{await me(),o(N)},className:`text-xs transition cursor-pointer ${N===c?"text-neutral-900 dark:text-neutral-100 font-medium":N<c?"text-brand-600 dark:text-brand-400 hover:underline":"text-neutral-400 hover:text-neutral-600 dar
105k:hover:text-neutral-300"}`,children:d(j.labelKey)}),N<se.length-1&&e.jsx("div",{className:`w-6 h-px ${N<c?"bg-brand-400":"bg-neutral-300 dark:bg-neutral-600"}`})]},j.key))}),e.jsxs("div",{className:"rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 p-6 space-y-4",children:[c===0&&e.jsx(da,{data:m,setData:v,errors:g,whatsappPhoneNumbers:r}),c===1&&e.jsx(ca,{data:m,setData:v,segments:s,tags:i,preview:_,errors:g}),c===2&&e.jsx(ua,{data:m,setData:v,whatsappTemplates:k,selectedTemplate:C,slots:z,updateSlot:Ue,contactTokens:l,insertTokenIntoTextarea:We,errors:g,campaignName:m.name}),c===3&&e.jsx(ma,{data:m,setData:v,errors:g}),c===4&&e.jsx(pa,{data:m,preview:_,selectedTemplate:C,slots:z,contactTokens:l,campaign:t,testTo:w,setTestTo:S,sendTest:qe})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[c>0&&e.jsxs("button",{type:"button",onClick:Be,className:"flex items-center gap-1.5 rounded-lg border border-neutral-300 dark:border-neutral-600 px-4 py-2 text-sm font-medium text-neutral-700 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-800 transition",children:[e.jsx(mt,{className:"h-4 w-4"})," ",d("common.back")]}),u==="saving"&&e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-neutral-400 dark:text-neutral-500",children:[e.jsx(q,{className:"h-3.5 w-3.5 animate-spin"})," ",d("campaign.saving_draft")]}),u==="saved"&&e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-emerald-600 dark:text-emerald-400",children:[e.jsx(Ze,{className:"h-3.5 w-3.5"})," ",d("campaign.draft_saved")]}),u==="error"&&e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-red-500 dark:text-red-400",children:[e.jsx(U,{className:"h-3.5 w-3.5"})," ",d("campaign.draft_save_failed")]}),c<se.length-1?e.jsx("button",{type:"button",onClick:Pe,disabled:!Fe||u==="saving",className:"ml-auto flex items-center gap-1.5 rounded-lg bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50 transition",children:u==="saving"?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-4 w-4 animate-spin"})," ",d("campaign.saving")]}):e.jsxs(e.Fragment,{children:[d("common.next")," ",e.jsx(pt,{className:"h-4 w-4"})]})}):e.jsxs("button",{type:"submit",disabled:B,className:"ml-auto flex items-center gap-1.5 rounded-lg bg-brand-600 px-5 py-2 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-60 transition",children:[e.jsx(Ie,{className:"h-4 w-4"}),d(B?"campaign.saving":a==="edit"?"campaign.save_changes":"campaign.create_campaign")]})]})]}),e.jsx(ba,{data:m,selectedTemplate:C,slots:z,contactTokens:l,audiencePreview:_,whatsappPhoneNumbers:r})]})})}function da({data:t,setData:a,errors:n,whatsappPhoneNumbers:r=[]}){const{t:s}=L();return e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"font-medium text-neutral-800 dark:text-neutral-200",children:s("campaign.name_and_channel")}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:s("common.name")}),e.jsx("input",{type:"text",value:t.name,onChange:i=>a("name",i.target.value),placeholder:s("campaign.name_placeholder"),required:!0,className:A}),e.jsx(H,{message:n.name})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300 block mb-2",children:s("campaign.channel")}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:Object.entries(ue).map(([i,l])=>{const d=l.Icon,c=t.channel===i;return e.jsxs("button",{type:"button",onClick:()=>a("channel",i),className:`rounded-xl border p-4 text-sm font-medium transition flex flex-col items-center gap-2 ${c?"border-brand-600 bg-brand-50 dark:bg-brand-900/20 text-brand-700 dark:text-brand-300":"border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:border-brand-300"}`,children:[e.jsx(d,{className:"h-6 w-6"}),l.label]},i)})}),e.jsx(H,{message:n.channel})]}),t.channel==="whatsapp"&&r.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300 block mb-2",children:s("campaign.send_from")}),r.length===1?e.jsxs("div",{className:"rounded-lg border border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800 px-3 py-2 text-sm text-neutral-700 dark:text-neutral-300",children:[r[0].display_phone,r[0].verified_name&&e.jsxs("span",{className:"ml-2 text-neutral-500 dark:text-neutral-400",children:["— ",r[0].verified_name]})]}):e.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:r.map(i=>{const l=t.whatsapp_phone_number_id===i.phone_number_id;return e.jsxs("button",{type:"button",onClick:()=>a("whatsapp_phone_number_id",i.phone_number_id),className:`rounded-xl border p-3 text-sm font-medium transition flex flex-col items-start gap-0.5 text-left ${l?"border-brand-600 bg-brand-50 dark:bg-brand-900/20 text-brand-700 dark:text-brand-300":"border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:border-brand-300"}`,children:[e.jsx("span",{children:i.display_phone}),i.verified_name&&e.jsx("span",{className:"text-xs font-normal text-neutral-500 dark:text-neutral-400",children:i.verified_name})]},i.phone_number_id)})}),e.jsx(H,{message:n.whatsapp_phone_number_id})]}),t.channel==="email"&&e.jsxs("div",{className:"rounded-lg border border-neutral-200 dark:border-neutral-700 p-4 space-y-4",children:[e.jsx("div",{className:"text-sm font-semibold text-neutral-700 dark:text-neutral-200",children:s("campaign.sender")}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-neutral-600 dar
105k:text-neutral-400",children:s("campaign.from_name")}),e.jsx("input",{type:"text",value:t.payload_json.from_name,onChange:i=>a("payload_json",{...t.payload_json,from_name:i.target.value}),placeholder:s("campaign.from_name_placeholder"),className:A})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-neutral-600 dark:text-neutral-400",children:s("campaign.from_email")}),e.jsx("input",{type:"email",value:t.payload_json.from_email,onChange:i=>a("payload_json",{...t.payload_json,from_email:i.target.value}),placeholder:s("campaign.from_email_placeholder"),className:A}),e.jsx(H,{message:n["payload_json.from_email"]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs font-medium text-neutral-600 dark:text-neutral-400",children:[s("campaign.reply_to")," ",e.jsxs("span",{className:"font-normal text-neutral-400",children:["(",s("common.optional"),")"]})]}),e.jsx("input",{type:"email",value:t.payload_json.reply_to,onChange:i=>a("payload_json",{...t.payload_json,reply_to:i.target.value}),placeholder:"[email protected]",className:A}),e.jsx(H,{message:n["payload_json.reply_to"]})]})]}),t.channel==="email"&&e.jsxs("div",{className:"rounded-lg border border-neutral-200 dark:border-neutral-700 p-4 space-y-4",children:[e.jsx("div",{className:"text-sm font-semibold text-neutral-700 dark:text-neutral-200",children:s("campaign.tracking")}),e.jsx(Te,{checked:!!t.payload_json.track_opens,onChange:i=>a("payload_json",{...t.payload_json,track_opens:i}),label:s("campaign.open_tracking"),description:s("campaign.open_tracking_desc")}),e.jsx(Te,{checked:!!t.payload_json.track_clicks,onChange:i=>a("payload_json",{...t.payload_json,track_clicks:i}),label:s("campaign.click_tracking"),description:s("campaign.click_tracking_desc")})]})]})}function ca({data:t,setData:a,segments:n,tags:r,preview:s,errors:i}){var c;const{t:l}=L(),d=((c=ue[t.channel])==null?void 0:c.label)??t.channel;return e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"font-medium text-neutral-800 dark:text-neutral-200",children:l("campaign.select_audience")}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300 block mb-2",children:l("campaign.audience_type")}),e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:[["segment",l("campaign.audience_segment")],["tag",l("campaign.audience_tag")],["contact_list",l("campaign.audience_all_contacts")],["csv",l("campaign.audience_csv_upload")]].map(([o,x])=>e.jsx("button",{type:"button",onClick:()=>{a("audience_type",o),o==="contact_list"&&a("audience_ref",""),o!==t.audience_type&&a("audience_ref","")},className:`rounded-lg border p-3 text-sm font-medium transition ${t.audience_type===o?"border-brand-600 bg-brand-50 dark:bg-brand-900/20 text-brand-700 dark:text-brand-300":"border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:border-brand-300"}`,children:x},o))}),e.jsx(H,{message:i.audience_type})]}),t.audience_type==="segment"&&e.jsx(Ee,{label:l("campaign.audience_segment"),items:n.map(o=>({id:o.id,label:o.name,meta:`${o.type??""}${o.contact_count?` · ${l("campaign.contact_count",{count:o.contact_count})}`:""}`})),value:t.audience_ref,onChange:o=>a("audience_ref",o),placeholder:l("campaign.pick_segment"),emptyHint:l("campaign.no_segments_hint")}),t.audience_type==="tag"&&e.jsx(Ee,{label:l("campaign.audience_tag"),items:r.map(o=>({id:o.id,label:o.name,meta:o.color??""})),value:t.audience_ref,onChange:o=>a("audience_ref",o),placeholder:l("campaign.pick_tag"),emptyHint:l("campaign.no_tags_hint")}),t.audience_type==="csv"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:l("campaign.csv_path")}),e.jsx("input",{type:"text",value:t.audience_ref,onChange:o=>a("audience_ref",o.target.value),placeholder:"campaigns/imports/abc.csv",className:A}),e.jsxs("p",{className:"mt-1 text-xs text-neutral-500 dark:text-neutral-400",children:[l("campaign.csv_hint"),e.jsx("span",{className:"font-mono",children:" phone_e164"})," ",l("campaign.or"),e.jsx("span",{className:"font-mono",children:" email"}),"."]})]}),e.jsxs("div",{className:"mt-4 rounded-lg border border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800/40 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-neutral-700 dark:text-neutral-200",children:[e.jsx(xt,{className:"h-4 w-4"})," ",l("campaign.audience_preview"),s.loading&&e.jsx(q,{className:"h-3.5 w-3.5 animate-spin text-neutral-400"})]}),s.error?e.jsx("p",{className:"mt-2 text-xs text-red-600 dark:text-red-400",children:s.error}):t.audience_type==="csv"?e.jsx("p",{className:"mt-2 text-xs text-neutral-500",children:l("campaign.csv_no_preview")}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"mt-2 text-sm text-neutral-700 dark:text-neutral-200",children:[e.jsx("span",{className:"font-semibold",children:s.matched.toLocaleStr
105ing()})," ",l("campaign.contacts_match")," ",e.jsxs("span",{className:"text-neutral-500 dark:text-neutral-400",children:[e.jsx("span",{className:"font-semibold text-emerald-600 dark:text-emerald-400",children:s.deliverable.toLocaleString()})," ",l("campaign.opted_in_for",{channel:d})]})]}),s.sample.length>0&&e.jsxs("div",{className:"mt-2 text-xs text-neutral-500",children:[l("campaign.sample"),": ",s.sample.map(o=>`${o.first_name??""} ${o.last_name??""}`.trim()||o.phone_e164||o.email).join(", ")]})]})]})]})}function ua({data:t,setData:a,whatsappTemplates:n,selectedTemplate:r,slots:s,updateSlot:i,contactTokens:l,insertTokenIntoTextarea:d,errors:c,campaignName:o}){var f;const{t:x}=L();return e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"font-medium text-neutral-800 dark:text-neutral-200",children:x("campaign.message_content")}),t.channel==="whatsapp"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:x("campaign.whatsapp_template")}),e.jsxs("select",{value:((f=n.find(u=>u.name===t.template_ref.name&&u.language===t.template_ref.language))==null?void 0:f.id)??"",onChange:u=>{const y=u.target.value;if(!y){a("template_ref",{name:"",language:"en",components:[]});return}const _=n.find(b=>String(b.id)===y);_&&a("template_ref",{...t.template_ref,name:_.name,language:_.language})},className:A,children:[e.jsx("option",{value:"",children:x("campaign.select_template")}),n.map(u=>e.jsxs("option",{value:u.id,children:[u.name," (",u.language,") — ",u.status]},u.id))]}),n.length===0&&e.jsx("p",{className:"mt-1 text-xs text-neutral-500 dark:text-neutral-400",children:x("campaign.no_templates_synced")}),e.jsx(H,{message:c["template_ref.name"]})]}),r&&s.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-neutral-800 dark:text-neutral-200",children:[e.jsx(de,{className:"h-4 w-4"})," ",x("campaign.template_variables")]}),s.map((u,y)=>e.jsxs("div",{className:"rounded-lg border border-neutral-200 dark:border-neutral-700 p-3 space-y-3",children:[e.jsxs("div",{className:"text-xs uppercase tracking-wider font-semibold text-neutral-500",children:[x(`campaign.section_${u.section}`,u.section),u.sub_type?` · ${u.sub_type}`:"",u.button_index!=null?` · ${x("campaign.button_n",{n:u.button_index+1})}`:""]}),u.slots.map((_,b)=>e.jsx(fa,{slot:_,label:_.label,mediaKind:_.mediaKind,contactTokens:l,onChange:w=>i(y,b,w)},b))]},`${u.section}-${u.sub_type}-${u.button_index??"x"}`))]}),r&&s.length===0&&e.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400",children:x("campaign.no_variables")})]}),t.channel==="sms"&&e.jsx(xa,{label:x("campaign.sms_body"),field:"body",value:t.payload_json.body,onChange:u=>a("payload_json",{...t.payload_json,body:u}),placeholder:x("campaign.sms_body_placeholder"),rows:4,contactTokens:l,onInsertToken:u=>d("body",u),error:c["payload_json.body"]}),t.channel==="email"&&e.jsxs(e.Fragment,{children:[e.jsx(ta,{subject:t.payload_json.subject,body:t.payload_json.body,onSubjectChange:u=>a("payload_json",{...t.payload_json,subject:u}),onBodyChange:u=>a("payload_json",{...t.payload_json,body:u}),contactTokens:l,campaignName:o}),c["payload_json.subject"]&&e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-xs text-red-600 dark:text-red-400",children:[e.jsx(U,{className:"h-3.5 w-3.5"}),c["payload_json.subject"]]}),c["payload_json.body"]&&e.jsxs("p",{className:"mt-1 flex items-center gap-1 text-xs text-red-600 dark:text-red-400",children:[e.jsx(U,{className:"h-3.5 w-3.5"}),c["payload_json.body"]]})]})]})}function ma({data:t,setData:a,errors:n}){const{t:r}=L(),s=t.timezone||Q(),i=t.schedule_at?Z(t.schedule_at,s):null,l=i?le(i,s):null,d=i&&s!==Q()?le(i,Q()):null;return e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"font-medium text-neutral-800 dark:text-neutral-200",children:r("campaign.step_schedule")}),e.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400",children:r("campaign.schedule_help")}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:r("campaign.send_at")}),e.jsx(ut,{mode:"datetime",value:t.schedule_at,onChange:c=>a("schedule_at",c),className:"mt-1",error:!!n.schedule_at}),e.jsx(H,{message:n.schedule_at})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:r("campaign.timezone")}),e.jsx(ct,{value:t.timezone,onChange:c=>a("timezone",c),className:"mt-1"}),e.jsx(H,{message:n.timezone})]})]}),l&&e.jsxs("div",{className:"rounded-md border border-blue-200 bg-blue-50 p-3 text-xs text-blue-900 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-200",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-medium",children:[e.jsx(te,{className:"h-3.5 w-3.5"}),r("campaign.will_be_sent_at")]}),e.jsx("div",{className:"mt-1",children:e.jsx("span",{className:"font-mono",children:l})}),d&&e.jsx("div",{className:"mt-0.5 text-[11px] text-blue-700 dark:text-blue-300",children:e.jsx(Re,{i18nKey:"campaign.which_is_browser",values:{time:d},components:{time:e.jsx("span",{className:"font-mono"})}})})]})]})}function pa({data:t,preview:a,selectedTemplate:n,slots:r,contactTokens:s,campaign:i,testTo:l,setTestTo:d,sendTest:c}){var f,u;const{t:o}=L(),x=((f=ue[t.channel])==null?void 0:f.label)??t.channel;return e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"font-medium text-neutral-800 dark:text-neutral-200",children:o("campaign.review_confirm")}),e.jsxs("dl",{className:"grid grid-cols-1 gap-2 text-sm sm:grid-cols-2",children:[[[o("common.name"),t.name||"—"],[o("campaign.col_channel"),x],[o("campaign.audience"),`${t.audience_type}${t.audience_ref?` · ${t.audience_ref}`:""}
105`],[o("campaign.reachable_contacts"),a.deliverable.toLocaleString()],[o("campaign.step_schedule"),t.schedule_at?`${le(Z(t.schedule_at,t.timezone),t.timezone)} (${t.timezone})`:o("campaign.on_demand")]].map(([y,_])=>e.jsxs("div",{className:"flex gap-3",children:[e.jsx("dt",{className:"w-32 shrink-0 font-medium text-neutral-500 dark:text-neutral-400",children:y}),e.jsx("dd",{className:"text-neutral-900 dark:text-neutral-100",children:_})]},y)),t.channel==="whatsapp"&&((u=t.template_ref)==null?void 0:u.name)&&e.jsxs("div",{className:"flex gap-3 sm:col-span-2",children:[e.jsx("dt",{className:"w-32 shrink-0 font-medium text-neutral-500 dark:text-neutral-400",children:o("campaign.template")}),e.jsxs("dd",{className:"text-neutral-900 dark:text-neutral-100 font-mono",children:[t.template_ref.name," (",t.template_ref.language,")"]})]}),t.channel==="email"&&(t.payload_json.from_email||t.payload_json.from_name)&&e.jsxs("div",{className:"flex gap-3 sm:col-span-2",children:[e.jsx("dt",{className:"w-32 shrink-0 font-medium text-neutral-500 dark:text-neutral-400",children:o("campaign.from")}),e.jsxs("dd",{className:"text-neutral-900 dark:text-neutral-100",children:[t.payload_json.from_name&&e.jsxs("span",{children:[t.payload_json.from_name," "]}),t.payload_json.from_email&&e.jsxs("span",{className:"text-neutral-500 dark:text-neutral-400",children:["<",t.payload_json.from_email,">"]})]})]}),t.channel==="email"&&t.payload_json.reply_to&&e.jsxs("div",{className:"flex gap-3 sm:col-span-2",children:[e.jsx("dt",{className:"w-32 shrink-0 font-medium text-neutral-500 dark:text-neutral-400",children:o("campaign.reply_to_short")}),e.jsx("dd",{className:"text-neutral-900 dark:text-neutral-100",children:t.payload_json.reply_to})]}),t.channel==="email"&&e.jsxs("div",{className:"flex gap-3 sm:col-span-2",children:[e.jsx("dt",{className:"w-32 shrink-0 font-medium text-neutral-500 dark:text-neutral-400",children:o("campaign.tracking")}),e.jsxs("dd",{className:"text-neutral-900 dark:text-neutral-100 space-x-2",children:[t.payload_json.track_opens&&e.jsx("span",{className:"inline-flex items-center rounded-full bg-emerald-100 dark:bg-emerald-900/30 px-2 py-0.5 text-xs font-medium text-emerald-700 dark:text-emerald-300",children:o("campaign.opens")}),t.payload_json.track_clicks&&e.jsx("span",{className:"inline-flex items-center rounded-full bg-blue-100 dark:bg-blue-900/30 px-2 py-0.5 text-xs font-medium text-blue-700 dark:text-blue-300",children:o("campaign.clicks")}),!t.payload_json.track_opens&&!t.payload_json.track_clicks&&e.jsx("span",{className:"text-neutral-400",children:o("campaign.disabled")})]})]})]}),(i==null?void 0:i.id)&&e.jsxs("div",{className:"rounded-lg border border-neutral-200 dark:border-neutral-700 p-4 mt-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-neutral-800 dark:text-neutral-200",children:[e.jsx(ie,{className:"h-4 w-4"})," ",o("campaign.send_a_test")]}),e.jsx("p",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:o("campaign.send_test_desc")}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("input",{type:"text",placeholder:o("campaign.phone_placeholder"),value:l.phone_e164,onChange:y=>d(_=>({..._,phone_e164:y.target.value})),className:A}),l.phone_e164&&!l.phone_e164.startsWith("+")&&!/^01[3-9]\d{8}$/.test(l.phone_e164)&&e.jsx("p",{className:"mt-1 text-xs text-amber-600 dark:text-amber-400",children:o("campaign.intl_number_hint")})]}),e.jsx("input",{type:"email",placeholder:o("common.email"),value:l.email,onChange:y=>d(_=>({..._,email:y.target.value})),className:A})]}),e.jsxs("button",{type:"button",disabled:l.sending||!l.phone_e164&&!l.email,onClick:c,className:"inline-flex items-center gap-2 rounded-lg bg-neutral-900 dark:bg-neutral-700 px-3 py-2 text-sm font-medium text-white hover:opacity-90 disabled:opacity-50",children:[l.sending?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(Ie,{className:"h-4 w-4"}),o("campaign.send_test")]}),l.result&&e.jsxs("p",{className:`text-xs ${l.result.ok?"text-emerald-600 dark:text-emerald-400":"text-red-600 dark:text-red-400"} flex items-center gap-1`,children:[l.result.ok?e.jsx(te,{className:"h-3.5 w-3.5"}):e.jsx(U,{className:"h-3.5 w-3.5"}),l.result.message]})]})]})}function Ee({label:t,items:a,value:n,onChange:r,placeholder:s,emptyHint:i}){const[l,d]=p.useState(""),[c,o]=p.useState(!1),x=p.useMemo(()=>a.filter(u=>u.label.toLowerCase().includes(l.toLowerCase())),[a,l]),f=a.find(u=>String(u.id)===String(n));return e.jsxs("div",{className:"relative",children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t}),e.jsxs("div",{className:"mt-1 relative",children:[e.jsx(ht,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-neutral-400"}),e.jsx("input",{type:"text",value:c?l:(f==null?void 0:f.label)??"",onChange:u=>{d(u.target.value),o(!0)},onFocus:()=>{o(!0),d("")},onBlur:()=>setTimeout(()=>
105o(!1),150),placeholder:s,className:`${A} pl-9`})]}),c&&e.jsx("div",{className:"absolute z-20 mt-1 max-h-56 w-full overflow-auto rounded-lg border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 shadow-lg",children:x.length===0?e.jsx("p",{className:"px-3 py-2 text-xs text-neutral-500",children:i}):x.map(u=>e.jsxs("button",{type:"button",onMouseDown:y=>{y.preventDefault(),r(String(u.id)),o(!1)},className:`flex w-full items-center justify-between px-3 py-2 text-left text-sm hover:bg-neutral-50 dark:hover:bg-neutral-700 ${String(u.id)===String(n)?"bg-brand-50 dark:bg-brand-900/30 text-brand-700 dark:text-brand-300":""}`,children:[e.jsx("span",{children:u.label}),u.meta&&e.jsx("span",{className:"text-xs text-neutral-400",children:u.meta})]},u.id))})]})}function xa({label:t,field:a,value:n,onChange:r,placeholder:s,rows:i=4,mono:l=!1,contactTokens:d,onInsertToken:c,error:o}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("label",{className:"text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t}),e.jsx(ha,{tokens:d,onPick:c})]}),e.jsx("textarea",{rows:i,value:n,onChange:x=>r(x.target.value),placeholder:s,className:`${A} resize-none ${l?"font-mono":""}`}),e.jsx(H,{message:o})]})}function ha({tokens:t,onPick:a}){const{t:n}=L(),[r,s]=p.useState(!1);return e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>s(i=>!i),className:"inline-flex items-center gap-1 rounded-md border border-neutral-300 dark:border-neutral-600 px-2 py-1 text-xs font-medium text-neutral-700 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-800",children:[e.jsx(de,{className:"h-3 w-3"})," ",n("campaign.insert_variable")]}),r&&e.jsx("div",{className:"absolute right-0 z-20 mt-1 w-56 rounded-lg border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 shadow-lg",onMouseLeave:()=>s(!1),children:t.map(i=>e.jsxs("button",{type:"button",onClick:()=>{a(i.key),s(!1)},className:"flex w-full items-center justify-between px-3 py-1.5 text-left text-xs hover:bg-neutral-50 dark:hover:bg-neutral-700",children:[e.jsx("span",{children:i.label}),e.jsx("span",{className:"font-mono text-neutral-400",children:i.key})]},i.key))})]})}function Te({checked:t,onChange:a,label:n,description:r}){return e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("button",{type:"button",role:"switch","aria-checked":t,onClick:()=>a(!t),className:`relative mt-0.5 inline-flex h-5 w-9 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2 ${t?"bg-brand-600":"bg-neutral-300 dark:bg-neutral-600"}`,children:e.jsx("span",{className:`pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow ring-0 transition duration-200 ${t?"translate-x-4":"translate-x-0"}`})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-neutral-800 dark:text-neutral-200",children:n}),r&&e.jsx("div",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:r})]})]})}function fa({slot:t,label:a,mediaKind:n,contactTokens:r,onChange:s}){const{t:i}=L();return n?e.jsx(ga,{slot:t,label:a,mediaKind:n,onChange:s}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-neutral-600 dar
105k:text-neutral-300",children:a}),!n&&e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{type:"button",onClick:()=>s({kind:"static"}),className:`rounded-md px-2 py-0.5 text-xs ${t.kind==="static"?"bg-brand-100 text-brand-700 dark:bg-brand-900/40 dark:text-brand-300":"text-neutral-500"}`,children:i("campaign.slot_static")}),e.jsx("button",{type:"button",onClick:()=>s({kind:"variable"}),className:`rounded-md px-2 py-0.5 text-xs ${t.kind==="variable"?"bg-brand-100 text-brand-700 dark:bg-brand-900/40 dark:text-brand-300":"text-neutral-500"}`,children:i("campaign.slot_variable")})]})]}),t.kind==="variable"?e.jsxs("select",{value:t.value,onChange:l=>s({value:l.target.value}),className:A,children:[e.jsx("option",{value:"",children:i("campaign.select_contact_field")}),r.map(l=>e.jsx("option",{value:l.key,children:l.label},l.key))]}):e.jsx("input",{type:"text",value:t.value,onChange:l=>s({value:l.target.value}),placeholder:n?`https://example.com/file.${n==="image"?"jpg":n==="video"?"mp4":"pdf"}`:i("campaign.enter_value"),className:A})]})}function ga({slot:t,label:a,mediaKind:n,onChange:r}){const{t:s}=L(),[i,l]=p.useState("upload"),[d,c]=p.useState(!1),[o,x]=p.useState(""),f=p.useRef(null),u=n==="image"?"image/*":n==="video"?"video/*":"application/pdf",y=n==="image"?"jpg":n==="video"?"mp4":"pdf",_=async b=>{var S,T,P;const w=(S=b.target.files)==null?void 0:S[0];if(w){c(!0),x("");try{const m=new FormData;m.append("file",w),m.append("collection","campaign-media");const v=await K.post(route("client.media.store"),m,{headers:{"Content-Type":"multipart/form-data"}});r({value:v.data.url})}catch(m){x(((P=(T=m==null?void 0:m.response)==null?void 0:T.data)==null?void 0:P.error)??s("campaign.upload_failed"))}finally{c(!1),f.current&&(f.current.value="")}}};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-xs text-neutral-600 dar
105k:text-neutral-300",children:a}),e.jsx("div",{className:"flex w-fit gap-0.5 rounded-lg bg-neutral-100 dark:bg-neutral-800 p-0.5",children:[["upload",s("campaign.tab_upload"),ke],["link",s("campaign.tab_link"),ft]].map(([b,w,S])=>e.jsxs("button",{type:"button",onClick:()=>l(b),className:`flex items-center gap-1.5 rounded-md px-3 py-1 text-xs font-medium transition ${i===b?"bg-white dark:bg-neutral-700 text-neutral-900 dark:text-neutral-100 shadow-sm":"text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300"}`,children:[e.jsx(S,{className:"h-3.5 w-3.5"})," ",w]},b))}),i==="upload"?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("input",{ref:f,type:"file",accept:u,onChange:_,className:"hidden"}),e.jsxs("button",{type:"button",onClick:()=>{var b;return(b=f.current)==null?void 0:b.click()},disabled:d,className:"flex w-full items-center justify-center gap-2 rounded-lg border border-dashed border-neutral-300 dark:border-neutral-600 px-3 py-2.5 text-sm text-neutral-600 dark:text-neutral-300 hover:border-brand-400 disabled:opacity-50",children:[d?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ke,{className:"h-4 w-4"}),d?s("campaign.uploading"):s("campaign.upload_media",{media:s(`campaign.media_${n}`,n)})]}),o&&e.jsxs("p",{className:"flex items-center gap-1 text-xs text-red-600 dark:text-red-400",children:[e.jsx(U,{className:"h-3.5 w-3.5"})," ",o]})]}):e.jsx("input",{type:"text",value:t.value,onChange:b=>r({value:b.target.value}),placeholder:`https://example.com/file.${y}`,className:A}),t.value&&!d&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-emerald-600 dark:text-emerald-400",children:[e.jsx(te,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("a",{href:t.value,target:"_blank",rel:"noreferrer",className:"truncate underline",children:s(n==="image"?"campaign.image_set":n==="video"?"campaign.video_set":"campaign.file_set")})]}),n==="image"&&t.value&&e.jsx("img",{src:t.value,alt:"",className:"mt-1 max-h-28 rounded-lg border border-neutral-200 dark:border-neutral-700 object-contain",onError:b=>{b.currentTarget.style.display="none"}})]})}function ba({data:t,selectedTemplate:a,slots:n,contactTokens:r,audiencePreview:s,whatsappPhoneNumbers:i=[]}){var c,o;const{t:l}=L();let d=null;if(t.channel==="whatsapp"){const x=ia((a==null?void 0:a.components)??[]),f=oa(x,n,r);d=e.jsx("div",{className:"rounded-2xl rounded-tl-none bg-emerald-50 dark:bg-emerald-900/20 px-3 py-2 text-sm text-neutral-800 dark:text-neutral-100 shadow-sm whitespace-pre-line",children:f||"—"})}else t.channel==="sms"?d=e.jsx("div",{className:"rounded-2xl rounded-tl-none bg-blue-50 dark:bg-blue-900/20 px-3 py-2 text-sm text-neutral-800 dark:text-neutral-100 whitespace-pre-line",children:t.payload_json.body||"—"}):t.channel==="email"&&(d=e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-wide text-neutral-500",children:l("campaign.subject")}),e.jsx("div",{className:"text-sm font-medium text-neutral-900 dark:text-neutral-100",children:t.payload_json.subject||"—"}),e.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert text-sm text-neutral-800 dark:text-neutral-200",dangerouslySetInnerHTML:{__html:t.payload_json.body||"—"}})]}));return e.jsxs("aside",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-neutral-800 dark:text-neutral-200",children:[e.jsx(ie,{className:"h-4 w-4"})," ",l("campaign.live_preview")]}),e.jsx("div",{className:"mt-3",children:d}),e.jsx("p",{className:"mt-3 text-xs text-neutral-500",children:e.jsx(Re,{i18nKey:"campaign.variables_hint",components:{field:e.jsx("span",{className:"font-mono"})}})})]}),e.jsxs("div",{className:"rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 p-4 space-y-1 text-xs",children:[e.jsx("div",{className:"font-medium text-neutral-700 dark:text-neutral-200",children:l("campaign.at_a_glance")}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-neutral-500",children:l("campaign.col_channel")}),e.jsx("span",{className:"font-medium text-neutral-800 dark:text-neutral-100",children:((c=ue[t.channel])==null?void 0:c.label)??t.channel})]}),t.channel==="whatsapp"&&t.whatsapp_phone_number_id&&(()=>{const x=i.find(f=>f.phone_number_id===t.whatsapp_phone_number_id);return x?e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-neutral-500",children:l("campaign.from")}),e.jsx("span",{className:"text-right font-medium text-neutral-800 dark:text-neutral-100",children:x.display_phone})]}):null})(),t.channel==="email"&&((o=t.payload_json)==null?void 0:o.from_email)&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-neutral-500",children:l("campaign.from")}),e.jsx("span",{className:"text-right font-medium text-neutral-800 dark:text-neutral-100 truncate max-w-[10rem]",children:t.payload_json.from_name?`${t.payload_json.from_name} <${t.payload_json.from_email}>`:t.payload_json.from_email})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-neutral-500",children:l("campaign.audience")}),e.jsx("span",{className:"font-medium text-neutral-800 dark:text-neutral-100",children:t.audience_type})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-neutral-500",children:l("campaign.reachable")}),e.jsx("span",{className:"font-medium text-emerald-600 dark:text-emerald-400",children:s.deliverable.toLocaleStr
105ing()})]}),t.schedule_at&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-neutral-500",children:l("campaign.step_schedule")}),e.jsx("span",{className:"text-right font-medium text-neutral-800 dark:text-neutral-100",children:le(Z(t.schedule_at,t.timezone),t.timezone)})]})]})]})}export{ln as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.