import{r,q as y,aV as T,eb as n,ec as o,ed as v}from"./index-Ef5HIHwv.js";function w(){const[c,m]=r.useState([]),[p,i]=r.useState(!0),{toast:a}=y(),l=r.useCallback(async()=>{try{i(!0);const e=await T({active_only:!0});m(e||[])}catch(e){console.error("Error fetching email templates:",e),a({title:"Error fetching email templates",description:e==null?void 0:e.message,variant:"destructive"})}finally{i(!1)}},[a]),d=async e=>{try{await n(e),a({title:"Email template created successfully"}),l()}catch(t){console.error("Error creating template:",t),a({title:"Error creating template",description:t==null?void 0:t.message,variant:"destructive"})}},u=async(e,t)=>{try{await v(e,t),a({title:"Email template updated successfully"}),l()}catch(s){console.error("Error updating template:",s),a({title:"Error updating template",description:s==null?void 0:s.message,variant:"destructive"})}},E=async e=>{try{await o(e),a({title:"Email template deleted successfully"}),l()}catch(t){console.error("Error deleting template:",t),a({title:"Error deleting template",description:t==null?void 0:t.message,variant:"destructive"})}},g=async()=>{try{for(const e of c)await o(e.id);a({title:"All email templates deleted successfully"}),l()}catch(e){console.error("Error deleting all templates:",e),a({title:"Error deleting all templates",description:e==null?void 0:e.message,variant:"destructive"})}},f=async e=>{try{for(const t of e)await n(t);a({title:`${e.length} email templates created successfully`}),l()}catch(t){console.error("Error creating bulk templates:",t),a({title:"Error creating bulk templates",description:t==null?void 0:t.message,variant:"destructive"})}};return r.useEffect(()=>{l()},[l]),{templates:c,loading:p,fetchTemplates:l,createTemplate:d,updateTemplate:u,deleteTemplate:E,deleteAllTemplates:g,createBulkTemplates:f}}export{w as u};
