1import{e as R,r as l,u as c,d as V,j as e}from"./vendor-query-CnAhr2B8.js";import{a as B,H as P,p as o,s as f,d as b,aH as w,q as k,r as T,I as D,O as q,Q as E,R as I,T as A,V as s,B as F,ak as O,a6 as _}from"./index-CLUtDhnY.js";import{T as $}from"./textarea-VdIEZsUv.js";import{f as z}from"./marketingHelpers-qSpyS2Z6.js";import"./vendor-ui-CYA7SV0W.js";import"./vendor-charts-CPMWc2oJ.js";import"./vendor-forms-UY-il7MQ.js";function Z(){const{toast:N}=B(),M=R(),[u,x]=l.useState(""),[g,h]=l.useState(""),[a,H]=l.useState("all"),[i,K]=l.useState("sms"),[v,y]=l.useState(""),{data:C=[]}=c({queryKey:["/api/marketing/templates"]}),{data:S=[]}=c({queryKey:["/api/marketing/campaigns"]}),{data:m=[]}=c({queryKey:["/api/customers"]}),{data:p=[]}=c({queryKey:["/api/marketing/inactive-customers",{days:"90"}]}),r=l.useMemo(()=>{if(a==="all")return m.map(t=>t.id);if(a==="inactive_90")return p.map(t=>t.id);if(a==="new"){const t=new Date;return t.setDate(t.getDate()-30),m.filter(d=>new Date(d.createdAt)>=t).map(d=>d.id)}if(a==="regular"){const t=new Date;t.setDate(t.getDate()-30);const d=new Set(p.map(n=>n.id));return m.filter(n=>new Date(n.createdAt)<t&&!d.has(n.id)).map(n=>n.id)}return[]},[a,m,p]),j=V({mutationFn:async()=>(await P("POST","/api/marketing/campaigns",{name:u,type:"campaign",template:g,channel:i,subject:i!=="sms"?v:void 0,customerIds:r,segment:a})).json(),onSuccess:()=>{N({title:"Campaign sent",description:`Sent to ${r.length} customer${r.length!==1?"s":""}`}),x(""),h(""),y(""),M.invalidateQueries({queryKey:["/api/marketing/campaigns"]})},onError:t=>{N({title:"Failed to send campaign",description:t.message,variant:"destructive"})}});function Q(t){x(t.name),h(t.template)}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground mb-3",children:"Template Gallery"}),C.length>0?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:C.map(t=>e.jsx(o,{className:"border-border bg-card hover:bg-muted/50 cursor-pointer transition-colors",onClick:()=>Q(t),children:e.jsxs(f,{className:"p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium text-foreground text-sm",children:t.name}),e.jsx(b,{variant:"secondary",className:"text-xs",children:t.type})]}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-3",children:t.template})]})},t.id))}):e.jsx(o,{className:"border-border bg-card",children:e.jsxs(f,{className:"py-8 text-center",children:[e.jsx(w,{className:"h-8 w-8 text-muted-foreground/40 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No templates available yet. Create your first campaign below."})]})})]}),e.jsxs(o,{className:"border-border bg-card",children:[e.jsx(k,{children:e.jsxs(T,{className:"text-base flex items-center gap-2",children:[e.jsx(w,{className:"h-4 w-4"}),"Campaign Editor"]})}),e.jsxs(f,{className:"space-y-4",children:[e.jsx(D,{placeholder:"Campaign name",value:u,onChange:t=>x(t.target.value)}),e.jsx($,{placeholder:"Write your campaign message...",value:g,onChange:t=>h(t.target.value),rows:4}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:"Target Segment"}),e.jsxs(q,{value:a,onValueChange:H,children:[e.jsx(E,{children:e.jsx(I,{})}),e.jsxs(A,{children:[e.jsx(s,{value:"all",children:"All Customers"}),e.jsx(s,{value:"new",children:"New (last 30 days)"}),e.jsx(s,{value:"regular",children:"Regular"}),e.jsx(s,{value:"inactive_90",children:"Inactive (90d+)"})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[r.length," customer",r.length!==1?"s":""," will receive this"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:"Channel"}),e.jsxs(q,{value:i,onValueChange:t=>K(t),children:[e.jsx(E,{children:e.jsx(I,{})}),e.jsxs(A,{children:[e.jsx(s,{value:"sms",children:"SMS"}),e.jsx(s,{value:"email",children:"Email"}),e.jsx(s,{value:"both",children:"SMS + Email"})]})]})]})]}),(i==="email"||i==="both")&&e.jsx(D,{placeholder:"Email subject line...",value:v,onCh
1ange:t=>y(t.target.value)}),e.jsxs(F,{onClick:()=>j.mutate(),disabled:j.isPending||!u.trim()||!g.trim()||r.length===0,children:[j.isPending?e.jsx(O,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(_,{className:"h-4 w-4 mr-2"}),"Send Campaign"]})]})]}),S.length>0&&e.jsxs(o,{className:"border-border bg-card overflow-hidden",children:[e.jsx(k,{children:e.jsx(T,{className:"text-base",children:"Campaign History"})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-muted/50",children:[e.jsx("th",{className:"p-3 text-left font-medium text-muted-foreground",children:"Name"}),e.jsx("th",{className:"p-3 text-left font-medium text-muted-foreground",children:"Type"}),e.jsx("th",{className:"p-3 text-left font-medium text-muted-foreground",children:"Channel"}),e.jsx("th",{className:"p-3 text-right font-medium text-muted-foreground",children:"Sent"}),e.jsx("th",{className:"p-3 text-left font-medium text-muted-foreground",children:"Date"}),e.jsx("th",{className:"p-3 text-left font-medium text-muted-foreground",children:"Status"})]})}),e.jsx("tbody",{children:S.map(t=>e.jsxs("tr",{className:"border-b border-border/50 hover:bg-muted/30 transition-colors",children:[e.jsx("td",{className:"p-3 font-medium text-foreground",children:t.name}),e.jsx("td",{className:"p-3",children:e.jsx(b,{variant:"secondary",className:"text-xs",children:t.type})}),e.jsx("td",{className:"p-3 text-muted-foreground capitalize",children:t.channel}),e.jsx("td",{className:"p-3 text-right text-foreground",children:t.sentCount}),e.jsx("td",{className:"p-3 text-muted-foreground",children:z(t.createdAt)}),e.jsx("td",{className:"p-3",children:e.jsx(b,{variant:"secondary",className:t.status==="sent"?"bg-green-100 dark:bg-green-900/30 text-green-600 dark:text-green-400":t.status==="failed"?"bg-red-100 dark:bg-red-900/30 text-red-600 dark:text-red-400":"bg-amber-100 dark:bg-amber-900/30 text-amber-600 dark:text-amber-400",children:t.status})})]},t.id))})]})})]})]})}export{Z 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.