1import{j as e}from"./ui-vendor-DeaCpvuz.js";import{r as m,l as K,u as O}from"./react-vendor-BwON9l4R.js";import{u as S,b as C,c as w}from"./query-vendor-DsJQQYkK.js";import{c as Q,D as q,e as D,f as A,g as _,r as F,d as f,I as N,B as u,u as x,s as y,T as k}from"./index-Kz-5MvZ9.js";import{C as H,b as R,c as B,a as M}from"./card-B7gy2v7u.js";import{M as P}from"./mail-Bo0erBmJ.js";import{A as V,a as Y,b as W,c as G,d as J,e as U,f as X,g as Z}from"./alert-dialog-Bzgk2_9Q.js";import{E as ee}from"./eye-Dv41zyqO.js";import{T as se}from"./trash-2-Be1tE6R7.js";import{A as ae}from"./arrow-left-q65SDx_G.js";import{P as T}from"./plus-BFZk4Bhp.js";import"./supabase-vendor-eEOYocAC.js";/** 2 * @license lucide-react v0.462.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 te=Q("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);function ie({open:a,onOpenChange:d,subject:j,content:h}){const[t,o]=m.useState(""),[n,i]=m.useState(!1),l=async()=>{if(!t){x.error("Please enter an email address");return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)){x.error("Please enter a valid email address");return}i(!0);try{const{error:c}=await y.functions.invoke("send-test-email",{body:{subject:j,content:h,recipientEmail:t}});if(c)throw c;x.success(`Test email sent to ${t}`),o(""),d(!1)}catch(c){console.error("Error sending test email:",c),x.error(c.message||"Failed to send test email")}finally{i(!1)}};return e.jsx(q,{open:a,onOpenChange:d,children:e.jsxs(D,{children:[e.jsxs(A,{children:[e.jsx(_,{children:"Send Test Email"}),e.jsx(F,{children:"Enter an email address to receive a test version of this email"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"recipientEmail",children:"Recipient Email"}),e.jsx(N,{id:"recipientEmail",type:"email",placeholder:"[email protected]",value:t,onChange:p=>o(p.target.value),disabled:n})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(u,{variant:"outline",onClick:()=>d(!1),disabled:n,children:"Cancel"}),e.jsxs(u,{onClick:l,disabled:n,children:[e.jsx(P,{className:"w-4 h-4 mr-2"}),n?"Sending...":"Send Test"]})]})]})]})})}function re({template:a,sequenceId:d,orderIndex:j}){const h=S(),[t,o]=m.useState(!1),[n,i]=m.useState(!1),[l,p]=m.useState(!1),[c,v]=m.useState(a.subject),[g,b]=m.useState(a.content),[r,I]=m.useState(a.delay_hours),L=C({mutationFn:async()=>{const{error:s}=await y.from("email_templates").update({subject:c,content:g,delay_hours:r}).eq("id",a.id);if(s)throw s},onSuccess:()=>{h.invalidateQueries({queryKey:["email-templates",d]}),x.success("Email template updated"),o(!1)},onError:s=>{x.error("Failed to update template: "+s.message)}}),$=C({mutationFn:async()=>{const{error:s}=await y.from("email_templates").delete().eq("id",a.id);if(s)throw s},onSuccess:()=>{h.invalidateQueries({queryKey:["email-templates",d]}),x.success("Email template deleted")},onError:s=>{x.error("Failed to delete template: "+s.message)}}),z=s=>{if(s===0)return"Immediately";if(s<24)return`${s} hour${s>1?"s":""} later`;const E=Math.floor(s/24);return`${E} day${E>1?"s":""} later`};
6return e.jsxs(e.Fragment,{children:[e.jsxs(H,{children:[e.jsx(R,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary text-primary-foreground flex items-center justify-center font-bold",children:j}),e.jsxs("div",{children:[e.jsx(B,{className:"text-lg",children:t?"Edit Email":c}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:z(t?r:a.delay_hours)})]})]}),e.jsxs("div",{className:"flex gap-2",children:[!t&&e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>p(!0),title:"Send test email",children:e.jsx(P,{className:"w-4 h-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>o(!0),children:e.jsx(ee,{className:"w-4 h-4"})}),e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>i(!0),children:e.jsx(se,{className:"w-4 h-4"})})]}),t&&e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"ghost",onClick:()=>o(!1),children:"Cancel"}),e.jsxs(u,{onClick:()=>L.mutate(),children:[e.jsx(te,{className:"w-4 h-4 mr-2"}),"Save"]})]})]})]})}),e.jsx(M,{children:t?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:"Subject"}),e.jsx(N,{value:c,onChange:s=>v(s.target.value),placeholder:"Email subject..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:"Delay (hours)"}),e.jsx(N,{type:"number",min:"0",value:r,onChange:s=>I(parseInt(s.target.value)||0)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"0 = send immediately, 24 = send after 1 day, etc."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{children:"Content (HTML)"}),e.jsx(k,{value:g,onChange:s=>b(s.target.value),rows:10,className:"font-mono text-sm"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Available variables: ","{{user_name}}, {{email}}, {{first_name}}"]})]})]}):e.jsx("div",{className:"prose prose-sm max-w-none",children:e.jsx("div",{className:"p-4 bg-muted rounded-lg",dangerouslySetInnerHTML:{__html:g}})})})]}),e.jsx(V,{open:n,onOpenChange:i,children:e.jsxs(Y,{children:[e.jsxs(W,{children:[e.jsx(G,{children:"Delete Email Template"}),e.jsx(J,{children:"This will permanently delete this email from the sequence. This action cannot be undone."})]}),e.jsxs(U,{children:[e.jsx(X,{children:"Cancel"}),e.jsx(Z,{onClick:()=>$.mutate(),children:"Delete"})]})]})}),e.jsx(ie,{open:l,onOpenChange:p,subject:c,content:g})]})}function ne({open:a,onOpenChange:d,sequenceId:j,nextOrderIndex:h}){const t=S(),[o,n]=m.useState(""),[i,l]=m.useState(`<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;"> 7 <h2>Hi {{first_name}},</h2> 8 9 <p>Your email content here...</p> 10 11 <p>Best regards,<br> 12 The SnapPilot Team</p> 13</div>`),[p,c]=m.useState(0),v=C({mutationFn:async()=>{const{error:r}=await y.from("email_templates").insert({sequence_id:j,order_index:h,subject:o,content:i,delay_hours:p});if(r)throw r},onSuccess:()=>{t.invalidateQueries({queryKey:["email-templates",j]}),x.success("Email template created"),d(!1),g()},onError:r=>{x.error("Failed to create template: "+r.message)}}),g=()=>{n(""),l(`<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;"> 14 <h2>Hi {{first_name}},</h2> 15 16 <p>Your email content here...</p> 17 18 <p>Best regards,<br> 19 The SnapPilot Team</p> 20</div>`),c(0)},b=r=>{if(r.preventDefault(),!o.trim()||!i.trim()){x.error("Please fill in all fields");return}v.mutate()};return e.jsx(q,{open:a,onOpenChange:d,children:e.jsxs(D,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(A,{children:[e.jsx(_,{children:"Add Email to Sequence"}),e.jsxs(F,{children:["This will be email #",h," in the sequence"]})]}),e.jsxs("form",{onSubmit:b,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"subject",children:"Email Subject"}),e.jsx(N,{id:"subject",placeholder:"e.g., Welcome to SnapPilot!",value:o,onChange:r=>n(r.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"delay",children:"Send After (hours)"}),e.jsx(N,{id:"delay",type:"number",min:"0",value:p,onChange:r=>c(parseInt(r.target.value)||0)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"0 = immediately, 24 = 1 day, 72 = 3 days, etc."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"content",children:"Email Content (HTML)"}),e.jsx(k,{id:"content",value:i,onChange:r=>l(r.target.value),rows:12,className:"font-mono text-sm",required:!0}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Available variables: ","{{user_name}}, {{email}}, {{first_name}}"]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(u,{type:"submit",disabled:v.isPending,children:v.isPending?"Creating...":"Add Email"})]})]})]})})}function ye(){const{id:a}=K(),d=O();S();const[j,h]=m.useState(!1),{data:t,isLoading:o}=w({queryKey:["email-sequence",a],queryFn:async()=>{const{data:i,error:l}=await y.from("email_sequences").select("*").eq("id",a).single();if(l)throw l;return i}}),{data:n}=w({queryKey:["email-templates",a],queryFn:async()=>{const{data:i,error:l}=await y.from("email_templates").select("*").eq("sequence_id",a).order("order_index",{ascending:!0});if(l)throw l;return i}});return o?e.jsx("div",{className:"p-8",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-8 bg-muted rounded w-1/4"}),e.jsx("div",{className:"h-32 bg-muted rounded"})]})}):e.jsxs("div",{className:"p-8 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(u,{variant:"ghost",size:"icon",onClick:()=>d("/dashboard/admin/email-sequences"),children:e.jsx(ae,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h1",{className:"text-3xl font-bold",children:t?.name}),e.jsx("p",{className:"text-muted-foreground mt-1",children:t?.description})]}),e.jsxs(u,{onClick:()=>h(!0),children:[e.jsx(T,{className:"w-4 h-4 mr-2"}),"Add Email"]})]}),(!n||n.length===0)&&e.jsx(H,{children:e.jsxs(M,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"No emails in this sequence yet"}),e.jsxs(u,{onClick:()=>h(!0),children:[e.jsx(T,{className:"w-4 h-4 mr-2"}),"Add First Email"]})]})}),e.jsx("div",{className:"space-y-4",children:n?.map((i,l)=>e.jsx(re,{template:i,sequenceId:a,orderIndex:l+1},i.id))}),e.jsx(ne,{open:j,onOpenChange:h,sequenceId:a,nextOrderIndex:(n?.length||0)+1})]})}export{ye 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.