1import{r as a,j as e,u as p}from"./index-DKJ0tKwF.js";import{r as q,J as v}from"./button-DFML8rOM.js";import{aE as B,jz as F,a5 as M,b2 as E,jr as T}from"./App-CL-mfmhu.js";import{M as z}from"./drawer-DvmpTcdR.js";import{M as A}from"./MobileSearchBar-BXL5g0Np.js";import{M as O}from"./MobileSegmented-Ds0FCyOJ.js";import{M as D}from"./MobileSectionHeader-CrLoEHm1.js";import{M as G}from"./MobileSheet-CMSXqRkP.js";import{M as H}from"./MobileEmptyState-CT6svArk.js";import{M as K}from"./MobileHeroHeader-C4IRj_Bm.js";import{M as N}from"./MobileBrandStat-BZCQ4DhC.js";import{B as L}from"./V2Layout-DEbe2yZA.js";import{T as I}from"./v3LegalOverrides-BUgTGJPl.js";import"./tracker-DzJH7QDt.js";import"./mouse-pointer-2-CzsmklB8.js";import"./index-BNGwt955.js";import"./SEOHead-B5IBZJEm.js";import"./types-DU7944Yl.js";function le(){const{workspace:o}=B(),[i,x]=a.useState([]),[y,f]=a.useState(!0),[h,k]=a.useState(""),[l,S]=a.useState("open"),[r,n]=a.useState(null),[b,d]=a.useState(!1),C=async()=>{if(!(o!=null&&o.id)){f(!1);return}f(!0);const{data:s,error:t}=await v.from("chatbot_knowledge_gaps").select("*").eq("workspace_id",o.id).order("created_at",{ascending:!1}).limit(300);x(t?[]:s??[]),f(!1)};a.useEffect(()=>{C()},[o==null?void 0:o.id]);const c=a.useMemo(()=>({total:i.length,open:i.filter(s=>s.status==="open"||!s.status).length,addressed:i.filter(s=>s.status==="addressed").length}),[i]),m=a.useMemo(()=>{const s=h.trim().toLowerCase();return i.filter(t=>l!=="all"&&(t.status||"open")!==l?!1:s?t.user_question.toLowerCase().includes(s):!0)},[i,l,h]),w=async(s,t)=>{d(!0);const{error:u}=await v.from("chatbot_knowledge_gaps").update({status:t}).eq("id",s);d(!1),u?p.error("Failed to update"):(p.success(t==="addressed"?"Marked as addressed":"Updated"),x(g=>g.map(j=>j.id===s?{...j,status:t}:j)),n(null))},_=async s=>{d(!0);const{error:t}=await v.from("chatbot_knowledge_gaps").delete().eq("id",s);d(!1),t?p.error("Failed to delete"):(p.success("Deleted"),x(u=>u.filter(g=>g.id!==s)),n(null))};return y?e.jsx(F,{}):e.jsxs(z,{padded:!1,children:[e.jsx(K,{eyebrow:"Bot training",title:"Knowledge Gaps",subtitle:"Questions your bot couldn't answer",children:e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(N,{size:"sm",label:"Total",value:c.total,icon:e.jsx(q,{className:"w-3.5 h-3.5"})}),e.jsx(N,{size:"sm",label:"Open",value:c.open,icon:e.jsx(L,{className:"w-3.5 h-3.5"})}),e.jsx(N,{size:"sm",label:"Fixed",value:c.addressed,icon:e.jsx(M,{className:"w-3.5 h-3.5"})})]})}),e.jsxs("div",{className:"px-4 pt-3 space-y-3",children:[e.jsx(A,{value:h,onChange:k,sticky:!1,placeholder:"Search questionsâ¦"}),e.jsx(O,{value:l,onChange:S,options:[{value:"open",label:"Open",badge:c.open},{value:"addressed",label:"Fixed"},{value:"ignored",label:"Ignored"},{value:"all",label:"All"}]})]}),e.jsx("div",{className:"px-4 pt-3",children:m.length===0?e.jsx(H,{icon:e.jsx(M,{className:"w-7 h-7"}),title:"No gaps to address",description:"Your chatbot is answering everything visitors ask."}):e.jsxs(e.Fragment,{children:[e.jsxs(D,{children:[m.length," question",m.length===1?"":"s"]}),e.jsx("div",{className:"space-y-2",children:m.map(s=>e.jsxs("button",{onClick:()=>{T("tap"),n(s)},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.jsx("div",{className:"text-[14px] font-medium text-foreground line-clamp-3",children:s.user_question}),e.jsxs("div",{className:"flex items-center gap-2 mt-2 text-[11px] text-muted-foreground",children:[typeof s.confidence=="number"&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded-md bg-amber-500/15 text-amber-500",children:[Math.round(s.confidence*100),"% confidence"]}),e.jsx("span",{children:E(s.created_at,{addSuffix:!0})})]})]},s.id))})]})}),e.jsx("div",{className:"h-12"}),e.jsx(G,{open:!!r,onOpenChange:s=>!s&&n(null),title:"Knowledge gap",children:r&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-muted/40 p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Visitor asked"}),e.jsx("div",{className:"text-[15px] text-foreground mt-1.5 whitespace-pre-wrap",children:r.user_question})]}),typeof r.confidence=="number"&&e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:["Bot confidence: ",e.jsxs("span",{className:"text-amber-500 font-medium",children:[Math.round(r.confidence*100),"%"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{disabled:b,onClick:()=>w(r.id,"addressed"),className:"h-11 rounded-xl bg-emerald-500/15 text-emerald-500 font-semibold text-[14px] active:scale-95 transition-transform disabled:opacity-50",children:"Mark fixed"}),e.jsx("button",{disabled:b,onClick:()=>w(r.id,"ignored"),className:"h-11 rounded-xl bg-muted text-foreground font-semibold text-[14px] active:scale-95 transition-transform disabled:opacity-50",children:"Ignore"})]}),e.jsxs("button",{disabled:b,onClick:()=>_(r.id),className:"w-full h-11 rounded-xl bg-rose-500/10 text-rose-500 font-semibold text-[14px] flex items-center justify-center gap-2 active:scale-95 transition-transform disabled:opacity-50",children:[e.jsx(I,{className:"w-4 h-4"})," Delete gap"]})]})})]})}export{le 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.