1import{r as o,y as e}from"./vendor-CAn19U_C.js";import{A as E,d as y,n as i}from"./index-CJ3hxe8K.js";import{l as T}from"./emailService-Dq7LSEVV.js";import{q as A,j as L,h as z,f as D,B as P,d as M}from"./vendor-firebase-CMgAD1F0.js";import{e as I,bn as R,l as j,bv as $,aa as F,a9 as q,b as J,ai as O,s as w,E as W,aD as B,a as H}from"./vendor-lucide-B99EgzbQ.js";function X(){const[x,m]=o.useState("composer"),[n,v]=o.useState([]),[h,N]=o.useState(""),[s,c]=o.useState({subject:"",recipientType:"specific",recipientEmail:"",recipientList:"",htmlContent:`<h1>Hello {{name}}!</h1> 2<p>We have news for you.</p>`,scheduledAt:""}),[p,g]=o.useState(!1),[k,u]=o.useState(!1);o.useEffect(()=>{const t=A(z(y,"newsletter_subscribers"),L("subscribedAt","desc")),r=D(t,l=>{const d=l.docs.map(a=>({id:a.id,...a.data()}));v(d)});return()=>r()},[]);const S=async t=>{if(window.confirm("Are you sure you want to remove this subscriber?"))try{await P(M(y,"newsletter_subscribers",t)),i.success("Removed","Subscriber removed successfully")}catch{i.error("Error","Failed to remove subscriber")}},f=t=>{c(r=>({...r,htmlContent:r.htmlContent+t}))},C=async()=>{var t,r;if(!s.subject||!s.htmlContent){i.error("Missing Fields","Please fill in subject and content");return}if(s.recipientType==="specific"&&!s.recipientEmail){i.error("Missing Recipient","Please enter a recipient email");return}if(s.recipientType==="list"&&!s.recipientList){i.error("Missing List","Please enter emails for the list");return}g(!0);try{let l=s.recipientEmail;s.recipientType==="list"?l=s.recipientList.split(",").map(a=>a.trim()).filter(a=>a):s.recipientType==="newsletter-subscribers"?l=n.map(a=>a.email):(s.recipientType==="all-students"||s.recipientType==="all-instructors")&&(l=void 0);let d;s.scheduledAt&&(d=new Date(s.scheduledAt).toISOString()),await T({to:l,subject:s.subject,htmlContent:s.htmlContent,recipientType:s.recipientType,scheduledAt:d}),d?i.success("Scheduled","Email has been scheduled successfully"):i.success("Sent","Emails are being processed")}catch(l){i.error("Error",((r=(t=l.response)==null?void 0:t.data)==null?void 0:r.error)||"Failed to send email"),console.error(l)}finally{g(!1)}},b=!!s.scheduledAt;return e.jsxs(E,{activePage:"Email Sender",children:[e.jsxs("div",{className:"mb-8 flex flex-col md:flex-row md:items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-black text-gray-900",children:"Email & Newsletter"}),e.jsx("p",{className:"text-gray-500 text-xs font-bold uppercase tracking-widest mt-1",children:"Send campaigns, updates, and announcements"})]}),e.jsxs("div",{className:"flex bg-white p-1 rounded-2xl border border-gray-100 shadow-sm",children:[e.jsx("button",{onClick:()=>m("composer"),className:`px-6 py-2.5 rounded-xl text-xs font-black uppercase tracking-widest transition-all ${x==="composer"?"bg-blue-600 text-white shadow-lg shadow-blue-200":"text-gray-400 hover:text-gray-600"}`,children:"Composer"}),e.jsxs("button",{onClick:()=>m("subscribers"),className:`px-6 py-2.5 rounded-xl text-xs font-black uppercase tracking-widest transition-all ${x==="subscribers"?"bg-blue-600 text-white shadow-lg shadow-blue-200":"text-gray-400 hover:text-gray-600"}`,children:["Subscribers (",n.length,")"]})]})]}),x==="composer"?e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"bg-white p-8 rounded-[32px] border border-gray-100 shadow-sm space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 block",children:"Subject Line"}),e.jsx("input",{type:"text",value:s.subject,onChange:t=>c({...s,subject:t.target.value}),placeholder:"e.g. Monthly Newsletter",className:"w-full px-5 py-3 bg-gray-50 border border-gray-100 rounded-xl font-bold text-gray-700 focus:bg-white focus:border-blue-500 outline-none transition-all"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 block flex items-center gap-1",children:[e.jsx(I,{size:12})," Recipient Group"]}
2),e.jsxs("select",{value:s.recipientType,onChange:t=>c({...s,recipientType:t.target.value}),className:"w-full px-5 py-3 bg-gray-50 border border-gray-100 rounded-xl font-bold text-gray-700 outline-none cursor-pointer hover:bg-gray-100 transition-colors",children:[e.jsx("option",{value:"specific",children:"Specific User"}),e.jsx("option",{value:"list",children:"Custom List (Comma Separated)"}),e.jsxs("option",{value:"newsletter-subscribers",children:["Newsletter Subscribers (",n.length,")"]}),e.jsx("option",{value:"all-students",children:"All Students"}),e.jsx("option",{value:"all-instructors",children:"All Instructors"})]})]}),e.jsxs("div",{children:[s.recipientType==="specific"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 block",children:"Email Address"}),e.jsx("input",{type:"email",value:s.recipientEmail,onChange:t=>c({...s,recipientEmail:t.target.value}),placeholder:"[email protected]",className:"w-full px-5 py-3 bg-gray-50 border border-gray-100 rounded-xl font-bold text-gray-700 focus:bg-white focus:border-blue-500 outline-none transition-all"})]}),s.recipientType==="list"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 block",children:"Email List"}),e.jsx("input",{type:"text",value:s.recipientList,onChange:t=>c({...s,recipientList:t.target.value}),placeholder:"[email protected], [email protected]",className:"w-full px-5 py-3 bg-gray-50 border border-gray-100 rounded-xl font-bold text-gray-700 focus:bg-white focus:border-blue-500 outline-none transition-all"})]}),(s.recipientType==="all-students"||s.recipientType==="all-instructors"||s.recipientType==="newsletter-subscribers")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 block",children:"Info"}),e.jsxs("div",{className:"px-5 py-3 bg-blue-50 border border-blue-100 rounded-xl text-blue-600 text-xs font-bold flex items-center gap-2",children:[e.jsx(R,{size:14}),s.recipientType==="newsletter-subscribers"?`Will send to all ${n.length} newsletter subscribers.`:`Will send to all active ${s.recipientType==="all-students"?"students":"instructors"}.`]})]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2 block flex items-center gap-1",children:[e.jsx(j,{size:12})," Schedule Send (Optional)"]}),e.jsx("input",{type:"datetime-local",value:s.scheduledAt,onChange:t=>c({...s,scheduledAt:t.target.value}),className:"w-full px-5 py-3 bg-gray-50 border border-gray-100 rounded-xl font-bold text-gray-700 focus:bg-white focus:border-blue-500 outline-none transition-all"}),e.jsx("p",{className:"text-[10px] text-gray-400 font-bold mt-1 pl-1",children:"Leave blank to send immediately."})]}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("label",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400 flex items-center gap-1",children:[e.jsx($,{size:12})," HTML Content"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>f("{{name}}"),className:"px-2 py-1 bg-gray-100 hover:bg-gray-200 rounded text-[10px] font-bold text-gray-600 transition-colors",children:"+ Name"}),e.jsx("button",{onClick:()=>f("{{email}}"),className:"px-2 py-1 bg-gray-100 hover:bg-gray-200 rounded text-[10px] font-bold text-gray-600 transition-colors",children:"+ Email"})]})]}),e.jsx("textarea",{value:s.htmlContent,onChange:t=>c({...s,htmlContent:t.target.value}),className:"w-full h-80 p-5 bg-gray-900 text-blue-300 font-mono text-xs rounded-xl border border-gray-700 focus:border-blue-500 outline-none custom-scrollbar",placeholder:"<div>Content here...</div>"})]}),e.jsxs("div",{className:"flex gap-4 pt-4",children:[e.jsxs("button",{onClick:()=>u(!0),className:"flex-1 py-3 px-6 bg-gray-100 text-gray-600 rounded-xl font-black uppercase tracking-widest text-[11px] hover:bg-gray-200 transition-colors flex items-center justify-center gap-2",children:[e.jsx(F,{size:16})," Preview"]}),e.jsxs("button",{onClick:C,disabled:p,className:`flex-1 py-3 px-6 text-white rounded-xl font-black uppercase tracking-widest text-[11px] transition-all flex items-center justify-center gap-2 shadow-lg ${b?"bg-emerald-600 hover:bg-emerald-700 shadow-emerald-200":"bg-blue-600 hover:bg-blue-700 shadow-blue-200"}`,children:[p?e.jsx("span",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"}):b?e.jsx(j,{size:16}):e.jsx(q,{size:16}),p?"Processing...":b?"Schedule Email":"Send Now"]})]})]}),e.jsxs("div",{className:"hidden lg:block bg-gray-50 p-8 rounded-[32px] border border-gray-200 shadow-inner h-full overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400",children:"Live Preview"}),e.jsx("div",{className:"px-3 py-1 bg-white rounded-full text-[10px] font-bold text-gray-400 shadow-sm border border-gray-100",children:"width: 600px"})]}),e.jsx("div",{className:"flex-1 bg-white rounded-2xl shadow-sm overflow-hidden border border-gray-200 mx-auto w-[600px] relative",children:e.jsx("iframe",{title:"Email Preview",srcDoc:s.htmlContent.replace("{{name}}","John Doe").replace("{{email}}","[email protected]"),className:"w-full h-full border-none"})})]})]}):e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"bg-white p-8 rounded-[32px] border border-gray-100 shadow-sm",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6 mb-8",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(J,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-400",size:18}),e.jsx("input",{type:"text",placeholder:"Search by email...",value:h,onChange:t=>N(t.target.value),className:"w-full pl-12 pr-6 py-3 bg-gray-50 border border-gray-100 rounded-2xl font-bold text-gray-700 focus:bg-white focus:border-blue-500 outline-none transition-all"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{className:"p-3 bg-gray-50 border border-gray-100 rounded-xl text-gray-400 hover:text-blue-600 transition-colors",children:e.jsx(O,{size:20})}),e.jsxs("span",{className:"text-xs font-black text-gray-400 uppercase tracking-widest",children:["Total: ",n.length]})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-50",children:[e.jsx("th",{className:"text-left py-4 px-4 text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"Subscriber"}),e.jsx("th",{className:"text-left py-4 px-4 text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"Status"}),e.jsx("th",{className:"text-left py-4 px-4 text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"Joined Date"}),e.jsx("th",{className:"text-right py-4 px-4 text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"Actions"})]})}),e.jsxs("tbody",{children:[n.filter(t=>t.email.toLowerCase().includes(h.toLowerCase())).map(t=>{var r;return e.jsxs("tr",{className:"group hover:bg-gray-50 transition-colors",children:[e.jsx("td",{className:"py-4 px-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center text-blue-600",children:e.jsx(w,{size:18})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-gray-900",children:t.email}),e.jsx("p",{className:"text-[10px] text-gray-400 font-bold uppercase tracking-wider",children:"Active Channel"})]})]})}),e.jsx("td",{className:"py-4 px-4",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-emerald-600 bg-emerald-50 px-3 py-1 rounded-full w-fit",children:[e.jsx(W,{size:12}),e.jsx("span",{className:"text-[10px] font-black uppercase tracking-widest",children:"Verified"})]})}),e.jsx("td",{className:"py-4 px-4",children:e.jsx("p",{className:"text-sm font-bold text-gray-600",children:(r=t.subscribedAt)!=null&&r.toDate?t.subscribedAt.toDate().toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"}):"Recently Added"})}),e.jsx("td",{className:"py-4 px-4 text-right",children:e.jsx("button",{onClick:()=>S(t.id),className:"p-2 text-gray-300 hover:text-red-500 hover:bg-red-50 rounded-lg transition-all",children:e.jsx(B,{size:18})})})]},t.id)}),n.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"py-20 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 bg-gray-50 rounded-full flex items-center justify-center text-gray-300",children:e.jsx(w,{size:32})}),e.jsx("p",{className:"text-gray-400 font-bold",children:"No subscribers found yet."})]})})})]})]})})]})}),k&&e.jsxs("div",{className:"fixed inset-0 z-[200] flex items-center justify-center p-4 lg:hidden",children:[e.jsx("div",{className:"absolute inset-0 bg-gray-900/80 backdrop-blur-sm",onClick:()=>u(!1)}),e.jsxs("div",{className:"relative bg-white w-full max-w-lg h-[80vh] rounded-[32px] overflow-hidden flex flex-col shadow-2xl",children:[e.jsxs("div",{className:"p-4 border-b border-gray-100 flex items-center justify-between bg-white",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"Email Preview"}),e.jsx("button",{onClick:()=>u(!1),className:"p-2 hover:bg-gray-50 rounded-full",children:e.jsx(H,{size:20})})]}),e.jsx("div",{className:"flex-1 bg-gray-50 p-4",children:e.jsx("div",{className:"bg-white w-full h-full rounded-xl shadow-sm overflow-hidden border border-gray-200",children:e.jsx("iframe",{title:"Email Preview Mobile",srcDoc:s.htmlContent.replace("{{name}}","John Doe").replace("{{email}}","[email protected]"),className:"w-full h-full border-none"})})})]})]})]})}export{X 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.