1import{u as $,r as v,c,j as e,cF as E,W as K,I as R,V as b,C as d,f as x,g as h,E as u,h as p,d6 as D,D as w,s as g,B as k,i as A,L as Q}from"./index-Dt_fZ0DR.js";import{S as C}from"./skeleton-C9AxFwjo.js";function P(){const[,S]=$(),[t,L]=v.useState(""),[r,j]=v.useState(null),{data:n,isLoading:q}=c({queryKey:["/api/customer/kb/categories"]}),{data:a,isLoading:F}=c({queryKey:["/api/customer/kb/articles"]}),{data:o}=c({queryKey:["/api/customer/kb/articles",{featured:!0}],queryFn:async()=>{const s=await fetch("/api/customer/kb/articles?featured=true");if(!s.ok)throw new Error("Failed to fetch featured articles");return s.json()}}),{data:I,isLoading:f}=c({queryKey:["/api/customer/kb/search",t],enabled:t.length>=3,queryFn:async()=>{const s=await fetch(`/api/customer/kb/search?q=${encodeURIComponent(t)}`);if(!s.ok)throw new Error("Failed to search articles");return s.json()}}),m=t.length>=3?I||[]:r?(a==null?void 0:a.filter(s=>s.categoryId===r))||[]:a||[],N=s=>{S(`/dashboard/kb/${s}`)};return e.jsx(E,{children:e.jsxs("div",{className:"container max-w-6xl mx-auto p-6 space-y-8",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-3xl font-bold","data-testid":"heading-knowledge-base",children:"Help Center"}),e.jsx("p",{className:"text-muted-foreground",children:"Find answers to common questions and learn how to get the most from your service"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(K,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(R,{type:"text",placeholder:"Search for help articles...",value:t,onChange:s=>L(s.target.value),className:"pl-10","data-testid":"input-search"}),t.length>0&&t.length<3&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Type at least 3 characters to search"}),f&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Searching..."})]}),!t&&!r&&o&&o.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{className:"w-5 h-5 text-yellow-500"}),e.jsx("h2",{className:"text-xl font-semibold",children:"Popular Articles"})]}),e.jsx("div",{className:"grid md:grid-cols-2 gap-4",children:o.map(s=>e.jsx(d,{className:"cursor-pointer hover-elevate",onClick:()=>N(s.slug),"data-testid":`featured-article-${s.slug}`,children:e.jsxs(x,{children:[e.jsxs(h,{className:"font-semibold tracking-tight flex items-start justify-between gap-2 text-[14px]",children:[s.title,e.jsx(u,{className:"w-4 h-4 shrink-0 text-muted-foreground"})]}),s.summary&&e.jsx(p,{className:"text-muted-foreground line-clamp-2 text-[12px]",children:s.summary})]})},s.id))})]}),!t&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Browse by Category"}),q?e.jsx("div",{className:"grid md:grid-cols-2 lg:grid-cols-3 gap-4",children:[1,2,3].map(s=>e.jsx(C,{className:"h-32"},s))}):e.jsx("div",{className:"grid md:grid-cols-2 lg:grid-cols-3 gap-4",children:n==null?void 0:n.map(s=>{const l=D[s.icon]||w,i=(a==null?void 0:a.filter(B=>B.categoryId===s.id).length)||0,y=r===s.id;return e.jsx(d,{className:`cursor-pointer transition-all hover-elevate ${y?"ring-2 ring-primary":""}`,onClick:()=>j(y?null:s.id),"data-testid":`category-${s.slug}`,children:e.jsx(x,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"p-3 rounded-md bg-primary/10 shrink-0",children:e.jsx(l,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(h,{className:"font-semibold tracking-tight mb-1 text-[12px]",children:s.title}),s.description&&e.jsx(p,{className:"text-muted-foreground text-[12px]",children:s.description}),e.jsxs(g,{variant:"secondary",className:"mt-2",children:[i," ",i===1?"article":"articles"]})]})]})})},s.id)})})]}),(r||t.length>=3)&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-xl font-semibold",children:t.length>=3?`Search Results (${m.length})`:"Articles in this Category"}),r&&e.jsx(k,{variant:"ghost",size:"sm",onClick:()=>j(null),"data-testid":"button-clear-category",children:"Clear Filter"})]}),F||f?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(s=>e.jsx(C,{className:"h-24"},s))}):m.length===0?e.jsx(d,{children:e.jsxs(A,{className:"py-12 text-center",children:[e.jsx(w,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-lg font-medium mb-2",children:"No articles found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.length>=3?"Try a different search term":"No articles in this category yet"})]})}):e.jsx("div",{className:"space-y-3",children:m.map(s=>{const l=n==null?void 0:n.find(i=>i.id===s.categoryId);return e.jsx(d,{className:"cursor-pointer hover-elevate",onClick:()=>N(s.slug),"data-testid":`article-${s.slug}`,children:e.jsx(x,{children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[l&&e.jsx(g,{variant:"outline",className:"text-xs",children:l.title}),s.isFeatured&&e.jsxs(g,{variant:"secondary",className:"text-xs flex items-center gap-1",children:[e.jsx(b,{className:"w-3 h-3"}),"Popular"]})]}),e.jsx(h,{className:"text-lg mb-1",children:s.title}),s.summary&&e.jsx(p,{className:"line-clamp-2",children:s.summary}),e.jsxs("div",{className:"flex items-center gap-4 mt-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[s.viewCount," views"]}),s.tags&&s.tags.length>
10&&e.jsxs("span",{children:["⢠",s.tags.slice(0,3).join(", ")]})]})]}),e.jsx(u,{className:"w-5 h-5 shrink-0 text-muted-foreground"})]})})},s.id)})})]}),e.jsx("div",{className:"pt-8 border-t",children:e.jsx(Q,{href:"/dashboard/support",children:e.jsxs(k,{variant:"outline","data-testid":"button-back-to-support",children:[e.jsx(u,{className:"w-4 h-4 mr-2 rotate-180"}),"Back to Support"]})})})]})})}export{P 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.