PageSourceSearch

https://thescope360.web.app/static/js/3046.cbd4404a.chunk.js

js thescope360.web.app collected 2026-10-03 12:40:29 UTC 40,221 bytes, 3 lines download raw bytes

1/*! For license information please see 3046.cbd4404a.chunk.js.LICENSE.txt */
2"use strict";(self.webpackChunkthescope360_app=self.webpackChunkthescope360_app||[]).push([[3046],{3046(e,t,s){s.r(t),s.d(t,{default:()=>D});var a=s(65043),r=s(64963),i=s(8729),n=s(89379),l=s(91729),o=s(3611);function d(){const[e,t]=(0,a.useState)([]),[s,r]=(0,a.useState)(!0);return(0,a.useEffect)(()=>{let e=!0,a=null;const i=setTimeout(()=>{e&&s&&r(!1)},3e3);try{a=(0,o.KR)(l.v$,"visitors"),(0,o.Zy)(a,s=>{if(e){if(s.exists()){const e=s.val(),a=Object.entries(e).map(e=>{let[t,s]=e;return(0,n.A)((0,n.A)({id:t},s),{},{lastSeenDate:s.lastSeen?new Date(s.lastSeen):null})}).filter(e=>e.isOnline).sort((e,t)=>(t.lastSeen||0)-(e.lastSeen||0));t(a)}else t([]);r(!1)}},s=>{var a,i;e&&(null!==s&&void 0!==s&&null!==(a=s.message)&&void 0!==a&&a.includes("configured correctly")||null!==s&&void 0!==s&&null!==(i=s.message)&&void 0!==i&&i.includes("FIREBASE")?console.warn("Realtime Database not configured. Visitor tracking disabled."):console.error("Visitor tracking error:",s),t([]),r(!1))})}catch(d){console.warn("Failed to setup visitor tracking:",d.message),r(!1)}return()=>{if(e=!1,clearTimeout(i),a)try{(0,o.AU)(a)}catch(t){}}},[]),{visitors:e,loading:s,onlineCount:e.length}}var c=s(68507),x=s(20254),u=s(77784);const m=(0,u.A)("phone-call",[["path",{d:"M13 2a9 9 0 0 1 9 9",key:"1itnx2"}],["path",{d:"M13 6a5 5 0 0 1 5 5",key:"11nki7"}],["path",{d:"M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384",key:"9njp5v"}]]);var p=s(37719);const g=(0,u.A)("radio",[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]]);var h=s(7899),b=s(42574),v=s(43677),f=s(75699),y=s(19233),j=s(63329),N=s(7118),A=s(14939),k=s(14459),w=s(35087),I=s(22024),C=s(55731),S=s(75088),z=s(28006),T=s(20073),M=s(76245),q=s(40614),B=s(85692),E=s(56099),Z=s(50516),H=s(35746),R=s(55472),G=s(70579);function D(){var e;const{currentUser:t,client:s,refreshClient:n}=(0,i.A)(),{visitors:o,loading:u,onlineCount:D}=d(),{chats:O,closedChats:J,loading:L,activeCount:W,error:V}=(0,c.jJ)(),[X,U]=(0,a.useState)("open"),F="open"===X?O:J,[Q,Y]=(0,a.useState)("live"),[P,_]=(0,a.useState)(null),[K,$]=(0,a.useState)(null),[ee,te]=(0,a.useState)(""),[se,ae]=(0,a.useState)(!1),[re,ie]=(0,a.useState)([]),[ne,le]=(0,a.useState)(!1),[oe,de]=(0,a.useState)(()=>"false"!==localStorage.getItem("live_support_visitor_sound")),[ce,xe]=(0,a.useState)(!1),[ue,me]=(0,a.useState)(""),[pe,ge]=(0,a.useState)(!1),he=(0,a.useRef)(null),be=(0,a.useRef)(null),ve=(0,a.useRef)(null),fe=(0,a.useRef)(null),ye=(0,a.useRef)(0),je=(0,a.useRef)(new Set),Ne=(0,a.useRef)(!0),Ae=O.filter(e=>e.needsHumanAttention&&!e.humanTakeover),ke=Ae.length,we=(0,a.useMemo)(()=>o.filter(e=>{var s,a;if(e.userId&&null!==t&&void 0!==t&&t.uid&&e.userId===t.uid)return!1;const r=(null===(s=e.page)||void 0===s?void 0:s.toLowerCase())||"";if(r.startsWith("/admin")||r.startsWith("/specialist")||r.startsWith("/mentor"))return!1;const i=null===(a=e.userRole)||void 0===a?void 0:a.toLowerCase();return"admin"!==i&&"specialist"!==i&&"mentor"!==i}),[o,null===t||void 0===t?void 0:t.uid]),Ie=we.length;(0,a.useEffect)(()=>{be.current=new Audio("data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2telehs+nODKqW0aP5jYu5hpGz+Z2LqZbB4/mte5mm0gP5nYu5pvJT+Y17qZbig/mNe5mW4pP5jXuJltKD+Y17iZbSg/mNe4mW0oP5jXuJltKD+Y17iZbSg/mNe4mW0n"),be.current.volume=.6,ve.current=new Audio("data:audio/wav;base64,UklGRl9nAABXQVZFZm10IBIAAAABAAEAQB8AAIA+AAACABAAZGF0YQBnAACAgICAgICAgICAgICAgICAgICAgICAgICAgICBg4aJi46QkpOVlpeYmJmZmZmZmJeWlZORj42KiIWDgYCAgICAgICBg4aJi46QkpOVlpeYmJmZmZmZmJeWlZORj42KiIWDgYCAgICAgICAgICAgICAgICAgICAgICAgICAgIB/fXp4dXNxb25tbWxsbW1ub3Fyc3V4en1/gICAgICAgICAgICAgICAf317eXZ0cnBubWxramloaGhoaGlqa2xucHJ0dnh7fX+AgICAgICAgICAgIB/fXt5dnRycG5tbGtqaWhoZ2dnZ2doaGlqa2xucHJ0dnh7fX+AgICAgICAgIB/fXt5dnRycG5tbGtqaWhoZ2dnZ2doaGlqa2xucHJ0dnh7fX+AgICAgICAgIB/fXt5dnRycG5tbGtqaWhoZ2dnZ2doaGlqa2xucHJ0dnh7fX+AgICAgICAgIB/fXt5dnRycG5tbGtqaWhoZ2dnZ2doaGlqa2xucHJ0dnh7fX+AgICAgICAgIB/fXt5dnRycG5tbGtqaWhoZ2dnZ2doaGlqa2xucHJ0dnh7fX+AgICAgICAgIB/fXt5dnRycG5tbGtqaWhoZ2dnZ2doaGlqa2xucHJ0dnh7fX+AgICAgICAgA=="),ve.current.volume=.7},[]),(0,a.useEffect)(()=>(fe.current&&(clearInterval(fe.current),fe.current=null),ke>0&&oe&&((0===ye.current||ke>ye.current)&&(ve.current&&ve.current.play().catch(()=>{}),ce&&new Notification("\ud83d\udea8 URGENT: Human Requested!",{body:"".concat(ke," visitor").concat(ke>1?"s":""," waiting for a live representative!"),icon:"/favicon.ico",tag:"urgent-support",requireInteraction:!0})),fe.current=setInterval(()=>{ve.current&&oe&&ve.current.play().catch(()=>{})},15e3)),ye.current=ke,()=>{fe.current&&clearInterval(fe.current)}),[ke,oe,ce]),(0,a.useEffect)(()=>{"Notification"in window&&("granted"===Notification.permission?xe(!0):"denied"!==Notification.permission&&Notification.requestPermission().then(e=>{xe("granted"===e)}))},[]),(0,a.useEffect)(()=>{localStorage.setItem("live_support_visitor_sound",String(oe))},[oe]),(0,a.useEffect)(()=>
2{if(u)return;if(Ne.current)return we.forEach(e=>je.current.add(e.id)),void(Ne.current=!1);const e=we.filter(e=>!je.current.has(e.id));if(e.length>0&&(e.forEach(e=>je.current.add(e.id)),oe&&be.current&&be.current.play().catch(()=>{}),ce&&document.hidden)){const t=e.map(e=>e.userName||"Anonymous").join(", ");new Notification("New Visitor Online",{body:"".concat(1===e.length?t+" is":e.length+" visitors are"," now on the site"),icon:"/favicon.ico",tag:"visitor-online"})}},[we,u,oe,ce]);const Ce=e=>{if(!e)return"";const t=Date.now()-e,s=Math.floor(t/1e3),a=Math.floor(s/60),r=Math.floor(a/60);return r>0?"".concat(r,"h ").concat(a%60,"m"):a>0?"".concat(a,"m ").concat(s%60,"s"):"".concat(s,"s")},[,Se]=(0,a.useState)(0);(0,a.useEffect)(()=>{const e=setInterval(()=>{Se(e=>e+1)},1e3);return()=>clearInterval(e)},[]);const{chat:ze,messages:Te,loading:Me}=(0,c.HJ)(P),qe=(null===s||void 0===s?void 0:s.chatAlias)||null,Be=!!qe;(0,a.useEffect)(()=>{null!==ze&&void 0!==ze&&ze.humanTakeover&&Te.length>0&&Ee()},[null===ze||void 0===ze?void 0:ze.humanTakeover,Te.length]);const Ee=async()=>{if(!Te.length)return;le(!0);const e=await(0,c.eL)(Te);ie(e),le(!1)},Ze=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ee;e.trim()&&P&&!se&&(ae(!0),te(""),await(0,c.H3)(P,e.trim(),t.uid,qe),ae(!1),Ee())},He=K?o.find(e=>e.id===K.id)||K:null,Re=e=>{if(!e)return"";const t=new Date(e),s=new Date,a=t.toDateString()===s.toDateString(),r=t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"});return a?"Today, ".concat(r):t.toLocaleDateString("en-US",{month:"short",day:"numeric"})+", ".concat(r)},Ge=e=>{if(!e)return"Unknown";const t=e.split("/").filter(Boolean);return 0===t.length?"Home":t[t.length-1].replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())};return Be?(0,G.jsxs)("div",{className:"max-w-7xl mx-auto space-y-6 pb-20",children:[ke>0&&(0,G.jsx)("div",{className:"animate-pulse bg-gradient-to-r from-red-600 via-orange-500 to-red-600 rounded-2xl p-4 shadow-lg shadow-red-500/30 border-2 border-red-400",children:(0,G.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[(0,G.jsxs)("div",{className:"flex items-center gap-4",children:[(0,G.jsxs)("div",{className:"relative",children:[(0,G.jsx)(m,{size:32,className:"text-white animate-bounce"}),(0,G.jsxs)("span",{className:"absolute -top-1 -right-1 flex h-4 w-4",children:[(0,G.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-white opacity-75"}),(0,G.jsx)("span",{className:"relative inline-flex rounded-full h-4 w-4 bg-white text-red-600 text-[10px] font-black items-center justify-center",children:ke})]})]}),(0,G.jsxs)("div",{children:[(0,G.jsxs)("h2",{className:"text-white font-black text-lg flex items-center gap-2",children:[(0,G.jsx)(p.A,{className:"animate-pulse",size:20}),"HUMAN REQUESTED!"]}),(0,G.jsxs)("p",{className:"text-white/90 text-sm",children:[ke," visitor",ke>1?"s are":" is"," waiting for a live representative"]})]})]}),(0,G.jsxs)("button",{onClick:()=>{Y("live");const e=Ae[0];e&&(_(e.id),$(null))},className:"px-6 py-3 bg-white text-red-600 rounded-xl font-black hover:bg-red-50 transition-colors flex items-center gap-2 shadow-lg",children:[(0,G.jsx)(x.A,{size:18}),"Take Over Now"]})]})}),(0,G.jsxs)("div",{className:"flex items-center gap-1 p-1 rounded-xl bg-gray-100 dark:bg-gray-800/60 border border-gray-200 dark:border-gray-700 w-fit",children:[(0,G.jsxs)("button",{onClick:()=>Y("live"),className:"relative flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold transition-all ".concat("live"===Q?"bg-white dark:bg-gray-700 text-emerald-600 dark:text-emerald-400 shadow-sm":ke>0?"text-red-500 dark:text-red-400 bg-red-500/10 animate-pulse":"text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"),children:[(0,G.jsx)(g,{size:14}),"Live Monitor",ke>0&&"live"!==Q&&(0,G.jsxs)("span",{className:"absolute -top-1.5 -right-1.5 flex h-5 w-5",children:[(0,G.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-red-500 opacity-75"}),(0,G.jsx)("span",{className:"relative inline-flex rounded-full h-5 w-5 bg-red-500 text-white text-[10px] font-black items-center justify-center",children:ke})]})]}),(0,G.jsxs)("button",{onClick:()=>Y("tickets"),className:"flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-bold transition-all ".concat("tickets"===Q?"bg-white dark:bg-gray-700 text-blue-600 dar
2k:text-blue-400 shadow-sm":"text-gray-500 hover:text-gray-700 dark:hover:text-gray-300"),children:[(0,G.jsx)(h.A,{size:14}),"Ticket Queue"]})]}),"live"===Q&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)("div",{className:"flex items-center justify-end gap-3",children:[(0,G.jsxs)("span",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-green-500/10 text-green-500 text-xs font-bold",children:[(0,G.jsx)("span",{className:"w-2 h-2 bg-green-500 rounded-full animate-pulse"}),Ie," Online"]}),(0,G.jsxs)("span",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-blue-500/10 text-blue-500 text-xs font-bold",children:[(0,G.jsx)(b.A,{size:12}),W," Active Chats"]}),(0,G.jsx)("button",{onClick:()=>de(!oe),className:"p-2 rounded-lg transition-colors ".concat(oe?"bg-emerald-500/10 text-emerald-500":"bg-gray-100 dark:bg-gray-800 text-gray-400"),title:oe?"Visitor sound on":"Visitor sound off",children:oe?(0,G.jsx)(v.A,{size:16}):(0,G.jsx)(f.A,{size:16})}),(0,G.jsx)("button",{onClick:()=>{!ce&&"Notification"in window?Notification.requestPermission().then(e=>{xe("granted"===e)}):xe(!ce)},className:"p-2 rounded-lg transition-colors ".concat(ce?"bg-emerald-500/10 text-emerald-500":"bg-gray-100 dark:bg-gray-800 text-gray-400"),title:ce?"Browser notifications on":"Browser notifications off",children:ce?(0,G.jsx)(y.A,{size:16}):(0,G.jsx)(j.A,{size:16})})]}),(0,G.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-5 gap-4",children:[ke>0&&(0,G.jsxs)("div",{className:"p-5 rounded-2xl border-2 border-red-500 bg-red-500/10 animate-pulse",children:[(0,G.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,G.jsx)(m,{size:16,className:"text-red-500 animate-bounce"}),(0,G.jsx)("p",{className:"text-[10px] font-black uppercase tracking-widest text-red-500",children:"URGENT"})]}),(0,G.jsx)("p",{className:"text-3xl font-black text-red-600",children:ke})]}),(0,G.jsxs)("div",{className:"p-5 rounded-2xl border border-gray-300 dark:border-gray-700 bg-transparent",children:[(0,G.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,G.jsx)(N.A,{size:16,className:"text-emerald-500"}),(0,G.jsx)("p",{className:"text-[10px] font-black uppercase tracking-widest opacity-40",children:"Live Visitors"})]}),(0,G.jsx)("p",{className:"text-3xl font-black",children:Ie})]}),(0,G.jsxs)("div",{className:"p-5 rounded-2xl border border-gray-300 dark:border-gray-700 bg-transparent",children:[(0,G.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,G.jsx)(b.A,{size:16,className:"text-blue-500"}),(0,G.jsx)("p",{className:"text-[10px] font-black uppercase tracking-widest opacity-40",children:"Active Chats"})]}),(0,G.jsx)("p",{className:"text-3xl font-black",children:W})]}),(0,G.jsxs)("div",{className:"p-5 rounded-2xl border border-gray-300 dark:border-gray-700 bg-transparent",children:[(0,G.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,G.jsx)(A.A,{size:16,className:"text-indigo-500"}),(0,G.jsx)("p",{className:"text-[10px] font-black uppercase tracking-widest opacity-40",children:"AI Handling"})]}),(0,G.jsx)("p",{className:"text-3xl font-black",children:O.filter(e=>!e.humanTakeover).length})]}),(0,G.jsxs)("div",{className:"p-5 rounded-2xl border border-gray-300 dark:border-gray-700 bg-transparent",children:[(0,G.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,G.jsx)(k.A,{size:16,className:"text-yellow-500"}),(0,G.jsx)("p",{className:"text-[10px] font-black uppercase tracking-widest opacity-40",children:"Human Assisted"})]}),(0,G.jsx)("p",{className:"text-3xl font-black",children:O.filter(e=>e.humanTakeover).length})]})]}),(0,G.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[(0,G.jsxs)("div",{className:"space-y-4",style:{height:"calc(100vh - 240px)",minHeight:"500px",maxHeight:"800px",display:"flex",flexDirection:"column"},children:[(0,G.jsxs)("div",{className:"rounded-2xl border border-gray-300 dark:border-gray-700 overflow-hidden flex-shrink-0",style:{maxHeight:"40%"},children:[(0,G.jsxs)("div",{className:"px-4 py-3 border-b border-gray-300 dark:border-gray-700 bg-emerald-500/10 flex items-center gap-2",children:[(0,G.jsx)(w.A,{size:16,className:"text-emerald-500"}),(0,G.jsx)("h3",{className:"text-xs font-black uppercase tracking-widest text-emerald-600 dark:text-emerald-400",children:"Live Visitors"})]}),(0,G.jsx)("div",{className:"overflow-y-auto",style:{maxHeight:"calc(100% - 44px)"},children:u?(0,G.jsx)("div",{className:"p-8 text-center",children:(0,G.jsx)(I.A,{size:24,className:"animate-spin mx-auto opacity-30"})}):0===we.length?(0,G.jsxs)("div",{className:"p-8 text-center opacity-40",children:[(0,G.jsx)(C.A,{size:32,className:"mx-auto mb-2 opacity-30"}),(0,G.jsx)("p",{className:"text-xs",children:"No visitors online"})]}):(0,G.jsx)("div",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:we.map(e=>{var t;const s=O.some(t=>t.visitorId===e.visitorId),a=(null===K||void 0===K?void 0:K.id)===e.id||P&&(null===(t=O.find(e=>e.id===P))||void 0===t?void 0:t.visitorId)===e.visitorId;return(0,G.jsxs)("button",{onClick:()=>(e=>{const t=O.find(t=>t.visitorId===e.visitorId);$(e),_(t?t.id:null)})(e),className:"w-full text-left p-3 transition-colors ".concat(a?"bg-emerald-50 dark:bg-emerald-900/20 border-l-2 border-emerald-500":"hover:bg-gray-50 dark:hover:bg-gray-800/50 border-l-2 border-transparent"),children:[(0,G.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,G.jsx)("span",{className:"font-bold text-sm truncate",children:e.userName||"Anonymous"}),(0,G.jsxs)("div",{className:"flex items-center gap-2",children:[s&&(0,G.jsx)("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-blue-500/10 text-blue-500 font-bold",children:"CHAT"}),e.sessionStart&&(0,G.jsxs)("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-500",children:[(0,G.jsx)(S.A,{size:8,className:"inline mr-1"}),Ce(e.sessionStart)]}),(0,G.jsx)("span",{className:"w-2 h-2 bg-green-500 rounded-full animate-pulse"})]})]}),(0,G.jsxs)("div",{className:"flex items-center gap-2 text-xs opacity-50 mb-1",children:[(0,G.jsx)(C.A,{size:10}),(0,G.jsx)("span",{className:"truncate font-medium",children:Ge(e.page)})]}),(0,G.jsx)("div",{className:"text-[10px] opacity-40 font-mono truncate pl-4",children:e.page||"/"}),e.userEmail&&(0,G.jsx)("div",{className:"text-[10px] opacity-40 truncate pl-4 mt-0.5",children:e.userEmail}),(e.city||e.country||e.ip)&&(0,G.jsxs)("div",{className:"flex items-center gap-1 text-[10px] opacity-40 truncate pl-4 mt-0.5",children:[(0,G.jsx)(z.A,{size:10,
2className:"shrink-0"}),(0,G.jsx)("span",{className:"truncate",children:[e.city,e.country].filter(Boolean).join(", ")||e.ip})]})]},e.id)})})})]}),(0,G.jsxs)("div",{className:"rounded-2xl border border-gray-300 dark:border-gray-700 overflow-hidden flex-1 flex flex-col min-h-0",children:[(0,G.jsxs)("div",{className:"px-4 py-3 border-b border-gray-300 dark:border-gray-700 bg-blue-500/10 flex items-center gap-2 flex-shrink-0",children:[(0,G.jsx)(b.A,{size:16,className:"text-blue-500"}),(0,G.jsx)("h3",{className:"text-xs font-black uppercase tracking-widest text-blue-600 dark:text-blue-400",children:"Chats"}),(0,G.jsx)("div",{className:"ml-auto flex gap-1",children:[["open","Open (".concat(O.length,")")],["closed","Closed (".concat(J.length,")")]].map(e=>{let[t,s]=e;return(0,G.jsx)("button",{onClick:()=>U(t),className:"px-2 py-0.5 rounded-full text-[10px] font-bold ".concat(X===t?"bg-blue-600 text-white":"text-blue-600 dark:text-blue-400 hover:bg-blue-500/10"),children:s},t)})})]}),V&&(0,G.jsxs)("div",{className:"px-4 py-3 bg-red-50 dark:bg-red-900/20 border-b border-red-300 dark:border-red-800 flex items-start gap-2 text-xs text-red-700 dark:text-red-300",children:[(0,G.jsx)(p.A,{size:14,className:"shrink-0 mt-0.5"}),(0,G.jsxs)("span",{children:["Could not load chats from Havlo: ",V,". Messages may be waiting. Check the Havlo dashboard directly."]})]}),(0,G.jsx)("div",{className:"overflow-y-auto flex-1",children:L?(0,G.jsx)("div",{className:"p-8 text-center",children:(0,G.jsx)(I.A,{size:24,className:"animate-spin mx-auto opacity-30"})}):0===F.length?(0,G.jsxs)("div",{className:"p-8 text-center opacity-40",children:[(0,G.jsx)(b.A,{size:32,className:"mx-auto mb-2 opacity-30"}),(0,G.jsx)("p",{className:"text-xs",children:"open"===X?"No open chats":"No closed chats"})]}):(0,G.jsx)("div",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:F.map(e=>{const t=e.needsHumanAttention&&!e.humanTakeover;return(0,G.jsxs)("button",{onClick:()=>{_(e.id),$(null)},className:"w-full p-3 text-left transition-colors relative ".concat(t?"bg-red-50 dark:bg-red-900/20 animate-pulse ring-2 ring-red-500 ring-inset":P===e.id?"bg-blue-50 dark:bg-blue-900/20":"hover:bg-gray-50 dark:hover:bg-gray-800/50"),children:[t&&(0,G.jsxs)("div",{className:"absolute -top-1 -right-1 flex items-center gap-1 px-2 py-0.5 bg-red-600 text-white text-[8px] font-black rounded-full animate-bounce",children:[(0,G.jsx)(m,{size:8}),"URGENT"]}),(0,G.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,G.jsx)("span",{className:"font-bold text-sm truncate",children:e.visitorName||"Visitor"}),(0,G.jsxs)("div",{className:"flex items-center gap-1",children:[t?(0,G.jsx)("span",{className:"px-2 py-0.5 rounded-full bg-red-600 text-white text-[8px] font-bold uppercase animate-pulse",children:"Needs Rep"}):e.humanTakeover?(0,G.jsx)("span",{className:"px-2 py-0.5 rounded-full bg-yellow-500/10 text-yellow-600 text-[8px] font-bold uppercase",children:"Human"}):(0,G.jsx)("span",{className:"px-2 py-0.5 rounded-full bg-indigo-500/10 text-indigo-600 text-[8px] font-bold uppercase",children:"AI"}),"outbound"===e.origin&&(0,G.jsx)("span",{className:"px-2 py-0.5 rounded-full bg-purple-500/10 text-purple-600 text-[8px] font-bold uppercase",children:"Outbound"})]})]}),(0,G.jsx)("p",{className:"text-xs opacity-50 truncate",children:e.lastMessageText||"No messages"}),(0,G.jsxs)("div",{className:"flex items-center gap-2 mt-1 text-[10px] opacity-40",children:[(0,G.jsx)(S.A,{size:10}),Re(e.lastMessageIso)]})]},e.id)})})})]})]}),(0,G.jsx)("div",{className:"lg:col-span-2 rounded-2xl border border-gray-300 dark:border-gray-700 overflow-hidden flex flex-col",style:{height:"calc(100vh - 240px)",minHeight:"500px",maxHeight:"800px"},children:He||P?Me&&P?(0,G.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,G.jsx)(I.A,{size:32,className:"animate-spin opacity-30"})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)("div",{className:"px-4 py-2 border-b border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50",children:(0,G.jsxs)("div",{className:"flex items-center justify-between",children:[(0,G.jsxs)("div",{className:"flex items-center gap-3",children:[(0,G.jsxs)("div",{className:"relative",children:[(0,G.jsx)("div",{className:"w-9 h-9 rounded-full bg-emerald-500/20 flex items-center justify-center",children:(0,G.jsx)(k.A,{size:16,className:"text-emerald-600 dark:text-emerald-400"})}),(0,G.jsx)("span",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 bg-green-500 rounded-full border-2 border-white dark:border-gray-800"})]}),(0,G.jsxs)("div",{children:[(0,G.jsxs)("div",{className:"flex items-center gap-2",children:[(0,G.jsx)("h3",{className:"font-bold text-sm",children:(null===He||void 0===He?void 0:He.userName)||(null===ze||void 0===ze?void 0:ze.visitorName)||"Visitor"}),P&&(0,G.jsx)("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full font-bold ".concat(null!==ze&&void 0!==ze&&ze.humanTakeover?"bg-yellow-500/10 text-yellow-600":"bg-indigo-500/10 text-indigo-600"),children:null!==ze&&void 0!==ze&&ze.humanTakeover?"HUMAN":"AI BOT"})]}),(0,G.jsx)("p",{className:"text-[10px] opacity-50",children:(null===He||void 0===He?void 0:He.userEmail)||(null===ze||void 0===ze?void 0:ze.userEmail)||"Guest"})]})]}),(0,G.jsxs)("div",{className:"flex-1 mx-4 flex items-center justify-center gap-4",children:[(0,G.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1 rounded-lg bg-emerald-500/10",children:[(0,G.jsx)(C.A,{size:12,className:"text-emerald-500"}),(0,G.jsxs)("div",{className:"text-xs",children:[(0,G.jsx)("span",{className:"font-bold text-emerald-600 dark:text-emerald-400",children:Ge((null===He||void 0===He?void 0:He.page)||(null===ze||void 0===ze?void 0:ze.currentPage))}),(0,G.jsx)("span",{className:"ml-2 font-mono opacity-40 text-[10px]",children:(null===He||void 0===He?void 0:He.page)||(null===ze||void 0===ze?void 0:ze.currentPage)||"/"})]})]}),(null===He||void 0===He?void 0:He.sessionStart)&&(0,G.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-lg bg-blue-500/10 text-blue-500 text-xs font-mono",children:[(0,G.jsx)(S.A,{size:10}
2),Ce(He.sessionStart)]}),((null===He||void 0===He?void 0:He.city)||(null===He||void 0===He?void 0:He.country)||(null===He||void 0===He?void 0:He.ip))&&(0,G.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-lg bg-purple-500/10 text-purple-600 dark:text-purple-400 text-xs",children:[(0,G.jsx)(z.A,{size:10}),(0,G.jsx)("span",{className:"font-medium",children:[null===He||void 0===He?void 0:He.city,null===He||void 0===He?void 0:He.region,null===He||void 0===He?void 0:He.country].filter(Boolean).join(", ")||"Unknown"}),(null===He||void 0===He?void 0:He.ip)&&(0,G.jsx)("span",{className:"ml-1 font-mono opacity-50 text-[10px]",children:He.ip})]})]}),(0,G.jsxs)("div",{className:"flex items-center gap-2",children:[P&&!(null!==ze&&void 0!==ze&&ze.humanTakeover)&&(0,G.jsxs)("button",{onClick:async()=>{P&&(await(0,c.CZ)(P,t.uid,qe),Ee())},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-yellow-500 text-black text-[10px] font-bold hover:bg-yellow-400 transition-colors",children:[(0,G.jsx)(T.A,{size:12})," Take Over"]}),P&&(0,G.jsxs)("button",{onClick:async()=>{P&&(await(0,c.vt)(P),_(null),$(null))},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-red-300 dark:border-red-600 text-red-600 dark:text-red-400 text-[10px] font-bold hover:bg-red-50 dark:hover:bg-red-900/30 transition-colors",children:[(0,G.jsx)(M.A,{size:12}),"End Chat"]}),(0,G.jsxs)("button",{onClick:()=>{$(null),_(null)},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-700 transition-colors opacity-60 hover:opacity-100 text-[10px] font-bold",children:[(0,G.jsx)(q.A,{size:12}),"Dismiss"]})]})]})}),(null===He||void 0===He||null===(e=He.pageVisits)||void 0===e?void 0:e.length)>0&&(0,G.jsxs)("div",{className:"px-4 py-2 border-b border-gray-200 dark:border-gray-700 bg-gray-50/50 dark:bg-slate-800/20",children:[(0,G.jsxs)("p",{className:"text-[9px] font-black uppercase tracking-widest opacity-40 mb-1.5 flex items-center gap-1",children:[(0,G.jsx)(w.A,{size:10})," Page Journey"]}),(0,G.jsx)("div",{className:"flex items-center gap-1.5 overflow-x-auto pb-1",children:He.pageVisits.map((e,t,s)=>{const a=t===s.length-1,r=(e=>{if(!e||e<0)return"0s";const t=Math.floor(e/1e3),s=Math.floor(t/60);return s>0?"".concat(s,"m ").concat(t%60,"s"):"".concat(t,"s")})((a?He.lastSeen||Date.now():s[t+1].enteredAt)-e.enteredAt);return(0,G.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",children:[t>0&&(0,G.jsx)(B.A,{size:10,className:"opacity-30 shrink-0"}),(0,G.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] ".concat(a?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 font-bold":"bg-gray-200/60 dark:bg-slate-700/60 opacity-70"),children:[(0,G.jsx)("span",{className:"font-medium max-w-[120px] truncate",children:Ge(e.path)}),(0,G.jsxs)("span",{className:"font-mono opacity-60",children:[r,a?" \xb7 now":""]})]})]},"".concat(e.path,"-").concat(e.enteredAt))})})]}),(0,G.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 bg-gray-50 dark:bg-slate-800/30",children:[(null===ze||void 0===ze?void 0:ze.needsHumanAttention)&&!(null!==ze&&void 0!==ze&&ze.humanTakeover)&&(0,G.jsx)("div",{className:"flex justify-center my-2",children:(0,G.jsx)("div",{className:"px-5 py-2.5 rounded-xl bg-red-500/10 border-2 border-red-500/40 text-center animate-pulse shadow-lg shadow-red-500/10",children:(0,G.jsxs)("div",{className:"flex items-center gap-2 text-red-500",children:[(0,G.jsx)(m,{size:14,className:"animate-bounce"}),(0,G.jsx)("span",{className:"text-xs font-black uppercase tracking-widest",children:"Visitor Requested a Live Rep"}),(0,G.jsx)(m,{size:14,className:"animate-bounce"})]})})}),Te&&Te.length>0?Te.map(e=>{const t="rep"===e.sender||"ai"===e.sender,s="system"===e.sender;return(0,G.jsx)("div",{className:"flex ".concat(s?"justify-center":t?"justify-end":"justify-start"),children:(0,G.jsxs)("div",{className:"max-w-[75%] px-4 py-2.5 rounded-2xl ".concat("visitor"===e.sender?"bg-white dark:bg-slate-700 text-gray-900 dark:text-white border border-gray-200 dark:border-gray-600 rounded-bl-sm":"ai"===e.sender?"bg-indigo-100 dark:bg-indigo-900/50 text-indigo-900 dark:text-indigo-100 border border-indigo-200 dark:border-indigo-700 rounded-br-sm":"system"===e.sender?"bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300 text-xs italic rounded-lg mx-auto text-center":"bg-blue-600 text-white rounded-br-sm"),children:["visitor"===e.sender&&(0,G.jsxs)("p",{className:"text-[10px] font-bold mb-1 opacity-60 flex items-center gap-1",children:[(0,G.jsx)(k.A,{size:10}),e.senderName||(null===ze||void 0===ze?void 0:ze.visitorName)||"Visitor"]}),"ai"===e.sender&&(0,G.jsxs)("p",{className:"text-[10px] font-bold mb-1 opacity-60 flex items-center gap-1",children:[(0,G.jsx)(A.A,{size:10}),"AI Bot"]}),"rep"===e.sender&&(0,G.jsxs)("p",{className:"text-[10px] font-bold mb-1 opacity-80 flex items-center gap-1 text-blue-100",children:[(0,G.jsx)(k.A,{size:10}
2),e.senderName||"Support Rep"]}),(0,G.jsx)("p",{className:"text-sm leading-relaxed",children:e.text}),(0,G.jsx)("p",{className:"text-[9px] mt-1 ".concat("rep"===e.sender?"opacity-60 text-blue-200":"opacity-40"),children:Re(e.timestamp)})]})},e.id)}):(0,G.jsx)("div",{className:"flex-1 flex items-center justify-center text-center py-12",children:(0,G.jsxs)("div",{children:[(0,G.jsx)(b.A,{size:32,className:"mx-auto mb-3 opacity-20"}),(0,G.jsx)("p",{className:"text-sm opacity-40",children:"No chat messages yet"}),(0,G.jsx)("p",{className:"text-xs opacity-30 mt-1",children:"Visitor is browsing without starting a chat"})]})}),(0,G.jsx)("div",{ref:he})]}),(null===ze||void 0===ze?void 0:ze.humanTakeover)&&(0,G.jsxs)("div",{className:"px-4 py-2 border-t border-gray-200 dark:border-gray-700 bg-indigo-50 dark:bg-indigo-900/20",children:[(0,G.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,G.jsx)(E.A,{size:12,className:"text-indigo-500"}),(0,G.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-widest text-indigo-600 dark:text-indigo-400",children:"AI Suggested Replies"}),(0,G.jsx)("button",{onClick:Ee,disabled:ne,className:"ml-auto p-1 hover:bg-indigo-100 dark:hover:bg-indigo-800 rounded transition-colors",children:(0,G.jsx)(Z.A,{size:12,className:"text-indigo-500 ".concat(ne?"animate-spin":"")})})]}),(0,G.jsx)("div",{className:"flex flex-wrap gap-2",children:ne?(0,G.jsx)("span",{className:"text-xs opacity-50",children:"Loading suggestions..."}):re.map((e,t)=>(0,G.jsx)("button",{onClick:()=>Ze(e),className:"px-3 py-1.5 text-xs bg-white dark:bg-slate-700 border border-indigo-200 dark:border-indigo-600 rounded-lg hover:bg-indigo-100 dark:hover:bg-indigo-800 transition-colors text-left",children:e},t))})]}),(null===ze||void 0===ze?void 0:ze.humanTakeover)&&(0,G.jsx)("div",{className:"p-3 border-t border-gray-200 dark:border-gray-700 bg-white dark:bg-slate-900",children:(0,G.jsxs)("div",{className:"flex gap-2",children:[(0,G.jsx)("input",{type:"text",placeholder:"Type your message...",value:ee,onChange:e=>te(e.target.value),onKeyPress:e=>"Enter"===e.key&&Ze(),className:"flex-1 px-4 py-2.5 rounded-xl border border-gray-300 dark:border-gray-600 bg-transparent text-sm outline-none focus:border-blue-500"}),(0,G.jsx)("button",{onClick:()=>Ze(),disabled:!ee.trim()||se,className:"p-2.5 bg-blue-600 text-white rounded-xl hover:bg-blue-700 transition-colors disabled:opacity-50",children:se?(0,G.jsx)(I.A,{size:18,className:"animate-spin"}):(0,G.jsx)(H.A,{size:18})})]})}),P&&!(null!==ze&&void 0!==ze&&ze.humanTakeover)&&(null!==ze&&void 0!==ze&&ze.needsHumanAttention?(0,G.jsxs)("div",{className:"p-3 border-t-2 border-red-500 bg-red-50 dark:bg-red-900/30 text-center animate-pulse",children:[(0,G.jsxs)("div",{className:"flex items-center justify-center gap-2 text-red-600 dark:text-red-400",children:[(0,G.jsx)(m,{size:14,className:"animate-bounce"}),(0,G.jsx)("span",{className:"text-xs font-black uppercase tracking-wider",children:"Live Rep Requested"})]}),(0,G.jsx)("p",{className:"text-[10px] text-red-500/70 mt-0.5",children:'Click "Take Over" to respond now'})]}):(0,G.jsxs)("div",{className:"p-3 border-t border-gray-200 dark:border-gray-700 bg-indigo-50 dark:bg-indigo-900/20 text-center",children:[(0,G.jsxs)("div",{className:"flex items-center justify-center gap-2 text-indigo-600 dark:text-indigo-400",children:[(0,G.jsx)(A.A,{size:14}),(0,G.jsx)("span",{className:"text-xs font-medium",children:"AI Bot is handling this conversation"})]}),(0,G.jsx)("p",{className:"text-[10px] opacity-50 mt-0.5",children:'Click "Take Over" to respond directly'})]}))]}):(0,G.jsx)("div",{className:"flex-1 flex items-center justify-center text-center p-8",children:(0,G.jsxs)("div",{children:[(0,G.jsx)(b.A,{size:48,className:"mx-auto mb-4 opacity-20"}),(0,G.jsx)("p",{className:"text-sm opacity-40",children:"Select a visitor or chat to view details"})]})})})]})]}),"tickets"===Q&&(0,G.jsx)(r.default,{})]}):(0,G.jsx)("div",{className:"max-w-lg mx-auto mt-20",children:(0,G.jsxs)("div",{className:"rounded-2xl border border-blue-500/30 bg-blue-500/5 p-8 text-center space-y-6",children:[(0,G.jsx)("div",{className:"w-16 h-16 rounded-full bg-blue-500/20 flex items-center justify-center mx-auto",children:(0,G.jsx)(x.A,{size:32,className:"text-blue-400"})}),(0,G.jsxs)("div",{children:[(0,G.jsx)("h2",{className:"text-xl font-black text-white",children:"Set Your Chat Alias"}),(0,G.jsx)("p",{className:"text-sm text-slate-400 mt-2",children:"Before you can go online and assist customers, you must set a chat alias. This protects your privacy \u2014 customers will only see your alias, never your real name."}),(0,G.jsx)("p",{className:"text-xs text-slate-500 mt-2",children:"We recommend using your first name and last initial (e.g. Sarah W.)"})]}),(0,G.jsxs)("div",{className:"flex items-center justify-center gap-3",children:[(0,G.jsx)("input",{type:"text",value:ue,onChange:e=>me(e.target.value),onKeyDown:async e=>{if("Enter"===e.key&&ue.trim()){ge(!0);try{await(0,R.updateDoc)((0,R.doc)(l.db,"users",t.uid),{chatAlias:ue.trim()}),n&&await n()}finally{ge(!1)}}},placeholder:"e.g. Sarah W.",className:"px-4 py-3 rounded-xl border border-blue-500/30 bg-slate-800 text-white text-sm outline-none focus:border-blue-500 
2w-48"}),(0,G.jsx)("button",{onClick:async()=>{if(ue.trim()){ge(!0);try{await(0,R.updateDoc)((0,R.doc)(l.db,"users",t.uid),{chatAlias:ue.trim()}),n&&await n()}finally{ge(!1)}}},disabled:!ue.trim()||pe,className:"px-6 py-3 rounded-xl bg-blue-600 text-white text-sm font-bold hover:bg-blue-700 disabled:opacity-50 transition-colors",children:pe?"Saving...":"Save & Go Online"})]})]})})}},7899(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("headphones",[["path",{d:"M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 18 0v7a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3",key:"1xhozi"}]])},14939(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]])},20073(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]])},28006(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("map-pin",[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]])},35087(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]])},56217(e,t,s){s.d(t,{L:()=>n});var a=s(37064),r=s(55472);const i=(0,a.Wp)({apiKey:"AIzaSyB7Nu_j6cDdZWU-fw7pqrItXLtuZfjdxTw",authDomain:"havlo-c644c.firebaseapp.com",projectId:"havlo-c644c",storageBucket:"havlo-c644c.firebasestorage.app",messagingSenderId:"333888193262",appId:"1:333888193262:web:b372aef9f65dfadb5569ff"},"havlo"),n=(0,r.getFirestore)(i)},68507(e,t,s){s.d(t,{CZ:()=>b,H3:()=>v,HJ:()=>h,eL:()=>f,h$:()=>j,jJ:()=>g,lA:()=>p,vt:()=>y,wx:()=>d});var a=s(89379),r=s(65043),i=s(91729),n=s(56217),l=s(55472),o=s(52395);const d="workspaces/".concat("Q6qETEYaE9SxhkqTGos7o1f5hqk2","/conversations"),c=new Set(["open","queued","active","waiting"]),x=/no live agents|connect you with a team member|leave your message|\b(human|real person|live (rep|agent|person)|representative|speak to (someone|a person)|talk to (someone|a person))\b/i;function u(e){if(!e)return null;if("function"===typeof e.toDate)return e.toDate().toISOString();const t=new Date(e);return Number.isNaN(t.getTime())?null:t.toISOString()}const m={client:"visitor",bot:"ai",agent:"rep",system:"system"};function p(e,t){return(0,a.A)((0,a.A)({id:e},t),{},{visitorName:t.visitorName||t.visitorEmail||t.visitorId||"Visitor",status:"open"===t.status?"active":"queued"===t.status?"waiting":t.status,isOpen:c.has(t.status),humanTakeover:!!t.assignedAgentId,needsHumanAttention:c.has(t.status)&&!t.assignedAgentId&&x.test(t.lastMessage||""),lastMessageText:t.lastMessage||"",lastMessageIso:u(t.lastMessageAt)||u(t.updatedAt)||u(t.createdAt)})}function g(){const[e,t]=(0,r.useState)([]),[s,a]=(0,r.useState)([]),[i,o]=(0,r.useState)(!0),[c,x]=(0,r.useState)(null);return(0,r.useEffect)(()=>{let e=!0,s=null;const r=setTimeout(()=>{e&&i&&o(!1)},3e3);try{const r=(0,l.rJ)(n.L,d);s=(0,l.aQ)(r,s=>{if(!e)return;const r=s.docs.map(e=>p(e.id,e.data())).sort((e,t)=>(t.lastMessageIso||"").localeCompare(e.lastMessageIso||""));t(r.filter(e=>e.isOpen)),a(r.filter(e=>!e.isOpen)),o(!1),x(null)},s=>
2{e&&("failed-precondition"===s.code||"unavailable"===s.code?(console.warn("Live chats: index not ready or empty collection. Check console for index creation link."),t([])):(console.error("Live chats error:",s),x(s.message)),o(!1))})}catch(c){console.error("Failed to setup live chats listener:",c),o(!1),x(c.message)}return()=>{if(e=!1,clearTimeout(r),s)try{s()}catch(t){}}},[]),{chats:e,closedChats:s,loading:i,activeCount:e.length,error:c}}function h(e){const[t,s]=(0,r.useState)(null),[i,o]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{if(!e)return o(!1),void s(null);let t=!0,r=null;try{const i=(0,l.aQ)((0,l.doc)(n.L,d,e),e=>{if(t){if(e.exists()){const t=p(e.id,e.data());s(e=>(0,a.A)((0,a.A)({},t),{},{messages:(null===e||void 0===e?void 0:e.id)===t.id?e.messages:[]}))}else s(null);o(!1)}},e=>{t&&(console.error("Chat conversation error:",e),o(!1))}),c=(0,l.aQ)((0,l.rJ)(n.L,d,e,"messages"),r=>{if(!t)return;const i=r.docs.map(e=>{return t=e.id,s=e.data(),(0,a.A)((0,a.A)({id:t},s),{},{sender:s.sender||m[s.type]||"visitor",timestamp:u(s.createdAt)});var t,s}).sort((e,t)=>(e.timestamp||"").localeCompare(t.timestamp||""));s(t=>(0,a.A)((0,a.A)({},t||{id:e}),{},{messages:i}))},e=>console.error("Chat messages error:",e));r=()=>{i(),c()}}catch(i){console.error("Failed to setup chat listener:",i),o(!1)}return()=>{if(t=!1,r)try{r()}catch(e){}}},[e]),{chat:t,messages:(null===t||void 0===t?void 0:t.messages)||[],loading:i}}async function b(e,t,s){try{return await(0,l.updateDoc)((0,l.doc)(n.L,d,e),{assignedAgentId:t,assignedAgentName:s,status:"open",lastMessageAt:(0,l.O5)()}),await(0,l.gS)((0,l.rJ)(n.L,d,e,"messages"),{text:"".concat(s," has joined the conversation."),type:"system",senderId:"system",createdAt:(0,l.O5)()}),{success:!0}}catch(a){return console.error("Takeover error:",a),{success:!1,error:a.message}}}async function v(e,t,s,a){try{return await(0,l.gS)((0,l.rJ)(n.L,d,e,"messages"),{text:t,type:"agent",senderId:s,senderName:a,createdAt:(0,l.O5)()}),await(0,l.updateDoc)((0,l.doc)(n.L,d,e),{lastMessageAt:(0,l.O5)()}),{success:!0}}catch(r){return console.error("Send message error:",r),{success:!1,error:r.message}}}async function f(e){try{var t;const s=(0,o.httpsCallable)((0,i.t1)(),"chatSupportAI");return(null===(t=(await s({action:"suggestReplies",messages:e})).data)||void 0===t?void 0:t.suggestions)||[]}catch(s){return console.error("Suggested replies error:",s),["How can I help you further?","Would you like more information about our courses?","I'd be happy to assist with that!"]}}async function y(e){try{return await(0,l.updateDoc)((0,l.doc)(n.L,d,e),{status:"closed",closedAt:(0,l.O5)()}),await(0,l.gS)((0,l.rJ)(n.L,d,e,"messages"),{text:"This conversation has been closed. Thank you for chatting with us!",type:"system",senderId:"system",createdAt:(0,l.O5)()}),{success:!0}}catch(t){return console.error("Close chat error:",t),{success:!1,error:t.message}}}async function j(e){let{repId:t,repName:s,userId:a,userName:r,userEmail:n,initialMessage:o}=e;return(await(0,l.gS)((0,l.rJ)(i.db,"liveChats"),{visitorId:"outbound_".concat(a),visitorName:r,userId:a,userEmail:n,status:"active",origin:"outbound",humanTakeover:!0,assignedTo:t,assignedName:s,aiMessageCount:0,messages:[{id:"rep-".concat(Date.now()),text:o,sender:"rep",senderId:t,senderName:s,timestamp:(new Date).toISOString()}],startedAt:(0,l.O5)(),lastMessageAt:(0,l.O5)()})).id}},76245(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]])},85692(e,t,s){s.d(t,{A:()=>a});const a=(0,s(77784).A)("arrow-right",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]])}}]);
3//# sourceMappingURL=3046.cbd4404a.chunk.js.map

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.