1import{c as Y,r as s,j as e,ar as Me,as as Oe,at as Ae,au as Pe,q as re,bc as Le,f as ee,B as S,L as E,J as De,I as ne,bt as ze,K as C,bu as Be,v as h,bv as Fe,bw as He,bx as qe,by as oe,bz as $e,bA as Ge,bB as N,bC as Ke,bD as se,bE as ie,bF as Ve,bG as Ue,bH as We,bI as Ye,bJ as I,aZ as Xe,k as le,u as D,T as Qe,b5 as Je,ah as de,o as Ze,z as et,i as $,S as tt,bK as at,N as rt,O as nt}from"./index-DC5wYR5M.js";import{u as z}from"./useQuery-Dz0d3YqX.js";import{g as ot}from"./crm.functions-DQlzClng.js";import{s as st,a as it}from"./safe-auth-Cg2Ut_wS.js";import{o as lt}from"./step-up-bus-Hc7BWAXS.js";import{S as dt,a as ct,b as ut,c as pt,d as ft}from"./sheet-Dr2TVLut.js";import{R as mt}from"./index-Iv3e7zNv.js";import{u as bt}from"./useRouterState-Dc3eUuxc.js";import{g as ht}from"./approvals.functions-DdM-Vk-o.js";import{g as ce}from"./new-leads.functions-DFyuh_Hm.js";import{I as xt}from"./inbox-Nl2I8Hn4.js";import{M as gt}from"./messages-square-C0fLAYMF.js";import{M as vt}from"./megaphone-Dlm62Odr.js";import{H as wt}from"./handshake-DULuw4CV.js";import{A as H}from"./activity-BeHz067N.js";import{S as yt}from"./send-LkK0z7CW.js";import{S as jt}from"./settings-V99DAIif.js";import{L as Nt}from"./log-out-CqCD0DFi.js";import{B as St}from"./bell-C0hb55kl.js";import{S as Ct}from"./shield-alert-BwfqX1lj.js";import"./auth-middleware-wQ4Z7AfR.js";import"./admin-middleware-IMORJdUF.js";const Tt=[["rect",{width:"7",height:"9",x:"3",y:"3",rx:"1",key:"10lvy0"}],["rect",{width:"7",height:"5",x:"14",y:"3",rx:"1",key:"16une8"}],["rect",{width:"7",height:"9",x:"14",y:"12",rx:"1",key:"1hutg5"}],["rect",{width:"7",height:"5",x:"3",y:"16",rx:"1",key:"ldoo1y"}]],Rt=Y("layout-dashboard",Tt);const kt=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]],Et=Y("panel-left",kt);const _t=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M8 7v7",key:"1x2jlm"}],["path",{d:"M12 7v4",key:"xawao1"}],["path",{d:"M16 7v9",key:"1hp2iy"}]],It=Y("square-kanban",_t);function Mt(){const[a,r]=s.useState(!1),[t,n]=s.useState({kind:"idle"}),[o,i]=s.useState(""),[l,p]=s.useState(null),d=s.useRef(null);s.useEffect(()=>lt(async f=>{d.current=f,i(""),p(null),n({kind:"loading"}),r(!0);const{data:c,error:b}=await C.auth.mfa.listFactors();if(b){p(b.message),n({kind:"no_factor"});return}const x=c?.totp?.find(v=>v.status==="verified");if(!x){n({kind:"no_factor"});return}n({kind:"ready",factorId:x.id})}),[]);const m=f=>{r(!1),d.current?.(f),d.current=null},u=async f=>{if(f.preventDefault(),t.kind!=="ready")return;p(null),n({kind:"verifying",factorId:t.factorId});const{error:c}=await C.auth.mfa.challengeAndVerify({factorId:t.factorId,code:o});if(c){p(c.message),n({kind:"ready",factorId:t.factorId});return}m(!0)};return e.jsx(Me,{open:a,onOpenChange:f=>{f||m(!1)},children:e.jsxs(Oe,{className:"sm:max-w-md",children:[e.jsxs(Ae,{children:[e.jsxs(Pe,{className:"flex items-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"})," Two-factor verification required"]}),e.jsx(Le,{children:"This action needs a fresh two-factor code from your authenticator app."})]}),t.kind==="loading"&&e.jsx("div",{className:"flex items-center justify-center py-6 text-muted-foreground",children:e.jsx(ee,{className:"w-4 h-4 animate-spin"})}),t.kind==="no_factor"&&e.jsxs("div",{className:"space-y-3 py-2 text-sm",children:[e.jsx("p",{className:"text-muted-foreground",children:"You don't have a two-factor authenticator enrolled yet. Enroll one to unlock admin actions."}),l&&e.jsx("p",{className:"text-xs text-rose-300",children:l}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(S,{variant:"ghost",onClick:()=>m(!1),children:"Cancel"}),e.jsx(S,{asChild:!0,onClick:()=>m(!1),children:e.jsx(E,{to:"/crm/settings/security",children:"Enroll now"})})]})]}),(t.kind==="ready"||t.kind==="verifying")&&e.jsxs("form",{onSubmit:u,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(De,{htmlFor:"step-up-code",children:"6-digit code"}),e.jsx(ne,{id:"step-up-code",inputMode:"numeric",autoComplete:"one-time-code",maxLength:6,autoFocus:!0,required:!0,value:o,onChange:f=>i(f.target.value.replace(/\D/g,""))})]}),l&&e.jsx("p",{className:"text-xs text-rose-300",children:l}),e.jsxs(ze,{children:[e.jsx(S,{type:"button",variant:"ghost",onClick:()=>m(!1),children:"Cancel"}),e.jsx(S,{type:"submit",disabled:t.kind==="verifying"||o.length!==6,children:t.kind==="verifying"?e.jsx(ee,{className:"w-4 h-4 animate-spin"}):"Verify"})]})]})]})})}const q=768;function Ot(){const[a,r]=s.useState(void 0);return s.useEffect(()=>{const t=window.matchMedia(`(max-width: ${q-1}px)`),n=()=>{r(window.innerWidth<q)};return t.addEventListener("change",n),r(window.innerWidth<q),()=>t.removeEventListener("change",n)},[]),!!a}var At=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Pt=At.reduce((a,r)=>{const t=Be(`Primitive.${r}`),n=s.forwardRef((o,i)=>{const{asChild:l,...p}=o,d=l?t:r;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(d,{...p,ref:i})});return n.displayName=`Primitive.${r}`,{...a,[r]:n}},{}),Lt="Separator",te="horizontal",Dt=["horizontal","vertical"],ue=s.forwardRef((a,r)=>{const{decorative:t,orientation:n=te,...o}=a,i=zt(n)?n:te,p=t?{role:"none"}:{"aria-orientation":i==="vertical"?i:void 0,role:"separator"};return e.jsx(Pt.div,{"data-orientation":i,...p,...o,ref:r})});ue.displayName=Lt;function zt(a){return Dt.includes(a)}var pe=ue;const fe=s.forwardRef(({className:a,orientation:r="horizontal",decorative:t=!0,...n},o)=>e.jsx(pe,{ref:o,decorative:t,orientation:r,className:h("shrink-0 bg-border",r==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",a),...n}));fe.displayName=pe.displayName;function ae({className:a,...r}){return e.jsx("div",{className:h("animate-pulse rounded-md bg-primary/10",a),...r})}var Bt=Symbol("radix.slottable");function Ft(a){const r=({children:t})=>e.jsx(e.Fragment,{children:t});return r.displayName=`${a}.Slottable`,r.__radixId=Bt,r}var[B]=Ke("Tooltip",[se]),F=se(),me="TooltipProvider",Ht=700,G="tooltip.open",[qt,X]=B(me),be=a=>{const{__scopeTooltip:r,delayDuration:t=Ht,skipDelayDuration:n=300,disableHoverableContent:o=!1,children:i}=a,l=s.useRef(!0),p=s.useRef(!1),d=s.useRef(0);return s.useEffect(()=>{const m=d.current;return()=>window.clearTimeout(m)},[]),e.jsx(qt,{scope:r,isOpenDelayedRef:l,delayDuration:t,onOpen:s.useCallback(()=>{window.clearTimeout(d.current),l.current=!1},[]),onClose:s.useCallback(()=>{window.clearTimeout(d.current),d.current=window.setTimeout(()=>l.current=!0,n)},[n]),isPointerInTransitRef:p,onPointerInTransitChange:s.useCallback(m=>{p.current=m},[]),disableHoverableContent:o,children:i})};be.displayName=me;var _="Tooltip",[$t,M]=B(_),he=a=>{const{__scopeTooltip:r,children:t,open:n,defaultOpen:o,onOpenChange:i,disableHoverableContent:l,delayDuration:p}=a,d=X(_,a.__scopeTooltip),m=F(r),[u,f]=s.useState(null),c=Fe(),b=s.useRef(0),x=l??d.disableHoverableContent,v=p??d.delayDuration,w=s.useRef(!1),[j,g]=He({prop:n,defaultProp:o??!1,onChange:Z=>{Z?(d.onOpen(),document.dispatchEvent(new CustomEvent(G))):d.onClose(),i?.(Z)},caller:_}),y=s.useMemo(()=>j?w.current?"delayed-open":"instant-open":"closed",[j]),R=s.useCallback(()=>{window.clearTimeout(b.current),b.current=0,w.current=!1,g(!0)},[g]),k=s.useCallback(()=>{window.clearTimeout(b.current),b.current=0,g(!1)},[g]),J=s.useCallback(()=>{window.clearTimeout(b.current),b.current=window.setTimeout(()=>{w.current=!0,g(!0),b.current=0},v)},[v,g]);return s.useEffect(()=>()=>{b.current&&(window.clearTimeout(b.current),b.current=0)},[]),e.jsx(qe,{...m,children:e.jsx($t,{scope:r,contentId:c,open:j,stateAttribute:y,trigger:u,onTriggerChange:f,onTriggerEnter:s.useCallback(()=>{d.isOpenDelayedRef.current?J():R()},[d.isOpenDelayedRef,J,R]),onTriggerLeave:s.useCallback(()=>{x?k():(window.clearTimeout(b.current),b.current=0)},[k,x]),onOpen:R,onClose:k,disableHoverableContent:x,children:t})})};he.displayName=_;var K="TooltipTrigger",xe=s.forwardRef((a,r)=>{const{__scopeTooltip:t,...n}=a,o=M(K,t),i=X(K,t),l=F(t),p=s.useRef(null),d=oe(r,p,o.onTriggerChange),m=s.useRef(!1),u=s.useRef(!1),f=s.useCallback(()=>m.current=!1,[]);return s.useEffect(()=>()=>document.removeEventListener("pointerup",f),[f]),e.jsx($e,{asChild:!0,...l,children:e.jsx(Ge.button,{"aria-describedby":o.open?o.contentId:void 0,"data-state":o.stateAttribute,...n,ref:d,onPointerMove:N(a.onPointerMove,c=>{c.pointerType!=="touch"&&!u.current&&!i.isPointerInTransitRef.current&&(o.onTriggerEnter(),u.current=!0)}),onPointerLeave:N(a.onPointerLeave,()=>{o.onTriggerLeave(),u.current=!1}),onPointerDown:N(a.onPointerDown,()=>{o.open&&o.onClose(),m.current=!0,document.addEventListener("pointerup",f,{once:!0})}),onFocus:N(a.onFocus,()=>{m.current||o.onOpen()}),onBlur:N(a.onBlur,o.onClose),onClick:N(a.onClick,o.onClose)})})});xe.displayName=K;var Q="TooltipPortal",[Gt,Kt]=B(Q,{forceMount:void 0}),ge=a=>{const{__scopeTooltip:r,forceMount:t,children:n,container:o}=a,i=M(Q,r);return e.jsx(Gt,{scope:r,forceMount:t,children:e.jsx(ie,{present:t||i.open,children:e.jsx(Ve,{asChild:!0,container:o,children:n})})})};ge.displayName=Q;var T="TooltipContent",ve=s.forwardRef((a,r)=>{const t=Kt(T,a.__scopeTooltip),{forceMount:n=t.forceMount,side:o="top",...i}=a,l=M(T,a.__scopeTooltip);return e.jsx(ie,{present:n||l.open,children:l.disableHoverableContent?e.jsx(we,{side:o,...i,ref:r}):e.jsx(Vt,{side:o,...i,ref:r})})}),Vt=s.forwardRef((a,r)=>{const t=M(T,a.__scopeTooltip),n=X(T,a.__scopeTooltip),o=s.useRef(null),i=oe(r,o),[l,p]=s.useState(null),{trigger:d,onClose:m}=t,u=o.current,{onPointerInTransitChange:f}=n,c=s.useCallback(()=>{p(null),f(!1)},[f]),b=s.useCallback((x,v)=>{const w=x.currentTarget,j={x:x.clientX,y:x.clientY},g=Qt(j,w.getBoundingClientRect()),y=Jt(j,g),R=Zt(v.getBoundingClientRect()),k=ta([...y,...R]);p(k),f(!0)},[f]);return s.useEffect(()=>()=>c(),[c]),s.useEffect(()=>{if(d&&u){const x=w=>b(w,u),v=w=>b(w,d);return d.addEventListener("pointerleave",x),u.addEventListener("pointerleave",v),()=>{d.removeEventListener("pointerleave",x),u.removeEventListener("pointerleave",v)}}},[d,u,b,c]),s.useEffect(()=>{if(l){const x=v=>{const w=v.target,j={x:v.clientX,y:v.clientY},g=d?.contains(w)||u?.contains(w),y=!ea(j,l);g?c():y&&(c(),m())};return document.addEventListener("pointermove",x),()=>document.removeEventListener("pointermove",x)}},[d,u,l,m,c]),e.jsx(we,{...a,ref:i}
vendor: 4,130 bytes, line 1
1)}),[Ut,Wt]=B(_,{isInside:!1}),Yt=Ft("TooltipContent"),we=s.forwardRef((a,r)=>{const{__scopeTooltip:t,children:n,"aria-label":o,onEscapeKeyDown:i,onPointerDownOutside:l,...p}=a,d=M(T,t),m=F(t),{onClose:u}=d;return s.useEffect(()=>(document.addEventListener(G,u),()=>document.removeEventListener(G,u)),[u]),s.useEffect(()=>{if(d.trigger){const f=c=>{c.target?.contains(d.trigger)&&u()};return window.addEventListener("scroll",f,{capture:!0}),()=>window.removeEventListener("scroll",f,{capture:!0})}},[d.trigger,u]),e.jsx(Ue,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:i,onPointerDownOutside:l,onFocusOutside:f=>f.preventDefault(),onDismiss:u,children:e.jsxs(We,{"data-state":d.stateAttribute,...m,...p,ref:r,style:{...p.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[e.jsx(Yt,{children:n}),e.jsx(Ut,{scope:t,isInside:!0,children:e.jsx(mt,{id:d.contentId,role:"tooltip",children:o||n})})]})})});ve.displayName=T;var ye="TooltipArrow",Xt=s.forwardRef((a,r)=>{const{__scopeTooltip:t,...n}=a,o=F(t);return Wt(ye,t).isInside?null:e.jsx(Ye,{...o,...n,ref:r})});Xt.displayName=ye;function Qt(a,r){const t=Math.abs(r.top-a.y),n=Math.abs(r.bottom-a.y),o=Math.abs(r.right-a.x),i=Math.abs(r.left-a.x);switch(Math.min(t,n,o,i)){case i:return"left";case o:return"right";case t:return"top";case n:return"bottom";default:throw new Error("unreachable")}}function Jt(a,r,t=5){const n=[];switch(r){case"top":n.push({x:a.x-t,y:a.y+t},{x:a.x+t,y:a.y+t});break;case"bottom":n.push({x:a.x-t,y:a.y-t},{x:a.x+t,y:a.y-t});break;case"left":n.push({x:a.x+t,y:a.y-t},{x:a.x+t,y:a.y+t});break;case"right":n.push({x:a.x-t,y:a.y-t},{x:a.x-t,y:a.y+t});break}return n}function Zt(a){const{top:r,right:t,bottom:n,left:o}=a;return[{x:o,y:r},{x:t,y:r},{x:t,y:n},{x:o,y:n}]}function ea(a,r){const{x:t,y:n}=a;let o=!1;for(let i=0,l=r.length-1;i<r.length;l=i++){const p=r[i],d=r[l],m=p.x,u=p.y,f=d.x,c=d.y;u>n!=c>n&&t<(f-m)*(n-u)/(c-u)+m&&(o=!o)}return o}function ta(a){const r=a.slice();return r.sort((t,n)=>t.x<n.x?-1:t.x>n.x?1:t.y<n.y?-1:t.y>n.y?1:0),aa(r)}function aa(a){if(a.length<=1)return a.slice();const r=[];for(let n=0;n<a.length;n++){const o=a[n];for(;r.length>=2;){const i=r[r.length-1],l=r[r.length-2];if((i.x-l.x)*(o.y-l.y)>=(i.y-l.y)*(o.x-l.x))r.pop();else break}r.push(o)}r.pop();const t=[];for(let n=a.length-1;n>=0;n--){const o=a[n];for(;t.length>=2;){const i=t[t.length-1],l=t[t.length-2];if((i.x-l.x)*(o.y-l.y)>=(i.y-l.y)*(o.x-l.x))t.pop();else break}t.push(o)}return t.pop(),r.length===1&&t.length===1&&r[0].x===t[0].x&&r[0].y===t[0].y?r:r.concat(t)}var ra=be,na=he,oa=xe,sa=ge,je=ve;const ia=ra,la=na,da=oa,Ne=s.forwardRef(({className:a,sideOffset:r=4,...t},n)=>e.jsx(sa,{children:e.jsx(je,{ref:n,sideOffset:r,className:h("z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--radix-tooltip-content-transform-origin)",a),...t})}));Ne.displayName=je.displayName;const ca="sidebar_state",ua=3600*24*7,pa="16rem",fa="18rem",ma="3rem",ba="b",Se=s.createContext(null);function O(){const a=s.useContext(Se);if(!a)throw new Error("useSidebar must be used within a SidebarProvider.");return a}const Ce=s.forwardRef(({defaultOpen:a=!0,open:r,onOpenChange:t,className:n,style:o,children:i,...l},p)=>{const d=Ot(),[m,u]=s.useState(!1),[f,c]=s.useState(a),b=r??f,x=s.useCallback(g=>{const y=typeof g=="function"?g(b):g;t?t(y):c(y),document.cookie=`${ca}=${y}; path=/; max-age=${ua}`},[t,b]),v=s.useCallback(()=>d?u(g=>!g):x(g=>!g),[d,x,u]);s.useEffect(()=>{const g=y=>
1{y.key===ba&&(y.metaKey||y.ctrlKey)&&(y.preventDefault(),v())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[v]);const w=b?"expanded":"collapsed",j=s.useMemo(()=>({state:w,open:b,setOpen:x,isMobile:d,openMobile:m,setOpenMobile:u,toggleSidebar:v}),[w,b,x,d,m,u,v]);return e.jsx(Se.Provider,{value:j,children:e.jsx(ia,{delayDuration:0,children:e.jsx("div",{style:{"--sidebar-width":pa,"--sidebar-width-icon":ma,...o},className:h("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",n),ref:p,...l,children:i})})})});Ce.displayName="SidebarProvider";const Te=s.forwardRef(({side:a="left",variant:r="sidebar",collapsible:t="offcanvas",className:n,children:o,...i},l)=>{const{isMobile:p,state:d,openMobile:m,setOpenMobile:u}=O();return t==="none"?e.jsx("div",{className:h("flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",n),ref:l,...i,children:o}):p?e.jsx(dt,{open:m,onOpenChange:u,...i,children:e.jsxs(ct,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":fa},side:a,children:[e.jsxs(ut,{className:"sr-only",children:[e.jsx(pt,{children:"Sidebar"}),e.jsx(ft,{children:"Displays the mobile sidebar."})]}),e.jsx("div",{className:"flex h-full w-full flex-col",children:o})]})}):e.jsxs("div",{ref:l,className:"group peer hidden text-sidebar-foreground md:block","data-state":d,"data-collapsible":d==="collapsed"?t:"","data-variant":r,"data-side":a,children:[e.jsx("div",{className:h("relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",r==="floating"||r==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon)")}),e.jsx("div",{className:h("fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",a==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",r==="floating"||r==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",n),...i,children:e.jsx("div",{"data-sidebar":"sidebar",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow",children:o})})]})});Te.displayName="Sidebar";const Re=s.forwardRef(({className:a,onClick:r,...t},n)=>{const{toggleSidebar:o}=O();return e.jsxs(S,{ref:n,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:h("h-7 w-7",a),onClick:i=>{r?.(i),o()},...t,children:[e.jsx(Et,{}),e.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});Re.displayName="SidebarTrigger";const ha=s.forwardRef(({className:a,...r},t)=>{const{toggleSidebar:n}=O();return e.jsx("button",{ref:t,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:n,title:"Toggle Sidebar",className:h("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",a),...r})});ha.displayName="SidebarRail";const ke=s.forwardRef(({className:a,...r},t)=>e.jsx("main",{ref:t,className:h("relative flex w-full flex-1 flex-col bg-background","md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",a),...r}));ke.displayName="SidebarInset";const xa=s.forwardRef(({className:a,...r},t)=>e.jsx(ne,{ref:t,"data-sidebar":"input",className:h("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",a),...r}));xa.displayName="SidebarInput";const Ee=s.forwardRef(({className:a,...r},t)=>e.jsx("div",{ref:t,"data-sidebar":"header",className:h("flex flex-col gap-2 p-2",a),...r}));
1Ee.displayName="SidebarHeader";const _e=s.forwardRef(({className:a,...r},t)=>e.jsx("div",{ref:t,"data-sidebar":"footer",className:h("flex flex-col gap-2 p-2",a),...r}));_e.displayName="SidebarFooter";const ga=s.forwardRef(({className:a,...r},t)=>e.jsx(fe,{ref:t,"data-sidebar":"separator",className:h("mx-2 w-auto bg-sidebar-border",a),...r}));ga.displayName="SidebarSeparator";const Ie=s.forwardRef(({className:a,...r},t)=>e.jsx("div",{ref:t,"data-sidebar":"content",className:h("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",a),...r}));Ie.displayName="SidebarContent";const V=s.forwardRef(({className:a,...r},t)=>e.jsx("div",{ref:t,"data-sidebar":"group",className:h("relative flex w-full min-w-0 flex-col p-2",a),...r}));V.displayName="SidebarGroup";const U=s.forwardRef(({className:a,asChild:r=!1,...t},n)=>{const o=r?I:"div";return e.jsx(o,{ref:n,"data-sidebar":"group-label",className:h("flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground
1/70 outline-none ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",a),...t})});U.displayName="SidebarGroupLabel";const va=s.forwardRef(({className:a,asChild:r=!1,...t},n)=>{const o=r?I:"button";return e.jsx(o,{ref:n,"data-sidebar":"group-action",className:h("absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring cursor-pointer transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",a),...t})});va.displayName="SidebarGroupAction";const W=s.forwardRef(({className:a,...r},t)=>e.jsx("div",{ref:t,"data-sidebar":"group-content",className:h("w-full text-sm",a),...r}));W.displayName="SidebarGroupContent";const A=s.forwardRef(({className:a,...r},t)=>e.jsx("ul",{ref:t,"data-sidebar":"menu",className:h("flex w-full min-w-0 flex-col gap-1",a),...r}));A.displayName="SidebarMenu";const P=s.forwardRef(({className:a,...r},t)=>e.jsx("li",{ref:t,"data-sidebar":"menu-item",className:h("group/menu-item relative",a),...r}));P.displayName="SidebarMenuItem";const wa=Xe("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring cursor-pointer transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),L=s.forwardRef(({asChild:a=!1,isActive:r=!1,variant:t="default",size:n="default",tooltip:o,className:i,...l},p)=>{const d=a?I:"button",{isMobile:m,state:u}=O(),f=e.jsx(d,{ref:p,"data-sidebar":"menu-button","data-size":n,"data-active":r,className:h(wa({variant:t,size:n}),i),...l});return o?(typeof o=="string"&&(o={children:o}),e.jsxs(la,{children:[e.jsx(da,{asChild:!0,children:f}),e.jsx(Ne,{side:"right",align:"center",hidden:u!=="collapsed"||m,...o})]})):f});L.displayName="SidebarMenuButton";const ya=s.forwardRef(({className:a,asChild:r=!1,showOnHover:t=!1,...n},o)=>{const i=r?I:"button";return e.jsx(i,{ref:o,"data-sidebar":"menu-action",className:h("absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring cursor-pointer transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",t&&"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",a),...n})});ya.displayName="SidebarMenuAction";const ja=s.forwardRef(({className:a,...r},t)=>e.jsx("div",{ref:t,"data-sidebar":"menu-badge",className:h("pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",a),...r}));ja.displayName="SidebarMenuBadge";const Na=s.forwardRef(({className:a,showIcon:r=!1,...t},n)=>{const o=s.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return e.jsxs("div",{ref:n,"data-sidebar":"menu-skeleton",className:h("flex h-8 items-center gap-2 rounded-md px-2",a),...t,children:[r&&e.jsx(ae,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),e.jsx(ae,{className:"h-4 max-w-(--skeleton-width) flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":o}})]})});Na.displayName="SidebarMenuSkeleton";const Sa=s.forwardRef(({className:a,...r},t)=>e.jsx("ul",{ref:t,"data-sidebar":"menu-sub",className:h("mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",a),...r}));Sa.displayName="SidebarMenuSub";const Ca=s.forwardRef(({...a},r)=>e.jsx("li",{ref:r,...a}));Ca.displayName="SidebarMenuSubItem";const Ta=s.forwardRef(({asChild:a=!1,size:r="md",isActive:t,className:n,...o},i)=>{const l=a?I:"a";return e.jsx(l,{ref:i,"data-sidebar":"menu-sub-button","data-size":r,"data-active":t,className:h("flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring cursor-pointer hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",r==="sm"&&"text-xs",r==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",n),...o})});Ta.displayName="SidebarMenuSubButton";const Ra=[{to:"/crm",icon:Rt,label:"Dashboard",exact:!0},{to:"/crm/master",icon:Qe,label:"Master view"},{to:"/crm/new-leads",icon:Je,label:"New leads"},{to:"/crm/inbox",icon:xt,label:"Inbox"},{to:"/crm/approvals",icon:re,label:"Approvals"},{to:"/crm/leads",icon:de,label:"People"},{to:"/crm/companies",icon:Ze,label:"Companies"},{to:"/crm/chats",icon:gt,label:"Conversations"},{to:"/crm/targets",icon:et,label:"Targets"},{to:"/crm/pipeline",icon:It,label:"Pipeline"},{to:"/crm/campaigns",icon:vt,label:"Campaigns"},{to:"/crm/agent-trials",icon:$,label:"Agent trials"}],ka=[{to:"/crm/partners",icon:wt,label:"Partners",adminOnly:!0},{to:"/crm/investors",icon:de,label:"Investor portal",adminOnly:!0},{to:"/crm/orange",icon:$,label:"Orange page",adminOnly:!0},{to:"/crm/colleagues",icon:$,label:"Private colleagues"},{to:"/crm/health",icon:H,label:"Health",adminOnly:!0},{to:"/crm/otp-health",icon:H,label:"OTP health",adminOnly:!0}
1,{to:"/crm/outbound-log",icon:yt,label:"Outbound log",adminOnly:!0},{to:"/crm/security",icon:tt,label:"Security",adminOnly:!0},{to:"/crm/ops",icon:H,label:"Ops",adminOnly:!0},{to:"/crm/settings",icon:jt,label:"Settings",adminOnly:!0}];function Ea({isAdmin:a}){const r=bt({select:c=>c.location.pathname}),t=le(),{state:n}=O(),o=n==="collapsed",i=D(ht),p=z({queryKey:["approvals-pending-count"],queryFn:async()=>await i()??{count:0},refetchInterval:1e4}).data?.count??0,d=D(ce),u=z({queryKey:["new-lead-counts"],queryFn:()=>d(),refetchInterval:3e4}).data?.real??0,f=(c,b)=>b?r===c:r===c||r.startsWith(c+"/");return e.jsxs(Te,{collapsible:"icon",children:[e.jsx(Ee,{children:e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5",children:[e.jsx("div",{className:"w-7 h-7 rounded-md bg-sky-500/20 text-sky-300 grid place-items-center text-xs font-semibold",children:"OC"}),!o&&e.jsx("div",{className:"text-sm font-semibold text-foreground",children:"OptiComm CRM"})]})}),e.jsxs(Ie,{children:[e.jsxs(V,{children:[e.jsx(U,{children:"Workspace"}),e.jsx(W,{children:e.jsx(A,{children:Ra.map(c=>e.jsx(P,{children:e.jsx(L,{asChild:!0,isActive:f(c.to,c.exact),tooltip:c.label,children:e.jsxs(E,{to:c.to,className:"flex items-center gap-2",children:[e.jsx(c.icon,{className:"w-4 h-4 shrink-0"}),e.jsx("span",{className:"flex-1 truncate",children:c.label}),c.to==="/crm/new-leads"&&u>0&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/20 text-emerald-200 border border-emerald-400/30",children:u}),c.to==="/crm/approvals"&&p>0&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/20 text-amber-200 border border-amber-400/30",children:p})]})})},c.to))})})]}),a&&e.jsxs(V,{children:[e.jsx(U,{children:"Admin"}),e.jsx(W,{children:e.jsx(A,{children:ka.map(c=>e.jsx(P,{children:e.jsx(L,{asChild:!0,isActive:f(c.to),tooltip:c.label,children:e.jsxs(E,{to:c.to,className:"flex items-center gap-2",children:[e.jsx(c.icon,{className:"w-4 h-4 shrink-0"}),e.jsx("span",{className:"flex-1 truncate",children:c.label})]})})},c.to))})})]})]}),e.jsx(_e,{children:e.jsx(A,{children:e.jsx(P,{children:e.jsxs(L,{tooltip:"Sign out",onClick:async()=>{await C.auth.signOut(),t({to:"/auth"})},children:[e.jsx(Nt,{className:"w-4 h-4"}),e.jsx("span",{children:"Sign out"})]})})})})]})}const _a="@trials.opticomm.ai",Ia="@unknown.opticomm.ai";function Ma(a){const r=String(a??"").toLowerCase();return r?!r.endsWith(_a)&&!r.endsWith(Ia):!1}function Oa(){const a=at(),r=D(ce),{data:t}=z({queryKey:["new-lead-counts"],queryFn:()=>r(),refetchInterval:3e4});s.useEffect(()=>{const o=C.channel("crm-new-leads").on("postgres_changes",{event:"INSERT",schema:"public",table:"leads"},i=>{const l=i.new;a.invalidateQueries({queryKey:["new-lead-counts"]}),a.invalidateQueries({queryKey:["new-lead-queue"]}),Ma(l?.email)&&rt.success(`New lead: ${l?.name?.trim()||l?.email}`,{description:l?.company?`${l.company}`:"Open the new leads queue",duration:12e3})}).subscribe();return()=>{C.removeChannel(o)}},[a]);const n=t?.real??0;return e.jsxs(E,{to:"/crm/new-leads",className:"relative inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground hover:text-foreground hover:bg-white/5",title:"New leads waiting",children:[e.jsx(St,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"New leads"}),n>0&&e.jsx("span",{className:"ml-0.5 min-w-[18px] text-center text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/20 text-emerald-200 border border-emerald-400/30",children:n})]})}function ar(){const a=le(),r=D(ot),{data:t,isLoading:n,error:o}=z({queryKey:["crm-access"],queryFn:()=>r(),retry:!1}),[i,l]=s.useState({checked:!1,hasFactor:!1,needsChallenge:!1});return s.useEffect(()=>{t&&!t.canView&&a({to:"/"})},[t,a]),s.useEffect(()=>{if(!t?.canView)return;let p=!1;return(async()=>{const d=await st(),m=await it();if(p)return;const u=!!m.verifiedFactorId;if(d.currentLevel==="aal1"&&d.nextLevel==="aal2"&&u){a({to:"/auth/2fa"});return}l({checked:!0,hasFactor:u,needsChallenge:!1})})(),()=>{p=!0}},[t?.canView,a]),n?e.jsx("div",{className:"min-h-screen flex items-center justify-center text-muted-foreground",children:"Loading CRM,"}):o||!t?.canView?e.jsxs("div",{className:"min-h-screen flex flex-col items-center justify-center gap-3 text-center px-4",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"No CRM access"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-sm",children:"Your account exists but has not been granted a CRM role yet. Ask an admin to grant you access."}),e.jsx(S,{variant:"outline",onClick:async()=>{await C.auth.signOut(),a({to:"/auth"})},children:"Sign out"})]}):e.jsx(Ce,{children:e.jsxs("div",{className:"min-h-screen flex w-full bg-background",children:[e.jsx(Ea,{isAdmin:!!t.isAdmin}),e.jsxs(ke,{className:"flex flex-col min-w-0",children:[e.jsxs("header",{className:"h-11 border-b border-white/10 flex items-center px-2 gap-2 shrink-0",children:[e.jsx(Re,{className:"text-muted-foreground hover:text-foreground"}),e.jsx("div",{className:"h-4 w-px bg-white/10"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"CRM"}),e.jsx("div",{className:"ml-auto",children:e.jsx(Oa,{})})]}),i.checked&&!i.hasFactor&&e.jsxs("div",{className:"m-4 flex items-start gap-3 rounded-lg border border-amber-400/30 bg-amber-400/10 p-3 text-sm",children:[e.jsx(Ct,{className:"w-4 h-4 mt-0.5 text-amber-300 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-amber-100 font-medium",children:"Two-factor authentication is not set up."}),e.jsx("div",{className:"text-amber-100/80 text-xs mt-0.5",children:"Enroll a TOTP app to harden your account. Required for the team in a future release."})]}),e.jsx(E,{to:"/crm/settings",className:"text-xs text-amber-100 underline hover:text-amber-50 whitespace-nowrap",children:"Enroll now"})]}),e.jsx("main",{className:"flex-1 overflow-auto min-w-0","data-no-hover-fx":!0,children:e.jsx(nt,{})})]}),e.jsx(Mt,{})]})})}export{ar as component};
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.