1import{r,j as e}from"./react-vendor-BxUrAMDo.js";import{C as x,b as p,c as j,d as u,o as w,B as c,I as g}from"./index-CQAF4vvG.js";import{T as f}from"./textarea-DeKoTNkm.js";import{a7 as b,i as T,a8 as C,e as S,a9 as E}from"./icons-B2ApzMU8.js";import"./query-vendor-C8OxFoLA.js";import"./ui-vendor-BRGvjLlB.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};a.SENTRY_RELEASE={id:"76af7de9158b89afec09e7e9dfdae5ea3e5aff85"};var i=new a.Error().stack;i&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[i]="3d3e7ba1-da1a-4e65-b036-da6854057d21",a._sentryDebugIdIdentifier="sentry-dbid-3d3e7ba1-da1a-4e65-b036-da6854057d21")}catch{}})();function L(){const[a,i]=r.useState([]),[t,n]=r.useState(null),[d,h]=r.useState(!1),[m,v]=r.useState("html"),o=r.useCallback(async()=>{try{const l=await(await fetch("/api/email-templates")).json();i(l)}catch(s){console.error("Error fetching templates:",s)}},[]);r.useEffect(()=>{o()},[o]);const y=async s=>{try{(await fetch(`/api/email-templates/${s.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})).ok&&(o(),h(!1),alert("Template updated successfully"))}catch(l){console.error("Error updating template:",l)}},N=async s=>{try{(await fetch("/api/send-test-email",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({templateId:s.id})})).ok&&alert("Test email sent successfully")}catch(l){console.error("Error sending test email:",l)}};return e.jsx("div",{className:"min-h-screen bg-gray-50 p-6",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900 mb-2",children:"Email Templates"}),e.jsx("p",{className:"text-gray-600",children:"Manage your WhisperAI email templates"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsx("div",{className:"lg:col-span-1",children:e.jsxs(x,{children:[e.jsx(p,{children:e.jsxs(j,{className:"flex items-center gap-2",children:[e.jsx(b,{className:"w-5 h-5"}),"Templates (",a.length,")"]})}),e.jsx(u,{className:"space-y-3",children:a.map(s=>e.jsxs("button",{type:"button","aria-pressed":t?.id===s.id,className:`w-full text-left p-3 border rounded-lg cursor-pointer transition-all ${t?.id===s.id?"border-blue-500 bg-blue-50":"border-gray-200 hover:border-gray-300"}`,onClick:()=>n(s),children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:s.template_name}),e.jsx(w,{variant:s.is_active?"default":"secondary",children:s.is_active?"Active":"Inactive"})]}),e.jsx("p",{className:"text-xs text-gray-500 truncate",children:s.subject})]},s.id))})]})}),e.jsx("div",{className:"lg:col-span-2",children:t?e.jsxs(x,{className:"h-fit",children:[e.jsx(p,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(j,{children:t.template_name}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>v(m==="html"?"text":"html"),children:[e.jsx(T,{className:"w-4 h-4 mr-1"}),m==="html"?"Text":"HTML"]}),e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>h(!d),children:[e.jsx(C,{className:"w-4 h-4 mr-1"}),d?"Cancel":"Edit"]}),e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>N(t),children:[e.jsx(S,{className:"w-4 h-4 mr-1"}),"Test Send"]})]})]})}),e.jsx(u,{className:"space-y-4",children:d?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"template-name",className:"block text-sm font-medium mb-1",children:"Template Name"}),e.jsx(g,{id:"template-name",value:t.template_name,onChange:s=>n({...t,template_name:s.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"template-subject",className:"block text-sm font-medium mb-1",children:"Subject"}),e.jsx(g,{id:"template-subject",value:t.subject,onChange:s=>n({...t,subject:s.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"template-html",className:"block text-sm font-medium mb-1",children:"HTML Content"}),e.jsx(f,{id:"template-html",value:t.html_content,onChange:s=>n({...t,html_content:s.target.value}),rows:15,className:"font-mono text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"template-text",className:"block text-sm font-medium mb-1",children:"Text Content"}),e.jsx(f,{id:"template-text",value:t.text_content||"",onChange:s=>n({...t,text_content:s.target.value}),rows:8})]}),e.jsxs(c,{onClick:()=>y(t),children:[e.jsx(E,{className:"w-4 h-4 mr-1"}),"Save Changes"]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-gray-900 mb-2",children:"Subject"}),e.jsx("p",{className:"text-gray-600 bg-gray-50 p-3 rounded",children:t.subject})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-gray-900 mb-2",children:"Preview"}),m==="html"?e.jsx("div",{className:"border rounded-lg",children:e.jsx("iframe",{srcDoc:t.html_content,className:"w-full h-96 border-0",title:"Email Preview"})}):e.jsx("pre",{className:"bg-gray-50 p-4 rounded-lg text-sm whitespace-pre-wrap overflow-auto max-h-96",children:t.text_content})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm text-gray-500",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Created:"})," ",new Date(t.created_at).toLocaleDateString()]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Updated:"})," ",new Date(t.updated_at).toLocaleDateString()]})]})]})})]}):e.jsx(x,{className:"h-96 flex items-center justify-center",children:e.jsxs("div",{className:"text-center text-gray-500",children:[e.jsx(b,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Select a template to view and edit"})]})})})]})]})})}export{L 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.