1import{r as d,j as e}from"./react-vendor-pCX_OoB9.js";import{c as j,a1 as v,a as y,b as N,a2 as u,s as x}from"./index-CvanvASE.js";import{M as w}from"./quote-D-Gc74zt.js";import{E as k}from"./eye-Dz3b37yF.js";import"./pdf-CWGzimER.js";import"./radix-DPgQtnKV.js";import"./charts-POWNPXyX.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 _=j("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 T(){const p=v(),[b,g]=d.useState(null),[t,o]=d.useState({}),[l,f]=d.useState(!1),{data:s,isLoading:h}=y({queryKey:["email_templates"],queryFn:async()=>{const{data:r,error:n}=await x.from("email_templates").select("*").order("name",{ascending:!0});if(n)throw n;return r||[]}}),a=(s==null?void 0:s.find(r=>r.id===b))||(s==null?void 0:s[0]);d.useEffect(()=>{a&&a.id!==t.id&&(o({...a}),g(a.id))},[a,t.id]);const c=N({mutationFn:async()=>{if(!t.id)return;const{error:r}=await x.from("email_templates").update({subject:t.subject||"",html_body:t.html_body||"",from_name:t.from_name||null,enabled:t.enabled??!0}).eq("id",t.id);if(r)throw r},onSuccess:()=>{u.success("Template saved"),p.invalidateQueries({queryKey:["email_templates"]})},onError:r=>u.error(r.message)});if(h)return e.jsx("div",{className:"text-xs uppercase tracking-widest text-muted-foreground",children:"Loadingâ¦"});if(!(s!=null&&s.length))return e.jsx("div",{className:"text-xs uppercase tracking-widest text-muted-foreground",children:"No templates yet."});const i=r=>{const n={project_title:"Sample Project",name_greeting:" Alex",name:"Alex",email:"[email protected]",company:"Acme Corp",download_url:"https://example.com/download/sample.pdf"};return r.replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g,(S,m)=>n[m]??`{{${m}}}`)};return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[260px_1fr] gap-6",children:[e.jsxs("aside",{className:"space-y-1",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.3em] text-muted-foreground mb-3",children:"Templates"}),s.map(r=>{const n=(t.id||(a==null?void 0:a.id))===r.id;return e.jsxs("button",{onClick:()=>o({...r}),className:`w-full text-left px-3 py-2 border-l-2 transition-colors ${n?"border-foreground bg-secondary/30":"border-transparent hover:bg-secondary/20"}`,children:[e.jsxs("p",{className:"text-xs flex items-center gap-2",children:[e.jsx(w,{className:"w-3 h-3"}),r.name]}),e.jsx("p",{className:"text-[10px] uppercase tracking-[0.2em] text-muted-foreground mt-1 truncate",children:r.key})]},r.id)})]}),e.jsx("div",{className:"space-y-5 min-w-0",children:t.id&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-heading",children:t.name}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.description})]}),t.variables&&t.variables.length>0&&e.jsxs("div",{className:"border border-border bg-secondary/10 p-3",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.3em] text-muted-foreground mb-2",children:"Available placeholders"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.variables.map(r=>e.jsx("code",{className:"text-[11px] font-mono bg-background border border-border px-2 py-0.5",children:`{{${r}}}`},r))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-[0.2em] text-muted-foreground mb-1",children:"From Name"}),e.jsx("input",{type:"text",value:t.from_name||"",onChange:r=>o({...t,from_name:r.target.value}),className:"w-full bg-background border border-border px-3 py-2 text-sm focus:outline-none focus:border-foreground",placeholder:"BSDXR"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-[0.2em] text-muted-foreground mb-1",children:"Subject Line"}),e.jsx("input",{type:"text",value:t.subject||"",onChange:r=>o({...t,subject:r.target.value}),className:"w-full bg-background border border-border px-3 py-2 text-sm focus:outline-none focus:border-foreground"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"block text-[10px] uppercase tracking-[0.2em] text-muted-foreground",children:"HTML Body"}),e.jsxs("button",{type:"button",onClick:()=>f(r=>!r),className:"inline-flex items-center gap-1 text-[10px] uppercase tracking-[0.2em] text-muted-foreground hover:text-foreground",children:[e.jsx(k,{className:"w-3 h-3"}),l?"Hide preview":"Show preview"]})]}),e.jsx("textarea",{value:t.html_body||"",onChange:r=>o({...t,html_body:r.target.value}),rows:14,className:"w-full bg-background border border-border px-3 py-2 text-xs font-mono focus:outline-none focus:border-foreground resize-y"})]}),l&&e.jsxs("div",{className:"border border-border",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-border bg-secondary/20",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.2em] text-muted-foreground",children:"Preview"}),e.jsxs("p",{className:"text-xs mt-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"Subject:"})," ",i(t.subject||"")]})]}),e.jsx("iframe",{title:"Email preview",srcDoc:i(t.html_body||""),className:"w-full h-96 bg-white"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-border",children:[e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:t.enabled??!0,onChange:r=>o({...t,enabled:r.target.checked})}),"Enabled"]}),e.jsxs("button",{onClick:()=>c.mutate(),disabled:c.isPending,className:"inline-flex items-center gap-2 text-[10px] uppercase tracking-[0.2em] border border-foreground px-4 py-2 hover:bg-foreground hover:text-background disabled:opacity-50",children:[e.jsx(_,{className:"w-3 h-3"}),c.isPending?"Savingâ¦":"Save Template"]})]})]})})]})}export{T 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.