PageSourceSearch

https://hurricaneshuttersflorida.com/assets/Admin-DU8dZs26.js

js hurricaneshuttersflorida.com collected 2026-09-25 06:49:03 UTC 149,542 bytes, 58 lines download raw bytes

1import{c as pe,a as Ie,r as h,u as Me,b as ts,j as e,P as fe,d as xe,e as Zt,f as Xt,g as V,h as Ls,T as Jt,O as ea,W as sa,C as ta,i as aa,D as na,k as Os,R as ra,l as la,m as ia,n as Bs,o as ca,p as Us,q as oa,s as Vs,t as da,v as re,w as me,x as U,y as S,z as q,A as E,B as te,E as C,L as B,I as O,F as T,X as xa,M as ma,U as Ne,S as as,G as $e,H as zs,J as Le,K as ua,N as ha,Q as ve,V as z,Y as Ae,Z as Qs,_ as Ye,$ as Pe,a0 as qe,a1 as Ee,a2 as Oe,a3 as ie,a4 as ce,a5 as oe,a6 as de,a7 as k,a8 as ns,a9 as je,aa as Rs,ab as pa,ac as Te,ad as K,ae as rs,af as Ks,ag as Be,ah as F,ai as ja,aj as ga,ak as Hs,al as fa,am as Na,an as Ue,ao as Ve,ap as Ws,aq as ba,ar as We,as as Fs}from"./index-CPAHsPJE.js";/**
2 * @license lucide-react v0.453.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ls=pe("Activity",[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]]);/**
7 * @license lucide-react v0.453.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const va=pe("ChartColumn",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]]);/**
12 * @license lucide-react v0.453.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const ya=pe("LogIn",[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]]);/**
17 * @license lucide-react v0.453.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const _s=pe("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/**
22 * @license lucide-react v0.453.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const wa=pe("MailX",[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h9",key:"1j9vog"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m17 17 4 4",key:"1b3523"}],["path",{d:"m21 17-4 4",key:"uinynz"}]]);/**
27 * @license lucide-react v0.453.0 - ISC
28 *
29 * This source code is licensed under the ISC license.
30 * See the LICENSE file in the root directory of this source tree.
31 */const Ze=pe("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);/**
32 * @license lucide-react v0.453.0 - ISC
33 *
34 * This source code is licensed under the ISC license.
35 * See the LICENSE file in the root directory of this source tree.
36 */const $s=pe("Smartphone",[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]]);/**
37 * @license lucide-react v0.453.0 - ISC
38 *
39 * This source code is licensed under the ISC license.
40 * See the LICENSE file in the root directory of this source tree.
41 */const is=pe("Target",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["circle",{cx:"12",cy:"12",r:"6",key:"1vlfrh"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);/**
42 * @license lucide-react v0.453.0 - ISC
43 *
44 * This source code is licensed under the ISC license.
45 * See the LICENSE file in the root directory of this source tree.
46 */const ze=pe("TrendingUp",[["polyline",{points:"22 7 13.5 15.5 8.5 10.5 2 17",key:"126l90"}],["polyline",{points:"16 7 22 7 22 13",key:"kwv8wd"}]]);/**
47 * @license lucide-react v0.453.0 - ISC
48 *
49 * This source code is licensed under the ISC license.
50 * See the LICENSE file in the root directory of this source tree.
51 */const Is=pe("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);var cs="Switch",[Sa,kn]=Ie(cs),[Ca,ka]=Sa(cs),Gs=h.forwardRef((s,n)=>{const{__scopeSwitch:t,name:l,checked:o,defaultChecked:j,required:m,disabled:g,value:v="on",onCheckedChange:a,form:p,...d}=s,[x,r]=h.useState(null),w=Me(n,R=>r(R)),y=h.useRef(!1),f=x?p||!!x.closest("form"):!0,[A=!1,c]=ts({prop:o,defaultProp:j,onChange:a});return e.jsxs(Ca,{scope:t,checked:A,disabled:g,children:[e.jsx(fe.button,{type:"button",role:"switch","aria-checked":A,"aria-required":m,"data-state":Xs(A),"data-disabled":g?"":void 0,disabled:g,value:v,...d,ref:w,onClick:xe(s.onClick,R=>{c(I=>!I),f&&(y.current=R.isPropagationStopped(),y.current||R.stopPropagation())})}),f&&e.jsx(Ta,{control:x,bubbles:!y.current,name:l,value:v,checked:A,required:m,disabled:g,form:p,style:{transform:"translateX(-100%)"}})]})});Gs.displayName=cs;var Ys="SwitchThumb",Zs=h.forwardRef((s,n)=>{const{__scopeSwitch:t,...l}=s,o=ka(Ys,t);return e.jsx(fe.span,{"data-state":Xs(o.checked),"data-disabled":o.disabled?"":void 0,...l,ref:n})});Zs.displayName=Ys;var Ta=s=>{const{control:n,checked:t,bubbles:l=!0,...o}=s,j=h.useRef(null),m=Zt(t),g=Xt(n);return h.useEffect(()=>{const v=j.current,a=window.HTMLInputElement.prototype,d=Object.getOwnPropertyDescriptor(a,"checked").set;if(m!==t&&d){const x=new Event("click",{bubbles:l});d.call(v,t),v.dispatchEvent(x)}},[m,t,l]),e.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:t,...o,tabIndex:-1,ref:j,style:{...s.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function Xs(s){return s?"checked":"unchecked"}var Js=Gs,Da=Zs;const et=h.forwardRef(({className:s,...n},t)=>e.jsx(Js,{className:V("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s
51),...n,ref:t,children:e.jsx(Da,{className:V("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));et.displayName=Js.displayName;const Y=h.forwardRef(({className:s,...n},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:V("w-full caption-bottom text-sm",s),...n})}));Y.displayName="Table";const Z=h.forwardRef(({className:s,...n},t)=>e.jsx("thead",{ref:t,className:V("[&_tr]:border-b",s),...n}));Z.displayName="TableHeader";const X=h.forwardRef(({className:s,...n},t)=>e.jsx("tbody",{ref:t,className:V("[&_tr:last-child]:border-0",s),...n}));X.displayName="TableBody";const Aa=h.forwardRef(({className:s,...n},t)=>e.jsx("tfoot",{ref:t,className:V("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...n}));Aa.displayName="TableFooter";const D=h.forwardRef(({className:s,...n},t)=>e.jsx("tr",{ref:t,className:V("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s),...n}));D.displayName="TableRow";const N=h.forwardRef(({className:s,...n},t)=>e.jsx("th",{ref:t,className:V("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",s),...n}));N.displayName="TableHead";const u=h.forwardRef(({className:s,...n},t)=>e.jsx("td",{ref:t,className:V("p-4 align-middle [&:has([role=checkbox])]:pr-0",s),...n}));u.displayName="TableCell";const Pa=h.forwardRef(({className:s,...n},t)=>e.jsx("caption",{ref:t,className:V("mt-4 text-sm text-muted-foreground",s),...n}));Pa.displayName="TableCaption";var st="AlertDialog",[qa,Tn]=Ie(st,[Ls]),ge=Ls(),tt=s=>{const{__scopeAlertDialog:n,...t}=s,l=ge(n);return e.jsx(ra,{...l,...t,modal:!0})};tt.displayName=st;var Ea="AlertDialogTrigger",at=h.forwardRef((s,n)=>{const{__scopeAlertDialog:t,...l}=s,o=ge(t);return e.jsx(Jt,{...o,...l,ref:n})});at.displayName=Ea;var Ra="AlertDialogPortal",nt=s=>{const{__scopeAlertDialog:n,...t}=s,l=ge(n);return e.jsx(la,{...l,...t})};nt.displayName=Ra;var Fa="AlertDialogOverlay",rt=h.forwardRef((s,n)=>{const{__scopeAlertDialog:t,...l}=s,o=ge(t);return e.jsx(ea,{...o,...l,ref:n})});rt.displayName=Fa;var be="AlertDialogContent",[_a,$a]=qa(be),Ia=ia("AlertDialogContent"),lt=h.forwardRef((s,n)=>{const{__scopeAlertDialog:t,children:l,...o}=s,j=ge(t),m=h.useRef(null),g=Me(n,m),v=h.useRef(null);return e.jsx(sa,{contentName:be,titleName:it,docsSlug:"alert-dialog",children:e.jsx(_a,{scope:t,cancelRef:v,children:e.jsxs(ta,{role:"alertdialog",...j,...o,ref:g,onOpenAutoFocus:xe(o.onOpenAutoFocus,a=>{var p;a.preventDefault(),(p=v.current)==null||p.focus({preventScroll:!0})}),onPointerDownOutside:a=>a.preventDefault(),onInteractOutside:a=>a.preventDefault(),children:[e.jsx(Ia,{children:l}),e.jsx(La,{contentRef:m})]})})})});lt.displayName=be;var it="AlertDialogTitle",ct=h.forwardRef((s,n)=>{const{__scopeAlertDialog:t,...l}=s,o=ge(t);return e.jsx(aa,{...o,...l,ref:n})});ct.displayName=it;var ot="AlertDialogDescription",dt=h.forwardRef((s,n)=>{const{__scopeAlertDialog:t,...l}=s,o=ge(t);return e.jsx(na,{...o,...l,ref:n})});dt.displayName=ot;var Ma="AlertDialogAction",xt=h.forwardRef((s,n)=>{const{__scopeAlertDialog:t,...l}=s,o=ge(t);return e.jsx(Os,{...o,...l,ref:n})});xt.displayName=Ma;var mt="AlertDialogCancel",ut=h.forwardRef((s,n)=>{const{__scopeAlertDialog:t,...l}=s,{cancelRef:o}=$a(mt,t),j=ge(t),m=Me(n,o);return e.jsx(Os,{...j,...l,ref:m})});ut.displayName=mt;var La=({contentRef:s})=>{const n=`\`${be}\` requires a description for the component to be accessible for screen reader users.
52
53You can add a description to the \`${be}\` by passing a \`${ot}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
54
55Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${be}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component.
56
57For more information, see https://radix-ui.com/primitives/docs/components/
57alert-dialog`;return h.useEffect(()=>{var l;document.getElementById((l=s.current)==null?void 0:l.getAttribute("aria-describedby"))||console.warn(n)},[n,s]),null},Oa=tt,Ba=at,Ua=nt,ht=rt,pt=lt,jt=xt,gt=ut,ft=ct,Nt=dt;const bt=Oa,vt=Ba,Va=Ua,yt=h.forwardRef(({className:s,...n},t)=>e.jsx(ht,{className:V("fixed inset-0 z-50 bg-black/80  data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...n,ref:t}));yt.displayName=ht.displayName;const os=h.forwardRef(({className:s,...n},t)=>e.jsxs(Va,{children:[e.jsx(yt,{}),e.jsx(pt,{ref:t,className:V("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s),...n})]}));os.displayName=pt.displayName;const ds=({className:s,...n})=>e.jsx("div",{className:V("flex flex-col space-y-2 text-center sm:text-left",s),...n});ds.displayName="AlertDialogHeader";const xs=({className:s,...n})=>e.jsx("div",{className:V("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s),...n});xs.displayName="AlertDialogFooter";const ms=h.forwardRef(({className:s,...n},t)=>e.jsx(ft,{ref:t,className:V("text-lg font-semibold",s),...n}));ms.displayName=ft.displayName;const us=h.forwardRef(({className:s,...n},t)=>e.jsx(Nt,{ref:t,className:V("text-sm text-muted-foreground",s),...n}));us.displayName=Nt.displayName;const hs=h.forwardRef(({className:s,...n},t)=>e.jsx(jt,{ref:t,className:V(Bs(),s),...n}));hs.displayName=jt.displayName;const ps=h.forwardRef(({className:s,...n},t)=>e.jsx(gt,{ref:t,className:V(Bs({variant:"outline"}),"mt-2 sm:mt-0",s),...n}));ps.displayName=gt.displayName;var Ge="rovingFocusGroup.onEntryFocus",za={bubbles:!1,cancelable:!0},Qe="RovingFocusGroup",[Xe,wt,Qa]=ca(Qe),[Ka,St]=Ie(Qe,[Qa]),[Ha,Wa]=Ka(Qe),Ct=h.forwardRef((s,n)=>e.jsx(Xe.Provider,{scope:s.__scopeRovingFocusGroup,children:e.jsx(Xe.Slot,{scope:s.__scopeRovingFocusGroup,children:e.jsx(Ga,{...s,ref:n})})}));Ct.displayName=Qe;var Ga=h.forwardRef((s,n)=>{const{__scopeRovingFocusGroup:t,orientation:l,loop:o=!1,dir:j,currentTabStopId:m,defaultCurrentTabStopId:g,onCurrentTabStopIdChange:v,onEntryFocus:a,preventScrollOnEntryFocus:p=!1,...d}=s,x=h.useRef(null),r=Me(n,x),w=Us(j),[y=null,f]=ts({prop:m,defaultProp:g,onChange:v}),[A,c]=h.useState(!1),R=oa(a),I=wt(t),J=h.useRef(!1),[Q,ne]=h.useState(0);return h.useEffect(()=>{const M=x.current;if(M)return M.addEventListener(Ge,R),()=>M.removeEventListener(Ge,R)},[R]),e.jsx(Ha,{scope:t,orientation:l,dir:w,loop:o,currentTabStopId:y,onItemFocus:h.useCallback(M=>f(M),[f]),onItemShiftTab:h.useCallback(()=>c(!0),[]),onFocusableItemAdd:h.useCallback(()=>ne(M=>M+1),[]),onFocusableItemRemove:h.useCallback(()=>ne(M=>M-1),[]),children:e.jsx(fe.div,{tabIndex:A||Q===0?-1:0,"data-orientation":l,...d,ref:r,style:{outline:"none",...s.style},onMouseDown:xe(s.onMouseDown,()=>{J.current=!0}),onFocus:xe(s.onFocus,M=>{const P=!J.current;if(M.target===M.currentTarget&&P&&!A){const L=new CustomEvent(Ge,za);if(M.currentTarget.dispatchEvent(L),!L.defaultPrevented){const W=I().filter($=>$.focusable),se=W.find($=>$.active),le=W.find($=>$.id===y),b=[se,le,...W].filter(Boolean).map($=>$.ref.current);Dt(b,p)}}J.current=!1}),onBlur:xe(s.onBlur,()=>c(!1))})})}),kt="RovingFocusGroupItem",Tt=h.forwardRef((s,n)=>{const{__scopeRovingFocusGroup:t,focusable:l=!0,active:o=!1,tabStopId:j,...m}=s,g=Vs(),v=j||g,a=Wa(kt,t),p=a.currentTabStopId===v,d=wt(t),{onFocusableItemAdd:x,onFocusableItemRemove:r}=a;return h.useEffect(()=>{if(l)return x(),()=>r()},[l,x,r]),e.jsx(Xe.ItemSlot,{scope:t,id:v,focusable:l,active:o,children:e.jsx(fe.span,{tabIndex:p?0:-1,"data-orientation":a.orientation,...m,ref:n,onMouseDown:xe(s.onMouseDown,w=>{l?a.onItemFocus(v):w.preventDefault()}),onFocus:xe(s.onFocus,()=>a.onItemFocus(v)),onKeyDown:xe(s.onKeyDown,w=>
57{if(w.key==="Tab"&&w.shiftKey){a.onItemShiftTab();return}if(w.target!==w.currentTarget)return;const y=Xa(w,a.orientation,a.dir);if(y!==void 0){if(w.metaKey||w.ctrlKey||w.altKey||w.shiftKey)return;w.preventDefault();let A=d().filter(c=>c.focusable).map(c=>c.ref.current);if(y==="last")A.reverse();else if(y==="prev"||y==="next"){y==="prev"&&A.reverse();const c=A.indexOf(w.currentTarget);A=a.loop?Ja(A,c+1):A.slice(c+1)}setTimeout(()=>Dt(A))}})})})});Tt.displayName=kt;var Ya={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Za(s,n){return n!=="rtl"?s:s==="ArrowLeft"?"ArrowRight":s==="ArrowRight"?"ArrowLeft":s}function Xa(s,n,t){const l=Za(s.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(l))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(l)))return Ya[l]}function Dt(s,n=!1){const t=document.activeElement;for(const l of s)if(l===t||(l.focus({preventScroll:n}),document.activeElement!==t))return}function Ja(s,n){return s.map((t,l)=>s[(n+l)%s.length])}var en=Ct,sn=Tt,js="Tabs",[tn,Dn]=Ie(js,[St]),At=St(),[an,gs]=tn(js),Pt=h.forwardRef((s,n)=>{const{__scopeTabs:t,value:l,onValueChange:o,defaultValue:j,orientation:m="horizontal",dir:g,activationMode:v="automatic",...a}=s,p=Us(g),[d,x]=ts({prop:l,onChange:o,defaultProp:j});return e.jsx(an,{scope:t,baseId:Vs(),value:d,onValueChange:x,orientation:m,dir:p,activationMode:v,children:e.jsx(fe.div,{dir:p,"data-orientation":m,...a,ref:n})})});Pt.displayName=js;var qt="TabsList",Et=h.forwardRef((s,n)=>{const{__scopeTabs:t,loop:l=!0,...o}=s,j=gs(qt,t),m=At(t);return e.jsx(en,{asChild:!0,...m,orientation:j.orientation,dir:j.dir,loop:l,children:e.jsx(fe.div,{role:"tablist","aria-orientation":j.orientation,...o,ref:n})})});Et.displayName=qt;var Rt="TabsTrigger",Ft=h.forwardRef((s,n)=>{const{__scopeTabs:t,value:l,disabled:o=!1,...j}=s,m=gs(Rt,t),g=At(t),v=It(m.baseId,l),a=Mt(m.baseId,l),p=l===m.value;return e.jsx(sn,{asChild:!0,...g,focusable:!o,active:p,children:e.jsx(fe.button,{type:"button",role:"tab","aria-selected":p,"aria-controls":a,"data-state":p?"active":"inactive","data-disabled":o?"":void 0,disabled:o,id:v,...j,ref:n,onMouseDown:xe(s.onMouseDown,d=>{!o&&d.button===0&&d.ctrlKey===!1?m.onValueChange(l):d.preventDefault()}),onKeyDown:xe(s.onKeyDown,d=>{[" ","Enter"].includes(d.key)&&m.onValueChange(l)}),onFocus:xe(s.onFocus,()=>{const d=m.activationMode!=="manual";!p&&!o&&d&&m.onValueChange(l)})})})});Ft.displayName=Rt;var _t="TabsContent",$t=h.forwardRef((s,n)=>{const{__scopeTabs:t,value:l,forceMount:o,children:j,...m}=s,g=gs(_t,t),v=It(g.baseId,l),a=Mt(g.baseId,l),p=l===g.value,d=h.useRef(p);return h.useEffect(()=>{const x=requestAnimationFrame(()=>d.current=!1);return()=>cancelAnimationFrame(x)},[]),e.jsx(da,{present:o||p,children:({present:x})=>e.jsx(fe.div,{"data-state":p?"active":"inactive","data-orientation":g.orientation,role:"tabpanel","aria-labelledby":v,hidden:!x,id:a,tabIndex:0,...m,ref:n,style:{...s.style,animationDuration:d.current?"0s":void 0},children:x&&j})})});$t.displayName=_t;function It(s,n){return`${s}-trigger-${n}`}function Mt(s,n){return`${s}-content-${n}`}var nn=Pt,Lt=Et,Ot=Ft,Bt=$t;const rn=nn,Ut=h.forwardRef(({className:s,...n},t)=>e.jsx(Lt,{ref:t,className:V("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",s),...n}));Ut.displayName=Lt.displayName;const Je=h.forwardRef(({className:s,...n},t)=>e.jsx(Ot,{ref:t,className:V("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",s),...n}));Je.displayName=Ot.displayName;const es=h.forwardRef(({className:s,...n},t)=>e.jsx(Bt,{ref:t,className:V("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s),...n}));es.displayName=Bt.displayName;const ln=[{id:"dashboard",label:"Dashboard",icon:va},{id:"discount-users",label:"Entry Pop-up Sign Up",icon:Ne},{id:"abandoned-carts",label:"Abandon Cart",icon:as},{id:"orders",label:"Order/Quotes",icon:$e},{id:"credit-cards",label:"Secure Payment Methods",icon:zs},{id:"testimonials",label:"Testimonials",icon:Ze},{id:"pricing",label:"Adjust Price",icon:Le},{id:"lead-times",label:"Turn Around Times",icon:ua},{id:"content",label:"CMS",icon:ha},{id:"analytics",label:"Visitor Analytics",icon:ze},{id:"ab-test",label:"Headline Test Results",icon:is},{id:"email-report",label:"Email Reports",icon:ve},{id:"chat-logs",label:"Chat Logs",icon:Ze}];function An(){const{toast:s}=re(),n=me(),[t,l]=h.useState(!1),[o,j]=h.useState("dashboard"),[m,g]=h.useState(!0),[v,a]=h.useState({username:"",password:""});h.useEffect(()=>{const w=new URLSearchParams(window.location.search).get("section");
57w&&["dashboard","discount-users","abandoned-carts","orders","credit-cards","testimonials","pricing","lead-times","content","analytics","ab-test","email-report","chat-logs"].includes(w)&&j(w)},[]),h.useEffect(()=>{fetch("/api/admin/me",{credentials:"include"}).then(r=>r.json()).then(r=>{r.isAuthenticated&&l(!0)}).catch(()=>{})},[]);const p=U({mutationFn:async r=>{const w=await fetch("/api/admin/login",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(r)});if(!w.ok)throw new Error("Invalid credentials");return w.json()},onSuccess:()=>{l(!0),s({title:"Login Successful",description:"Welcome to the admin panel."})},onError:()=>{s({title:"Login Failed",description:"Invalid username or password.",variant:"destructive"})}}),d=r=>{if(r.preventDefault(),!v.username.trim()||!v.password){s({title:"Username and password required",description:"Enter both fields to sign in.",variant:"destructive"});return}p.mutate(v)},x=async()=>{await fetch("/api/admin/logout",{method:"POST",credentials:"include"}),l(!1),n.clear(),s({title:"Logged Out",description:"You have been successfully logged out."})};return t?e.jsxs("div",{className:"min-h-screen bg-slate-100 flex",children:[e.jsxs("aside",{className:`${m?"w-64":"w-16"} bg-[#1B4D3E] text-white transition-all duration-300 flex flex-col`,children:[e.jsxs("div",{className:"p-4 border-b border-white/10 flex items-center justify-between",children:[m&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 bg-red-600 rounded-full flex items-center justify-center text-xs font-bold",children:"HS"}),e.jsx("span",{className:"font-bold text-sm",children:"HURRICANE SHUTTERS"})]}),e.jsx(T,{variant:"ghost",size:"sm",className:"text-white hover:bg-white/10",onClick:()=>g(!m),children:m?e.jsx(xa,{className:"w-4 h-4"}):e.jsx(ma,{className:"w-4 h-4"})})]}),m&&e.jsx("div",{className:"p-4 border-b border-white/10",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 bg-white/20 rounded-full flex items-center justify-center",children:e.jsx(Ne,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"User Admin"}),e.jsxs(T,{variant:"link",className:"text-xs text-white/70 p-0 h-auto",onClick:x,children:[e.jsx(_s,{className:"w-3 h-3 mr-1"}),"Log Out"]})]})]})}),e.jsx("nav",{className:"flex-1 py-4 overflow-y-auto",children:ln.map(r=>e.jsxs("button",{onClick:()=>j(r.id),className:`w-full flex items-center gap-3 px-4 py-3 text-sm transition-colors ${o===r.id?"bg-[#C25B2B] text-white":"text-white/80 hover:bg-white/10"}`,"data-testid":`nav-${r.id}`,children:[e.jsx(r.icon,{className:"w-5 h-5 flex-shrink-0"}),m&&e.jsx("span",{className:"truncate",children:r.label})]},r.id))}),e.jsx("div",{className:"p-4 border-t border-white/10",children:e.jsxs(T,{variant:"ghost",className:"w-full justify-start text-white/80 hover:bg-white/10",onClick:x,children:[e.jsx(_s,{className:"w-5 h-5 mr-3"}),m&&"Logout"]})})]}),e.jsx("main",{className:"flex-1 overflow-auto",children:e.jsxs("div",{className:"p-6",children:[o==="dashboard"&&e.jsx(cn,{}),o==="discount-users"&&e.jsx(on,{}),o==="abandoned-carts"&&e.jsx(dn,{}),o==="orders"&&e.jsx(xn,{}),o==="credit-cards"&&e.jsx(mn,{}),o==="testimonials"&&e.jsx(un,{}),o==="pricing"&&e.jsx(hn,{}),o==="lead-times"&&e.jsx(pn,{}),o==="content"&&e.jsx(jn,{}),o==="analytics"&&e.jsx(bn,{}),o==="ab-test"&&e.jsx(Sn,{}),o==="email-report"&&e.jsx(wn,{}),o==="chat-logs"&&e.jsx(vn,{})]})})]}):e.jsx("div",{className:"min-h-screen bg-slate-100 flex items-center justify-center p-4",children:e.jsxs(S,{className:"w-full max-w-md",children:[e.jsxs(q,{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-[#1B4D3E]/10 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(ya,{className:"w-8 h-8 text-[#1B4D3E]"})}),e.jsx(E,{className:"text-2xl",children:"Admin Login"}),e.jsx(te,{children:"Access the Hurricane Shutters Florida admin panel"})]}),e.jsx(C,{children:e.jsxs("form",{onSubmit:d,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(B,{htmlFor:"username",children:"Username"}),e.jsx(O,{id:"username",autoComplete:"username",required:!0,value:v.username,onChange:r=>a({...v,username:r.target.value}),placeholder:"Enter your username","data-testid":"admin-username-input"})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"password",children:"Password"}),e.jsx(O,{id:"password",type:"password",autoComplete:"current-password",required:!0,value:v.password,onChange:r=>a({...v,password:r.target.value}),placeholder:"Enter your password","data-testid":"admin-password-input"})]}),e.jsx(T,{type:"submit",className:"w-full bg-[#1B4D3E] hover:bg-[#163D32]",disabled:p.isPending,"data-testid":"admin-login-button",children:p.isPending?"Signing In...":"Sign In"})]})})]})})}function cn(){var J,Q,ne,M;const{toast:s}=re(),[n,t]=h.useState("today"),[l,o]=h.useState(""),[j,m]=h.useState(""),[g,v]=h.useState("1"),[a,p]=h.useState(!1);me();const d=U({mutationFn:P=>F("POST","/api/admin/send-weekly-summary",{weeksAgo:P}),onSuccess:(P,L)=>{s({title:"Weekly Summary Sent",description:`The ${L===0?"current week's":L===1?"last week's":`${L} weeks ago`} report was sent to the office.`}),p(!1)},onError:()=>{s({title:"Failed to Send",description:"Could not send the weekly summary. Please try again.",variant:"destructive"})}}),r=(()=>
57{if(n==="custom")return l&&j?`?from=${l}&to=${j}`:null;const P=new Date().toISOString().split("T")[0];if(n==="today")return`?from=${P}&to=${P}`;if(n==="yesterday"){const se=new Date;se.setDate(se.getDate()-1);const le=se.toISOString().split("T")[0];return`?from=${le}&to=${le}`}const L=parseInt(n),W=new Date;return W.setDate(W.getDate()-L),`?from=${W.toISOString().split("T")[0]}&to=${P}`})(),w=n==="custom"&&(!l||!j),{data:y,isLoading:f}=z({queryKey:["/api/admin/analytics/summary",n,l,j],queryFn:async()=>(await fetch(`/api/admin/analytics/summary${r}`,{credentials:"include"})).json(),enabled:!w}),{data:A=[]}=z({queryKey:["/api/customers"]}),c=P=>{const L=A.find(W=>W.id===P);return L?`${L.firstName} ${L.lastName}`:"Unknown"},R=P=>{const L=A.find(W=>W.id===P);return(L==null?void 0:L.phone)||"N/A"},I=P=>`$${(P||0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between mb-6 gap-4",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Dashboard"}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs(Ae,{open:a,onOpenChange:p,children:[e.jsx(Qs,{asChild:!0,children:e.jsxs(T,{variant:"outline",size:"sm",className:"flex items-center gap-2",children:[e.jsx(Ye,{className:"w-4 h-4"}),"Send Weekly Report"]})}),e.jsxs(Pe,{className:"sm:max-w-md",children:[e.jsxs(qe,{children:[e.jsx(Ee,{children:"Send Weekly Summary Report"}),e.jsx(Oe,{children:"Send the weekly activity report email to the office. Choose which week to include."})]}),e.jsxs("div",{className:"py-4",children:[e.jsx(B,{className:"mb-2 block",children:"Which week?"}),e.jsxs(ie,{value:g,onValueChange:v,children:[e.jsx(ce,{children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(k,{value:"0",children:"This week (Mon–today)"}),e.jsx(k,{value:"1",children:"Last week"}),e.jsx(k,{value:"2",children:"2 weeks ago"}),e.jsx(k,{value:"3",children:"3 weeks ago"})]})]})]}),e.jsxs(ns,{children:[e.jsx(T,{variant:"outline",onClick:()=>p(!1),children:"Cancel"}),e.jsxs(T,{onClick:()=>d.mutate(parseInt(g)),disabled:d.isPending,className:"flex items-center gap-2",children:[d.isPending?e.jsx(je,{className:"w-4 h-4 animate-spin"}):e.jsx(Ye,{className:"w-4 h-4"}),d.isPending?"Sending…":"Send Report"]})]})]})]}),e.jsxs(ie,{value:n,onValueChange:t,children:[e.jsx(ce,{className:"w-40",children:e.jsx(oe,{placeholder:"Date Range"})}),e.jsxs(de,{children:[e.jsx(k,{value:"today",children:"Today"}),e.jsx(k,{value:"yesterday",children:"Yesterday"}),e.jsx(k,{value:"7",children:"Last 7 Days"}),e.jsx(k,{value:"30",children:"Last 30 Days"}),e.jsx(k,{value:"90",children:"Last 90 Days"}),e.jsx(k,{value:"365",children:"Last Year"}),e.jsx(k,{value:"custom",children:"Custom Range"})]})]}),n==="custom"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{type:"date",value:l,onChange:P=>o(P.target.value),className:"w-36"}),e.jsx("span",{children:"to"}),e.jsx(O,{type:"date",value:j,onChange:P=>m(P.target.value),className:"w-36"})]})]})]}),w?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Rs,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{className:"font-medium",children:"Select both start and end dates"}),e.jsx("p",{className:"text-sm",children:"Choose a date range to view your dashboard metrics"})]}):f?e.jsx("div",{className:"text-center py-8",children:"Loading dashboard..."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid md:grid-cols-4 gap-4 mb-6",children:[e.jsx(S,{className:"border-l-4 border-l-[#1B4D3E]",children:e.jsxs(C,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Quotes Collected"}),e.jsx("p",{className:"text-3xl font-bold text-[#1B4D3E]",children:(y==null?void 0:y.quotesCollected)||0})]}),e.jsx($e,{className:"w-8 h-8 text-[#1B4D3E]/30"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["+",(y==null?void 0:y.todayCollected)||0," today"]})]})}),e.jsx(S,{className:"border-l-4 border-l-green-500",children:e.jsxs(C,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Converted to Orders"}),e.jsx("p",{className:"text-3xl font-bold text-green-600",children:(y==null?void 0:y.quotesConverted)||0})]}),e.jsx(pa,{className:"w-8 h-8 text-green-500/30"})]}),e.jsxs("p",{className:"text-xs text-green-600 mt-1",children:[(y==null?void 0:y.conversionRate)||0,"% conversion rate"]})]})}),e.jsx(S,{className:"border-l-4 border-l-blue-500",children:e.jsxs(C,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Quoted Value (Not Revenue)"}),e.jsx("p",{className:"text-2xl font-bold text-blue-600",children:I(y==null?void 0:y.revenueFromQuotes)})]}),e.jsx(Le,{className:"w-8 h-8 text-blue-500/30"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Total value of quotes"})]})}),e.jsx(S,{className:"border-l-4 border-l-emerald-500",children:e.jsxs(C,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Order Revenue"}),e.jsx("p",{className:"text-2xl font-bold text-emerald-600",children:I(y==null?void 0:y.revenueFromOrders)})]}),e.jsx(ze,{className:"w-8 h-8 text-emerald-500/30"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Actual sales closed"})]})})]}),e.jsx(gn,{dateParams:r}),e.jsxs("div",{className:"grid md:grid-cols-3 gap-6 mb-6",children:[e.jsxs(S,{className:"md:col-span-2",children:[e.jsxs(q,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(Te,{className:"w-5 h-5 text-[#C25B2B]"}),"Today's Follow-Ups"]}),e.jsxs(K,{variant:"destructive",className:"text-sm",children:[(y==null?void 0:y.followUpsToday)||0," pending"]})]}),e.jsx(te,{children:"Customers scheduled for follow-up today or overdue"})]}),e.jsx(C,{children:(((J=y==null?void 0:y.followUpsList)==null?void 0:J.length)||0)===0?e.jsxs("div",{className:"text-center py-6 text-muted-foreground",children:[e.jsx(Rs,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"No follow-ups scheduled for today"})]}):e.jsx("div",{className:"space-y-2",children:(Q=y==null?void 0:y.followUpsList)==null?void 0:Q.map(P=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-orange-50 rounded-lg border border-orange-100",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:c(P.customerId)}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[P.quoteNumber," • ",I(parseFloat(P.totalCost||0))]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("a",{href:`tel:${R(P.customerId)}`,className:"bg-[#1B4D3E] text-white px-3 py-1 rounded text-sm hover:bg-[#163D32] flex items-center gap-1",children:[e.jsx(Te,{className:"w-3 h-3"})," Call"]})})]},P.id))})})]}),e.jsxs(S,{children:[e.jsx(q,{className:"pb-3",children:e.jsx(E,{children:"Qu
57ick Actions"})}),e.jsxs(C,{className:"space-y-2",children:[e.jsxs(T,{variant:"outline",className:"w-full justify-start h-12 text-left",children:[e.jsx(Ne,{className:"w-5 h-5 mr-3 text-[#1B4D3E]"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"New Leads"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(y==null?void 0:y.newLeadsNeedingContact)||0," need contact"]})]})]}),e.jsxs(T,{variant:"outline",className:"w-full justify-start h-12 text-left",children:[e.jsx(as,{className:"w-5 h-5 mr-3 text-orange-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Abandoned Carts"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(y==null?void 0:y.abandonedCarts)||0," to recover"]})]})]}),e.jsxs(T,{variant:"outline",className:"w-full justify-start h-12 text-left",children:[e.jsx($e,{className:"w-5 h-5 mr-3 text-blue-500"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Pending Orders"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(y==null?void 0:y.pendingOrders)||0," to process"]})]})]})]})]})]}),e.jsxs(S,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"w-5 h-5 text-[#1B4D3E]"}),"New Leads Needing Contact"]}),e.jsx(K,{className:"bg-[#1B4D3E]",children:(y==null?void 0:y.newLeadsNeedingContact)||0})]}),e.jsx(te,{children:"Recently saved quotes that haven't been contacted yet"})]}),e.jsx(C,{children:(((ne=y==null?void 0:y.newLeadsList)==null?void 0:ne.length)||0)===0?e.jsxs("div",{className:"text-center py-6 text-muted-foreground",children:[e.jsx(Ne,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"All leads have been contacted"})]}):e.jsx("div",{className:"grid md:grid-cols-2 gap-3",children:(M=y==null?void 0:y.newLeadsList)==null?void 0:M.map(P=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-blue-50 rounded-lg border border-blue-100",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:c(P.customerId)}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[P.quoteNumber," • ",I(parseFloat(P.totalCost||0))]}),e.jsx("p",{className:"text-xs text-blue-600",children:new Date(P.createdAt).toLocaleDateString()})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("a",{href:`tel:${R(P.customerId)}`,className:"bg-[#1B4D3E] text-white px-3 py-1 rounded text-sm hover:bg-[#163D32] flex items-center gap-1",children:[e.jsx(Te,{className:"w-3 h-3"})," Call"]})})]},P.id))})})]})]})]})}function on(){const[s,n]=h.useState(""),[t,l]=h.useState(null),[o,j]=h.useState(!1),[m,g]=h.useState(null),{toast:v}=re(),{data:a}=z({queryKey:["/api/admin/promo-blast-status"],refetchInterval:3e4}),{data:p=[],isLoading:d}=z({queryKey:["/api/admin/discount-signups"]}),x=U({mutationFn:async({id:c,status:R})=>await F("PATCH",`/api/admin/discount-signups/${c}/status`,{status:R}),onSuccess:()=>{We.invalidateQueries({queryKey:["/api/admin/discount-signups"]}),v({title:"Status updated"})},onError:c=>v({title:"Update failed",description:c==null?void 0:c.message,variant:"destructive"})}),r=U({mutationFn:async c=>await F("DELETE",`/api/admin/discount-signups/${c}`),onSuccess:()=>{We.invalidateQueries({queryKey:["/api/admin/discount-signups"]}),l(null),v({title:"Entry deleted"})},onError:c=>v({title:"Delete failed",description:c==null?void 0:c.message,variant:"destructive"})}),w=U({mutationFn:async()=>await F("POST","/api/admin/queue-promo-blast",{}),onSuccess:c=>{j(!1),g({queued:c.queued,durationMinutes:c.durationMinutes,code:c.code}),v({title:`Blast queued — ${c.queued} emails scheduled`,description:`Sending over ~${c.durationMinutes} min via the production queue.`})},onError:c=>{j(!1),v({title:"Blast failed",description:String((c==null?void 0:c.message)||c),variant:"destructive"})}}),y=U({mutationFn:async()=>await F("POST","/api/admin/cancel-promo-blast",{}),onSuccess:c=>{g(null),We.invalidateQueries({queryKey:["/api/admin/promo-blast-status"]}),v({title:`Blast stopped — ${c.cancelled} pending emails cancelled`,variant:"destructive"})},onError:c=>{v({title:"Stop failed",description:String((c==null?void 0:c.message)||c),variant:"destructive"})}}),f=c=>new Date(c).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),A=s?p.filter(c=>{var R,I,J,Q;return((R=c.firstName)==null?void 0:R.toLowerCase().includes(s.toLowerCase()))||((I=c.lastName)==null?void 0:I.toLowerCase().includes(s.toLowerCase()))||((J=c.email)==null?void 0:J.toLowerCase().includes(s.toLowerCase()))||((Q=c.phone)==null?void 0:Q.includes(s))}):p;return e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"Entry Pop-up Sign Up"}),e.jsx(S,{className:"mb-6 border-orange-200 bg-orange-50",children:e.jsx(C,{className:"p-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-orange-800 flex items-center gap-2",children:"📣 Promo Blast — APRIL5 (5% off, expires June 1)"}),e.jsx("p",{className:"text-sm text-orange-700 mt-1",children:"Queues a staggered blast (40 s between sends) to all eligible subscribers + saved-quote leads, excluding purchased / not_interested / unsubscribed. The production email queue handles delivery automatically."}),m&&e.jsxs("p",{className:"text-sm font-medium text-green-700 mt-2",children:["✅ ",m.queued," emails queued with code ",e.jsx("strong",{children:m.code})," — delivering over ~",m.durationMinutes," min"]}),a&&a.total>0&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-green-100 px-3 py-1 text-sm font-medium text-green-800",children:["✅ ",a.sent," sent"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-orange-100 px-3 py-1 text-sm font-medium text-orange-800",children:["⏳ ",a.pending," pending"]}),a.failed>0&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-red-100 px-3 py-1 text-sm font-medium text-red-800",children:["❌ ",a.failed," failed/cancelled"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-gray-100 px-3 py-1 text-sm font-medium text-gray-600",children:[a.sent," / ",a.total," total"]}),a.nextScheduledAt&&a.pending>0&&e.jsxs("span",{className:"text-xs text-orange-600 self-center",children:["Next: ",new Date(a.nextScheduledAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]}),e.jsxs("div",{className:"flex gap-2 items-center flex-shrink-0 flex-wrap justify-end",children:[m&&e.jsx(T,{variant:"outline",className:"border-red-400 text-red-600 hover:bg-red-50",onClick:()=>y.mutate(),disabled:y.isPending,children:y.isPending?"Stopping…":"⛔ Stop Blast"}),o?e.jsxs("div",{className:"flex items-center gap-2 border border-orange-400 rounded-md p-2 bg-white",children:[e.jsx("span",{className:"text-sm font-medium text-orange-800",children:"Send to all ~195 recipients?"}),e.jsx(T,{size:"sm",className:"bg-orange-600 hover:bg-orange-700 text-white",onClick:()=>w.mutate(),disabled:w.isPending,children:w.isPending?"Queuing…":"Yes, Send"}),e.jsx(T,{size:"sm",variant:"outline",onClick:()=>j(!1),children:"Cancel"})]}):e.jsx(T,{variant:"default",className:"bg-orange-600 hover:bg-orange-700 text-white",onClick:()=>j(!0),disabled:!!m,children:m?"Blast Sent ✓":"Launch Promo Blast"})]})]})})}),e.jsx(S,{children:e.jsxs(C,{className:"p-6",children:[e.jsxs("div",{className:"flex flex-wrap justify-between items-center gap-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Show"}),e.jsxs(ie,{defaultValue:"10",children:[e.jsx(ce,{className:"w-20",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(k,{value:"10",children:"10"}),e.jsx(k,{value:"25",children:"25"}),e.jsx(k,{value:"50",children:"50"})]})]}),e.jsx("span",{children:"entries"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(T,{variant:"outline",size:"sm",className:"bg-[#1B4D3E] text-white hover:bg-[#163D32]",onClick:()=>window.open("/api/admin/discount-signups/export.csv","_blank"),"data-testid":"export-signups-csv",children:[e.jsx(rs,{className:"w-4 h-4 mr-2"})," Export CSV"]}),e.jsx("span",{children:"Search:"}),e.jsx(O,{className:"w-48",value:s,onChange:c=>n(c.target.value)})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"ID"}),e.jsx(N,{children:"Name"}),e.jsx(N,{children:"Phone"}),e.jsx(N,{children:"Email"}),e.jsx(N,{children:"Source"}),e.jsx(N,{children:"Status"}),e.jsx(N,{children:"Date"}),e.jsx(N,{})]})}),e.jsx(X,{children:d?e.jsx(D,{children:e.jsx(u,{colSpan:8,className:"text-center py-8",children:"Loading..."})}):A.length===0?e.jsx(D,{children:e.jsx(u,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"No sign ups yet. Users will appear here when they sign up through the entry pop-up."})}):A.map((c,R)=>e.jsxs(D,{children:[e.jsx(u,{children:R+1}),e.jsxs(u,{children:[c.firstName," ",c.lastName||""]}),e.jsx(u,{children:c.phone||"N/A"}),e.jsx(u,{className:"text-[#C25B2B]",children:c.email}),e.jsx(u,{children:e.jsx("span",{className:`px-2 py-1 rounded text-xs ${c.source==="quote_abandon_popup"?"bg-orange-100 text-orange-700":c.source==="promo_popup"?"bg-blue-100 text-blue-700":"bg-gray-100 text-gray-700"}`,children:c.source==="quote_abandon_popup"?"Quote Abandon":c.source==="promo_popup"?"Welcome Popup":c.source||"Popup"})}),e.jsx(u,{children:c._origin==="lead"?e.jsx("span",{className:`px-2 py-1 rounded text-xs ${c.status==="purchased"?"bg-green-100 text-green-700":c.status==="not_interested"?"bg-red-100 text-red-700":"bg-gray-100 text-gray-700"}`,title:"This person is also a lead — set status from the Leads pipeline",children:c.status==="purchased"?"✅ Purchased (Lead)":c.status==="not_interested"?"🚫 Not Interested (Lead)":c.status==="unsubscribed"?"🔕 Unsubscribed (Lead)":c.status==="in_quote_funnel"?"📨 In Quote Funnel (Lead)":"📧 Subscribed (Lead)"}):e.jsxs(ie,{value:c.status||"subscribed",onValueChange:I=>x.mutate({id:c.id,status:I}),children:[e.jsx(ce,{className:"w-40 h-8 text-xs","data-testid":`select-status-${c.id}`,children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(k,{value:"subscribed",children:"📧 Subscribed"}),e.jsx(k,{value:"in_quote_funnel",children:"📨 In Quote Funnel"}),e.jsx(k,{value:"purchased",children:"✅ Purchased"}),e.jsx(k,{value:"not_interested",children:"🚫 Not Interested"}),e.jsx(k,{value:"unsubscribed",children:"🔕 Unsubscribed"})]})]})}),e.jsx(u,{children:f(c.createdAt)}),e.jsx(u,{children:t===c.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>r.mutate(c.id),disabled:r.isPending,className:"px-2 py-1 text-xs bg-red-600 text-white rounded hover:bg-red-700 disabled:opacity-50",children:r.isPending?"...":"Confirm"}),e.jsx("button",{onClick:()=>l(null),className:"px-2 py-1 text-xs bg-gray-200 text-gray-700 rounded hover:bg-gray-300",children:"Cancel"})]}):e.jsx("button",{onClick:()=>l(c.id),className:"p-1 text-gray-400 hover:text-red-600 rounded",title:"Delete entry",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),e.jsx("path",{d:"M10 11v6"}),e.jsx("path",{d:"M14 11v6"}),e.jsx("path",{d:"M9 6V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"})]})})})]},c.id))})]})}),e.jsx("div",{className:"flex justify-between items-center mt-4 text-sm text-muted-foreground",children:e.jsx("span",{children:A.length===0?"N
57o entries found":`Showing 1 to ${A.length} of ${p.length} entries`})})]})})]})}function dn(){var Q,ne,M,P,L,W,se,le,ae;const[s,n]=h.useState(null),[t,l]=h.useState(!1),[o,j]=h.useState(""),[m,g]=h.useState("new"),[v,a]=h.useState(""),[p,d]=h.useState(""),x=me(),{toast:r}=re(),{data:w=[],isLoading:y}=z({queryKey:["/api/admin/abandoned-carts"]}),f=U({mutationFn:async({id:b,_type:$,contactStatus:H,crmNotes:_,followUpDate:ue})=>$==="lead"?F("PATCH",`/api/admin/leads/${b}/crm`,{contactStatus:H,crmNotes:_,followUpDate:ue}):F("PATCH",`/api/admin/quotes/${b}/crm`,{contactStatus:H,crmNotes:_,followUpDate:ue}),onSuccess:b=>{x.invalidateQueries({queryKey:["/api/admin/abandoned-carts"]}),n($=>$&&{...$,contactStatus:b.contactStatus,crmNotes:b.crmNotes,followUpDate:b.followUpDate}),r({title:"CRM Updated",description:"Contact information has been saved."})},onError:b=>{r({title:"Save Failed",description:(b==null?void 0:b.message)||"Could not save CRM changes. Please try again.",variant:"destructive"})}}),A=b=>new Date(b).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),c=b=>{n(b),j(b.crmNotes||""),g(b.contactStatus||"new"),a(b.followUpDate?new Date(b.followUpDate).toISOString().split("T")[0]:""),l(!0)},R=()=>{s&&f.mutate({id:s.id,_type:s._type,contactStatus:m,crmNotes:o,followUpDate:v||void 0})},I=p?w.filter(b=>{var $,H,_,ue,Re,Fe;return`${($=b.customer)==null?void 0:$.firstName} ${(H=b.customer)==null?void 0:H.lastName}`.toLowerCase().includes(p.toLowerCase())||((ue=(_=b.customer)==null?void 0:_.email)==null?void 0:ue.toLowerCase().includes(p.toLowerCase()))||((Fe=(Re=b.customer)==null?void 0:Re.phone)==null?void 0:Fe.includes(p))}):w,J=()=>{window.open("/api/admin/abandoned-carts/export.csv","_blank")};return e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"View Abandon Cart"}),e.jsx(S,{children:e.jsxs(C,{className:"p-6",children:[e.jsxs("div",{className:"flex flex-wrap justify-between gap-2 mb-4",children:[e.jsxs(T,{variant:"outline",className:"bg-[#1B4D3E] text-white hover:bg-[#163D32]",onClick:J,"data-testid":"export-carts-csv",children:[e.jsx(rs,{className:"w-4 h-4 mr-2"})," Export CSV"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Search:"}),e.jsx(O,{className:"w-56",placeholder:"Name, email, phone…",value:p,onChange:b=>d(b.target.value)})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Sr. No."}),e.jsx(N,{children:"Name"}),e.jsx(N,{children:"Email"}),e.jsx(N,{children:"Date"}),e.jsx(N,{children:"Order Detail"})]})}),e.jsx(X,{children:y?e.jsx(D,{children:e.jsx(u,{colSpan:5,className:"text-center py-8",children:"Loading..."})}):I.length===0?e.jsx(D,{children:e.jsx(u,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:p?"No results match your search.":"No abandoned carts found."})}):I.map((b,$)=>{var H,_,ue;return e.jsxs(D,{children:[e.jsx(u,{children:$+1}),e.jsx(u,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(T,{variant:"link",className:"text-foreground hover:text-[#C25B2B] p-0 font-normal",onClick:()=>c(b),children:[(H=b.customer)==null?void 0:H.firstName," ",((_=b.customer)==null?void 0:_.lastName)||"Unknown"]}),b._type==="lead"&&e.jsx(K,{variant:"outline",className:"text-xs border-amber-500 text-amber-600",children:"Email Lead"})]})}),e.jsx(u,{className:"text-[#C25B2B]",children:((ue=b.customer)==null?void 0:ue.email)||"N/A"}),e.jsx(u,{children:A(b.createdAt)}),e.jsx(u,{children:e.jsx(T,{variant:"link",className:"text-[#C25B2B] p-0",onClick:()=>c(b),children:b._type==="lead"?"Lead Details":"Order Details"})})]},b.id)})})]})})]})}),e.jsx(Ae,{open:t,onOpenChange:l,children:e.jsxs(Pe,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(qe,{children:[e.jsxs(Ee,{className:"text-xl flex items-center gap-2",children:[(s==null?void 0:s._type)==="lead"?"Email Lead Details":`Quote Details - ${(s==null?void 0:s.quoteNumber)||((Q=s==null?void 0:s.id)==null?void 0:Q.slice(0,8))}`,(s==null?void 0:s._type)==="lead"&&e.jsx(K,{variant:"outline",className:"text-xs border-amber-500 text-amber-600",children:"Email Lead"})]}),e.jsx(Oe,{children:(s==null?void 0:s._type)==="lead"?"Lead captured from quote wizard — no quote saved yet":"View quote details and manage customer contact"})]}),s&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs(S,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Ks,{className:"w-4 h-4"})," Customer Information"]})}),e.jsxs(C,{className:"space-y-2 text-sm",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Name:"})," ",(ne=s.customer)==null?void 0:ne.firstName," ",(M=s.customer)==null?void 0:M.lastName]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Email:"})," ",e.jsx("a",{href:`mailto:${(P=s.customer)==null?void 0:P.email}`,className:"text-[#C25B2B]",children:(L=s.customer)==null?void 0:L.email})]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Phone:"})," ",e.jsx("a",{href:`tel:${(W=s.customer)==null?void 0:W.phone}`,className:"text-[#C25B2B]",children:(se=s.customer)==null?void 0:se.ph
57one})]})]})]}),e.jsxs(S,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[s._type==="lead"?e.jsx(ve,{className:"w-4 h-4"}):e.jsx(Le,{className:"w-4 h-4"}),s._type==="lead"?"Email Sequence":"Quote Summary"]})}),e.jsx(C,{className:"space-y-2 text-sm",children:s._type==="lead"?e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Abandon Email Step:"})," ",s.abandonSequenceStep??0," of 4"]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Automation:"})," ",e.jsx(K,{variant:"outline",className:"capitalize",children:s.automationStatus||"active"})]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Captured:"})," ",A(s.createdAt)]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Status:"})," ",e.jsx(K,{variant:"outline",children:s.status})]}),e.jsxs("p",{className:"text-lg font-bold",children:[e.jsx("span",{className:"font-medium",children:"Total:"})," $",parseFloat(s.totalCost||0).toFixed(2)]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Created:"})," ",A(s.createdAt)]})]})})]})]}),s._type!=="lead"&&e.jsx(Vt,{quoteId:s.id}),s._type!=="lead"&&e.jsxs(S,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(E,{className:"text-base",children:["Line Items (",((le=s.lineItems)==null?void 0:le.length)||0,")"]})}),e.jsx(C,{children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Product"}),e.jsx(N,{children:"Opening Size"}),e.jsx(N,{children:"Finished Size"}),e.jsx(N,{children:"Color"}),e.jsx(N,{children:"Track"}),e.jsx(N,{children:"Motor"}),e.jsx(N,{children:"Qty"}),e.jsx(N,{className:"text-right",children:"Shutter"}),e.jsx(N,{className:"text-right",children:"Motor $"}),e.jsx(N,{className:"text-right",children:"Total"})]})}),e.jsx(X,{children:(ae=s.lineItems)==null?void 0:ae.map(b=>e.jsxs(D,{children:[e.jsxs(u,{className:"font-medium",children:[e.jsx("div",{children:b.productName}),(()=>{const $={"40mm":"40MM (Impact)","44mm":"44MM (Non-Impact)","44mm-er":"44MM ER (Impact)","55mm-er":"55MM ER (Impact)","63mm":"63MM"},H={mill:"Mill .050 Aluminum",white:"White .050 Aluminum",clear:"Clear Polycarbonate",steel:"24 Gauge Steel"},_=[];return b.productType==="rolling"&&b.shutterType&&_.push(`Type: ${$[b.shutterType]||b.shutterType.toUpperCase()}`),b.productType==="storm"&&(_.push(`Material: ${H[(b.color||"").toLowerCase()]||b.color}`),b.clearPanels>0&&_.push(`Clear Panels: ${b.clearPanels}`)),b.productType==="accordion"&&b.clearBlades>0&&_.push(`Clear Blades: ${b.clearBlades}`),_.length?e.jsx("div",{className:"text-xs text-primary mt-1 font-normal",children:_.join(" · ")}):null})()]}),e.jsxs(u,{children:[b.openingWidth,'" × ',b.openingHeight,'"']}),e.jsx(u,{children:b.finishedWidth&&b.finishedHeight?`${parseFloat(b.finishedWidth).toFixed(2)}" × ${parseFloat(b.finishedHeight).toFixed(2)}"`:"—"}),e.jsx(u,{className:"capitalize",children:b.color}),e.jsx(u,{children:b.productType==="storm"?b.addHeaderTrack?"Yes":"No":"—"}),e.jsx(u,{children:b.productType==="rolling"?e.jsx("span",{className:"capitalize",children:b.motorType}):"—"}),e.jsx(u,{children:b.quantity}),e.jsxs(u,{className:"text-right",children:["$",parseFloat(b.shutterCost||0).toFixed(2)]}),e.jsx(u,{className:"text-right",children:b.productType==="rolling"?`$${parseFloat(b.motorCost||0).toFixed(2)}`:"—"}),e.jsxs(u,{className:"text-right font-semibold",children:["$",parseFloat(b.lineTotalCost||0).toFixed(2)]})]},b.id))})]})})]}),e.jsxs(S,{className:"border-[#1B4D3E]",children:[e.jsx(q,{className:"pb-2 bg-[#1B4D3E]/5",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Te,{className:"w-4 h-4"})," CRM - Contact Management"]})}),e.jsxs(C,{className:"pt-4 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(B,{children:"Contact Status"}),e.jsxs(ie,{value:m,onValueChange:g,children:[e.jsx(ce,{children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(k,{value:"new",children:"New - Not Contacted"}),e.jsx(k,{value:"contacted",children:"Contacted"}),e.jsx(k,{value:"voicemail_left",children:"Voicemail Left"}),e.jsx(k,{value:"no_response",children:"No Response"}),e.jsx(k,{value:"follow_up",children:"Follow Up Needed"}),e.jsx(k,{value:"closed_won",children:"Closed - Won"}),e.jsx(k,{value:"closed_lost",children:"Closed - Lost"})]})]})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Follow Up Date"}
57),e.jsx(O,{type:"date",value:v,onChange:b=>a(b.target.value)})]})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Notes"}),e.jsx(Be,{placeholder:"Add notes about customer contact, preferences, etc...",value:o,onChange:b=>j(b.target.value),className:"min-h-[100px]"})]}),e.jsx(T,{onClick:R,className:"bg-[#1B4D3E] hover:bg-[#163D32]",disabled:f.isPending,children:f.isPending?"Saving...":"Save CRM Changes"}),s._type!=="lead"&&e.jsxs(T,{variant:"outline",className:"ml-3",onClick:async()=>{var b,$;try{const H=await F("POST",`/api/admin/quotes/${s.id}/resend-notifications`);r({title:"Notifications Sent",description:`Office: ${((b=H.results)==null?void 0:b.office)||"N/A"} | Customer: ${(($=H.results)==null?void 0:$.customer)||"N/A"}`})}catch{r({title:"Failed to resend notifications",variant:"destructive"})}},children:[e.jsx(ve,{className:"w-4 h-4 mr-2"})," Resend Notifications"]})]})]}),s._type==="lead"?e.jsx(ss,{leadId:s.id}):e.jsx(ss,{quoteId:s.id})]})]})})]})}function ss({quoteId:s,leadId:n}){const t=me(),{toast:l}=re(),o=!!n&&!s,j=o?`/api/admin/leads/${n}/email-automation`:`/api/admin/quotes/${s}/email-automation`,m=o?["/api/admin/leads",n,"email-automation"]:["/api/admin/quotes",s,"email-automation"],{data:g,isLoading:v,isError:a}=z({queryKey:m,queryFn:async()=>{const r=await fetch(j,{credentials:"include"});if(!r.ok)throw new Error("Failed to load email automation status");return r.json()}}),p=()=>{t.invalidateQueries({queryKey:m}),t.invalidateQueries({queryKey:["/api/admin/abandoned-carts"]})},d=U({mutationFn:async()=>o?F("POST",`/api/admin/leads/${n}/stop-automation`,{}):F("POST",`/api/admin/quotes/${s}/email-automation/stop`,{}),onSuccess:()=>{p(),l({title:"Email drip stopped",description:"No further automated emails will be sent to this customer."})},onError:r=>l({title:"Could not stop drip",description:r==null?void 0:r.message,variant:"destructive"})}),x=U({mutationFn:async()=>o?F("POST",`/api/admin/leads/${n}/resume-automation`,{}):F("POST",`/api/admin/quotes/${s}/email-automation/resume`,{}),onSuccess:()=>{p(),l({title:"Email drip resumed",description:"Automated emails will continue per the schedule."})},onError:r=>l({title:"Could not resume drip",description:r==null?void 0:r.message,variant:"destructive"})});return e.jsxs(S,{className:"border-amber-300",children:[e.jsx(q,{className:"pb-2 bg-amber-50",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(ve,{className:"w-4 h-4"})," Customer Email Drip Automation"]})}),e.jsx(C,{className:"pt-4 space-y-3",children:v?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}):a?e.jsx("p",{role:"alert",className:"text-sm text-red-700",children:"Email automation status could not be loaded. Do not assume reminders are stopped. Reload to check again."}):g!=null&&g.hasLead?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm",children:[e.jsx("span",{className:"font-medium",children:"Status:"}),e.jsx(K,{variant:"outline",className:g.automationStatus==="stopped"?"bg-red-50 text-red-700 border-red-300":g.automationStatus==="paused"?"bg-amber-50 text-amber-700 border-amber-300":"bg-green-50 text-green-700 border-green-300",children:g.automationStatus==="stopped"?"Stopped":g.automationStatus==="paused"?"Paused":"Active"}),g.emailOptOut&&e.jsx(K,{variant:"outline",className:"bg-red-50 text-red-700 border-red-300",children:"Unsubscribed"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsx("p",{children:"This history covers the customer across quotes, not just this order. Initial order notifications are separate."}),(g.abandonSequenceStep??0)>0&&e.jsxs("p",{children:["Abandon sequence: step ",g.abandonSequenceStep]}),(g.savedSequenceStep??0)>0&&e.jsxs("p",{children:["Saved-quote sequence: step ",g.savedSequenceStep]}),g.lastEmailSentAt&&e.jsxs("p",{children:["Last customer drip email recorded: ",new Date(g.lastEmailSentAt).toLocaleString()]})]}),e.jsx("div",{className:"flex gap-2 pt-1",children:g.automationStatus!=="stopped"?e.jsx(T,{variant:"outline",size:"sm",className:"border-red-300 text-red-700 hover:bg-red-50",onClick:()=>d.mutate(),disabled:d.isPending,"data-testid":"stop-email-drip",children:d.isPending?"Stopping…":"Stop Email Drip"}):e.jsx(T,{variant:"outline",size:"sm",className:"border-green-300 text-green-700 hover:bg-green-50",onClick:()=>x.mutate(),disabled:x.isPending,"data-testid":"resume-email-drip",children:x.isPending?"Resuming…":"Resume Email Drip"})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No email lead was found for this customer. This does not confirm delivery of order notifications."})})]})}function xn(){var ws,Ss,Cs,ks,Ts,Ds,As,Ps,qs,Es;const[s,n]=h.useState("all"),[t,l]=h.useState(""),[o,j]=h.useState(""),[m,g]=h.useState(""),[v,a]=h.useState(""),[p,d]=h.useState(1),[x,r]=h.useState(10),[w,y]=h.useState("createdAt"),[f,A]=h.useState("desc"),[c,R]=h.useState(null),[I,J]=h.useState(!1),[Q,ne]=h.useState(""),[M,P]=h.useState("new"),[L,W]=h.useState(""),[se,le]=h.useState(!1),ae=me(),{toast:b}=re(),H=`/api/admin/orders?${new URLSearchParams({status:s,search:t,page:String(p),limit:String(x),sortBy:w,sortOrder:f,...m?{from:m}:{},...v?{to:v}:{}}).toString()}`,{data:_,isLoading:ue}=z({queryKey:[H]});h.useEffect(()=>{le(localStorage.getItem("admin_notify_new_orders")==="1")},[]),h.useEffect(()=>{if(!se||typeof window>"u"||!("Notification"in window))return;let i=new Date().toISOString();const he=setInterval(async()=>{try{const G=await fetch(`/api/admin/orders/new-count?since=${encodeURIComponent(i)}`,{credentials:"include"});if(!G.ok)return;const Ce=await G.json();Ce.count>0&&(Ce.latest.forEach(ke=>{try{new Notification(`New order ${ke.orderNumber||""}`.trim(),{body:`${ke.customer||"Customer"} — $${parseFloat(ke.totalCost||"0").toFixed(2)}`})}catch{}}),i=new Date().toISOString(),ae.invalidateQueries({queryKey:[H]}))}catch{}},6e4);return()=>clearInterval(he)},[se,H,ae]);const Re=async()=>
57{if(!("Notification"in window)){b({title:"Not supported",description:"This browser does not support notifications.",variant:"destructive"});return}if(se)localStorage.removeItem("admin_notify_new_orders"),le(!1),b({title:"Notifications disabled"});else{if(await Notification.requestPermission()!=="granted"){b({title:"Permission denied",description:"Enable notifications in your browser settings.",variant:"destructive"});return}localStorage.setItem("admin_notify_new_orders","1"),le(!0),b({title:"Notifications enabled",description:"You'll get a desktop alert for new orders."})}},Fe=()=>{const i=new URLSearchParams({status:s,search:t,...m?{from:m}:{},...v?{to:v}:{}});window.open(`/api/admin/orders/export.csv?${i.toString()}`,"_blank")},ye=i=>{w===i?A(f==="asc"?"desc":"asc"):(y(i),A("desc")),d(1)},we=i=>w!==i?"":f==="asc"?" ▲":" ▼",fs=()=>{l(o),d(1)},_e=i=>Array.isArray(i.queryKey)&&typeof i.queryKey[0]=="string"&&i.queryKey[0].startsWith("/api/admin/orders"),Qt=U({mutationFn:async({id:i,status:ee})=>F("PATCH",`/api/admin/quotes/${i}/status`,{status:ee}),onSuccess:()=>{ae.invalidateQueries({predicate:_e}),ae.invalidateQueries({queryKey:["/api/quotes"]}),b({title:"Status Updated"})},onError:i=>{b({title:"Failed to update status",description:(i==null?void 0:i.message)||"Could not save the new status. Please try again.",variant:"destructive"})}}),Ke=U({mutationFn:async({id:i,contactStatus:ee,crmNotes:he,followUpDate:G})=>F("PATCH",`/api/admin/quotes/${i}/crm`,{contactStatus:ee,crmNotes:he,followUpDate:G}),onSuccess:i=>{ae.invalidateQueries({predicate:_e}),ae.invalidateQueries({queryKey:["/api/quotes"]}),R(ee=>ee&&{...ee,contactStatus:i.contactStatus,crmNotes:i.crmNotes,followUpDate:i.followUpDate}),b({title:"CRM Updated",description:"Contact information has been saved."})},onError:i=>{b({title:"Save Failed",description:(i==null?void 0:i.message)||"Could not save CRM changes. Please try again.",variant:"destructive"})}}),Ns=U({mutationFn:async i=>F("POST",`/api/admin/quotes/${i}/stop-emails`,{}),onSuccess:i=>{ae.invalidateQueries({predicate:_e}),i!=null&&i.alreadyStopped?b({title:"Already stopped",description:"Emails were already stopped for this customer."}):b({title:"Emails stopped",description:"No more automated emails will be sent to this customer."})},onError:i=>{b({title:"Could not stop emails",description:(i==null?void 0:i.message)||"Customer may not have been in an email sequence.",variant:"destructive"})}}),Kt=U({mutationFn:async i=>F("DELETE",`/api/quotes/${i}`),onSuccess:()=>{ae.invalidateQueries({predicate:_e}),ae.invalidateQueries({queryKey:["/api/quotes"]}),ae.invalidateQueries({queryKey:["/api/admin/analytics/summary"]}),b({title:"Quote Deleted",description:"The quote and associated data have been removed."})},onError:()=>{b({title:"Error",description:"Failed to delete quote.",variant:"destructive"})}}),He=i=>new Date(i).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),bs=(_==null?void 0:_.orders)||[],Se=(_==null?void 0:_.total)??bs.length,vs=(_==null?void 0:_.totalPages)??Math.max(1,Math.ceil(Se/x)),ys=bs,Ht=Se===0?0:(p-1)*x+1,Wt=Math.min(Se,p*x),Gt=i=>{R(i),ne(i.crmNotes||""),P(i.contactStatus||"new"),W(i.followUpDate?new Date(i.followUpDate).toISOString().split("T")[0]:""),J(!0)},Yt=()=>{c&&Ke.mutate({id:c.id,contactStatus:M,crmNotes:Q,followUpDate:L||void 0})};return e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"Order/Quotes"}),e.jsx(S,{className:"mb-6",children:e.jsxs(C,{className:"p-6",children:[e.jsxs("div",{className:"flex flex-wrap gap-4 items-end",children:[e.jsxs("div",{children:[e.jsx(B,{children:"From"}),e.jsx(O,{type:"date",className:"w-40",value:m,onChange:i=>{g(i.target.value),d(1)}})]}),e.jsxs("div",{children:[e.jsx(B,{children:"To"}),e.jsx(O,{type:"date",className:"w-40",value:v,onChange:i=>{a(i.target.value),d(1)}})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Status"}),e.jsxs(ie,{value:s,onValueChange:i=>{n(i),d(1)},children:[e.jsx(ce,{className:"w-40",children:e.jsx(oe,{placeholder:"Select Status"})}),e.jsxs(de,{children:[e.jsx(k,{value:"all",children:"All"}),e.jsx(k,{value:"saved",children:"Saved"}),e.jsx(k,{value:"checked_out",children:"Checked Out"}),e.jsx(k,{value:"purchased",children:"Purchased"}),e.jsx(k,{value:"shipped",children:"Shipped"}),e.jsx(k,{value:"not_interested",children:"Not Interested"})]})]})]}),e.jsx(T,{variant:se?"default":"outline",className:se?"bg-green-600 hover:bg-green-700 text-white":"",onClick:Re,"data-testid":"toggle-notifications",children:se?"🔔 Notifications On":"🔕 Enable Notifications"}),e.jsxs(T,{variant:"outline",className:"bg-[#1B4D3E] text-white hover:bg-[#163D32]",onClick:Fe,"data-testid":"export-orders-csv",children:[e.jsx(rs,{className:"w-4 h-4 mr-2"})," Export CSV"]})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-4",children:[{label:"All",value:"all"},{label:"Saved",value:"saved"},{label:"Checked Out",value:"checked_out"},{label:"Purchased",value:"purchased"},{label:"Shipped",value:"shipped"}].map(i=>e.jsx("button",{onClick:()=>{n(i.value),d(1)},className:`px-3 py-1 rounded-full text-xs font-medium border transition-colors ${s===i.value?"bg-[#1B4D3E] text-white border-[#1B4D3E]":"bg-white text-slate-700 border-slate-300 hover:bg-slate-50"}`,"data-testid":`chip-${i.value}`,children:i.label},i.value))})]})}),e.jsx(S,{children:e.jsxs(C,{className:"p-6",children:[e.jsxs("div",{className:"flex flex-wrap justify-between items-center gap-3 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Show"}),e.jsxs(ie,{value:String(x),onValueChange:i=>{r(parseInt(i)),d(1)},children:[e.jsx(ce,{className:"w-20",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(k,{value:"10",children:"10"}),e.jsx(k,{value:"25",children:"25"}),e.jsx(k,{value:"50",children:"50"}),e.jsx(k,{value:"100",children:"100"})]})]}),e.jsx("span",{children:"entries"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ja,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(O,{className:"pl-10 w-64",placeholder:"Search order#, name, email, phone…",value:o,onChange:i=>j(i.target.value),onKeyDown:i=>{i.key==="Enter"&&fs()},"data-testid":"orders-search"})]}),e.jsx(T,{size:"sm",variant:"outline",onClick:fs,children:"Search"}),t&&e.jsx(T,{size:"sm",variant:"ghost",onClick:()=>{j(""),l(""),d(1)},children:"Clear"})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{}),e.jsx(N,{children:"ID"}),e.jsxs(N,{className:"cursor-pointer select-none",onClick:()=>ye("name"),children:["Name",we("name")]}),e.jsxs(N,{className:"cursor-pointer select-none",onClick:()=>ye("email"),children:["Email",we("email")]}),e.jsx(N,{children:"Phone"}),e.jsxs(N,{className:"cursor-pointer select-none",onClick:()=>ye("createdAt"),children:["Date",we("createdAt")]}),e.jsxs(N,{className:"cursor-pointer select-none",onClick:()=>ye("total"),children:["Total",we("total")]}),e.jsx(N,{children:"Payment Method"}),e.jsxs(N,{className:"cursor-pointer select-none",onClick:()=>ye("status"),children:["Order Status",we("status")]}),e.jsx(N,{})]})}),e.jsx(X,{children:ue?e.jsx(D,{children:e.jsx(u,{colSpan:10,className:"text-center py-8",children:"Loading..."})}):ys.length===0?e.jsx(D,{children:e.jsx(u,{colSpan:10,className:"text-center py-8 text-muted-foreground",children:"No orders found."})}):ys.map(i=>{var ee,he,G,Ce;return e.jsxs(D,{children:[e.jsx(u,{children:e.jsx(ga,{className:"w-4 h-4 text-muted-foreground cursor-pointer"})}),e.jsx(u,{className:"font-mono text-sm",children:i.orderNumber||i.quoteNumber||i.id.slice(0,8)}),e.jsx(u,{children:e.jsxs(T,{variant:"link",className:"text-foreground hover:text-[#C25B2B] p-0 font-normal",onClick:()=>Gt(i),children:[(ee=i.customer)==null?void 0:ee.firstName," ",((he=i.customer)==null?void 0:he.lastName)||"Unknown"]})}),e.jsx(u,{className:"text-[#C25B2B]",children:((G=i.customer)==null?void 0:G.email)||"N/A"}),e.jsx(u,{children:((Ce=i.customer)==null?void 0:Ce.phone)||"N/A"}),e.jsx(u,{children:He(i.createdAt)}),e.jsxs(u,{className:"font-medium",children:["$",parseFloat(i.totalCost||i.totalAmount||"0").toFixed(2)]}),e.jsx(u,{children:i.paymentStatus==="profile_saved"?e.jsx(K,{variant:"outline",className:"bg-green-50 text-green-700 border-green-300",children:"Secured"}):i.orderId?e.jsx(K,{variant:"outline",className:"bg-amber-50 text-amber-700 border-amber-300",children:"Waiting for customer"}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not collected"})}),e.jsx(u,{children:e.jsxs(ie,{value:i.status||"saved",onValueChange:ke=>Qt.mutate({id:i.quoteId||i.id,status:ke}),children:[e.jsx(ce,{className:"w-32",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(k,{value:"saved",children:"Saved"}),e.jsx(k,{value:"checked_out",children:"Checked Out"}),e.jsx(k,{value:"purchased",children:"Purchased"}),e.jsx(k,{value:"shipped",children:"Shipped"}),e.jsx(k,{value:"not_interested",children:"Not Interested"})]})]},`${i.id}-${i.status||"saved"}`)}),e.jsx(u,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(T,{variant:"ghost",size:"sm",title:"Stop all automated emails to this customer",className:"text-orange-500 hover:text-orange-700 hover:bg-orange-50",onClick:()=>Ns.mutate(i.quoteId||i.id),disabled:Ns.isPending,children:e.jsx(wa,{className:"w-4 h-4"})}),e.jsxs(bt,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(T,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-700 hover:bg-red-50",children:e.jsx(Hs,{className:"w-4 h-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"Delete Quote"}),e.jsxs(us,{children:["Are you sure you want to delete quote ",i.quoteNumber||i.id.slice(0,8),"? This will permanently remove the quote, all line items, and any associated orders. This action cannot be undone."]})]}),e.jsxs(xs,{children:[e.jsx(ps,{children:"Cancel"}),e.jsx(hs,{className:"bg-red-600 hover:bg-red-700",onClick:()=>Kt.mutate(i.id),children:"Delete"})]})]})]})]})})]},i.id)})})]})}),e.jsxs("div",{className:"flex flex-wrap gap-3 justify-between items-center mt-4 text-sm text-muted-foreground",children:[e.jsx("span",{children:Se
57===0?"No entries found":`Showing ${Ht} to ${Wt} of ${Se} entries`}),e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx(T,{variant:"outline",size:"sm",disabled:p<=1,onClick:()=>d(p-1),"data-testid":"prev-page",children:"Previous"}),e.jsxs("span",{className:"px-3 py-1 bg-[#1B4D3E] text-white rounded text-xs font-medium",children:[p," / ",vs]}),e.jsx(T,{variant:"outline",size:"sm",disabled:p>=vs,onClick:()=>d(p+1),"data-testid":"next-page",children:"Next"})]})]})]})}),e.jsx(Ae,{open:I,onOpenChange:J,children:e.jsxs(Pe,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(qe,{children:[e.jsx(Ee,{className:"text-xl",children:c!=null&&c.orderNumber?`Order Details - ${c.orderNumber}`:`Quote Details - ${(c==null?void 0:c.quoteNumber)||((ws=c==null?void 0:c.id)==null?void 0:ws.slice(0,8))}`}),e.jsxs(Oe,{children:["View ",c!=null&&c.orderNumber?"order":"quote"," details and manage customer contact"]})]}),c&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs(S,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Ks,{className:"w-4 h-4"})," Customer Information"]})}),e.jsxs(C,{className:"space-y-2 text-sm",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Name:"})," ",(Ss=c.customer)==null?void 0:Ss.firstName," ",(Cs=c.customer)==null?void 0:Cs.lastName]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Email:"})," ",e.jsx("a",{href:`mailto:${(ks=c.customer)==null?void 0:ks.email}`,className:"text-[#C25B2B]",children:(Ts=c.customer)==null?void 0:Ts.email})]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Phone:"})," ",e.jsx("a",{href:`tel:${(Ds=c.customer)==null?void 0:Ds.phone}`,className:"text-[#C25B2B]",children:(As=c.customer)==null?void 0:As.phone})]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Zip Code:"})," ",((Ps=c.customer)==null?void 0:Ps.zipCode)||"N/A"]})]})]}),e.jsxs(S,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Le,{className:"w-4 h-4"})," Quote Summary"]})}),e.jsxs(C,{className:"space-y-2 text-sm",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Status:"})," ",e.jsx(K,{variant:"outline",children:c.status})]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Subtotal:"})," $",parseFloat(c.subtotal||0).toFixed(2)]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Tax:"})," $",parseFloat(c.totalTax||0).toFixed(2)]}),e.jsxs("p",{className:"text-lg font-bold",children:[e.jsx("span",{className:"font-medium",children:"Total:"})," $",parseFloat(c.totalCost||0).toFixed(2)]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Created:"})," ",He(c.createdAt)]})]})]})]}),e.jsx(Vt,{quoteId:c.id}),e.jsxs(S,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(E,{className:"text-base",children:["Line Items (",((qs=c.lineItems)==null?void 0:qs.length)||0,")"]})}),e.jsx(C,{children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Product"}),e.jsx(N,{children:"Opening Size"}),e.jsx(N,{children:"Finished Size"}),e.jsx(N,{children:"Color"}),e.jsx(N,{children:"Track"}),e.jsx(N,{children:"Motor"}),e.jsx(N,{children:"Qty"}),e.jsx(N,{className:"text-right",children:"Shutter"}),e.jsx(N,{className:"text-right",children:"Motor $"}),e.jsx(N,{className:"text-right",children:"Total"})]})}),e.jsx(X,{children:(Es=c.lineItems)==null?void 0:Es.map(i=>e.jsxs(D,{children:[e.jsxs(u,{className:"font-medium",children:[e.jsx("div",{children:i.productName}),(()=>{const ee={"40mm":"40MM (Impact)","44mm":"44MM (Non-Impact)","44mm-er":"44MM ER (Impact)","55mm-er":"55MM ER (Impact)","63mm":"63MM"},he={mill:"Mill .050 Aluminum",white:"White .050 Aluminum",clear:"Clear Polycarbonate",steel:"24 Gauge Steel"},G=[];return i.productType==="rolling"&&i.shutterType&&G.push(`Type: ${ee[i.shutterType]||i.shutterType.toUpperCase()}`),i.productType==="storm"&&(G.push(`Material: ${he[(i.color||"").toLowerCase()]||i.color}`),i.clearPanels>0&&G.push(`Clear Panels: ${i.clearPanels}`)),i.productType==="accordion"&&i.clearBlades>0&&G.push(`Clear Blades: ${i.clearBlades}`),G.length?e.jsx("div",{className:"text-xs text-primary mt-1 font-normal",children:G.join(" · ")}):null})()]}),e.jsxs(u,{children:[i.openingWidth,'" × ',i.openingHeight,'"']}),e.jsx(u,{children:i.finishedWidth&&i.finishedHeight?`${parseFloat(i.finishedWidth).toFixed(2)}" × ${parseFloat(i.finishedHeight).toFixed(2)}"`:"—"}),e.jsx(u,{className:"capitalize",children:i.color}),e.jsx(u,{children:i.productType==="storm"?i.addHeaderTrack?"Yes":"No":"—"}),e.jsx(u,{children:i.productType==="rolling"?e.jsx("span",{className:"capitalize",children:i.motorType}):"—"}),e.jsx(u,{children:i.quantity}),e.jsxs(u,{className:"text-right",children:["$",parseFloat(i.shutterCost||0).toFixed(2)]}),e.jsx(u,{className:"text-right",children:i.productType==="rolling"?`$${parseFloat(i.motorCost||0).toFixed(2)}`:"—"}),e.jsxs(u,{className:"text-right font-semibold",children:["$",parseFloat(i.lineTotalCost||0).toFixed(2)]})]},i.id))})]})})]}),e.jsxs(S,{className:"border-[#1B4D3E]",children:[e.jsx(q,{className:"pb-2 bg-[#1B4D3E]/5",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Te,{className:"w-4 h-4"})," CRM - Contact Management"]})}),e.jsxs(C,{className:"pt-4 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(B,{children:"Contact Status"}),e.jsxs(ie,{value:M,onValueChange:P,children:[e.jsx(ce,{children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(k,{value:"new",children:"New - Not Contacted"}),e.jsx(k,{value:"contacted",children:"Contacted"}),e.jsx(k,{value:"voicemail_left",children:"Voicemail Left"}),e.jsx(k,{value:"no_response",children:"No Response"}),e.jsx(k,{value:"follow_up",children:"Follow Up Needed"}),e.jsx(k,{value:"closed_won",children:"Closed - Won"}),e.jsx(k,{value:"closed_lost",children:"Closed - Lost"})]})]})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Follow Up Date"}),e.jsx(O,{type:"date",value:L,onChange:i=>W(i.target.value)})]})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Notes"}),e.jsx(Be,{placeholder:"Add notes about customer contact, preferences, etc...",value:Q,onChange:i=>ne(i.target.value),className:"min-h-[100px]"})]}),c.lastContactedAt&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Last contacted: ",He(c.lastContactedAt)]}),e.jsx(T,{onClick:Yt,className:"bg-[#1B4D3E] hover:bg-[#163D32]",disabled:Ke.isPending,children:Ke.isPending?"Saving...":"Save CRM Changes"}),e.jsxs(T,{variant:"outline",className:"ml-3",onClick:async()=>{var i,ee;
57try{const G=await(await F("POST",`/api/admin/quotes/${c.id}/resend-notifications`)).json();b({title:"Notifications Sent",description:`Office: ${((i=G.results)==null?void 0:i.office)||"N/A"} | Customer: ${((ee=G.results)==null?void 0:ee.customer)||"N/A"}`})}catch{b({title:"Failed to resend notifications",variant:"destructive"})}},children:[e.jsx(ve,{className:"w-4 h-4 mr-2"})," Resend Notifications"]})]})]}),e.jsx(ss,{quoteId:c.quoteId||c.id})]})]})})]})}function Vt({quoteId:s}){const n=me(),{toast:t}=re(),{data:l,isLoading:o}=z({queryKey:["/api/admin/orders/by-quote",s],enabled:!!s,retry:!1}),j=U({mutationFn:async g=>F("POST",`/api/admin/orders/${g}/payment-profile/sync`),onSuccess:g=>{n.invalidateQueries({queryKey:["/api/admin/orders/by-quote",s]}),n.invalidateQueries({predicate:a=>typeof a.queryKey[0]=="string"&&a.queryKey[0].startsWith("/api/admin/orders")}),n.invalidateQueries({queryKey:["/api/admin/credit-cards"]});const v=g.checkoutRemindersCancelled>0?` ${g.checkoutRemindersCancelled} outdated customer reminder${g.checkoutRemindersCancelled===1?" was":"s were"} cancelled.`:"";if(g.officeNotificationStatus==="failed"){t({title:"Payment method secured, email needs attention",description:`The Authorize.net profile is synced, but the office notification could not be submitted. Please notify the office manually.${v}`,variant:"destructive"});return}if(g.officeNotificationStatus==="submitted"){t({title:"Payment method secured",description:`The Authorize.net profile is synced and the office notification was submitted to the email provider.${v}`});return}t({title:"Payment method synced",description:`The payment method was already secured, so no duplicate office notification was sent.${v}`})},onError:g=>t({title:"Payment method not found yet",description:(g==null?void 0:g.message)||"The customer may still be completing the Authorize.net form.",variant:"destructive"})});if(o||!l)return null;const m=l.billingAddress&&l.billingAddress!=="N/A";return e.jsxs(S,{children:[e.jsx(q,{className:"pb-2",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(zs,{className:"w-4 h-4"})," Authorize.net Payment Method"]})}),e.jsxs(C,{className:"text-sm space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2",children:[e.jsx("span",{className:"font-medium",children:"Status:"}),e.jsx(K,{variant:"outline",className:l.paymentStatus==="profile_saved"?"bg-green-50 text-green-700 border-green-300":"bg-amber-50 text-amber-700 border-amber-300",children:l.paymentStatus==="profile_saved"?"Secured in Authorize.net":"Waiting for customer"})]}),l.cardholderName&&e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Cardholder:"})," ",l.cardholderName]}),m?e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Street:"})," ",l.billingAddress]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"City/State/ZIP:"})," ",l.billingCity,","," ",e.jsx("span",{className:"uppercase",children:l.billingState})," ",l.billingZip]})]}):e.jsxs("p",{className:"text-muted-foreground",children:["No street address on file. ZIP: ",l.billingZip||"N/A"]}),l.cardLastFour&&e.jsxs("p",{className:"text-muted-foreground text-xs pt-1",children:["Card on file: ",e.jsx("span",{className:"capitalize",children:l.cardType})," ending in ",l.cardLastFour]}),l.authorizeNetCustomerProfileId&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"pt-2",children:[e.jsx("span",{className:"font-medium",children:"Customer Profile:"})," ",e.jsx("span",{className:"font-mono text-xs",children:l.authorizeNetCustomerProfileId})]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium",children:"Payment Profile:"})," ",e.jsx("span",{className:"font-mono text-xs",children:l.authorizeNetPaymentProfileId||"Pending"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground pt-1",children:["In Authorize.net Customer Information Manager, search by Customer ID ",e.jsx("strong",{children:l.orderNumber}),"."]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"After the customer approves the revised total and the charge succeeds, set this order's status to Purchased."}),e.jsx("a",{href:"https://account.authorize.net/",target:"_blank",rel:"noreferrer",className:"inline-flex mt-2 items-center rounded-md bg-[#166534] px-3 py-2 text-xs font-semibold text-white hover:bg-[#14532d]",children:"Open Authorize.net"}),l.paymentStatus!=="profile_saved"&&e.jsx(T,{type:"button",variant:"outline",size:"sm",className:"ml-2 mt-2",onClick:()=>j.mutate(l.orderId),disabled:j.isPending,children:j.isPending?"Checking...":"Refresh Authorize.net Status"})]})]})]})}function mn(){const{data:s=[],isLoading:n}=z({queryKey:["/api/admin/credit-cards"]});return e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"Secure Payment Methods"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Full card numbers, expiration dates, and CVV are stored only by Authorize.net. Hurricane Shutters Florida keeps the masked card details and profile references needed to locate the payment method in Customer Information Manager."}),e.jsx(S,{children:e.jsx(C,{className:"p-6 overflow-x-auto",children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Order #"}),e.jsx(N,{children:"Customer"}),e.jsx(N,{children:"Cardholder Name"}),e.jsx(N,{children:"Billing Address"}),e.jsx(N,{children:"Card"}),e.jsx(N,{children:"Status"}),e.jsx(N,{children:"Authorize.net Customer Profile"}),e.jsx(N,{children:"Payment Profile"})]})}),e.jsx(X,{children:n?e.jsx(D,{children:e.jsx(u,{colSpan:8,className:"text-center py-8",children:"Loading..."})}):s.length===0?e.jsx(D,{children:e.jsx(u,{colSpan:8,className:"text-center py-8 text-muted-foreground",children:"No secure payment profiles are available yet."})}):s.map(t=>{const l=t.billingAddress&&t.billingAddress!=="N/A";return e.jsxs(D,{children:[e.jsx(u,{className:"font-mono text-xs",children:t.orderNumber}),e.jsx(u,{children:t.customerName}),e.jsx(u,{children:t.cardholderName}),e.jsx(u,{className:"text-xs whitespace-pre-line max-w-[180px]",children:l?e.jsxs(e.Fragment,{children:[t.billingAddress,`
58`,t.billingCity,", ",e.jsx("span",{className:"uppercase",children:t.billingState})," ",t.billingZip]}):e.jsxs("span",{className:"text-muted-foreground",children:["ZIP only: ",t.billingZip]})}),e.jsxs(u,{className:"capitalize",children:[t.cardType||"Card"," ",t.cardLastFour?`ending in ${t.cardLastFour}`:"pending"]}),e.jsx(u,{className:"capitalize",children:String(t.paymentStatus||"pending").replace(/_/g," ")}),e.jsx(u,{className:"font-mono text-xs",children:t.authorizeNetCustomerProfileId||"Pending"}),e.jsx(u,{className:"font-mono text-xs",children:t.authorizeNetPaymentProfileId||"Pending"})]},t.orderId)})})]})})})]})}function un(){const s=me(),{toast:n}=re(),[t,l]=h.useState(!1),[o,j]=h.useState(null),[m,g]=h.useState({customerName:"",location:"",rating:5,content:"",productType:"",isActive:!0}),{data:v=[],isLoading:a}=z({queryKey:["/api/testimonials"]}),p=U({mutationFn:f=>F("POST","/api/admin/testimonials",f),onSuccess:()=>{s.invalidateQueries({queryKey:["/api/testimonials"]}),n({title:"Testimonial Created"}),l(!1),r()}}),d=U({mutationFn:({id:f,data:A})=>F("PATCH",`/api/admin/testimonials/${f}`,A),onSuccess:()=>{s.invalidateQueries({queryKey:["/api/testimonials"]}),n({title:"Testimonial Updated"}),l(!1),r()}}),x=U({mutationFn:f=>F("DELETE",`/api/admin/testimonials/${f}`),onSuccess:()=>{s.invalidateQueries({queryKey:["/api/testimonials"]}),n({title:"Testimonial Deleted"})}}),r=()=>{g({customerName:"",location:"",rating:5,content:"",productType:"",isActive:!0}),j(null)},w=()=>{o?d.mutate({id:o.id,data:m}):p.mutate(m)},y=f=>{j(f),g({customerName:f.customerName,location:f.location||"",rating:f.rating,content:f.content,productType:f.productType||"",isActive:f.isActive}),l(!0)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Testimonials"}),e.jsxs(Ae,{open:t,onOpenChange:f=>{l(f),f||r()},children:[e.jsx(Qs,{asChild:!0,children:e.jsxs(T,{className:"bg-[#1B4D3E] hover:bg-[#163D32]",children:[e.jsx(fa,{className:"w-4 h-4 mr-2"})," Add Testimonial"]})}),e.jsxs(Pe,{children:[e.jsx(qe,{children:e.jsx(Ee,{children:o?"Edit Testimonial":"Add New Testimonial"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(B,{children:"Customer Name"}),e.jsx(O,{value:m.customerName,onChange:f=>g({...m,customerName:f.target.value})})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Location"}),e.jsx(O,{value:m.location,onChange:f=>g({...m,location:f.target.value}),placeholder:"e.g., Miami, FL"})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Rating (1-5)"}),e.jsxs(ie,{value:String(m.rating),onValueChange:f=>g({...m,rating:parseInt(f)}),children:[e.jsx(ce,{children:e.jsx(oe,{})}),e.jsx(de,{children:[5,4,3,2,1].map(f=>e.jsxs(k,{value:String(f),children:[f," Stars"]},f))})]})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Product Type"}
58),e.jsx(O,{value:m.productType,onChange:f=>g({...m,productType:f.target.value}),placeholder:"e.g., Accordion Shutters"})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Testimonial Content"}),e.jsx(Be,{value:m.content,onChange:f=>g({...m,content:f.target.value}),rows:4})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(et,{checked:m.isActive,onCheckedChange:f=>g({...m,isActive:f})}),e.jsx(B,{children:"Active (visible on website)"})]})]}),e.jsxs(ns,{children:[e.jsx(T,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),e.jsx(T,{onClick:w,className:"bg-[#1B4D3E] hover:bg-[#163D32]",children:o?"Update":"Create"})]})]})]})]}),e.jsx(S,{children:e.jsx(C,{className:"p-6",children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Customer"}),e.jsx(N,{children:"Location"}),e.jsx(N,{children:"Rating"}),e.jsx(N,{children:"Product"}),e.jsx(N,{children:"Status"}),e.jsx(N,{children:"Actions"})]})}),e.jsx(X,{children:a?e.jsx(D,{children:e.jsx(u,{colSpan:6,className:"text-center py-8",children:"Loading..."})}):v.length===0?e.jsx(D,{children:e.jsx(u,{colSpan:6,className:"text-center py-8 text-muted-foreground",children:"No testimonials yet."})}):v.map(f=>e.jsxs(D,{children:[e.jsx(u,{className:"font-medium",children:f.customerName}),e.jsx(u,{children:f.location||"N/A"}),e.jsx(u,{children:e.jsx("div",{className:"flex",children:[...Array(f.rating)].map((A,c)=>e.jsx(Na,{className:"w-4 h-4 fill-yellow-400 text-yellow-400"},c))})}),e.jsx(u,{children:f.productType||"General"}),e.jsx(u,{children:e.jsx(K,{variant:f.isActive?"default":"secondary",children:f.isActive?"Active":"Inactive"})}),e.jsx(u,{children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>y(f),children:e.jsx(Ue,{className:"w-4 h-4"})}),e.jsxs(bt,{children:[e.jsx(vt,{asChild:!0,children:e.jsx(T,{variant:"ghost",size:"sm",className:"text-red-600",children:e.jsx(Hs,{className:"w-4 h-4"})})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"Delete Testimonial?"}),e.jsx(us,{children:"This action cannot be undone."})]}),e.jsxs(xs,{children:[e.jsx(ps,{children:"Cancel"}),e.jsx(hs,{onClick:()=>x.mutate(f.id),className:"bg-red-600",children:"Delete"})]})]})]})]})})]},f.id))})]})})})]})}function hn(){const{toast:s}=re(),n=me(),{data:t=[]}=z({queryKey:["/api/admin/pricing"]}),o=[{productType:"accordion",product:"Accordion Shutters",price:27.25,unit:"per_sqft"},{productType:"storm-mill",product:"Storm Panels - Mill",price:10.95,unit:"per_sqft"},{productType:"storm-white",product:"Storm Panels - White",price:19,unit:"per_sqft"},{productType:"storm-clear",product:"Storm Panels - Clear Guard",price:14.95,unit:"per_sqft"},{productType:"storm-steel",product:"Storm Panels - Steel",price:9.95,unit:"per_sqft"},{productType:"rolling-40mm",product:"40MM Rolling Shutter (Impact)",price:58.37,unit:"per_sqft",note:"Rate per sqft (+ $159.55 base)"},{productType:"rolling-44mm-er",product:"44MM ER Rolling Shutter (Impact)",price:31.61,unit:"per_sqft",note:"Rate per sqft (+ $94.78 base)"},{productType:"rolling-44mm-foam",product:"44MM Foam Filled (Non-Impact)",price:31.61,unit:"per_sqft",note:"Rate per sqft (+ $94.78 base)"},{productType:"rolling-55mm",product:"55MM ER Rolling Shutter",price:31.61,unit:"per_sqft",note:"Rate per sqft (+ $94.78 base)"},{productType:"rolling-63mm",product:"63MM Rolling Shutter",price:31.61,unit:"per_sqft",note:"Rate per sqft (+ $94.78 base)"},{productType:"bahama",product:"Bahama Shutters (Non-Impact)",price:45.95,unit:"per_sqft"},{productType:"colonial",product:"Colonial Shutters (Non-Impact)",price:45.95,unit:"per_sqft"},{productType:"impact-bahama",product:"Bahama Shutters (Impact)",price:61.75,unit:"per_sqft"},{productType:"impact-colonial",product:"Colonial Shutters (Impact)",price:61.75,unit:"per_sqft"},{productType:"clamshell",product:"Clamshell Awnings",price:29.5,unit:"per_sqft"},{productType:"track",product:"Track (Header & F-Track)",price:17.5,unit:"per_linear_ft"}].map(d=>{const x=t.find(r=>r.productType===d.productType);return x?{...d,price:parseFloat(x.priceValue),dbId:x.id}:d}),[j,m]=h.useState(null),[g,v]=h.useState(""),a=U({mutationFn:async d=>F("POST","/api/admin/pricing",d),onSuccess:()=>{n.invalidateQueries({queryKey:["/api/admin/pricing"]}),s({title:"Price updated successfully"}),m(null)},onError:()=>{s({title:"Error updating price",variant:"destructive"})}}),p={per_sqft:"per sq ft",per_linear_ft:"per linear ft"};return e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"Adjust Price"}),e.jsx(S,{children:e.jsx(C,{className:"p-6",children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Product"}),e.jsx(N,{children:"Current Price"}),e.jsx(N,{children:"Unit"}),e.jsx(N,{children:"Actions"})]})}),e.jsx(X,{children:o.map((d,x)=>e.jsxs(D,{children:[e.jsx(u,{className:"font-medium",children:d.product}),e.jsx(u,{children:j===x?e.jsx(O,{type:"number",step:"0.01",value:g,onChange:r=>v(r.target.value),className:"w-28"}):e.jsxs("span",{children:["$",d.price.toFixed(2)]})}),e.jsx(u,{children:p[d.unit]||d.unit}),e.jsx(u,{children:j===x?e.jsxs("div",{className:"flex gap-1",children:[e.jsx(T,{size:"sm",onClick:()=>{a.mutate({productType:d.productType,priceValue:g,priceType:d.unit,description:d.product})},disabled:a.isPending,children:"Save"}),e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>m(null),children:"Cancel"})]}):e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>{m(x),v(d.price.toFixed(2))},children:e.jsx(Ue,{className:"w-4 h-4"})})})]},x))})]})})})]})}function pn(){const{toast:s}=re(),n=me(),{data:t=[]}=z({queryKey:["/api/admin/lead-times"]}),o=[{productType:"storm-panels",product:"Storm Panels",min:2,max:3},{productType:"accordion",product:"Accordion Shutters",min:3,max:4},{productType:"rolling",product:"Rolling Shutters",min:4,max:6},{productType:"bahama",product:"Bahama Shutters",min:3,max:4},{productType:"colonial",product:"Colonial Shutters",min:3,max:4},{productType:"impact-bahama",product:"Impact Bahama",min:4,max:5},{productType:"impact-colonial",product:"Impact Colonial",min:4,max:5},{productType:"clamshell",product:"Clamshell Awnings",min:4,max:5},{productType:"fabric",product:"Hurricane Fabric",min:1,max:2}].map(x=>{const r=t.find(w=>w.productType===x.productType);return r?{...x,min:r.minDays,max:r.maxDays,dbId:r.id}:x}),[j,m]=h.useState(null),[g,v]=h.useState(""),[a,p]=h.useState(""),d=U({mutationFn:async x=>F("PATCH","/api/admin/lead-times/update",x),onSuccess:()=>{n.invalidateQueries({queryKey:["/api/admin/lead-times"]}),s({title:"Lead time updated successfully"}),m(null)},onError:()=>{s({title:"Error updating lead time",variant:"destructive"})}});return e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"Turn Around Times"}),e.jsx(S,{children:e.jsx(C,{className:"p-6",children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Product Type"}),e.jsx(N,{children:"Min Weeks"}),e.jsx(N,{children:"Max Weeks"}),e.jsx(N,{children:"Display Text"}),e.jsx(N,{children:"Actions"})]})}),e.jsx(X,{children:o.map((x,r)=>e.jsxs(D,{children:[e.jsx(u,{className:"font-medium",children:x.product}),e.jsx(u,{children:j===r?e.jsx(O,{type:"number",value:g,onChange:w=>v(w.target.value),className:"w-20"}):x.min}),e.jsx(u,{children:j===r?e.jsx(O,{type:"number",value:a,onChange:w=>p(w.target.value),className:"w-20"}):x.max}),e.jsx(u,{children:j===r?`${g}-${a} weeks`:`${x.min}-${x.max} weeks`}),e.jsx(u,{children:j===r?e.jsxs("div",{className:"flex gap-1",children:[e.jsx(T,{size:"sm",onClick:()=>{d.mutate({productType:x.productType,minDays:parseInt(g),maxDays:parseInt(a),displayText:`${g}-${a} weeks`})},disabled:d.isPending,children:"Save"}),e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>m(null),children:"Cancel"})]}):e.jsx(T,{variant:"ghost",size:"sm",onClick:()=>{m(r),v(String(x.min)),p(String(x.max))},children:e.jsx(Ue,{className:"w-4 h-4"})})})]},r))})]})})})]})}function jn(){var d;const{toast:s}=re(),n=me(),[t,l]=h.useState(null),o={home:[{key:"hero_title",label:"Hero Title",type:"text"},{key:"hero_subtitle",label:"Hero Subtitle",type:"textarea"},{key:"intro_text",label:"Introduction Text",type:"textarea"}],about:[{key:"page_title",label:"Page Title",type:"text"},{key:"intro_text",label:"Introduction Text",type:"textarea"},{key:"story_text",label:"Our Story",type:"textarea"},{key:"years_in_business",label:"Years in Business",type:"text"}],warranty:[{key:"page_title",label:"Page Title",type:"text"},{key:"warranty_text",label:"Warranty Details",type:"textarea"}],shipping:[{key:"page_title",label:"Page Title",type:"text"},{key:"shipping_info",label:"Shipping Information",type:"textarea"}],faqs:[{key:"page_title",label:"Page Title",type:"text"},{key:"intro_text",label:"Introduction Text",type:"textarea"}],contact:[{key:"page_title",label:"Page Title",type:"text"},{key:"phone",label:"Phone Number",type:"text"},{key:"email",label:"Email Address",type:"text"},{key:"address",label:"Address",type:"textarea"},{key:"hours",label:"Business Hours",type:"text"}]},{data:j=[]}
58=z({queryKey:["/api/admin/content",t==null?void 0:t.slug],enabled:!!t}),[m,g]=h.useState({});h.useEffect(()=>{if(t&&j.length>0){const x={};j.forEach(r=>{x[r.sectionKey]=r.content}),g(x)}else t&&g({})},[t,j]);const v=U({mutationFn:async x=>F("POST","/api/admin/content",x),onSuccess:()=>{n.invalidateQueries({queryKey:["/api/admin/content"]})}}),a=async()=>{if(!t)return;const x=o[t.slug]||[];try{for(const r of x)m[r.key]!==void 0&&m[r.key]!==""&&await F("POST","/api/admin/content",{pageSlug:t.slug,sectionKey:r.key,content:m[r.key],contentType:"text"});n.invalidateQueries({queryKey:["/api/admin/content"]}),s({title:`${t.name} content saved successfully`}),l(null)}catch{s({title:"Error saving content",variant:"destructive"})}},p=[{slug:"home",name:"Home Page"},{slug:"about",name:"About Us"},{slug:"warranty",name:"Warranty"},{slug:"shipping",name:"Shipping"},{slug:"faqs",name:"FAQs"},{slug:"contact",name:"Contact"}];return e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"Content Management System"}),e.jsx("div",{className:"grid md:grid-cols-3 gap-4",children:p.map(x=>e.jsx(S,{className:"cursor-pointer hover:shadow-lg transition-shadow",onClick:()=>l(x),children:e.jsx(C,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:x.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["/",x.slug]})]}),e.jsx(Ue,{className:"w-5 h-5 text-muted-foreground"})]})})},x.slug))}),e.jsx(Ae,{open:!!t,onOpenChange:x=>{x||l(null)},children:e.jsxs(Pe,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(qe,{children:[e.jsxs(Ee,{children:["Edit ",t==null?void 0:t.name]}),e.jsxs(Oe,{children:["Update the content for the ",(d=t==null?void 0:t.name)==null?void 0:d.toLowerCase()," page. Changes will be saved to the database."]})]}),e.jsx("div",{className:"space-y-4 py-4",children:t&&(o[t.slug]||[]).map(x=>e.jsxs("div",{children:[e.jsx(B,{className:"mb-2 block",children:x.label}),x.type==="textarea"?e.jsx(Be,{value:m[x.key]||"",onChange:r=>g(w=>({...w,[x.key]:r.target.value})),rows:4,placeholder:`Enter ${x.label.toLowerCase()}...`}):e.jsx(O,{value:m[x.key]||"",onChange:r=>g(w=>({...w,[x.key]:r.target.value})),placeholder:`Enter ${x.label.toLowerCase()}...`})]},x.key))}),e.jsxs(ns,{children:[e.jsx(T,{variant:"outline",onClick:()=>l(null),children:"Cancel"}),e.jsx(T,{onClick:a,disabled:v.isPending,children:"Save Changes"})]})]})})]})}function gn({dateParams:s}){var v;const{data:n}=z({queryKey:["/api/admin/analytics/live"],queryFn:async()=>(await fetch("/api/admin/analytics/live",{credentials:"include"})).json(),refetchInterval:1e4}),{data:t,isLoading:l}=z({queryKey:["/api/admin/analytics/dashboard",s],queryFn:async()=>(await fetch(`/api/admin/analytics/dashboard${s||""}`,{credentials:"include"})).json(),enabled:!!s}),o=(n==null?void 0:n.count)||0,j=(n==null?void 0:n.visitors)||[],m=[{label:"Visitors",value:(t==null?void 0:t.uniqueVisitors)||0,color:"bg-blue-500"},{label:"Quote Started",value:(t==null?void 0:t.quoteStarted)||0,color:"bg-amber-500"},{label:"Quote Saved",value:(t==null?void 0:t.quoteSaved)||0,color:"bg-green-500"},{label:"Checkout",value:(t==null?void 0:t.quoteCheckout)||0,color:"bg-emerald-600"}],g=Math.max(...m.map(a=>a.value),1);return e.jsxs("div",{className:"grid md:grid-cols-3 gap-4 mb-6",children:[e.jsxs(S,{className:"border-l-4 border-l-green-500",children:[e.jsx(q,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ls,{className:"w-4 h-4 text-green-600"}),o>0&&e.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 bg-green-500 rounded-full animate-pulse"})]}),"Live on Site"]}),e.jsx("span",{className:"text-2xl font-bold text-green-600",children:o})]})}),e.jsx(C,{className:"pt-0",children:o===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No active visitors right now"}):e.jsxs("div",{className:"space-y-1.5",children:[j.slice(0,4).map((a,p)=>e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 bg-green-500 rounded-full"}),e.jsx("span",{className:"text-muted-foreground truncate max-w-[120px]",children:De(a.page)})]}),e.jsx("span",{className:"text-muted-foreground",children:zt(a.duration)})]},p)),o>4&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["+",o-4," more"]})]})})]}),e.jsxs(S,{className:"border-l-4 border-l-blue-500",children:[e.jsx(q,{className:"pb-2",children:e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(Ve,{className:"w-4 h-4 text-blue-600"}),"Traffic Overview"]})}),e.jsx(C,{className:"pt-0",children:l?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-bold",children:(t==null?void 0:t.uniqueVisitors)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Visitors"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-bold",children:(t==null?void 0:t.totalPageViews)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Page Views"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-bold",children:(t==null?void 0:t.uniqueSessions)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sessions"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-bold",children:(t==null?void 0:t.popupSignups)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Signups"})]})]}),(((v=t==null?void 0:t.topPages)==null?void 0:v.length)||0)>0&&e.jsxs("div",{className:"border-t pt-2 mt-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Top Pages"}),t.topPages.slice(0,3).map((a,p)=>e.jsxs("div",{className:"flex items-center justify-between text-xs py-0.5",children:[e.jsx("span",{className:"truncate max-w-[150px]",children:De(a.page)}),e.jsx("span",{className:"font-medium text-muted-foreground",children:a.views})]},p))]})]})})]}),e.jsxs(S,{className:"border-l-4 border-l-purple-500",children:[e.jsx(q,{className:"pb-2",children:e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(ze,{className:"w-4 h-4 text-purple-600"}),"Conversion Funnel"]})}),e.jsx(C,{className:"pt-0",children:l?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}):e.jsxs("div",{className:"space-y-2",children:[m.map((a,p)=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-0.5",children:[e.jsx("span",{className:"text-muted-foreground",children:a.label}),e.jsx("span",{className:"font-bold",children:a.value})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2",children:e.jsx("div",{className:`${a.color} h-2 rounded-full transition-all duration-500`,style:{width:`${Math.max(a.value/g*100,a.value>0?4:0)}%`}})})]},p)),e.jsxs("div",{className:"border-t pt-1.5 mt-1 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Conversion Rate"}),e.jsxs("span",{className:"text-sm font-bold text-purple-600",children:[(t==null?void 0:t.uniqueVisitors)>0?(((t==null?void 0:t.quoteSaved)||0)/t.uniqueVisitors*100).toFixed(1):"0.0","%"]})]})]})})]})]})}function zt(s){if(s<60)return`${s}s`;const n=Math.floor(s/60),t=s%60;return n<60?`${n}m ${t}s`:`${Math.floor(n/60)}h ${n%60}m`}function De(s){if(s==="/")return"Home";const n={"/products":"Products","/about":"About","/contact":"Contact","/testimonials":"Testimonials","/faqs":"FAQs","/blog":"Blog","/press-room":"Press Room","/warranty":"Warranty","/shipping":"Shipping","/contractors":"Contractors","/color-chart":"Color Chart","/color-swatch":"Color Swatch","/product-drawings":"Product Drawings","/installation-guidelines":"Installation Guide","/measuring-windows":"Measuring Guide","/storm-panel-tracks":"Storm Panel Tracks","/insurance-discounts":"Insurance Discounts","/privacy-policy":"Privacy Policy","/code-of-ethics":"Code of Ethics"};return n[s]?n[s]:s.startsWith("/products/")?s.split("/products/")[1].split("-").map(l=>l.charAt(0).toUpperCase()+l.slice(1)).join(" "):s.startsWith("/quote/")?"Quote Summary":s}function fn(){const{data:s,isLoading:n}=z({queryKey:["/api/admin/analytics/live"],queryFn:async()=>(await fetch("/api/admin/analytics/live",{credentials:"include"})).json(),refetchInterval:5e3}),t=(s==null?void 0:s.visitors)||[],l=(s==null?void 0:s.count)||0;return e.jsxs(S,{className:"mb-6 border-green-200 dark:border-green-800",children:[e.jsx(q,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ls,{className:"w-5 h-5 text-green-600"}),e.jsx("span",{className:"absolute -top-1 -right-1 w-2.5 h-2.5 bg-green-500 rounded-full animate-pulse"})]}),e.jsxs(E,{className:"text-lg",children:["Live Visitors",e.jsx(K,{variant:"secondary",className:"ml-2 bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200",children:l})]})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Updates every 5s"})]})}),e.jsx(C,{children:n?e.jsx("p",{className:"text-muted-foreground text-sm",children:"Loading..."}):t.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:"No active visitors right now"}):e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Visitor"}),e.jsx(N,{children:"Current Page"}),e.jsx(N,{children:"Time on Site"}),e.jsx(N,{children:"Pages Viewed"}),e.jsx(N,{children:"Source"})]})}),e.jsx(X,{children:t.map((o,j)=>e.jsxs(D,{children:[e.jsx(u,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 bg-green-500 rounded-full inline-block"}),e.jsx("span",{className:"text-xs font-mono text-muted-foreground",children:o.visitorId})]})}),e.jsx(u,{className:"font-medium",children:De(o.page)}),e.jsx(u,{children:zt(o.duration)}),e.jsxs(u,{children:[e.jsxs("span",{className:"text-sm",children:[o.pagesViewed," page",o.pagesViewed!==1?"s":""]}),o.pagesViewed>1&&e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:o.pagesList.map(m=>De(m)).join(" → ")})]}),e.jsx(u,{className:"text-xs text-muted-foreground",children:o.referrer?(()=>{try{return new URL(o.referrer).hostname}catch{return o.referrer}})():"Direct"})]},j))})]})})]})}function Nn({dateParams:s}){const{data:n,isLoading:t}=z({queryKey:["/api/admin/analytics/acquisition",s],queryFn:async()=>(await fetch(`/api/admin/analytics/acquisition${s||""}`,{credentials:"include"})).json(),enabled:!!s});if(t)return e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(je,{className:"w-8 h-8 animate-spin text-muted-foreground"})});const l=(n==null?void 0:n.channels)||[],o=(n==null?void 0:n.devices)||[],j=(n==null?void 0:n.organicPages)||[],m=(n==null?void 0:n.products)||[],g=(n==null?void 0:n.keywords)||[],v={Direct:"bg-slate-500","Organic Search":"bg-emerald-500",Social:"bg-blue-500",Referral:"bg-purple-500",Email:"bg-amber-500","Paid Search":"bg-red-500",Campaign:"bg-orange-500",Unknown:"bg-gray-400"},a=o.filter(r=>r.device!=="Unknown"),p=Math.max(...m.map(r=>r.started),1),d=Math.max(...l.map(r=>r.sessions),1),x=r=>r==="mobile"?e.jsx($s,{className:"w-4 h-4 text-blue-500"}):r==="tablet"?e.jsx(Fs,{className:"w-4 h-4 text-purple-500"}):e.jsx(Fs,{className:"w-4 h-4 text-emerald-600"});return e.jsxs("div",{className:"space-y-6 mt-2",children:[e.jsxs("div",{className:"bg-blue-50 dark:bg-blue-950/40 border border-blue-200 dark:border-blue-800 rounded-lg p-3 flex items-start gap-2",children:[e.jsx(Is,{className:"w-4 h-4 text-blue-500 flex-shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-xs text-blue-700 dark:text-blue-300",children:['Device and UTM/campaign tracking is active for all new sessions. Historical sessions without this data will appear under "Unknown" device. To track campaigns, add ',e.jsx("code",{className:"bg-blue-100 dar
58k:bg-blue-900 px-1 rounded",children:"?utm_source=google&utm_medium=cpc"})," to your ad links."]})]}),e.jsxs(S,{children:[e.jsxs(q,{className:"pb-2",children:[e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Ve,{className:"w-4 h-4 text-indigo-500"}),"Traffic Channels — Conversion Quality"]}),e.jsx(te,{children:"Ranked by which sources bring visitors who actually save quotes or check out"})]}),e.jsx(C,{children:l.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No channel data in this date range yet"}):e.jsxs("div",{className:"space-y-3",children:[[...l].sort((r,w)=>w.saveRate-r.saveRate).map(r=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${v[r.channel]||"bg-gray-400"}`}),e.jsx("span",{className:"font-semibold",children:r.channel}),e.jsxs("span",{className:"text-muted-foreground",children:["· ",r.sessions," sessions"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-amber-600 font-medium",children:[r.quoteStarted," starts"]}),e.jsxs("span",{className:"text-green-600 font-medium",children:[r.quoteSaved," saved"]}),e.jsxs("span",{className:"text-blue-600 font-medium",children:[r.quoteCheckout," checkout"]}),e.jsxs("span",{className:`font-bold px-2 py-0.5 rounded text-[11px] ${r.saveRate>=5?"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200":r.saveRate>=1?"bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200":"bg-muted text-muted-foreground"}`,children:[r.saveRate.toFixed(1),"% save rate"]})]})]}),e.jsxs("div",{className:"flex gap-1 h-3",children:[e.jsx("div",{className:"bg-muted rounded-l-full rounded-r-sm h-full flex-1 overflow-hidden",children:e.jsx("div",{className:`${v[r.channel]||"bg-gray-400"} h-full rounded-l-full opacity-30 transition-all`,style:{width:`${Math.max(r.sessions/d*100,2)}%`}})}),r.quoteStarted>0&&e.jsx("div",{className:"bg-amber-500 rounded-sm h-full transition-all",style:{width:`${Math.max(r.quoteStarted/Math.max(r.sessions,1)*60,4)}px`}}),r.quoteSaved>0&&e.jsx("div",{className:"bg-green-500 rounded-sm h-full transition-all",style:{width:`${Math.max(r.quoteSaved/Math.max(r.sessions,1)*60,4)}px`}})]})]},r.channel)),e.jsxs("div",{className:"flex items-center gap-4 text-[10px] text-muted-foreground pt-1 border-t",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-amber-500 inline-block"}),"Quote started"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 inline-block"}),"Quote saved"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-blue-500 inline-block"}),"Checked out"]})]})]})})]}),e.jsxs(S,{children:[e.jsxs(q,{className:"pb-2",children:[e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx($s,{className:"w-4 h-4 text-blue-500"}),"Desktop vs Mobile — User Quality"]}),e.jsx(te,{children:"Which device type produces more engaged users and higher conversion rates"})]}),e.jsx(C,{children:a.length===0?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Device data will appear for new visitor sessions"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Sessions from today onward will have device type tracked automatically"})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:a.map(r=>{const w=a.every(y=>y.device===r.device||r.saveRate>=y.saveRate);return e.jsxs("div",{className:`rounded-lg border p-4 ${w&&a.length>1?"border-green-300 dark:border-green-700 bg-green-50/50 dark:bg-green-950/20":"bg-muted/20"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[x(r.device),e.jsx("span",{className:"font-semibold capitalize",children:r.device})]}),w&&a.length>1&&e.jsx("span",{className:"text-[10px] font-semibold bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300 px-2 py-0.5 rounded-full",children:"Best"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-y-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:"Sessions"}),e.jsx("span",{className:"text-right font-semibold",children:r.sessions}),e.jsx("span",{className:"text-muted-foreground text-xs",children:"Quote Starts"}),e.jsx("span",{className:"text-right font-semibold text-amber-600",children:r.quoteStarted}),e.jsx("span",{className:"text-muted-foreground text-xs",children:"Saved"}),e.jsx("span",{className:"text-right font-semibold text-green-600",children:r.quoteSaved}),e.jsx("span",{className:"text-muted-foreground text-xs",children:"Checked Out"}),e.jsx("span",{className:"text-right font-semibold text-blue-600",children:r.quoteCheckout})]}
58),e.jsxs("div",{className:"border-t mt-3 pt-3 grid grid-cols-2 gap-y-1 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Start Rate"}),e.jsxs("span",{className:`text-right font-bold ${r.startRate>=5?"text-green-600":"text-muted-foreground"}`,children:[r.startRate.toFixed(1),"%"]}),e.jsx("span",{className:"text-muted-foreground",children:"Save Rate"}),e.jsxs("span",{className:`text-right font-bold ${r.saveRate>=3?"text-green-600":"text-muted-foreground"}`,children:[r.saveRate.toFixed(1),"%"]})]})]},r.device)})})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs(S,{children:[e.jsxs(q,{className:"pb-2",children:[e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(is,{className:"w-4 h-4 text-emerald-600"}),"Top Organic Pages"]}),e.jsx(te,{className:"text-xs",children:"Pages getting the most Direct + Organic Search traffic"})]}),e.jsx(C,{children:j.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"No organic data in this range"}):e.jsx("div",{className:"space-y-2.5",children:j.map((r,w)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"w-4 text-muted-foreground shrink-0 text-right font-mono",children:w+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:De(r.page)}),e.jsx("p",{className:"text-muted-foreground text-[10px] truncate",children:r.page})]}),e.jsx("span",{className:"shrink-0 font-bold text-emerald-700 dark:text-emerald-400",children:r.views})]},w))})})]}),e.jsxs(S,{children:[e.jsxs(q,{className:"pb-2",children:[e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(ze,{className:"w-4 h-4 text-amber-500"}),"Product Interest"]}),e.jsx(te,{className:"text-xs",children:"Which products drive the most quote activity"})]}),e.jsx(C,{children:m.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"No product data yet — requires product selection events"}):e.jsx("div",{className:"space-y-3",children:m.map((r,w)=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"font-medium truncate",children:r.label||r.product}),e.jsx("span",{className:"text-muted-foreground ml-2 shrink-0 font-semibold",children:r.started})]}),e.jsx("div",{className:"bg-muted rounded-full h-2.5 overflow-hidden",children:e.jsx("div",{className:"bg-amber-500 h-full rounded-full transition-all",style:{width:`${Math.max(r.started/p*100,4)}%`}})})]},w))})})]}),e.jsxs(S,{children:[e.jsxs(q,{className:"pb-2",children:[e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(Is,{className:"w-4 h-4 text-purple-500"}),"UTM Keywords"]}),e.jsx(te,{className:"text-xs",children:"Search terms & campaign keywords from UTM links"})]}),e.jsx(C,{children:g.length===0?e.jsxs("div",{className:"py-4 text-center",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"No keyword data yet"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-1",children:["Add ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"utm_term=keyword"})," to campaign links"]})]}):e.jsx("div",{className:"space-y-1.5",children:g.map((r,w)=>e.jsxs("div",{className:"flex items-center justify-between text-xs py-1 border-b last:border-0",children:[e.jsx("span",{className:"font-medium",children:r.term}),e.jsx(K,{variant:"secondary",className:"text-[10px]",children:r.count})]},w))})})]})]})]})}function bn(){var x,r,w,y;const[s,n]=h.useState("today"),[t,l]=h.useState(""),[o,j]=h.useState(""),g=(()=>{if(s==="custom")return t&&o?`?from=${t}&to=${o}`:null;const f=new Date().toISOString().split("T")[0];if(s==="today")return`?from=${f}&to=${f}`;if(s==="yesterday"){const R=new Date;R.setDate(R.getDate()-1);const I=R.toISOString().split("T")[0];return`?from=${I}&to=${I}`}const A=parseInt(s),c=new Date;return c.setDate(c.getDate()-A),`?from=${c.toISOString().split("T")[0]}&to=${f}`})(),v=s==="custom"&&(!t||!o),{data:a,isLoading:p}=z({queryKey:["/api/admin/analytics/dashboard",s,t,o],queryFn:async()=>(await fetch(`/api/admin/analytics/dashboard${g}`,{credentials:"include"})).json(),enabled:!v}),d=(x=a==null?void 0:a.dailyTrends)!=null&&x.length?Math.max(...a.dailyTrends.map(f=>f.pageViews),1):1;return e.jsxs("div",{children:[e.jsx(fn,{}),e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between mb-6 gap-4",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Visitor Analytics"}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs(ie,{value:s,onValueChange:n,children:[e.jsx(ce,{className:"w-40",children:e.jsx(oe,{placeholder:"Date Range"})}),e.jsxs(de,{children:[e.jsx(k,{value:"today",children:"Today"}),e.jsx(k,{value:"yesterday",children:"Yesterday"}),e.jsx(k,{value:"7",children:"Last 7 Days"}),e.jsx(k,{value:"30",children:"Last 30 Days"}),e.jsx(k,{value:"90",children:"Last 90 Days"}),e.jsx(k,{value:"365",children:"Last Year"}),e.jsx(k,{value:"custom",children:"Custom Range"})]})]}),s==="custom"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{type:"date",value:t,onChange:f=>l(f.target.value),className:"w-36"}),e.jsx("span",{children:"to"}),e.jsx(O,{type:"date",value:o,onChange:f=>j(f.target.value),className:"w-36"})]})]})]}),e.jsxs(rn,{defaultValue:"traffic",className:"w-full",children:[e.jsxs(Ut,{className:"mb-6",children:[e.jsx(Je,{value:"traffic",children:"Traffic & Funnel"}),e.jsx(Je,{value:"acquisition",children:"Acquisition Intelligence"})]}),e.jsx(es,{value:"traffic",children:p?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(je,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[e.jsx(S,{children:e.jsxs(C,{className:"p-4 text-center",children:[e.jsx(Ne,{className:"w-7 h-7 mx-auto mb-1 text-[#1B4D3E]"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.uniqueVisitors)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Unique Visitors"})]})}),e.jsx(S,{children:e.jsxs(C,{className:"p-4 text-center",children:[e.jsx(je,{className:"w-7 h-7 mx-auto mb-1 text-blue-600"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.repeatVisitors)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Repeat Visitors"})]})}),e.jsx(S,{children:e.jsxs(C,{className:"p-4 text-center",children:[e.jsx(Ve,{className:"w-7 h-7 mx-auto mb-1 text-indigo-600"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.totalPageViews)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Page Views"})]})}),e.jsx(S,{children:e.jsxs(C,{className:"p-4 text-center",children:[e.jsx(ls,{className:"w-7 h-7 mx-auto mb-1 text-purple-600"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.uniqueSessions)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sessions"})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-7 gap-4 mb-6",children:[e.jsx(S,{className:"border-l-4 border-l-amber-500",children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Quotes 
58Started"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.quoteStarted)||0})]})}),e.jsx(S,{className:"border-l-4 border-l-green-500",children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Quotes Saved"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.quoteSaved)||0})]})}),e.jsx(S,{className:"border-l-4 border-l-blue-500",children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Checked Out"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.quoteCheckout)||0})]})}),e.jsx(S,{className:"border-l-4 border-l-pink-500",children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Popup Signups"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.popupSignups)||0})]})}),e.jsx(S,{className:"border-l-4 border-l-orange-500",children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Starts Minus Saved Quotes (Estimate)"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.abandonedCarts)||0})]})}),e.jsx(S,{className:"border-l-4 border-l-cyan-500",children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Chatbot Opens"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.chatbotOpened)||0})]})}),e.jsx(S,{className:"border-l-4 border-l-violet-500",children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Chatbot Messages"}),e.jsx("p",{className:"text-2xl font-bold",children:(a==null?void 0:a.chatbotMessages)||0})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-6",children:[e.jsx(S,{children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Conversion Rate"}),e.jsxs("p",{className:"text-2xl font-bold text-green-600",children:[(a==null?void 0:a.conversionRate)||0,"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Visitors to Saved Quotes"})]})}),e.jsx(S,{children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Quoted Value (Not Revenue)"}),e.jsxs("p",{className:"text-2xl font-bold text-[#1B4D3E]",children:["$",((a==null?void 0:a.revenueFromQuotes)||0).toLocaleString(void 0,{minimumFractionDigits:2})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"From Saved/Checkout Quotes"})]})}),e.jsx(S,{children:e.jsxs(C,{className:"p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Total Leads"}),e.jsx("p",{className:"text-2xl font-bold text-blue-600",children:(a==null?void 0:a.totalLeads)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Email Leads Captured"})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6",children:[e.jsxs(S,{children:[e.jsxs(q,{className:"pb-2",children:[e.jsx(E,{className:"text-base",children:"Daily Traffic"}),e.jsx(te,{children:"Page views over time"})]}),e.jsx(C,{children:((r=a==null?void 0:a.dailyTrends)==null?void 0:r.length)>0?e.jsx("div",{className:"space-y-1",children:a.dailyTrends.map(f=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"w-20 text-muted-foreground shrink-0",children:new Date(f.date+"T12:00:00").toLocaleDateString("en-US",{month:"short",day:"numeric"})}),e.jsx("div",{className:"flex-1 bg-slate-100 rounded-full h-5 overflow-hidden",children:e.jsx("div",{className:"bg-[#1B4D3E] h-full rounded-full flex items-center justify-end pr-2 transition-all",style:{width:`${Math.max(f.pageViews/d*100,8)}%`},children:e.jsx("span",{className:"text-white text-[10px] font-medium",children:f.pageViews})})}),e.jsxs("span",{className:"w-14 text-right text-muted-foreground shrink-0",children:[f.visitors," vis"]})]},f.date))}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No traffic data yet. Events will appear as visitors browse your site."})})]}),e.jsxs(S,{children:[e.jsxs(q,{className:"pb-2",children:[e.jsx(E,{className:"text-base",children:"Conversion Funnel"}),e.jsx(te,{children:"From visitor to checkout"})]}),e.jsx(C,{children:(()=>{const f=(a==null?void 0:a.uniqueVisitors)||0,A=(a==null?void 0:a.quoteStarted)||0,c=(a==null?void 0:a.quoteSaved)||0,R=(a==null?void 0:a.quoteCheckout)||0,I=Math.max(f,1),J=[{label:"Visitors",value:f,color:"bg-slate-400"}
58,{label:"Quote Started",value:A,color:"bg-amber-500"},{label:"Quote Saved",value:c,color:"bg-green-500"},{label:"Checked Out",value:R,color:"bg-blue-600"}];return e.jsx("div",{className:"space-y-3 py-2",children:J.map((Q,ne)=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"font-medium",children:Q.label}),e.jsxs("span",{className:"text-muted-foreground",children:[Q.value,ne>0&&f>0&&e.jsxs("span",{className:"ml-1",children:["(",(Q.value/f*100).toFixed(1),"%)"]})]})]}),e.jsx("div",{className:"bg-slate-100 rounded-full h-6 overflow-hidden",children:e.jsx("div",{className:`${Q.color} h-full rounded-full transition-all`,style:{width:`${Math.max(Q.value/I*100,2)}%`}})})]},Q.label))})})()})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(S,{children:[e.jsx(q,{className:"pb-2",children:e.jsx(E,{className:"text-base",children:"Top Pages"})}),e.jsx(C,{children:((w=a==null?void 0:a.topPages)==null?void 0:w.length)>0?e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Page"}),e.jsx(N,{className:"text-right",children:"Views"})]})}),e.jsx(X,{children:a.topPages.map(f=>e.jsxs(D,{children:[e.jsx(u,{className:"text-sm font-medium",children:f.page}),e.jsx(u,{className:"text-right",children:f.views})]},f.page))})]}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No page data yet"})})]}),e.jsxs(S,{children:[e.jsx(q,{className:"pb-2",children:e.jsx(E,{className:"text-base",children:"Top Referrers"})}),e.jsx(C,{children:((y=a==null?void 0:a.topReferrers)==null?void 0:y.length)>0?e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Source"}),e.jsx(N,{className:"text-right",children:"Visits"})]})}),e.jsx(X,{children:a.topReferrers.map(f=>e.jsxs(D,{children:[e.jsx(u,{className:"text-sm font-medium",children:f.source}),e.jsx(u,{className:"text-right",children:f.count})]},f.source))})]}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No referrer data yet"})})]})]})]})}),e.jsx(es,{value:"acquisition",children:e.jsx(Nn,{dateParams:g})})]})]})}function vn(){const[s,n]=h.useState(0),[t,l]=h.useState(null),o=30,{data:j,isLoading:m,refetch:g}=z({queryKey:["/api/admin/chat-logs",s],queryFn:async()=>(await fetch(`/api/admin/chat-logs?limit=${o}&offset=${s*o}`,{credentials:"include"})).json()}),v=(j==null?void 0:j.logs)||[],a=(j==null?void 0:j.total)||0,p=Math.ceil(a/o),d=x=>new Date(x).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Chat Logs"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Review Stormy's conversations with visitors to check for accuracy. Click any row to expand."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(K,{variant:"secondary",children:[a," conversations"]}),e.jsxs(T,{variant:"outline",size:"sm",onClick:()=>g(),children:[e.jsx(je,{className:"w-4 h-4 mr-1"})," Refresh"]})]})]}),e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-lg p-3 mb-4 flex items-start gap-2",children:[e.jsx(Ws,{className:"w-4 h-4 text-amber-600 shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:["Tip: Look for any answers that seem inaccurate. Stormy's material knowledge has been corrected — clear storm panels are now correctly identified as ",e.jsx("strong",{children:"polycarbonate"}),", not aluminum."]})]}),m?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(je,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):v.length===0?e.jsx(S,{children:e.jsxs(C,{className:"py-12 text-center",children:[e.jsx(Ze,{className:"w-12 h-12 mx-auto text-muted-foreground mb-3 opacity-40"}),e.jsx("p",{className:"font-medium text-muted-foreground",children:"No chat logs yet"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Conversations will appear here as visitors chat with Stormy"})]})}):e.jsx("div",{className:"space-y-2",children:v.map(x=>{var f;const w=((f=(x.messages||[]).filter(A=>A.role==="user")[0])==null?void 0:f.content)||"No messages",y=t===x.id;
58return e.jsxs(S,{className:`cursor-pointer transition-colors ${y?"border-primary shadow-md":"hover:border-muted-foreground/30"}`,children:[e.jsx(q,{className:"pb-2 pt-3 px-4",onClick:()=>l(y?null:x.id),children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"font-medium text-sm truncate text-foreground",children:['"',w,'"']}),e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:d(x.updatedAt||x.createdAt)}),e.jsxs(K,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:[x.messageCount," msg",x.messageCount!==1?"s":""]}),x.page&&e.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[140px]",children:x.page})]})]}),e.jsx(ba,{className:`w-4 h-4 text-muted-foreground shrink-0 transition-transform duration-200 ${y?"rotate-90":""}`})]})}),y&&e.jsx(C,{className:"px-4 pb-4 pt-0",children:e.jsx("div",{className:"border-t pt-3 space-y-3 max-h-[520px] overflow-y-auto pr-1",children:(x.messages||[]).map((A,c)=>e.jsx("div",{className:`flex ${A.role==="user"?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] rounded-2xl px-3.5 py-2.5 text-sm ${A.role==="user"?"bg-primary text-primary-foreground rounded-br-sm":"bg-muted rounded-bl-sm"}`,children:[e.jsx("p",{className:"text-[10px] font-semibold mb-1 opacity-60 uppercase tracking-wide",children:A.role==="user"?"Customer":"Stormy"}),e.jsx("p",{className:"whitespace-pre-wrap leading-relaxed",children:A.content})]})},c))})})]},x.id)})}),p>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4",children:[e.jsx(T,{variant:"outline",size:"sm",onClick:()=>n(x=>Math.max(0,x-1)),disabled:s===0,children:"Previous"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",s+1," of ",p]}),e.jsx(T,{variant:"outline",size:"sm",onClick:()=>n(x=>Math.min(p-1,x+1)),disabled:s>=p-1,children:"Next"})]})]})}function yn(){const s=me(),{toast:n}=re(),t=U({mutationFn:()=>F("POST","/api/admin/email-report/cleanup"),onSuccess:l=>{n({title:`Cleaned up ${l.reclassified??0} records`,description:"Expired and cancelled emails moved out of the failure bucket."}),s.invalidateQueries({queryKey:["/api/admin/email-report"]})},onError:()=>n({title:"Cleanup failed",variant:"destructive"})});return e.jsxs(T,{size:"sm",variant:"outline",onClick:()=>t.mutate(),disabled:t.isPending,className:"flex-shrink-0",children:[t.isPending?e.jsx(je,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(je,{className:"w-4 h-4 mr-2"}),"Fix Historical Records"]})}function wn(){const{data:s,isLoading:n}=z({queryKey:["/api/admin/email-report"]}),t=a=>a?new Date(a).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):"—",l={discount_welcome:"Discount Welcome",cart_abandoned_1:"Abandon Cart #1",cart_abandoned_2:"Abandon Cart #2",cart_abandoned_3:"Abandon Cart #3",cart_abandoned_4:"Abandon Cart #4",quote_saved_1:"Saved Quote #1",quote_saved_2:"Saved Quote #2",quote_saved_3:"Saved Quote #3",quote_saved_4:"Saved Quote #4",quote_saved_5:"Saved Quote #5",quote_checkout_1:"Checkout Follow-up #1",quote_checkout_2:"Checkout Follow-up #2",quote_confirmation:"Quote Confirmation",promo_blast:"Promo Blast",office_notification:"Office Alert",contact_form:"Contact Form",weekly_summary:"Weekly Summary",eom_reminder:"End-of-Month Reminder"},o={promo_popup:"Discount Popup",quote_abandon_popup:"Quote Abandon Popup",quote_form:"Quote Form",footer:"Footer",unknown:"Unknown"};if(n)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(je,{className:"w-6 h-6 animate-spin text-muted-foreground"})});const j=(s==null?void 0:s.queue)??{},m=(s==null?void 0:s.leads)??{},g=(s==null?void 0:s.discountSignups)??{},v=(j.sent??0)+(j.pending??0)+(j.failed??0)+(j.cancelled??0);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:"Email Reports"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Live snapshot of all automated email activity."})]}),e.jsx(yn,{})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-4",children:[{label:"Emails Sent",value:j.sent??0,color:"text-green-600"},{label:"Pending",value:j.pending??0,color:"text-yellow-600"},{label:"True Failures",value:j.failed??0,color:(j.failed??0)>20?"text-red-600":"text-green-600"},{label:"Cancelled/Expired",value:j.cancelled??0,color:"text-muted-foreground"},{label:"Total Leads",value:m.total??0,color:"text-primary"},{label:"Opted Out",value:m.optedOut??0,color:"text-red-500"}].map(a=>e.jsx(S,{children:e.jsxs(C,{className:"p-4 text-center",children:[e.jsx("p",{className:`text-2xl font-bold ${a.color}
58`,children:a.value.toLocaleString()}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:a.label})]})},a.label))}),Object.keys(j.failureReasons??{}).length>0&&e.jsxs(S,{className:"border-orange-200 dark:border-orange-900",children:[e.jsxs(q,{className:"pb-3",children:[e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Ws,{className:"w-4 h-4 text-orange-500"})," Why Emails Are Marked Failed"]}),e.jsx(te,{className:"text-xs",children:"Review failed notifications before resending. Sent means accepted by the email provider, not confirmed inbox delivery. Use the order's Resend Notifications action only after checking the provider for an earlier delivery."})]}),e.jsx(C,{children:e.jsx("div",{className:"space-y-2",children:Object.entries(j.failureReasons??{}).sort(([,a],[,p])=>p-a).map(([a,p])=>{const d=a.includes("Expired")||a.includes("interrupted")||a.includes("opted out");return e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-2 h-2 rounded-full mt-1.5 flex-shrink-0 ${d?"bg-yellow-400":"bg-red-500"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm",children:a}),d&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground italic",children:"— no action needed"})]}),e.jsx("span",{className:"text-sm font-semibold flex-shrink-0",children:p})]},a)})})})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs(S,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Ne,{className:"w-4 h-4"})," Lead Automation Status"]})}),e.jsxs(C,{className:"space-y-2",children:[[{label:"Active — receiving emails",value:m.active??0,bar:"bg-green-500"},{label:"Paused — temporarily suppressed",value:m.paused??0,bar:"bg-yellow-500"},{label:"Stopped — no further emails",value:m.stopped??0,bar:"bg-red-400"},{label:"Opted out / Unsubscribed",value:m.optedOut??0,bar:"bg-slate-400"}].map(a=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${a.bar} flex-shrink-0`}),e.jsx("span",{className:"text-sm flex-1",children:a.label}),e.jsx("span",{className:"text-sm font-semibold",children:a.value})]},a.label)),e.jsxs("div",{className:"pt-2 border-t border-border",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-blue-400 flex-shrink-0"}),e.jsx("span",{className:"text-sm flex-1",children:"Discount signups (popup)"}),e.jsx("span",{className:"text-sm font-semibold",children:g.total??0})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-blue-200 flex-shrink-0"}),e.jsx("span",{className:"text-sm flex-1",children:"Welcome email sent"}),e.jsx("span",{className:"text-sm font-semibold",children:g.emailSent??0})]})]})]})]}),e.jsxs(S,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Ve,{className:"w-4 h-4"})," Lead Sources"]})}),e.jsx(C,{children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Source"}),e.jsx(N,{className:"text-right",children:"Leads"})]})}),e.jsxs(X,{children:[Object.entries(m.sources??{}).sort(([,a],[,p])=>p-a).map(([a,p])=>e.jsxs(D,{children:[e.jsx(u,{className:"text-sm",children:o[a]??a}),e.jsx(u,{className:"text-right font-semibold",children:p})]},a)),Object.keys(m.sources??{}).length===0&&e.jsx(D,{children:e.jsx(u,{colSpan:2,className:"text-center text-muted-foreground text-sm py-4",children:"No data yet"})})]})]})})]})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs(S,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(as,{className:"w-4 h-4"})," Abandon Cart Sequence"]}),e.jsx(te,{className:"text-xs",children:"Leads currently at each email step (active or completed)"})]}),e.jsx(C,{className:"space-y-2",children:(m.abandonFunnel??[0,0,0,0]).map((a,p)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-xs text-muted-foreground w-20 flex-shrink-0",children:["Email ",p+1]}),e.jsx("div",{className:"flex-1 bg-muted rounded-full h-2 overflow-hidden",children:e.jsx("div",{className:"h-2 rounded-full bg-accent transition-all",style:{width:m.total>0?`${Math.min(100,a/(m.total||1)*100)}%`:"0%"}})}),e.jsx("span",{className:"text-sm font-semibold w-8 text-right",children:a})]},p))})]}),e.jsxs(S,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx($e,{className:"w-4 h-4"})," Saved Quote Sequence"]}),e.jsx(te,{className:"text-xs",children:"Leads currently at each email step (active or completed)"})]}),e.jsx(C,{className:"space-y-2",children:(m.savedFunnel??[0,0,0,0,0]).map((a,p)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-xs text-muted-foreground w-20 flex-shrink-0",children:["Email ",p+1]}),e.jsx("div",{className:"flex-1 bg-muted rounded-full h-2 overflow-hidden",children:e.jsx("div",{className:"h-2 rounded-full bg-primary transition-all",style:{width:m.total>0?`${Math.min(100,a/(m.total||1)*100)}%`:"0%"}})}),e.jsx("span",{className:"text-sm font-semibold w-8 text-right",children:a})]},p))})]})]}),e.jsxs(S,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(Ye,{className:"w-4 h-4"})," Breakdown by Email Type"]}),e.jsx(te,{className:"text-xs",children:"Total emails in the system b
58y template, all time"})]}),e.jsx(C,{children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Email Type"}),e.jsx(N,{className:"text-center",children:"Sent"}),e.jsx(N,{className:"text-center",children:"Pending"}),e.jsx(N,{className:"text-center",children:"Failed"}),e.jsx(N,{className:"text-center",children:"Cancelled"}),e.jsx(N,{className:"text-right",children:"Total"})]})}),e.jsxs(X,{children:[Object.entries(j.byType??{}).sort(([,a],[,p])=>p.sent+p.pending-(a.sent+a.pending)).map(([a,p])=>e.jsxs(D,{children:[e.jsx(u,{className:"text-sm font-medium",children:l[a]??a}),e.jsx(u,{className:"text-center text-green-600 font-semibold",children:p.sent}),e.jsx(u,{className:"text-center text-yellow-600",children:p.pending}),e.jsx(u,{className:"text-center text-red-600",children:p.failed}),e.jsx(u,{className:"text-center text-muted-foreground",children:p.cancelled}),e.jsx(u,{className:"text-right font-semibold",children:p.sent+p.pending+p.failed+p.cancelled})]},a)),Object.keys(j.byType??{}).length===0&&e.jsx(D,{children:e.jsx(u,{colSpan:6,className:"text-center text-muted-foreground text-sm py-6",children:"No email data yet"})}),v>0&&e.jsxs(D,{className:"bg-muted/40 font-semibold",children:[e.jsx(u,{children:"Total"}),e.jsx(u,{className:"text-center text-green-600",children:j.sent}),e.jsx(u,{className:"text-center text-yellow-600",children:j.pending}),e.jsx(u,{className:"text-center text-red-600",children:j.failed}),e.jsx(u,{className:"text-center text-muted-foreground",children:j.cancelled}),e.jsx(u,{className:"text-right",children:v})]})]})]})})]}),e.jsxs(S,{children:[e.jsx(q,{className:"pb-3",children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(ve,{className:"w-4 h-4"})," Recent Sent Emails (last 30)"]})}),e.jsx(C,{children:e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{children:"Recipient"}),e.jsx(N,{children:"Email Type"}),e.jsx(N,{children:"Sent At"})]})}),e.jsxs(X,{children:[(j.recentSent??[]).length===0&&e.jsx(D,{children:e.jsx(u,{colSpan:3,className:"text-center text-muted-foreground text-sm py-6",children:"No sent emails yet"})}),(j.recentSent??[]).map(a=>e.jsxs(D,{children:[e.jsxs(u,{className:"text-sm",children:[e.jsx("div",{className:"font-medium",children:a.recipientName||"—"}),e.jsx("div",{className:"text-muted-foreground text-xs",children:a.recipientEmail})]}),e.jsx(u,{className:"text-sm",children:l[a.emailType]??a.emailType}),e.jsx(u,{className:"text-sm text-muted-foreground",children:t(a.sentAt)})]},a.id))]})]})})]})]})}const Ms={A:{label:"Control",headline:"Custom Hurricane Shutters — Built in Florida, Shipped Nationwide"},B:{label:"No Dealer Markup",headline:"Hurricane Shutters Direct from the Manufacturer — No Dealer Markup"},C:{label:"Stop Overpaying",headline:"Stop Overpaying for Hurricane Shutters. Buy Direct, Save Big."},D:{label:"Factory Prices",headline:"Custom Hurricane Shutters, Factory Prices — Protect Your Home for Less"}};function Sn(){var a,p;const[s,n]=h.useState(()=>{const d=new Date;return d.setDate(d.getDate()-90),d.toISOString().split("T")[0]}),[t,l]=h.useState(()=>new Date().toISOString().split("T")[0]),{data:o,isLoading:j}=z({queryKey:["/api/admin/analytics/ab-test",s,t],queryFn:async()=>(await fetch(`/api/admin/analytics/ab-test?from=${s}&to=${t}`,{credentials:"include"})).json()}),m=o?(a=[...o].sort((d,x)=>x.checkoutRate-d.checkoutRate)[0])==null?void 0:a.variant:null,g=o?(p=[...o].sort((d,x)=>x.quoteStartedRate-d.quoteStartedRate)[0])==null?void 0:p.variant:null,v=o?o.reduce((d,x)=>d+x.visitors,0):0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:"Headline Test Results"}),e.jsx(K,{className:"bg-slate-100 text-slate-700 border-0",children:"Concluded"})]}),e.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:"Variant D, Factory Prices, is now the permanent homepage headline. Historical results remain available below."})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"text-xs text-muted-foreground",children:"From"}),e.jsx(O,{type:"date",value:s,onChange:d=>n(d.target.value),className:"w-36 h-8 text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"text-xs text-muted-foreground",children:"To"}),e.jsx(O,{type:"date",value:t,onChange:d=>l(d.target.value),className:"w-36 h-8 text-sm"})]}),v>0&&e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:[v.toLocaleStr
58ing()," total assigned visitors"]})]}),e.jsxs(S,{children:[e.jsxs(q,{className:"pb-3",children:[e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(is,{className:"w-4 h-4 text-primary"}),"Headline Performance"]}),e.jsx(te,{className:"text-xs",children:"Rates = unique visitors who completed each step ÷ visitors assigned to that variant."})]}),e.jsx(C,{className:"p-0",children:j?e.jsx("div",{className:"p-8 text-center text-muted-foreground text-sm",children:"Loading..."}):e.jsxs(Y,{children:[e.jsx(Z,{children:e.jsxs(D,{children:[e.jsx(N,{className:"w-8",children:"Var."}),e.jsx(N,{children:"Headline"}),e.jsx(N,{className:"text-right w-20",children:"Visitors"}),e.jsx(N,{className:"text-right w-28",children:"Quote Started"}),e.jsx(N,{className:"text-right w-28",children:"Quote Saved"}),e.jsx(N,{className:"text-right w-28",children:"Checkout"})]})}),e.jsxs(X,{children:[(o||[]).map(d=>{const x=Ms[d.variant]||{label:d.variant,headline:""},r=d.variant===m&&d.checkoutRate>0,w=d.variant===g&&d.quoteStartedRate>0;return e.jsxs(D,{className:r?"bg-emerald-50 dark:bg-emerald-950/20":"",children:[e.jsx(u,{className:"font-bold text-primary text-lg",children:d.variant}),e.jsxs(u,{children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:x.label}),r&&e.jsx(K,{className:"text-[10px] bg-emerald-100 text-emerald-800 dark:bg-emerald-900 dark:text-emerald-200 border-0 py-0",children:"🏆 Best checkout"}),w&&!r&&e.jsx(K,{className:"text-[10px] bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200 border-0 py-0",children:"⚡ Best start rate"})]}),e.jsx("p",{className:"text-sm text-foreground mt-0.5 leading-snug",children:x.headline})]}),e.jsx(u,{className:"text-right font-medium",children:d.visitors.toLocaleString()}),e.jsxs(u,{className:"text-right",children:[e.jsx("div",{className:"text-sm font-semibold text-amber-600",children:d.quoteStarted}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[d.quoteStartedRate.toFixed(1),"%"]})]}),e.jsxs(u,{className:"text-right",children:[e.jsx("div",{className:"text-sm font-semibold text-green-600",children:d.quoteSaved}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[d.quoteSavedRate.toFixed(1),"%"]})]}),e.jsxs(u,{className:"text-right",children:[e.jsx("div",{className:"text-sm font-semibold text-emerald-700",children:d.checkout}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[d.checkoutRate.toFixed(1),"%"]})]})]},d.variant)}),(!o||o.length===0)&&e.jsx(D,{children:e.jsx(u,{colSpan:6,className:"text-center text-muted-foreground py-8 text-sm",children:"No historical test data is available for this date range."})})]})]})})]}),o&&o.some(d=>d.visitors>0)&&e.jsx("div",{className:"grid sm:grid-cols-2 xl:grid-cols-4 gap-4",children:o.map(d=>{const x=Ms[d.variant]||{label:d.variant};return e.jsxs(S,{className:d.variant===m&&d.checkoutRate>0?"border-emerald-500 border-2":"",children:[e.jsxs(q,{className:"pb-2",children:[e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"text-lg font-bold text-primary",children:d.variant}),e.jsx("span",{className:"text-muted-foreground font-normal",children:x.label})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[d.visitors," visitors"]})]}),e.jsx(C,{className:"space-y-3 pt-0",children:[{label:"Quote Started",value:d.quoteStartedRate,color:"bg-amber-500",count:d.quoteStarted},{label:"Quote Saved",value:d.quoteSavedRate,color:"bg-green-500",count:d.quoteSaved},{label:"Checkout",value:d.checkoutRate,color:"bg-emerald-600",count:d.checkout}].map(r=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-muted-foreground",children:r.label}),e.jsxs("span",{className:"font-semibold",children:[r.count," · ",r.value.toFixed(1),"%"]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2",children:e.jsx("div",{className:`${r.color} h-2 rounded-full transition-all duration-500`,style:{width:`${Math.min(r.value,100)}%`}})})]},r.label))})]},d.variant)})}),e.jsx(S,{className:"bg-muted/40",children:e.jsx(C,{className:"pt-4 pb-4",children:e.jsxs("p",{className:"text-xs text-muted-foreground leading-relaxed",children:[e.jsx("strong",{children:"Test concluded:"})," Visitors were assigned variants A through D and conversion events were attributed to the assigned headline. Variant D was selected as the permanent homepage headline. New visitors are no longer assigned a test variant, while this report preserves the historical results."]})})})]})}export{An 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.