1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9607],{31010:(e,t,a)=>{"use strict";a.d(t,{A:()=>r});var s=a(14232);let r=s.forwardRef(function(e,t){let{title:a,titleId:r,...l}=e;return s.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:t,"aria-labelledby":r},l),a?s.createElement("title",{id:r},a):null,s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v3.75m0-10.036A11.959 11.959 0 0 1 3.598 6 11.99 11.99 0 0 0 3 9.75c0 5.592 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.57-.598-3.75h-.152c-3.196 0-6.1-1.25-8.25-3.286Zm0 13.036h.008v.008H12v-.008Z"}))})},31452:(e,t,a)=>{"use strict";a.d(t,{A:()=>c});var s=a(37876);a(14232);var r=a(89099),l=a(62125),i=a(28567),n=a(31010);let c=e=>{let{title:t="Access Denied",message:a="You don't have permission to access this section.",description:c,requiredRoles:m,redirectPath:o="/dashboard",redirectText:d="Back to Dashboard",icon:x,variant:h="danger"}=e,p=(0,r.useRouter)(),{iconColor:u,icon:g}=(()=>{switch(h){case"warning":return{iconColor:"text-yellow-500",icon:x||n.A};case"info":return{iconColor:"text-blue-500",icon:x||n.A};default:return{iconColor:"text-red-500",icon:x||n.A}}})();return(0,s.jsx)(i.Zp,{children:(0,s.jsxs)(i.Wu,{className:"p-8 text-center",children:[(0,s.jsx)(g,{className:"h-16 w-16 ".concat(u," mx-auto mb-4")}),(0,s.jsx)("h3",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:t}),(0,s.jsx)("p",{className:"text-gray-600 dark:text-gray-400 mb-4",children:a}),c&&(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-500 mb-4",children:c}),m&&(0,s.jsxs)("p",{className:"text-sm text-gray-500 dark:text-gray-500 mb-6",children:["Required role: ",m]}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 justify-center",children:[(0,s.jsx)(l.$,{variant:"outline",onClick:()=>p.push(o),className:"w-full sm:w-auto",children:d}),(0,s.jsx)(l.$,{variant:"ghost",onClick:()=>p.back(),className:"w-full sm:w-auto",children:"Go Back"})]})]})})}},35917:(e,t,a)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/dashboard/email-templates",function(){return a(81384)}])},81384:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>P});var s=a(37876),r=a(14232),l=a(89099),i=a(94246),n=a(41762),c=a(62125),m=a(28567),o=a(32764),d=a(78769),x=a(31452),h=a(34572),p=a(21379),u=a(11659),g=a(7021),b=a(11629),y=a(63393),f=a(94471),j=a(35765),w=a(68974),v=a(96668);let N=e=>{let{isOpen:t,onClose:a,onGenerate:l,category:n="marketing",businessName:o="",existingHtml:x=null,templateName:h=""}=e,{business:p}=(0,i.A)();o||null==p||p.businessName;let u=!!x,[N,k]=(0,r.useState)("input"),[C,A]=(0,r.useState)(""),[T,S]=(0,r.useState)(""),[E,D]=(0,r.useState)(""),[z,$]=(0,r.useState)(!1),[P,_]=(0,r.useState)(!1),[M,R]=(0,r.useState)(null),[q,H]=(0,r.useState)(!0),[O,F]=(0,r.useState)(""),L=e=>{F(e.replace(/\{\{content\}\}/g,'\n <p style="margin: 0 0 16px 0; padding: 0; line-height: 1.6; color: #333333; font-family: Arial, Helvetica, sans-serif;">\n This is a sample preview of your email template. The content you write in the email composer will replace this text.\n </p>\n <p style="margin: 0 0 16px 0; padding: 0; line-height: 1.6; color: #333333; font-family: Arial, Helvetica, sans-serif;">\n You can customize this template further or use it as-is for your email campaigns.\n </p>'))},I=()=>{u?(k("preview"),D(x||""),x&&L(x),A(""),S("")):(k("input"),A(""),S(""),D(""),F("")),R(null),H(!0),a()};(0,r.useEffect)(()=>{t&&u&&x?(k("preview"),D(x),L(x),A("Refine this ".concat(h||"email template"))):t&&!u&&(k("input"),D(""),A(""))},[t,u,x,h]);let B=async()=>{if(!C.trim())return void R("Please describe what kind of email template you want to create.");$(!0),R(null),k("generating");try{var e;let t=localStorage.getItem("tkn")||(null==(e=document.cookie.split("; ").find(e=>e.startsWith("tkn=")))?void 0:e.split("=")[1]),a=await fetch("/api/email-templates/generate-html",{method:"POST",headers:{"Content-Type":"application/json",Authorization:t?"Bearer ".concat(t):""},body:JSON.stringify({userRequest:C.trim(),category:n,isRefinement:!1})}),s=await a.json();if(!a.ok)throw Error(s.error||s.message||"Failed to generate template");if(s.success&&s.htmlContent)D(s.htmlContent),L(s.htmlContent),k("preview");else throw Error("Invalid response from server")}catch(e){console.error("Error generating template:",e),R(e.message||"Failed to generate template. Please try again."),k("input")}finally{$(!1)}},U=async()=>
1{if(!T.trim())return void R("Please describe what you'd like to change.");_(!0),R(null),k("refining");try{var e;let t=localStorage.getItem("tkn")||(null==(e=document.cookie.split("; ").find(e=>e.startsWith("tkn=")))?void 0:e.split("=")[1]),a=await fetch("/api/email-templates/generate-html",{method:"POST",headers:{"Content-Type":"application/json",Authorization:t?"Bearer ".concat(t):""},body:JSON.stringify({userRequest:T.trim(),category:n,isRefinement:!0,currentHtml:E,originalRequest:C})}),s=await a.json();if(!a.ok)throw Error(s.error||s.message||"Failed to refine template");if(s.success&&s.htmlContent)D(s.htmlContent),L(s.htmlContent),S(""),k("preview");else throw Error("Invalid response from server")}catch(e){console.error("Error refining template:",e),R(e.message||"Failed to refine template. Please try again."),k("preview")}finally{_(!1)}};return t?(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-0 sm:p-4",children:(0,s.jsxs)(m.Zp,{className:"w-full h-full sm:h-auto sm:max-w-5xl sm:max-h-[90vh] overflow-hidden flex flex-col m-0 sm:m-4 rounded-none sm:rounded-xl",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-3 sm:p-6 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"p-1.5 sm:p-2 bg-gradient-to-br from-yellow-400 via-orange-400 to-pink-400 rounded-lg flex-shrink-0",children:(0,s.jsx)(g.A,{className:"h-4 w-4 sm:h-6 sm:w-6 text-white"})}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("h2",{className:"text-base sm:text-xl font-semibold text-gray-900 dark:text-white truncate",children:u?"Refine Template":"AI Template Generator"}),(0,s.jsx)("p",{className:"text-xs sm:text-sm text-gray-600 dark:text-gray-400 hidden sm:block",children:u?"Describe what you'd like to change, and AI will refine your template":"Describe your ideal email template and let AI create it for you"})]})]}),(0,s.jsx)(c.$,{variant:"ghost",size:"sm",onClick:I,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex-shrink-0 ml-2",children:(0,s.jsx)(b.A,{className:"h-5 w-5"})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-3 sm:p-6",children:["input"===N&&!u&&(0,s.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-xs sm:text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Describe Your Email Template"}),(0,s.jsx)("textarea",{value:C,onChange:e=>A(e.target.value),placeholder:"Example: Create a professional welcome email template with a modern header, clean content area, and footer with social media links. Use a blue color scheme and include space for a logo.",rows:6,className:"w-full px-3 sm:px-4 py-2 sm:py-3 border border-gray-200 dark:border-gray-600 rounded-lg sm:rounded-xl bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm sm:text-base focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent resize-none"}),(0,s.jsx)("p",{className:"mt-2 text-xs text-gray-500 dark:text-gray-400",children:"Be as specific as possible. Mention colors, layout, sections, style, and any special features you want."})]}),M&&(0,s.jsxs)(d.F,{variant:"danger",children:[(0,s.jsx)(y.A,{className:"h-4 w-4 sm:h-5 sm:w-5 flex-shrink-0"}),(0,s.jsx)("div",{children:(0,s.jsx)("p",{className:"text-xs sm:text-sm",children:M})})]}),(0,s.jsxs)("div",{className:"bg-blue-50 dark:bg-blue-900/20 p-3 sm:p-4 rounded-lg sm:rounded-xl",children:[(0,s.jsx)("h4",{className:"text-xs sm:text-sm font-medium text-blue-900 dark:text-blue-100 mb-2",children:"\uD83D\uDCA1 Tips for Best Results"}),(0,s.jsxs)("ul",{className:"text-xs text-blue-700 dark:text-blue-300 space-y-1 list-disc list-inside",children:[(0,s.jsx)("li",{children:"Specify the template purpose (welcome, newsletter, follow-up, etc.)"}),(0,s.jsx)("li",{children:"Describe the color scheme or branding preferences"}),(0,s.jsx)("li",{children:"Mention layout preferences (header, content sections, footer)"}),(0,s.jsx)("li",{children:"Include any special features (buttons, images, social links)"}),(0,s.jsx)("li",{children:"Describe the tone (professional, friendly, modern, etc.)"})]})]})]}),("generating"===N||"refining"===N)&&(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 sm:py-12",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 sm:h-16 sm:w-16 border-4 border-blue-200 border-t-blue-600"}),(0,s.jsx)(g.A,{className:"h-6 w-6 sm:h-8 sm:w-8 text-blue-600 absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 animate-pulse"})]}),(0,s.jsx)("h3",{className:"mt-4 sm:mt-6 text-base sm:text-lg font-semibold text-gray-900 dark:text-white text-center px-4",children:"generating"===N?"Generating Your Template":"Refining Your Template"}),(0,s.jsx)("p",{className:"mt-2 text-xs sm:text-sm text-gray-600 dark:text-gray-400 text-center max-w-md px-4",children:"generating"===N?"Our AI is creating a professional email template based on your description. This may take a few moments...":"Applying your refinements to make the template perfect. Please wait..."})]}),"preview"===N&&E&&(0,s.jsxs)("div",{className:"space-y-4 sm:sp
1ace-y-6",children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("h3",{className:"text-base sm:text-lg font-semibold text-gray-900 dark:text-white",children:u?"Template Preview":"Generated Template Preview"}),(0,s.jsx)("p",{className:"text-xs sm:text-sm text-gray-600 dark:text-gray-400 mt-1",children:u?"Review your template below. Describe what you'd like to change in the refine section.":"Review your template below. If you'd like changes, use the refine option."})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 flex-shrink-0",children:(0,s.jsx)(c.$,{type:"button",onClick:()=>H(!q),variant:"outline",size:"sm",className:"text-xs sm:text-sm",children:q?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(f.A,{className:"h-3 w-3 sm:h-4 sm:w-4 sm:mr-2"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"View Code"}),(0,s.jsx)("span",{className:"sm:hidden",children:"Code"})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(j.A,{className:"h-3 w-3 sm:h-4 sm:w-4 sm:mr-2"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:"View Preview"}),(0,s.jsx)("span",{className:"sm:hidden",children:"Preview"})]})})})]}),M&&(0,s.jsxs)(d.F,{variant:"danger",children:[(0,s.jsx)(y.A,{className:"h-4 w-4 sm:h-5 sm:w-5 flex-shrink-0"}),(0,s.jsx)("div",{children:(0,s.jsx)("p",{className:"text-xs sm:text-sm",children:M})})]}),q?(0,s.jsx)("div",{className:"border border-gray-200 dark:border-gray-600 rounded-lg sm:rounded-xl p-3 sm:p-4 bg-white dark:bg-gray-800 min-h-[300px] sm:min-h-[400px] max-h-[400px] sm:max-h-[500px] overflow-y-auto",children:(0,s.jsx)("div",{className:"prose dark:prose-invert max-w-none prose-sm sm:prose-base",dangerouslySetInnerHTML:{__html:O}})}):(0,s.jsx)("textarea",{value:E,readOnly:!0,rows:15,className:"w-full px-3 sm:px-4 py-2 sm:py-3 border border-gray-200 dark:border-gray-600 rounded-lg sm:rounded-xl bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-white font-mono text-xs overflow-auto"}),(0,s.jsxs)("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-4 sm:pt-6",children:[(0,s.jsx)("h4",{className:"text-sm sm:text-base font-medium text-gray-900 dark:text-white mb-2 sm:mb-3",children:u?"What Would You Like to Change?":"Want to Make Changes?"}),(0,s.jsxs)("div",{className:"space-y-2 sm:space-y-3",children:[(0,s.jsx)("textarea",{value:T,onChange:e=>S(e.target.value),placeholder:u?"Example: Change the header color to green, make the footer more compact, increase padding in the content area, or adjust the font size. Be specific about what to change.":"Example: Make the header smaller, change the color to green, add more padding to the content area, or make the footer more compact...",rows:4,className:"w-full px-3 sm:px-4 py-2 sm:py-3 border border-gray-200 dark:border-gray-600 rounded-lg sm:rounded-xl bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm sm:text-base focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent resize-none"}),(0,s.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:u?"Be specific about what you want to change. The AI will only modify what you mention, keeping everything else exactly as it is.":"Describe what you'd like to change, and we'll refine the template for you."}),u&&(0,s.jsx)("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 p-2 sm:p-3 rounded-lg border border-yellow-200 dark:border-yellow-800",children:(0,s.jsxs)("p",{className:"text-xs text-yellow-800 dark:text-yellow-200",children:[(0,s.jsx)("strong",{children:"Note:"})," Only the changes you specify will be made. Everything else will remain unchanged."]})})]})]})]})]}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3 p-3 sm:p-6 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800 flex-shrink-0",children:[(0,s.jsx)(c.$,{variant:"outline",onClick:I,className:"w-full sm:w-auto order-2 sm:order-1",children:"Cancel"}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2 sm:gap-3 w-full sm:w-auto order-1
1sm:order-2",children:["preview"===N&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(c.$,{variant:"secondary",onClick:U,disabled:P||!T.trim(),className:"flex items-center justify-center gap-2 text-xs sm:text-sm w-full sm:w-auto",children:[(0,s.jsx)(w.A,{className:"h-3 w-3 sm:h-4 sm:w-4"}),P?"Refining...":u?"Apply Changes":"Refine"]}),(0,s.jsxs)(c.$,{variant:"primary",onClick:()=>{E&&(l(E),I())},className:"flex items-center justify-center gap-2 text-xs sm:text-sm w-full sm:w-auto",children:[(0,s.jsx)(v.A,{className:"h-3 w-3 sm:h-4 sm:w-4"}),(0,s.jsx)("span",{className:"hidden sm:inline",children:u?"Save Changes":"Use This Template"}),(0,s.jsx)("span",{className:"sm:hidden",children:u?"Save":"Use"})]})]}),"input"===N&&(0,s.jsxs)(c.$,{variant:"primary",onClick:B,disabled:!C.trim()||z,className:"flex items-center justify-center gap-2 text-xs sm:text-sm w-full sm:w-auto",children:[(0,s.jsx)(g.A,{className:"h-3 w-3 sm:h-4 sm:w-4"}),"Generate Template"]})]})]})]})}):null},k=r.forwardRef(function(e,t){let{title:a,titleId:s,...l}=e;return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:t,"aria-labelledby":s},l),a?r.createElement("title",{id:s},a):null,r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4.745 3A23.933 23.933 0 0 0 3 12c0 3.183.62 6.22 1.745 9M19.5 3c.967 2.78 1.5 5.817 1.5 9s-.533 6.22-1.5 9M8.25 8.885l1.444-.89a.75.75 0 0 1 1.105.402l2.402 7.206a.75.75 0 0 0 1.104.401l1.445-.889m-8.25.75.213.09a1.687 1.687 0 0 0 2.062-.617l4.45-6.676a1.688 1.688 0 0 1 2.062-.618l.213.09"}))});var C=a(96816),A=a(67346),T=a(74550);let S=e=>{let{template:t=null,onSubmit:a,onCancel:l,isSubmitting:i=!1,error:n=null,canCreate:m=!1,canDelete:x=!1,onDelete:h=()=>{}}=e,{theme:g}=(0,p.D)(),[v,S]=(0,r.useState)({name:"",description:"",subject:"",htmlContent:"",category:"marketing",isDefault:!1,isPublic:!1,variables:[],tags:[]}),[E,D]=(0,r.useState)({}),[z,$]=(0,r.useState)("content"),[P,_]=(0,r.useState)(""),[M,R]=(0,r.useState)(!0),[q,H]=(0,r.useState)(""),[O,F]=(0,r.useState)(!1),[L,I]=(0,r.useState)(""),[B,U]=(0,r.useState)(!1),[V,G]=(0,r.useState)(null),[W,Y]=(0,r.useState)(!1),[Z,J]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e={name:"content",description:"Dynamic email content that will be inserted into the template",defaultValue:"",required:!0};if(t){let a=t.htmlContent||"";if(S({name:t.name||"",description:t.description||"",subject:t.subject||"",htmlContent:a,category:t.category||"marketing",isDefault:t.isDefault||!1,isPublic:t.isPublic||!1,variables:[e,{name:"name",description:"Recipient name",defaultValue:"",required:!1}],tags:t.tags||[]}),a&&M){let e=a;H(e=(e=e.replace(/\{\{content\}\}/g,'\n <p style="margin: 0 0 16px 0; padding: 0; line-height: 1.6; color: #333333; font-family: Arial, Helvetica, sans-serif;">This is a sample preview of your email template. The content you write in the email composer will replace this text.</p>')).replace(/\{\{name\}\}/g,"[Name]"))}}else{let t={name:"name",description:"Recipient name",defaultValue:"",required:!1};S(a=>({...a,variables:[e,t]}))}},[t]),(0,r.useEffect)(()=>{if(M&&v.htmlContent){let e=v.htmlContent;H(e=(e=e.replace(/\{\{content\}\}/g,'\n <p style="margin: 0 0 16px 0; padding: 0; line-height: 1.6; color: #333333; font-family: Arial, Helvetica, sans-serif;">This is a sample preview of your email template. The content you write in the email composer will replace this text.</p>')).replace(/\{\{name\}\}/g,"[Name]"))}},[v.htmlContent,M]);let K=e=>{let{name:t,value:a,type:s,checked:r}=e.target;if(t.startsWith("variables.")){let e=t.split("."),l=parseInt(e[1]),i=e[2];S(e=>({...e,variables:e.variables.map((e,t)=>t===l?{...e,[i]:"checkbox"===s?r:a}:e)}))}else S(e=>({...e,[t]:"checkbox"===s?r:a}));E[t]&&D(e=>({...e,[t]:null}))},X=()=>{P.trim()&&!v.tags.includes(P.trim())&&(S(e=>({...e,tags:[...e.tags,P.trim()]})),_(""))},Q=()=>{F(!1),I("")},ee=async e=>{e.preventDefault();let t={};if(v.name.trim()||(t.name="Template name is required"),v.subject.trim()||(t.subject="Subject is required"),v.htmlContent.trim()||(t.htmlContent="HTML content is required"),v.htmlContent.includes("{{content}}")||(t.htmlContent="HTML content must contain {{content}} placeholder"),Object.keys(t).length>0)return void D(t);let s={...v,variables:[{name:"content",description:"Dynamic email content that will be inserted into the template",defaultValue:"",required:!0},{name:"name",description:"Recipient name",defaultValue:"",required:!1}]};await a(s)},et=[{id:"content",label:"Content",icon:f.A},{id:"variables",label:"Variables",icon:k},{id:"settings",label:"Settings",icon:C.A}];return(0,s.jsxs)("form",{onSubmit:ee,className:"",children:[n&&(0,s.jsxs)(d.F,{variant:"danger",children:[(0,s.jsx)(y.A,{className:"h-5 w-5"}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"font-medium",children:"Error"}),(0,s.jsx)("p",{className:"text-sm",children:n})]})]}),(0,s.jsx)("div",{className:"border-b border-gray-200 dark:border-gray-700",children:(0,s.jsx)("nav",{className:"-mb-px flex space-x-4 sm:sp
1ace-x-8 overflow-x-auto",children:et.map(e=>(0,s.jsxs)("button",{type:"button",onClick:()=>$(e.id),className:"flex items-center gap-1 sm:gap-2 py-2 px-1 border-b-2 font-medium text-xs sm:text-sm whitespace-nowrap ".concat(z===e.id?"border-blue-500 text-blue-600 dark:text-blue-400":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300 dark:text-gray-400 dark:hover:text-gray-300"),children:[(0,s.jsx)(e.icon,{className:"h-3 w-3 sm:h-4 sm:w-4"}),e.label]},e.id))})}),"content"===z&&(0,s.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,s.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4",children:[(0,s.jsx)(u.p,{label:"Template Name",name:"name",value:v.name,onChange:K,error:E.name,placeholder:"Enter template name",required:!0,className:"text-sm sm:text-base"}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1 sm:mb-2",children:"Category"}),(0,s.jsx)("select",{name:"category",value:v.category,onChange:K,className:"w-full px-3 sm:px-4 py-2 sm:py-3 border border-gray-200 dark:border-gray-600 rounded-xl bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:border-transparent text-sm sm:text-base",children:[{value:"marketing",label:"Marketing"},{value:"follow_up",label:"Follow Up"},{value:"notification",label:"Notification"},{value:"transactional",label:"Transactional"},{value:"newsletter",label:"Newsletter"},{value:"welcome",label:"Welcome"},{value:"other",label:"Other"}].map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))})]})]}),(0,s.jsx)(u.p,{label:"Description",name:"description",value:v.description,onChange:K,placeholder:"Brief description of this template",className:"text-sm sm:text-base"}),(0,s.jsx)(u.p,{label:"Email Subject",name:"subject",value:v.subject,onChange:K,error:E.subject,placeholder:"Enter email subject (use {{variable}} for dynamic content)",required:!0,className:"text-sm sm:text-base"}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between mb-2",children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"HTML Content *"}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-2 sm:mt-0",children:[(0,s.jsxs)(c.$,{type:"button",onClick:()=>{I(v.htmlContent),F(!0)},variant:"secondary",size:"sm",className:"flex items-center gap-2 text-xs sm:text-sm",children:[(0,s.jsx)(f.A,{className:"h-3 w-3 sm:h-4 sm:w-4"}),"Open in Editor"]}),t&&v.htmlContent&&(0,s.jsxs)(c.$,{type:"button",onClick:()=>{J(!0),Y(!0)},variant:"secondary",size:"sm",className:"flex items-center gap-2 text-xs sm:text-sm bg-gradient-to-br from-purple-400 via-pink-400 to-red-400 hover:from-purple-500 hover:via-pink-500 hover:to-red-500 text-white border-0 shadow-lg hover:shadow-xl transition-all",title:"Refine this template with AI",children:[(0,s.jsx)(w.A,{className:"h-3 w-3 sm:h-4 sm:w-4"}),"Refine Template"]}),(0,s.jsxs)(c.$,{type:"button",onClick:()=>{J(!1),Y(!0)},variant:"secondary",size:"sm",className:"flex items-center gap-2 text-xs sm:text-sm bg-gradient-to-br from-yellow-400 via-orange-400 to-pink-400 hover:from-yellow-500 hover:via-orange-500 hover:to-pink-500 text-white border-0 shadow-lg hover:shadow-xl transition-all",title:"Generate HTML with AI",children:[(0,s.jsx)(A.A,{className:"h-3 w-3 sm:h-4 sm:w-4"}),"Generate with AI"]}),(0,s.jsxs)(c.$,{type:"button",onClick:()=>{if(M)R(!1);else{let e=v.htmlContent;H(e=(e=e.replace(/\{\{content\}\}/g,'\n <p style="margin: 0 0 16px 0; padding: 0; line-height: 1.6; color: #333333; font-family: Arial, Helvetica, sans-serif;">This is a sample preview of your email template. The content you write in the email composer will replace this text.</p>')).replace(/\{\{name\}\}/g,"[Name]")),R(!0)}},variant:"outline",size:"sm",className:"flex items-center gap-2 text-xs sm:text-sm",children:[(0,s.jsx)(j.A,{className:"h-3 w-3 sm:h-4 sm:w-4"}),M?"Edit":"Preview"]})]})]}),M?(0,s.jsx)("div",{className:"border border-gray-200 dark:border-gray-600 rounded-xl p-3 sm:p-4 bg-white dark:bg-gray-800 min-h-[300px] sm:min-h-[400px]",children:(0,s.jsx)("div",{className:"prose dark:prose-invert max-w-none text-sm sm:text-base",dangerouslySetInnerHTML:{__html:q}})}):(0,s.jsx)("textarea",{name:"htmlContent",value:v.htmlContent,onChange:K,rows:15,className:"w-full px-3 sm:px-4 py-2 sm:py-3 border border-gray-200 dark:border-gray-600 rounded-xl bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:border-transparent font-mono text-xs sm:text-sm",placeholder:"Enter your HTML content here. Make sure to include {{content}} placeholder where you want the dynamic content to appear.",required:!0}),E.htmlContent&&(0,s.jsx)("p",{className:"mt-1 text-xs sm:text-sm text-red-600",children:E.htmlContent}),(0,s.jsxs)("div",{className:"mt-2 sm:mt-3 p-3 sm:p-4 bg-blue-50 dark:bg-blue-900/20 rounded-xl",children:[(0,s.jsx)("h4",{className:"text-xs sm:text-sm font-medium text-blue-900 dark:text-blue-100 mb-2",children:"Template Guidelines"}),(0,s.jsxs)("ul",{className:"text-xs sm:text-sm text-blue-700 dark:text-blue-300 space-y-1",children:[(0,s.jsxs)("li",{children:["⢠Always include"," ",(0,s.jsx)("code",{className:"bg-blue-100 dar
1k:bg-blue-800 px-1 rounded text-xs",children:"{{content}}"})," ","placeholder for dynamic content"]}),(0,s.jsxs)("li",{children:["⢠Use"," ",(0,s.jsx)("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded text-xs",children:"{{variable}}"})," ","for custom variables"]}),(0,s.jsx)("li",{children:"⢠Keep HTML simple and email-client compatible"}),(0,s.jsx)("li",{children:"⢠Use inline CSS for styling"}),(0,s.jsx)("li",{children:"⢠Test your template before using"})]})]})]})]}),"variables"===z&&(0,s.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,s.jsxs)("div",{className:"bg-blue-50 dark:bg-blue-900/20 p-3 sm:p-4 rounded-xl",children:[(0,s.jsx)("h3",{className:"text-base sm:text-lg font-medium text-blue-900 dark:text-blue-100 mb-2",children:"Template Variables"}),(0,s.jsxs)("p",{className:"text-xs sm:text-sm text-blue-700 dark:text-blue-300 mb-3",children:["Use these variables in your email subject or HTML content. The ",(0,s.jsx)("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded text-xs",children:"{{content}}"})," variable is required, and ",(0,s.jsx)("code",{className:"bg-blue-100 dark:bg-blue-800 px-1 rounded text-xs",children:"{{name}}"})," is optional."]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{className:"text-sm sm:text-base font-medium text-gray-900 dark:text-white mb-3",children:"Available Variables"}),(0,s.jsx)("div",{className:"space-y-2 sm:space-y-3",children:v.variables.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-center justify-between p-3 sm:p-4 bg-gray-50 dark:bg-gray-800 rounded-xl border-2 ".concat(e.required?"border-blue-200 dark:border-blue-700":"border-green-200 dark:border-green-700"),children:[(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3 flex-1 min-w-0",children:[(0,s.jsx)(o.E,{variant:e.required?"primary":"secondary",className:"text-xs",children:"{{".concat(e.name,"}}")}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("p",{className:"font-medium text-gray-900 dark:text-white text-sm sm:text-base",children:e.name}),e.description&&(0,s.jsx)("p",{className:"text-xs sm:text-sm text-gray-600 dark:text-gray-400",children:e.description})]}),(0,s.jsx)(o.E,{variant:e.required?"warning":"success",className:"text-xs",children:e.required?"Required":"Optional"})]}),e.required&&(0,s.jsx)("div",{className:"text-xs sm:text-sm text-gray-500 dark:text-gray-400 italic",children:"Fixed"})]},t))})]})]}),"settings"===z&&(0,s.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,s.jsx)("div",{className:"space-y-3 sm:space-y-4",children:(0,s.jsxs)("div",{className:"flex items-center",children:[(0,s.jsx)("input",{type:"checkbox",name:"isDefault",checked:v.isDefault,onCh
1ange:K,className:"h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"}),(0,s.jsx)("label",{className:"ml-2 block text-sm text-gray-900 dark:text-gray-300",children:"Set as default template"})]})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1 sm:mb-2",children:"Tags"}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-2 mb-2",children:[(0,s.jsx)(u.p,{value:P,onChange:e=>_(e.target.value),placeholder:"Add a tag",onKeyPress:e=>"Enter"===e.key&&(e.preventDefault(),X()),className:"text-sm sm:text-base"}),(0,s.jsx)(c.$,{type:"button",onClick:X,variant:"outline",className:"text-sm sm:text-base",children:(0,s.jsx)(T.A,{className:"h-3 w-3 sm:h-4 sm:w-4"})})]}),(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:v.tags.map(e=>(0,s.jsxs)(o.E,{variant:"secondary",className:"flex items-center gap-1 text-xs",children:[e,(0,s.jsx)("button",{type:"button",onClick:()=>{S(t=>({...t,tags:t.tags.filter(t=>t!==e)}))},className:"ml-1 hover:text-red-600",children:(0,s.jsx)(b.A,{className:"h-3 w-3"})})]},e))})]})]}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row justify-end gap-3 pt-4 sm:pt-6 border-t border-gray-200 dark:border-gray-700",children:[(0,s.jsx)(c.$,{type:"button",variant:"outline",onClick:l,className:"w-full sm:w-auto text-sm sm:text-base",children:"Cancel"}),x&&t&&(0,s.jsx)(c.$,{type:"button",variant:"danger",onClick:h,loading:i,className:"w-full sm:w-auto text-sm sm:text-base",children:"Delete Template"}),m&&(0,s.jsx)(c.$,{type:"submit",variant:"primary",loading:i,className:"w-full sm:w-auto text-sm sm:text-base",children:t?"Update Template":"Create Template"})]}),O&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:Q,children:(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl shadow-2xl p-6 max-w-6xl w-full mx-4 border border-gray-200 dark:border-gray-700 max-h-[90vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-4 pb-4 border-b border-gray-200 dark:border-gray-700",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("h3",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Edit HTML Content"}),(0,s.jsxs)(c.$,{type:"button",onClick:()=>Y(!0),variant:"secondary",size:"sm",className:"flex items-center gap-2 bg-gradient-to-br from-yellow-400 via-orange-400 to-pink-400 hover:from-yellow-500 hover:via-orange-500 hover:to-pink-500 text-white border-0",title:"Generate HTML with AI",children:[(0,s.jsx)(A.A,{className:"h-4 w-4"}),"Generate with AI"]})]}),(0,s.jsx)("button",{type:"button",onClick:Q,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",children:(0,s.jsx)(b.A,{className:"w-6 h-6"})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,s.jsx)("textarea",{value:L,onChange:e=>I(e.target.value),placeholder:"Enter your HTML content here. Make sure to include {{content}} placeholder where you want the dynamic content to appear.",className:"flex-1 w-full px-4 py-3 border border-gray-200 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm sm:text-base focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent resize-none font-mono",style:{minHeight:"400px"}}),(0,s.jsxs)("div",{className:"mt-4 flex items-center justify-between",children:[(0,s.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Always include ",(0,s.jsx)("code",{className:"bg-gray-100 dark:bg-gray-700 px-1 rounded",children:"{{content}}"})," placeholder for dynamic content"]}),(0,s.jsxs)(c.$,{type:"button",onClick:()=>Y(!0),variant:"secondary",size:"sm",className:"flex items-center gap-2 bg-gradient-to-br from-yellow-400 via-orange-400 to-pink-400 hover:from-yellow-500 hover:via-orange-500 hover:to-pink-500 text-white border-0",children:[(0,s.jsx)(A.A,{className:"h-4 w-4"}),"Generate with AI"]})]})]}),(0,s.jsxs)("div",{className:"flex justify-end gap-3 mt-4 pt-4 border-t border-gray-200 dark:border-gray-700",children:[(0,s.jsx)(c.$,{type:"button",onClick:Q,variant:"secondary",size:"md",children:"Cancel"}),(0,s.jsx)(c.$,{type:"button",onClick:()=>{K({target:{name:"htmlContent",value:L}}),F(!1)},variant:"primary",size:"md",children:"Save HTML"})]})]})}),(0,s.jsx)(N,{isOpen:W,onClose:()=>{Y(!1),J(!1)},onGenerate:e=>{e&&(K({target:{name:"htmlContent",value:e}}),G(null),M&&H(e.replace(/\{\{content\}\}/g,'\n <p style="margin: 0 0 16px 0; padding: 0; line-height: 1.6; color: #333333; font-family: Arial, Helvetica, sans-serif;">This is a sample preview of your email template. The content you write in the email composer will replace this text.</p>')))},category:v.category,businessName:v.name||"Your Business",existingHtml:Z&&t?v.htmlContent:null,templateName:Z&&t?v.name:""})]})};var E=a(49539),D=a(14534),z=a(28022),$=a(29454);function P(){let e=(0,l.useRouter)(),{user:t,loading:a}
1=(0,i.A)(),p=null==t?void 0:t.role,u=(0,h.Vi)(p),g=(0,h.E4)(p),w=(0,h.xY)(p),[v,N]=(0,r.useState)([]),[k,C]=(0,r.useState)(!0),[P,_]=(0,r.useState)(null),[M,R]=(0,r.useState)(1),[q,H]=(0,r.useState)(1),[O,F]=(0,r.useState)(""),[L,I]=(0,r.useState)("all"),[B,U]=(0,r.useState)(!1),[V,G]=(0,r.useState)(null),[W,Y]=(0,r.useState)(!1),[Z,J]=(0,r.useState)(!1),[K,X]=(0,r.useState)(null),[Q,ee]=(0,r.useState)(!1),et=(0,r.useCallback)(async()=>{try{var e,t;C(!0),_(null);let a=new URLSearchParams({page:M.toString(),limit:"20"});O&&a.append("search",O),"all"!==L&&a.append("category",L);let s=$.A.get("tkn"),r=await fetch("/api/email-templates?".concat(a),{headers:{Authorization:"Bearer ".concat(s),"Content-Type":"application/json"}});if(!r.ok){let e=await r.json();throw Error(e.error||"Failed to fetch templates")}let l=await r.json();N(l.templates||[]),H((null==(e=l.pagination)?void 0:e.totalPages)||1),R((null==(t=l.pagination)?void 0:t.currentPage)||1)}catch(e){console.error("Error fetching templates:",e),_(e.message)}finally{C(!1)}},[M,O,L]);(0,r.useEffect)(()=>{!a&&t&&et()},[a,t,et]);let ea=async e=>{Y(!0),_(null);try{let t=$.A.get("tkn"),a=V?"/api/email-templates/".concat(V._id):"/api/email-templates",s=V?"PUT":"POST",r=await fetch(a,{method:s,headers:{Authorization:"Bearer ".concat(t),"Content-Type":"application/json"},body:JSON.stringify(e)}),l=await r.json();if(!r.ok)throw Error(l.error||"Failed to save template");await et(),U(!1),G(null)}catch(e){console.error("Error saving template:",e),_(e.message)}finally{Y(!1)}},es=async()=>{if(K)try{ee(!0);let e=$.A.get("tkn"),t=await fetch("/api/email-templates/".concat(K._id),{method:"DELETE",headers:{Authorization:"Bearer ".concat(e)}});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to delete template")}await et(),J(!1),X(null)}catch(e){console.error("Error deleting template:",e),_(e.message)}finally{ee(!1)}},er=async e=>{try{let t=$.A.get("tkn"),a=await fetch("/api/email-templates/".concat(e._id),{method:"POST",headers:{Authorization:"Bearer ".concat(t),"Content-Type":"application/json"},body:JSON.stringify({action:"duplicate",name:"".concat(e.name," (Copy)")})});if(!a.ok){let e=await a.json();throw Error(e.error||"Failed to duplicate template")}await et()}catch(e){console.error("Error duplicating template:",e),_(e.message)}},el=async()=>{try{let e=$.A.get("tkn"),t=await fetch("/api/email-templates/seed",{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}});if(!t.ok){let e=await t.json();throw Error(e.error||"Failed to create sample templates")}await et()}catch(e){console.error("Error seeding templates:",e),_(e.message)}},ei=e=>{switch(e){case"marketing":case"newsletter":return"primary";case"follow_up":case"welcome":return"success";case"notification":return"warning";default:return"secondary"}},en=e=>e?new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"Never";return a?(0,s.jsx)(n.A,{children:(0,s.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,s.jsx)("div",{className:"animate-spin rounded-full h-32 w-32 border-b-2 border-blue-600"})})}):t?u?(0,s.jsx)(n.A,{children:(0,s.jsxs)("div",{className:"py-6",children:[(0,s.jsxs)("div",{className:"mb-6 sm:mb-8",children:[(0,s.jsx)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3 sm:gap-4 mb-4",children:(0,s.jsxs)("div",{className:"flex items-center gap-3 sm:gap-4",children:[(0,s.jsx)("div",{className:"p-2 sm:p-3 bg-purple-100 dark:bg-purple-900 rounded-lg",children:(0,s.jsx)(f.A,{className:"h-6 w-6 sm:h-8 sm:w-8 text-purple-600 dark:text-purple-400"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{className:"text-2xl sm:text-3xl font-bold text-gray-900 dark:text-white",children:"Email Templates"}),(0,s.jsx)("p",{className:"mt-1 text-sm sm:text-base text-gray-600 dark:text-gray-400",children:"Create and manage professional email templates for your campaigns"})]})]})}),(0,s.jsx)("div",{className:"flex flex-col sm:flex-row sm:justify-between sm:items-center gap-3 sm:gap-4",children:(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-2 sm:gap-2",children:[(0,s.jsxs)(c.$,{onClick:()=>{G(null),U(!0)},className:"flex items-center gap-2 text-sm sm:text-base px-3 sm:px-4 py-2 sm:py-2.5",children:[(0,s.jsx)(T.A,{className:"h-4 w-4"}),"Create Template"]}),(0,s.jsxs)(c.$,{onClick:el,variant:"outline",className:"flex items-center gap-2 text-sm sm:text-base px-3 sm:px-4 py-2 sm:py-2.5",children:[(0,s.jsx)(f.A,{className:"h-4 w-4"}),"Add Sample Templates"]})]})})]}),P&&(0,s.jsx)(d.F,{variant:"danger",className:"mb-6",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"font-medium",children:"Error"}),(0,s.jsx)("p",{className:"text-sm",children:P})]})}),(0,s.jsx)(m.Zp,{className:"mb-4 sm:mb-6",children:(0,s.jsx)("div",{className:"p-3 sm:p-4",children:(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 sm:gap-4",children:[(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsx)("input",{type:"text",placeholder:"Search templates...",value:O,onChange:e=>F(e.target.value),className:"w-full px-3 sm:px-4 py-2 sm:py-3 border border-gray-200 dark:border-gray-600 rounded-xl bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:border-transparent text-sm sm:text-base"})}),(0,s.jsxs)("select",{value:L,onChange:e=>I(e.target.value),className:"px-3 sm:px-4 py-2 sm:py-3 border border-gray-200 dark:border-gray-600 rounded-xl bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-gray-900 dark:focus:ring-white focus:border-transparent min-w-[140px] text-sm sm:text-base",children:[(0,s.jsx)("option",{value:"all",children:"All Categories"}),(0,s.jsx)("option",{value:"marketing",children:"Marketing"}),(0,s.jsx)("option",{value:"follow_up",children:"Follow Up"}),(0,s.jsx)("option",{value:"notification",children:"Notification"}),(0,s.jsx)("option",{value:"transactional",children:"Transactional"}),(0,s.jsx)("option",{value:"newsletter",children:"Newsletter"}),(0,s.jsx)("option",{value:"welcome",children:"Welcome"}),(0,s.jsx)("option",{value:"other",children:"Other"})]})]})})}),k?(0,s.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,s.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})}):0===v.length?(0,s.jsx)(m.Zp,{children:(0,s.jsxs)("div",{className:"p-12 text-center",children:[(0,s.jsx)(f.A,{className:"h-12 w-12 mx-auto mb-4 text-gray-400"}),(0,s.jsx)("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-2",children:"No Templates Found"}),(0,s.jsx)("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:"Get started by creating your first email template."}),(0,s.jsxs)(c.$,{onClick:()=>{G(null),U(!0)},className:"flex items-center gap-2 mx-auto",children:[(0,s.jsx)(T.A,{className:"h-4 w-4"}),"Create Your First Template"]})]})}):(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("div",{className:"hidden md:block",children:(0,s.jsx)(m.Zp,{children:(0,s.jsx)("div",{className:"overflow-x-auto rounded-xl",children:(0,s.jsxs)("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[(0,s.jsx)("thead",{className:"bg-gray-50 dark:bg-gray-800",children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Template"}),(0,s.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Category"}),(0,s.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Variables"}),(0,s.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Usage"}),(0,s.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Created"}),g&&(0,s.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Actions"})]})}),(0,s.jsx)("tbody",{className:"bg-white dark:bg-gray-900 divide-y divide-gray-200 dark:divide-gray-700",children:v.map(e=>{var t;return(0,s.jsxs)("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-800",children:[(0,s.jsx)("td",{className:"px-6 py-4",children:(0,s.jsx)("div",{className:"flex items-center",children:(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"text-sm font-medium text-gray-900 dark:text-white flex items-center gap-2",children:[e.name,e.isDefault&&(0,s.jsx)(A.A,{className:"h-4 w-4 text-yellow-500"})]}),(0,s.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400 truncate max-w-xs",children:e.description||e.subject})]})})}),(0,s.jsx)("td",{className:"px-6 py-4 whitespace-nowrap",children:(0,s.jsx)(o.E,{variant:ei(e.category),children:e.category.replace("_"," ")})}),(0,s.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-white",children:e.variableCount||(null==(t=e.variables)?void 0:t.length)||0}),(0,s.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-white",children:e.usageCount||0}),(0,s.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400",children:en(e.createdAt)}),(0,s.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[g&&(0,s.jsx)(c.$,{onClick:()=>{G(e),U(!0)},variant:"ghost",size:"sm",children:(0,s.jsx)(E.A,{className:"h-4 w-4"})}),g&&(0,s.jsx)(c.$,{onClick:()=>er(e),variant:"ghost",size:"sm",className:"text-blue-600 hover:text-blue-700",children:(0,s.jsx)(D.A,{className:"h-4 w-4"})}),w&&(0,s.jsx)(c.$,{onClick:()=>{X(e),J(!0)},variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700",children:(0,s.jsx)(z.A,{className:"h-4 w-4"})})]})})]},e._id)})})]})})})}),(0,s.jsx)("div",{className:"md:hidden space-y-3 sm:space-y-4",children:v.map(t=>{var a;return(0,s.jsx)(m.Zp,{children:(0,s.jsxs)("div",{className:"p-3 sm:p-4",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between mb-2 sm:mb-3",children:[(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("h3",{className:"text-sm sm:text-base font-semibold text-gray-900 dark:text-white truncate flex items-center gap-1 sm:gap-2",children:[t.name,t.isDefault&&(0,s.jsx)(A.A,{className:"h-3 w-3 sm:h-4 sm:w-4 text-yellow-500"})]}),(0,s.jsx)("p",{className:"text-xs sm:text-sm text-gray-500 dark:text-gray-400 truncate",children:t.description||t.subject})]}),(0,s.jsx)("div",{className:"flex items-center gap-1 sm:gap-2 ml-2 sm:ml-4",children:(0,s.jsx)(o.E,{variant:ei(t.category),className:"text-xs",children:t.category.replace("_"," ")})})]}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between text-xs sm:text-sm text-gray-500 dark:text-gray-400 mb-2 sm:mb-3 space-y-1 sm:space-y-0",children:[(0,s.jsxs)("span",{children:["Variables:"," ",t.variableCount||(null==(a=t.variables)?void 0:a.length)||0]}),(0,s.jsxs)("span",{children:["Usage: ",t.usageCount||0]}),(0,s.jsx)("span",{children:en(t.createdAt)})]}),(0,s.jsxs)("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2",children:[g&&(0,s.jsxs)(c.$,{onClick:()=>e.push("/dashboard/email-templates/view/".concat(t._id)),variant:"ghost",size:"sm",className:"flex-1 text-xs sm:text-sm",children:[(0,s.jsx)(j.A,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1 sm:mr-2"}),"View"]}
1),g&&(0,s.jsxs)(c.$,{onClick:()=>{G(t),U(!0)},variant:"ghost",size:"sm",className:"flex-1 text-xs sm:text-sm",children:[(0,s.jsx)(E.A,{className:"h-3 w-3 sm:h-4 sm:w-4 mr-1 sm:mr-2"}),"Edit"]}),w&&(0,s.jsx)(c.$,{onClick:()=>er(t),variant:"ghost",size:"sm",className:"text-blue-600 hover:text-blue-700 text-xs sm:text-sm",children:(0,s.jsx)(D.A,{className:"h-3 w-3 sm:h-4 sm:w-4"})})]})]})},t._id)})})]}),q>1&&(0,s.jsx)("div",{className:"flex justify-center mt-6",children:(0,s.jsx)("div",{className:"flex gap-2",children:Array.from({length:q},(e,t)=>(0,s.jsx)(c.$,{variant:M===t+1?"primary":"outline",size:"sm",onClick:()=>R(t+1),children:t+1},t+1))})}),B&&(0,s.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-2 sm:p-4 z-50",children:(0,s.jsx)(m.Zp,{className:"w-full max-w-6xl max-h-[90vh] overflow-y-auto rounded-xl sm:rounded-2xl",children:(0,s.jsxs)("div",{className:"p-4 sm:p-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-3 sm:mb-4",children:[(0,s.jsx)("h2",{className:"text-lg sm:text-xl font-semibold",children:V?"Edit Template":"Create New Template"}),(0,s.jsx)(c.$,{variant:"ghost",size:"sm",onClick:()=>{U(!1),G(null)},children:(0,s.jsx)(b.A,{className:"h-4 w-4 sm:h-5 sm:w-5"})})]}),(0,s.jsx)(S,{template:V,onSubmit:ea,canCreate:g,canDelete:w,onDelete:es,onCancel:()=>{U(!1),G(null)},isSubmitting:W,error:P})]})})}),Z&&(0,s.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50",children:(0,s.jsx)(m.Zp,{className:"w-full max-w-md",children:(0,s.jsxs)("div",{className:"p-6",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,s.jsx)("div",{className:"p-2 bg-red-100 dark:bg-red-900 rounded-lg",children:(0,s.jsx)(y.A,{className:"h-6 w-6 text-red-600 dark:text-red-400"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Delete Template"}),(0,s.jsx)("p",{className:"text-gray-600 dark:text-gray-400",children:"This action cannot be undone."})]})]}),(0,s.jsxs)("p",{className:"text-gray-700 dark:text-gray-300 mb-6",children:["Are you sure you want to delete"," ",(0,s.jsx)("strong",{children:null==K?void 0:K.name}),"? This will permanently remove the template and all associated data."]}),(0,s.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,s.jsx)(c.$,{variant:"outline",onClick:()=>{J(!1),X(null)},children:"Cancel"}),(0,s.jsx)(c.$,{variant:"danger",onClick:es,loading:Q,children:"Delete"})]})]})})})]})}):(0,s.jsx)(n.A,{children:(0,s.jsx)("div",{className:"space-y-6 mt-2 mb-2",children:(0,s.jsx)(x.A,{title:"Access Denied",message:"You don't have permission to access email templates.",requiredRoles:"Admin or Manager",redirectPath:"/dashboard",redirectText:"Back to Dashboard"})})}):(e.push("/auth/login"),null)}}},e=>{e.O(0,[7725,347,2858,3,5885,1762,636,6593,8792],()=>e(e.s=35917)),_N_E=e.O()}]);
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.