1import{b as D,r as h,u as q,e as j,j as e}from"./query-vendor-Dp9tfhuh.js";import{x as S,s as l,h as p,i as f,k as y,m as g,l as E,D as F,N as M,B as c,p as B,q as H,r as Q,t as k,L as i}from"./index-CgOeqv80.js";import{T as K,a as L,b as T,c as t,d as A,e as r}from"./table-DCRDDm_8.js";import{I as m}from"./input-go5takyh.js";import{T as I}from"./textarea-BSB7eVDL.js";import{S as O}from"./skeleton-U7PtyM3w.js";import{B as b}from"./badge-CarGzGVG.js";import{M as P}from"./mail-CObWevXE.js";import{P as R}from"./plus-CYnN_kFu.js";import{T as U}from"./trash-2-DAqLpVlV.js";import"./react-vendor-DfslLuwi.js";import"./ui-vendor-DW4RoVmg.js";import"./chart-vendor-BoynbIzZ.js";function ie(){const{toast:d}=S(),o=D(),[w,u]=h.useState(!1),[z,V]=h.useState(null),{data:n,isLoading:N}=q({queryKey:["all-message-templates"],queryFn:async()=>{const{data:s,error:a}=await l.from("message_templates").select(` 2 *, 3 profile:profiles(full_name, email) 4 `).order("created_at",{ascending:!1});if(a)throw a;return s}}),C=j({mutationFn:async s=>{const{data:{user:a}}=await l.auth.getUser();if(!a)throw new Error("Not authenticated");const{error:x}=await l.from("message_templates").insert({...s,user_id:a.id});if(x)throw x},onSuccess:()=>{o.invalidateQueries({queryKey:["all-message-templates"]}),d({title:"Template created successfully"}),u(!1)}}),_=j({mutationFn:async s=>{const{error:a}=await l.from("message_templates").delete().eq("id",s);if(a)throw a},onSuccess:()=>{o.invalidateQueries({queryKey:["all-message-templates"]}),d({title:"Template deleted successfully"})}}),v=s=>{s.preventDefault();const a=new FormData(s.currentTarget);C.mutate({name:a.get("name"),subject:a.get("subject"),content:a.get("content"),template_type:a.get("template_type"),is_default:!1})};return N?e.jsxs(p,{children:[e.jsx(f,{children:e.jsx(y,{children:"Email Templates Management"})}),e.jsx(g,{children:e.jsx("div",{className:"space-y-2",children:[1,2,3].map(s=>e.jsx(O,{className:"h-12 w-full"},s))})})]}):e.jsxs(p,{children:[e.jsx(f,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx(y,{children:"Email Templates Management"}),e.jsx(E,{children:"Create and manage platform-wide email templates"})]})]}),e.jsxs(F,{open:w,onOpenChange:u,children:[e.jsx(M,{asChild:!0,children:e.jsxs(c,{children:[e.jsx(R,{className:"h-4 w-4 mr-2"}),"New Template"]})}
4),e.jsxs(B,{className:"max-w-2xl",children:[e.jsxs(H,{children:[e.jsx(Q,{children:"Create Email Template"}),e.jsx(k,{children:"Add a new email template for system notifications"})]}),e.jsxs("form",{onSubmit:v,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"name",children:"Template Name"}),e.jsx(m,{id:"name",name:"name",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"template_type",children:"Type"}),e.jsx(m,{id:"template_type",name:"template_type",defaultValue:"email",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"subject",children:"Subject"}),e.jsx(m,{id:"subject",name:"subject",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"content",children:"Content"}),e.jsx(I,{id:"content",name:"content",rows:10,placeholder:"Use {{variable_name}} for dynamic content",required:!0})]}),e.jsx(c,{type:"submit",className:"w-full",children:"Create Template"})]})]})]})]})}),e.jsx(g,{children:e.jsxs(K,{children:[e.jsx(L,{children:e.jsxs(T,{children:[e.jsx(t,{children:"Name"}),e.jsx(t,{children:"Type"}),e.jsx(t,{children:"Subject"}),e.jsx(t,{children:"Created By"}),e.jsx(t,{children:"Default"}),e.jsx(t,{children:"Actions"})]})}),e.jsx(A,{children:n==null?void 0:n.map(s=>{var a;return e.jsxs(T,{children:[e.jsx(r,{className:"font-medium",children:s.name}),e.jsx(r,{children:e.jsx(b,{variant:"outline",children:s.template_type})}),e.jsx(r,{className:"max-w-xs truncate",children:s.subject}),e.jsx(r,{children:((a=s.profile)==null?void 0:a.full_name)||"System"}),e.jsx(r,{children:s.is_default&&e.jsx(b,{children:"Default"})}),e.jsx(r,{children:e.jsx("div",{className:"flex gap-2",children:e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>_.mutate(s.id),children:e.jsx(U,{className:"h-4 w-4"})})})})]},s.id)})})]})})]})}export{ie as EmailTemplatesManagement};
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.