1import{X as j,r as b,j as e}from"./index-CFYEvtKP.js";import{u as N}from"./useBrokerAnalyticsSummary-6dpPNF3Q.js";import{u as v}from"./useBrokerClients-C2D8zc0n.js";import{u as y}from"./useBrokerRenewalReport-TDIt32Q-.js";function q(){const{summary:s}=N(!0),{sponsors:t}=j(),{clients:o}=v(),[n,d]=b.useState("");b.useEffect(()=>{var r;!n&&t.length>0&&d(((r=t[0])==null?void 0:r.sponsorId)??"")},[t,n]);const{report:x,loading:g}=y(n||null),a=(s==null?void 0:s.eligibleUsers)??0,i=(s==null?void 0:s.activeUsers)??0,l=o.filter(r=>r.status==="pending").length,p=Math.max(0,a-i),c=a+l,h=a>0?Math.round(i/a*100):0;return e.jsxs("div",{"data-testid":"broker-analytics",children:[e.jsxs("header",{className:"mb-8",children:[e.jsx("h1",{className:"font-serif text-3xl text-foreground",children:"Analytics"}),e.jsx("p",{className:"mt-1 text-foreground-muted",children:"Adoption and sentiment across your whole book of business."})]}),e.jsxs("h2",{className:"mb-4 font-serif text-xl text-foreground",children:["Across your book"," ",e.jsxs("span",{className:"ml-1 text-sm font-normal text-foreground-muted",children:[t.length," sponsors · last 30 days"]})]}),e.jsxs("div",{className:"mb-6 grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(u,{testId:"broker-quant-eligible",label:"Eligible users",value:a,sub:`+${l} pending invites`}),e.jsx(u,{testId:"broker-quant-active",label:"Active users",value:i,sub:"chatted ⥠1 time"}),e.jsx(u,{testId:"broker-quant-sessions",label:"Chat sessions",value:(s==null?void 0:s.sessions)??0,sub:"conversations started"}),e.jsx(u,{testId:"broker-quant-interactions",label:"Total interactions",value:(s==null?void 0:s.interactions)??0,sub:"messages exchanged"})]}),e.jsxs("div",{"data-testid":"broker-analytics-adoption",className:"mb-10 flex flex-col gap-5 rounded-xl border border-border bg-surface p-6 sm:flex-row sm:items-center",children:[e.jsx(k,{percent:h}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium text-foreground",children:"Adoption"}),e.jsx("p",{"data-testid":"broker-analytics-empty",className:"text-sm text-foreground-muted",children:c===0?"No activity yet â invite clients to get started.":`${i} of ${a} eligible users have started at least one chat. ${l} invites still pending.`}),e.jsxs("div",{"data-testid":"broker-adoption-bar",className:"mt-3 flex h-3 overflow-hidden rounded-full bg-surface-muted",children:[e.jsx("span",{className:"bg-success",style:{width:f(i,c)}}),e.jsx("span",{className:"bg-warning",style:{width:f(l,c)}}),e.jsx("span",{className:"bg-foreground-muted/30",style:{width:f(p,c)}})]}),e.jsxs("div",{className:"mt-2 flex gap-4 text-xs text-foreground-muted",children:[e.jsx(m,{color:"bg-success",label:"Active"}),e.jsx(m,{color:"bg-warning",label:"Pending"}),e.jsx(m,{color:"bg-foreground-muted/40",label:"Not started"})]})]})]}),e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("h2",{className:"font-serif text-xl text-foreground",children:["Plan sentiment"," ",e.jsx("span",{className:"ml-1 text-sm font-normal text-foreground-muted",children:"4 indices · lower is better for Confusion & Frustration"})]}),e.jsx("select",{value:n,onChange:r=>d(r.target.value),"aria-label":"Select sponsor",className:"rounded-lg border border-border bg-surface px-3 py-2 text-sm text-foreground",children:t.map(r=>e.jsx("option",{value:r.sponsorId,children:r.sponsorName??"Unnamed sponsor"},r.sponsorId))})]}),g?e.jsx("p",{className:"rounded-xl border border-border bg-surface px-5 py-8 text-center text-sm text-foreground-muted",children:"Loading plan sentimentâ¦"}):!x||x.plans.length===0?e.jsx("p",{"data-testid":"broker-analytics-sentiment-empty",className:"rounded-xl border border-border bg-surface px-5 py-8 text-center text-sm text-foreground-muted",children:"No plans with sentiment for this sponsor yet."}):e.jsx("div",{"data-testid":"broker-analytics-sentiment-cards",className:"space-y-4",children:x.plans.map(r=>e.jsx(I,{plan:r},r.planId))})]})}function u({label:s,value:t,sub:o,testId:n}){return e.jsxs("div",{"data-testid":n,className:"rounded-xl border border-border bg-surface p-5",children:[e.jsx("div",{className:"text-sm text-foreground-muted",children:s}),e.jsx("div",{className:"mt-2 font-serif text-4xl text-foreground",children:t.toLocaleStr
1ing()}),e.jsx("p",{className:"mt-3 text-xs text-foreground-muted",children:o})]})}function k({percent:s}){return e.jsx("div",{className:"flex h-24 w-24 shrink-0 items-center justify-center rounded-full",style:{background:`conic-gradient(rgb(var(--success)) ${s*3.6}deg, rgb(var(--surface-muted)) 0deg)`},role:"img","aria-label":`${s}% adoption`,children:e.jsxs("div",{className:"flex h-[4.5rem] w-[4.5rem] items-center justify-center rounded-full bg-surface font-serif text-xl text-foreground",children:[s,"%"]})})}function m({color:s,label:t}){return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${s}`})," ",t]})}const w=[{key:"happiness",label:"Happiness",better:"higher is better",bar:"bg-success"},{key:"confusion",label:"Confusion",better:"lower is better",bar:"bg-warning"},{key:"frustration",label:"Frustration",better:"lower is better",bar:"bg-destructive"},{key:"engagement",label:"Engagement",better:"higher is better",bar:"bg-primary"}];function I({plan:s}){return e.jsxs("div",{"data-testid":"broker-sentiment-card",className:"rounded-xl border border-border bg-surface p-5",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[e.jsx("div",{className:"font-medium text-foreground",children:s.planName}),s.downTrendFlag&&e.jsx("span",{className:"rounded-full bg-destructive/15 px-2.5 py-1 text-xs text-destructive",children:"â¼ Sentiment sliding"})]}),s.insufficientData||!s.trend?e.jsx("p",{className:"text-sm text-foreground-muted",children:"Not enough chat activity yet to show a sentiment trend for this plan."}):e.jsx("div",{className:"grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-4",children:w.map(t=>e.jsx(A,{label:t.label,better:t.better,bar:t.bar,trend:s.trend[t.key]},t.key))})]})}function A({label:s,better:t,bar:o,trend:n}){const d=Math.round(n.recent);return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-foreground",children:s}),e.jsx($,{trend:n})]}),e.jsxs("div",{className:"font-serif text-2xl text-foreground",children:[d,e.jsx("span",{className:"ml-1 text-xs font-normal text-foreground-muted",children:"/100"})]}),e.jsx("div",{className:"mt-1 h-1.5 overflow-hidden rounded-full bg-surface-muted",children:e.jsx("span",{className:`block h-full ${o}`,style:{width:`${d}%`}})}),e.jsx("p",{className:"mt-1 text-xs text-foreground-muted",children:t})]})}function $({trend:s}){return s.improved?e.jsx("span",{className:"text-success",children:"â²"}):s.declined?e.jsx("span",{className:"text-destructive",children:"â¼"}):e.jsx("span",{className:"text-foreground-muted",children:"â"})}function f(s,t){return t>0?`${s/t*100}%`:"0%"}export{q as BrokerAnalyticsPage,q 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.