1import{j as e}from"./ui-vendor-BdGJ2N7D.js";import{e as D,r as o}from"./react-vendor-CFTYVGkA.js";import{s as x,N as E,B as I,aP as U,ao as B,bg as Q,bo as z,bh as F,C as n,d as i,a$ as H,a1 as L,a0 as V,a as W,b as P,o as R,k as $}from"./index-B16Fkjed.js";import{T as G,a as J,b as N,c as m,d as K,e as h}from"./table-CeQclnvS.js";import{T as O}from"./triangle-alert-5ePBBunS.js";import{M as u}from"./message-square-DRBOvW_4.js";import"./form-vendor-R7B4_meU.js";const re=()=>{const f=D(),[l,g]=o.useState(null),[a,w]=o.useState([]),[y,p]=o.useState(!0);o.useEffect(()=>{(async()=>{const{data:{user:t}}=await x.auth.getUser();if(!t){g(!1);return}const{data:r}=await x.rpc("has_role",{_user_id:t.id,_role:"admin"});g(!!r)})()},[]),o.useEffect(()=>{l&&A()},[l]);const A=async()=>{p(!0);const{data:s,error:t}=await x.from("vet_chat_sessions").select("*").order("created_at",{ascending:!1});!t&&s&&w(s),p(!1)};if(l===!1)return f("/"),null;const c=a.length,v=a.reduce((s,t)=>s+(Array.isArray(t.messages)?t.messages.length:0),0),T=a.reduce((s,t)=>Array.isArray(t.messages)?s+t.messages.filter(r=>r.role==="user").length:s,0),k=new Set(a.map(s=>s.customer_profile_id)).size,C=c>0?(v/c).toFixed(1):"0",j=new Date,M=new Date(j.getTime()-7*24*60*60*1e3),S=new Date(j.getTime()-30*24*60*60*1e3),_=a.filter(s=>new Date(s.created_at)>=M).length,q=a.filter(s=>new Date(s.created_at)>=S).length,d=new Map;a.forEach(s=>{Array.isArray(s.messages)&&s.messages.filter(t=>t.role==="user").forEach(t=>{const r=(t.content||"").trim().toLowerCase();r.length>5&&d.set(r,(d.get(r)||0)+1)})});const b=Array.from(d.entries()).map(([s,t])=>({question:s,count:t})).sort((s,t)=>t.count-s.count).slice(0,50);return e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsx(E,{}),e.jsxs("main",{className:"flex-grow container mx-auto px-4 py-8 max-w-6xl",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx(I,{variant:"ghost",size:"icon",onClick:()=>f("/admin"),children:e.jsx(U,{className:"h-5 w-5"})}),e.jsx(B,{className:"h-6 w-6 text-primary"}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"AI Vet Assistant Analytics"})]}),e.jsxs(Q,{className:"mb-6 border-destructive/50 bg-destructive/5",children:[e.jsx(O,{className:"h-5 w-5 text-destructive"}),e.jsx(z,{className:"text-destructive font-semibold",children:"Important Medical Disclaimer"}),e.jsx(F,{className:"text-muted-foreground mt-1",children:"If a pet is sick, owners should seek immediate medical attention from a licensed veterinarian. The AI Vet Assistant is designed only for basic questions and is not a substitute for professional veterinary care. It provides preliminary insight to help pet owners before visiting a veterinarian and does not diagnose, treat, or prescribe."})]}),y?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4 mb-8",children:[e.jsx(n,{children:e.jsxs(i,{className:"pt-4 pb-4 text-center",children:[e.jsx(u,{className:"h-5 w-5 mx-auto mb-1 text-primary"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:c}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Sessions"})]})}),e.jsx(n,{children:e.jsxs(i,{className:"pt-4 pb-4 text-center",children:[e.jsx(H,{className:"h-5 w-5 mx-auto mb-1 text-primary"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:T}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Questions Asked"})]})}),e.jsx(n,{children:e.jsxs(i,{className:"pt-4 pb-4 text-center",children:[e.jsx(L,{className:"h-5 w-5 mx-auto mb-1 text-primary"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:k}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Unique Customers"})]})}),e.jsx(n,{children:e.jsxs(i,{className:"pt-4 pb-4 text-center",children:[e.jsx(V,{className:"h-5 w-5 mx-auto mb-1 text-primary"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:C}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Avg Msgs/Session"})]})}),e.jsx(n,{children:e.jsxs(i,{className:"pt-4 pb-4 text-center",children:[e.jsx(u,{className:"h-5 w-5 mx-auto mb-1 text-primary"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:_}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This Week"})]})}),e.jsx(n,{children:e.jsxs(i,{className:"pt-4 pb-4 text-center",children:[e.jsx(u,{className:"h-5 w-5 mx-auto mb-1 text-primary"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:q}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This Month"})]})})]}),e.jsxs(n,{children:[e.jsx(W,{children:e.jsx(P,{className:"text-lg",children:"Most Common Questions"})}),e.jsx(i,{children:b.length===0?e.jsx("p",{className:"text-muted-foreground text-sm py-4 text-center",children:"No questions recorded yet."}):e.jsxs(G,{children:[e.jsx(J,{children:e.jsxs(N,{children:[e.jsx(m,{className:"w-16",children:"#"}),e.jsx(m,{children:"Question"}),e.jsx(m,{className:"w-24 text-right",children:"Times Asked"})]})}),e.jsx(K,{children:b.map((s,t)=>e.jsxs(N,{children:[e.jsx(h,{children:e.jsx(R,{variant:t<3?"default":"secondary",children:t+1})}),e.jsx(h,{className:"capitalize",children:s.question}),e.jsx(h,{className:"text-right font-medium",children:s.count})]},t))})]})})]})]})]}),e.jsx($,{})]})};export{re 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.