1import{a as H,r as o,j as e,m as te,R as se,O as ae}from"./react-vendor-834d7d6d.js";import{X as ne,M as R,p as V,m as E,s as p,q as re,z as P}from"./index-7dccf6da.js";import{u as q}from"./useUser-095b4654.js";import{g as G,f as ie,a as U}from"./utils-dad28b47.js";import{m as y,A as S}from"./animation-vendor-78ea158c.js";import{C as le}from"./chevron-right-0a4fcccb.js";import{C as oe}from"./chevron-left-f8efa3a4.js";import{L as A}from"./log-out-869bf8fa.js";import{L as ce}from"./layout-dashboard-a51c17ae.js";import{P as W}from"./phone-899cbbb6.js";import{B as de}from"./bar-chart-3-5b1746c4.js";import{C as xe}from"./credit-card-3076944a.js";import{H as me}from"./headphones-d2c624cf.js";import{S as Y}from"./settings-f2a3ae7c.js";import{U as he}from"./users-7354667f.js";import{P as ue}from"./plug-368ffe48.js";import{H as pe}from"./help-circle-d8712315.js";import{u as X}from"./useQuery-87f7e096.js";import{u as Z}from"./useMutation-9346c5b9.js";import{m as fe,a as be}from"./mappers-939d4528.js";import{u as ge}from"./useLocations-1c65f871.js";import{u as we,L as ve}from"./LocationContext-27574cef.js";import{C as J}from"./chevron-down-6b878b0e.js";import{B as je}from"./building-2-966f6eed.js";import{C as Q}from"./check-35b38bb8.js";import{S as O}from"./search-8e2f2e24.js";import{B as K}from"./bell-16f9cd8c.js";import{U as Ne}from"./user-0bc3fa71.js";import{A as ye}from"./alert-triangle-3f036724.js";import{R as Fe}from"./refresh-cw-2ca0b8d5.js";import{u as ke,P as ze}from"./PlanSelectionModal-f751e278.js";import"./posthog-vendor-82586d23.js";import"./clsx-0839fdbe.js";import"./n8n-981240fe.js";import"./pricingData-d0a8932a.js";import"./crown-3c1bd25a.js";import"./dollar-sign-ec7c27ce.js";import"./clock-9a595fca.js";import"./file-text-2bfbb968.js";import"./x-circle-d53a670c.js";import"./shield-c8441123.js";import"./shield-check-01cdbffa.js";import"./zap-23cd3b4d.js";import"./arrow-right-e3d19d84.js";const Ce=[{label:"MAIN",items:[{to:"/dashboard",icon:ce,label:"Overview",end:!0},{to:"/dashboard/calls",icon:W,label:"Calls"},{to:"/dashboard/analytics",icon:de,label:"Analytics"},{to:"/dashboard/billing",icon:xe,label:"Billing"}]},{label:"CONFIGURE",items:[{to:"/dashboard/ai-agent",icon:me,label:"Receptionist"},{to:"/dashboard/settings",icon:Y,label:"Settings"}]},{label:"MANAGE",items:[{to:"/dashboard/locations",icon:R,label:"Locations",custom:!0},{to:"/dashboard/team",icon:he,label:"Team"},{to:"/dashboard/integrations",icon:ue,label:"Integrations"}]},{label:"SUPPORT",items:[{to:"/dashboard/support",icon:pe,label:"Help"}]}];function _e({collapsed:t,setCollapsed:s,mobileOpen:n,setMobileOpen:a}){var x,w;const l=H(),{data:r}=q(),[i,m]=o.useState(!1),h={companyName:((x=r==null?void 0:r.tenant)==null?void 0:x.company_name)||"Title Voice",email:((w=r==null?void 0:r.profile)==null?void 0:w.email)||""},g=async()=>{m(!0);const{error:v}=await V();v&&console.error("Logout failed:",v),l("/login")},u=(v=!1)=>{const d=t&&!v;return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:`flex items-center h-16 flex-shrink-0 border-b border-white/[0.06] ${d?"justify-center":"justify-between px-5"}`,children:[d?e.jsx("a",{href:"https://www.titlevoice.ai",target:"_blank",rel:"noopener noreferrer",className:"group",children:e.jsxs("div",{className:"relative",children:[e.jsxs("picture",{children:[e.jsx("source",{srcSet:"/logo-dark-64.webp 64w, /logo-dark-128.webp 128w, /logo-dark.webp 256w",sizes:"36px",type:"image/webp"}),e.jsx("img",{src:"/logo-dark.png",srcSet:"/logo-dark-64.png 64w, /logo-dark-128.png 128w, /logo-dark.png 256w",sizes:"36px",alt:"Title Voice",width:36,height:36,fetchpriority:"high",className:"w-9 h-9 rounded-xl object-cover ring-1 ring-white/[0.08] group-hover:ring-[#0080FF]/30 transition-all duration-300"})]}),e.jsx("div",{className:"absolute inset-0 rounded-xl bg-[#0080FF]/0 group-hover:bg-[#0080FF]/10 transition-all duration-300"})]})}):e.jsxs("a",{href:"https://www.titlevoice.ai",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-3 group",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("picture",{children:[e.jsx("source",{srcSet:"/logo-dark-64.webp 64w, /logo-dark-128.webp 128w, /logo-dark.webp 256w",sizes:"36px",type:"image/webp"}),e.jsx("img",{src:"/logo-dark.png",srcSet:"/logo-dark-64.png 64w, /logo-dark-128.png 128w, /logo-dark.png 256w",sizes:"36px",alt:"Title V
1oice",width:36,height:36,fetchpriority:"high",className:"w-9 h-9 rounded-xl object-cover ring-1 ring-white/[0.08] group-hover:ring-[#0080FF]/30 transition-all duration-300"})]}),e.jsx("div",{className:"absolute inset-0 rounded-xl bg-[#0080FF]/0 group-hover:bg-[#0080FF]/10 transition-all duration-300"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[15px] font-bold text-white tracking-tight block",children:"Title Voice"}),e.jsx("span",{className:"text-[10px] text-zinc-500 font-medium",children:"Dashboard"})]})]}),v&&e.jsx("button",{onClick:()=>a(!1),className:"p-2 rounded-xl hover:bg-white/[0.06] text-zinc-400 hover:text-white transition-colors",children:e.jsx(ne,{className:"w-5 h-5"})})]}),e.jsx("nav",{className:`flex-1 overflow-y-auto py-4 space-y-1 ${d?"px-2":"px-3"}`,children:Ce.map((F,z)=>e.jsxs("div",{children:[z>0&&e.jsx("div",{className:`my-3 ${d?"mx-1":"mx-2"}`,children:e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-white/[0.06] to-transparent"})}),!d&&e.jsx("p",{className:"px-3 mb-2 text-[10px] font-semibold text-zinc-500/80 uppercase tracking-[0.18em]",children:F.label}),e.jsx("div",{className:`space-y-0.5 ${d?"flex flex-col items-center":""}`,children:F.items.map(b=>e.jsx(te,{to:b.to,end:b.end,onClick:()=>a(!1),className:({isActive:j})=>`group relative flex items-center rounded-xl text-sm font-medium transition-all duration-200 ${d?`w-10 h-10 justify-center ${j?"bg-[#0080FF]/[0.12] text-white shadow-[0_0_12px_rgba(0,128,255,0.08)]":"text-zinc-500 hover:text-zinc-300 hover:bg-white/[0.05]"}`:`gap-3 px-3 py-2.5 ${j?"bg-[#0080FF]/[0.08] text-white":"text-zinc-500 hover:text-zinc-300 hover:bg-white/[0.04]"}`}`,children:({isActive:j})=>{var k,f;return e.jsxs(e.Fragment,{children:[j&&!d&&e.jsx(y.div,{layoutId:"nav-indicator",className:"absolute left-0 top-1/2 -translate-y-1/2 w-[3px] h-5 rounded-r-full bg-[#0080FF] shadow-[0_0_8px_rgba(0,128,255,0.5)]",transition:{type:"spring",stiffness:350,damping:30}}),j&&d&&e.jsx(y.div,{layoutId:"nav-dot",className:"absolute -left-0.5 top-1/2 -translate-y-1/2 w-1 h-1 rounded-full bg-[#0080FF] shadow-[0_0_6px_rgba(0,128,255,0.6)]",transition:{type:"spring",stiffness:350,damping:30}}),e.jsx(b.icon,{className:`flex-shrink-0 transition-colors duration-200 ${d?"w-[18px] h-[18px]":"w-[17px] h-[17px]"} ${j?"text-[#0080FF]":"text-zinc-500 group-hover:text-zinc-300"}`}),!d&&e.jsx("span",{className:"truncate",children:b.label}),!d&&b.custom&&((k=r==null?void 0:r.tenant)==null?void 0:k.plan)!=="custom"&&e.jsx("span",{className:"ml-auto px-1.5 py-0.5 rounded text-[9px] font-bold tracking-wider bg-gradient-to-r from-[#0080FF]/15 to-[#4F1AD6]/15 text-[#0080FF] border border-[#0080FF]/20",children:"CUSTOM"}),d&&e.jsxs("div",{className:"absolute left-full ml-3 px-3 py-1.5 rounded-lg bg-[#111119]/95 backdrop-blur-xl border border-white/[0.08] text-[11px] text-white font-medium whitespace-nowrap opacity-0 group-hover:opacity-100 pointer-events-none transition-all duration-150 shadow-xl shadow-black/40 z-50 translate-x-1 group-hover:translate-x-0",children:[b.label,b.custom&&((f=r==null?void 0:r.tenant)==null?void 0:f.plan)!=="custom"&&e.jsx("span",{className:"ml-1.5 text-[9px] text-[#0080FF] font-bold",children:"CUSTOM"})]})]})}},b.to))})]},F.label))}),e.jsx("div",{className:"hidden lg:block px-3 py-2",children:e.jsxs("button",{onClick:()=>s(!t),className:`group flex items-center justify-center rounded-xl text-zinc-500 hover:text-zinc-300 hover:bg-white/[0.04] transition-all duration-200 ${d?"w-10 h-10 mx-auto":"w-full gap-2 px-3 py-2.5"}`,children:[e.jsx("div",{className:`flex items-center justify-center rounded-lg transition-all duration-200 ${d?"":"w-6 h-6 bg-white/[0.04] group-hover:bg-white/[0.08]"}`,children:t?e.jsx(le,{className:"w-3.5 h-3.5"}):e.jsx(oe,{className:"w-3.5 h-3.5"})}),!d&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})}),e.jsx("div",{className:`border-t border-white/[0.06] ${d?"px-2 py-3":"px-3 py-3"}`,children:e.jsxs("div",{className:`group relative ${d?"flex justify-center":""}`,children:[e.jsxs("div",{className:`flex items-center gap-3 ${d?"justify-center":""}`,children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-gradient-to-br from-[#0080FF]/20 to-[#4F1AD6]/20 border border-white/[0.08] flex items-center justify-center transition-all duration-200 group-hover:border-[#0080FF]/20 group-hover:shadow-[0_0_12px_rgba(0,128,255,0.08)]",children:e.jsx("span",{className:"text-[11px] font-bold bg-gradient-to-br from-[#0080FF] to-[#4F1AD6] bg-clip-text text-transparent",children:G(h.companyName)})}),e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full bg-emerald-400 border-2 border-[#0a0a0f]"})]}),!d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-semibold text-zinc-200 truncate",children:h.companyName}),e.jsx("p",{className:"text-[11px] text-zinc-500 truncate",children:h.email})]}),e.jsx("button",{onClick:g,disabled:i,className:"p-2 rounded-xl text-zinc-600 hover:text-red-400 hover:bg-red-400/[0.06] transition-all duration-200",children:e.jsx(A,{className:"w-4 h-4"})})]})]}),d&&e.jsxs("div",{className:"absolute left-full ml-3 bottom-0 min-w-[180px] rounded-xl bg-[#111119]/95 backdrop-blur-xl border border-white/[0.08] opacity-0 group-hover:opacity-100 pointer-events-none group-hover:pointer-events-auto transition-all duration-150 shadow-xl shadow-black/40 z-50 translate-x-1 group-hover:translate-x-0 overflow-hidden",children:[e.jsxs("div",{className:"px-3.5 py-3 border-b border-white/[0.06]",children:[e.jsx("p",{className:"text-[12px] font-semibold text-zinc-200 truncate",children:h.companyName}),e.jsx("p",{className:"text-[10px] text-zinc-500 truncate mt-0.5",children:h.email})]}),e.jsxs("button",{onClick:g,disabled:i,className:"w-full flex items-center gap-2 px-3.5 py-2.5 text-[11px] text-zinc-400 hover:text-red-400 hover:bg-red-400/[0.06] transition-all",children:[e.jsx(A,{className:"w-3.5 h-3.5"}),i?"Signing out...":"Sign out"]})]})]})})]})};return e.jsxs(e.Fragment,{children:[e.jsxs(y.aside,{initial:!1,animate:{width:t?72:260},transition:{duration:.2,ease:[.25,.46,.45,.94]},className:"hidden lg:flex flex-col fixed left-0 top-0 bottom-0 z-40 bg-[#0a0a0f]/80 backdrop-blur-2xl border-r border-white/[0.06]",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-[#0080FF]/[0.02] via-trans
1parent to-[#4F1AD6]/[0.01] pointer-events-none"}),e.jsx("div",{className:"relative z-10 flex flex-col h-full",children:u()})]}),e.jsx(S,{children:n&&e.jsxs(e.Fragment,{children:[e.jsx(y.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>a(!1),className:"fixed inset-0 z-40 bg-black/70 backdrop-blur-sm lg:hidden"}),e.jsxs(y.aside,{initial:{x:-280},animate:{x:0},exit:{x:-280},transition:{type:"spring",stiffness:350,damping:30},className:"fixed left-0 top-0 bottom-0 z-50 w-[260px] bg-[#0a0a0f]/90 backdrop-blur-2xl border-r border-white/[0.06] lg:hidden",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-[#0080FF]/[0.02] via-transparent to-[#4F1AD6]/[0.01] pointer-events-none"}),e.jsx("div",{className:"relative z-10 flex flex-col h-full",children:u(!0)})]})]})})]})}function Se(){const t=E(),[s,n]=o.useState(null),a=X({queryKey:["notifications"],queryFn:async()=>{const{data:l,error:r}=await p.auth.getUser();if(r)throw r;const i=l==null?void 0:l.user;if(!i)throw new Error("Not authenticated");n(g=>g===i.id?g:i.id);const{data:m,error:h}=await p.from("notifications").select("*").eq("user_id",i.id).order("created_at",{ascending:!1}).limit(20);if(h)throw h;return(m||[]).map(fe)}});return o.useEffect(()=>{if(!s)return;const l=p.channel("notifications_realtime").on("postgres_changes",{event:"INSERT",schema:"public",table:"notifications",filter:`user_id=eq.${s}`},()=>{t.invalidateQueries({queryKey:["notifications"]})}).subscribe();return()=>{p.removeChannel(l)}},[t,s]),a}function Ee(){const t=E();return Z({mutationFn:async s=>{const{error:n}=await p.from("notifications").update({is_read:!0}).eq("id",s);if(n)throw n;return s},onMutate:async s=>{await t.cancelQueries({queryKey:["notifications"]});const n=t.getQueryData(["notifications"]);return t.setQueryData(["notifications"],a=>a&&a.map(l=>l.id===s?{...l,isRead:!0}:l)),{prev:n}},onError:(s,n,a)=>{(a==null?void 0:a.prev)!==void 0&&t.setQueryData(["notifications"],a.prev)},onSettled:()=>t.invalidateQueries({queryKey:["notifications"]})})}function Le(){const t=E();return Z({mutationFn:async()=>{const{data:s}=await p.auth.getUser(),n=s==null?void 0:s.user;if(!n)return;const{error:a}=await p.from("notifications").update({is_read:!0}).eq("user_id",n.id).eq("is_read",!1);if(a)throw a},onMutate:async()=>{await t.cancelQueries({queryKey:["notifications"]});const s=t.getQueryData(["notifications"]);return t.setQueryData(["notifications"],n=>n&&n.map(a=>({...a,isRead:!0}))),{prev:s}},onError:(s,n,a)=>{(a==null?void 0:a.prev)!==void 0&&t.setQueryData(["notifications"],a.prev)},onSettled:()=>t.invalidateQueries({queryKey:["notifications"]})})}function qe(){const t=E(),[s,n]=o.useState(null);o.useEffect(()=>{p.auth.getUser().then(({data:l})=>{const r=l==null?void 0:l.user;r&&p.from("users").select("tenant_id").eq("id",r.id).single().then(({data:i})=>{i!=null&&i.tenant_id&&n(m=>m===i.tenant_id?m:i.tenant_id)})})},[]);const a=X({queryKey:["activeCalls",s],queryFn:async()=>{if(!s)return[];const{data:l,error:r}=await p.from("active_calls").select("*").eq("tenant_id",s).order("started_at",{ascending:!1});if(r)throw r;return(l||[]).map(be)},enabled:!!s});return o.useEffect(()=>{if(!s)return;const l=p.channel("active_calls_changes").on("postgres_changes",{event:"INSERT",schema:"public",table:"active_calls",filter:`tenant_id=eq.${s}`},()=>{t.invalidateQueries({queryKey:["activeCalls",s]})}).on("postgres_changes",{event:"DELETE",schema:"public",table:"active_calls",filter:`tenant_id=eq.${s}`},()=>{t.invalidateQueries({queryKey:["activeCalls",s]})}).subscribe();return()=>{p.removeChannel(l)}},[t,s]),a}function Re(){var u;const{data:t}=q(),{data:s=[]}=ge(),{activeLocationId:n,setActiveLocationId:a}=we(),[l,r]=o.useState(!1),i=o.useRef(null);if(!(((u=t==null?void 0:t.tenant)==null?void 0:u.plan)==="custom")||s.length<=1)return null;const h=n?s.find(x=>x.id===n):null,g=(h==null?void 0:h.name)||"All Locations";return o.useEffect(()=>{const x=w=>{i.current&&!i.current.contains(w.target)&&r(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[]),e.jsxs("div",{ref:i,className:"relative hidden sm:block",children:[e.jsxs(y.button,{onClick:()=>r(x=>!x),whileHover:{scale:1.02},whileTap:{scale:.98},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-white/[0.04] border border-white/[0.08] hover:border-white/[0.14] transition-all",children:[e.jsx(R,{className:"w-3 h-3 text-[#0080FF]"}),e.jsx("span",{className:"text-xs font-medium text-zinc-300 max-w-[120px] truncate",children:g}),e.jsx(J,{className:`w-3 h-3 text-zinc-500 transition-transform ${l?"rotate-180":""}`})]}),e.jsx(S,{children:l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>r(!1)}),e.jsxs(y.div,{initial:{opacity:0,y:6,scale:.97}
1,animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:6,scale:.97},transition:{duration:.12},className:"absolute left-0 top-full mt-1.5 w-56 z-50 bg-[#0c0c14]/95 backdrop-blur-2xl border border-zinc-800 rounded-xl shadow-2xl shadow-black/40 overflow-hidden",children:[e.jsx("div",{className:"px-3 py-2 border-b border-zinc-800/50",children:e.jsx("p",{className:"text-[10px] text-zinc-500 font-semibold uppercase tracking-wider",children:"View Location"})}),e.jsxs("div",{className:"py-1",children:[e.jsxs("button",{onClick:()=>{a(null),r(!1)},className:"w-full flex items-center gap-2.5 px-3 py-2 text-sm hover:bg-white/[0.04] transition-colors group",children:[e.jsx("div",{className:"w-6 h-6 rounded-lg bg-[#0080FF]/10 flex items-center justify-center flex-shrink-0",children:e.jsx(je,{className:"w-3 h-3 text-[#0080FF]"})}),e.jsx("span",{className:`flex-1 text-left text-xs font-medium truncate ${n?"text-zinc-400 group-hover:text-zinc-300":"text-white"}`,children:"All Locations"}),!n&&e.jsx(Q,{className:"w-3 h-3 text-[#0080FF] flex-shrink-0"})]}),s.map(x=>{const w=n===x.id,v=!!x.retell_agent_id;return e.jsxs("button",{onClick:()=>{a(x.id),r(!1)},className:"w-full flex items-center gap-2.5 px-3 py-2 text-sm hover:bg-white/[0.04] transition-colors group",children:[e.jsx("div",{className:"w-6 h-6 rounded-lg bg-white/[0.04] border border-zinc-800 flex items-center justify-center flex-shrink-0",children:e.jsx(R,{className:"w-3 h-3 text-zinc-500"})}),e.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[e.jsx("p",{className:`text-xs font-medium truncate ${w?"text-white":"text-zinc-400 group-hover:text-zinc-300"}`,children:x.name}),!v&&e.jsx("p",{className:"text-[9px] text-amber-500/80 font-medium",children:"Setup required"})]}),w&&e.jsx(Q,{className:"w-3 h-3 text-[#0080FF] flex-shrink-0"})]},x.id)})]})]})]})})]})}function Ae({startedAt:t}){const[s,n]=o.useState("");return o.useEffect(()=>{const a=()=>{const r=new Date(t).getTime();if(isNaN(r)){n("00:00");return}const i=Math.max(0,Math.floor((Date.now()-r)/1e3)),m=String(Math.floor(i/60)).padStart(2,"0"),h=String(i%60).padStart(2,"0");n(`${m}:${h}`)};a();const l=setInterval(a,1e3);return()=>clearInterval(l)},[t]),e.jsx(y.span,{animate:{opacity:[1,.5,1]},transition:{duration:1.5,repeat:1/0},className:"text-xs text-[#0080FF] font-semibold tabular-nums flex-shrink-0",children:s})}const B=[{label:"Overview",path:"/dashboard",keywords:"home dashboard overview stats"},{label:"Calls",path:"/dashboard/calls",keywords:"calls history phone log"},{label:"Analytics",path:"/dashboard/analytics",keywords:"analytics charts reports heatmap"},{label:"Billing",path:"/dashboard/billing",keywords:"billing invoices payment plan subscription"},{label:"Receptionist",path:"/dashboard/ai-agent",keywords:"receptionist voice greeting faq configuration taylor"},{label:"Integrations",path:"/dashboard/integrations",keywords:"integrations crm connect software"},{label:"Locations",path:"/dashboard/locations",keywords:"locations offices branches multi-location"},{label:"Team",path:"/dashboard/team",keywords:"team members invite roles access"},{label:"Settings",path:"/dashboard/settings",keywords:"settings company phone notifications account"},{label:"Support",path:"/dashboard/support",keywords:"support help docs chat email"}];function Te({onMenuClick:t}){var M,$;const s=H(),{data:n}=q(),{data:a=[]}=Se(),{data:l=[]}=qe(),r=Ee(),i=Le(),m={companyName:((M=n==null?void 0:n.tenant)==null?void 0:M.company_name)||"Title Voice",email:(($=n==null?void 0:n.profile)==null?void 0:$.email)||""},h=c=>r.mutate(c),g=()=>i.mutate(),[u,x]=o.useState(!1),[w,v]=o.useState(!1),[d,F]=o.useState(!1),[z,b]=o.useState(!1),[j,k]=o.useState(""),f=o.useRef(null),C=a.filter(c=>!c.read).length,L=j?B.filter(c=>c.label.toLowerCase().includes(j.toLowerCase())||c.keywords.includes(j.toLowerCase())):B;o.useEffect(()=>{z&&f.current&&f.current.focus()},[z]),o.useEffect(()=>{const c=_=>{(_.metaKey||_.ctrlKey)&&_.key==="k"&&(_.preventDefault(),b(N=>!N),k("")),_.key==="Escape"&&(b(!1),v(!1),x(!1),F(!1))};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[]);const D=async()=>{const{error:c}=await V();c&&console.error("Logout failed:",c),s("/login")},T=c=>{s(c),b(!1),k("")}
1,I=parseInt(new Date().toLocaleString("en-US",{timeZone:"America/New_York",hour:"numeric",hour12:!1}),10),ee=I<12?"Good morning":I<17?"Good afternoon":"Good evening";return e.jsxs("header",{className:"h-14 border-b border-zinc-800/50 bg-[#050508]/60 backdrop-blur-xl flex items-center justify-between px-4 lg:px-6 sticky top-0 z-30",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:t,className:"lg:hidden p-2 -ml-1 rounded-lg hover:bg-white/5 text-zinc-500",children:e.jsx(re,{className:"w-5 h-5"})}),e.jsxs("p",{className:"text-sm text-zinc-500 hidden sm:block",children:[ee,", ",e.jsx("span",{className:"text-zinc-300 font-medium",children:m.companyName})]}),e.jsx(Re,{})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("div",{className:"relative hidden sm:block mr-3",children:[e.jsxs(y.button,{onClick:()=>F(!d),whileHover:{scale:1.02},whileTap:{scale:.98},className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-[#0080FF]/[0.08] border border-[#0080FF]/20 transition-all",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-[#0080FF] opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-[#0080FF]"})]}),e.jsx("span",{className:"text-xs font-medium text-[#0080FF]",children:l.length>0?`${l.length} Live`:"Active"})]}),e.jsx(S,{children:d&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>F(!1)}),e.jsxs(y.div,{initial:{opacity:0,y:6,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:6,scale:.97},transition:{duration:.12},className:"absolute right-0 top-full mt-1.5 w-80 z-50 bg-[#0c0c14]/95 backdrop-blur-2xl border border-zinc-800 rounded-xl shadow-2xl shadow-black/40 overflow-hidden",children:[e.jsxs("div",{className:"px-3.5 py-3 border-b border-zinc-800/50 flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-medium text-white",children:"Active Calls"}),e.jsxs("span",{className:"text-xs text-[#0080FF] font-medium",children:[l.length," live"]})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto",children:l.length===0?e.jsxs("div",{className:"px-3.5 py-8 text-center",children:[e.jsx("p",{className:"text-xs text-zinc-500",children:"No active calls right now"}),e.jsx("p",{className:"text-[10px] text-zinc-500 mt-1",children:"Calls will appear here in real-time"})]}):l.map(c=>e.jsx("div",{className:"px-3.5 py-3 border-b border-zinc-800/50 hover:bg-white/[0.03] transition-colors",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative w-8 h-8 rounded-xl bg-[#0080FF]/10 flex items-center justify-center flex-shrink-0",children:[e.jsx(W,{className:"w-3.5 h-3.5 text-[#0080FF]"}),e.jsx(y.div,{className:"absolute inset-0 rounded-xl border border-[#0080FF]/30",animate:{scale:[1,1.15,1],opacity:[.3,0,.3]},transition:{duration:2,repeat:1/0}})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold text-zinc-200 truncate",children:c.callerName||ie(c.callerNumber)||"Unknown"}),e.jsx("p",{className:"text-[10px] text-zinc-500 capitalize",children:c.currentAction})]}),e.jsx(Ae,{startedAt:c.startedAt})]})},c.id))}),l.length>0&&e.jsx("div",{className:"px-3.5 py-2 border-t border-zinc-800/50",children:e.jsx("button",{onClick:()=>{s("/dashboard/calls"),F(!1)},className:"text-xs text-[#0080FF] hover:text-[#00D9FF] font-medium transition-colors",children:"View all calls â"})})]})]})})]}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>{b(!z),k("")},className:"p-2 rounded-lg hover:bg-white/5 text-zinc-500 hover:text-zinc-300 transition-colors",children:e.jsx(O,{className:"w-4 h-4"})}),e.jsx(S,{children:z&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>b(!1)}),e.jsxs(y.div,{initial:{opacity:0,y:6,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:6,scale:.97},transition:{duration:.12},className:"absolute right-0 top-full mt-1.5 w-72 z-50 bg-[#0c0c14]/95 backdrop-blur-2xl border border-zinc-800 rounded-xl shadow-2xl shadow-black/40 overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-zinc-800/50 flex items-center gap-2",children:[e.jsx(O,{className:"w-3.5 h-3.5 text-zinc-500"}),e.jsx("input",{ref:f,type:"text",value:j,onChange:c=>k(c.target.value),placeholder:"Search pages...",className:"flex-1 bg-transparent text-sm text-white outline-none placeholder:text-zinc-500",onKeyDown:c=>{c.key==="Enter"&&L.length>0&&T(L[0].path)}}),e.jsx("kbd",{className:"text-[9px] text-zinc-500 bg-white/5 px-1.5 py-0.5 rounded",children:"ESC"})]}),e.jsxs("div",{className:"py-1 max-h-60 overflow-y-auto",children:[L.map(c=>e.jsx("button",{onClick:()=>T(c.path),className:"w-full px-3.5 py-2 text-left text-sm text-zinc-500 hover:text-white hover:bg-white/[0.04] transition-colors",children:c.label},c.path)),L.length===0&&e.jsx("p",{className:"px-3.5 py-4 text-center text-xs text-zinc-500",children:"No results"})]})]})]})})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>v(!w),className:"relative p-2 rounded-lg hover:bg-white/5 text-zinc-500 hover:text-zinc-300 transition-colors",children:[e.jsx(K,{className:"w-4 h-4"}),C>0&&e.jsx("span",{className:"absolute top-1.5 right-1.5 w-3.5 h-3.5 bg-[#0080FF] text-white text-[9px] font-bold rounded-full flex items-center justify-center ring-2 ring-[#050508]",children:C})]}),e.jsx(S,{children:w&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>v(!1)}),e.jsxs(y.div,{initial:{opacity:0,y:6,scale:.97}
1,animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:6,scale:.97},transition:{duration:.12},className:"absolute right-0 top-full mt-1.5 w-80 z-50 bg-[#0c0c14]/95 backdrop-blur-2xl border border-zinc-800 rounded-xl shadow-2xl shadow-black/40 overflow-hidden",children:[e.jsxs("div",{className:"px-3.5 py-3 border-b border-zinc-800/50 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-white",children:"Notifications"}),C>0&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded-full bg-[#0080FF]/15 text-[10px] font-bold text-[#0080FF]",children:[C," new"]})]}),C>0&&e.jsx("button",{onClick:()=>g(),className:"text-xs text-[#0080FF] hover:text-[#00D9FF] transition-colors font-medium",children:"Mark all read"})]}),e.jsx("div",{className:"max-h-80 overflow-y-auto",children:a.length===0?e.jsxs("div",{className:"px-3.5 py-10 text-center",children:[e.jsx(K,{className:"w-5 h-5 text-zinc-700 mx-auto mb-2"}),e.jsx("p",{className:"text-xs text-zinc-500",children:"No notifications yet"})]}):(()=>{const c=a.filter(N=>!N.read).slice(0,10),_=a.filter(N=>N.read).slice(0,5);return e.jsxs(e.Fragment,{children:[c.map(N=>e.jsx("button",{onClick:()=>h(N.id),className:"w-full text-left px-3.5 py-2.5 border-b border-zinc-800/50 hover:bg-white/[0.04] transition-colors bg-[#0080FF]/[0.04]",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-[#0080FF] mt-1 flex-shrink-0 shadow-[0_0_6px_rgba(0,128,255,0.4)]"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-white font-medium leading-relaxed",children:N.message}),e.jsx("p",{className:"text-[10px] text-zinc-500 mt-0.5",children:U(N.timestamp)})]})]})},N.id)),_.length>0&&e.jsxs(e.Fragment,{children:[c.length>0&&e.jsx("div",{className:"px-3.5 py-1.5 bg-zinc-900/50 border-b border-zinc-800/50",children:e.jsx("p",{className:"text-[10px] text-zinc-600 font-medium uppercase tracking-wider",children:"Earlier"})}),_.map(N=>e.jsx("div",{className:"w-full text-left px-3.5 py-2.5 border-b border-zinc-800/50",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-zinc-800 mt-1 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-zinc-500 leading-relaxed",children:N.message}),e.jsx("p",{className:"text-[10px] text-zinc-600 mt-0.5",children:U(N.timestamp)})]})]})},N.id))]}),c.length===0&&e.jsx("div",{className:"px-3.5 py-2 text-center border-t border-zinc-800/50",children:e.jsx("p",{className:"text-[10px] text-zinc-600",children:"You're all caught up"})})]})})()})]})]})})]}),e.jsxs("div",{className:"relative ml-1",children:[e.jsxs("button",{onClick:()=>x(!u),className:"flex items-center gap-2 p-1.5 rounded-lg hover:bg-white/5 transition-colors",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-gradient-to-br from-[#0080FF]/15 to-[#4F1AD6]/15 border border-zinc-800 flex items-center justify-center",children:e.jsx("span",{className:"text-[10px] font-bold text-[#0080FF]",children:G(m.companyName)})}),e.jsx(J,{className:"w-3 h-3 text-zinc-500 hidden sm:block"})]}),e.jsx(S,{children:u&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>x(!1)}),e.jsxs(y.div,{exit:{opacity:0,y:6,scale:.97},initial:{opacity:0,y:6,scale:.97},animate:{opacity:1,y:0,scale:1},transition:{duration:.12},className:"absolute right-0 top-full mt-1.5 w-52 z-50 bg-[#0c0c14]/95 backdrop-blur-2xl border border-zinc-800 rounded-xl shadow-2xl shadow-black/40 overflow-hidden",children:[e.jsxs("div",{className:"px-3.5 py-3 border-b border-zinc-800/50",children:[e.jsx("p",{className:"text-sm font-medium text-white",children:m.companyName}),e.jsx("p",{className:"text-xs text-zinc-500 mt-0.5",children:m.email})]}),e.jsxs("div",{className:"py-1",children:[e.jsxs("button",{onClick:()=>{x(!1),s("/dashboard/settings")},className:"w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-zinc-500 hover:text-white hover:bg-white/[0.04] transition-colors",children:[e.jsx(Y,{className:"w-3.5 h-3.5"})," Settings"]}),e.jsxs("button",{onClick:()=>{x(!1),s("/dashboard/support")},className:"w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-zinc-500 hover:text-white hover:bg-white/[0.04] transition-colors",children:[e.jsx(Ne,{className:"w-3.5 h-3.5"})," Support"]})]}),e.jsx("div",{className:"py-1 border-t border-zinc-800/50",children:e.jsxs("button",{onClick:D,className:"w-full flex items-center gap-2.5 px-3.5 py-2 text-sm text-red-400/80 hover:text-red-400 hover:bg-white/[0.04] transition-colors",children:[e.jsx(A,{className:"w-3.5 h-3.5"})," Sign out"]})})]})]})})]})]})]})}function Ie(){return e.jsx("div",{className:"fixed inset-0 pointer-events-none z-[1]",style:{opacity:.025,backgroundImage:`url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E")`,backgroundRepeat:"repeat",backgroundSize:"128px 128px"}})}class Me extends se.Component{constructor(s){super(s),this.state={hasError:!1,error:null}}static getDerivedStateFromError(s){return{hasError:!0,error:s}}componentDidCatch(s,n){console.error("Dashboard page crashed:",s,n)}render(){return this.state.hasError?e.jsx("div",{className:"flex items-center justify-center min-h-[60vh]",children:e.jsxs("div",{className:"bg-white/[0.03] backdrop-blur-xl border border-zinc-700 rounded-3xl p-10 max-w-md w-full text-center",children:[e.jsx("div",{className:"mx-auto mb-6 w-14 h-14 roun
1ded-2xl bg-red-500/10 border border-red-500/20 flex items-center justify-center",children:e.jsx(ye,{className:"w-7 h-7 text-red-400"})}),e.jsx("h2",{className:"text-lg font-bold text-white mb-2",children:"This page encountered an error"}),e.jsx("p",{className:"text-sm text-zinc-500 mb-6 leading-relaxed",children:"Something unexpected happened. Your other pages are unaffected."}),e.jsxs("div",{className:"flex gap-3 justify-center",children:[e.jsx("button",{onClick:()=>this.setState({hasError:!1,error:null}),className:"px-5 py-2.5 bg-white/5 hover:bg-white/10 border border-zinc-700 text-white text-sm font-medium rounded-full transition-colors",children:"Try Again"}),e.jsxs("button",{onClick:()=>window.location.reload(),className:"px-5 py-2.5 bg-gradient-to-r from-[#0080FF] to-[#00D9FF] text-white text-sm font-medium rounded-full flex items-center gap-2 shadow-lg shadow-[#0080FF]/20",children:[e.jsx(Fe,{className:"w-4 h-4"}),"Reload Page"]})]})]})}):this.props.children}}function $e(t){const s=E(),[n,a]=o.useState(null),l=o.useRef(t);l.current=t,o.useEffect(()=>{let r=!1;return p.auth.getUser().then(({data:i,error:m})=>{var g;if(m){console.error("[useRealtimeCalls] getUser failed:",m.message);return}const h=(g=i==null?void 0:i.user)==null?void 0:g.id;!h||r||p.from("users").select("tenant_id").eq("id",h).single().then(({data:u,error:x})=>{if(x){console.error("[useRealtimeCalls] profile fetch failed:",x.message);return}!r&&(u!=null&&u.tenant_id)&&a(w=>w===u.tenant_id?w:u.tenant_id)})}).catch(i=>console.error("[useRealtimeCalls] tenant resolution failed:",i)),()=>{r=!0}},[]),o.useEffect(()=>{if(!n)return;const r=p.channel("calls_realtime").on("postgres_changes",{event:"INSERT",schema:"public",table:"calls",filter:`tenant_id=eq.${n}`},i=>{var m;s.invalidateQueries({queryKey:["calls"]}),(m=l.current)==null||m.call(l,i.new)}).subscribe();return()=>{p.removeChannel(r)}},[s,n])}function Pe(){const t=o.useCallback(s=>{const n=s.caller_name||s.caller_number||"Unknown";P.custom(a=>e.jsx("div",{className:`${a.visible?"animate-enter":"animate-leave"} max-w-sm w-full bg-[#0c0c14]/95 backdrop-blur-xl border border-[#0080FF]/20 rounded-xl shadow-2xl shadow-black/40 pointer-events-auto`,children:e.jsx("div",{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-[#0080FF]/10 border border-[#0080FF]/20 flex items-center justify-center flex-shrink-0",children:e.jsx("span",{className:"text-sm",children:"ð"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-bold text-[#0080FF]",children:"New Call"}),e.jsx("p",{className:"text-[11px] text-zinc-500 truncate mt-0.5",children:n})]}),e.jsx("button",{onClick:()=>P.dismiss(a.id),className:"text-zinc-600 hover:text-zinc-400 p-1",children:"â"})]})})}),{duration:4e3})},[]);$e(t)}function Ue(){const[t,s]=o.useState("recovering"),n=E(),a=o.useRef(!1),l=async()=>{var r;if(!a.current){a.current=!0;try{const{data:{user:i}}=await p.auth.getUser();if(!i){s("error");return}const m=i.user_metadata||{},h=m.company_name||"My Company",g=m.full_name||((r=i.email)==null?void 0:r.split("@")[0])||"User",{error:u}=await p.functions.invoke("n8n-proxy",{body:{endpoint:"/provision-account",data:{userId:i.id,email:i.email}}});if(u)throw u;await n.invalidateQueries({queryKey:["user"]}),s("success"),setTimeout(()=>window.location.reload(),1e3)}catch(i){console.error("Account recovery error:",i),s("error")}}};return o.useEffect(()=>{l()},[]),t==="error"?e.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center p-4",children:e.jsxs("div",{className:"text-center space-y-4 max-w-sm",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-red-500/10 border border-red-500/20 flex items-center justify-center mx-auto",children:e.jsx("svg",{className:"w-6 h-6 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("p",{className:"text-white font-semibold",children:"Something went wrong setting up your account."}),e.jsx("p",{className:"text-sm text-zinc-500",children:"Please try again or c
1ontact [email protected]"}),e.jsx("button",{onClick:()=>{a.current=!1,s("recovering"),l()},className:"w-full py-3 rounded-xl bg-gradient-to-r from-[#0080FF] to-[#4F1AD6] text-white text-sm font-bold transition-all",children:"Try Again"})]})}):e.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-[#0080FF] border-t-transparent rounded-full animate-spin mx-auto"}),e.jsx("p",{className:"text-zinc-500 text-sm",children:t==="success"?"Account ready! Loading dashboard...":"Setting up your account..."})]})})}function Lt(){var v,d,F,z,b,j,k;Pe();const{data:t,isLoading:s}=q(),n=ke(),[a,l]=o.useState(!1),[r,i]=o.useState(!1),[m,h]=o.useState(!1),[g,u]=o.useState(()=>typeof window<"u"&&window.innerWidth>=1024);o.useEffect(()=>{if(s)return;const f=t==null?void 0:t.tenant;f&&f.subscription_status!=="active"&&(f.plan_modal_shown||(h(!0),p.from("tenants").update({plan_modal_shown:!0}).eq("id",f.id).then()))},[s,(v=t==null?void 0:t.tenant)==null?void 0:v.id,(d=t==null?void 0:t.tenant)==null?void 0:d.subscription_status,(F=t==null?void 0:t.tenant)==null?void 0:F.plan_modal_shown]);const x=()=>h(!1);o.useEffect(()=>{let f;const C=()=>{clearTimeout(f),f=setTimeout(()=>u(window.innerWidth>=1024),150)};return window.addEventListener("resize",C),()=>{clearTimeout(f),window.removeEventListener("resize",C)}},[]);const w=g?a?72:260:0;return!s&&(t!=null&&t.user)&&(t==null?void 0:t.profile)===null?e.jsx(Ue,{}):e.jsx(ve,{children:e.jsxs("div",{className:"min-h-screen bg-[#050508] relative",children:[e.jsxs("div",{className:"fixed inset-0 pointer-events-none overflow-hidden z-0",children:[e.jsx("div",{className:"absolute -top-[300px] -left-[200px] w-[600px] h-[600px] rounded-full bg-[#0080FF]/[0.07] blur-[120px]"}),e.jsx("div",{className:"absolute -bottom-[200px] -right-[200px] w-[500px] h-[500px] rounded-full bg-[#4F1AD6]/[0.05] blur-[120px]"}),e.jsx("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[800px] h-[400px] rounded-full bg-[#00D9FF]/[0.025] blur-[200px]"})]}),e.jsx(Ie,{}),e.jsx(_e,{collapsed:a,setCollapsed:l,mobileOpen:r,setMobileOpen:i}),e.jsxs("div",{className:"relative z-10 flex flex-col min-h-screen transition-[margin] duration-200 ease-out",style:{marginLeft:w},children:[e.jsx(Te,{onMenuClick:()=>i(!0)}),e.jsx("main",{className:"flex-1 p-4 lg:p-8 overflow-x-hidden",children:e.jsx(Me,{children:e.jsx(o.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center min-h-[60vh]",children:e.jsx("div",{className:"w-8 h-8 border-2 border-[#0080FF] border-t-transparent rounded-full animate-spin"})}),children:e.jsx(ae,{})})})})]}),e.jsx(ze,{isOpen:m,onClose:x,currentPlan:((z=t==null?void 0:t.tenant)==null?void 0:z.plan)||"professional",tenantId:(b=t==null?void 0:t.tenant)==null?void 0:b.id,hasStripe:!!((j=t==null?void 0:t.tenant)!=null&&j.stripe_customer_id),subscriptionStatus:((k=t==null?void 0:t.tenant)==null?void 0:k.subscription_status)||"inactive",onOpenPortal:()=>{var f;return(f=t==null?void 0:t.tenant)!=null&&f.id?n.mutateAsync(t.tenant.id):Promise.reject()}})]})})}export{Lt 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.