PageSourceSearch

https://ineedleads.co.uk/assets/Conversations-BkXggF6H.js

js ineedleads.co.uk collected 2026-10-09 22:57:33 UTC 103,981 bytes, 5 lines download raw bytes

1import{r as m,j as e,e as xn,u as U}from"./index-DKJ0tKwF.js";import{u as pn}from"./useDesktopToolbarAction-BjAss24h.js";import{u as gn}from"./useDesktopStatusUpdate-V-hQXDku.js";import{eP as bn,eS as ks,cC as is,ap as St,aq as kt,as as zt,n as jn,r as be,cU as Ge,bR as st,bS as nt,bU as at,bV as Ie,g as zs,ed as wn,aE as He,c$ as Kt,cY as _s,f as ye,cw as Wt,s as Es,v as Ps,w as As,x as Ms,y as Is,$ as os,ar as Qt,at as yn,a2 as ot,b1 as ht,S as Nn,bz as Rs,bf as cs,a3 as vn,bE as Ot,bd as Cn,eN as Sn,b2 as $s,aR as Ds,bM as kn,bN as zn,bO as Je,bP as Ye,aw as _n,F as En,aA as Pn,T as Xt,ba as xt,bK as An,fT as Mn,fW as In,cb as Ls,bW as Ts,ha as bt,aj as Rn,k as $n,d as Dn,h3 as Ln,hb as Tn,hc as qn,hd as Hn,a8 as ds,he as Fn,hf as Wn,hg as On,g0 as Bn,aM as Un,U as Vn,ck as Gn,cm as Kn,bj as Qn,bm as Xn}from"./App-CL-mfmhu.js";import{u as Jn}from"./useEnsureInboundSmsWebhooks-BGvNajNj.js";import{g as qs,D as k,X as Bt,t as P,P as ge,k as pe,M as ze,e as us,J as V,o as De,G as Yn,T as Zn,r as ea,l as ta,K as sa,S as Ut,b as na,f as aa}from"./button-DFML8rOM.js";import{I as ra,g as Le,j as la,u as ia,E as Hs,v as Re,T as oa}from"./v3LegalOverrides-BUgTGJPl.js";import{F as ca}from"./mouse-pointer-2-CzsmklB8.js";import{C as da,R as ua,E as ma}from"./ContactBriefingCard-CYgarrAz.js";import{f as ms,U as tt,I as fa,p as Jt,O as Fs,W as Vt,C as Yt,o as ha,al as rt,T as Qe,aQ as de,aR as ue,aS as me,ao as jt,a8 as wt,a0 as fs}from"./V2Layout-DEbe2yZA.js";import{L as Te,S as xa}from"./tracker-DzJH7QDt.js";import{u as pa}from"./useWhatsAppConnection-DRcWzPyl.js";import{u as Ws,a as ga}from"./useEmailSenders-nLhUUeXd.js";import{E as ba}from"./EmailComposer-X6aVPDiR.js";import{S as ja}from"./SenderNumberPicker-CHXamrNA.js";import{d as wa}from"./differenceInHours-BMs4llpZ.js";import{s as yt}from"./setMinutes-Dkmufa5H.js";import{s as Nt}from"./setHours--tQ0ZQly.js";import{I as ya}from"./InternalPageSEO-loZWkmv4.js";import"./index-BNGwt955.js";import"./SEOHead-B5IBZJEm.js";import"./types-DU7944Yl.js";import"./useEmailSendingDomains-NbQNazAe.js";import"./useEmailSignature-Ce2rzS_V.js";import"./useEmailCampaigns-Ce5FuaOK.js";import"./mergeTags-DreIBWcr.js";function hs(){const t=new Date,s=t.getFullYear(),n=t.getMonth(),a=t.getDate(),l=new Date(0);return l.setFullYear(s,n,a+1),l.setHours(0,0,0,0),l}const Rt=t=>{const s=`${t.type} ${t.name}`.toLowerCase();return/image|\.(png|jpe?g|gif|webp|heic)\b/.test(s)?"image":/video|\.(mp4|mov|webm)\b/.test(s)?"video":/audio|\.(mp3|ogg|wav|m4a)\b/.test(s)?"audio":/pdf|\.pdf\b/.test(s)?"pdf":"file"},Na=t=>t?t<1024?`${t} B`:t<1048576?`${Math.round(t/1024)} KB`:`${(t/1048576).toFixed(1)} MB`:"";function $t(t,s,n){var r;const a=[];let l=t;if(typeof l=="string")try{l=JSON.parse(l)}catch{l=[]}return Array.isArray(l)&&l.forEach(i=>{var h;if(!i||typeof i!="object")return;const d=i.url||i.public_url||i.signed_url||i.href,f=i.filename||i.name||i.file_name||(d?(h=String(d).split("/").pop())==null?void 0:h.split("?")[0]:"")||"Attachment";a.push({name:f,url:typeof d=="string"&&/^https?:\/\//.test(d)?d:void 0,type:i.content_type||i.contentType||i.mime_type||i.type||"",size:Number(i.size)||void 0})}),s&&!a.some(i=>i.url===s)&&a.push({name:((r=s.split("/").pop())==null?void 0:r.split("?")[0])||"Attachment",url:s,type:n||""}),a}function va({attachments:t}){const[s,n]=m.useState(null);if(!t.length)return null;const a=t.filter(r=>r.url&&Rt(r)==="image"),l=t.filter(r=>!a.includes(r));return e.jsxs("div",{className:"mt-2 space-y-2",children:[a.length>0&&e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:a.map((r,i)=>e.jsx("button",{type:"button",onClick:()=>n(r),className:"group relative overflow-hidden rounded-md border border-border bg-muted aspect-video","aria-label":`Preview ${r.name}`,children:e.jsx("img",{src:r.url,alt:r.name,loading:"lazy",className:"h-full w-full object-cover transition-transform group-hover:scale-105"})},i))}),l.map((r,i)=>{const d=Rt(r);if(r.url&&d==="video")return e.jsx("video",{src:r.url,controls:!0,className:"w-full max-h-72 rounded-md border border-border"},i);if(r.url&&d==="audio")return e.jsx("audio",{src:r.url,controls:!0,className:"w-full"},i);const f=d==="pdf"?qs:d==="image"?ra:d==="video"?ca:d==="audio"?bn:ks;return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border bg-muted/50 px-3 py-2 min-w-0",children:[e.jsx(f,{className:"h-5 w-5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-card-foreground",children:r.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[[d==="pdf"?"PDF":d==="file"?"File":d,Na(r.size)].filter(
1Boolean).join(" · "),!r.url&&" · not downloadable"]})]}),r.url&&d==="pdf"&&e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>n(r),children:"Preview"}),r.url&&e.jsx(k,{asChild:!0,variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":`Download ${r.name}`,children:e.jsx("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",download:r.name,children:e.jsx(is,{className:"h-4 w-4"})})})]},i)}),e.jsx(St,{open:!!s,onOpenChange:r=>!r&&n(null),children:e.jsxs(kt,{className:"max-w-4xl p-2",children:[e.jsx(zt,{className:"sr-only",children:s==null?void 0:s.name}),s&&(Rt(s)==="pdf"?e.jsx("iframe",{src:s.url,title:s.name,className:"h-[75vh] w-full rounded-md bg-background"}):e.jsx("img",{src:s.url,alt:s.name,className:"max-h-[80vh] w-full object-contain rounded-md"})),(s==null?void 0:s.url)&&e.jsxs("div",{className:"flex justify-end gap-2 p-1",children:[e.jsx(k,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",download:s.name,children:[e.jsx(is,{className:"h-4 w-4 mr-1"}),"Download"]})}),e.jsxs(k,{variant:"ghost",size:"sm",onClick:()=>n(null),children:[e.jsx(Bt,{className:"h-4 w-4 mr-1"}),"Close"]})]})]})})]})}const _t=m.createContext(null);_t.displayName="PanelGroupContext";const Y={group:"data-panel-group",groupDirection:"data-panel-group-direction",groupId:"data-panel-group-id",panel:"data-panel",panelCollapsible:"data-panel-collapsible",panelId:"data-panel-id",panelSize:"data-panel-size",resizeHandle:"data-resize-handle",resizeHandleActive:"data-resize-handle-active",resizeHandleEnabled:"data-panel-resize-handle-enabled",resizeHandleId:"data-panel-resize-handle-id",resizeHandleState:"data-resize-handle-state"},Zt=10,$e=m.useLayoutEffect,xs=xn.useId,Ca=typeof xs=="function"?xs:()=>null;let Sa=0;function es(t=null){const s=Ca(),n=m.useRef(t||s||null);return n.current===null&&(n.current=""+Sa++),t??n.current}function Os({children:t,className:s="",collapsedSize:n,collapsible:a,defaultSize:l,forwardedRef:r,id:i,maxSize:d,minSize:f,onCollapse:h,onExpand:p,onResize:x,order:o,style:g,tagName:u="div",...b}){const v=m.useContext(_t);if(v===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:S,expandPanel:A,getPanelSize:F,getPanelStyle:T,groupId:W,isPanelCollapsed:M,reevaluatePanelConstraints:j,registerPanel:R,resizePanel:O,unregisterPanel:G}=v,w=es(i),q=m.useRef({callbacks:{onCollapse:h,onExpand:p,onResize:x},constraints:{collapsedSize:n,collapsible:a,defaultSize:l,maxSize:d,minSize:f},id:w,idIsFromProps:i!==void 0,order:o});m.useRef({didLogMissingDefaultSizeWarning:!1}),$e(()=>{const{callbacks:X,constraints:Z}=q.current,se={...Z};q.current.id=w,q.current.idIsFromProps=i!==void 0,q.current.order=o,X.onCollapse=h,X.onExpand=p,X.onResize=x,Z.collapsedSize=n,Z.collapsible=a,Z.defaultSize=l,Z.maxSize=d,Z.minSize=f,(se.collapsedSize!==Z.collapsedSize||se.collapsible!==Z.collapsible||se.maxSize!==Z.maxSize||se.minSize!==Z.minSize)&&j(q.current,se)}),$e(()=>{const X=q.current;return R(X),()=>{G(X)}},[o,w,R,G]),m.useImperativeHandle(r,()=>({collapse:()=>{S(q.current)},expand:X=>{A(q.current,X)},getId(){return w},getSize(){return F(q.current)},isCollapsed(){return M(q.current)},isExpanded(){return!M(q.current)},resize:X=>{O(q.current,X)}}),[S,A,F,M,w,O]);const oe=T(q.current,l);return m.createElement(u,{...b,children:t,className:s,id:w,style:{...oe,...g},[Y.groupId]:W,[Y.panel]:"",[Y.panelCollapsible]:a||void 0,[Y.panelId]:w,[Y.panelSize]:parseFloat(""+oe.flexGrow).toFixed(1)})}const Bs=m.forwardRef((t,s)=>m.createElement(Os,{...t,forwardedRef:s}));Os.displayName="Panel";Bs.displayName="forwardRef(Panel)";let Gt=null,pt=-1,Se=null;function ka(t,s){if(s){const n=(s&Qs)!==0,a=(s&Xs)!==0,l=(s&Js)!==0,r=(s&Ys)!==0;if(n)return l?"se-resize":r?"ne-resize":"e-resize";if(a)return l?"sw-resize":r?"nw-resize":"w-resize";if(l)return"s-resize";if(r)return"n-resize"}switch(t){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function za(){Se!==null&&(document.head.removeChild(Se),Gt=null,Se=null,pt=-1)}function Dt(t,s){var n,a;const l=ka(t,s);if(Gt!==l){if(Gt=l,Se===null&&(Se=document.createElement("style"),document.head.appendChild(Se)),pt>=0){var r;(r=Se.sheet)===null||r===void 0||r.removeRule(pt)}pt=(n=(a=Se.sheet)===null||a===void 0?void 0:a.insertRule(`*{curs
1or: ${l} !important;}`))!==null&&n!==void 0?n:-1}}function Us(t){return t.type==="keydown"}function Vs(t){return t.type.startsWith("pointer")}function Gs(t){return t.type.startsWith("mouse")}function Et(t){if(Vs(t)){if(t.isPrimary)return{x:t.clientX,y:t.clientY}}else if(Gs(t))return{x:t.clientX,y:t.clientY};return{x:1/0,y:1/0}}function _a(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function Ea(t,s,n){return t.x<s.x+s.width&&t.x+t.width>s.x&&t.y<s.y+s.height&&t.y+t.height>s.y}function Pa(t,s){if(t===s)throw new Error("Cannot compare node with itself");const n={a:bs(t),b:bs(s)};let a;for(;n.a.at(-1)===n.b.at(-1);)t=n.a.pop(),s=n.b.pop(),a=t;D(a,"Stacking order can only be calculated for elements with a common ancestor");const l={a:gs(ps(n.a)),b:gs(ps(n.b))};if(l.a===l.b){const r=a.childNodes,i={a:n.a.at(-1),b:n.b.at(-1)};let d=r.length;for(;d--;){const f=r[d];if(f===i.a)return 1;if(f===i.b)return-1}}return Math.sign(l.a-l.b)}const Aa=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Ma(t){var s;const n=getComputedStyle((s=Ks(t))!==null&&s!==void 0?s:t).display;return n==="flex"||n==="inline-flex"}function Ia(t){const s=getComputedStyle(t);return!!(s.position==="fixed"||s.zIndex!=="auto"&&(s.position!=="static"||Ma(t))||+s.opacity<1||"transform"in s&&s.transform!=="none"||"webkitTransform"in s&&s.webkitTransform!=="none"||"mixBlendMode"in s&&s.mixBlendMode!=="normal"||"filter"in s&&s.filter!=="none"||"webkitFilter"in s&&s.webkitFilter!=="none"||"isolation"in s&&s.isolation==="isolate"||Aa.test(s.willChange)||s.webkitOverflowScrolling==="touch")}function ps(t){let s=t.length;for(;s--;){const n=t[s];if(D(n,"Missing node"),Ia(n))return n}return null}function gs(t){return t&&Number(getComputedStyle(t).zIndex)||0}function bs(t){const s=[];for(;t;)s.push(t),t=Ks(t);return s}function Ks(t){const{parentNode:s}=t;return s&&s instanceof ShadowRoot?s.host:s}const Qs=1,Xs=2,Js=4,Ys=8,Ra=_a()==="coarse";let je=[],Ke=!1,Me=new Map,Pt=new Map;const lt=new Set;function $a(t,s,n,a,l){var r;const{ownerDocument:i}=s,d={direction:n,element:s,hitAreaMargins:a,setResizeHandlerState:l},f=(r=Me.get(i))!==null&&r!==void 0?r:0;return Me.set(i,f+1),lt.add(d),vt(),function(){var p;Pt.delete(t),lt.delete(d);const x=(p=Me.get(i))!==null&&p!==void 0?p:1;if(Me.set(i,x-1),vt(),x===1&&Me.delete(i),je.includes(d)){const o=je.indexOf(d);o>=0&&je.splice(o,1),ss(),l("up",!0,null)}}}function Da(t){const{target:s}=t,{x:n,y:a}=Et(t);Ke=!0,ts({target:s,x:n,y:a}),vt(),je.length>0&&(Ct("down",t),t.preventDefault(),Zs(s)||t.stopImmediatePropagation())}function Lt(t){const{x:s,y:n}=Et(t);if(Ke&&t.buttons===0&&(Ke=!1,Ct("up",t)),!Ke){const{target:a}=t;ts({target:a,x:s,y:n})}Ct("move",t),ss(),je.length>0&&t.preventDefault()}function Tt(t){const{target:s}=t,{x:n,y:a}=Et(t);Pt.clear(),Ke=!1,je.length>0&&(t.preventDefault(),Zs(s)||t.stopImmediatePropagation()),Ct("up",t),ts({target:s,x:n,y:a}),ss(),vt()}function Zs(t){let s=t;for(;s;){if(s.hasAttribute(Y.resizeHandle))return!0;s=s.parentElement}return!1}function ts({target:t,x:s,y:n}){je.splice(0);let a=null;(t instanceof HTMLElement||t instanceof SVGElement)&&(a=t),lt.forEach(l=>{const{element:r,hitAreaMargins:i}=l,d=r.getBoundingClientRect(),{bottom:f,left:h,right:p,top:x}=d,o=Ra?i.coarse:i.fine;if(s>=h-o&&s<=p+o&&n>=x-o&&n<=f+o){if(a!==null&&document.contains(a)&&r!==a&&!r.contains(a)&&!a.contains(r)&&Pa(a,r)>0){let u=a,b=!1;for(;u&&!u.contains(r);){if(Ea(u.getBoundingClientRect(),d)){b=!0;break}u=u.parentElement}if(b)return}je.push(l)}})}function qt(t,s){Pt.set(t,s)}function ss(){let t=!1,s=!1;je.forEach(a=>{const{direction:l}=a;l==="horizontal"?t=!0:s=!0});let n=0;Pt.forEach(a=>{n|=a}),t&&s?Dt("intersection",n):t?Dt("horizontal",n):s?Dt("vertical",n):za()}let Ht=new AbortController;function vt(){Ht.abort(),Ht=new AbortController;const t={capture:!0,signal:Ht.signal};lt.size&&(Ke?(je.length>0&&Me.forEach((s,n)=>{const{body:a}=n;s>0&&(a.addEventListener("contextmenu",Tt,t),a.addEventListener("pointerleave",Lt,t),a.addEventListener("pointermove",Lt,t))}),window.addEventListener("pointerup",Tt,t),window.addEventListener("pointercancel",Tt,t)):Me.forEach((s,n)=>{const{body:a}=n;s>0&&(a.addEventListener("pointerdown",Da,t),a.addEventListener("pointermove",Lt,t))}))}function Ct(t,s){lt.forEach(n=>{const{setResizeHandlerState:a}=n,l=je.includes(n);a(t,l,s)})}function La(){const[t,s]=m.useState(0);return m.useCallback(()=>s(n=>n+1),[])}function D(t,s){if(!t)throw console.error(s),Error(s)}function qe(t,s,n=Zt){return t.toFixed(n)===s.toFixed(n)?0:t>s?1:-1}function we(t,s,n=Zt){return qe(t,s,n)===0}function fe(t,s,n){return qe(t,s,n)===0}function Ta(t,s,n){if(t.length!==s.length)return!1;for(let a=0;a<t.length;a++){const l=t[a],r=s[a];if(!fe(l,r,n))return!1}return!0}function Ve({panelConstraints:t,panelIndex:s,size:n}){const a=t[s];D(a!=null,`Panel constraints not found for index ${s}`);let{collapsedSize:l=0,collapsible:r,maxSize:i=100,minSize:d=0}=a;if(qe(n,d)<0)if(r){const f=(l+d)/2;qe(n,f)<0?n=l:n=d}else n=d;return n=Math.min(i,n),n=parseFloat(n.toFixed(Zt)),n}function Ze({delta:t,initialLayout:s,panelConstraints:n,pivotIndices:a,prevLayout:l,trigger:r}){if(fe(t,0))return s;const i=[...s],[d,f]=a;D(d!=null,"Invalid first pivot index"),D(f!=null,"Invalid second pivot index");let h=0;if(r==="keyboard"){{const x=t<0?f:d,o=n[x];D(o,`Panel constraints not found for index ${x}`);const{collapsedSize:g=0,collapsible:u,minSize:b=0}=o;if(u){const v=s[x];if(D(v!=null,`Previous layout not found for panel index ${x}`),fe(v,g)){const S=b-v;qe(S,Math.abs(t))>0&&(t=t<0?0-S:S)}}}{const x=t<0?d:f,o=n[x];
1D(o,`No panel constraints found for index ${x}`);const{collapsedSize:g=0,collapsible:u,minSize:b=0}=o;if(u){const v=s[x];if(D(v!=null,`Previous layout not found for panel index ${x}`),fe(v,b)){const S=v-g;qe(S,Math.abs(t))>0&&(t=t<0?0-S:S)}}}}{const x=t<0?1:-1;let o=t<0?f:d,g=0;for(;;){const b=s[o];D(b!=null,`Previous layout not found for panel index ${o}`);const S=Ve({panelConstraints:n,panelIndex:o,size:100})-b;if(g+=S,o+=x,o<0||o>=n.length)break}const u=Math.min(Math.abs(t),Math.abs(g));t=t<0?0-u:u}{let o=t<0?d:f;for(;o>=0&&o<n.length;){const g=Math.abs(t)-Math.abs(h),u=s[o];D(u!=null,`Previous layout not found for panel index ${o}`);const b=u-g,v=Ve({panelConstraints:n,panelIndex:o,size:b});if(!fe(u,v)&&(h+=u-v,i[o]=v,h.toPrecision(3).localeCompare(Math.abs(t).toPrecision(3),void 0,{numeric:!0})>=0))break;t<0?o--:o++}}if(Ta(l,i))return l;{const x=t<0?f:d,o=s[x];D(o!=null,`Previous layout not found for panel index ${x}`);const g=o+h,u=Ve({panelConstraints:n,panelIndex:x,size:g});if(i[x]=u,!fe(u,g)){let b=g-u,S=t<0?f:d;for(;S>=0&&S<n.length;){const A=i[S];D(A!=null,`Previous layout not found for panel index ${S}`);const F=A+b,T=Ve({panelConstraints:n,panelIndex:S,size:F});if(fe(A,T)||(b-=T-A,i[S]=T),fe(b,0))break;t>0?S--:S++}}}const p=i.reduce((x,o)=>o+x,0);return fe(p,100)?i:l}function qa({layout:t,panelsArray:s,pivotIndices:n}){let a=0,l=100,r=0,i=0;const d=n[0];D(d!=null,"No pivot index found"),s.forEach((x,o)=>{const{constraints:g}=x,{maxSize:u=100,minSize:b=0}=g;o===d?(a=b,l=u):(r+=b,i+=u)});const f=Math.min(l,100-r),h=Math.max(a,100-i),p=t[d];return{valueMax:f,valueMin:h,valueNow:p}}function it(t,s=document){return Array.from(s.querySelectorAll(`[${Y.resizeHandleId}][data-panel-group-id="${t}"]`))}function en(t,s,n=document){const l=it(t,n).findIndex(r=>r.getAttribute(Y.resizeHandleId)===s);return l??null}function tn(t,s,n){const a=en(t,s,n);return a!=null?[a,a+1]:[-1,-1]}function sn(t,s=document){var n;if(s instanceof HTMLElement&&(s==null||(n=s.dataset)===null||n===void 0?void 0:n.panelGroupId)==t)return s;
1const a=s.querySelector(`[data-panel-group][data-panel-group-id="${t}"]`);return a||null}function At(t,s=document){const n=s.querySelector(`[${Y.resizeHandleId}="${t}"]`);return n||null}function Ha(t,s,n,a=document){var l,r,i,d;const f=At(s,a),h=it(t,a),p=f?h.indexOf(f):-1,x=(l=(r=n[p])===null||r===void 0?void 0:r.id)!==null&&l!==void 0?l:null,o=(i=(d=n[p+1])===null||d===void 0?void 0:d.id)!==null&&i!==void 0?i:null;return[x,o]}function Fa({committedValuesRef:t,eagerValuesRef:s,groupId:n,layout:a,panelDataArray:l,panelGroupElement:r,setLayout:i}){m.useRef({didWarnAboutMissingResizeHandle:!1}),$e(()=>{if(!r)return;const d=it(n,r);for(let f=0;f<l.length-1;f++){const{valueMax:h,valueMin:p,valueNow:x}=qa({layout:a,panelsArray:l,pivotIndices:[f,f+1]}),o=d[f];if(o!=null){const g=l[f];D(g,`No panel data found for index "${f}"`),o.setAttribute("aria-controls",g.id),o.setAttribute("aria-valuemax",""+Math.round(h)),o.setAttribute("aria-valuemin",""+Math.round(p)),o.setAttribute("aria-valuenow",x!=null?""+Math.round(x):"")}}return()=>{d.forEach((f,h)=>{f.removeAttribute("aria-controls"),f.removeAttribute("aria-valuemax"),f.removeAttribute("aria-valuemin"),f.removeAttribute("aria-valuenow")})}},[n,a,l,r]),m.useEffect(()=>{if(!r)return;const d=s.current;D(d,"Eager values not found");const{panelDataArray:f}=d,h=sn(n,r);D(h!=null,`No group found for id "${n}"`);const p=it(n,r);D(p,`No resize handles found for group id "${n}"`);const x=p.map(o=>{const g=o.getAttribute(Y.resizeHandleId);D(g,"Resize handle element has no handle id attribute");const[u,b]=Ha(n,g,f,r);if(u==null||b==null)return()=>{};const v=S=>{if(!S.defaultPrevented)switch(S.key){case"Enter":{S.preventDefault();const A=f.findIndex(F=>F.id===u);if(A>=0){const F=f[A];D(F,`No panel data found for index ${A}`);const T=a[A],{collapsedSize:W=0,collapsible:M,minSize:j=0}=F.constraints;if(T!=null&&M){const R=Ze({delta:fe(T,W)?j-W:W-T,initialLayout:a,panelConstraints:f.map(O=>O.constraints),pivotIndices:tn(n,g,r),prevLayout:a,trigger:"keyboard"});a!==R&&i(R)}}break}}};return o.addEventListener("keydown",v),()=>{o.removeEventListener("keydown",v)}});return()=>{x.forEach(o=>o())}},[r,t,s,n,a,l,i])}function js(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==s[n])return!1;return!0}function nn(t,s){const n=t==="horizontal",{x:a,y:l}=Et(s);return n?a:l}function Wa(t,s,n,a,l){const r=n==="horizontal",i=At(s,l);D(i,`No resize handle element found for id "${s}"`);const d=i.getAttribute(Y.groupId);D(d,"Resize handle element has no group id attribute");let{initialCursorPosition:f}=a;const h=nn(n,t),p=sn(d,l);D(p,`No group element found for id "${d}"`);const x=p.getBoundingClientRect(),o=r?x.width:x.height;return(h-f)/o*100}function Oa(t,s,n,a,l,r){if(Us(t)){const i=n==="horizontal";let d=0;t.shiftKey?d=100:l!=null?d=l:d=10;let f=0;switch(t.key){case"ArrowDown":f=i?0:d;break;case"ArrowLeft":f=i?-d:0;break;case"ArrowRight":f=i?d:0;break;case"ArrowUp":f=i?0:-d;break;case"End":f=100;break;case"Home":f=-100;break}return f}else return a==null?0:Wa(t,s,n,a,r)}function Ba({panelDataArray:t}){const s=Array(t.length),n=t.map(r=>r.constraints);let a=0,l=100;for(let r=0;r<t.length;r++){const i=n[r];D(i,`Panel constraints not found for index ${r}`);const{defaultSize:d}=i;d!=null&&(a++,s[r]=d,l-=d)}for(let r=0;r<t.length;r++){const i=n[r];D(i,`Panel constraints not found for index ${r}`);const{defaultSize:d}=i;if(d!=null)continue;const f=t.length-a,h=l/f;a++,s[r]=h,l-=h}return s}function Oe(t,s,n){s.forEach((a,l)=>{const r=t[l];D(r,`Panel data not found for index ${l}`);const{callbacks:i,constraints:d,id:f}=r,{collapsedSize:h=0,collapsible:p}=d,x=n[f];if(x==null||a!==x){n[f]=a;const{onCollapse:o,onExpand:g,onResize:u}=i;u&&u(a,x),p&&(o||g)&&(g&&(x==null||we(x,h))&&!we(a,h)&&g(),o&&(x==null||!we(x,h))&&we(a,h)&&o())}})}function ut(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!=s[n])return!1;return!0}function Ua({defaultSize:t,dragState:s,layout:n,panelData:a,panelIndex:l,precision:r=3}){const i=n[l];let d;return i==null?d=t!=null?t.toPrecision(r):"1":a.length===1?d="1":d=i.toPrecision(r),{flexBasis:0,flexGrow:d,flexShrink:1,overflow:"hidden",pointerEvents:s!==null?"none":void 0}}function Va(t,s=10){let n=null;return(...l)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{t(...l)},s)}}function ws(t){try{if(typeof localStorage<"u")t.getItem=s=>localStorage.getItem(s),t.setItem=(s,n)=>{localStorage.setItem(s,n)};else throw new Error("localStorage not supported in this environment")}catch(s){console.error(s),t.getItem=()=>null,t.setItem=()=>{}}}function an(t){return`react-resizable-panels:${t}`}function rn(t){return t.map(s=>{const{constraints:n,id:a,idIsFromProps:l,order:r}=s;return l?a:r?`${r}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((s,n)=>s.localeCompare(n)).join(",")}function ln(t,s){try{const n=an(t),a=s.getItem(n);if(a){const l=JSON.parse(a);if(typeof l=="object"&&l!=null)return l}}catch{}return null}function Ga(t,s,n){var a,l;const r=(a=ln(t,n))!==null&&a!==void 0?a:{},i=rn(s);return(l=r[i])!==null&&l!==void 0?l:null}function Ka(t,s,n,a,l){var r;const i=an(t),d=rn(s),f=(r=ln(t,l))!==null&&r!==void 0?r:{};f[d]={expandToSizes:Object.fromEntries(n.entries()),layout:a};try{l.setItem(i,JSON.stringify(f))}catch(h){console.error(h)}}function ys({layout:t,panelConstraints:s}){const n=[...t],a=n.reduce((r,i)=>r+i,0);if(n.length!==s.length)throw Error(`Invalid ${s.length} panel layout: ${n.map(r=>`${r}%`).join(", ")}`);
1if(!fe(a,100)&&n.length>0)for(let r=0;r<s.length;r++){const i=n[r];D(i!=null,`No layout data found for index ${r}`);const d=100/a*i;n[r]=d}let l=0;for(let r=0;r<s.length;r++){const i=n[r];D(i!=null,`No layout data found for index ${r}`);const d=Ve({panelConstraints:s,panelIndex:r,size:i});i!=d&&(l+=i-d,n[r]=d)}if(!fe(l,0))for(let r=0;r<s.length;r++){const i=n[r];D(i!=null,`No layout data found for index ${r}`);const d=i+l,f=Ve({panelConstraints:s,panelIndex:r,size:d});if(i!==f&&(l-=f-i,n[r]=f,fe(l,0)))break}return n}const Qa=100,et={getItem:t=>(ws(et),et.getItem(t)),setItem:(t,s)=>{ws(et),et.setItem(t,s)}},Ns={};function on({autoSaveId:t=null,children:s,className:n="",direction:a,forwardedRef:l,id:r=null,onLayout:i=null,keyboardResizeBy:d=null,storage:f=et,style:h,tagName:p="div",...x}){const o=es(r),g=m.useRef(null),[u,b]=m.useState(null),[v,S]=m.useState([]),A=La(),F=m.useRef({}),T=m.useRef(new Map),W=m.useRef(0),M=m.useRef({autoSaveId:t,direction:a,dragState:u,id:o,keyboardResizeBy:d,onLayout:i,storage:f}),j=m.useRef({layout:v,panelDataArray:[],panelDataArrayChanged:!1});m.useRef({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),m.useImperativeHandle(l,()=>({getId:()=>M.current.id,getLayout:()=>{const{layout:N}=j.current;return N},setLayout:N=>{const{onLayout:E}=M.current,{layout:$,panelDataArray:_}=j.current,C=ys({layout:N,panelConstraints:_.map(I=>I.constraints)});js($,C)||(S(C),j.current.layout=C,E&&E(C),Oe(_,C,F.current))}}),[]),$e(()=>{M.current.autoSaveId=t,M.current.direction=a,M.current.dragState=u,M.current.id=o,M.current.onLayout=i,M.current.storage=f}),Fa({committedValuesRef:M,eagerValuesRef:j,groupId:o,layout:v,panelDataArray:j.current.panelDataArray,setLayout:S,panelGroupElement:g.current}),m.useEffect(()=>{const{panelDataArray:N}=j.current;if(t){if(v.length===0||v.length!==N.length)return;let E=Ns[t];E==null&&(E=Va(Ka,Qa),Ns[t]=E);const $=[...N],_=new Map(T.current);E(t,$,_,v,f)}},[t,v,f]),m.useEffect(()=>{});const R=m.useCallback(N=>{const{onLayout:E}=M.current,{layout:$,panelDataArray:_}=j.current;if(N.constraints.collapsible){const C=_.map(he=>he.constraints),{collapsedSize:I=0,panelSize:B,pivotIndices:J}=Ae(_,N,$);if(D(B!=null,`Panel size not found for panel "${N.id}"`),!we(B,I)){T.current.set(N.id,B);const xe=Ue(_,N)===_.length-1?B-I:I-B,K=Ze({delta:xe,initialLayout:$,panelConstraints:C,pivotIndices:J,prevLayout:$,trigger:"imperative-api"});ut($,K)||(S(K),j.current.layout=K,E&&E(K),Oe(_,K,F.current))}}},[]),O=m.useCallback((N,E)=>{const{onLayout:$}=M.current,{layout:_,panelDataArray:C}=j.current;if(N.constraints.collapsible){const I=C.map(ne=>ne.constraints),{collapsedSize:B=0,panelSize:J=0,minSize:he=0,pivotIndices:xe}=Ae(C,N,_),K=E??he;if(we(J,B)){const ne=T.current.get(N.id),Ce=ne!=null&&ne>=K?ne:K,Ee=Ue(C,N)===C.length-1?J-Ce:Ce-J,ae=Ze({delta:Ee,initialLayout:_,panelConstraints:I,pivotIndices:xe,prevLayout:_,trigger:"imperative-api"});ut(_,ae)||(S(ae),j.current.layout=ae,$&&$(ae),Oe(C,ae,F.current))}}},[]),G=m.useCallback(N=>{const{layout:E,panelDataArray:$}=j.current,{panelSize:_}=Ae($,N,E);return D(_!=null,`Panel size not found for panel "${N.id}"`),_},[]),w=m.useCallback((N,E)=>{const{panelDataArray:$}=j.current,_=Ue($,N);return Ua({defaultSize:E,dragState:u,layout:v,panelData:$,panelIndex:_})},[u,v]),q=m.useCallback(N=>{const{layout:E,panelDataArray:$}=j.current,{collapsedSize:_=0,collapsible:C,panelSize:I}
1=Ae($,N,E);return D(I!=null,`Panel size not found for panel "${N.id}"`),C===!0&&we(I,_)},[]),oe=m.useCallback(N=>{const{layout:E,panelDataArray:$}=j.current,{collapsedSize:_=0,collapsible:C,panelSize:I}=Ae($,N,E);return D(I!=null,`Panel size not found for panel "${N.id}"`),!C||qe(I,_)>0},[]),X=m.useCallback(N=>{const{panelDataArray:E}=j.current;E.push(N),E.sort(($,_)=>{const C=$.order,I=_.order;return C==null&&I==null?0:C==null?-1:I==null?1:C-I}),j.current.panelDataArrayChanged=!0,A()},[A]);$e(()=>{if(j.current.panelDataArrayChanged){j.current.panelDataArrayChanged=!1;const{autoSaveId:N,onLayout:E,storage:$}=M.current,{layout:_,panelDataArray:C}=j.current;let I=null;if(N){const J=Ga(N,C,$);J&&(T.current=new Map(Object.entries(J.expandToSizes)),I=J.layout)}I==null&&(I=Ba({panelDataArray:C}));const B=ys({layout:I,panelConstraints:C.map(J=>J.constraints)});js(_,B)||(S(B),j.current.layout=B,E&&E(B),Oe(C,B,F.current))}}),$e(()=>{const N=j.current;return()=>{N.layout=[]}},[]);const Z=m.useCallback(N=>{let E=!1;const $=g.current;return $&&window.getComputedStyle($,null).getPropertyValue("direction")==="rtl"&&(E=!0),function(C){C.preventDefault();const I=g.current;if(!I)return()=>null;const{direction:B,dragState:J,id:he,keyboardResizeBy:xe,onLayout:K}=M.current,{layout:ne,panelDataArray:Ce}=j.current,{initialLayout:Fe}=J??{},Ee=tn(he,N,I);let ae=Oa(C,N,B,J,xe,I);const ct=B==="horizontal";ct&&E&&(ae=-ae);const dt=Ce.map(Mt=>Mt.constraints),Pe=Ze({delta:ae,initialLayout:Fe??ne,panelConstraints:dt,pivotIndices:Ee,prevLayout:ne,trigger:Us(C)?"keyboard":"mouse-or-touch"}),Xe=!ut(ne,Pe);(Vs(C)||Gs(C))&&W.current!=ae&&(W.current=ae,!Xe&&ae!==0?ct?qt(N,ae<0?Qs:Xs):qt(N,ae<0?Js:Ys):qt(N,0)),Xe&&(S(Pe),j.current.layout=Pe,K&&K(Pe),Oe(Ce,Pe,F.current))}},[]),se=m.useCallback((N,E)=>{const{onLayout:$}=M.current,{layout:_,panelDataArray:C}=j.current,I=C.map(ne=>ne.constraints),{panelSize:B,pivotIndices:J}=Ae(C,N,_);D(B!=null,`Panel size not found for panel "${N.id}"`);const xe=Ue(C,N)===C.length-1?B-E:E-B,K=Ze({delta:xe,initialLayout:_,panelConstraints:I,pivotIndices:J,prevLayout:_,trigger:"imperative-api"});ut(_,K)||(S(K),j.current.layout=K,$&&$(K),Oe(C,K,F.current))},[]),_e=m.useCallback((N,E)=>{const{layout:$,panelDataArray:_}=j.current,{collapsedSize:C=0,collapsible:I}=E,{collapsedSize:B=0,collapsible:J,maxSize:he=100,minSize:xe=0}=N.constraints,{panelSize:K}=Ae(_,N,$);K!=null&&(I&&J&&we(K,C)?we(C,B)||se(N,B):K<xe?se(N,xe):K>he&&se(N,he))},[se]),Ne=m.useCallback((N,E)=>{const{direction:$}=M.current,{layout:_}=j.current;if(!g.current)return;const C=At(N,g.current);D(C,`Drag handle element not found for id "${N}"`);const I=nn($,E);b({dragHandleId:N,dragHandleRect:C.getBoundingClientRect(),initialCursorPosition:I,initialLayout:_})},[]),re=m.useCallback(()=>{b(null)},[]),y=m.useCallback(N=>{const{panelDataArray:E}=j.current,$=Ue(E,N);$>=0&&(E.splice($,1),delete F.current[N.id],j.current.panelDataArrayChanged=!0,A())},[A]),te=m.useMemo(()=>({collapsePanel:R,direction:a,dragState:u,expandPanel:O,getPanelSize:G,getPanelStyle:w,groupId:o,isPanelCollapsed:q,isPanelExpanded:oe,reevaluatePanelConstraints:_e,registerPanel:X,registerResizeHandle:Z,resizePanel:se,startDragging:Ne,stopDragging:re,unregisterPanel:y,panelGroupElement:g.current}),[R,u,a,O,G,w,o,q,oe,_e,X,Z,se,Ne,re,y]),ve={display:"flex",flexDirection:a==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return m.createElement(_t.Provider,{value:te},m.createElement(p,{...x,children:s,className:n,id:r,ref:g,style:{...ve,...h},[Y.group]:"",[Y.groupDirection]:a,[Y.groupId]:o}))}const cn=m.forwardRef((t,s)=>m.createElement(on,{...t,forwardedRef:s}));on.displayName="PanelGroup";cn.displayName="forwardRef(PanelGroup)";function Ue(t,s){return t.findIndex(n=>n===s||n.id===s.id)}function Ae(t,s,n){const a=Ue(t,s),r=a===t.length-1?[a-1,a]:[a,a+1],i=n[a];return{...s.constraints,panelSize:i,pivotIndices:r}}function Xa({disabled:t,handleId:s,resizeHandler:n,panelGroupElement:a}){m.useEffect(()=>{if(t||n==null||a==null)return;const l=At(s,a);if(l==null)return;const r=i=>{if(!i.defaultPrevented)switch(i.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{i.preventDefault(),n(i);break}case"F6":{i.preventDefault();const d=l.getAttribute(Y.groupId);D(d,`No group element found for id "${d}"`);const f=it(d,a),h=en(d,s,a);D(h!==null,`No resize element found for id "${s}"`);const p=i.shiftKey?h>0?h-1:f.length-1:h+1<f.length?h+1:0;f[p].focus();break}}};return l.addEventListener("keydown",r),()=>{l.removeEventListener("keydown",r)}},[a,t,s,n])}function dn({children:t=null,className:s="",disabled:n=!1,hitAreaMargins:a,id:l,onBlur:r,onClick:i,onDragging:d,onFocus:f,onPointerDown:h,onPointerUp:p,style:x={},tabIndex:o=0,tagName:g="div",...u}){var b,v;const S=m.useRef(null),A=m.useRef({onClick:i,onDragging:d,onPointerDown:h,onPointerUp:p});m.useEffect(()=>{A.current.onClick=i,A.current.onDragging=d,A.current.onPointerDown=h,A.current.onPointerUp=p});const F=m.useContext(_t);if(F===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:T,groupId:W,registerResizeHandle:M,startDragging:j,stopDragging:R,panelGroupElement:O}=F,G=es(l),[w,q]=m.useState("inactive"),[oe,X]=m.useState(!1),[Z,se]=m.useState(null),_e=m.useRef({state:w});$e(()=>{_e.current.state=w}),m.useEffect(()=>{if(n)se(null);else{const te=M(G);se(()=>te)}},[n,G,M]);const Ne=(b=a==null?void 0:a.coarse)!==null&&b!==void 0?b:15,re=(v=a==null?void 0:a.fine)!==null&&v!==void 0?v:5;m.useEffect(()=>{if(n||Z==null)return;const te=S.current;D(te,"Element ref not attached");let ve=!1;return $a(G,te,T,{coarse:Ne,fine:re},(E,$,_)=>{if(!$){q("inactive");return}switch(E){case"down":{q("drag"),ve=!1,D(_,'Expected event to be defined for "down" action'),j(G,_);const{onDragging:C,onPointerDown:I}=A.current;C==null||C(!0),I==null||I();break}case"move":{const{state:C}=_e.current;ve=!0,C!=="drag"&&q("hover"),D(_,'Expected event to be defined for "move" action'),Z(_);break}case"up":{q("hover"),R();const{onClick:C,onDragging:I,onPointerUp:B}=A.current;I==null||I(!1),B==null||B(),ve||C==null||C();break}}})},[Ne,T,n,re,M,G,Z,j,R]),Xa({disabled:n,handleId:G,resizeHandler:Z,panelGroupElement:O});const y={touchAction:"none",userSelect:"none"};return m.createElement(g,{...u,children:t,className:s,id:l,onBlur:()=>{X(!1),r==null||r()},onFocus:()=>{X(!0),f==null||f()},ref:S,role:"separator",style:{...y,...x},tabIndex:o,[Y.groupDirection]:T,[Y.groupId]:W,[Y.resizeHandle]:"",[Y.resizeHandleActive]:w==="drag"?"pointer":oe?"keyboard":void 0,[Y.resizeHandleEnabled]:!n,[Y.resizeHandleId]:G,[Y.resizeHandleState]:w})}dn.displayName="PanelResizeHandle";const Ja=({className:t,...s})=>e.jsx(cn,{className:P("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",t),...s}),mt=Bs,Ft=({withHandle:t,className:s,...n})=>e.jsx(dn,{className:P("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 [&[data-panel-group-direction=vertical]>div]:rotate-90",s),...n,children:t&&e.jsx("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:e.jsx(jn,{className:"h-2.5 w-2.5"})})});function Ya({activeFilter:t,onFilterChange:s,channelFilter:n,onChannelChange:a,assigneeFilter:l,onAssigneeChange:r,counts:i}){var h,p;const d=[{key:"all",label:"All",icon:e.jsx(fa,{className:"h-4 w-4"})},{key:"unread",label:"Unread",icon:e.jsx(zs,{className:"h-4 w-4"})},{key:"starred",label:"Starred",icon:e.jsx(Jt,{className:"h-4 w-4"})},{key:"archived",label:"Archived",icon:e.jsx(wn,{className:"h-4 w-4"})}],f=[{key:"all",label:"All Channels",icon:e.jsx(la,{className:"h-4 w-4"})},{key:"sms",label:"SMS",icon:e.jsx(ge,{className:"h-4 w-4"})},{key:"whatsapp",label:"WhatsApp",icon:e.jsx(pe,{className:"h-4 w-4 text-green-500"})},{key:"email",label:"Email",icon:e.jsx(ze,{className:"h-4 w-4 text-orange-500"})},{key:"call",label:"Calls",icon:e.jsx(ge,{className:"h-4 w-4 text-blue-500"})}];return e.jsxs("div",{className:"px-2 py-3 space-y-3",children:[e.jsx("div",{className:"space-y-1",children:d.map(x=>e.jsxs(k,{variant:t===x.key?"secondary":"ghost",className:P("w-full justify-start",t===x.key&&"bg-primary/10 text-primary"),size:"sm",onClick:()=>s(x.key),children:[x.icon,e.jsx("span",{className:"ml-2 flex-1 text-left",children:x.label}),e.jsx(be,{variant:"secondary",className:P("ml-auto text-xs",t===x.key&&"bg-primary text-primary-foreground"),children:i[x.key]})]},x.key))}),e.jsx(Ge,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground px-2 mb-1",children:"Channel"}),e.jsxs(st,{children:[e.jsx(nt,{asChild:!0,children:e.jsxs(k,{variant:"outline",className:"w-full justify-between",size:"sm",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[(h=f.find(x=>x.key===n))==null?void 0:h.icon,(p=f.find(x=>x.key===n))==null?void 0:p.label]}),e.jsx(ms,{className:"h-4 w-4 opacity-50"})]})}),e.jsx(at,{className:"w-48",children:f.map(x=>e.jsxs(Ie,{onClick:()=>a(x.key),className:P(n===x.key&&"bg-accent"),children:[x.icon,e.jsx("span",{className:"ml-2",children:x.label})]},x.key))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground px-2 mb-1",children:"Assignee"}),e.jsxs(st,{children:[e.jsx(nt,{asChild:!0,children:e.jsxs(k,{variant:"outline",className:"w-full justify-between",size:"sm",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(tt,{className:"h-4 w-4"}),l==="all"?"Anyone":l==="me"?"Assigned to me":"Unassigned"]}),e.jsx(ms,{className:"h-4 w-4 opacity-50"})]})}),e.jsxs(at,{className:"w-48",children:[e.jsxs(Ie,{onClick:()=>r("all"),children:[e.jsx(tt,{className:"h-4 w-4 mr-2"}),"Anyone"]}),e.jsxs(Ie,{onClick:()=>r("me"),children:[e.jsx(tt,{className:"h-4 w-4 mr-2"}),"Assigned to me"]}),e.jsxs(Ie,{onClick:()=>r("unassigned"),children:[e.jsx(Le,{className:"h-4 w-4 mr-2"}),"Unassigned"]})]})]})]})]})}function un({contactId:t,variant:s="full",className:n}){const{workspace:a}=He(),{data:l}=Kt(t),r=_s(),[i,d]=m.useState(null),f=!(l!=null&&l.ai_disabled),h=i??f;m.useEffect(()=>{i!==null&&i===f&&d(null)},[f,i]);const{data:p}=ye({queryKey:["chatbots-active",a==null?void 0:a.id],queryFn:async()=>
1{if(!a)return[];const{data:o}=await V.from("chatbots").select("id, name, status").eq("workspace_id",a.id).eq("status","active");return o||[]},enabled:!!a}),x=o=>{t&&(d(o),r.mutate({id:t,ai_disabled:!o},{onSuccess:()=>U.success(o?"AI agent is now replying":"AI agent paused for this contact"),onError:()=>{d(null),U.error("Couldn't change the AI agent — try again")}}))};return t?s==="compact"?e.jsxs(k,{type:"button",variant:"outline",size:"sm","aria-pressed":h,onClick:()=>x(!h),className:P("h-8 gap-1.5 px-2.5 text-xs font-medium",h?"border-primary/40 bg-primary/10 text-primary hover:bg-primary/20":"text-muted-foreground",n),children:[r.isPending?e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(us,{className:"h-3.5 w-3.5"}),h?"AI On":"AI Off"]}):e.jsxs("div",{className:P("space-y-2 p-3 rounded-lg bg-muted/40 border border-border",n),children:[e.jsxs("button",{type:"button",onClick:()=>x(!h),className:"flex w-full items-center justify-between gap-2 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(us,{className:P("h-4 w-4",h?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:"text-sm font-medium",children:"AI Agent"}),e.jsx("span",{className:P("text-xs",h?"text-primary":"text-muted-foreground"),children:h?"On":"Off"})]}),e.jsx(Wt,{checked:h,tabIndex:-1,className:"pointer-events-none"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:h?"Replies to this contact automatically.":"You reply manually — no automatic replies."}),h&&e.jsxs(Es,{value:(l==null?void 0:l.assigned_chatbot_id)||"",onValueChange:o=>{r.mutate({id:t,assigned_chatbot_id:o||null},{onSuccess:()=>U.success("Agent assigned"),onError:()=>U.error("Failed")})},children:[e.jsx(Ps,{className:"h-8 text-xs",children:e.jsx(As,{placeholder:"Select agent..."})}),e.jsx(Ms,{children:p==null?void 0:p.map(o=>e.jsx(Is,{value:o.id,className:"text-xs",children:o.name},o.id))})]})]}):null}const vs={sms:{label:"SMS",color:"text-green-400",bgColor:"bg-green-500/20",badgeBg:"bg-green-500/15 text-green-400 border-green-500/30",gradient:"from-green-500 to-emerald-400"},email:{label:"Email",color:"text-blue-400",bgColor:"bg-blue-500/20",badgeBg:"bg-blue-500/15 text-blue-400 border-blue-500/30",gradient:"from-blue-500 to-cyan-400"},whatsapp:{label:"WhatsApp",color:"text-teal-400",bgColor:"bg-teal-500/20",badgeBg:"bg-teal-500/15 text-teal-400 border-teal-500/30",gradient:"from-teal-500 to-emerald-400"},messenger:{label:"Messenger",color:"text-purple-400",bgColor:"bg-purple-500/20",badgeBg:"bg-purple-500/15 text-purple-400 border-purple-500/30",gradient:"from-purple-500 to-violet-400"},instagram:{label:"Instagram",color:"text-pink-400",bgColor:"bg-pink-500/20",badgeBg:"bg-pink-500/15 text-pink-400 border-pink-500/30",gradient:"from-pink-500 to-rose-400"},call:{label:"Calls",color:"text-orange-400",bgColor:"bg-orange-500/20",badgeBg:"bg-orange-500/15 text-orange-400 border-orange-500/30",gradient:"from-orange-500 to-amber-400"},livechat:{label:"Live Chat",color:"text-cyan-400",bgColor:"bg-cyan-500/20",badgeBg:"bg-cyan-500/15 text-cyan-400 border-cyan-500/30",gradient:"from-cyan-500 to-sky-400"}};function ke(t){return vs[t]||vs.sms}function Za(t){const s=["from-violet-500 to-purple-600","from-blue-500 to-indigo-600","from-emerald-500 to-teal-600","from-orange-500 to-red-600","from-pink-500 to-rose-600","from-cyan-500 to-blue-600","from-amber-500 to-orange-600","from-fuchsia-500 to-pink-600","from-lime-500 to-green-600","from-sky-500 to-cyan-600"];let n=0;for(let a=0;a<t.length;a++)n=t.charCodeAt(a)+((n<<5)-n);return s[Math.abs(n)%s.length]}const er={sm:"h-8 w-8 text-xs",md:"h-10 w-10 text-sm",lg:"h-16 w-16 text-xl"},tr={sm:"h-3 w-3 -bottom-0.5 -right-0.5",md:"h-4 w-4 -bottom-0.5 -right-0.5",lg:"h-5 w-5 -bottom-0 -right-0"},Cs={sms:"bg-green-500",email:"bg-blue-500",whatsapp:"bg-teal-500",messenger:"bg-purple-500",instagram:"bg-pink-500",call:"bg-orange-500",livechat:"bg-cyan-500"};function gt({name:t,size:s="md",lastChannel:n,className:a}){const l=t.split(" ").map(i=>i[0]).join("").toUpperCase().slice(0,2)||"?",r=Za(t);return e.jsxs("div",{className:P("relative shrink-0",a),children:[e.jsx("div",{className:P("rounded-full bg-gradient-to-br flex items-center justify-center font-semibold text-white shadow-lg",r,er[s]),children:l}),n&&Cs[n]&&e.jsx("div",{className:P("absolute rounded-full border-2 border-background",Cs[n],tr[s])})]})}function sr({open:t,onOpenChange:s,contactId:n,contactName:a,mode:l}){const{workspace:r}=He(),i=Fs(),[d,f]=m.useState(null),{data:h=[],isLoading:p}=ye({queryKey:["automations-active",r==null?void 0:r.id],queryFn:async()=>
1{if(!(r!=null&&r.id))return[];const{data:u,error:b}=await V.from("automations").select("id, name, description, trigger_type, status").eq("workspace_id",r.id).eq("status","active").order("name");if(b)throw b;return u||[]},enabled:!!(r!=null&&r.id)&&t}),{data:x=[]}=ye({queryKey:["contact-automation-runs",n],queryFn:async()=>{const{data:u,error:b}=await V.from("automation_runs").select("id, automation_id, status, started_at, automations:automation_id(name)").eq("contact_id",n).in("status",["running","pending"]).order("started_at",{ascending:!1});if(b)throw b;return u||[]},enabled:l==="remove"&&t&&!!n}),o=os({mutationFn:async u=>{const{error:b}=await V.functions.invoke("fire-automation-triggers",{body:{eventType:"manual_enrollment",contactId:n,workspaceId:r==null?void 0:r.id,triggerData:{automationId:u,enrolledBy:"manual"}}});if(b)throw b},onSuccess:()=>{U.success(`${a||"Contact"} enrolled in workflow`),i.invalidateQueries({queryKey:["contact-automation-runs",n]}),s(!1)},onError:u=>U.error("Failed to enroll: "+u.message)}),g=os({mutationFn:async u=>{const{error:b}=await V.from("automation_runs").update({status:"cancelled",completed_at:new Date().toISOString()}).eq("id",u);if(b)throw b},onSuccess:()=>{U.success("Removed from workflow"),i.invalidateQueries({queryKey:["contact-automation-runs",n]}),s(!1)},onError:u=>U.error("Failed to remove: "+u.message)});return e.jsx(St,{open:t,onOpenChange:s,children:e.jsxs(kt,{className:"max-w-md",children:[e.jsxs(Qt,{children:[e.jsxs(zt,{className:"flex items-center gap-2",children:[e.jsx(Vt,{className:"h-5 w-5"}),l==="add"?"Add to Workflow":"Remove from Workflow"]}),e.jsx(yn,{children:l==="add"?`Select a workflow to enroll ${a||"this contact"} in.`:`Cancel active workflows for ${a||"this contact"}.`})]}),e.jsx(ot,{className:"max-h-[300px]",children:p?e.jsx("div",{className:"space-y-2 p-1",children:[1,2,3].map(u=>e.jsx(ht,{className:"h-14 w-full"},u))}):l==="add"?h.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No active workflows found"}):e.jsx("div",{className:"space-y-1 p-1",children:h.map(u=>e.jsxs("button",{className:`w-full text-left p-3 rounded-lg border transition-colors ${d===u.id?"border-primary bg-primary/5":"hover:bg-muted/50"}`,onClick:()=>f(u.id),children:[e.jsx("p",{className:"text-sm font-medium",children:u.name}),u.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-1",children:u.description}),e.jsx(be,{variant:"secondary",className:"text-xs mt-1",children:u.trigger_type})]},u.id))}):x.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No active workflows for this contact"}):e.jsx("div",{className:"space-y-1 p-1",children:x.map(u=>{var b;return e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:((b=u.automations)==null?void 0:b.name)||"Workflow"}),e.jsx(be,{variant:"outline",className:"text-xs mt-1",children:u.status})]}),e.jsxs(k,{size:"sm",variant:"destructive",onClick:()=>g.mutate(u.id),disabled:g.isPending,children:[g.isPending?e.jsx(Te,{className:"h-3 w-3 animate-spin"}):e.jsx(Nn,{className:"h-3 w-3 mr-1"}),"Stop"]})]},u.id)})})}),l==="add"&&e.jsxs(Rs,{children:[e.jsx(k,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsxs(k,{onClick:()=>d&&o.mutate(d),disabled:!d||o.isPending,children:[o.isPending?e.jsx(Te,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(ia,{className:"h-4 w-4 mr-1"}),"Enroll"]})]})]})})}const ft={sms:"comms",whatsapp:"comms",email:"comms",call:"comms",note:"comms",deal:"sales",task:"tasks",meeting:"tasks"},nr={sms:pe,whatsapp:pe,email:ze,call:ge,note:Ot,deal:vn,task:ha,meeting:Yt},ar={sms:"text-blue-400",whatsapp:"text-green-400",email:"text-purple-400",call:"text-orange-400",note:"text-yellow-400",deal:"text-emerald-400",task:"text-cyan-400",meeting:"text-pink-400"};function rr({contactId:t,className:s}){const{workspace:n}=He(),[a,l]=m.useState("all"),{data:r=[],isLoading:i}=ye({queryKey:["unified-timeline",n==null?void 0:n.id,t],enabled:!!(n!=null&&n.id)&&!!t,queryFn:async()=>
1{if(!(n!=null&&n.id)||!t)return[];const h=[],{data:p}=await V.from("unified_messages").select("id, channel, content, direction, created_at, conversation:unified_conversations!inner(contact_id)").eq("conversation.contact_id",t).order("created_at",{ascending:!1}).limit(50);(p||[]).forEach(u=>{var v;const b=u.channel==="email"?"email":u.channel==="whatsapp"?"whatsapp":"sms";h.push({id:`msg-${u.id}`,kind:b,title:`${u.direction==="outbound"?"Sent":"Received"} ${b.toUpperCase()}`,preview:(v=u.content)==null?void 0:v.slice(0,120),at:u.created_at,meta:{direction:u.direction}})});const{data:x}=await V.from("call_logs").select("id, direction, duration_seconds, outcome, started_at").eq("contact_id",t).order("started_at",{ascending:!1}).limit(30);(x||[]).forEach(u=>{h.push({id:`call-${u.id}`,kind:"call",title:`${u.direction==="outbound"?"Called":"Inbound call"}${u.duration_seconds?` · ${Math.round(u.duration_seconds/60)}m`:""}`,preview:u.outcome||null,at:u.started_at,meta:{direction:u.direction}})});const{data:o}=await V.from("activities").select("id, type, subject, description, scheduled_at, completed_at, created_at").eq("contact_id",t).order("created_at",{ascending:!1}).limit(30);(o||[]).forEach(u=>{var v;const b=u.type==="note"?"note":u.type==="meeting"?"meeting":"task";h.push({id:`act-${u.id}`,kind:b,title:u.subject||(b==="note"?"Note":b==="meeting"?"Meeting":"Task"),preview:(v=u.description)==null?void 0:v.slice(0,120),at:u.scheduled_at||u.created_at})});const{data:g}=await V.from("deals").select("id, name, value, status, created_at, updated_at").eq("contact_id",t).order("updated_at",{ascending:!1}).limit(20);return(g||[]).forEach(u=>{h.push({id:`deal-${u.id}`,kind:"deal",title:u.name,preview:`${u.status||"open"}${u.value?` · £${Number(u.value).toLocaleString()}`:""}`,at:u.updated_at||u.created_at})}),h.sort((u,b)=>new Date(b.at).getTime()-new Date(u.at).getTime()),h}}),d=m.useMemo(()=>a==="all"?r:r.filter(h=>ft[h.kind]===a),[r,a]),f=m.useMemo(()=>({all:r.length,comms:r.filter(h=>ft[h.kind]==="comms").length,sales:r.filter(h=>ft[h.kind]==="sales").length,tasks:r.filter(h=>ft[h.kind]==="tasks").length}),[r]);return t?e.jsxs("div",{className:P("flex flex-col h-full",s),children:[e.jsxs("div",{className:"px-3 py-2 border-b border-white/[0.06] flex items-center gap-2",children:[e.jsx(cs,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"text-xs font-semibold",children:"Activity Timeline"}),e.jsx(be,{variant:"secondary",className:"text-[10px] ml-auto",children:r.length})]}),e.jsx("div",{className:"px-2 py-2 flex gap-1 border-b border-white/[0.04]",children:["all","comms","sales","tasks"].map(h=>e.jsxs(k,{variant:a===h?"default":"ghost",size:"sm",className:"h-6 px-2 text-[10px] capitalize",onClick:()=>l(h),children:[h," ",e.jsx("span",{className:"ml-1 opacity-60",children:f[h]})]},h))}),e.jsx(ot,{className:"flex-1",children:e.jsx("div",{className:"p-2 space-y-1",children:i?e.jsx("div",{className:"text-xs text-muted-foreground p-3",children:"Loading…"}):d.length===0?e.jsx("div",{className:"text-xs text-muted-foreground p-3 text-center",children:"No activity yet"}):d.map(h=>{var g;const p=nr[h.kind],x=((g=h.meta)==null?void 0:g.direction)==="inbound",o=h.kind==="call"&&x?Cn:h.kind==="call"?Sn:p;return e.jsxs("div",{className:"flex gap-2 p-2 rounded hover:bg-white/[0.03] transition-colors",children:[e.jsx("div",{className:P("h-7 w-7 rounded-full flex items-center justify-center shrink-0 bg-white/5",ar[h.kind]),children:e.jsx(o,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium truncate",children:h.title}),h.preview&&e.jsx("div",{className:"text-[11px] text-muted-foreground truncate",children:h.preview}),e.jsx("div",{className:"text-[10px] text-muted-foreground/70 mt-0.5",children:$s(h.at,{addSuffix:!0})})]})]},h.id)})})})]}):e.jsxs("div",{className:P("flex flex-col items-center justify-center text-center p-6",s),children:[e.jsx(cs,{className:"h-8 w-8 text-muted-foreground/30 mb-2"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select a contact to see their timeline"})]})}function lr({conversation:t,className:s}){const n=Ds(),{workspace:a}=He(),{data:l}=Kt((t==null?void 0:t.contact_id)||null);_s();const[r,i]=m.useState(!1),[d,f]=m.useState("details"),[h,p]=m.useState(""),[x,o]=m.useState(!1),[g,u]=m.useState(!1),[b,v]=m.useState(!1),[S,A]=m.useState("add"),{data:F}=ye({queryKey:["chatbots-active",a==null?void 0:a.id],queryFn:async()=>
1{if(!a)return[];const{data:w}=await V.from("chatbots").select("id, name, status").eq("workspace_id",a.id).eq("status","active");return w||[]},enabled:!!a}),{data:T}=ye({queryKey:["contact-deals",t==null?void 0:t.contact_id],queryFn:async()=>{if(!(t!=null&&t.contact_id))return[];const{data:w}=await V.from("deals").select("id, name, value, stage_id, pipeline_id, created_at, pipelines(name), pipeline_stages(name)").eq("contact_id",t.contact_id).order("created_at",{ascending:!1}).limit(10);return w||[]},enabled:!!(t!=null&&t.contact_id)}),{data:W,refetch:M}=ye({queryKey:["contact-notes-panel",t==null?void 0:t.contact_id],queryFn:async()=>{if(!(t!=null&&t.contact_id)||!(a!=null&&a.id))return[];const{data:w}=await V.from("notes").select("id, content, created_at, created_by").eq("contact_id",t.contact_id).eq("workspace_id",a.id).order("created_at",{ascending:!1}).limit(20);return w||[]},enabled:!!(t!=null&&t.contact_id)&&!!(a!=null&&a.id)}),{data:j}=ye({queryKey:["contact-activity-panel",t==null?void 0:t.contact_id],queryFn:async()=>{if(!(t!=null&&t.contact_id)||!(a!=null&&a.id))return[];const{data:w}=await V.from("activities").select("id, type, subject, description, created_at").eq("contact_id",t.contact_id).eq("workspace_id",a.id).order("created_at",{ascending:!1}).limit(30);return w||[]},enabled:!!(t!=null&&t.contact_id)&&!!(a!=null&&a.id)});if(!t)return e.jsxs("div",{className:P("flex flex-col items-center justify-center p-6 text-center",s),children:[e.jsx(tt,{className:"h-12 w-12 text-muted-foreground mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a conversation to view contact details"})]});const R=l||t.contact,O=`${R.first_name||""} ${R.last_name||""}`.trim()||"Unknown",G=async()=>{if(!h.trim()||!(a!=null&&a.id)||!t.contact_id)return;const{error:w}=await V.from("notes").insert({contact_id:t.contact_id,workspace_id:a.id,title:"Inbox Note",content:h.trim()});w?U.error("Failed to add note"):(U.success("Note added"),p(""),M())};return e.jsxs(ot,{className:P("h-full",s),children:[e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"flex justify-center mb-3",children:e.jsx(gt,{name:O,size:"lg",lastChannel:t.channels[t.channels.length-1]})}),e.jsx("button",{type:"button",onClick:()=>t.contact_id&&n(`/contacts/${t.contact_id}`),className:"font-semibold text-lg hover:text-primary hover:underline underline-offset-4 transition-colors",title:"Open contact in CRM",children:O}),(l==null?void 0:l.job_title)&&e.jsx("p",{className:"text-xs text-muted-foreground",children:l.job_title}),e.jsx("div",{className:"flex items-center justify-center gap-1 mt-2 flex-wrap",children:t.channels.map(w=>{const q=ke(w);return e.jsx(be,{variant:"outline",className:P("text-[10px]",q.badgeBg),children:q.label},w)})})]}),e.jsx(un,{contactId:t.contact_id}),(a==null?void 0:a.id)&&(r?e.jsx(da,{contactId:t.contact_id,workspaceId:a.id,contactName:O,variant:"compact",onClose:()=>i(!1)}):e.jsxs(k,{variant:"outline",size:"sm",className:"w-full gap-2 border-primary/30 hover:bg-primary/10",onClick:()=>i(!0),children:[e.jsx(De,{className:"h-3.5 w-3.5 text-primary"}),"Brief Me"]})),e.jsx(Ge,{className:"bg-white/[0.06]"}),e.jsxs(kn,{value:d,onValueChange:f,className:"w-full",children:[e.jsxs(zn,{className:"w-full grid grid-cols-3 gap-1 h-auto p-1 bg-muted/40",children:[e.jsx(Je,{value:"details",className:"text-xs px-2 py-1.5",children:"Details"}),e.jsx(Je,{value:"notes",className:"text-xs px-2 py-1.5",children:"Notes"}),e.jsx(Je,{value:"activity",className:"text-xs px-2 py-1.5",children:"Activity"}),e.jsx(Je,{value:"actions",className:"text-xs px-2 py-1.5",children:"Actions"}),e.jsx(Je,{value:"dnd",className:"text-xs px-2 py-1.5",children:"DND"})]}),e.jsxs(Ye,{value:"details",className:"mt-3 space-y-3",children:[e.jsx(Be,{label:"First Name",value:R.first_name}),e.jsx(Be,{label:"Last Name",value:R.last_name}),e.jsx(Be,{label:"Email",value:R.email,icon:e.jsx(ze,{className:"h-3.5 w-3.5 text-blue-400"})}),e.jsx(Be,{label:"Phone",value:R.phone||R.mobile,icon:e.jsx(ge,{className:"h-3.5 w-3.5 text-green-400"})}),l&&e.jsx(Be,{label:"Origin",value:ir(l),icon:e.jsx(Yn,{className:"h-3.5 w-3.5 text-muted-foreground"})}),(l==null?void 0:l.lifecycle_stage)&&e.jsx(Be,{label:"Stage",value:l.lifecycle_stage}),e.jsxs(k,{variant:"outline",size:"sm",className:"w-full mt-2",onClick:()=>n(`/contacts/${t.contact_id}`),children:[e.jsx(Hs,{className:"h-3.5 w-3.5 mr-1.5"}),"Full Profile"]})]}),e.jsxs(Ye,{value:"dnd",className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-white/[0.03] border border-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_n,{className:"h-4 w-4 text-red-400"}),e.jsx("span",{className:"text-sm font-medium",children:"Master DND"})]}),e.jsx(Wt,{disabled:!0,checked:!1}
1)]}),e.jsx("div",{className:"space-y-2",children:[{key:"email",label:"Email",icon:e.jsx(ze,{className:"h-4 w-4 text-blue-400"})},{key:"sms",label:"SMS",icon:e.jsx(pe,{className:"h-4 w-4 text-green-400"})},{key:"call",label:"Calls",icon:e.jsx(ge,{className:"h-4 w-4 text-orange-400"})},{key:"messenger",label:"Facebook Messenger",icon:e.jsx(En,{className:"h-4 w-4 text-purple-400"})},{key:"whatsapp",label:"WhatsApp",icon:e.jsx(pe,{className:"h-4 w-4 text-teal-400"})},{key:"instagram",label:"Instagram",icon:e.jsx(Pn,{className:"h-4 w-4 text-pink-400"})}].map(w=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-md bg-white/[0.02]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[w.icon,e.jsx("span",{className:"text-xs",children:w.label})]}),e.jsx(Wt,{disabled:!0,checked:!1})]},w.key))})]}),e.jsx(Ye,{value:"actions",className:"mt-3 space-y-2",children:[{label:"Add to Workflow",icon:e.jsx(Vt,{className:"h-4 w-4"}),gradient:"from-violet-500 to-purple-600",action:()=>{A("add"),v(!0)}},{label:"Create Deal",icon:e.jsx(Re,{className:"h-4 w-4"}),gradient:"from-blue-500 to-indigo-600",action:()=>o(!0)},{label:"Book Appointment",icon:e.jsx(Yt,{className:"h-4 w-4"}),gradient:"from-emerald-500 to-teal-600",action:()=>n(`/calendar?contactId=${t.contact_id}`)},{label:"Send Review Request",icon:e.jsx(Jt,{className:"h-4 w-4"}),gradient:"from-amber-500 to-orange-600",action:()=>u(!0)},{label:"Add Tag",icon:e.jsx(Zn,{className:"h-4 w-4"}),gradient:"from-pink-500 to-rose-600",action:()=>n(`/contacts/${t.contact_id}`)},{label:"Remove from Workflow",icon:e.jsx(Vt,{className:"h-4 w-4"}),gradient:"from-red-500 to-rose-600",action:()=>{A("remove"),v(!0)}}].map(w=>e.jsxs(k,{variant:"ghost",size:"sm",className:P("w-full justify-start gap-2 bg-gradient-to-r text-white hover:opacity-90 hover:text-white",w.gradient),onClick:w.action,children:[w.icon,w.label]},w.label))}),e.jsxs(Ye,{value:"notes",className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Xt,{placeholder:"Add a note...",value:h,onChange:w=>
1p(w.target.value),className:"min-h-[60px] bg-white/[0.03] border-white/[0.08] text-sm",rows:3}),e.jsxs(k,{size:"sm",className:"w-full",onClick:G,disabled:!h.trim(),children:[e.jsx(Re,{className:"h-3.5 w-3.5 mr-1"}),"Add Note"]})]}),e.jsxs("div",{className:"space-y-2 max-h-[300px] overflow-y-auto",children:[(W==null?void 0:W.length)===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"No notes yet"}),W==null?void 0:W.map(w=>e.jsxs("div",{className:"p-2.5 rounded-lg bg-white/[0.03] border border-white/[0.06] space-y-1",children:[e.jsx("p",{className:"text-xs whitespace-pre-wrap",children:w.content}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:xt(w.created_at,"MMM d, h:mm a")})]},w.id))]})]}),e.jsx(Ye,{value:"activity",className:"mt-3",children:e.jsx("div",{className:"-mx-3",style:{height:360},children:e.jsx(rr,{contactId:(t==null?void 0:t.contact_id)||null,className:"border border-white/[0.06] rounded-md"})})})]}),e.jsx(Ge,{className:"bg-white/[0.06]"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Opportunities"}),e.jsx(k,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>o(!0),children:e.jsx(Re,{className:"h-3.5 w-3.5"})})]}),(T==null?void 0:T.length)===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-3",children:"No deals linked"}):e.jsx("div",{className:"space-y-2",children:T==null?void 0:T.map(w=>{var q,oe;return e.jsxs("div",{className:"p-2.5 rounded-lg bg-white/[0.03] border border-white/[0.06] cursor-pointer hover:bg-white/[0.06] transition-colors",onClick:()=>n(`/pipeline?dealId=${w.id}`),children:[e.jsx("p",{className:"text-xs font-medium truncate",children:An(w)}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[((q=w.pipelines)==null?void 0:q.name)&&e.jsx(be,{variant:"outline",className:"text-[9px] bg-white/[0.04]",children:w.pipelines.name}),((oe=w.pipeline_stages)==null?void 0:oe.name)&&e.jsx(be,{variant:"secondary",className:"text-[9px]",children:w.pipeline_stages.name})]}),w.value&&e.jsxs("p",{className:"text-xs font-semibold text-primary mt-1",children:["£",Number(w.value).toLocaleString()]})]},w.id)})})]}),e.jsx(Ge,{className:"bg-white/[0.06]"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2.5 rounded-lg bg-white/[0.03] border border-white/[0.06] text-center",children:[e.jsx("p",{className:"text-lg font-bold text-primary",children:t.channels.length}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Channels"})]}),e.jsxs("div",{className:"p-2.5 rounded-lg bg-white/[0.03] border border-white/[0.06] text-center",children:[e.jsx("p",{className:"text-lg font-bold text-primary",children:t.unreadCount}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Unread"})]})]})]}),e.jsx(or,{open:x,onOpenChange:o,contactId:t.contact_id,workspaceId:a==null?void 0:a.id}),(t==null?void 0:t.contact_id)&&(a==null?void 0:a.id)&&e.jsx(ua,{open:g,onOpenChange:u,contactId:t.contact_id,contactName:l!=null&&l.first_name?`${l.first_name} ${l.last_name||""}`.trim():"Customer",contactPhone:(l==null?void 0:l.phone)||(l==null?void 0:l.mobile),contactEmail:l==null?void 0:l.email,workspaceId:a.id}),(t==null?void 0:t.contact_id)&&e.jsx(sr,{open:b,onOpenChange:v,contactId:t.contact_id,contactName:l!=null&&l.first_name?`${l.first_name} ${l.last_name||""}`.trim():"Contact",mode:S})]})}function Be({label:t,value:s,icon:n}){return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:t}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[n,e.jsx("p",{className:"text-xs truncate",children:s||"—"})]})]})}function ir(t){const s=(t==null?void 0:t.last_attribution)||{},n=(t==null?void 0:t.first_attribution)||{},a=s.channel||(t==null?void 0:t.utm_source)||s.utm_source||n.utm_source||(t!=null&&t.gclid?"google":null)||(t!=null&&t.fbclid?"meta":null)||(t==null?void 0:t.source)||(t==null?void 0:t.consent_source)||null;return a?{meta:"Meta (Facebook / Instagram)",meta_organic:"Meta (organic)",meta_in_app:"Meta (in-app browser)",google:"Google Ads",google_organic:"Google (organic)",tiktok:"TikTok Ads",tiktok_organic:"TikTok (organic)",form:"Web form",forms_v1:"Web form",forms_v2:"Web form",website_form_unknown:"Website form (source not captured)"}[String(a).toLowerCase()]||String(a):"—"}function or({open:t,onOpenChange:s,contactId:n,workspaceId:a}){const[l,r]=m.useState(""),[i,d]=m.useState(""),{data:f}=ye({queryKey:["pipelines-list",a],queryFn:async()=>
1{if(!a)return[];const{data:o}=await V.from("pipelines").select("id, name").eq("workspace_id",a);return o||[]},enabled:!!a&&t}),[h,p]=m.useState(""),x=async()=>{var v,S;if(!l.trim()||!a)return;const o=h||((v=f==null?void 0:f[0])==null?void 0:v.id);if(!o){U.error("No pipeline available");return}const{data:g}=await V.from("pipeline_stages").select("id").eq("pipeline_id",o).order("sort_order",{ascending:!0}).limit(1),u=(S=g==null?void 0:g[0])==null?void 0:S.id;if(!u){U.error("No stages found");return}const{error:b}=await V.from("deals").insert({name:l.trim(),contact_id:n,workspace_id:a,pipeline_id:o,stage_id:u,value:i?parseFloat(i):null});b?U.error("Failed to create deal"):(U.success("Deal created"),r(""),d(""),s(!1))};return e.jsx(St,{open:t,onOpenChange:s,children:e.jsxs(kt,{className:"sm:max-w-md",children:[e.jsx(Qt,{children:e.jsx(zt,{children:"Add Opportunity"})}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx(rt,{placeholder:"Deal Name",value:l,onChange:o=>r(o.target.value)}),f&&f.length>0&&e.jsxs(Es,{value:h,onValueChange:p,children:[e.jsx(Ps,{children:e.jsx(As,{placeholder:"Select Pipeline"})}),e.jsx(Ms,{children:f.map(o=>e.jsx(Is,{value:o.id,children:o.name},o.id))})]}),e.jsx(rt,{placeholder:"Value (£)",type:"number",value:i,onChange:o=>d(o.target.value)})]}),e.jsxs(Rs,{children:[e.jsx(k,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(k,{onClick:x,disabled:!l.trim(),children:"Create Deal"})]})]})})}function cr({value:t,onChange:s,onKeyDown:n,placeholder:a="Type a message...",disabled:l=!1,className:r,rows:i=3,contactName:d,channel:f="sms",conversationContext:h=[]}){const[p,x]=m.useState(""),[o,g]=m.useState(!1),[u,b]=m.useState(!1),v=m.useRef(null),S=m.useRef(void 0),A=m.useRef(void 0),F=m.useCallback(async M=>{var j;if(M.length<10||l){x(""),b(!1);return}A.current&&A.current.abort(),A.current=new AbortController,g(!0);try{const{data:R,error:O}=await V.functions.invoke("ai-smart-compose",{body:{partialMessage:M,contactName:d,channel:f,conversationContext:h.slice(-5)}});if(O)throw O;R!=null&&R.completion&&!((j=A.current)!=null&&j.signal.aborted)&&(x(R.completion),b(!0))}catch(R){R.name!=="AbortError"&&console.error("Smart compose error:",R),x(""),b(!1)}finally{g(!1)}},[d,f,h,l]);m.useEffect(()=>(S.current&&clearTimeout(S.current),t.length>=10?S.current=setTimeout(()=>{F(t)},500):(x(""),b(!1)),()=>{S.current&&clearTimeout(S.current)}),[t,F]);const T=M=>{if(M.key==="Tab"&&u&&p){M.preventDefault(),s(t+p),x(""),b(!1);return}if(M.key==="Escape"&&u){M.preventDefault(),x(""),b(!1);return}n==null||n(M)},W=M=>{s(M.target.value),u&&(x(""),b(!1))};return e.jsxs("div",{className:"relative",children:[e.jsx(Xt,{ref:v,value:t,onChange:W,onKeyDown:T,placeholder:a,disabled:l,className:P("pr-24 resize-none",r),rows:i}),u&&p&&e.jsxs("div",{className:"absolute inset-0 pointer-events-none p-3 text-sm overflow-hidden","aria-hidden":"true",children:[e.jsx("span",{className:"invisible whitespace-pre-wrap",children:t}),e.jsx("span",{className:"text-muted-foreground/50 whitespace-pre-wrap",children:p})]}),u&&p&&e.jsxs("div",{className:"absolute bottom-1 left-2 flex items-center gap-1.5 text-[10px] text-muted-foreground bg-background/80 backdrop-blur-sm px-1.5 py-0.5 rounded",children:[e.jsx(De,{className:"h-3 w-3 text-primary"}),e.jsx("span",{children:"Tab to accept"}),e.jsx("span",{className:"text-muted-foreground/50",children:"• Esc to dismiss"})]}),o&&e.jsxs("div",{className:"absolute bottom-1 left-2 flex items-center gap-1.5 text-[10px] text-muted-foreground",children:[e.jsx(De,{className:"h-3 w-3 text-primary animate-pulse"}),e.jsx("span",{children:"Thinking..."})]})]})}function dr({conversation:t,selectedChannel:s,onChannelChange:n,onSend:a,sending:l,disabled:r}){const[i,d]=m.useState(""),[f,h]=m.useState(null),{hasWhatsAppCapability:p,isLoadingCapability:x}=pa();Ws();const{options:o,isLoading:g}=ga(),u=m.useMemo(()=>{if(t!=null&&t.contact)return[t.contact.first_name,t.contact.last_name].filter(Boolean).join(" ")||void 0},[t==null?void 0:t.contact]),b=async()=>{!i.trim()||l||r||(await a(i.trim(),s,f||void 0),d(""))};m.useEffect(()=>{const j=R=>{const O=R.detail;O!=null&&O.text&&d(O.text)};return window.addEventListener("inbox-prefill-composer",j),()=>window.removeEventListener("inbox-prefill-composer",j)},[]);const v=j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),b())},S=j=>{const R=ke(j);switch(j){case"sms":return e.jsx(ge,{className:P("h-4 w-4",R.color)});case"whatsapp":return e.jsx(pe,{className:P("h-4 w-4",R.color)});case"email":return e.jsx(ze,{className:P("h-4 w-4",R.color)});default:return e.jsx(pe,{className:"h-4 w-4"})}},A=i.length,F=Math.ceil(A/160)||0,T=(t==null?void 0:t.contact.phone)||(t==null?void 0:t.contact.mobile);if(!t)return null;const W=s==="email",M=s==="sms"||s==="whatsapp";return e.jsxs("div",{className:"bg-transparent",children:[e.jsx("div",{className:"flex items-center gap-1 px-3 pt-2 pb-1.5",children:e.jsx(Qe,{children:["sms","whatsapp","email"].map(j=>{const R=j==="whatsapp"&&!p&&!x,O=j==="email"&&!g&&o.length===0,G=R||O,w=ke(j);return e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsxs(k,{variant:s===j?"default":"ghost",size:"sm",className:P("gap-1.5 h-7 text-xs",s===j&&`shadow-sm bg-gradient-to-r ${w.gradient} text-white`),onClick:()=>n(j),disabled:G,children:[S(j),w.label,(O||R)&&e.jsx(be,{variant:"outline",className:"ml-1 text-[8px] px-1 py-0",children:"Setup"})]})}),e.jsx(me,{children:O?"Add a sending domain in Settings → Domains → Email Sending":R?"WhatsApp not configured. Go to Settings → Phone to connect.":`Send via ${w.label}`})]},j)})})}),T&&!W&&e.jsxs("div",{className:"flex flex-col gap-1 px-4 pb-1.5",children:[M&&e.jsx(ja,{selected:f,onSelect:h,disabled:l||r}),e.jsxs("span",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"To:"}),e.jsx("span",{className:"font-mono text-[11px]",children:T})]})]}),W?t.contact.email?e.jsx(ba,{to:t.contact.email,contact:{...t.contact,id:t.contact_id},compact:!0,className:"border-t-0"},t.contact_id):e.jsx("p",{className:"px-4 pb-3 text-xs text-muted-foreground",children:"This contact has no email address yet."}):e.jsxs("div",{className:"relative px-3 pb-3",children:[e.jsx(cr,{placeholder:"Type a message...",value:i,onChange:j=>{d(j),t!=null&&t.contact_id&&window.dispatchEvent(new CustomEvent("inbox-typing",{detail:{contactId:t.contact_id}}))}
1,onKeyDown:v,disabled:r||l,className:"min-h-[60px] pr-28 bg-white/[0.03] border-white/[0.08]",rows:2,contactName:u,channel:s}),e.jsxs("div",{className:"absolute bottom-5 right-5 flex items-center gap-1",children:[e.jsxs(Qe,{delayDuration:200,children:[e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-60 hover:opacity-100",disabled:!0,children:e.jsx(Mn,{className:"h-3.5 w-3.5"})})}),e.jsx(me,{children:"Emoji"})]}),e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-60 hover:opacity-100",disabled:!0,children:e.jsx(ks,{className:"h-3.5 w-3.5"})})}),e.jsx(me,{children:"Attach"})]}),e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-60 hover:opacity-100",disabled:!0,children:e.jsx(qs,{className:"h-3.5 w-3.5"})})}),e.jsx(me,{children:"Templates"})]}),e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7 opacity-60 hover:opacity-100",disabled:!0,children:e.jsx(De,{className:"h-3.5 w-3.5"})})}),e.jsx(me,{children:"AI Assist"})]})]}),e.jsx(k,{onClick:b,disabled:!i.trim()||l||r,size:"icon",className:"h-8 w-8 bg-gradient-to-r from-primary to-primary/80 shadow-lg",children:l?e.jsx("span",{className:"h-4 w-4 animate-spin border-2 border-current border-t-transparent rounded-full"}):e.jsx(xa,{className:"h-4 w-4"})})]})]}),s==="sms"&&e.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 pb-2 text-[10px] text-muted-foreground",children:[e.jsxs("span",{children:["Chars: ",A]}),e.jsx("span",{children:"•"}),e.jsxs("span",{children:["Segments: ",F]})]})]})}function ur({lastInboundAt:t,isRead:s,targetMinutes:n=60,className:a}){const{label:l,status:r,minutesElapsed:i}=m.useMemo(()=>{if(!t||s)return{label:null,status:"ok",minutesElapsed:0};const d=new Date,f=new Date(t),h=In(d,f),p=wa(d,f);let x;h<1?x="Just now":h<60?x=`${h}m`:p<24?x=`${p}h`:x=`${Math.floor(p/24)}d`;const o=h/n;let g;return o>=1?g="breached":o>=.75?g="warning":g="ok",{label:x,status:g,minutesElapsed:h}},[t,s,n]);return l?e.jsx(Qe,{children:e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsxs("div",{className:P("inline-flex items-center gap-1 text-[10px] font-medium px-1.5 py-0.5 rounded-full",r==="breached"&&"bg-destructive/15 text-destructive",r==="warning"&&"bg-amber-500/15 text-amber-500",r==="ok"&&"bg-muted text-muted-foreground",a),children:[r==="breached"?e.jsx(ea,{className:"h-2.5 w-2.5"}):r==="warning"?e.jsx(Le,{className:"h-2.5 w-2.5"}):e.jsx(Le,{className:"h-2.5 w-2.5"}),l]})}),e.jsx(me,{side:"top",className:"text-xs",children:r==="breached"?`SLA breached — waiting ${l} (target: ${n}m)`:r==="warning"?`SLA warning — ${l} elapsed of ${n}m target`:`Response time: ${l}`})]})}):null}function mr({conversationId:t,onSnooze:s,isSnoozed:n,snoozedUntil:a,onUnsnooze:l}){const r=[{label:"1 hour",getValue:()=>bt(new Date,1)},{label:"3 hours",getValue:()=>bt(new Date,3)},{label:"Tomorrow morning",getValue:()=>yt(Nt(hs(),9),0)},{label:"Tomorrow afternoon",getValue:()=>yt(Nt(hs(),14),0)},{label:"In 2 days",getValue:()=>wt(new Date,2)},{label:"In 1 week",getValue:()=>wt(new Date,7)}];return n&&a?e.jsx(Qe,{children:e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 text-amber-500",onClick:()=>{l==null||l(),U.success("Conversation unsnoozed")},children:e.jsx(Ls,{className:"h-4 w-4"})})}),e.jsxs(me,{children:["Snoozed until ",jt(a,"MMM d, h:mm a")," — click to unsnooze"]})]})}):e.jsxs(st,{children:[e.jsx(nt,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(at,{align:"end",className:"w-48",children:[e.jsx("div",{className:"px-2 py-1.5 text-xs font-medium text-muted-foreground",children:"Snooze until..."}),e.jsx(Ts,{}),r.map(i=>e.jsxs(Ie,{onClick:()=>{const d=i.getValue();s(d),U.success(`Snoozed until ${jt(d,"MMM d, h:mm a")}`)},children:[e.jsx(Le,{className:"h-4 w-4 mr-2"}),i.label]},i.label))]})]})}
1function fr({messageId:t,onSnooze:s,className:n}){const a=[{label:"1 hour",getValue:()=>bt(new Date,1)},{label:"3 hours",getValue:()=>bt(new Date,3)},{label:"Tomorrow 9 AM",getValue:()=>yt(Nt(wt(fs(new Date),1),9),0)},{label:"Next Monday 9 AM",getValue:()=>{const l=new Date,r=(8-l.getDay())%7||7;return yt(Nt(wt(fs(l),r),9),0)}}];return e.jsxs(st,{children:[e.jsx(Qe,{children:e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(nt,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:`h-6 w-6 ${n}`,children:e.jsx(Ls,{className:"h-3.5 w-3.5"})})})}),e.jsx(me,{children:"Snooze this email"})]})}),e.jsxs(at,{align:"end",className:"w-48",children:[e.jsx("div",{className:"px-2 py-1.5 text-xs font-medium text-muted-foreground",children:"Snooze until..."}),e.jsx(Ts,{}),a.map(l=>e.jsx(Ie,{onClick:()=>{const r=l.getValue();s(t,r),U.success(`Email snoozed until ${jt(r,"MMM d, h:mm a")}`)},children:l.label},l.label))]})]})}const hr={greeting:e.jsx(pe,{className:"h-3 w-3"}),followup:e.jsx(Le,{className:"h-3 w-3"}),appointment:e.jsx(Yt,{className:"h-3 w-3"}),question:e.jsx($n,{className:"h-3 w-3"}),closing:e.jsx(Rn,{className:"h-3 w-3"}),custom:e.jsx(De,{className:"h-3 w-3"})},Ss=[{id:"1",text:"Hi! Thanks for reaching out. How can I help you today?",type:"greeting"},{id:"2",text:"Just following up on our previous conversation. Do you have any questions?",type:"followup"},{id:"3",text:"I'd love to schedule a call to discuss this further. What time works best for you?",type:"appointment"},{id:"4",text:"Great question about pricing! Our plans start from £99/month. Would you like more details?",type:"question"},{id:"5",text:"Thank you for your business! Is there anything else I can help you with?",type:"closing"}];function xr({contactName:t,lastMessage:s,conversationContext:n=[],channel:a="sms",onSelectSuggestion:l}){const[r,i]=m.useState([]),[d,f]=m.useState(!1),[h,p]=m.useState(!1),x=async()=>{f(!0);try{const{data:o,error:g}=await V.functions.invoke("inbox-ai-suggestions",{body:{contactName:t,lastMessage:s,conversationContext:n,channel:a}});if(g)throw g;o!=null&&o.suggestions&&Array.isArray(o.suggestions)?i(o.suggestions):i(Ss.map(u=>({...u,text:t?u.text.replace("Hi!",`Hi ${t}!`):u.text})))}catch(o){console.error("Error fetching suggestions:",o),i(Ss.map(g=>({...g,text:t?g.text.replace("Hi!",`Hi ${t}!`):g.text})))}finally{f(!1),p(!0)}};return m.useEffect(()=>{h||x()},[t]),e.jsxs("div",{className:"border-t border-border bg-muted/30",children:[e.jsxs("div",{className:"px-4 py-2 flex items-center gap-2 border-b border-border/50",children:[e.jsx(De,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"text-sm font-medium",children:"Quick Replies"}),e.jsx(be,{variant:"secondary",className:"text-xs ml-auto",children:"AI-powered"}),e.jsx(k,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:x,disabled:d,children:d?e.jsx(Te,{className:"h-3 w-3 animate-spin"}):e.jsx(ta,{className:"h-3 w-3"})})]}),e.jsx(ot,{className:"max-h-32",children:e.jsx("div",{className:"p-2 flex flex-wrap gap-2",children:d&&!h?e.jsxs(e.Fragment,{children:[e.jsx(ht,{className:"h-8 w-48"}),e.jsx(ht,{className:"h-8 w-36"}),e.jsx(ht,{className:"h-8 w-52"})]}):r.map(o=>e.jsxs(k,{variant:"outline",size:"sm",className:"h-auto py-1.5 px-3 text-xs text-left flex items-center gap-1.5 hover:bg-primary/10 hover:border-primary/30 transition-all max-w-full",onClick:()=>l(o.text),children:[e.jsx("span",{className:"text-primary shrink-0",children:hr[o.type]||e.jsx(De,{className:"h-3 w-3"})}),e.jsxs("span",{className:"truncate",children:[o.text.substring(0,50),"..."]})]},o.id))})})]})}const pr=4e3;function mn(t,s){const{user:n}=Dn(),{workspace:a}=He(),[l,r]=m.useState([]),i=m.useRef(null),d=m.useRef(new Map),f=m.useRef(0);m.useEffect(()=>{if(!(a!=null&&a.id)||!t)return;const p=V.channel(`typing:${a.id}:${t}`);return i.current=p,p.on("broadcast",{event:"typing"},({payload:x})=>{const o=x;if(o.user_id===(n==null?void 0:n.id))return;r(b=>[...b.filter(S=>S.user_id!==o.user_id),o]);const g=d.current.get(o.user_id);g&&clearTimeout(g);const u=setTimeout(()=>{r(b=>b.filter(v=>
1v.user_id!==o.user_id)),d.current.delete(o.user_id)},pr);d.current.set(o.user_id,u)}).subscribe(),()=>{V.removeChannel(p),d.current.forEach(x=>clearTimeout(x)),d.current.clear(),i.current=null}},[a==null?void 0:a.id,t,n==null?void 0:n.id]);const h=m.useCallback(()=>{if(!i.current||!(n!=null&&n.id))return;const p=Date.now();p-f.current<1500||(f.current=p,i.current.send({type:"broadcast",event:"typing",payload:{user_id:n.id,name:"Someone",scope:t||""}}))},[n==null?void 0:n.id,s,t]);return{typingUsers:l,broadcastTyping:h}}function gr({scope:t,className:s}){const{typingUsers:n}=mn(t);if(!n.length)return null;const a=n.map(r=>r.name).join(", "),l=n.length===1?"is":"are";return e.jsxs("div",{className:`flex items-center gap-2 px-3 py-1.5 text-xs text-muted-foreground ${s||""}`,children:[e.jsxs("div",{className:"flex gap-0.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary animate-bounce",style:{animationDelay:"300ms"}})]}),e.jsxs("span",{children:[a," ",l," typing…"]})]})}function br(t,s){if(!t)return s;const n=t.indexOf("?");return n>=0?t.slice(n):""}function jr(t){var n;const s=(t.get("channel")||t.get("compose")||"").toLowerCase();return s==="sms"||s==="whatsapp"||s==="email"?s:t.get("compose")==="1"&&((n=t.get("to"))!=null&&n.includes("@"))?"email":null}function wr({onNewConversation:t,initialContactId:s}){var as,rs,ls;const n=m.useRef(null),[a,l]=m.useState(!1);m.useEffect(()=>{const c=n.current;if(!c)return;const z=new ResizeObserver(([L])=>l(L.contentRect.width<1200));return z.observe(c),()=>z.disconnect()},[]);const r=Ds(),i=sa(),d=Ln(),f=m.useRef(null),h=m.useRef(null),p=Fs(),{workspace:x}=He(),{conversations:o,isLoading:g}=Tn(),[u,b]=m.useState(s||null),[v,S]=m.useState(""),[A,F]=m.useState("");m.useEffect(()=>F(""),[u]);const[T,W]=m.useState("sms"),[M,j]=m.useState(!1),[R,O]=m.useState(!0),[G,w]=m.useState("reply"),[q,oe]=m.useState("all"),[X,Z]=m.useState("all"),[se,_e]=m.useState("all"),Ne=o.find(c=>c.contact_id===u),{data:re}=Kt(Ne?null:u),y=Ne||(re?{id:`virtual-${re.id}`,contact_id:re.id,contact:{id:re.id,first_name:re.first_name,last_name:re.last_name,phone:re.phone,mobile:re.mobile,email:re.email},lastMessage:null,lastActivity:new Date().toISOString(),unreadCount:0,channels:[],status:"open",is_starred:!1,assigned_to:null}:null),{messages:te,isLoading:ve}=qn(u),N=Hn();m.useEffect(()=>{const c=br(d,i.search);if(!c)return;const z=new URLSearchParams(c),L=z.get("contact")||z.get("contactId"),H=z.get("to")||"",le=jr(z),ie=`${L||""}|${H}|${le||""}|${c}`;if(h.current!==ie){if(L){b(L),le&&W(le),w("reply"),O(!0),h.current=ie;return}if(H&&o.length){const Q=H.toLowerCase().replace(/\s+/g,""),ce=o.find(ee=>{const We=(ee.contact.phone||ee.contact.mobile||"").toLowerCase().replace(/\s+/g,""),It=(ee.contact.email||"").toLowerCase();return We===Q||It===Q});ce&&(b(ce.contact_id),le&&W(le),w("reply"),O(!0),h.current=ie)}}},[d,i.search,o]);const{broadcastTyping:E}=mn(u?`conversation:${u}`:null);m.useEffect(()=>{const c=z=>{const L=z.detail;(L==null?void 0:L.contactId)===u&&E()};return window.addEventListener("inbox-typing",c),()=>window.removeEventListener("inbox-typing",c)},[u,E]);const $=m.useMemo(()=>({all:o.length,unread:o.filter(c=>c.unreadCount>0).length,starred:0,archived:0}),[o]),_=m.useMemo(()=>{let c=[...o];if(v){const z=v.trim().toLowerCase(),L=z.replace(/\D/g,"");c=c.filter(H=>{var ee;const le=`${H.contact.first_name||""} ${H.contact.last_name||""}`.toLowerCase(),ie=`${H.contact.phone||""} ${H.contact.mobile||""}`,Q=(H.contact.email||"").toLowerCase(),ce=(((ee=H.lastMessage)==null?void 0:ee.content)||"").toLowerCase();return le.includes(z)||Q.includes(z)||ce.includes(z)||ie.toLowerCase().includes(z)||L.length>=4&&ie.replace(/\D/g,"").includes(L)})}return X!=="all"&&(c=c.filter(z=>z.channels.includes(X))),q==="unread"&&(c=c.filter(z=>z.unreadCount>0)),c},[o,v,X,q]);m.useEffect(()=>{const z=setTimeout(()=>{if(f.current){const L=f.current.querySelector("[data-radix-scroll-area-viewport]");
1L&&(L.scrollTop=L.scrollHeight)}},50);return()=>clearTimeout(z)},[te,u,ve]),m.useEffect(()=>{if(y!=null&&y.channels.length){if(y.channels.includes(T)||T==="email"&&y.contact.email)return;y.channels.includes("whatsapp")?W("whatsapp"):y.channels.includes("sms")?W("sms"):y.channels.includes("email")&&W("email")}},[y,T]);const C=async(c,z,L)=>{if(!y)return;const H=z==="email"?y.contact.email:y.contact.phone||y.contact.mobile;if(!H){U.error(z==="email"?"No email address available for this contact":"No phone number available for this contact");return}j(!0);try{await N.mutateAsync({contactId:y.contact_id,channel:z,message:c,phoneNumber:H,fromNumber:L})}finally{j(!1)}},I=m.useCallback(()=>{if(!y)return;const c=y.contact.phone||y.contact.mobile;if(!c){U.error("No phone number for this contact");return}const z=[y.contact.first_name,y.contact.last_name].filter(Boolean).join(" ").trim(),L=new URLSearchParams({phone:c,contact:y.contact_id});z&&L.set("name",z),r(`/dialler?${L.toString()}`)},[y,r]),B=m.useCallback(()=>{y&&(W("email"),w("reply"),U.info("Switched to email — compose your message below"))},[y]),J=m.useCallback(async()=>{if(!y||y.id.startsWith("virtual-"))return;const c=!y.is_starred,{error:z}=await V.from("unified_conversations").update({is_starred:c}).eq("id",y.id);if(z){U.error("Failed to update star");return}p.invalidateQueries({queryKey:["unified-conversations"]}),U.success(c?"Conversation starred":"Star removed")},[y,p]),he=m.useCallback(async()=>{if(!y||y.id.startsWith("virtual-"))return;const{error:c}=await V.from("unified_conversations").update({is_read:!1,unread_count:1}).eq("id",y.id);if(c){U.error("Failed to mark unread");return}p.invalidateQueries({queryKey:["unified-conversations"]}),U.success("Marked as unread")},[y,p]),xe=m.useCallback(()=>{O(!0),U.info("Use the contact panel to assign this conversation")},[]),K=m.useCallback(async()=>{if(!y||y.id.startsWith("virtual-")||!window.confirm("Delete this conversation? This cannot be undone."))return;const{error:c}=await V.from("unified_conversations").update({status:"archived"}).eq("id",y.id);if(c){U.error("Failed to delete conversation");return}b(null),p.invalidateQueries({queryKey:["unified-conversations"]}),U.success("Conversation archived")},[y,p]),ne=c=>c.first_name||c.last_name?`${c.first_name||""} ${c.last_name||""}`.trim():c.phone||c.mobile||"Unknown",Ce=(c,z="h-4 w-4")=>{const L=ke(c);switch(c){case"sms":return e.jsx(ge,{className:P(z,L.color)});case"whatsapp":return e.jsx(pe,{className:P(z,L.color)});case"call":return e.jsx(ge,{className:P(z,L.color)});case"email":return e.jsx(ze,{className:P(z,L.color)});default:return null}},Fe=c=>{switch(c){case"read":return e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(ds,{className:"h-3 w-3 text-primary"}),e.jsx("span",{className:"text-[9px] text-primary",children:"Seen"})]});case"delivered":return e.jsx(Bn,{className:"h-3 w-3 text-primary"});case"sent":return e.jsx(aa,{className:"h-3 w-3 text-muted-foreground"});case"pending":return e.jsx(Le,{className:"h-3 w-3 text-muted-foreground"});case"failed":case"rejected":case"undeliverable":return e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(zs,{className:"h-3 w-3 text-destructive"}),e.jsx("span",{className:"text-[9px] text-destructive",children:"Failed"})]});default:return null}},Ee=m.useMemo(()=>{if(!te.length)return[];const c=[];let z="",L=-1;return te.forEach(H=>{if(H.channel==="email"&&H.content){const le=H.content.match(/^📧\s*(.+?)(?:\n|$)/),ie=le?le[1].replace(/^(Re:|Fwd:)\s*/gi,"").trim():"";if(ie&&ie===z&&L>=0){const Q=c[L];Q&&(Q.threadCount=(Q.threadCount||1)+1),c.push({...H,isThreadStart:!1})}else z=ie,L=c.length,c.push({...H,isThreadStart:!0,threadCount:1})}else z="",L=-1,c.push(H)}),c},[te]),[ae,ct]=m.useState(new Set),[dt,Pe]=m.useState(new Set),[Xe,Mt]=m.useState(new Set),ns=(as=[...Ee].reverse().find(c=>c.channel==="email"))==null?void 0:as.id,fn=c=>{ct(z=>new Set(z).add(c))},hn=c=>{const z=dt.has(c)||c===ns&&!Xe.has(c);Pe(L=>{const H=new Set(L);return z?H.delete(c):H.add(c),H}),Mt(L=>{const H=new Set(L);return z?H.add(c):H.delete(c),H})};return e.jsx("div",{ref:n,className:"flex h-full min-h-0 rounded-lg overflow-hidden border border-border bg-card/30",children:e.jsxs(Ja,{direction:"horizontal",children:[!a&&e.jsx(mt,{defaultSize:12,minSize:10,maxSize:18,className:"hidden lg:block",children:e.jsxs("div",{className:"h-full border-r border-white/[0.06] flex flex-col bg-white/[0.01]",children:[e.jsx("div",{className:"p-3 border-b border-white/[0.06]",children:e.jsxs(k,{onClick:t,className:"w-full bg-gradient-to-r from-primary to-primary/80",size:"sm",children:[e.jsx(Re,{className:"h-4 w-4 mr-2"}),"New Chat"]})}),e.jsx(Ya,{activeFilter:q,onFilterChange:oe,channelFilter:X,onChannelChange:Z,assigneeFilter:se,onAssigneeChange:_e,counts:$})]})}),!a&&e.jsx(Ft,{className:"hidden lg:flex bg-white/[0.04]"}),e.jsx(mt,{defaultSize:a?35:22,minSize:a?28:18,maxSize:a?50:32,children:e.jsxs("div",{className:P("h-full border-r border-white/[0.06] flex flex-col bg-white/[0.01]",u&&"hidden md:flex"),children:[e.jsxs("div",{className:"p-3 border-b border-white/[0.06] space-y-2",children:[a&&e.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto",children:[e.jsx(k,{size:"sm",variant:q==="all"?"secondary":"ghost",onClick:()=>oe("all"),children:"All"}),e.jsx(k,{size:"sm",variant:q==="unread"?"secondary":"ghost",onClick:()=>oe("unread"),children:"Unread"}),e.jsxs(st,{children:[e.jsx(nt,{asChild:!0,children:e.jsx(k,{size:"sm",variant:"ghost",className:"shrink-0",children:X==="all"?"Channels":ke(X).label})}),e.jsx(at,{children:["all","sms","whatsapp","email","call"].map(c=>e.jsx(Ie,{onClick:()=>Z(c),children:c==="all"?"All channels":ke(c).label},c))})]})]}),e.jsxs(k,{onClick:t,className:"w-full lg:hidden",size:"sm",children:[e.jsx(Re,{className:"h-4 w-4 mr-2"}),"New Conversation"]}),e.jsxs("div",{className:"relative",children:[e.jsx(Ut,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(rt,{placeholder:"Search name, email, phone or message…",value:v,onCh
1ange:c=>S(c.target.value),className:"pl-9 bg-white/[0.03] border-white/[0.08]"}),v&&e.jsx(k,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6",onClick:()=>S(""),children:e.jsx(Bt,{className:"h-3 w-3"})})]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:g?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Te,{className:"h-8 w-8 animate-spin text-primary"})}):_.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 px-4 text-center",children:[e.jsx(pe,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"font-medium mb-1",children:"No conversations yet"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Start messaging your contacts"}),e.jsxs(k,{variant:"outline",size:"sm",onClick:t,children:[e.jsx(Re,{className:"h-4 w-4 mr-1"}),"New Conversation"]})]}):e.jsx("div",{className:"divide-y divide-white/[0.04]",children:_.map(c=>{var le,ie,Q,ce;const z=((le=c.lastMessage)==null?void 0:le.direction)==="inbound",L=z?c.lastActivity:null,H=((ie=c.lastMessage)==null?void 0:ie.channel)||c.channels[c.channels.length-1];return e.jsx("div",{onClick:()=>b(c.contact_id),className:P("group p-3 cursor-pointer hover:bg-accent/50 transition-colors",u===c.contact_id&&"bg-accent border-l-2 border-primary"),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(gt,{name:ne(c.contact),size:"md",lastChannel:H}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:P("font-medium truncate text-sm",c.unreadCount>0&&"font-semibold"),children:ne(c.contact)}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-2",children:[e.jsx(k,{variant:"ghost",size:"icon",title:"Open contact in CRM",onClick:ee=>{ee.stopPropagation(),r(`/contacts/${c.contact_id}`)},className:"h-6 w-6 opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity text-muted-foreground hover:text-primary",children:e.jsx(Hs,{className:"h-3.5 w-3.5"})}),z&&c.unreadCount>0&&e.jsx(ur,{lastInboundAt:L,isRead:c.unreadCount===0}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:$s(c.lastActivity,{addSuffix:!1})})]})]}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[c.lastMessage&&Ce(c.lastMessage.channel,"h-3 w-3 shrink-0"),e.jsxs("p",{className:P("text-xs truncate flex-1",c.unreadCount>0?"text-foreground font-medium":"text-muted-foreground"),children:[((Q=c.lastMessage)==null?void 0:Q.direction)==="outbound"&&"You: ",((ce=c.lastMessage)==null?void 0:ce.content)||"No messages yet"]})]}),e.jsx("div",{className:"flex items-center gap-1 mt-1",children:c.channels.map(ee=>{const We=ke(ee);return e.jsx(be,{variant:"outline",className:P("text-[9px] px-1 py-0 border",We.badgeBg),children:We.label},ee)})})]})]})},c.contact_id)})})})]})}),e.jsx(Ft,{className:"bg-white/[0.04]"}),e.jsx(mt,{defaultSize:a?65:48,minSize:a?50:36,children:e.jsx("div",{className:P("h-full flex flex-col bg-white/[0.01]",!u&&"hidden md:flex"),children:y?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"p-3 border-b border-white/[0.06] flex items-center gap-3 bg-white/[0.02]",children:[e.jsx(k,{variant:"ghost",size:"icon",className:"md:hidden",onClick:()=>b(null),children:e.jsx(na,{className:"h-4 w-4"})}),e.jsx(gt,{name:ne(y.contact),size:"md",lastChannel:y.channels[y.channels.length-1]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("button",{type:"button",title:"Open contact in CRM",onClick:()=>r(`/contacts/${y.contact_id}`),className:"font-medium truncate max-w-full hover:text-primary hover:underline underline-offset-4 transition-colors",children:ne(y.contact)}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:y.contact.phone||y.contact.mobile})]}),e.jsx(un,{contactId:y.contact_id,variant:"compact"}),e.jsx(Qe,{delayDuration:200,children:e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-white/[0.06]",onClick:I,children:e.jsx(ge,{className:"h-4 w-4 text-orange-400"})})}),e.jsx(me,{children:"Call"})]}),e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-white/[0.06]",onClick:B,children:e.jsx(ze,{className:"h-4 w-4 text-blue-400"})})}),e.jsx(me,{children:"Email"})]}),e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-white/[0.06]",onClick:J,children:e.jsx(Jt,{className:P("h-4 w-4",y.is_starred&&"fill-yellow-400 text-yellow-400")})})}),e.jsx(me,{children:y.is_starred?"Unstar":"Star"})]}),e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-white/[0.06]",onClick:he,children:e.jsx(ds,{className:"h-4 w-4"})})}),e.jsx(me,{children:"Mark Unread"})]}),e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-white/[0.06]",onClick:xe,children:e.jsx(tt,{className:"h-4 w-4"})})}),e.jsx(me,{children:"Assign"})]}),e.jsxs(de,{children:[e.jsx(ue,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-white/[0.06] hover:text-destructive",onClick:K,children:e.jsx(oa,{className:"h-4 w-4"})})}),e.jsx(me,{children:"Delete"})]})]})}),e.jsx(k,{variant:"ghost",size:"icon",className:"hidden lg:flex h-8 w-8",onClick:()=>O(!R),children:R?e.jsx(Fn,{className:"h-4 w-4"}):e.jsx(Wn,{className:"h-4 w-4"})}),e.jsx(mr,{conversationId:y.id,onSnooze:c=>U.success(`Snoozed until ${jt(c,"MMM d, h:mm a")}`)})]}),e.jsxs("div",{className:"relative border-b border-border px-4 py-2",children:[e.jsx(Ut,{className:"absolute left-6 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}
1),e.jsx(rt,{placeholder:"Find in this conversation (subject, words, sender)…",value:A,onChange:c=>F(c.target.value),className:"h-8 pl-8 text-sm","aria-label":"Find in this conversation"}),A&&e.jsx(k,{variant:"ghost",size:"icon",className:"absolute right-5 top-1/2 -translate-y-1/2 h-6 w-6",onClick:()=>F(""),"aria-label":"Clear find",children:e.jsx(Bt,{className:"h-3 w-3"})})]}),e.jsx(ot,{ref:f,className:"flex-1 p-4",children:ve?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Te,{className:"h-8 w-8 animate-spin text-primary"})}):te.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[e.jsx(pe,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"font-medium mb-1",children:"No messages yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Send a message to start the conversation"})]}):e.jsxs("div",{className:"space-y-3 min-w-0",children:[A.trim()&&e.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:[Ee.filter(c=>c.content.toLowerCase().includes(A.trim().toLowerCase())).length," message(s) match “",A.trim(),"”"]}),Ee.filter(c=>!ae.has(c.id)).filter(c=>!A.trim()||c.content.toLowerCase().includes(A.trim().toLowerCase())||(c.from_number||"").toLowerCase().includes(A.trim().toLowerCase())).map((c,z,L)=>{const H=z>0?L[z-1]:null,le=z===0||new Date(c.created_at).toDateString()!==new Date(H.created_at).toDateString(),ie=c.channel==="call",Q=c.channel==="email",ce=dt.has(c.id)||c.id===ns&&!Xe.has(c.id),ee=c.direction==="outbound",We=Q&&c.isThreadStart===!1,It=ke(c.channel);return e.jsxs("div",{children:[le&&e.jsxs("div",{className:"flex items-center justify-center my-4",children:[e.jsx(Ge,{className:"flex-1 bg-white/[0.06]"}),e.jsx("span",{className:"px-3 text-[10px] text-muted-foreground bg-white/[0.02] rounded-full py-0.5",children:xt(c.created_at,"MMMM d, yyyy")}),e.jsx(Ge,{className:"flex-1 bg-white/[0.06]"})]}),Q&&c.isThreadStart&&(c.threadCount??1)>1&&e.jsx("div",{className:"flex items-center gap-1 px-4 mb-1",children:e.jsxs(be,{variant:"secondary",className:"text-xs",children:["Email thread · ",c.threadCount," messages"]})}),ie?e.jsx("div",{className:"flex justify-center",children:e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 rounded-full bg-white/[0.04] border border-white/[0.06] text-sm",children:[e.jsx(ge,{className:"h-4 w-4 text-orange-400"}),e.jsx("span",{children:c.content}),e.jsx("span",{className:"text-muted-foreground text-xs",children:xt(c.created_at,"h:mm a")})]})}):e.jsxs("div",{className:P("flex items-end gap-2 group min-w-0",ee?"justify-end":"justify-start",We&&"ml-8 border-l-2 border-white/[0.06] pl-2"),children:[!ee&&e.jsx(gt,{name:ne(y.contact),size:"sm",className:"mb-5"}),e.jsxs("div",{className:P("relative min-w-0 transition-colors",Q?"w-full rounded-md border border-border bg-card text-card-foreground px-4 py-3 shadow-sm":"max-w-[70%] rounded-2xl px-4 py-2.5",!Q&&(ee?"bg-primary text-primary-foreground rounded-br-md":"bg-muted border border-border rounded-bl-md")),children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[Ce(c.channel,"h-3 w-3"),e.jsx("span",{className:P("text-[10px] uppercase tracking-wide font-medium",ee&&!Q?"text-primary-foreground/70":"text-muted-foreground"),children:It.label}),Q&&c.direction==="inbound"&&e.jsx(fr,{messageId:c.id,onSnooze:fn,className:"opacity-0 group-hover:opacity-100 transition-opacity ml-1"}),Q&&e.jsx(k,{variant:"ghost",size:"sm",className:"ml-auto h-7 px-2 text-xs text-muted-foreground",onClick:()=>hn(c.id),"aria-expanded":ce,"aria-label":ce?"Collapse email":"Read email",children:ce?"Collapse":"Read email"})]}),Q&&c.content.startsWith("📧 ")&&e.jsx("p",{className:P("text-base font-semibold mb-2 break-words text-card-foreground"),children:c.content.substring(2,c.content.indexOf(`
2`)>0?c.content.indexOf(`
3`):void 0).trim()}),(!Q||ce)&&e.jsx(va,{attachments:$t(c.attachments,c.media_url,c.media_type)}),Q&&!ce&&$t(c.attachments).length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mb-1",children:["📎 ",$t(c.attachments).length," attachment(s)"]}),Q?ce?e.jsx("div",{className:"mt-2 border-t border-border pt-3 max-h-[min(45vh,440px)] overflow-y-auto overscroll-contain",children:e.jsx(ma,{content:c.content,htmlContent:c.html_content,className:"text-card-foreground"})}):e.jsxs("p",{className:P("text-sm line-clamp-2 text-muted-foreground break-words"),children:[c.content.startsWith("📧 ")&&c.content.indexOf(`
4`)>0?c.content.substring(c.content.indexOf(`
5`)+1).trim().slice(0,120):c.content.slice(0,120),c.content.length>120&&"…"]}):e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed",children:c.content}),e.jsxs("div",{className:P("flex items-center gap-1.5 mt-1.5",ee?"justify-end":"justify-start"),children:[e.jsx("span",{className:P("text-[10px]",ee&&!Q?"text-primary-foreground
5/70":"text-muted-foreground"),children:xt(c.created_at,"h:mm a")}),ee&&Fe(c.status)]})]})]})]},`${c.channel}-${c.id}-${c.created_at}`)})]})}),y&&e.jsx(gr,{scope:`conversation:${y.contact_id}`}),G==="reply"&&T!=="email"&&te.length>0&&((rs=te[te.length-1])==null?void 0:rs.direction)==="inbound"&&e.jsx(xr,{contactName:y!=null&&y.contact?`${y.contact.first_name||""} ${y.contact.last_name||""}`.trim():void 0,lastMessage:(ls=te[te.length-1])==null?void 0:ls.content,conversationContext:te.slice(-6).map(c=>`${c.direction==="outbound"?"Me":"Them"}: ${c.content}`),channel:T==="whatsapp"?"whatsapp":"sms",onSelectSuggestion:c=>{window.dispatchEvent(new CustomEvent("inbox-prefill-composer",{detail:{text:c}}))}}),e.jsxs("div",{className:P("border-t border-white/[0.06]",G==="note"?"bg-yellow-500/[0.04]":"bg-white/[0.01]"),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2",children:[e.jsxs(k,{variant:G==="reply"?"default":"ghost",size:"sm",className:"h-6 text-[10px] gap-1",onClick:()=>w("reply"),children:[e.jsx(On,{className:"h-3 w-3"}),"Reply"]}),e.jsxs(k,{variant:G==="note"?"default":"ghost",size:"sm",className:P("h-6 text-[10px] gap-1",G==="note"&&"bg-yellow-600 hover:bg-yellow-700"),onClick:()=>w("note"),children:[e.jsx(Ot,{className:"h-3 w-3"}),"Internal Note"]})]}),G==="reply"?e.jsx(dr,{conversation:y,selectedChannel:T,onChannelChange:W,onSend:C,sending:M}):e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsx(Xt,{placeholder:"Write an internal note... (only visible to your team)",className:"min-h-[60
5px] bg-yellow-500/[0.03] border-yellow-500/20 text-sm",rows:2}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(k,{size:"sm",className:"bg-yellow-600 hover:bg-yellow-700 text-white gap-1",children:[e.jsx(Ot,{className:"h-3.5 w-3.5"}),"Save Note"]})})]})]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center p-8",children:[e.jsxs("div",{className:"relative mb-6",children:[e.jsx("div",{className:"h-24 w-24 rounded-3xl bg-gradient-to-br from-primary/20 to-primary/5 flex items-center justify-center border border-primary/10 shadow-lg shadow-primary/5",children:e.jsx(pe,{className:"h-12 w-12 text-primary"})}),e.jsx("div",{className:"absolute -top-2 -right-2 h-8 w-8 rounded-full bg-gradient-to-br from-green-500 to-emerald-400 flex items-center justify-center shadow-lg",children:e.jsx(ze,{className:"h-4 w-4 text-white"})}),e.jsx("div",{className:"absolute -bottom-1 -left-2 h-7 w-7 rounded-full bg-gradient-to-br from-blue-500 to-cyan-400 flex items-center justify-center shadow-lg",children:e.jsx(ge,{className:"h-3.5 w-3.5 text-white"})})]}),e.jsx("h3",{className:"text-xl font-semibold mb-2",children:"Unified Inbox"}),e.jsx("p",{className:"text-muted-foreground max-w-sm mb-6 text-sm",children:"All your SMS, WhatsApp, Email, and call conversations unified in one powerful inbox. Select a conversation to get started."}),e.jsxs(k,{onClick:t,className:"bg-gradient-to-r from-primary to-primary/80 shadow-lg",children:[e.jsx(Re,{className:"h-4 w-4 mr-2"}),"Start Conversation"]})]})})}),R&&!a&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{className:"hidden lg:flex bg-white/[0.04]"}),e.jsx(mt,{defaultSize:18,minSize:15,maxSize:30,className:"hidden lg:block",children:e.jsx(lr,{conversation:y,className:"h-full border-l border-white/[0.06] bg-white/[0.01]"})})]})]})})}function yr({open:t,onOpenChange:s,onSelectContact:n}){const[a,l]=m.useState(""),{data:r,isLoading:i}=Un(),d=(r||[]).filter(p=>{if(!a)return!0;const x=`${p.first_name||""} ${p.last_name||""}`.toLowerCase(),o=(p.phone||p.mobile||"").toLowerCase(),g=(p.email||"").toLowerCase(),u=a.toLowerCase();return x.includes(u)||o.includes(u)||g.includes(u)}),f=p=>p.first_name||p.last_name?`${p.first_name||""} ${p.last_name||""}`.trim():p.email||p.phone||"Unknown",h=p=>{n(p),s(!1),l("")};return e.jsx(St,{open:t,onOpenChange:s,children:e.jsxs(kt,{className:"sm:max-w-md p-0 gap-0 overflow-hidden",children:[e.jsx(Qt,{className:"px-5 pt-5 pb-3",children:e.jsx(zt,{className:"text-lg",children:"New Conversation"})}),e.jsx("div",{className:"px-5 pb-3",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ut,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(rt,{placeholder:"Search contacts...",value:a,onChange:p=>l(p.target.value),className:"pl-9",autoFocus:!0})]})}),e.jsx("div",{className:"border-t max-h-[360px] overflow-y-auto",children:i?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Te,{className:"h-6 w-6 animate-spin text-primary"})}):d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(Vn,{className:"h-10 w-10 text-muted-foreground mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a?"No contacts found":"No contacts yet"})]}):e.jsx("div",{className:"divide-y divide-border/50",children:d.map(p=>{var o,g;const x=p.phone||p.mobile;return e.jsxs("button",{className:"w-full flex items-center gap-3 px-5 py-3 text-left hover:bg-accent/50 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",onClick:()=>h(p),disabled:!x,children:[e.jsx(Gn,{className:"h-9 w-9 shrink-0",children:e.jsx(Kn,{className:"bg-primary/10 text-primary text-sm font-medium",children:(((o=p.first_name)==null?void 0:o[0])||((g=p.email)==null?void 0:g[0])||"?").toUpperCase()})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium text-sm truncate",children:f(p)}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:x?p.phone||p.mobile:"No phone number"})]})]},p.id)})})})]})})}function Kr(){const[t,s]=m.useState(!1),[n,a]=m.useState(null),{workspace:l}=He();pn("inbox",{Compose:()=>s(!0),"Mark all read":()=>{window.dispatchEvent(new CustomEvent("inbox-toolbar-action",{detail:{action:"mark-all-read"}}))}}),gn("inbox","Conversations"),Jn();const{isConnected:r,fetchEmails:i}=Ws();m.useEffect(()=>{if(!r||!(l!=null&&l.id))return;let f=!1;const h=async()=>{var o;const{data:x}=await V.auth.getSession();f||!((o=x.session)!=null&&o.access_token)||i.isPending||i.mutate()};h();const p=setInterval(h,3e4);return()=>{f=!0,clearInterval(p)}},[r,l==null?void 0:l.id]);const d=f=>{a(f.id)};return e.jsxs(Qn,{children:[e.jsx(ya,{title:"Conversations",description:"Unified inbox for SMS, WhatsApp, and calls"}),e.jsx("main",{className:"flex-1 min-h-0 p-2 md:p-4 overflow-hidden",children:e.jsx(wr,{onNewConversation:()=>s(!0),initialContactId:n},n||"default")}),e.jsx(yr,{open:t,onOpenChange:s,onSelectContact:d}),e.jsx(Xn,{})]})}
5export{Kr 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.