1import{b as ue,u as U,r as f,j as e,d as ve}from"./query-vendor-CqOtiPNe.js";import{D as we,I as E,J as ye,K as _e,N as G}from"./DashboardLayout-bhpyg6kK.js";import{P as Ce}from"./PageHeader-CZkE0AwI.js";import{d as L,s as b,c as v,B as y,J as Me,x as Se,D as Ae,p as ke,q as De,r as Re,h as I,m as T,u as pe,a as D,b as J}from"./index-CgiuONvO.js";import{E as qe,u as Le}from"./use-mobile-Bs-uMLmp.js";import{I as z}from"./input-oPoHA7Fw.js";import{S as O}from"./scroll-area-Cf6pvS46.js";import{S as C}from"./skeleton-B97PTBMn.js";import{A as Q,a as W,b as V}from"./avatar-B9y0eyOh.js";import{B as S}from"./badge-CSzvBtO5.js";import{i as Y}from"./isToday-C3mvRkZe.js";import{f as A}from"./format-Ch7dQtBq.js";import{i as xe}from"./isYesterday-kv79t7uQ.js";import{D as Ee,a as Ie,b as Te,c as Pe}from"./dropdown-menu-D-1fS2hr.js";import{C as Fe}from"./chevron-down-C04YKbFY.js";import{U as P}from"./users-BKG6ZMTq.js";import{U as $e}from"./user-C4n8hF8r.js";import{H as Ue}from"./house-C9sHcoTX.js";import{B as X}from"./building-B1y8ifkf.js";import{W as Oe}from"./wrench-BveqLzJ6.js";import{S as he}from"./search-CT8fLn3_.js";import{M as k}from"./message-square-BqIfb2eA.js";import{A as He}from"./arrow-left-Cg5pwYzI.js";import{C as Be}from"./check-check-XSobeTl0.js";import{C as fe}from"./check-EsNBkSFR.js";import{T as Ke}from"./textarea-CxLaKExY.js";import{S as ge}from"./send-Dev9pED3.js";import{u as ze}from"./useUserRole-kvNPaeKq.js";import{u as Qe}from"./useRouteAction-DcIrIJiC.js";import{P as Z}from"./plus-DhJDBkeB.js";import{M as F}from"./mail-dnbKMUvE.js";import{f as je}from"./formatDistanceToNow-DExfhm_y.js";import{u as We,a as Ve,b as Ye,c as Ge}from"./usePortfolioInquiries-C0NesdLf.js";import{A as Je,a as Xe,b as Ze,c as es,d as ss,e as ts,f as as,g as rs}from"./alert-dialog-3FMVIuPP.js";import{S as ee,a as se,b as te,c as ae,d as M}from"./select-DLa9MRfA.js";import{P as ns}from"./phone-CCpZm87m.js";import{E as is}from"./external-link-DLbL3mEn.js";import{T as os}from"./trash-2-XdlKjO4t.js";import{u as ls}from"./useLiveChatSession-C6nYnPhY.js";import{u as cs,a as ds}from"./useSalesAgentStatus-AQfKLAY0.js";import{H as $,M as re}from"./message-circle-C3Kdh8KU.js";import{T as ms,a as us,b as R,c as q}from"./tabs-DhAXdYsK.js";import{O as ps,c as ne,d as ie}from"./OperationsWorkspace-CMZPPGWo.js";import{W as xs}from"./WhatsAppBrowserComposer-DcBd0F80.js";import{p as hs}from"./parseISO-k3Q1d3Py.js";import"./ui-vendor-C92kXd7i.js";import"./react-vendor-Oyj1q24G.js";import"./separator-BBHmpRWz.js";import"./sheet-Dt5T48FQ.js";import"./tooltip-DukMi9Yb.js";import"./Logo-BMQirxBI.js";import"./calendar-njTWr43i.js";import"./calendar-days-BvC5INej.js";import"./building-2-Dhg-JMoH.js";import"./map-pin-C3B4zHzE.js";import"./wifi-off--tLv87Xm.js";import"./file-text-BqBFGr3S.js";import"./credit-card-B4XMcBmh.js";import"./panel-top-C_rCNK16.js";import"./log-out-BzS-CLno.js";import"./bell-CJIBHycy.js";import"./en-US-5rFTtd83.js";import"./LanguageSwitcher-k7A6VFzv.js";import"./languages-1QBd6nWm.js";import"./activity-DmUxG0fV.js";import"./arrow-down-C4HxAdL9.js";import"./arrow-right-left-tf9Dbt9n.js";import"./arrow-right-CcjvJnjH.js";import"./banknote-wg82AAG7.js";import"./bed--FRu_ZOR.js";import"./list-ordered-CD-hc5AR.js";import"./book-open-check-DeGSCDpn.js";import"./book-open-CkJItcBu.js";import"./brain-QP504LxU.js";import"./calculator-BuA7e-mZ.js";import"./car-BBeSSily.js";import"./landmark-DVOwzqRj.js";import"./chart-no-axes-column-increasing-DINm0A4J.js";import"./chart-pie-BH1JXQN4.js";import"./chevron-left-ChhJq7GD.js";import"./chevron-right-Cl4Mx2Wq.js";import"./chevron-up-YEko4sQ9.js";import"./circle-check-big-B-nqExcc.js";import"./circle-check-DJQ0aRpE.js";import"./message-square-text-CGi8Ghec.js";import"./circle-help-C7Zpw0pA.js";import"./circle-x-BuyswQ-Z.js";import"./circle-QNrbGPhh.js";import"./clipboard-check-BqHgjlQp.js";import"./clipboard-list-Csw_7fPS.js";import"./clipboard-BrLc9XKt.js";import"./clock-DZbyb8Zh.js";import"./copy-B3hQhSgM.js";import"./database-BFqeg3FR.js";import"./dollar-sign-BoJmMuTa.js";import"./download-CVkjVrJo.js";import"./zoom-out-CZzr-t9-.js";import"./twitter-DZP3beY2.js";import"./file-chart-column-increasing-B5g6evDe.js";import"./file-check-2P_f7S4-.js";import"./file-spreadsheet-BbKDqPhp.js";import"./filter-DOTkE5Cb.js";import"./folder-open-CQAcdSBr.js";import"./tree-pine-BPQJJftn.js";import"./globe-CnUNDEKq.js";import"./video-CEw6mOAP.js";import"./hammer-wk7AQWqX.js";import"./heart-BnQgcucT.js";import"./hotel-GOTEiWOT.js";
1import"./image-plus-DfX-_AyQ.js";import"./image-DrO_YHf9.js";import"./infinity-BeOXN0LM.js";import"./key-round-Cl3pyXjD.js";import"./pen-tool-ErvG_pvg.js";import"./keyboard-CzV9enBr.js";import"./layers-BFQ0OLI3.js";import"./lightbulb-IBP3Qpkq.js";import"./list-checks-CsRR_GQp.js";import"./list-Cj3mFARp.js";import"./lock-rMWs3zu_.js";import"./map-pinned-DBhEITMu.js";import"./map-Dml-fuwB.js";import"./maximize-2-BAo6X0VP.js";import"./maximize-DllRQL4I.js";import"./menu-B6QavzjZ.js";import"./minus-BWhsihkF.js";import"./mouse-pointer-click-BX0OFv2U.js";import"./mouse-z7gxK0yj.js";import"./navigation-CE5W2bfp.js";import"./pause-DMf9J0er.js";import"./pencil-s0UamddO.js";import"./ruler-PMZpHEX4.js";import"./play-jGttOVZX.js";import"./printer-DPItEGKX.js";import"./refresh-ccw-D8-NZbc0.js";import"./rocket-o5dk1x7z.js";import"./rotate-ccw-D5LvpNON.js";import"./rotate-cw-qBQXdDzU.js";import"./route-BHkgA-GC.js";import"./save-CD5NOpBU.js";import"./scale-ChbaOrX5.js";import"./share-2-CZ8fruyy.js";import"./square-plus-BYoTN96c.js";import"./skip-forward-B2g28Adz.js";import"./smartphone-BVaS8Ogf.js";import"./square-check-big-S7f3xHqK.js";import"./square-pen-Cd8FE6iD.js";import"./square-DpPlSXOl.js";import"./star-DgTF5ai2.js";import"./trending-down-BOTbmgUi.js";import"./trending-up-BVHf_RoK.js";import"./upload-B2TjyuSq.js";import"./user-check-DLa2T6BS.js";import"./volume-2-CyzFl9Wm.js";import"./volume-x-DwUdAb_B.js";import"./wallet-DFZjOwp1.js";import"./workflow-eRF_Iozj.js";import"./zap-CZwSyBya.js";import"./useIsRTL-CvXztNyx.js";import"./useOrganization-BfvJJCCq.js";import"./chart-vendor-De-uRwFm.js";import"./index-BdQq_4o_.js";import"./index-DBVc4pCm.js";import"./isSameDay-DKb4pGQS.js";import"./subDays-CTCG_ujS.js";import"./addDays-DdzlNAKv.js";import"./checkbox-DKjJLhPq.js";import"./useWhatsAppTemplates-PCjsFKWj.js";import"./whatsappBrowser-Bk8kXzkW.js";const Ne=()=>{const{user:s}=L(),t=ue(),{data:d=[],isLoading:a}=U({queryKey:["conversations",s==null?void 0:s.id],queryFn:async()=>{if(!s)return[];const{data:l,error:m}=await b.from("messages").select(` 2 *, 3 sender:sender_id (id, full_name, avatar_url, email), 4 recipient:recipient_id (id, full_name, avatar_url, email) 5 `).or(`sender_id.eq.${s.id},recipient_id.eq.${s.id}`).order("created_at",{ascending:!1});if(m)throw m;const o=new Set;l==null||l.forEach(n=>{const x=n.sender_id===s.id?n.recipient_id:n.sender_id;o.add(x)});const{data:r}=await b.from("user_roles").select("user_id, role").in("user_id",Array.from(o)),i=new Map;r==null||r.forEach(n=>{(!i.has(n.user_id)||oe(n.role)<oe(i.get(n.user_id)))&&i.set(n.user_id,n.role)});const c=new Map;return l==null||l.forEach(n=>{const x=n.sender_id===s.id?n.recipient_id:n.sender_id,g=n.sender_id===s.id?Array.isArray(n.recipient)?n.recipient[0]:n.recipient:Array.isArray(n.sender)?n.sender[0]:n.sender;if(c.has(x)||c.set(x,{contactId:x,contactName:(g==null?void 0:g.full_name)||"Unknown User",contactAvatar:(g==null?void 0:g.avatar_url)||null,contactEmail:(g==null?void 0:g.email)||null,contactRole:i.get(x)||null,lastMessage:n.message,lastMessageAt:n.created_at,unreadCount:0,isFromMe:n.sender_id===s.id}),n.recipient_id===s.id&&!n.read){const h=c.get(x);h.unreadCount++}}),Array.from(c.values()).sort((n,x)=>new Date(x.lastMessageAt).getTime()-new Date(n.lastMessageAt).getTime())},enabled:!!s});f.useEffect(()=>{if(!s)return;const l=b.channel("conversations-realtime").on("postgres_changes",{event:"*",schema:"public",table:"messages"},()=>{t.invalidateQueries({queryKey:["conversations",s.id]})}).subscribe();return()=>{b.removeChannel(l)}},[s,t]);const p=d.reduce((l,m)=>l+m.unreadCount,0);return{conversations:d,isLoading:a,totalUnread:p}};function oe(s){return s?{site_admin:0,admin:1,owner:2,manager:3,property_manager:4,maintenance_staff:5,tenant:6}[s]??99:99}const fs={tenant:"bg-emerald-500",owner:"bg-slate-700",manager:"bg-blue-500",property_manager:"bg-purple-500",maintenance_staff:"bg-orange-500",admin:"bg-red-500",site_admin:"bg-red-700"},gs={tenant:"Tenant",owner:"Owner",manager:"Manager",property_manager:"PM",maintenance_staff:"Maint.",admin:"Admin",
5site_admin:"Admin"};function js({conversation:s,isSelected:t,onClick:d}){const a=r=>{const i=new Date(r);return Y(i)?A(i,"HH:mm"):xe(i)?"Yesterday":A(i,"dd/MM")},p=r=>r.split(" ").map(i=>i[0]).join("").toUpperCase().slice(0,2),l=s.unreadCount>0,m=s.contactRole?fs[s.contactRole]:"bg-muted",o=s.contactRole?gs[s.contactRole]:"";return e.jsxs("div",{onClick:d,className:v("flex items-center gap-3 p-3 hover:bg-accent/50 cursor-pointer transition-colors border-b border-border",t&&"bg-accent",l&&"bg-primary/5 border-l-2 border-l-primary"),children:[e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs(Q,{className:"h-12 w-12",children:[e.jsx(W,{src:s.contactAvatar||void 0}),e.jsx(V,{className:"bg-muted text-muted-foreground",children:p(s.contactName)})]}),l&&e.jsx("div",{className:"absolute -top-1 -right-1 bg-primary text-primary-foreground rounded-full h-5 min-w-[20px] flex items-center justify-center text-xs font-semibold px-1.5",children:s.unreadCount>99?"99+":s.unreadCount})]}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1 overflow-hidden",children:[e.jsx("h3",{className:v("font-medium truncate",l&&"font-bold"),children:s.contactName}),o&&e.jsx(S,{variant:"secondary",className:v("text-[10px] px-1.5 py-0 h-4 text-white shrink-0",m),children:o})]}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap shrink-0",children:a(s.lastMessageAt)})]}),e.jsxs("p",{className:v("text-sm truncate text-muted-foreground",l&&"text-foreground font-medium"),children:[s.isFromMe&&e.jsx("span",{className:"text-muted-foreground",children:"You: "}),s.lastMessage]})]})]})}const B=[{value:"all",label:"All Roles",icon:e.jsx(P,{className:"h-4 w-4"}),color:""},{value:"tenant",label:"Tenants",icon:e.jsx($e,{className:"h-4 w-4"}),color:"text-emerald-500"},{value:"owner",label:"Owners",icon:e.jsx(Ue,{className:"h-4 w-4"}),color:"text-slate-700"},{value:"manager",label:"Managers",icon:e.jsx(X,{className:"h-4 w-4"}),color:"text-blue-500"},{value:"property_manager",label:"Property Managers",icon:e.jsx(X,{className:"h-4 w-4"}),color:"text-purple-500"},{value:"maintenance_staff",label:"Maintenance",icon:e.jsx(Oe,{className:"h-4 w-4"}),color:"text-orange-500"},{value:"admin",label:"Admins",icon:e.jsx(Me,{className:"h-4 w-4"}),color:"text-red-500"}];function Ns({value:s,onChange:t}){const d=B.find(a=>a.value===s)||B[0];return e.jsxs(Ee,{children:[e.jsx(Ie,{asChild:!0,children:e.jsxs(y,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx("span",{className:d.color,children:d.icon}),d.label,e.jsx(Fe,{className:"h-3 w-3 opacity-50"})]})}),e.jsx(Te,{align:"start",className:"w-48",children:B.map(a=>e.jsxs(Pe,{onClick:()=>
5t(a.value),className:v("gap-2",s===a.value&&"bg-accent"),children:[e.jsx("span",{className:a.color,children:a.icon}),a.label]},a.value||"all"))})]})}function le({selectedContactId:s,onSelectConversation:t}){const{conversations:d,isLoading:a}=Ne(),[p,l]=f.useState(""),[m,o]=f.useState("all"),r=d.filter(i=>{var x;const c=i.contactName.toLowerCase().includes(p.toLowerCase())||((x=i.contactEmail)==null?void 0:x.toLowerCase().includes(p.toLowerCase())),n=m==="all"||i.contactRole===m;return c&&n});return a?e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"p-3 border-b border-border space-y-3",children:[e.jsx(C,{className:"h-9 w-full"}),e.jsx(C,{className:"h-8 w-32"})]}),e.jsx("div",{className:"flex-1 p-2 space-y-2",children:[...Array(5)].map((i,c)=>e.jsx(C,{className:"h-16 w-full"},c))})]}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"p-3 border-b border-border space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(he,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(z,{placeholder:"Search conversations...",value:p,onChange:i=>l(i.target.value),className:"pl-9"})]}),e.jsx(Ns,{value:m,onChange:o})]}),e.jsx(O,{className:"flex-1",children:r.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-muted-foreground",children:[e.jsx(k,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No conversations yet"}),e.jsx("p",{className:"text-xs",children:"Start a new chat to begin"})]}):r.map(i=>e.jsx(js,{conversation:i,isSelected:s===i.contactId,onClick:()=>t(i)},i.contactId))})]})}const bs=s=>{const{user:t}=L(),{toast:d}=Se(),a=ue(),{data:p=[],isLoading:l}=U({queryKey:["conversation-messages",t==null?void 0:t.id,s],queryFn:async()=>{if(!t||!s)return[];const{data:o,error:r}=await b.from("messages").select("*").or(`and(sender_id.eq.${t.id},recipient_id.eq.${s}),and(sender_id.eq.${s},recipient_id.eq.${t.id})`).order("created_at",{ascending:!0});if(r)throw r;return o.map(i=>({id:i.id,senderId:i.sender_id,recipientId:i.recipient_id,message:i.message,subject:i.subject,read:i.read??!1,createdAt:i.created_at,isFromMe:i.sender_id===t.id}))},enabled:!!t&&!!s});f.useEffect(()=>{if(!t||!s||p.length===0)return;const o=p.filter(r=>!r.isFromMe&&!r.read).map(r=>r.id);o.length>0&&b.from("messages").update({read:!0}).in("id",o).then(()=>{a.invalidateQueries({queryKey:["conversations",t.id]})})},[p,t,s,a]),f.useEffect(()=>{if(!t||!s)return;const o=b.channel(`conversation-${s}`).on("postgres_changes",{event:"INSERT",schema:"public",table:"messages"},r=>{const i=r.new;(i.sender_id===t.id&&i.recipient_id===s||i.sender_id===s&&i.recipient_id===t.id)&&a.invalidateQueries({queryKey:["conversation-messages",t.id,s]})}).subscribe();return()=>{b.removeChannel(o)}},[t,s,a]);const m=ve({mutationFn:async o=>{if(!t||!s)throw new Error("Missing user or contact");const{data:r,error:i}=await b.from("messages").insert({sender_id:t.id,recipient_id:s,message:o,subject:null,read:!1,related_maintenance_id:null}).select().single();if(i)throw i;return r},onSuccess:()=>{a.invalidateQueries({queryKey:["conversation-messages",t==null?void 0:t.id,s]}),a.invalidateQueries({queryKey:["conversations",t==null?void 0:t.id]})},onError:o=>{d({title:"Failed to send message",description:o.message,variant:"destructive"})}});return{messages:p,isLoading:l,sendMessage:m}},vs={tenant:"bg-emerald-500",owner:"bg-slate-700",manager:"bg-blue-500",property_manager:"bg-purple-500",maintenance_staff:"bg-orange-500",admin:"bg-red-500",site_admin:"bg-red-700"},ws={tenant:"Tenant",owner:"Owner",manager:"Manager",property_manager:"Property Manager",maintenance_staff:"Maintenance Staff",admin:"Admin",site_admin:"Site Admin"};function ys({conversation:s,onBack:t,showBackButton:d=!1}){const a=m=>m.split(" ").map(o=>o[0]).join("").toUpperCase().slice(0,2),p=s.contactRole?vs[s.contactRole]:"bg-muted",l=s.contactRole?ws[s.contactRole]:"User";return e.jsxs("div",{className:"flex items-center gap-3 p-3 border-b border-border bg-background",children:[d&&e.jsx(y,{variant:"ghost",size:"icon",onClick:t,className:"shrink-0 md:hidden",children:e.jsx(He,{className:"h-5 w-5"})}),e.jsxs(Q,{className:"h-10 w-10",children:[e.jsx(W,{src:s.contactAvatar||void 0}),e.jsx(V,{className:"bg-muted text-muted-foreground",children:a(s.contactName)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold truncate",children:s.contactName}),e.jsx(S,{variant:"secondary",className:v("text-[10px] px-1.5 py-0 h-4 text-white shrink-0",p),children:l})]}),s.contactEmail&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.contactEmail})]}),e.jsx(y,{variant:"ghost",size:"icon",className:"shrink-0",children:e.jsx(qe,{className:"h-5 w-5"})})]})}function _s({message:s,showTimestamp:t=!0}){const d=a=>A(new Date(a),"HH:mm");return e.jsx("div",{className:v("flex flex-col",s.isFromMe?"items-end":"items-start"),children:e.jsxs("div",{className:v("max-w-[75%] rounded-2xl px-4 py-2 shadow-sm",s.isFromMe?"bg-primary text-primary-foreground rounded-br-md":"bg-muted text-foreground rounded-bl-md"),children:[e.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:s.message}),e.jsxs("div",{className:v("flex items-center justify-end gap-1 mt-1",s.isFromMe?"text-primary-foreground
5/70":"text-muted-foreground"),children:[e.jsx("span",{className:"text-[10px]",children:d(s.createdAt)}),s.isFromMe&&(s.read?e.jsx(Be,{className:"h-3 w-3"}):e.jsx(fe,{className:"h-3 w-3"}))]})]})})}function Cs({date:s}){const t=d=>{const a=new Date(d);return Y(a)?"Today":xe(a)?"Yesterday":A(a,"EEEE, MMMM d")};return e.jsx("div",{className:"flex items-center justify-center my-4",children:e.jsx("div",{className:"bg-muted text-muted-foreground text-xs px-3 py-1 rounded-full",children:t(s)})})}function Ms({onSend:s,disabled:t=!1,placeholder:d="Type a message..."}){const[a,p]=f.useState(""),l=f.useRef(null),m=()=>{const r=a.trim();r&&!t&&(s(r),p(""),l.current&&(l.current.style.height="auto"))},o=r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),m())};return f.useEffect(()=>{l.current&&(l.current.style.height="auto",l.current.style.height=`${Math.min(l.current.scrollHeight,150)}px`)},[a]),e.jsxs("div",{className:"flex items-end gap-2 p-3 border-t border-border bg-background",children:[e.jsx(Ke,{ref:l,value:a,onChange:r=>p(r.target.value),onKeyDown:o,placeholder:d,disabled:t,className:"min-h-[40px] max-h-[150px] resize-none rounded-2xl",rows:1}),e.jsx(y,{size:"icon",onClick:m,disabled:!a.trim()||t,className:"shrink-0 h-10 w-10 rounded-full",children:e.jsx(ge,{className:"h-4 w-4"})})]})}function ce({conversation:s,onBack:t,showBackButton:d=!1}){const{messages:a,isLoading:p,sendMessage:l}=bs((s==null?void 0:s.contactId)||null),m=f.useRef(null),o=f.useRef(null);f.useEffect(()=>{var n;(n=o.current)==null||n.scrollIntoView({behavior:"smooth"})},[a]);const r=n=>{l.mutate(n)};if(!s)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-full bg-muted/30",children:[e.jsx(k,{className:"h-16 w-16 text-muted-foreground/50 mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-muted-foreground",children:"Select a conversation"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose a contact to start messaging"})]});const i=[];let c=null;return a.forEach(n=>{const x=A(new Date(n.createdAt),"yyyy-MM-dd");x!==c&&(i.push({type:"divider",data:n.createdAt}),c=x),i.push({type:"message",data:n})}),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(ys,{conversation:s,onBack:t,showBackButton:d}),e.jsx(O,{className:"flex-1 p-4",ref:m,children:p?e.jsx("div",{className:"space-y-4",children:[...Array(5)].map((n,x)=>e.jsx("div",{className:`flex ${x%2===0?"justify-start":"justify-end"}`,children:e.jsx(C,{className:"h-12 w-48 rounded-2xl"})},x))}):a.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground",children:[e.jsx(k,{className:"h-12 w-12 mb-4 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No messages yet"}),e.jsx("p",{className:"text-xs",children:"Send a message to start the conversation"})]}):e.jsxs("div",{className:"space-y-3",children:[i.map((n,x)=>n.type==="divider"?e.jsx(Cs,{date:n.data},`divider-${x}`):e.jsx(_s,{message:n.data},n.data.id)),e.jsx("div",{ref:o})]})}),e.jsx(Ms,{onSend:r,disabled:l.isPending,placeholder:`Message ${s.contactName}...`})]})}const Ss=()=>{const{user:s}=L(),{data:t}=ze(),{data:d=[],isLoading:a}=U({queryKey:["team-contacts",s==null?void 0:s.id,t==null?void 0:t.role],queryFn:async()=>{var x,g;if(!s)return[];if((t==null?void 0:t.role)==="tenant"){const{data:h,error:_}=await b.from("leases").select(` 6 unit:units( 7 property:properties( 8 manager_id, 9 manager:profiles!properties_manager_id_fkey(id, full_name, email, avatar_url, phone) 10 ) 11 ) 12 `).eq("tenant_id",s.id).eq("status","active").limit(1).maybeSingle();_&&console.error("Error fetching tenant lease:",_);const w=(g=(x=h==null?void 0:h.unit)==null?void 0:x.property)==null?void 0:g.manager;return w&&w.id!==s.id?[{id:w.id,fullName:w.full_name||w.email||"Property Manager",email:w.email,role:"property_manager",avatar:w.avatar_url,phone:w.phone,isPriorityContact:!0}]:[]}const{data:m,error:o}=await b.from("user_roles").select("user_id, role").neq("user_id",s.id);if(o)throw o;if(!m||m.length===0)return[];const r=new Map;m.forEach(h=>
12{const _=r.get(h.user_id);(!_||de(h.role)<de(_))&&r.set(h.user_id,h.role)});const i=Array.from(r.keys()),{data:c,error:n}=await b.from("profiles").select("id, full_name, email, avatar_url, phone").in("id",i);if(n)throw n;return c.map(h=>({id:h.id,fullName:h.full_name||h.email||"Unknown",email:h.email,role:r.get(h.id)||null,avatar:h.avatar_url,phone:h.phone}))},enabled:!!s&&!!t}),p=d.reduce((l,m)=>{const o=m.role||"other";return l[o]||(l[o]=[]),l[o].push(m),l},{});return{contacts:d,groupedByRole:p,isLoading:a}};function de(s){return s?{site_admin:0,admin:1,owner:2,manager:3,property_manager:4,maintenance_staff:5,tenant:6}[s]??99:99}const As={tenant:"bg-emerald-500",owner:"bg-slate-700",manager:"bg-blue-500",property_manager:"bg-purple-500",maintenance_staff:"bg-orange-500",admin:"bg-red-500",site_admin:"bg-red-700"},ks={tenant:"Tenant",owner:"Owner",manager:"Manager",property_manager:"Property Manager",maintenance_staff:"Maintenance",admin:"Admin",site_admin:"Admin"},K=["owner","manager","property_manager","maintenance_staff","tenant","admin","site_admin"];function me({open:s,onOpenChange:t,onSelectContact:d}){const{groupedByRole:a,isLoading:p}=Ss(),[l,m]=f.useState(""),o=c=>c.split(" ").map(n=>n[0]).join("").toUpperCase().slice(0,2),r=c=>{d(c),t(!1),m("")},i=Object.entries(a).filter(([c])=>K.includes(c)).sort(([c],[n])=>K.indexOf(c)-K.indexOf(n)).map(([c,n])=>({role:c,contacts:n.filter(x=>{var g;return x.fullName.toLowerCase().includes(l.toLowerCase())||((g=x.email)==null?void 0:g.toLowerCase().includes(l.toLowerCase()))})})).filter(c=>c.contacts.length>0);return e.jsx(Ae,{open:s,onOpenChange:t,children:e.jsxs(ke,{className:"max-w-md max-h-[80vh] flex flex-col",children:[e.jsx(De,{children:e.jsxs(Re,{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-5 w-5"}),"Start New Chat"]})}),e.jsxs("div",{className:"relative",children:[e.jsx(he,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(z,{placeholder:"Search contacts...",value:l,onChange:c=>m(c.target.value),className:"pl-9"})]}),e.jsx(O,{className:"flex-1 -mx-6 px-6",children:p?e.jsx("div",{className:"space-y-4 py-4",children:[...Array(5)].map((c,n)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(C,{className:"h-10 w-10 rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(C,{className:"h-4 w-32"}),e.jsx(C,{className:"h-3 w-24"})]})]},n))}):i.length===0?e.jsxs("div",{className:"py-12 text-center text-muted-foreground",children:[e.jsx(P,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No contacts found"})]}):e.jsx("div",{className:"py-2 space-y-4",children:i.map(({role:c,contacts:n})=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[e.jsx(S,{variant:"secondary",className:v("text-xs text-white",As[c]),children:ks[c]||c}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[n.length," ",n.length===1?"contact":"contacts"]})]}),e.jsx("div",{className:"space-y-1",children:n.map(x=>e.jsxs("div",{onClick:()=>r(x),className:"flex items-center gap-3 p-2 rounded-lg hover:bg-accent cursor-pointer transition-colors",children:[e.jsxs(Q,{className:"h-10 w-10",children:[e.jsx(W,{src:x.avatar||void 0}),e.jsx(V,{className:"bg-muted text-muted-foreground",children:o(x.fullName)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:x.fullName}),x.email&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:x.email})]})]},x.id))})]},c))})})]})})}function Ds(){const s=Le(),[t,d]=f.useState(null),[a,p]=f.useState(!1),[l,m]=f.useState(!1);Qe("new",()=>p(!0));const o=c=>{d(c),s&&m(!0)},r=c=>{const n={contactId:c.id,contactName:c.fullName,contactAvatar:c.avatar,contactEmail:c.email,contactRole:c.role,lastMessage:"",lastMessageAt:new Date().toISOString(),unreadCount:0,isFromMe:!0};d(n),s&&m(!0)},i=()=>{m(!1)};return s?e.jsxs("div",{className:"h-[calc(100vh-8rem)] flex flex-col bg-background rounded-lg border border-border overflow-hidden",children:[l?e.jsx(ce,{conversation:t,onBack:i,showBackButton:!0}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-border",children:[e.jsx("h2",{className:"font-semibold",children:"Messages"}),e.jsxs(y,{size:"sm",onClick:()=>p(!0),className:"gap-1",children:[e.jsx(Z,{className:"h-4 w-4"}),"New"]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(le,{selectedContactId:(t==null?void 0:t.contactId)||null,onSelectConversation:o})})]}),e.jsx(me,{open:a,onOpenChange:p,onSelectContact:r})]}):e.jsxs("div",{className:"h-[calc(100vh-8rem)] flex bg-background rounded-lg border border-border overflow-hidden",children:[e.jsxs("div",{className:"w-80 border-r border-border flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-border",children:[e.jsx("h2",{className:"font-semibold",children:"Conversations"}),e.jsxs(y,{size:"sm",onClick:()=>p(!0),className:"gap-1",children:[e.jsx(Z,{className:"h-4 w-4"}),"New Chat"]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(le,{selectedContactId:(t==null?void 0:t.contactId)||null,onSelectConversation:o})})]}),e.jsx("div",{className:"flex-1",children:e.jsx(ce,{conversation:t})}),e.jsx(me,{open:a,onOpenChange:p,onSelectContact:r})]})}function Rs(s){const t=U({queryKey:["landing-page-inquiries",s],queryFn:async()=>
12{if(!s)return[];try{const{data:d,error:a}=await b.from("landing_pages").select("id, title").eq("created_by",s);if(a)throw a;if(!d||d.length===0)return[];const p=d.map(r=>r.id),l=new Map(d.map(r=>[r.id,r.title])),{data:m,error:o}=await b.from("landing_page_inquiries").select("*").in("landing_page_id",p).order("created_at",{ascending:!1});if(o)throw o;return(m||[]).map(r=>({id:r.id,name:r.name,email:r.email,phone:r.phone,message:r.message,inquiry_type:r.inquiry_type,created_at:r.created_at,landing_page_id:r.landing_page_id,landing_page_title:l.get(r.landing_page_id)}))}catch(d){return console.error("Error fetching landing page inquiries:",d),[]}},enabled:!!s});return{inquiries:t.data,isLoading:t.isLoading}}function qs(){const{user:s}=L(),{inquiries:t,isLoading:d}=Rs(s==null?void 0:s.id);return d?e.jsx("div",{className:"space-y-4",children:[...Array(3)].map((a,p)=>e.jsx(C,{className:"h-32 w-full"},p))}):!t||t.length===0?e.jsx(I,{children:e.jsxs(T,{className:"p-12 text-center",children:[e.jsx(F,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"No landing page inquiries yet"})]})}):e.jsx("div",{className:"space-y-4",children:t.map(a=>e.jsx(I,{className:"shadow-card hover:shadow-elevated transition-all",children:e.jsxs(T,{className:"p-4",children:[e.jsx("div",{className:"flex items-start justify-between mb-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(F,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-semibold",children:a.name}),e.jsx(S,{variant:"secondary",children:a.inquiry_type||"Contact"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:je(new Date(a.created_at),{addSuffix:!0})})]})]})}),e.jsxs("div",{className:"space-y-2 mb-3",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"Email:"})," ",a.email]}),a.phone&&e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"Phone:"})," ",a.phone]}),a.landing_page_title&&e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"Landing Page:"})," ",a.landing_page_title]})]}),a.message&&e.jsx("div",{className:"bg-muted/30 p-3 rounded-md",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:a.message})})]})},a.id))})}const Ls={new:"bg-blue-500",contacted:"bg-yellow-500",closed:"bg-green-500"};function Es(){const{t:s}=pe(),{user:t}=L(),{inquiries:d,isLoading:a}=We(t==null?void 0:t.id),p=Ve(),l=Ye(),m=Ge(),[o,r]=f.useState(null),[i,c]=f.useState("all"),n=d.filter(u=>i==="all"?!0:u.status===i),x=d.filter(u=>!u.read).length,g=async u=>{if(!u.read)try{await p.mutateAsync(u.id)}catch{D.error(s("common.error","Error"))}},h=async(u,j)=>{try{await l.mutateAsync({id:u,status:j}),D.success(s("inquiry.statusUpdated","Status updated"))}catch{D.error(s("common.error","Error"))}},_=async()=>{if(o)try{await m.mutateAsync(o),D.success(s("inquiry.deleted","Inquiry deleted")),r(null)}catch{D.error(s("common.error","Error"))}},w=(u,j)=>{const H=encodeURIComponent(`Hi ${j}, thank you for your inquiry. I'd like to discuss your property interest.`);window.open(`https://wa.me/${u.replace(/[^0-9]/g,"")}?text=${H}`,"_blank")},N=(u,j)=>{const H=encodeURIComponent("Re: Your Property Inquiry"),be=encodeURIComponent(`Hi ${j}, 13 14Thank you for your inquiry. I'd like to discuss your property interest. 15 16Best regards`);window.location.href=`mailto:${u}?subject=${H}&body=${be}`};return a?e.jsx("div",{className:"space-y-4",children:[...Array(3)].map((u,j)=>e.jsx(C,{className:"h-40 w-full"},j))}):d.length===0?e.jsx(I,{children:e.jsxs(T,{className:"p-12 text-center",children:[e.jsx(k,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:s("inquiry.noInquiries","No inquiries yet")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:s("inquiry.noInquiriesDesc","When visitors send inquiries from your portfolios or landing pages, they'll appear here.")})]})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[s("inquiry.total","Total"),": ",d.length]}),x>0&&e.jsxs(S,{variant:"destructive",className:"text-xs",children:[x," ",s("inquiry.unread","new")]})]}),e.jsxs(ee,{value:i,onValueChange:u=>c(u),children:[e.jsx(se,{className:"w-full sm:w-[150px]",children:e.jsx(te,{placeholder:s("inquiry.filterStatus","Filter by status")})}),e.jsxs(ae,{children:[e.jsx(M,{value:"all",children:s("common.all","All")}),e.jsx(M,{value:"new",children:s("inquiry.statusNew","New")}),e.jsx(M,{value:"contacted",children:s("inquiry.statusContacted","Contacted")}),e.jsx(M,{value:"closed",children:s("inquiry.statusClosed","Closed")})]})]})]}),n.map(u=>e.jsx(I,{className:`shadow-card hover:shadow-elevated transition-all ${u.read?"":"border-l-4 border-l-blue-500"}`,onClick:()=>g(u),children:e.jsxs(T,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${Ls[u.status]}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-semibold",children:u.visitor_name}),e.jsx(S,{variant:"outline",className:"text-xs capitalize",children:u.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:je(new Date(u.created_at),{addSuffix:!0})})]})]}),e.jsxs(ee,{value:u.status,onValueChange:j=>h(u.id,j),children:[e.jsx(se,{className:"w-[120px] h-8 text-xs",children:e.jsx(te,{})}),e.jsxs(ae,{children:[e.jsx(M,{value:"new",children:s("inquiry.statusNew","New")}),e.jsx(M,{value:"contacted",children:s("inquiry.statusContacted","Contacted")}),e.jsx(M,{value:"closed",children:s("inquiry.statusClosed","Closed")})]})]})]}),e.jsxs("div",{className:"space-y-2 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(F,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:u.visitor_email})]}),u.visitor_phone&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ns,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:u.visitor_phone})]}),u.property_interest&&e.jsxs("div",{className:"text-sm",children:[e.jsxs("span",{className:"font-medium",children:[s("inquiry.lookingFor","Looking for"),":"]})," ",u.property_interest]}),u.source_url&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(is,{className:"h-3 w-3"}),e.jsx("span",{className:"truncate max-w-[300px]",children:u.source_url})]})]}),u.message&&e.jsx("div",{className:"bg-muted/30 p-3 rounded-md mb-3",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:u.message})}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.visitor_phone&&e.jsxs(y,{size:"sm",variant:"outline",className:"text-green-600 border-green-600 hover:bg-green-50",onClick:j=>{j.stopPropagation(),w(u.visitor_phone,u.visitor_name)},children:[e.jsx("svg",{className:"h-4 w-4 mr-1",viewBox:"0 0 24 24",fill:"
16currentColor",children:e.jsx("path",{d:"M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"})}),"WhatsApp"]}),e.jsxs(y,{size:"sm",variant:"outline",className:"text-blue-600 border-blue-600 hover:bg-blue-50",onClick:j=>{j.stopPropagation(),N(u.visitor_email,u.visitor_name)},children:[e.jsx(F,{className:"h-4 w-4 mr-1"}),s("inquiry.replyEmail","Email")]}),u.status!=="contacted"&&e.jsxs(y,{size:"sm",variant:"outline",onClick:j=>{j.stopPropagation(),h(u.id,"contacted")},children:[e.jsx(fe,{className:"h-4 w-4 mr-1"}),s("inquiry.markContacted","Mark Contacted")]}),e.jsx(y,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",onClick:j=>{j.stopPropagation(),r(u.id)},children:e.jsx(os,{className:"h-4 w-4"})})]})]})},u.id)),e.jsx(Je,{open:!!o,onOpenChange:()=>r(null),children:e.jsxs(Xe,{children:[e.jsxs(Ze,{children:[e.jsx(es,{children:s("inquiry.deleteTitle","Delete Inquiry")}),e.jsx(ss,{children:s("inquiry.deleteDesc","Are you sure you want to delete this inquiry? This action cannot be undone.")})]}),e.jsxs(ts,{children:[e.jsx(as,{children:s("common.cancel","Cancel")}),e.jsx(rs,{onClick:_,className:"bg-destructive text-destructive-foreground",children:s("common.delete","Delete")})]})]})})]})}function Is(){const[s,t]=f.useState(""),d=f.useRef(null),a=f.useRef(),{sessionId:p,isLoading:l,updateActivity:m,setTyping:o}=ls(),{messages:r,isLoading:i,isSending:c,sendMessage:n}=cs(p),{isOnline:x}=ds();f.useEffect(()=>{d.current&&(d.current.scrollTop=d.current.scrollHeight)},[r]);const g=N=>{t(N.target.value),o(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{o(!1)},2e3)},h=async()=>{if(!s.trim()||c)return;const N=s.trim();t(""),o(!1),await n(N,"user"),m()},_=N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),h())},w=l||i;return e.jsxs("div",{className:"flex flex-col h-[600px] border rounded-lg bg-card",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 border-b bg-muted/30",children:[e.jsx("div",{className:"flex items-center justify-center h-10 w-10 rounded-full bg-primary/10",children:e.jsx($,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold",children:"Contact Support"}),e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx("span",{className:v("h-2 w-2 rounded-full",x?"bg-green-500":"bg-muted-foreground")}),x?"Support team online":"Leave us a message"]})]})]}),e.jsx(O,{className:"flex-1 p-4",ref:d,children:w?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(J,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):r.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center p-6",children:[e.jsx($,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h4",{className:"font-medium mb-2",children:"How can we help?"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Send us a message and our support team will get back to you as soon as possible."})]}):e.jsx("div",{className:"space-y-4",children:r.map(N=>e.jsx("div",{className:v("flex",N.from_role==="user"?"justify-end":"justify-start"),children:e.jsxs("div",{className:v("max-w-[80%] rounded-lg px-4 py-2",N.from_role==="user"?"bg-primary text-primary-foreground":"bg-muted"),children:[e.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:N.message}),e.jsx("span",{className:"text-xs opacity-70 mt-1 block",children:A(new Date(N.created_at),"HH:mm")}
16)]})},N.id))})}),e.jsx("div",{className:"p-4 border-t",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(z,{placeholder:"Type your message...",value:s,onChange:g,onKeyDown:_,disabled:c,className:"flex-1"}),e.jsx(y,{onClick:h,disabled:!s.trim()||c,size:"icon",children:c?e.jsx(J,{className:"h-4 w-4 animate-spin"}):e.jsx(ge,{className:"h-4 w-4"})})]})})]})}const Br=()=>{const{t:s}=pe(),[t,d]=f.useState("messages"),{conversations:a,totalUnread:p,isLoading:l}=Ne(),m=f.useMemo(()=>{const o=a.filter(c=>Y(hs(c.lastMessageAt))).length,r=a.filter(c=>!c.isFromMe).length,i=new Set(a.map(c=>c.contactId)).size;return{today:o,needsReply:r,activeContacts:i}},[a]);return e.jsxs(we,{children:[e.jsx(Ce,{title:s("messages.title"),subtitle:s("messages.subtitle","One inbox for tenants, owners, portfolio leads, landing-page inquiries, and support."),icon:e.jsx(E,{className:"h-5 w-5"})}),e.jsx(ps,{metrics:[{label:"Unread",value:l?"...":p,detail:"Messages waiting on you",icon:E,tone:p?"warning":"success"},{label:"Needs reply",value:l?"...":m.needsReply,detail:"Latest message came from them",icon:ye,tone:m.needsReply?"info":"default"},{label:"Active today",value:l?"...":m.today,detail:"Conversations with activity",icon:_e,tone:"info"},{label:"Contacts",value:l?"...":m.activeContacts,detail:"People in your inbox",icon:P}]}),e.jsx(ne,{title:"Inbox Routing",subtitle:"Start with direct messages, then clear portfolio and landing-page inquiries before they age.",action:e.jsx(ie,{tone:"info",children:t.replace("-"," ")}),children:e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-5",children:[{value:"messages",title:"Direct messages",description:"Tenants, staff, managers, and owners.",icon:E},{value:"inquiries",title:"Portfolio leads",description:"People asking about shared portfolios.",icon:k},{value:"landing-inquiries",title:"Landing pages",description:"Inbound leads from public property pages.",icon:G},{value:"support",title:"Support",description:"Ask for product or account help.",icon:$},{value:"whatsapp",title:"WhatsApp",description:"Prepare a chat in your browser.",icon:re}].map(o=>e.jsxs("button",{type:"button",onClick:()=>d(o.value),className:"rounded-lg border bg-background p-4 text-left transition-colors hover:bg-muted/60",children:[e.jsx(o.icon,{className:"h-5 w-5 text-primary"}),e.jsx("p",{className:"mt-3 font-medium",children:o.title}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-muted-foreground",children:o.description})]},o.value))})}),e.jsxs(ms,{value:t,onValueChange:d,className:"w-full",children:[e.jsxs(us,{className:"h-auto flex-wrap justify-start gap-1 rounded-lg border bg-card p-1",children:[e.jsxs(R,{value:"messages",className:"gap-1.5",children:[e.jsx(E,{className:"h-4 w-4"}),s("messages.title","Messages")]}),e.jsxs(R,{value:"inquiries",className:"flex items-center gap-1.5",children:[e.jsx(k,{className:"h-4 w-4"}),s("inquiry.portfolioInquiries","Portfolio Inquiries")]}),e.jsxs(R,{value:"landing-inquiries",className:"gap-1.5",children:[e.jsx(G,{className:"h-4 w-4"}),s("inquiry.landingInquiries","Landing Page Inquiries")]}),e.jsxs(R,{value:"support",className:"flex items-center gap-1.5",children:[e.jsx($,{className:"h-4 w-4"}),s("messages.contactSupport","Contact Support")]}),e.jsxs(R,{value:"whatsapp",className:"flex items-center gap-1.5",children:[e.jsx(re,{className:"h-4 w-4"}),"WhatsApp"]})]}),e.jsx(q,{value:"messages",className:"mt-4",children:e.jsx(Ds,{})}),e.jsx(q,{value:"inquiries",className:"mt-4",children:e.jsx(Es,{})}),e.jsx(q,{value:"landing-inquiries",className:"mt-4",children:e.jsx(qs,{})}),e.jsx(q,{value:"support",className:"mt-4",children:e.jsx(Is,{})}),e.jsx(q,{value:"whatsapp",className:"mt-4",children:e.jsx(ne,{title:"WhatsApp",subtitle:"Prepare the message here, then review and send it from your own WhatsApp session.",action:e.jsx(ie,{tone:"success",children:"Browser local"}),children:e.jsx(xs,{})})})]})]})};export{Br 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.