1import{r as d,j as e}from"./query-vendor-D9HxUwVw.js";import{N as D,S as I}from"./Navbar-BqJTjusa.js";import{B as l}from"./badge-CfqqaGGs.js";import{C as i,a as m,c as o,b as x,d as g}from"./card-Dr1ffPuS.js";import{I as M}from"./input-CwhkcFhu.js";import{T as R,a as A,b as y,c as f,d as B,e as h}from"./table-2srWrW1w.js";import{j as F,o as U,i as q}from"./main-Beet4ICb.js";import{S as H}from"./star-t1EXA29_.js";import"./button-LbntbU2-.js";import"./supabase-vendor-oIW8hzbJ.js";const $="bg-primary/28 hover:bg-primary/28 shadow-[inset_4px_0_0_hsl(var(--primary))] dark:bg-primary/32 dark:hover:bg-primary/32";function L(t){const c=new Date(t);return Number.isNaN(c.getTime())?t:c.toLocaleString()}function C({title:t,values:c}){const u=Math.max(...c.map(n=>n.count),0);return c.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:t}),e.jsx("div",{className:"space-y-2",children:c.map(n=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:n.label}),e.jsx("span",{children:n.count})]}),e.jsx("div",{className:"h-2 rounded-full bg-muted",children:e.jsx("div",{className:"h-2 rounded-full bg-primary/70",style:{width:`${u>0?n.count/u*100:0}%`}})})]},n.key))})]})}function X(){const{session:t}=F(),[c,u]=d.useState(!0),[n,N]=d.useState(""),[v,T]=d.useState(""),[r,E]=d.useState({feedback:[],summary:{totalFeedback:0,avgRating:0,uniqueSubmitters:0,bySatisfaction:[],byDeploymentMode:[],topInstances:[],topTerms:[]}}),[_,k]=d.useState(null);d.useEffect(()=>{t!=null&&t.access_token&&(u(!0),N(""),U("/api/admin/customer-feedback",{accessToken:t.access_token}).then(s=>{E(s),k(b=>{var S;return b||((S=s.feedback[0])==null?void 0:S.id)||null})}).catch(s=>{N(s instanceof Error?s.message:"Failed to load customer feedback")}).finally(()=>u(!1)))},[t==null?void 0:t.access_token]);const p=d.useDeferredValue(v.trim().toLowerCase()),j=d.useMemo(()=>p?r.feedback.filter(s=>[s.userEmail,s.userName,s.customerName,s.instanceLabel,s.deploymentModeLabel,s.categoryLabel,s.customCategory,s.satisfactionLabel,s.feedback].filter(Boolean).join(" ").toLowerCase().includes(p)):r.feedback,[r.feedback,p]),a=j.find(s=>s.id===_)||j[0]||null;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(D,{}),e.jsxs("main",{className:"container mx-auto space-y-6 px-4 pb-12 pt-24",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight text-foreground",children:"Customer feedback"}),e.jsx("p",{className:"max-w-3xl text-sm text-muted-foreground",children:"Separate from surveys and template feedback. This page captures direct customer reactions to the service and to specific running deployments."})]}),e.jsxs("section",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(i,{children:e.jsxs(m,{className:"pb-2",children:[e.jsx(o,{children:"Total feedback"}),e.jsx(x,{className:"text-3xl",children:r.summary.totalFeedback})]})}),e.jsx(i,{children:e.jsxs(m,{className:"pb-2",children:[e.jsx(o,{children:"Average rating"}),e.jsxs(x,{className:"flex items-center gap-2 text-3xl",children:[e.jsx(H,{className:"h-6 w-6 fill-current text-amber-500"}),r.summary.avgRating||"â"]})]})}),e.jsx(i,{children:e.jsxs(m,{className:"pb-2",children:[e.jsx(o,{children:"Unique submitters"}),e.jsx(x,{className:"text-3xl",children:r.summary.uniqueSubmitters})]})})]}),e.jsxs("section",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.1fr)_minmax(0,0.9fr)]",children:[e.jsxs(i,{children:[e.jsxs(m,{children:[e.jsx(x,{children:"Feedback log"}),e.jsx(o,{children:"Search by customer, deployment, satisfaction, or the written feedback itself."}),e.jsxs("div",{className:"relative max-w-md",children:[e.jsx(I,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(M,{value:v,onChange:s=>T(s.target.value),placeholder:"Search customer feedback",className:"pl-9"})]})]}),e.jsxs(g,{children:[c?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading customer feedbackâ¦"}):null,n?e.jsx("p",{className:"text-sm text-destructive",children:n}):null,!c&&!n?e.jsxs(R,{children:[e.jsx(A,{children:e.jsxs(y,{children:[e.jsx(f,{children:"Customer"}),e.jsx(f,{children:"Deployment"}),e.jsx(f,{children:"Signal"}),e.jsx(f,{children:"Latest"})]})}),e.jsxs(B,{children:[j.length===0?e.jsx(y,{children:e.jsx(h,{colSpan:4,className:"py-8 text-center text-sm text-muted-foreground",children:"No customer feedback yet."})}):null,j.map(s=>e.jsxs(y,{className:q("cursor-pointer",(a==null?void 0:a.id)===s.id&&$),onClick:()=>k(s.id),children:[e.jsx(h,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"font-medium",children:s.customerName||s.userName||"Unknown customer"}),s.userEmail?e.jsx("div",{className:"text-xs text-muted-foreground",children:s.userEmail}):null]})}),e.jsx(h,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsx(l,{variant:"outline",children:s.deploymentModeLabel}),s.categoryLabel?e.jsx(l,{variant:"outline",children:s.categoryLabel}):null,s.instanceLabel?e.jsx("div",{className:"text-xs text-muted-foreground",children:s.instanceLabel}):null]})}),e.jsx(h,{children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs(l,{children:[s.rating,"/5"]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.satisfactionLabel})]})}),e.jsx(h,{className:"text-xs text-muted-foreground",children:L(s.createdAt)})]},s.id))]})]}):null]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(i,{children:[e.jsxs(m,{children:[e.jsx(x,{children:"Signals"}),e.jsx(o,{children:"Structured fields and repeated themes from customer feedback."})]}),e.jsxs(g,{className:"space-y-5",children:[e.jsx(C,{title:"Satisfaction",values:r.summary.bySatisfaction}),e.jsx(C,{title:"Deployment mode",values:r.summary.byDeploymentMode}),r.summary.topInstances.length?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Most-mentioned deployments"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.summary.topInstances.map(s=>e.jsxs(l,{variant:"outline",children:[s.label," · ",s.count]},s.label))})]}):null,r.summary.topTerms.length?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:"Repeated themes"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.summary.topTerms.map(s=>e.jsxs(l,{variant:"secondary",children:[s.term," · ",s.count]},s.term))})]}):null]})]}),e.jsxs(i,{children:[e.jsxs(m,{children:[e.jsx(x,{children:"Selected feedback"}),e.jsx(o,{children:"Keep the raw customer note visible while reviewing the structured signal."})]}),e.jsx(g,{children:a?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(l,{variant:"outline",children:a.deploymentModeLabel}),a.categoryLabel?e.jsx(l,{variant:"outline",children:a.categoryLabel}):null,a.category==="other"&&a.customCategory?e.jsx(l,{variant:"secondary",children:a.customCategory}):null,e.jsx(l,{variant:"outline",children:a.satisfactionLabel}),e.jsxs(l,{children:[a.rating,"/5"]}),a.instanceLabel?e.jsx(l,{variant:"secondary",children:a.instanceLabel}):null]}),e.jsx("div",{className:"text-sm font-medium text-foreground",children:a.customerName||a.userName||a.userEmail||"Unknown customer"}),e.jsx("div",{className:"rounded-md border border-border bg-muted/20 px-3 py-3 text-sm text-foreground",children:a.feedback}),a.attachments.length?e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:a.attachments.map((s,b)=>e.jsx("a",{href:s.dataUrl,target:"_blank",rel:"noreferrer",className:"block overflow-hidden rounded-md border border-border",children:e.jsx("img",{src:s.dataUrl,alt:s.name,className:"h-36 w-full object-cover"})},`${a.id}-attachment-${b}`))}):null,e.jsx("div",{className:"text-xs text-muted-foreground",children:L(a.createdAt)})]}):e.jsx("div",{className:"text-sm text-muted-foreground",children:"Select a feedback entry to inspect it."})})]})]})]})]})]})}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.