1import{r as t,j as e,J as B,g as H,C as j,a as w,b as f,a3 as v,d as b,L as y,I as N,B as C,m as k,_ as $,i as D,s as S,u as i}from"./index-DaxYHL_c.js";import{E as M}from"./eye-BjgtwxLJ.js";import{C as E}from"./circle-alert-BSao5Pkh.js";function _(){const[n,T]=t.useState("[email protected]"),[l,L]=t.useState("Test Couple"),[o,c]=t.useState(null),[m,d]=t.useState([]),[h,x]=t.useState(!1),[u,p]=t.useState(!1),[a,g]=t.useState(null),P=async()=>{x(!0),c(null),d([]);try{const{data:s,error:r}=await S.functions.invoke("send-bundle-preview",{body:{mode:"html",name:l||"Test Couple"}});if(r)throw r;if(!(s!=null&&s.ok))throw new Error((s==null?void 0:s.error)||"Preview failed");c(s.html),d(s.missing||[])}catch(s){i.error(s instanceof Error?s.message:"Could not load preview")}finally{x(!1)}},R=async()=>{if(!n.trim()){i.error("Please enter a recipient email");return}p(!0);try{const{data:s,error:r}=await S.functions.invoke("send-bundle-preview",{body:{mode:"send",to:n.trim(),name:l||"Test Couple"}});if(r)throw r;if(!(s!=null&&s.ok))throw new Error((s==null?void 0:s.error)||"Send failed");g({ok:!0,to:s.sent_to,at:new Date}),d(s.missing||[]),i.success(`Test email sent to ${s.sent_to}`)}catch(s){i.error(s instanceof Error?s.message:"Could not send test email"),g({ok:!1,at:new Date})}finally{p(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(B,{children:e.jsx("title",{children:"Bundle Email Preview â Admin"})}),e.jsxs("div",{className:"space-y-6 p-4 md:p-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"font-display text-3xl text-foreground flex items-center gap-2",children:[e.jsx(H,{className:"h-7 w-7 text-primary"}),"Bundle Email Test Send"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Validate wording, pricing and download links for the App + Bundle (£15) delivery email before going live. This is the exact email a paying customer receives, with a PREVIEW banner added."})]}),e.jsxs(j,{children:[e.jsxs(w,{children:[e.jsx(f,{children:"Test Recipient"}),e.jsx(v,{children:"Send the live email to yourself (or any inbox) without making a purchase."})]}),e.jsxs(b,{className:"space-y-4",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{htmlFor:"to",children:"Send test to"}),e.jsx(N,{id:"to",type:"email",value:n,onChange:s=>T(s.target.value),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(y,{htmlFor:"name",children:"Recipient name (used in greeting)"}),e.jsx(N,{id:"name",value:l,onChange:s=>L(s.target.value),placeholder:"Test Couple"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(C,{onClick:P,disabled:h,variant:"outline",className:"gap-2",children:[h?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx(M,{className:"h-4 w-4"}),"Preview in browser"]}),e.jsxs(C,{onClick:R,disabled:u,className:"gap-2",children:[u?e.jsx(k,{className:"h-4 w-4 animate-spin"}):e.jsx($,{className:"h-4 w-4"}),"Send test email"]})]}),a&&e.jsxs("div",{className:`flex items-center gap-2 text-sm rounded-md p-3 ${a.ok?"bg-primary/10 text-primary":"bg-destructive/10 text-destructive"}`,children:[a.ok?e.jsx(D,{className:"h-4 w-4"}):e.jsx(E,{className:"h-4 w-4"}),a.ok?`Sent to ${a.to} at ${a.at.toLocaleTimeString()} â check inbox (and spam).`:`Send failed at ${a.at.toLocaleTimeString()}.`]}),m.length>0&&e.jsxs("div",{className:"flex items-start gap-2 text-sm rounded-md p-3 bg-amber-100 text-amber-900 dark:bg-amber-950/40 dark:text-amber-200",children:[e.jsx(E,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:"Missing files in storage â links will not appear in the email:"}),e.jsx("ul",{className:"list-disc ml-5 mt-1",children:m.map(s=>e.jsx("li",{children:e.jsx("code",{children:s})},s))})]})]})]})]}),e.jsxs(j,{children:[e.jsxs(w,{children:[e.jsx(f,{children:"Live preview"}),e.jsx(v,{children:"Renders the same HTML as the email. Links are real signed download URLs."})]}),e.jsx(b,{children:o?e.jsx("iframe",{title:"Bundle email preview",srcDoc:o,className:"w-full rounded-md border border-border bg-white",style:{height:"1200px"}}):e.jsxs("div",{className:"border border-dashed border-border rounded-md py-16 text-center text-muted-foreground",children:["Click ",e.jsx("strong",{children:"Preview in browser"})," to render the email here."]})})]})]})]})}export{_ 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.