PageSourceSearch

https://quotexinsurance.com/assets/AnalyticsPage-BIBL9Q0t.js

js quotexinsurance.com collected 2026-09-24 14:51:09 UTC 79,181 bytes, 21 lines download raw bytes

1import{r as y,u as ze,d as $e,j as e,L as Ae}from"./index-CU9pv9kH.js";import{E as Ve,C as E,a as G,S as T}from"./Card-BzpsXsdE.js";import{c as Ie,C as _e,T as de,g as te,a as ge,b as fe,d as ve,P as Ke,p as me,G as oe,i as ce}from"./performanceGoals-sxH7Cv0n.js";import{B as q}from"./Badge-s9iX0649.js";import{M as je}from"./Modal-C6kFkAbC.js";import{E as Xe}from"./EmployeeBackButton-DrH7Mo2r.js";import{A as Ye}from"./AiCustomFilterChip-TtsCynAC.js";import{d as Qe,D as Ze}from"./DocumentViewerModal-DhQe74A9.js";import{R as Je,P as Me,C as pe,E as Y,a as se,D as ne}from"./MetricLists-Cjj3W5Ta.js";import{a as et,u as Be,j as tt,e as h,k as j}from"./ApplicationRoot-D4scxSx1.js";import{C as ue}from"./chart-column-DgE4L3TC.js";import{U as J}from"./users-DxU3LW1g.js";import{S as ke}from"./shield-check-D3tb1wLl.js";import{T as ye}from"./trending-up-DnOVKuBi.js";import{c as xe}from"./createLucideIcon-IZvJT3Oh.js";import{S as ee}from"./sparkles-y0wkYNFy.js";import{C as V}from"./circle-check-qSrjwebh.js";import{A as st}from"./arrow-left-B0QZoWyb.js";import{C as nt}from"./clock-CVZZ9FTa.js";import{P as lt}from"./plus-DyEPwt-R.js";import{C as Oe}from"./chevron-up-C9WwYN1L.js";import{C as Ue}from"./chevron-down-Bt45DgM_.js";import{C as we}from"./circle-x-SdNQ2nSR.js";import{T as Te}from"./trophy-mT79tc3p.js";import{A as Se}from"./archive-BfSN1Byw.js";import{P as it}from"./pencil-CV7ycgge.js";import{T as at}from"./trash-2-B6s-XdFu.js";import{D as rt}from"./download-DetgfXnG.js";import"./aiCustomFilters-D7rmd0oC.js";import"./documentUrls-Cn1xQvsu.js";import"./file-image-ClpwilzM.js";import"./save-CRDfMfIA.js";import"./MapLink-5IWQoa0g.js";import"./map-pin-CqcGKtCU.js";import"./external-link-CAml7HFm.js";/**
2 * @license lucide-react v0.460.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Ee=xe("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);/**
7 * @license lucide-react v0.460.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const ot=xe("Medal",[["path",{d:"M7.21 15 2.66 7.14a2 2 0 0 1 .13-2.2L4.4 2.8A2 2 0 0 1 6 2h12a2 2 0 0 1 1.6.8l1.6 2.14a2 2 0 0 1 .14 2.2L16.79 15",key:"143lza"}],["path",{d:"M11 12 5.12 2.2",key:"qhuxz6"}],["path",{d:"m13 12 5.88-9.8",key:"hbye0f"}],["path",{d:"M8 7h8",key:"i86dvs"}],["circle",{cx:"12",cy:"17",r:"5",key:"qbz8iq"}],["path",{d:"M12 18v-2h-.5",key:"fawc4q"}]]);/**
12 * @license lucide-react v0.460.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const Ge=xe("Timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);/**
17 * @license lucide-react v0.460.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const Fe=xe("UserCheck",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["polyline",{points:"16 11 18 13 22 9",key:"1pwet4"}]]);function gs(){const{agency:l}=et(),{user:t}=Be(),[,n]=y.useState(0),s=()=>n(p=>p+1);y.useEffect(()=>tt(s),[]);const i=ze();y.useEffect(()=>{if(i.hash!=="#performance-goals")return;const p=window.setTimeout(()=>{var k;(k=document.getElementById("performance-goals"))==null||k.scrollIntoView({behavior:"smooth",block:"start"})},120);return()=>window.clearTimeout(p)},[i.hash]);const[r,x]=$e(),c=r.get("agent"),o=p=>{const k=new URLSearchParams(r);p?k.set("agent",p):k.delete("agent"),x(k)};if(!l||!t)return null;if(t.role==="agent")return e.jsx(gt,{agency:l,user:t});if(t.role!=="manager")return e.jsx(Ve,{title:"Analytics is for agency staff",description:"Sign in as an agent or manager to view agency analytics.",icon:e.jsx(ue,{className:"h-8 w-8"})});const u=h.users.list(l.id).filter(p=>p.role==="agent"||p.role==="manager"),m=c?u.find(p=>p.id===c):void 0;return m?e.jsx(Pt,{agent:m,agencyId:l.id,onBack:()=>o(null)}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(Xe,{}),e.jsxs("div",{className:"flex items-end justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-3xl",children:"Analytics"}),e.jsx("p",{className:"text-ink-500 text-sm mt-1",children:"Team performance at a glance. Click an agent for the full per-metric drill-down."})]}),e.jsxs("div",{className:"text-xs text-ink-400",children:[u.length," agent",u.length===1?"":"s"," on the team"]})]}),e.jsx(Tt,{agencyId:l.id}),e.jsx(ct,{agencyId:l.id}),e.jsx(mt,{agencyId:l.id}),e.jsx(ut,{agencyId:l.id}),e.jsx(wt,{agencyId:l.id,onOpenAgent:o}),e.jsxs(E,{children:[e.jsx(G,{title:"Team",subtitle:"Click an agent to open the full drill-down."}),e.jsx("div",{className:"grid sm:grid-cols-2 lg:grid-cols-3 gap-4",children:u.map(p=>e.jsx(St,{agencyId:l.id,agent:p,onOpen:()=>o(p.id)},p.id))})]})]})}function ct({agencyId:l}){const[t,n]=y.useState("1y"),s=y.useMemo(()=>dt(l,t),[l,t]);return e.jsxs(E,{children:[e.jsx(G,{title:"Retention",subtitle:"Clients and policies that stuck around vs the cohort active at the start of the peri
21od.",action:e.jsx("div",{className:"flex items-center gap-1 text-xs",children:["30d","90d","1y","2y"].map(i=>e.jsx("button",{type:"button",onClick:()=>n(i),className:`px-2.5 py-1 rounded ${t===i?"bg-ink-900 text-white":"bg-white border border-ink-200 text-ink-600 hover:bg-ink-50"}`,children:i==="30d"?"30 days":i==="90d"?"90 days":i==="1y"?"1 year":"2 years"},i))})}),e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(le,{label:"Client retention",rate:s.client.rate,retained:s.client.retained,cohort:s.client.cohort}),e.jsx(le,{label:"Policy retention",rate:s.policy.rate,retained:s.policy.retained,cohort:s.policy.cohort}),e.jsx(le,{label:"Personal lines retention",rate:s.personal.rate,retained:s.personal.retained,cohort:s.personal.cohort}),e.jsx(le,{label:"Commercial lines retention",rate:s.commercial.rate,retained:s.commercial.retained,cohort:s.commercial.cohort})]})]})}function le({label:l,rate:t,retained:n,cohort:s}){return e.jsxs("div",{className:"rounded-md border border-ink-100 bg-white px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-ink-500",children:l}),e.jsx("div",{className:"mt-1 text-2xl font-semibold tabular-nums",children:t==null?"—":`${Math.round(t*100)}%`}),e.jsxs("div",{className:"text-[11px] text-ink-500 mt-0.5",children:[n,"/",s," ","retained"," from cohort"]})]})}function dt(l,t){const i=Date.now()-(t==="30d"?30:t==="90d"?90:t==="1y"?365:730)*24*60*60*1e3,r=h.customers.list(l),x=h.policies.listByTenant(l);function c(C,a){return a===0?null:C/a}const o=r.filter(C=>new Date(C.createdAt).getTime()<i),u=o.filter(C=>!C.archived||C.archivedAt&&new Date(C.archivedAt).getTime()<i?!C.archived:!1),m=x.filter(C=>new Date(C.createdAt).getTime()<i),p=m.filter(C=>C.status==="bound"||C.status==="renewed");function k(C){const a=m.filter(w=>(w.department??"personal")===C),b=a.filter(w=>w.status==="bound"||w.status==="renewed");return{cohort:a.length,retained:b.length,rate:c(b.length,a.length)}}return{client:{cohort:o.length,retained:u.length,rate:c(u.length,o.length)},policy:{cohort:m.length,retained:p.length,rate:c(p.length,m.length)},personal:k("personal"),commercial:k("commercial")}}function mt({agencyId:l}){const[t,n]=y.useState("30d"),s=y.useMemo(()=>Mt(l,t),[l,t]);return e.jsxs(E,{children:[e.jsx(G,{title:"Agency performance trends",subtitle:"Activity, outreach, and book-growth over time.",action:e.jsx("div",{className:"flex items-center gap-1 text-xs",children:["7d","30d","90d","1y"].map(i=>e.jsx("button",{type:"button",onClick:()=>n(i),className:`px-2.5 py-1 rounded ${t===i?"bg-ink-900 text-white":"bg-white border border-ink-200 text-ink-600 hover:bg-ink-50"}`,children:i==="7d"?"7 days":i==="30d"?"30 days":i==="90d"?"90 days":"1 year"},i))})}),e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-5",children:[e.jsx(ae,{label:"Activities resolved",value:s.totals.resolved}),e.jsx(ae,{label:"Inbound requests",value:s.totals.inbound}),e.jsx(ae,{label:"Outbound messages",value:s.totals.outbound}),e.jsx(ae,{label:"New customers",value:s.totals.newCustomers,hint:`Premium written ${j.money(s.totals.premiumWritten)}`})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-5",children:[e.jsx(re,{title:"Activities resolved",buckets:s.buckets,valueKey:"resolved",tone:"emerald"}),e.jsx(re,{title:"Inbound customer requests",buckets:s.buckets,valueKey:"inbound",tone:"indigo"}),e.jsx(re,{title:"Outbound messages",buckets:s.buckets,valueKey:"outbound",tone:"gold"}),e.jsx(re,{title:"New customers",buckets:s.buckets,valueKey:"newCustomers",tone:"violet"})]})]})}function ut({agencyId:l}){const{user:t}=Be(),[,n]=y.useState(0),[s,i]=y.useState(!1),[r,x]=y.useState(null),[c,o]=y.useState(!1),[u]=$e(),m=u.get("celebrate"),p=u.get("request"),k=h.agencies.get(l),C=Ie(k==null?void 0:k.performanceGoals),a=((k==null?void 0:k.performanceGoalRequests)??[]).filter(N=>N.status==="pending"),b=(k==null?void 0:k.performanceGoalHistory)??[],w=()=>n(N=>N+1),A=C.filter(N=>N.scope==="company"),M=C.filter(N=>N.scope==="personal"),R=b.filter(N=>N.met),d=b.filter(N=>!N.met),L=R.filter(N=>N.scope==="company"),B=R.filter(N=>N.scope==="personal"),D=d.filter(N=>N.scope==="company"),$=d.filter(N=>N.scope==="personal"),S=r?C.find(N=>N.id===r):void 0,v=!!m&&C.some(N=>N.id===m);function P(){x(null),i(!0)}return e.jsxs(E,{id:"performance-goals",children:[v&&e.jsx(_e,{}),e.jsx(G,{title:"Performance goals",subtitle:"Company-wide and personal targets vs. today's actuals. Company goals track the whole agency; personal goals track the assigned staff member(s).",action:e.jsxs("button",{type:"button",className:"btn-gold text-xs",onClick:P,children:[e.jsx(lt,{className:"h-3.5 w-3.5"})," Set a goal"]})}),a.length>0&&e.jsx(xt,{agencyId:l,requests:a,highlightedRequestId:p,reviewerId:t==null?void 0:t.id,onChanged:w}),C.length===0?e.jsxs("div",{className:"rounded-md border border-dashed border-ink-200 p-6 text-center",children:[e.jsx(de,{className:"h-8 w-8 mx-auto text-ink-300"}),e.jsx("div",{className:"mt-3 text-sm text-ink-700 font-medium",children:"No goals set yet."}),e.jsxs("div",{className:"mt-1 text-xs text-ink-500",children:["Click ",e.jsx("span",{className:"font-medium",children:"Set a goal"})," to add a company-wide or personal target."]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ht,{agencyId:l,goals:C}),A.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-5 text-[11px] uppercase tracking-wider text-ink-500 font-semibold",children:"Company goals"}),e.jsx("ul",{className:"mt-2 space-y-3",children:A.map(N=>e.jsx(Pe,{agencyId:l,goal:N,celebrated:N.id===m,onEdit:()=>{x(N.id),i(!0)},onChanged:w},N.id))})]}),M.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-5 text-[11px] uppercase tracking-wider text-ink-500 font-semibold",children:"Personal goals"}),e.jsx("ul",{className:"mt-2 space-y-3",children:M.map(N=>e.jsx(Pe,{agencyId:l,goal:N,celebrated:N.id===m,onEdit:()=>{x(N.id),i(!0)},onChanged:w},N.id))})]})]}),b.length>0&&e.jsxs("div",{className:"mt-5 pt-4 border-t border-ink-100",children:[e.jsxs("button",{type:"button",onClick:()=>o(N=>!N),className:"w-full flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-[11px] uppercase tracking-wider text-ink-500 font-semibold",children:["Previous targets · ",b.length]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-ink-500",children:[c?"Hide":"Show",c?e.jsx(Oe,{className:"h-3.5 w-3.5"}):e.jsx(Ue,{className:"h-3.5 w-3.5"})]})]}),c&&e.jsxs("div",{className:"mt-3 space-y-4",children:[e.jsxs("div",{className:"rounded-md border border-emerald-200 bg-emerald-50/40 p-3",children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-wider font-bold text-emerald-700 inline-flex items-center gap-1 mb-2",children:[e.jsx(V,{className:"h-3.5 w-3.5"})," Targets achieved · ",R.length]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsx(ie,{title:"Company",tone:"met",rows:L,agencyId:l}),e.jsx(ie,{title:"Personal",tone:"met",rows:B,agencyId:l})]})]}),e.jsxs("div",{className:"rounded-md border border-rose-200 bg-rose-50/40 p-3",children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-wider font-bold text-rose-700 inline-flex items-center gap-1 mb-2",children:[e.jsx(we,{className:"h-3.5 w-3.5"})," Targets not achieved · ",d.length]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsx(ie,{title:"Company",tone:"missed",rows:D,agencyId:l}),e.jsx(ie,{title:"Personal",tone:"missed",rows:$,agencyId:l})]})]})]})]}),e.jsx(bt,{open:s,agencyId:l,existing:S,onClose:()=>{i(!1),x(null),w()}})]})}function xt({agencyId:l,requests:t,highlightedRequestId:n,reviewerId:s,onChanged:i}){return e.jsxs("div",{className:"mb-5 rounded-lg border border-gold-200 bg-gold-50/35 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider font-bold text-gold-800",children:"Requested goals"}),e.jsx("div",{className:"text-xs text-ink-500 mt-0.5",children:"Agent-submitted requests waiting for manager review."})]}),e.jsxs(q,{tone:"gold",children:[t.length," pending"]})]}),e.jsx("ul",{className:"mt-3 space-y-2",children:t.map(r=>e.jsx(pt,{agencyId:l,request:r,highlighted:r.id===n,reviewerId:s,onChanged:i},r.id))})]})}function pt({agencyId:l,request:t,highlighted:n,reviewerId:s,onChanged:i}){const r=h.users.get(t.requestedById),x=te(t),c=x.format==="money"?j.money(t.target):t.target.toLocaleStr
21ing(),o=s??"manager";return e.jsx("li",{className:`rounded-md border bg-white p-3 ${n?"border-gold-500 ring-2 ring-gold-200":"border-ink-100"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-semibold text-ink-900",children:[x.label,e.jsx("span",{className:"ml-2 rounded bg-ink-100 px-1.5 py-0.5 text-[9px] uppercase tracking-wider font-semibold text-ink-600",children:t.scope==="company"?"Company-wide":(r==null?void 0:r.name)??"Personal"})]}),e.jsxs("div",{className:"mt-1 text-xs text-ink-500",children:["Requested by ",(r==null?void 0:r.name)??"Unknown staff"," · ",c," this"," ",me(t.period)," · ",j.dateTime(t.createdAt),t.dueDate&&e.jsxs(e.Fragment,{children:[" · due ",j.date(t.dueDate)]})]}),t.note&&e.jsx("div",{className:"mt-2 rounded-md bg-ink-50 px-3 py-2 text-xs text-ink-600",children:t.note})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("button",{type:"button",className:"btn-primary text-xs",onClick:()=>{h.agencies.approvePerformanceGoalRequest(l,t.id,o),i()},children:[e.jsx(V,{className:"h-3.5 w-3.5"})," Approve"]}),e.jsxs("button",{type:"button",className:"btn-outline text-xs text-rose-600",onClick:()=>{h.agencies.rejectPerformanceGoalRequest(l,t.id,o),i()},children:[e.jsx(we,{className:"h-3.5 w-3.5"})," Reject"]})]})]})})}function Pe({agencyId:l,goal:t,celebrated:n,onEdit:s,onChanged:i}){const r=te(t),x=ge(l,t),c=fe(x,t.target),o=t.target>0&&x>=t.target,u=c>=100?"emerald":c>=75?"gold":c>=40?"amber":"rose",m=a=>r.format==="money"?j.money(a):a.toLocaleString(),p=t.dueDate!=null&&new Date(t.dueDate).getTime()<Date.now(),k=u==="emerald"?"text-emerald-700":u==="gold"?"text-gold-700":u==="amber"?"text-amber-700":"text-rose-700",C=u==="emerald"?"bg-emerald-500":u==="gold"?"bg-gold-500":u==="amber"?"bg-amber-500":"bg-rose-500";return e.jsxs("li",{className:`rounded-md border p-3 ${o?"border-emerald-300 bg-emerald-50/50":"border-ink-100 bg-white"} ${n?"ring-2 ring-emerald-300":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-semibold inline-flex items-center gap-1.5",children:[e.jsx(Ee,{className:"h-3.5 w-3.5 text-gold-700"}),r.label,e.jsx("span",{className:"ml-1 rounded bg-ink-100 px-1.5 py-0.5 text-[9px] uppercase tracking-wider font-semibold text-ink-600",children:ve(l,t)}),o&&e.jsxs("span",{className:"rounded bg-emerald-100 px-1.5 py-0.5 text-[9px] uppercase tracking-wider font-bold text-emerald-700 inline-flex items-center gap-1",children:[e.jsx(Ke,{className:"h-3 w-3"})," Goal achieved"]})]}),e.jsxs("div",{className:"text-[11px] text-ink-500 mt-0.5",children:[m(x)," of ",m(t.target)," this ",me(t.period),t.dueDate&&e.jsxs(e.Fragment,{children:[" · ",e.jsxs("span",{className:p?"text-rose-600 font-medium":"",children:["due ",j.date(t.dueDate)]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("span",{className:`text-xs font-semibold ${o?"text-emerald-700":k}`,children:[c,"%"]}),o?e.jsxs("button",{type:"button",className:"btn-primary text-xs",title:"Archive this completed goal into Previous targets",onClick:()=>{h.agencies.archivePerformanceGoal(l,t.id,x),i()},children:[e.jsx(Se,{className:"h-3 w-3"})," Move to previous targets"]}):e.jsxs("button",{type:"button",className:"btn-outline text-xs",title:"Archive this goal into Previous targets (records met / not-met)",onClick:()=>{h.agencies.archivePerformanceGoal(l,t.id,x),i()},children:[e.jsx(Se,{className:"h-3 w-3"})," Archive"]}),e.jsxs("button",{type:"button",className:"btn-outline text-xs",onClick:s,children:[e.jsx(it,{className:"h-3 w-3"})," Edit"]}),e.jsx("button",{type:"button",className:"btn-outline text-xs !px-2 text-rose-600",title:"Delete this goal (no history entry)",onClick:()=>{confirm(`Delete this ${(r==null?void 0:r.label.toLowerCase())??"goal"}?`)&&(h.agencies.removePerformanceGoal(l,t.id),i())},children:e.jsx(at,{className:"h-3 w-3"})})]})]}),e.jsx("div",{className:"mt-2 h-2 rounded-full bg-ink-100 overflow-hidden",children:e.jsx("div",{className:`h-full ${C}`,style:{width:`${c}%`}})})]})}function ie({title:l,tone:t,rows:n,agencyId:s}){const i=t==="met"?"text-emerald-700":"text-rose-700";return e.jsxs("div",{className:"rounded-md border border-ink-100 p-3",children:[e.jsxs("div",{className:`text-[11px] uppercase tracking-wider font-semibold mb-2 inline-flex items-center gap-1 ${i}`,children:[t==="met"?e.jsx(V,{className:"h-3.5 w-3.5"}):e.jsx(we,{className:"h-3.5 w-3.5"}),l," · ",n.length]}),n.length===0?e.jsx("div",{className:"text-xs text-ink-400",children:"None yet."}):e.jsx("ul",{className:`space-y-2 ${n.length>5?"max-h-[16rem] dropdown-scroll-y":""}`,children:n.map((r,x)=>{const c=te(r),o=u=>
21(c==null?void 0:c.format)==="money"?j.money(u):u.toLocaleString();return e.jsxs("li",{className:"text-xs",children:[e.jsxs("div",{className:"font-medium text-ink-800",children:[c.label,e.jsx("span",{className:"ml-1.5 text-[10px] text-ink-400",children:ve(s,r)})]}),e.jsxs("div",{className:"text-ink-500",children:[o(r.actual)," of ",o(r.target)," (",me(r.period),")",r.dueDate&&` · due ${j.date(r.dueDate)}`]}),e.jsxs("div",{className:"text-[10px] text-ink-400",children:["Archived ",j.dateTime(r.archivedAt)]})]},x)})})]})}function ht({agencyId:l,goals:t}){const n=t.map(s=>{const i=te(s),r=ge(l,s),x=fe(r,s.target);return{id:s.id,label:i.label,format:i.format,scopeLabel:ve(l,s),target:s.target,actual:r,pct:x}});return n.length===0?null:e.jsxs("div",{className:"rounded-md border border-ink-100 bg-ink-50/40 p-4",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-ink-500 font-semibold mb-3",children:"Actual vs. target"}),e.jsx("ul",{className:"space-y-3",children:n.map(s=>{const i=x=>s.format==="money"?j.money(x):x.toLocaleString(),r=s.pct>=100?"bg-emerald-500":s.pct>=75?"bg-gold-500":s.pct>=40?"bg-amber-500":"bg-rose-500";return e.jsxs("li",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-ink-700 mb-1",children:[e.jsxs("span",{className:"font-medium",children:[s.label,e.jsx("span",{className:"ml-1.5 text-[10px] text-ink-400",children:s.scopeLabel})]}),e.jsxs("span",{className:"tabular-nums",children:[i(s.actual)," ",e.jsxs("span",{className:"text-ink-400",children:["/ ",i(s.target)]})]})]}),e.jsx("div",{className:"h-2 rounded-full bg-ink-100 overflow-hidden",children:e.jsx("div",{className:`h-full ${r}`,style:{width:`${s.pct}%`}})})]},s.id)})})]})}function bt({open:l,agencyId:t,existing:n,onClose:s}){const i=!!n,x=["premiumWritten","activitiesResolved","newCustomers","newProspects","policiesBound"].map(g=>oe.find(I=>I.key===g)).filter(g=>!!g),[c,o]=y.useState("premiumWritten"),[u,m]=y.useState(""),[p,k]=y.useState("monthly"),[C,a]=y.useState(""),[b,w]=y.useState("company"),[A,M]=y.useState(new Set),[R,d]=y.useState(""),[L,B]=y.useState(null),[D,$]=y.useState(null),S=y.useMemo(()=>h.users.list(t).filter(g=>g.role==="agent"||g.role==="manager").sort((g,I)=>g.name.localeCompare(I.name)),[t,l]);if(y.useEffect(()=>{l&&(o((n==null?void 0:n.metric)??"premiumWritten"),m(n?String(n.target):""),k((n==null?void 0:n.period)??"monthly"),a(n!=null&&n.dueDate?n.dueDate.slice(0,10):""),w((n==null?void 0:n.scope)??"company"),M(new Set((n==null?void 0:n.assigneeIds)??[])),d((n==null?void 0:n.customMetricPrompt)??(n==null?void 0:n.customMetricLabel)??""),B((n==null?void 0:n.metric)==="custom"?{prompt:n.customMetricPrompt??n.customMetricLabel??"",formula:n.customMetricFormula??"activitiesResolved",label:n.customMetricLabel??"Custom metric",helper:n.customMetricHelper??"AI-tracked custom operational metric.",format:"count"}:null),$(null))},[l,n==null?void 0:n.id]),!l)return null;const v=c==="custom"?L??{helper:"Describe the operational result you want AI to track.",format:"count"}:oe.find(g=>g.key===c),P=Number(u),N=Number.isFinite(P)&&P>0&&(b==="company"||A.size>0)&&(c!=="custom"||L!=null||R.trim().length>0);function H(g){M(I=>{const _=new Set(I);return _.has(g)?_.delete(g):_.add(g),_})}function W(){const g=R.trim();if(!g){$("Describe the custom metric first.");return}B(ce(g)),o("custom"),$(null)}function U(){if(!Number.isFinite(P)||P<=0){$("Enter a positive target.");return}if(b==="personal"&&A.size===0){$("Pick at least one person for a personal goal.");return}const g=c==="custom"?L??ce(R):null;if(c==="custom"&&!(g!=null&&g.prompt.trim())){$("Describe the custom metric you want AI to track.");return}const I={target:P,customMetricLabel:g==null?void 0:g.label,customMetricPrompt:g==null?void 0:g.prompt,customMetricHelper:g==null?void 0:g.helper,customMetricFormula:g==null?void 0:g.formula,period:p,dueDate:C?new Date(C).toISOString():void 0,scope:b,assigneeIds:b==="personal"?Array.from(A):void 0};i&&n?h.agencies.updatePerformanceGoal(t,n.id,I):h.agencies.addPerformanceGoal(t,{metric:c,...I}),s()}return e.jsx(je,{open:l,onClose:s,title:i?"Edit goal":"Set a goal",size:"md",children:e.jsxs("div",{className:"space-y-4",children:[!i&&e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Metric"}),e.jsxs("div",{className:"grid auto-rows-fr gap-2 sm:grid-cols-2",children:[x.map(g=>{const I=c===g.key;return e.jsxs("button",{type:"button",onClick:()=>{o(g.key),$(null)},className:`flex min-h-[4.75rem] flex-col justify-center rounded-md border px-3 py-2 text-left text-sm ${I?"border-gold-400 bg-gold-50 text-ink-900":"border-ink-200 bg-white text-ink-700 hover:border-ink-300"}`,children:[e.jsx("div",{className:"font-medium",children:g.label}),e.jsx("div",{className:"text-[11px] text-ink-500",children:g.helper})]},g.key)}),e.jsxs("button",{type:"button",onClick:()=>{o("custom"),$(null)},className:`flex min-h-[4.75rem] flex-col justify-center rounded-md border px-3 py-2 text-left text-sm ${c==="custom"?"border-gold-400 bg-gold-50 text-ink-900":"border-ink-200 bg-white text-ink-700 hover:border-ink-300"}`,children:[e.jsxs("div",{className:"font-medium inline-flex items-center gap-1.5",children:[e.jsx(ee,{className:"h-3.5 w-3.5 text-gold-600"})," Custom AI metric"]}),e.jsx("div",{className:"text-[11px] text-ink-500",children:"Type your own metric and AI maps it to live data."})]})]})]}),c==="custom"&&e.jsxs("div",{className:"rounded-md border border-gold-200 bg-gold-50/40 p-3",children:[e.jsx("label",{className:"label",children:"Custom metric"}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("input",{className:"input text-sm",placeholder:"e.g. policies renewed",value:R,onChange:g=>{d(g.target.value),B(null)}}),e.jsxs("button",{type:"button",className:"btn-primary text-sm whitespace-nowrap",onClick:W,children:[e.jsx(ee,{className:"h-3.5 w-3.5"})," AI build"]})]}),e.jsx("div",{className:"mt-2 text-xs text-ink-600",children:L?e.jsxs(e.Fragment,{children:["AI will track"," ",e.jsx("span",{className:"font-semibold text-ink-900",children:L.label})," ","using the closest available agency data signal."]}
21):"Examples: policies renewed, claims closed, approved documents, new leads."})]}),e.jsx("p",{className:"text-sm text-ink-600",children:v.helper}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Goal for"}),e.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:[{v:"company",label:"Company-wide",hint:"Whole agency"},{v:"personal",label:"Specific person(s)",hint:"Selected staff"}].map(g=>{const I=b===g.v;return e.jsxs("button",{type:"button",onClick:()=>w(g.v),className:`text-left rounded-md border px-3 py-2 text-sm ${I?"border-gold-400 bg-gold-50 text-ink-900":"border-ink-200 bg-white text-ink-700 hover:border-ink-300"}`,children:[e.jsx("div",{className:"font-medium",children:g.label}),e.jsx("div",{className:"text-[11px] text-ink-500",children:g.hint})]},g.v)})})]}),b==="personal"&&e.jsxs("div",{children:[e.jsxs("label",{className:"label",children:["Who is this goal for? (",A.size," selected)"]}),e.jsx("div",{className:"grid sm:grid-cols-2 gap-1.5 max-h-48 overflow-y-auto rounded-md border border-ink-100 p-2 bg-ink-50/30",children:S.map(g=>{const I=A.has(g.id);return e.jsxs("label",{className:`flex items-center gap-2 rounded px-2 py-1.5 cursor-pointer text-sm ${I?"bg-gold-50 border border-gold-200":"border border-transparent hover:bg-white"}`,children:[e.jsx("input",{type:"checkbox",checked:I,onChange:()=>H(g.id)}),e.jsxs("span",{className:"min-w-0 truncate",children:[g.name,e.jsxs("span",{className:"text-[11px] text-ink-500",children:[" ","· ",g.role==="manager"?"Manager":"Agent"]})]})]},g.id)})}),e.jsx("div",{className:"text-[11px] text-ink-500 mt-1",children:"The actual is summed across the selected staff member(s)' book / resolved work."})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"label",children:["Target (",v.format==="money"?"$":"count",")"]}),e.jsx("input",{className:"input",type:"number",min:0,step:v.format==="money"?1e3:1,value:u,onChange:g=>m(g.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Period"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:["monthly","quarterly","annual"].map(g=>{const I=p===g;return e.jsx("button",{type:"button",onClick:()=>k(g),className:`rounded-md border px-2 py-1.5 text-sm capitalize ${I?"border-gold-400 bg-gold-50 text-ink-900":"border-ink-200 bg-white text-ink-700 hover:border-ink-300"}`,children:g},g)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Due date (optional)"}),e.jsx("input",{className:"input",type:"date",value:C,onChange:g=>a(g.target.value)}),e.jsx("div",{className:"text-[11px] text-ink-500 mt-1",children:"A custom deadline for this target. Recorded when you archive it into Previous goals."})]}),D&&e.jsx("div",{className:"rounded-md border border-alert-ring bg-alert-soft px-3 py-2 text-xs text-alert",children:D}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-ink-100",children:[e.jsx("button",{type:"button",className:"btn-outline text-sm",onClick:s,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn-primary text-sm",onClick:U,disabled:!N,children:[e.jsx(de,{className:"h-3.5 w-3.5"})," Save goal"]})]})]})})}function gt({agency:l,user:t}){const n=Ce(l.id,t.id),[s,i]=y.useState(null),r=Ie(l.performanceGoals),x=r.filter(o=>o.scope==="company"),c=r.filter(o=>o.scope==="personal"&&(o.assigneeIds??[]).includes(t.id));return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-3xl",children:"Analytics"}),e.jsx("p",{className:"text-ink-500 text-sm mt-1",children:"Your personal book, activity performance, and company goals."})]}),e.jsx(q,{tone:"info",children:"Personal view"})]}),e.jsx(F,{title:"My book",children:e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(T,{label:"Assigned clients",value:n.assignedClients,icon:e.jsx(J,{className:"h-5 w-5"}),onClick:()=>i("assignedClients")}),e.jsx(T,{label:"Bound policies",value:n.boundPolicies,icon:e.jsx(ke,{className:"h-5 w-5"}),onClick:()=>i("boundPolicies")}),e.jsx(T,{label:"Premium under mgmt",value:j.money(n.premiumUnderMgmt),icon:e.jsx(ye,{className:"h-5 w-5"}),onClick:()=>i("premiumUnderMgmt")}),e.jsx(T,{label:"Renewals upcoming",value:n.renewalsUpcoming,icon:e.jsx(Fe,{className:"h-5 w-5"}),onClick:()=>i("renewalsUpcoming")})]})}),e.jsxs(F,{title:"My activity performance",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(T,{label:"Open activities",value:n.openActivities,icon:e.jsx(ue,{className:"h-5 w-5"}),onClick:()=>i("openActivities")}),e.jsx(T,{label:"In progress",value:n.inProgress,icon:e.jsx(ee,{className:"h-5 w-5"}),onClick:()=>i("inProgress")}),e.jsx(T,{label:"Resolved (30d)",value:n.resolvedLast30,icon:e.jsx(V,{className:"h-5 w-5"}),onClick:()=>i("resolvedLast30")}),e.jsx(T,{label:"Avg handle time",value:n.avgHandleMs?O(n.avgHandleMs):"-",icon:e.jsx(Ge,{className:"h-5 w-5"}),hint:"Started to resolved",onClick:()=>i("avgHandleMs")})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-4 mt-4",children:[e.jsx(T,{label:"Response rate",value:n.responseRate!=null?`${Math.round(n.responseRate*100)}%`:"-",hint:"Inbound resolved",onClick:()=>i("responseRate")}),e.jsx(T,{label:"Outbound messages",value:n.outboundMessages,onClick:()=>i("outboundMessages")}),e.jsx(T,{label:"Documents uploaded",value:n.docsUploaded,onClick:()=>i("docsUploaded")}),e.jsx(T,{label:"Open claims",value:n.openClaims,onClick:()=>i("openClaims")})]})]}
21),e.jsxs("div",{className:"grid xl:grid-cols-[minmax(0,1.35fr)_minmax(22rem,0.65fr)] gap-4",children:[e.jsxs(E,{children:[e.jsx(G,{title:"Company goals",subtitle:"Management-set targets for the agency, plus any personal goals assigned to you."}),e.jsxs("div",{className:"space-y-5",children:[e.jsx(De,{title:"Company-wide",empty:"No company goals are active right now.",agencyId:l.id,userId:t.id,goals:x}),c.length>0&&e.jsx(De,{title:"Assigned to me",empty:"No personal goals assigned.",agencyId:l.id,userId:t.id,goals:c,personal:!0})]})]}),e.jsx(vt,{agencyId:l.id,user:t})]}),e.jsx(Ne,{metric:s,agentId:t.id,agentName:t.name,agencyId:l.id,onClose:()=>i(null)})]})}function De({title:l,empty:t,agencyId:n,userId:s,goals:i,personal:r=!1}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-ink-500 font-semibold",children:l}),i.length===0?e.jsx("div",{className:"mt-2 rounded-md border border-dashed border-ink-200 p-4 text-sm text-ink-500",children:t}):e.jsx("ul",{className:"mt-2 space-y-3",children:i.map(x=>e.jsx(ft,{agencyId:n,userId:s,goal:x,scopeLabel:r?"Your assigned goal":"Company-wide"},x.id))})]})}function ft({agencyId:l,userId:t,goal:n,scopeLabel:s}){const i=n.scope==="personal"?{...n,assigneeIds:[t]}:n,r=te(n),x=ge(l,i),c=fe(x,n.target),o=n.target>0&&x>=n.target,u=c>=100?"bg-emerald-500":c>=75?"bg-gold-500":c>=40?"bg-amber-500":"bg-rose-500",m=p=>r.format==="money"?j.money(p):p.toLocaleString();return e.jsxs("li",{className:"rounded-md border border-ink-100 bg-white p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx(Ee,{className:"h-3.5 w-3.5 text-gold-700"}),e.jsx("span",{className:"text-sm font-semibold text-ink-900",children:r.label}),e.jsx("span",{className:"rounded bg-ink-100 px-1.5 py-0.5 text-[9px] uppercase tracking-wider font-semibold text-ink-600",children:s}),o&&e.jsx(q,{tone:"success",children:"Achieved"})]}),e.jsxs("div",{className:"mt-1 text-xs text-ink-500",children:[m(x)," of ",m(n.target)," this ",me(n.period),n.dueDate&&e.jsxs(e.Fragment,{children:[" · due ",j.date(n.dueDate)]})]})]}),e.jsxs("div",{className:"shrink-0 text-sm font-semibold tabular-nums text-ink-800",children:[c,"%"]})]}),e.jsx("div",{className:"mt-2 h-2 rounded-full bg-ink-100 overflow-hidden",children:e.jsx("div",{className:`h-full ${u}`,style:{width:`${c}%`}})})]})}function vt({agencyId:l,user:t}){const[n,s]=y.useState(!1),[i,r]=y.useState(null);return e.jsxs(E,{children:[e.jsx(G,{title:"Request a performance goal",subtitle:"Ask management to add a goal for you or for the agency."}),e.jsxs("div",{className:"rounded-md border border-dashed border-ink-200 bg-ink-50/40 p-4",children:[e.jsx("div",{className:"text-sm font-medium text-ink-900",children:"Use the same goal builder managers use."}),e.jsx("p",{className:"mt-1 text-xs text-ink-500",children:"Pick the metric, target, period, and whether it should be company-wide or for you."}),i&&e.jsx("div",{className:"mt-3 rounded-md border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-700",children:i}),e.jsxs("button",{type:"button",className:"btn-primary mt-4 w-full justify-center",onClick:()=>s(!0),children:[e.jsx(de,{className:"h-4 w-4"})," Request a goal"]})]}),e.jsx(jt,{open:n,agencyId:l,user:t,onClose:()=>s(!1),onSent:()=>{s(!1),r("Request sent to management for review in Analytics.")}})]})}function jt({open:l,agencyId:t,user:n,onClose:s,onSent:i}){const x=["premiumWritten","activitiesResolved","newCustomers","newProspects","policiesBound"].map(v=>oe.find(P=>P.key===v)).filter(v=>!!v),[c,o]=y.useState("premiumWritten"),[u,m]=y.useState(""),[p,k]=y.useState(""),[C,a]=y.useState("monthly"),[b,w]=y.useState("personal"),[A,M]=y.useState(""),[R,d]=y.useState(""),[L,B]=y.useState(null),D=c==="custom"&&u.trim()?ce(u):null,$=c==="custom"?D??{helper:"Describe the performance target you want management to consider.",format:"count"}:oe.find(v=>v.key===c);y.useEffect(()=>{l&&(o("premiumWritten"),m(""),k(""),a("monthly"),w("personal"),M(""),d(""),B(null))},[l]);function S(){const v=Number(p);if(!Number.isFinite(v)||v<=0){B("Enter a positive target.");return}if(c==="custom"&&!u.trim()){B("Describe the custom metric you want AI to track.");return}const P=c==="custom"?D??ce(u):null;
21h.agencies.addPerformanceGoalRequest(t,{requestedById:n.id,metric:c,customMetricLabel:P==null?void 0:P.label,customMetricPrompt:P==null?void 0:P.prompt,customMetricHelper:P==null?void 0:P.helper,customMetricFormula:P==null?void 0:P.formula,target:v,period:C,dueDate:A?new Date(A).toISOString():void 0,scope:b,note:R.trim()||void 0}),B(null),i()}return l?e.jsx(je,{open:l,onClose:s,title:"Request a goal",size:"md",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Metric"}),e.jsxs("div",{className:"grid auto-rows-fr gap-2 sm:grid-cols-2",children:[x.map(v=>e.jsxs("button",{type:"button",onClick:()=>{o(v.key),B(null)},className:`flex min-h-[4.75rem] flex-col justify-center rounded-md border px-3 py-2 text-left text-sm ${c===v.key?"border-gold-400 bg-gold-50 text-ink-900":"border-ink-200 bg-white text-ink-700 hover:border-ink-300"}`,children:[e.jsx("div",{className:"font-medium",children:v.label}),e.jsx("div",{className:"text-[11px] text-ink-500",children:v.helper})]},v.key)),e.jsxs("button",{type:"button",onClick:()=>{o("custom"),B(null)},className:`flex min-h-[4.75rem] flex-col justify-center rounded-md border px-3 py-2 text-left text-sm ${c==="custom"?"border-gold-400 bg-gold-50 text-ink-900":"border-ink-200 bg-white text-ink-700 hover:border-ink-300"}`,children:[e.jsxs("div",{className:"font-medium inline-flex items-center gap-1.5",children:[e.jsx(ee,{className:"h-3.5 w-3.5 text-gold-600"})," Custom AI metric"]}),e.jsx("div",{className:"text-[11px] text-ink-500",children:"Request something like policies renewed or approved documents."})]})]})]}),c==="custom"&&e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Custom metric"}),e.jsx("input",{className:"input text-sm",placeholder:"e.g. policies renewed",value:u,onChange:v=>m(v.target.value)}),e.jsx("div",{className:"mt-1 text-xs text-ink-500",children:D?`AI will map this request to ${D.label}.`:"AI will map your wording to the closest live platform metric."})]}),e.jsx("p",{className:"text-sm text-ink-600",children:$.helper}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Goal for"}),e.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:[{value:"company",label:"Company-wide",helper:"Whole agency"},{value:"personal",label:"For me",helper:n.name}].map(v=>e.jsxs("button",{type:"button",onClick:()=>w(v.value),className:`rounded-md border px-3 py-2 text-left text-sm ${b===v.value?"border-gold-400 bg-gold-50 text-ink-900":"border-ink-200 bg-white text-ink-700 hover:border-ink-300"}`,children:[e.jsx("div",{className:"font-medium",children:v.label}),e.jsx("div",{className:"text-[11px] text-ink-500",children:v.helper})]},v.value))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"label",children:["Target (",$.format==="money"?"$":"count",")"]}),e.jsx("input",{className:"input",type:"number",min:0,step:$.format==="money"?1e3:1,value:p,onChange:v=>k(v.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Period"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:["monthly","quarterly","annual"].map(v
21=>{const P=C===v;return e.jsx("button",{type:"button",onClick:()=>a(v),className:`rounded-md border px-2 py-1.5 text-sm capitalize ${P?"border-gold-400 bg-gold-50 text-ink-900":"border-ink-200 bg-white text-ink-700 hover:border-ink-300"}`,children:v},v)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Due date (optional)"}),e.jsx("input",{className:"input",type:"date",value:A,onChange:v=>M(v.target.value)}),e.jsx("div",{className:"text-[11px] text-ink-500 mt-1",children:"A custom deadline for this requested target. If approved, it carries into the goal."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"label",children:"Note for manager"}),e.jsx("textarea",{className:"input min-h-[5.5rem] resize-none text-sm",placeholder:"Why this goal would help, what you want to be measured on, or timing.",value:R,onChange:v=>d(v.target.value)})]}),L&&e.jsx("div",{className:"rounded-md border border-alert-ring bg-alert-soft px-3 py-2 text-xs text-alert",children:L}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-3 border-t border-ink-100",children:[e.jsx("button",{type:"button",className:"btn-outline text-sm",onClick:s,children:"Cancel"}),e.jsxs("button",{type:"button",className:"btn-primary text-sm",onClick:S,children:[e.jsx(de,{className:"h-3.5 w-3.5"})," Send request"]})]})]})}):null}const be=[{key:"premiumUnderMgmt",label:"Premium under mgmt",format:"money",direction:"high",blurb:"Sum of bound-policy premium across each agent's book."},{key:"boundPolicies",label:"Bound policies",format:"count",direction:"high",blurb:"Count of bound policies on each agent's clients."},{key:"resolvedLast30",label:"Activities resolved (30d)",format:"count",direction:"high",blurb:"Activity Center tasks resolved in the last 30 days."},{key:"resolvedLifetime",label:"Activities resolved (lifetime)",format:"count",direction:"high",blurb:"All-time activity resolutions."},{key:"outboundMessages",label:"Outbound messages",format:"count",direction:"high",blurb:"AI / marketing messages sent on behalf of each agent's clients."},{key:"responseRate",label:"Response rate",format:"percent",direction:"high",blurb:"Share of inbound client messages this agent has resolved."},{key:"avgHandleMs",label:"Avg handle time",format:"duration",direction:"low",blurb:"Average time from in-progress → resolved on Activity Center cards."},{key:"avgAckMs",label:"Avg ack time",format:"duration",direction:"low",blurb:"How quickly each agent acknowledges new notifications."},{key:"docsUploaded",label:"Documents uploaded",format:"count",direction:"high",blurb:"Files this agent has shared into client files."},{key:"assignedClients",label:"Book size",format:"count",direction:"high",blurb:"Active clients assigned to this agent."},{key:"openActivities",label:"Open activities",format:"count",direction:"low",blurb:"Activity Center cards still on each agent's plate (lower = cleaner queue)."}],Q={newClients:{key:"newClients",label:"New clients (30d)",format:"count",direction:"high",blurb:"Client profiles created in the last 30 days, ranked by assigned book."},newProspects:{key:"newProspects",label:"New prospects (30d)",format:"count",direction:"high",blurb:"Prospect profiles created in the last 30 days and assigned to each staff member."},policiesRenewed:{key:"policiesRenewed",label:"Policies renewed",format:"count",direction:"high",blurb:"Renewal records marked renewed for policies in each staff member's book."},claimsOpened:{key:"claimsOpened",label:"Claims opened",format:"count",direction:"low",blurb:"Claims opened for each staff member's assigned clients. Lower usually means a cleaner book."},claimsClosed:{key:"claimsClosed",label:"Claims closed",format:"count",direction:"high",blurb:"Closed claim files for each staff member's assigned clients."}};function kt(l){const t=l.trim().toLowerCase(),n=s=>be.find(i=>i.key===s);return/\b(ack|acknowledge|acknowledged|first response|response time|fastest response|quickest response)\b/.test(t)?n("avgAckMs"):/\b(handle time|handling time|turnaround|cycle time|resolution time|fastest close|fastest resolve|quickest close)\b/.test(t)?n("avgHandleMs"):/\b(response rate|reply rate|inbound rate|client replies|customer replies)\b/.test(t)?n("responseRate"):/\b(backlog|open queue|open activities|open activity|open tasks|open task|pen
21ding tasks|pending task|unresolved)\b/.test(t)?n("openActivities"):/\b(premium|revenue|written premium|book premium|aum|management|mgmt)\b/.test(t)?n("premiumUnderMgmt"):/\b(book size|largest book|assigned clients|managed clients|client count|customer count|accounts managed)\b/.test(t)?n("assignedClients"):/\b(new clients?|new customers?|new accounts?|client growth|customer growth)\b/.test(t)?Q.newClients:/\b(prospect|prospects|lead|leads|quote start|quote starts)\b/.test(t)?Q.newProspects:/\b(renew|renewal|renewed|retention)\b/.test(t)?Q.policiesRenewed:/\b(closed|close|resolved|settled)\b/.test(t)&&/\bclaim/.test(t)?Q.claimsClosed:/\bclaim/.test(t)?Q.claimsOpened:/\b(document|documents|doc|docs|upload|uploaded)\b/.test(t)?n("docsUploaded"):/\b(message|messages|outbound|sms|email)\b/.test(t)?n("outboundMessages"):/\b(policy|policies|bound|bind|bindings?)\b/.test(t)?n("boundPolicies"):(/\b(activity|activities|task|tasks|resolved|closed|completed|done)\b/.test(t),n("resolvedLast30"))}function yt(l,t){return l==null?"—":t==="money"?j.money(l):t==="percent"?`${Math.round(l*100)}%`:t==="duration"?O(l):l.toLocaleString()}function wt({agencyId:l,onOpenAgent:t}){const[n,s]=y.useState("premiumUnderMgmt"),[i,r]=y.useState(""),x=i.trim()?kt(i):null,c=(x==null?void 0:x.key)??n,o=x??be.find(a=>a.key===n),u=y.useMemo(()=>h.users.list(l).filter(a=>a.role==="agent"||a.role==="manager"),[l]),m=y.useMemo(()=>u.map(a=>{const b=h.customers.list(l).filter(f=>f.assignedAgentId===a.id||(f.additionalAgentIds??[]).includes(a.id)),w=new Set(b.map(f=>f.id)),A=h.prospects.listByTenant(l).filter(f=>f.assignedAgentId===a.id||(f.additionalAgentIds??[]).includes(a.id)),M=h.policies.listByTenant(l).filter(f=>w.has(f.customerId)),R=h.tasks.listByTenant(l).filter(f=>f.assignedToId===a.id||(f.additionalAssignedToIds??[]).includes(a.id)),d=h.aiNotifications.listByTenant(l).filter(f=>f.assignedToId===a.id),L=h.claims.listByTenant(l).filter(f=>w.has(f.customerId)),B=h.renewals.listByTenant(l).filter(f=>{const z=h.policies.get(f.policyId);return z?w.has(z.customerId):!1}),D=Date.now()-720*60*60*1e3,$=b.filter(f=>new Date(f.createdAt).getTime()>=D).length,S=A.filter(f=>new Date(f.createdAt).getTime()>=D).length,v=R.filter(f=>f.completedAt&&new Date(f.completedAt).getTime()>=D).length,P=R.filter(f=>!!f.completedAt).length,N=R.filter(f=>!f.completedAt).length,H=R.filter(f=>f.startedAt&&f.completedAt).map(f=>new Date(f.completedAt).getTime()-new Date(f.startedAt).getTime()).filter(f=>f>0),W=d.filter(f=>f.acknowledgedAt).map(f=>new Date(f.acknowledgedAt).getTime()-new Date(f.createdAt).getTime()).filter(f=>f>0),U=b.flatMap(f=>h.communications.listByCustomer(f.id).filter(z=>z.direction==="inbound")),g=U.filter(f=>f.resolvedAt).length,I=h.marketing.listMessages(l).filter(f=>f.customerId&&w.has(f.customerId)&&f.deliveryStatus==="sent").length,_=h.documents.listByTenant(l).filter(f=>f.uploadedById===a.id).length,qe=M.filter(f=>f.status==="bound").reduce((f,z)=>f+(z.finalPremium??z.premiumEstimate??0),0),He=M.filter(f=>f.status==="bound").length,We={premiumUnderMgmt:qe,boundPolicies:He,resolvedLast30:v,resolvedLifetime:P,openActivities:N,outboundMessages:I,responseRate:U.length===0?null:g/U.length,avgHandleMs:H.length?X(H):null,avgAckMs:W.length?X(W):null,docsUploaded:_,assignedClients:b.length,newClients:$,newProspects:S,policiesRenewed:B.filter(f=>f.status==="renewed").length,claimsOpened:L.length,claimsClosed:L.filter(f=>f.status==="closed").length};return{agent:a,values:We}}),[Nt(u),l]),p=y.useMemo(()=>{const a=o.direction;return[...m].sort((b,w)=>{const A=b.values[c],M=w.values[c];return A==null&&M==null?0:A==null?1:M==null?-1:a==="high"?M-A:A-M})},[m,o,c]),k=y.useMemo(()=>{const a=p.map(b=>b.values[c]).filter(b=>b!=null);return a.length===0?1:o.direction==="high"?Math.max(...a,1):Math.max(...a,1)},[p,o,c]);function C(a){if(a==null||k===0)return 0;if(o.direction==="high")return Math.min(100,a/k*100);const b=Math.min(...p.map(w=>w.values[c]).filter(w=>w!=null))||a;return a===0?100:Math.max(8,Math.min(100,b/a*100))}return e.jsxs(E,{children:[e.jsx(G,{title:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Te,{className:"h-4 w-4 text-gold-600"}),"Performance leaderboard"]}),subtitle:o.blurb}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-4",children:[be.map(a=>{const b=!x&&n===a.key;return e.jsxs("button",{type:"button",onClick:()=>{s(a.key),r("")},className:`px-3 py-1.5 rounded-full text-xs font-medium border ${b?"bg-ink-900 text-white border-ink-900":"bg-white text-ink-700 border-ink-200 hover:bg-ink-50"}`,children:[a.label,a.direction==="low"&&e.jsx("span",{className:"ml-1 text-[10px] opacity-70",children:"↓ lower"})]},a.key)}),e.jsx(Ye,{value:i,onChange:r,label:"AI Custom",placeholder:"ex: new prospects, policies renewed, claims closed, response rate"})]}),x&&e.jsxs("div",{className:"mb-4 rounded-md border border-gold-200 bg-gold-50/50 px-3 py-2 text-xs text-gold-900",children:["AI mapped this leaderboard to ",e.jsx("span",{className:"font-semibold",children:x.label}),"."]}),p.length===0?e.jsx("div",{className:"text-sm text-ink-400",children:"No agents on this team yet."}):e.jsx("ol",{className:"space-y-2",children:p.map((a,b)=>{const w=a.values[c],A=C(w),M=b===0?"bg-gold-100 text-gold-800 border-gold-300":b===1?"bg-ink-100 text-ink-800 border-ink-300":b===2?"bg-amber-100 text-amber-800 border-amber-300":"bg-white text-ink-500 border-ink-200";return e.jsx("li",{children:e.jsx("button",{type:"button",onClick:()=>
21t(a.agent.id),className:"w-full text-left rounded-md border border-ink-100 bg-white hover:bg-ink-50/40 px-3 py-2.5 transition-colors",children:e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:`inline-flex items-center justify-center min-w-[28px] h-7 rounded-md border text-xs font-semibold tabular-nums ${M}`,children:b<3?b===0?e.jsx(Te,{className:"h-3.5 w-3.5"}):e.jsx(ot,{className:"h-3.5 w-3.5"}):b+1}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"text-sm font-semibold text-ink-900 truncate",children:[a.agent.name,e.jsx("span",{className:"ml-1.5 text-[10px] uppercase tracking-wider text-ink-400",children:a.agent.role==="manager"?"Manager":"Agent"})]}),e.jsx("span",{className:"text-sm font-semibold tabular-nums",children:yt(w,o.format)})]}),e.jsx("div",{className:"mt-1.5 h-1.5 rounded-full bg-ink-100 overflow-hidden",children:e.jsx("div",{className:`h-full ${b===0?"bg-gold-400":b===1?"bg-ink-400":b===2?"bg-amber-400":"bg-ink-300"}`,style:{width:`${A}%`}})})]})]})})}
21,a.agent.id)})})]})}function Nt(l){return l.map(t=>t.id).sort().join("|")}function ae({label:l,value:t,hint:n}){return e.jsxs("div",{className:"rounded-md border border-ink-100 bg-white px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-ink-500",children:l}),e.jsx("div",{className:"mt-1 text-xl font-semibold tabular-nums",children:t}),n&&e.jsx("div",{className:"text-[11px] text-ink-500 mt-0.5",children:n})]})}const Ct={emerald:{stroke:"#059669",fill:"#10B981",tint:"rgba(16,185,129,0.12)"},indigo:{stroke:"#4F46E5",fill:"#6366F1",tint:"rgba(99,102,241,0.12)"},gold:{stroke:"#876826",fill:"#a98532",tint:"rgba(169,133,50,0.12)"},violet:{stroke:"#7C3AED",fill:"#8B5CF6",tint:"rgba(139,92,246,0.12)"}};function re({title:l,buckets:t,valueKey:n,tone:s}){const[i,r]=y.useState(null),x=640,c=260,o={top:16,right:16,bottom:32,left:44},u=x-o.left-o.right,m=c-o.top-o.bottom,p=Math.max(1,...t.map(S=>S[n])),k=At(p),C=k/4,a=Array.from({length:5},(S,v)=>v*C);function b(S){return t.length<=1?o.left+u/2:o.left+S/(t.length-1)*u}function w(S){return o.top+(1-S/k)*m}const A=Ct[s],M=t.map((S,v)=>({x:b(v),y:w(S[n]),v:S[n],label:S.label})),R=M.length>0?"M "+M.map(S=>`${S.x.toFixed(2)} ${S.y.toFixed(2)}`).join(" L "):"",d=M.length>0?`${R} L ${M[M.length-1].x.toFixed(2)} ${o.top+m} L ${M[0].x.toFixed(2)} ${o.top+m} Z`:"",L=Math.max(1,Math.ceil(t.length/6));function B(S){const P=S.currentTarget.getBoundingClientRect(),N=(S.clientX-P.left)/P.width*x;let H=0,W=1/0;for(let U=0;U<M.length;U++){const g=Math.abs(M[U].x-N);g<W&&(W=g,H=U)}r(H)}const D=i!=null?M[i]:null,$=`tg-${s}-${n}`;return e.jsxs("div",{className:"rounded-md border border-ink-100 bg-white p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"text-xs uppercase tracking-wider text-ink-500 flex items-center gap-1.5 font-medium",children:[e.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-sm",style:{backgroundColor:A.fill}}),l]}),e.jsxs("div",{className:"text-[11px] text-ink-400 tabular-nums",children:["Peak ",e.jsx("span",{className:"text-ink-700 font-medium",children:p})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{viewBox:`0 0 ${x} ${c}`,className:"w-full h-auto cursor-crosshair",onMouseLeave:()=>r(null),onMouseMove:B,role:"img","aria-label":l,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:$,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:A.fill,stopOpacity:.28}),e.jsx("stop",{offset:"100%",stopColor:A.fill,stopOpacity:0})]})}),a.map((S,v)=>{const P=w(S);return e.jsxs("g",{children:[e.jsx("line",{x1:o.left,x2:x-o.right,y1:P,y2:P,stroke:"#e9e8e3",strokeWidth:1,strokeDasharray:v===0?"":"3 4"}),e.jsx("text",{x:o.left-8,y:P+4,textAnchor:"end",fontSize:11,fill:"#a8a394",fontFamily:"Inter, system-ui, sans-serif",children:Math.round(S)})]},v)}),e.jsx("line",{x1:o.left,x2:x-o.right,y1:o.top+m,y2:o.top+m,stroke:"#cfccc1",strokeWidth:1}),e.jsx("path",{d,fill:`url(#${$})`}),e.jsx("path",{d:R,fill:"none",stroke:A.stroke,strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round"}),D&&e.jsx("line",{x1:D.x,x2:D.x,y1:o.top,y2:o.top+m,stroke:A.stroke,strokeWidth:1,strokeDasharray:"3 4",opacity:.45}),M.length<=16&&M.map((S,v)=>e.jsx("circle",{cx:S.x,cy:S.y,r:i===v?5:3,fill:i===v?A.stroke:"white",stroke:A.stroke,strokeWidth:1.75},v)),M.length>16&&D&&e.jsx("circle",{cx:D.x,cy:D.y,r:5,fill:A.stroke,stroke:"white",strokeWidth:2}),M.map((S,v)=>v%L===0||v===M.length-1?e.jsx("text",{x:S.x,y:c-10,textAnchor:"middle",fontSize:11,fill:"#a8a394",fontFamily:"Inter, system-ui, sans-serif",children:S.label},v):null)]}),D&&e.jsx("div",{className:"absolute pointer-events-none z-10",style:{left:`${D.x/x*100}%`,top:`${D.y/c*100}%`,transform:`translate(${D.x>x*.7?"calc(-100% - 12px)":"12px"}, -100%)`},children:e.jsxs("div",{className:"rounded-md bg-ink-900 text-white text-[11px] px-3 py-2 shadow-luxe whitespace-nowrap",children:[e.jsx("div",{className:"text-ink-200",children:D.label}),e.jsx("div",{className:"font-semibold tabular-nums text-sm leading-tight",children:D.v})]})})]})]})}function At(l){if(l<=0)return 4;const t=Math.floor(Math.log10(l)),n=Math.pow(10,t),s=l/n;let i;return s<=1?i=1:s<=2?i=2:s<=2.5?i=2.5:s<=5?i=5:i=10,Math.max(4,i*n)}function Mt(l,t){const n=Date.now(),s=t==="7d"?7:t==="30d"?30:t==="90d"?90:365,i=t==="7d"||t==="30d"?1:t==="90d"?7:30,r=Math.ceil(s/i),x=n-s*24*60*60*1e3,c=Array.from({length:r},(m,p)=>{const k=new Date(x+p*i*24*60*60*1e3);return{label:i===1?j.date(k.toISOString()):i===7?`Wk ${Math.floor(p+1)}
21`:k.toLocaleString("en-US",{month:"short"}),startsAt:k.toISOString(),resolved:0,inbound:0,outbound:0,newCustomers:0,premiumWritten:0}});function o(m){if(!m)return-1;const p=new Date(m).getTime();return p<x?-1:Math.min(r-1,Math.floor((p-x)/(i*24*60*60*1e3)))}h.tasks.listByTenant(l).forEach(m=>{if(!m.completedAt)return;const p=o(m.completedAt);p>=0&&(c[p].resolved+=1)}),h.customers.list(l).forEach(m=>{h.communications.listByCustomer(m.id).forEach(p=>{if(p.direction!=="inbound")return;const k=o(p.createdAt);k>=0&&(c[k].inbound+=1)})}),h.marketing.listMessages(l).forEach(m=>{if(m.deliveryStatus!=="sent")return;const p=o(m.sentAt??m.createdAt);p>=0&&(c[p].outbound+=1)}),h.customers.list(l).forEach(m=>{const p=o(m.createdAt);p>=0&&(c[p].newCustomers+=1)}),h.policies.listByTenant(l).forEach(m=>{if(m.status!=="bound")return;const p=o(m.createdAt);p>=0&&(c[p].premiumWritten+=m.finalPremium??m.premiumEstimate??0)});const u=c.reduce((m,p)=>({resolved:m.resolved+p.resolved,inbound:m.inbound+p.inbound,outbound:m.outbound+p.outbound,newCustomers:m.newCustomers+p.newCustomers,premiumWritten:m.premiumWritten+p.premiumWritten}),{resolved:0,inbound:0,outbound:0,newCustomers:0,premiumWritten:0});return{buckets:c,totals:u}}function Tt({agencyId:l}){const t=It(l),[n,s]=y.useState(null);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(T,{label:"Active clients",value:t.activeClients,icon:e.jsx(J,{className:"h-5 w-5"}),hint:`${t.personalClients} personal · ${t.commercialClients} commercial`,onClick:()=>s("assignedClients")}),e.jsx(T,{label:"Personal lines clients",value:t.personalClients,icon:e.jsx(J,{className:"h-5 w-5"}),hint:"≥ 1 personal-lines policy",onClick:()=>s("personalClients")}),e.jsx(T,{label:"Commercial lines clients",value:t.commercialClients,icon:e.jsx(J,{className:"h-5 w-5"}),hint:"≥ 1 commercial-lines policy",onClick:()=>s("commercialClients")}),e.jsx(T,{label:"Bound policies",value:t.boundPolicies,icon:e.jsx(ke,{className:"h-5 w-5"}),onClick:()=>s("boundPolicies")})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-3 gap-4 mt-4",children:[e.jsx(T,{label:"Premium under mgmt",value:j.money(t.premiumUnderMgmt),icon:e.jsx(ye,{className:"h-5 w-5"}),onClick:()=>s("premiumUnderMgmt")}),e.jsx(T,{label:"Activities open",value:t.openActivities,icon:e.jsx(ue,{className:"h-5 w-5"}),onClick:()=>s("openActivities")}),e.jsx(T,{label:"Resolved (30d)",value:t.resolvedLast30,icon:e.jsx(V,{className:"h-5 w-5"}),hint:t.avgHandleMs?`Avg handle ${O(t.avgHandleMs)}`:void 0,onClick:()=>s("resolvedLast30")})]}),e.jsx(Ne,{metric:n,agencyId:l,onClose:()=>s(null)})]})}function St({agencyId:l,agent:t,onOpen:n}){const s=Ce(l,t.id);return e.jsxs("button",{type:"button",onClick:n,className:"text-left rounded-lg border border-ink-100 bg-white shadow-luxe p-4 hover:border-gold-300 hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-ink-900 truncate",children:t.name}),e.jsx("div",{className:"text-[11px] text-ink-500 uppercase tracking-wider mt-0.5",children:t.role})]}),e.jsx(q,{tone:s.openActivities>0?"warn":"success",children:s.openActivities>0?`${s.openActivities} open`:"Caught up"})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-3 gap-y-1.5 text-xs",children:[e.jsx(K,{label:"Clients",value:s.assignedClients}),e.jsx(K,{label:"Bound policies",value:s.boundPolicies}),e.jsx(K,{label:"Resolved (30d)",value:s.resolvedLast30}),e.jsx(K,{label:"Premium",value:j.money(s.premiumUnderMgmt)}),e.jsx(K,{label:"Avg handle",value:s.avgHandleMs?O(s.avgHandleMs):"—"}),e.jsx(K,{label:"Avg response",value:s.avgAckMs?O(s.avgAckMs):"—"})]})]})}function K({label:l,value:t}){return e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsx("dt",{className:"text-ink-500",children:l}),e.jsx("dd",{className:"text-ink-900 font-medium tabular-nums",children:t})]})}function Pt({agent:l,agencyId:t,onBack:n}){const s=Ce(t,l.id),[i,r]=y.useState(null),x=h.tasks.listByTenant(t).filter(u=>u.assignedToId===l.id),c=x.filter(u=>u.completedAt).sort((u,m)=>u.completedAt<m.completedAt?1:-1).slice(0,8),o=x.filter(u=>!u.completedAt).sort((u,m)=>u.createdAt<m.createdAt?1:-1).slice(0,8);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("button",{className:"btn-ghost -ml-2",onClick:n,children:[e.jsx(st,{className:"h-4 w-4"})," Back to team"]}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-3xl",children:l.name}),e.jsxs("p",{className:"text-ink-500 text-sm mt-1",children:[j.titleCase(l.role)," · ",l.email]})]}),e.jsx(F,{title:"Book & clients",children:e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(T,{label:"Assigned clients",value:s.assignedClients,icon:e.jsx(J,{className:"h-5 w-5"}),onClick:()=>r("assignedClients")}),e.jsx(T,{label:"Bound policies",value:s.boundPolicies,icon:e.jsx(ke,{className:"h-5 w-5"}),onClick:()=>r("boundPolicies")}),e.jsx(T,{label:"Premium under mgmt",value:j.money(s.premiumUnderMgmt),icon:e.jsx(ye,{className:"h-5 w-5"}),onClick:()=>r("premiumUnderMgmt")}),e.jsx(T,{label:"Renewals upcoming",value:s.renewalsUpcoming,icon:e.jsx(Fe,{className:"h-5 w-5"}),onClick:()=>r("renewalsUpcoming")})]})}),e.jsxs(F,{title:"Activity Center performance",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(T,{label:"Open activities",value:s.openActivities,icon:e.jsx(ue,{className:"h-5 w-5"}),onClick:()=>r("openActivities")}),e.jsx(T,{label:"In progress",value:s.inProgress,icon:e.jsx(ee,{className:"h-5 w-5"}),onClick:()=>r("inProgress")}),e.jsx(T,{label:"Resolved (30d)",value:s.resolvedLast30,icon:e.jsx(V,{className:"h-5 w-5"}),onClick:()=>r("resolvedLast30")}),e.jsx(T,{label:"Avg handle time",value:s.avgHandleMs?O(s.avgHandleMs):"—",icon:e.jsx(Ge,{className:"h-5 w-5"}),hint:"From Started → Resolved",onClick:()=>r("avgHandleMs")})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4 mt-4",children:[e.jsx(T,{label:"Avg time-to-acknowledge",value:s.avgAckMs?O(s.avgAckMs):"—",icon:e.jsx(nt,{className:"h-5 w-5"}),hint:"From notification arrived → Acknowledged",onClick:()=>r("avgAckMs")}),e.jsx(T,{label:"Resolved (lifetime)",value:s.resolvedLifetime,icon:e.jsx(V,{className:"h-5 w-5"}),onClick:()=>r("resolvedLifetime")}
21)]})]}),e.jsx(F,{title:"Customer engagement & outreach",children:e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(T,{label:"Inbound requests",value:s.inboundRequests,hint:"Customer-initiated",onClick:()=>r("inboundRequests")}),e.jsx(T,{label:"Response rate",value:s.responseRate!=null?`${Math.round(s.responseRate*100)}%`:"—",hint:"Resolved / total inbound",onClick:()=>r("responseRate")}),e.jsx(T,{label:"Outbound messages",value:s.outboundMessages,hint:"AI + custom",onClick:()=>r("outboundMessages")}),e.jsx(T,{label:"Documents uploaded",value:s.docsUploaded,onClick:()=>r("docsUploaded")})]})}),e.jsx(F,{title:"Claims",children:e.jsxs("div",{className:"grid sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(T,{label:"Open claims",value:s.openClaims,onClick:()=>r("openClaims")}),e.jsx(T,{label:"Closed claims",value:s.closedClaims,onClick:()=>r("closedClaims")}),e.jsx(T,{label:"Avg time-to-close",value:s.avgClaimCloseMs?O(s.avgClaimCloseMs):"—",onClick:()=>r("avgClaimCloseMs")})]})}),e.jsx(Ne,{metric:i,agentId:l.id,agentName:l.name,agencyId:t,onClose:()=>r(null)}),e.jsx(F,{title:`Agent activities (${o.length})`,children:o.length===0?e.jsx("div",{className:"text-sm text-ink-400",children:"No open activities."}):e.jsx("ul",{className:"divide-y divide-ink-100",children:o.map(u=>{const m=h.tasks.statusOf(u),p=m==="in_progress"?{label:"In progress",cls:"bg-blue-50 text-blue-700 border-blue-200"}:m==="snoozed"?{label:"Snoozed",cls:"bg-amber-50 text-amber-700 border-amber-200"}:{label:"To do",cls:"bg-rose-50 text-rose-700 border-rose-200"};return e.jsxs("li",{className:"py-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-ink-700 truncate",children:u.title}),e.jsxs("div",{className:"text-[11px] text-ink-400",children:["Opened ",j.dateTime(u.createdAt)," · ",j.relative(u.createdAt)," ago"]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:`inline-block rounded px-1.5 py-0.5 border text-[10px] uppercase tracking-wider font-semibold ${p.cls}`,children:p.label}),e.jsx(Ae,{to:`/employee/tasks?focus=${encodeURIComponent(u.id)}`,className:"btn-outline text-[11px] inline-flex",children:"View"})]})]},u.id)})})}),e.jsx(F,{title:`Recently resolved (${c.length})`,collapsible:!0,defaultOpen:!1,children:c.length===0?e.jsx("div",{className:"text-sm text-ink-400",children:"No resolved activities yet."}):e.jsx("ul",{className:"divide-y divide-ink-100",children:c.map(u=>e.jsxs("li",{className:"py-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm text-ink-700 truncate",children:u.title}),e.jsxs("div",{className:"text-[11px] text-ink-400",children:["Resolved ",j.dateTime(u.completedAt),u.startedAt&&e.jsxs(e.Fragment,{children:[" · Handle time ",O(new Date(u.completedAt).getTime()-new Date(u.startedAt).getTime())]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"inline-block rounded px-1.5 py-0.5 border text-[10px] uppercase tracking-wider font-semibold bg-emerald-50 text-emerald-700 border-emerald-200",children:"Resolved"}),e.jsx(Ae,{to:`/employee/tasks?focus=${encodeURIComponent(u.id)}`,className:"btn-outline text-[11px] inline-flex",children:"View"})]})]},u.id))})})]})}function F({title:l,children:t,collapsible:n,defaultOpen:s=!0}){const[i,r]=y.useState(s);return n?e.jsxs(E,{children:[e.jsx(G,{title:l,action:e.jsx("button",{type:"button",className:"btn-outline text-xs inline-flex",onClick:()=>r(x=>!x),children:i?e.jsxs(e.Fragment,{children:["Hide ",e.jsx(Oe,{className:"h-3.5 w-3.5"})]}):e.jsxs(e.Fragment,{children:["Show ",e.jsx(Ue,{className:"h-3.5 w-3.5"})]})})}),i&&t]}):e.jsxs(E,{children:[e.jsx(G,{title:l}),t]})}const Re={assignedClients:"Assigned clients",personalClients:"Personal lines clients",commercialClients:"Commercial lines clients",boundPolicies:"Bound policies",premiumUnderMgmt:"Premium under management",renewalsUpcoming:"Renewals upcoming",openActivities:"Open activities",inProgress:"In progress",resolvedLast30:"Resolved in the last 30 days",avgHandleMs:"Average handle time — per activity",avgA
21ckMs:"Average time-to-acknowledge — per notification",resolvedLifetime:"Resolved (lifetime)",inboundRequests:"Inbound customer requests",responseRate:"Response rate",outboundMessages:"Outbound messages",docsUploaded:"Documents uploaded",openClaims:"Open claims",closedClaims:"Closed claims",avgClaimCloseMs:"Average time-to-close — per claim"};function Ne({metric:l,agentId:t,agentName:n,agencyId:s,onClose:i}){if(!l)return null;const r=n?`${n} — ${Re[l]}`:`Agency — ${Re[l]}`;return e.jsx(je,{open:!0,onClose:i,title:r,size:"xl",children:e.jsx(Dt,{metric:l,agentId:t,agencyId:s})})}function Dt({metric:l,agentId:t,agencyId:n}){const s=h.customers.list(n).filter(a=>t?a.assignedAgentId===t:!a.archived),i=new Set(s.map(a=>a.id)),r=h.policies.listByTenant(n).filter(a=>i.has(a.customerId)),x=h.tasks.listByTenant(n).filter(a=>t?a.assignedToId===t:!0),c=h.aiNotifications.listByTenant(n).filter(a=>t?a.assignedToId===t:!0),o=h.renewals.listByTenant(n).filter(a=>{const b=h.policies.get(a.policyId);return b&&i.has(b.customerId)}),u=s.flatMap(a=>h.communications.listByCustomer(a.id).filter(b=>b.direction==="inbound")),m=h.marketing.listMessages(n).filter(a=>a.customerId&&i.has(a.customerId)&&a.deliveryStatus==="sent"),p=h.documents.listByTenant(n).filter(a=>a.uploadedById===t),k=h.claims.listByTenant(n).filter(a=>i.has(a.customerId)),C=Date.now()-720*60*60*1e3;switch(l){case"assignedClients":return e.jsx(pe,{customers:s});case"personalClients":{const a=new Set(r.filter(b=>(b.department??"personal")==="personal"&&b.status==="bound").map(b=>b.customerId));return e.jsx(pe,{customers:s.filter(b=>a.has(b.id))})}case"commercialClients":{const a=new Set(r.filter(b=>b.department==="commercial"&&b.status==="bound").map(b=>b.customerId));return e.jsx(pe,{customers:s.filter(b=>a.has(b.id))})}case"boundPolicies":return e.jsx(Me,{policies:r.filter(a=>a.status==="bound")});case"premiumUnderMgmt":{const a=r.filter(w=>w.status==="bound"),b=a.reduce((w,A)=>w+(A.finalPremium??A.premiumEstimate??0),0);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs text-ink-500 mb-3",children:["Total bound premium: ",e.jsx("strong",{children:j.money(b)})]}),e.jsx(Me,{policies:a,showPremium:!0})]})}case"renewalsUpcoming":return e.jsx(Je,{renewals:o.filter(a=>a.status==="upcoming")});case"openActivities":return e.jsx(Z,{tasks:x.filter(a=>!a.completedAt&&h.tasks.statusOf(a)!=="snoozed")});case"inProgress":return e.jsx(Z,{tasks:x.filter(a=>h.tasks.statusOf(a)==="in_progress")});case"resolvedLast30":return e.jsx(Z,{tasks:x.filter(a=>a.completedAt&&new Date(a.completedAt).getTime()>=C),showResolutionTime:!0});case"resolvedLifetime":return e.jsx(Z,{tasks:x.filter(a=>a.completedAt),showResolutionTime:!0});case"avgHandleMs":return e.jsx(Z,{tasks:x.filter(a=>a.startedAt&&a.completedAt),showHandleTime:!0});case"avgAckMs":return e.jsx(Rt,{notifications:c.filter(a=>a.acknowledgedAt)});
21case"inboundRequests":return e.jsx(Le,{comms:u,customers:s});case"responseRate":{const a=u.filter(w=>w.resolvedAt).length,b=u.length?Math.round(a/u.length*100):0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs text-ink-500 mb-3",children:[a," of ",u.length," inbound requests resolved (",b,"%)."]}),e.jsx(Le,{comms:u,customers:s})]})}case"outboundMessages":return e.jsx(Lt,{messages:m});case"docsUploaded":return e.jsx($t,{docs:p});case"openClaims":return e.jsx(he,{claims:k.filter(a=>a.status!=="closed")});case"closedClaims":return e.jsx(he,{claims:k.filter(a=>a.status==="closed"),showCloseTime:!0});case"avgClaimCloseMs":return e.jsx(he,{claims:k.filter(a=>a.status==="closed"&&a.closedAt),showCloseTime:!0})}}function Z({tasks:l,showHandleTime:t,showResolutionTime:n}){return l.length===0?e.jsx(Y,{label:"Nothing to show in this slice."}):e.jsx("ul",{className:"divide-y divide-ink-100",children:l.map(s=>{const i=s.startedAt&&s.completedAt?new Date(s.completedAt).getTime()-new Date(s.startedAt).getTime():null,r=s.customerId?h.customers.get(s.customerId):null;return e.jsxs(se,{details:e.jsxs("div",{className:"space-y-3",children:[e.jsx(ne,{rows:[{label:"Client",value:(r==null?void 0:r.name)??"—"},{label:"Severity",value:s.severity?j.titleCase(s.severity):"—"},{label:"Status",value:j.titleCase(h.tasks.statusOf(s))},{label:"Opened",value:j.dateTime(s.createdAt)},{label:"Started",value:s.startedAt?j.dateTime(s.startedAt):"—"},{label:"Resolved",value:s.completedAt?j.dateTime(s.completedAt):"—"},{label:"Handle time",value:i!=null?O(i):"—"}]}),s.aiSummary&&e.jsxs("div",{className:"rounded border border-violet-100 bg-violet-50 px-3 py-2 text-violet-900",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-violet-700 font-semibold mb-1",children:"AI summary"}),e.jsx("p",{className:"leading-snug",children:s.aiSummary})]})]}),link:{to:`/employee/tasks?focus=${encodeURIComponent(s.id)}`,label:"Activity"},children:[e.jsx("div",{className:"text-sm text-ink-900 truncate",children:s.title}),e.jsxs("div",{className:"text-[11px] text-ink-400 flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{children:["Opened ",j.dateTime(s.createdAt)]}),t&&i!=null&&e.jsxs("span",{className:"font-medium text-ink-900",children:["· Handle ",O(i)]}),n&&s.completedAt&&e.jsxs("span",{children:["· Resolved ",j.relative(s.completedAt)," ago"]}),!t&&!n&&e.jsx(q,{tone:s.severity==="urgent"?"error":"warn",children:h.tasks.statusOf(s)==="in_progress"?"In progress":"Open"})]})]},s.id)})})}function Rt({notifications:l}){return l.length===0?e.jsx(Y,{label:"No acknowledged notifications yet."}):e.jsx("ul",{className:"divide-y divide-ink-100",children:l.map(t=>{const n=t.acknowledgedAt?new Date(t.acknowledgedAt).getTime()-new Date(t.createdAt).getTime():null,s=t.customerId?h.customers.get(t.customerId):null;return e.jsxs(se,{details:e.jsxs("div",{className:"space-y-3",children:[e.jsx(ne,{rows:[{label:"Client",value:(s==null?void 0:s.name)??"—"},{label:"Topic",value:t.topic?j.titleCase(t.topic):"—"},{label:"Severity",value:t.severity?j.titleCase(t.severity):"—"},{label:"Arrived",value:j.dateTime(t.createdAt)},{label:"Acknowledged",value:t.acknowledgedAt?j.dateTime(t.acknowledgedAt):"—"},{label:"Time-to-acknowledge",value:n!=null?O(n):"—"}]}),t.aiSummary&&e.jsx("div",{className:"rounded border border-violet-100 bg-violet-50 px-3 py-2 text-violet-900",children:t.aiSummary})]}),children:[e.jsx("div",{className:"text-sm text-ink-900 truncate",children:t.title}),e.jsxs("div",{className:"text-[11px] text-ink-400",children:["Arrived ",j.dateTime(t.createdAt),n!=null&&e.jsxs("span",{className:"text-ink-900 font-medium",children:[" · Ack ",O(n)]})]})]},t.id)})})}function Le({comms:l,customers:t}){if(l.length===0)return e.jsx(Y,{label:"No inbound requests yet."});const n=new Map(t.map(s=>[s.id,s]));return e.jsx("ul",{className:"divide-y divide-ink-100",children:l.slice().sort((s,i)=>s.createdAt<i.createdAt?1:-1).map(s=>{const i=s.customerId?n.get(s.customerId):null;return e.jsxs(se,{link:i?{to:`/employee/clients/${i.id}`,label:"Profile"}:void 0,details:e.jsxs("div",{className:"space-y-3",children:[e.jsx(ne,{rows:[{label:"Client",value:(i==null?void 0:i.name)??"—"},{label:"Subject",value:s.subject??"—"},{label:"Channel",value:s.channel.toUpperCase()},{label:"Direction",value:j.titleCase(s.direction)},{label:"Received",value:j.dateTime(s.createdAt)},{label:"Resolved",value:s.resolvedAt?j.dateTime(s.resolvedAt):"Still pending"}]}),e.jsx("pre",{className:"rounded border border-ink-100 bg-white p-3 text-ink-700 whitespace-pre-wrap font-sans text-xs",children:s.body})]}),children:[e.jsxs("div",{className:"text-sm text-ink-900 truncate",children:[e.jsx("span",{className:"font-medium",children:(i==null?void 0:i.name)??"—"})," ",e.jsx("span",{className:"text-ink-500",children:s.subject??"—"})]}),e.jsxs("div",{className:"text-[11px] text-ink-400 flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{children:[s.channel.toUpperCase()," · ",j.dateTime(s.createdAt)]}),e.jsx(q,{tone:s.resolvedAt?"success":"warn",children:s.resolvedAt?"Resolved":"Pending"})]})]},s.id)})})}function Lt({messages:l}){return l.length===0?e.jsx(Y,{label:"No outbound messages yet."}):e.jsx("ul",{className:"divide-y divide-ink-100",children:l.slice().sort((t,n)=>(t.sentAt??t.createdAt)<(n.sentAt??n.createdAt)?1:-1).map(t=>{const n=t.customerId?h.customers.get(t.customerId):null;return e.jsxs(se,{details:e.jsxs("div",{className:"space-y-3",children:[e.jsx(ne,{rows:[{label:"Recipient",value:(n==null?void 0:n.name)??"—"},{label:"Channel",value:t.channel.toUpperCase()},{label:"Subject",value:t.subject??"—"},{label:"Status",value:j.titleCase(t.deliveryStatus)},{label:"Sent",value:j.dateTime(t.sentAt??t.createdAt)}]}),e.jsx("pre",{className:"rounded border border-ink-100 bg-white p-3 text-ink-700 whitespace-pre-wrap font-sans text-xs",children:t.content})]}),children:[e.jsx("div",{className:"text-sm text-ink-900 truncate",children:t.subject??`${t.channel.toUpperCase()} message`}),e.jsxs("div",{className:"text-[11px] text-ink-400 flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{children:[(n==null?void 0:n.name)??"—"," · ",t.channel.toUpperCase()," ·"," ",j.dateTime(t.sentAt??t.createdAt)]}),e.jsx(q,{tone:t.deliveryStatus==="opened"?"success":"info",children:j.titleCase(t.deliveryStatus)})]})]},t.id)})})}function $t({docs:l}){const[t,n]=y.useState(null),s=t?l.find(r=>r.id===t)??null:null;if(l.length===0)return e.jsx(Y,{label:"No documents uploaded yet."});const i=l.slice().sort((r,x)=>r.uploadedAt<x.uploadedAt?1:-1);return e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-ink-100",children:i.map(r=>{const x=r.customerId?h.customers.get(r.customerId):null;return e.jsxs("li",{className:"py-2.5 flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm text-ink-900 truncate",children:r.fileName}),e.jsxs("div",{className:"text-[11px] text-ink-400",children:[h.helpers.documentTypeLabel(r.type),x?` · ${x.name}`:""," · ",j.relative(r.uploadedAt)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("button",{type:"button",className:"btn-ghost text-xs",onClick:()=>n(r.id),title:"Quick view — opens the in-app document viewer",children:"View"}),e.jsxs("button",{type:"button",className:"btn-outline text-xs",onClick:()=>Qe(r),children:[e.jsx(rt,{className:"h-3.5 w-3.5"})," Download"]})]})]},r.id)})}),e.jsx(Ze,{document:s,open:s!=null,onClose:()=>n(null)})]})}function he({claims:l,showCloseTime:t}){return l.length===0?e.jsx(Y,{label:"No claims in this slice."}):e.jsx("ul",{className:"divide-y divide-ink-100",children:l.map(n=>{const s=h.customers.get(n.customerId),i=h.carriers.get(n.carrierId),r=h.policies.get(n.policyId);return e.jsxs(se,{link:{to:`/employee/clients/${n.customerId}`,label:"Profile"},details:e.jsx(ne,{rows:[{label:"Client",value:(s==null?void 0:s.name)??"—"},{label:"Carrier",value:(i==null?void 0:i.name)??"—"},{label:"Policy",value:r?j.policyRef(r):"—"},{label:"Status",value:j.titleCase(n.status)},{label:"Closed",value:n.closedAt?j.dateTime(n.closedAt):"Still open"}]}),children:[e.jsx("div",{className:"text-sm font-medium text-ink-900",children:(s==null?void 0:s.name)??"—"}),e.jsxs("div",{className:"text-[11px] text-ink-400 flex items-center gap-2 flex-wrap",children:[e.jsx("span",{children:j.titleCase(n.status)}),t&&n.closedAt&&e.jsxs("span",{children:["· Closed ",j.dateTime(n.closedAt)]}),e.jsx(q,{tone:n.status==="closed"?"success":"warn",children:j.titleCase(n.status)})]})]},n.id)})})}function It(l){return y.useMemo(()=>{const t=h.customers.list(l),n=h.policies.listByTenant(l),s=h.tasks.listByTenant(l),i=Date.now()-720*60*60*1e3,r=s.filter(o=>o.completedAt&&new Date(o.completedAt).getTime()>=i),x=r.filter(o=>o.startedAt&&o.completedAt).map(o=>new Date(o.completedAt).getTime()-new Date(o.startedAt).getTime()).filter(o=>o>0),c=o=>{const u=new Set(n.filter(m=>(m.department??"personal")===o&&m.status==="bound").map(m=>m.customerId));return t.filter(m=>!m.archived&&u.has(m.id)).length};return{activeClients:t.filter(o=>!o.archived).length,personalClients:c("personal"),commercialClients:c("commercial"),boundPolicies:n.filter(o=>o.status==="bound").length,premiumUnderMgmt:n.filter(o=>o.status==="bound").reduce((o,u)=>o+(u.finalPremium??u.premiumEstimate??0),0),openActivities:s.filter(o=>!o.completedAt).length,resolvedLast30:r.length,avgHandleMs:x.length?X(x):null}},[l])}function Ce(l,t){return y.useMemo(()=>{const n=h.customers.list(l).filter(d=>d.assignedAgentId===t),s=new Set(n.map(d=>d.id)),i=h.policies.listByTenant(l).filter(d=>s.has(d.customerId)),r=h.tasks.listByTenant(l).filter(d=>d.assignedToId===t),x=h.aiNotifications.listByTenant(l).filter(d=>d.assignedToId===t),c=Date.now()-720*60*60*1e3,o=r.filter(d=>d.completedAt&&new Date(d.completedAt).getTime()>=c),u=r.filter(d=>d.startedAt&&d.completedAt).map(d=>new Date(d.completedAt).getTime()-new Date(d.startedAt).getTime()).filter(d=>d>0),m=x.filter(d=>d.acknowledgedAt).map(d=>new Date(d.acknowledgedAt).getTime()-new Date(d.createdAt).getTime()).filter(d=>d>0),p=h.communications.listPendingForTenant(l).filter(d=>d.customerId&&s.has(d.customerId)),k=n.flatMap(d=>h.communications.listByCustomer(d.id).filter(L=>L.direction==="inbound")),C=k.filter(d=>d.resolvedAt),a=h.marketing.listMessages(l).filter(d=>d.customerId&&s.has(d.customerId)&&d.deliveryStatus==="sent"),b=h.documents.listByTenant(l).filter(d=>d.uploadedById===t).length,w=h.claims.listByTenant(l).filter(d=>s.has(d.customerId)),A=w.filter(d=>d.status==="closed"),M=A.filter(d=>d.closedAt).map(d=>new Date(d.closedAt).getTime()-new Date(d.createdAt??d.closedAt).getTime()).filter(d=>d>0),R=h.renewals.listByTenant(l).filter(d=>i.find(B=>B.id===d.policyId)&&d.status==="upcoming");return{assignedClients:n.length,boundPolicies:i.filter(d=>d.status==="bound").length,premiumUnderMgmt:i.filter(d=>d.status==="bound").reduce((d,L)=>d+(L.finalPremium??L.premiumEstimate??0),0),renewalsUpcoming:R.length,openActivities:r.filter(d=>!d.completedAt).length,inProgress:r.filter(d=>h.tasks.statusOf(d)==="in_progress").length,resolvedLast30:o.length,resolvedLifetime:r.filter(d=>d.completedAt).length,avgHandleMs:u.length?X(u):null,avgAckMs:m.length?X(m):null,inbou
21ndRequests:k.length,responseRate:k.length===0?null:C.length/k.length,outboundMessages:a.length,docsUploaded:b,openClaims:w.filter(d=>d.status!=="closed").length,closedClaims:A.length,avgClaimCloseMs:M.length?X(M):null,pendingInbound:p.length}},[l,t])}function X(l){return l.reduce((t,n)=>t+n,0)/l.length}function O(l){const t=Math.round(l/6e4);if(t<1)return"<1m";if(t<60)return`${t}m`;const n=Math.floor(t/60),s=t%60;if(n<24)return s?`${n}h ${s}m`:`${n}h`;const i=Math.floor(n/24),r=n%24;return r?`${i}d ${r}h`:`${i}d`}export{gs as AnalyticsPage};

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.