1import{r as n,j as e}from"./index-DKJ0tKwF.js";import{J as m,U as j,G as N,l as v,h as _,n as w}from"./button-DFML8rOM.js";import{aE as y,jz as M,a8 as f,jr as p,b2 as S,gc as C}from"./App-CL-mfmhu.js";import{M as E}from"./drawer-DvmpTcdR.js";import{M as k}from"./MobileSectionHeader-CrLoEHm1.js";import{M as z}from"./MobileSheet-CMSXqRkP.js";import{M as V}from"./MobileEmptyState-CT6svArk.js";import{M as B}from"./MobileHeroHeader-C4IRj_Bm.js";import{M as x}from"./MobileBrandStat-BZCQ4DhC.js";import{r as D}from"./v3LegalOverrides-BUgTGJPl.js";import"./V2Layout-DEbe2yZA.js";import"./tracker-DzJH7QDt.js";import"./mouse-pointer-2-CzsmklB8.js";import"./index-BNGwt955.js";import"./SEOHead-B5IBZJEm.js";import"./types-DU7944Yl.js";function R(s){return s==="mobile"?w:s==="tablet"?C:D}function X(){var h;const{workspace:s}=y(),[i,g]=n.useState([]),[b,l]=n.useState(!0),[r,u]=n.useState(null),d=async()=>{if(!(s!=null&&s.id)){l(!1);return}l(!0);const t=new Date(Date.now()-10*60*1e3).toISOString(),{data:o}=await m.from("chatbot_visitor_sessions").select("*, chatbot:chatbots(name)").eq("workspace_id",s.id).gte("last_seen_at",t).order("last_seen_at",{ascending:!1}).limit(100);g(o??[]),l(!1)};n.useEffect(()=>{d()},[s==null?void 0:s.id]),n.useEffect(()=>{if(!(s!=null&&s.id))return;const t=m.channel(`mobile-chatbot-visitors-${s.id}`).on("postgres_changes",{event:"*",schema:"public",table:"chatbot_visitor_sessions",filter:`workspace_id=eq.${s.id}`},()=>d()).subscribe();return()=>{m.removeChannel(t)}},[s==null?void 0:s.id]);const c=n.useMemo(()=>{const t=i.filter(a=>a.is_browsing).length,o=new Set(i.map(a=>a.country).filter(Boolean)).size;return{total:i.length,browsing:t,countries:o}},[i]);return b?e.jsx(M,{}):e.jsxs(E,{padded:!1,children:[e.jsx(B,{eyebrow:"Live now",title:"Chatbot Visitors",subtitle:"Visitors active in the last 10 minutes",trailing:e.jsx("button",{onClick:()=>{p("tap"),d()},className:"w-9 h-9 rounded-full bg-white/10 text-white flex items-center justify-center active:scale-90 transition-transform","aria-label":"Refresh",children:e.jsx(v,{className:"w-4 h-4"})}),children:e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(x,{size:"sm",label:"Online",value:c.total,icon:e.jsx(j,{className:"w-3.5 h-3.5"})}),e.jsx(x,{size:"sm",label:"Browsing",value:c.browsing,icon:e.jsx(f,{className:"w-3.5 h-3.5"})}),e.jsx(x,{size:"sm",label:"Countries",value:c.countries,icon:e.jsx(N,{className:"w-3.5 h-3.5"})})]})}),e.jsx("div",{className:"px-4 pt-3",children:i.length===0?e.jsx(V,{icon:e.jsx(f,{className:"w-7 h-7"}),title:"No live visitors",description:"When people land on your chatbot, you'll see them here in real-time."}):e.jsxs(e.Fragment,{children:[e.jsxs(k,{children:[i.length," visitor",i.length===1?"":"s"]}),e.jsx("div",{className:"space-y-2",children:i.map(t=>{var a;const o=R(t.device_type);return e.jsx("button",{onClick:()=>{p("tap"),u(t)},className:"w-full text-left rounded-2xl bg-card/60 border border-border/40 p-3.5 active:bg-muted/40 active:scale-[0.99] transition-all",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0 ${t.is_browsing?"bg-emerald-500/15 text-emerald-500":"bg-muted text-muted-foreground"}`,children:e.jsx(o,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${t.is_browsing?"bg-emerald-500 animate-pulse":"bg-muted-foreground/40"}`}),e.jsx("span",{className:"text-[14px] font-medium text-foreground",children:t.city??t.country??"Unknown location"})]}),e.jsx("div",{className:"text-[12px] text-muted-foreground truncate mt-0.5",children:t.current_page_title??t.current_page_url??"â"}),e.jsxs("div",{className:"text-[11px] text-muted-foreground/70 mt-1",children:[S(t.last_seen_at,{addSuffix:!0})," · ",((a=t.chatbot)==null?void 0:a.name)??"Chatbot"]})]})]})},t.id)})})]})}),e.jsx("div",{className:"h-12"}),e.jsx(z,{open:!!r,onOpenChange:t=>!t&&u(null),title:(r==null?void 0:r.city)??(r==null?void 0:r.country)??"Visitor",children:r&&e.jsxs("div",{className:"space-y-3 text-[14px]",children:[e.jsxs("div",{className:"rounded-xl bg-muted/40 p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-[12px]",children:[e.jsx(_,{className:"w-3.5 h-3.5"})," Location"]}),e.jsx("div",{className:"text-foreground",children:[r.city,r.country].filter(
1Boolean).join(", ")||"Unknown"})]}),e.jsxs("div",{className:"rounded-xl bg-muted/40 p-3 space-y-1.5",children:[e.jsx("div",{className:"text-muted-foreground text-[12px]",children:"Current page"}),e.jsx("div",{className:"text-foreground break-words",children:r.current_page_title??"â"}),r.current_page_url&&e.jsx("div",{className:"text-muted-foreground text-[12px] break-all",children:r.current_page_url})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded-xl bg-muted/40 p-3",children:[e.jsx("div",{className:"text-muted-foreground text-[12px]",children:"Total visits"}),e.jsx("div",{className:"text-foreground font-semibold mt-0.5",children:r.total_visits??1})]}),e.jsxs("div",{className:"rounded-xl bg-muted/40 p-3",children:[e.jsx("div",{className:"text-muted-foreground text-[12px]",children:"Pages viewed"}),e.jsx("div",{className:"text-foreground font-semibold mt-0.5",children:((h=r.pages_viewed)==null?void 0:h.length)??0})]})]}),r.referrer&&e.jsxs("div",{className:"rounded-xl bg-muted/40 p-3",children:[e.jsx("div",{className:"text-muted-foreground text-[12px]",children:"Referrer"}),e.jsx("div",{className:"text-foreground break-all text-[13px] mt-0.5",children:r.referrer})]})]})})]})}export{X 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.