1import{a3 as An,b4 as En,a4 as Rn,r as h,j as t,aI as si,c as zn,b6 as gt,S as Yt,cX as ii,cY as Fi,cZ as Pi,c_ as Hi,c$ as Bi,aD as Mt,d0 as Ki,d1 as we,d2 as Wt,aF as oi,_ as Ui,J as qi,d3 as Yi,d4 as Vi,d5 as Gi,d6 as ys,c0 as Zi,d7 as Hn,d8 as li,d9 as Xi,da as Ji,db as Qi,dc as Bn,dd as rs,de as eo,df as Kn,dg as to,dh as no,di as so,dj as io,dk as oo,dl as lo,dm as ao,dn as mn,dp as ro,b3 as Un,dq as co}from"./index-CyIDn5oY.js";import{f as un,s as qn}from"./flagPerson-DrgTFns8.js";import{e as po,g as Yn,S as ho,a as mo,s as bs,d as uo,M as fo,b as go,r as xo}from"./coaching.functions-3JZr0e6b.js";import{c as yo,l as bo,s as vo,d as wo,e as vs,f as ws,r as jo,k as Vn,h as ko}from"./digest.functions-Cx7M_Ynq.js";import{P as So}from"./PeriodRange-CYqz4Q2g.js";import{T as cs}from"./Toggle-C8FngQhV.js";import{D as $o}from"./OutboundBadge-3yBis-Nm.js";import{P as st,a as ds,p as js,c as No,g as To,S as zo,E as Co,D as Io}from"./DigestBody-D-SaqcTs.js";import{u as Wo,n as ks,a as Zt,b as Ao,o as Eo,p as Ro,h as Ln,g as Ss,c as $s,s as Do,d as Lo,e as Mo,f as _o,i as Oo,j as Fo,k as Po,l as ai,m as Ho,C as Bo,q as Ko,r as Uo}from"./CoachingNoteRow-CpqaxU7p.js";import"./agent-prefs-TJFuZYrl.js";import"./voices-D_CNCoPH.js";const ri="policy_not_followed",Pt="could_do_better",Gn=new Set(["competitor_mention_dispatcher","policy_not_followed"]),qo=new Set(["driver_conduct","negative_call"]),ln="missed_callback",ci=new Set(["negative_call","repeat_contact"]),Yo=new Set(["billing_dispute","churn_switching","competitor_mention_caller","operational_risk","price_objection","safety_incident","service_complaint","tech_issue","left_on_hold"]),Vo=14,Go=3,Zo=864e5,Xo={low:1,medium:2,high:3,critical:4},Cn=e=>e?Xo[e]??0:0;function Jo(e){if(!e)return null;const n=i=>String(i??"").trim().length>0;return!n(e.did)||!n(e.instead)||!n(e.whatHappened)||!n(e.betterLine)?null:e.kind==="miss"?"miss":e.kind==="praise"?"praise":null}const Qo=e=>/^\s*\[keyword/i.test(String(e??""));function di(e){const n=String(e??"").match(/^\s*\[policy:\s*([^\]]+)\]/i);return(n?n[1].replace(/\s+/g," ").trim():"")||null}function Ut(e){return String(e??"").replace(/^\s*\[\s*follow[- ]?up\b[^\]]*\]\s*/i,"").replace(/^\s*\[policy:\s*[^\]]*\]?\s*/i,"").replace(/^\s*\[keyword\s+"[^"]*"\]\s*/i,"").replace(/\s+/g," ").trim()}const el=e=>(e.match(/[\p{L}\p{N}
1']+/gu)??[]).length,pi=e=>e.note==="miss"&&ci.has(e.key);function hi(e){return e.key===Pt?!0:!e.key||Qo(e.quote)||Yo.has(e.key)?!1:e.key===ln?e.speaker==="dispatcher":Gn.has(e.key)||e.speaker==="dispatcher"&&qo.has(e.key)?!0:pi(e)}function tl(e){return e.severity==="low"&&!pi({key:e.key??"",note:e.note})?"low severity":null}const Ns=e=>hi(e)&&tl({key:e.key,severity:e.severity??null,note:e.note})===null,nl=e=>e.key!==Pt&&hi({...e,note:null})&&e.severity!=="low"&&e.speaker==="dispatcher"&&el(Ut(e.quote))>=Go,Ts=e=>{const n=e.speaker==="dispatcher"?Ut(e.quote):"";return n||null},dt=e=>String(e??"").normalize("NFD").replace(new RegExp("\\p{M}+","gu"),"").replace(/[ââ]/g,"'").replace(/\s+/g," ").trim().toLowerCase(),Kt=e=>dt(e).split(" ")[0]??"";function zs(e,n){const i=dt(e),o=dt(n);return!i||!o?!1:i===o?!0:i.includes(" ")&&o.includes(" ")?!1:Kt(i)===Kt(o)}const sl=/^\s*(?:the\s+|our\s+)?(?:agent|dispatcher|reservationist|representative|rep|staff member|employee|colleague|coworker|co-worker|operator|csr)\b\s*/i,_t="\\p{Lu}[\\p{L}'â.-]*",il=new RegExp(`^(?:\\(\\s*(${_t}(?:\\s+${_t})?)\\s*\\)|,\\s*(${_t}(?:\\s+${_t})?)\\s*,|(${_t}(?:\\s+${_t})?)(?=[\\s,.;:]|$))`,"u"),ol=e=>{const n=e.replace(/\s+/g," ").trim(),i=n.match(new RegExp("^.+?[.?!](?=\\s+\\p{Lu}|$)","u"));return(i?i[0]:n).trim()};function Zn(e,n){const i=n.filter(o=>dt(o.name)===dt(e));return i.length?i:dt(e).includes(" ")?n.filter(o=>Kt(o.name)===Kt(e)&&dt(o.name).startsWith(dt(e))):n.filter(o=>Kt(o.name)===dt(e))}const Cs=(e,n)=>n.length===1?{name:n[0].name,known:!0}:{name:e,known:!1};function Is(e,n,i={}){const o=ol(Ut(e));if(!o)return null;const a=o.match(sl);if(a){const b=o.slice(a[0].length).match(il),f=b?(b[1]??b[2]??b[3]??"").trim():"";return f?Cs(f,Zn(f,n)):null}if(i.leading===!1)return null;const d=dt(o);let c=null;for(const b of n)for(const f of[dt(b.name),Kt(b.name)]){if(!f||d.startsWith(f)===!1)continue;const j=d.charAt(f.length);j&&/[\p{L}\p{N}]/u.test(j)||(!c||f.length>c.name.length)&&(c={name:f,hits:[]})}return c?Cs(c.name,Zn(c.name,n)):null}function Ws(e){if(e.ownerIsDesk)return e.owner;const n=Is(e.did,e.staff)??Is(e.quote,e.staff,{leading:!1});return!n||zs(n.name,e.owner)||n.known===!1&&Zn(n.name,e.staff).some(i=>zs(i.name,e.owner))?e.owner:n.known?n.name:null}function mi(e,n){const i=[Cn(e.severity)-Cn(n.severity),Number(Gn.has(e.key))-Number(Gn.has(n.key)),Ut(e.quote).length-Ut(n.quote).length];for(const o of i)if(o!==0)return o>0;return!1}const ll=e=>{if(e.key!==ri)return e.key;const n=di(e.quote);return n?`policy:${n.toLowerCase()}`:e.key};function al(e,n=Vo){const i=n*Zo,o=[...e].sort((c,b)=>b.at-c.at||c.callId.localeCompare(b.callId)),a=new Map,d=[];for(const c of o){const b=`${c.person}\0${c.habit}`,f=a.get(b);if(f&&f.lastAt-c.at<=i){f.moments.push(c),f.count++,f.firstAt=c.at,mi(c.shown,f.lead.shown)&&(f.lead=c);continue}const j={person:c.person,habit:c.habit,lead:c,moments:[c],count:1,firstAt:c.at,lastAt:c.at};a.set(b,j),d.push(j)}return d}const rl={driver_conduct:["language","profanity","professional","professionalism","courtesy","courteous","respect","respectful","conduct","manners","swearing","curse","cursing","polite"],negative_call:["tone","courtesy","courteous","empathy","attitude","professional","professionalism","calm","respect","polite","friendly"],missed_callback:["callback","callbacks","follow","followup","return","promise","promised"],competitor_mention_dispatcher:["competitor","competitors","referral","referrals","refer","partner","partners"]},cl=new Set(["about","after","again","also","because","been","before","call","calls","caller","could","does","from","have","here","into","just","know","like","make","more","need","only","over","said","same","should","some","that","their","them","then","there","they","this","those","through","very","want","what","when","where","which","will","with","would","your","yeah","okay","right","going","gonna","sure","well","thank","thanks","training","coaching","note","notes","policy","followed","flag","flagged"]),Mn=e=>new Set((String(e??"").normalize("NFD").replace(new RegExp("\\p{M}+","gu"),"").toLowerCase().match(/[a-z]+/g)??[]).filter(n=>n.length>=4&&!cl.has(n))),_n=(e,n)=>{let i=0;for(const o of e)n.has(o)&&i++;return i},Ot=e=>String(e??"").replace(/\s+/g," ").trim().toLowerCase();function dl(e,n){const i=e.key===ri?di(e.quote):null,o=Mn(`${e.label??""} ${Ut(e.quote)} ${i??""}`),a=new Set(rl[e.key]??[]),d=Mn(`${n.label} ${n.text??""}
1 ${n.policyTitle??""}`),c=_n(o,d),b=_n(a,d);return n.kind==="policy"?i&&Ot(i)===Ot(n.policyTitle??n.label)?100:i?0:b>0&&_n(a,Mn(n.policyTitle??n.label))>0?40+b:c>=2?30+c:0:n.kind==="coaching"?n.person&&e.person&&Ot(n.person)!==Ot(e.person)?0:i&&n.policyTitle&&Ot(i)===Ot(n.policyTitle)?90:c>=2?60+c+b:b>0?45+b:0:n.polarity&&n.polarity!=="is"||!n.ruleKey||n.ruleKey!==e.key?0:50+c}function Xt(e,n){let i=null;for(const o of n){const a=dl(e,o);a>0&&(!i||a>i.score)&&(i={source:o,score:a})}return i}function pl(e){return[...e].sort((n,i)=>Number(i.matched)-Number(n.matched)||i.count-n.count||Cn(i.severity)-Cn(n.severity)||i.at-n.at)}function hl(e,n){return{callId:n.callId,key:ln,quote:n.line,severity:e.severity,speaker:"dispatcher",at:e.at,person:n.owner.name,promiseCallId:n.callId,flagCallId:e.callId}}const ml=e=>!!e&&e.grade==="could_do_better"&&e.cause==="agent",ul=ml,fl=e=>e?e.moment??e.why:null,gl="TELESERV",xl=e=>/\bdesk$/i.test(e.trim())?e.trim():`${e.trim()} desk`,yl="Busiest week on record",bl=e=>e==="two_weeks"?"Two weeks":e==="month"?"This month":e==="custom"?"This period":"This week",As=e=>`${e} so far`,vl="Keep doing this",wl=(e,n,i)=>e?`Matched to what ${n||"your company"} asks of every call.`:`What went well ${i}.`,jl={call:"Call",email:"Email"},kl={happier:"Customer care",positive_plain:"Customer care",clean:"Clean handling",one_call:"Sorted first time",record:"Record volume",calls_plain:"Steady work"},Sl="What went well",ui=e=>(e.priority?e.priority.trim():"")||kl[e.id]||Sl,fi="Policy issue",$l="/email/score-confetti.png",Nl={call:"Hear the call",email:"Read the email"},Tl=e=>`${e.toLocaleString("en-US")} ${e===1?"moment":"moments"}`,zl="Where to improve",Es={did:"What happened",instead:"Next time, try"};function Cl(e,n,i,o,a=null){if(e===0)return n===0?`Nothing to work on ${o}. Keep it up.`:`Nothing picked to work on ${o}.`;const d=`${a?`The ${xl(a)} had`:"You had"} ${Tl(n)} to work on ${o}.`;return e===1?n<=1?`One moment to work on ${o}.`:`${d} This is the one that matters most.`:i*2>n?`${d} Most were the same ${e} habits, so these are the ${e} that matter.`:`${d} These ${e} matter most.`}const Il=(e,n,i,o=null)=>{const a=e==="week"?"Last week's focus":o?"The desk's last focus":"Your last focus";return n?`${a}, done.`:i?`${a} is moving the right way.`:`${a} is still one to work on.`},gi=e=>e||"Your manager",Wl="Read it? Tell us what you think.",Al="One click lets your manager know you've seen it, and you can add a note too. No login needed.",El="One click records that you've read it, and you can add a note too. No login needed.",Rs="Acknowledge and add a note",an=3,rn=2,Ct={headline:120,intro:900,winNote:300,note:1200};function Jt(e,n){const i=String(e??"").replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g,"").replace(/\r\n?/g,` 2`).replace(/\s*[\u2014\u2013]\s*/g,", ").replace(/[ \t]+/g," ").replace(/\n{3,}/g,` 3 4`).trim();return i.length>n?i.slice(0,n).trim():i}function Rl(e,n){const i=e&&typeof e=="object"?e:{},o={},a=new Set(n.wins.map(j=>j.id)),d=new Set(n.improve.map(j=>j.id)),c=(j,g,p)=>{if(Array.isArray(j)===!1)return null;const v=[];for(const N of j){const W=String(N??"");g.has(W)&&v.includes(W)===!1&&v.push(W)}return j.length>0&&v.length===0?null:v.slice(0,p)};typeof i.headline=="string"&&(o.headline=Jt(i.headline,Ct.headline)),typeof i.intro=="string"&&(o.intro=Jt(i.intro,Ct.intro)),typeof i.confetti=="boolean"&&(o.confetti=i.confetti);const b=c(i.wins,a,an);b&&(o.wins=b);const f=c(i.improve,d,rn);if(f&&(o.improve=f),i.winNotes&&typeof i.winNotes=="object"){const j={};for(const[g,p]of Object.entries(i.winNotes)){const v=a.has(g)?Jt(p,Ct.winNote):"";v&&(j[g]=v)}o.winNotes=j}return typeof i.note=="string"&&(o.note=Jt(i.note,Ct.note)),typeof i.noteBy=="string"&&(o.noteBy=Jt(i.noteBy,80)||null),typeof i.savedAt=="string"&&(o.savedAt=i.savedAt),o}function xi(e,n){const i=n?Rl(n,e):{},o=new Map(e.wins.map(W=>[W.id,W])),a=new Map(e.improve.map(W=>[W.id,W])),d=i.wins??e.winsDefault,c=i.improve??e.improveDefault,b=i.winNotes??{},f=[];for(const W of d.slice(0,an)){const T=o.get(W);T&&f.push({...T,word:b[W]?b[W]:null})}const j=[];for(const W of c.slice(0,rn)){const T=a.get(W);T&&j.push(T)}const g=i.headline?i.headline:e.headline,p=i.intro?i.intro:e.intro,v=i.note?i.note:null,N=Object.keys(i).some(W=>!(W==="savedAt"||W==="noteBy"));return{...e,headline:g,intro:p,wins:f,improve:j,note:v,noteBy:i.noteBy??null,confettiOn:typeof i.confetti=="boolean"?i.confetti:e.confetti,edited:N}}const B=e=>String(e??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Xn=e=>B(e).replace(/\n/g,"<br>"),oe="-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif",xt="'Source Serif 4',Georgia,'Times New Roman',serif",z={page:"#f3f2f2",card:"#ffffff",ink:"#201e1d",muted:"#6b6864",soft:"#8a8784",line:"#e6e4e1",teal:"#004961",tealText:"#d6eef7",tealSoft:"#a8dcef",tealSub:"#c6e6f2",gold:"#ffd166",goldInk:"#3d2900",link:"#006786",tint:"#e3f4fb",grey:"#f6f6f4",amber:"#a86a16",amberBg:"#fdf6e8",amberLine:"#ecd9b5",amberChip:"#8a5510",rose:"#aa0b56",roseBg:"#fbe7ef",cream:"#fff8e6",green:"#1e5a3a",greenBg:"#e8f5ec"},Ds="#406b62";function Dl(e){const n=e.score.week,i=e.score.ytd;if(n===null&&i===null)return"";const o=n===null?i:n,a=n===null?As(e.score.year):bl(e.period),d=n===null||i===null?"":`<div style="font-family:${oe};font-size:12.5px;line-height:16px;font-weight:500;color:${z.tealSub};text-align:center">${B(As(e.score.year))} <b style="font-family:${xt};font-size:15px;font-weight:700;color:${z.gold}">${i}</b></div>`,c=e.confettiOn&&e.appUrl?`${String(e.appUrl).replace(/\/+$/,"")}${$l}`:"",b=c?` background="${B(c)}"`:"",f=c?`background-image:url('${B(c)}');background-repeat:no-repeat;background-position:0 0;background-size:190px 176px;`:"",j=`<div style="font-family:${xt};font-size:44px;line-height:44px;font-weight:600;color:${z.goldInk}">${o}
4</div> 5<div style="font-family:${oe};font-size:10.5px;line-height:13px;letter-spacing:1px;text-transform:uppercase;font-weight:700;margin-top:3px;color:${z.goldInk}">${B(a)}</div>`;return`<td class="ts-score" width="190" valign="middle" align="center" style="width:190px"> 6<table role="presentation" width="190" cellpadding="0" cellspacing="0" border="0" align="center" style="width:190px;margin:0 auto"><tr> 7<td width="190" height="176" valign="top" align="center"${b} style="width:190px;height:176px;${f}"> 8<div style="height:12px;line-height:12px;font-size:1px"> </div> 9<!--[if mso]><v:oval xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroked="true" strokecolor="${Ds}" strokeweight="4.5pt" style="width:118px;height:118px;v-text-anchor:middle"><v:fill type="solid" color="${z.gold}"/><v:textbox inset="0,0,0,0"><center>${j}</center></v:textbox></v:oval><![endif]--> 10<!--[if !mso]><!--><table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin:0 auto"><tr><td width="112" height="112" align="center" valign="middle" style="width:112px;height:112px;border:6px solid ${Ds};border-radius:62px;background:${z.gold};color:${z.goldInk};text-align:center"> 11${j} 12</td></tr></table><!--<![endif]--> 13<div style="height:10px;line-height:10px;font-size:1px"> </div> 14${d} 15</td></tr></table> 16</td>`}function Ll(e){return e.stats.length===0?"":`<tr><td style="padding:30px 40px 6px" class="ts-pad"><table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr>${e.stats.map((i,o)=>{const a=i.key!=="handled",d=a?z.tint:z.grey;return`<td class="ts-stat" valign="top" width="${Math.floor(100/e.stats.length)}%" style="padding:${o===0?"0 5px 0 0":o===e.stats.length-1?"0 0 0 5px":"0 5px"}"> 17<div style="background:${d};border-radius:14px;padding:14px 16px 15px"> 18<div style="font-family:${oe};font-size:11px;line-height:14px;letter-spacing:0.9px;text-transform:uppercase;font-weight:700;color:${a?z.link:z.muted}">${B(i.label)}</div> 19<div style="font-family:${xt};font-size:32px;line-height:34px;font-weight:600;margin-top:6px;color:${a?z.teal:z.ink}">${B(i.value)}</div> 20${i.sub?`<div style="font-family:${oe};font-size:12px;line-height:16px;color:${z.muted};margin-top:4px">${B(i.sub)}</div>`:""} 21</div></td>`}).join("")}</tr></table></td></tr>`}const Jn=(e,n,i,o=null)=>`<span style="display:inline-block;font-family:${oe};font-size:11.5px;line-height:15px;font-weight:700;padding:3px 10px;border-radius:999px;background:${n};color:${i};${o?`border:1px solid ${o};`:""}">${B(e)}</span>`,yi=e=>`<span style="font-family:${oe};font-size:11.5px;line-height:15px;color:${z.muted};margin-left:8px">${B(jl[e])}</span>`,bi=(e,n)=>e?`<div style="margin-top:12px"><a href="${B(e)}" style="font-family:${oe};font-size:13px;line-height:17px;font-weight:600;color:${z.link};text-decoration:none">${B(Nl[n])}</a></div>`:"",Ls=(e,n,i,o,a)=>`<table role="presentation" cellpadding="0" cellspacing="0" border="0"><tr> 22<td width="32" height="32" align="center" valign="middle" style="width:32px;height:32px;border-radius:10px;background:${n};color:${i};font-family:${oe};font-size:17px;line-height:32px">${e}</td> 23<td style="padding-left:10px"><h2 style="margin:0;font-family:${xt};font-size:24px;line-height:30px;font-weight:600;color:${z.ink}">${B(o)}</h2></td> 24</tr></table>${a?`<p style="margin:6px 0 0 42px;font-family:${oe};font-size:14px;line-height:21px;color:${z.muted}">${a}</p>`:""}`;function Ml(e,n,i){const o=e.callId?i.call(e.callId):null;return`<div style="border:1px solid ${z.line};border-radius:16px;padding:18px 20px;margin-top:12px"> 25<div>${Jn(ui(e),z.tint,z.teal)}${yi(e.kind)}</div> 26<div style="font-family:${oe};font-size:17px;line-height:23px;font-weight:700;margin-top:10px;color:${z.ink}">${B(e.title)}</div> 27<div style="font-family:${oe};font-size:14px;line-height:22px;color:#4a4745;margin-top:6px">${B(e.text)}</div> 28${e.example?`<div style="font-family:${oe};font-size:13px;line-height:20px;color:${z.muted};margin-top:6px">${B(e.example)}</div>`:""} 29${e.word?`<div style="margin-top:12px;background:${z.cream};border-radius:12px;padding:11px 14px"><div style="font-family:${xt};font-style:italic;font-size:14px;line-height:21px;color:${z.ink}">“${Xn(e.word)}”</div><div style="font-family:${oe};font-size:12px;line-height:16px;color:${z.muted};margin-top:3px">${B(gi(n))}</div></div>`:""} 30${bi(o,e.kind)} 31</div>`}function _l(e,n,i){const o=e.callId?i.call(e.callId):null,a=n===1;return`<div style="border:1px solid ${a?z.amberLine:z.line};background:${a?z.amberBg:"#fbfaf7"};border-radius:16px;padding:18px 20px;margin-top:12px"> 32<div><span style="display:inline-block;width:22px;height:22px;line-height:22px;border-radius:11px;background:${z.amber};color:#ffffff;font-family:${oe};font-size:12px;font-weight:700;text-align:center;margin-right:8px">${n}</span>${e.priority?Jn(e.priority,"#ffffff",z.amberChip,z.amberLine):""}${e.matched?`<span style="display:inline-block;width:6px"></span>${Jn(fi,z.roseBg,z.rose)}`:""}${yi(e.kind)}</div> 33<div style="font-family:${oe};font-size:17px;line-height:23px;font-weight:700;margin-top:10px;color:${z.ink}">${B(e.title)}</div> 34<div style="font-family:${oe};font-size:12.5px;line-height:17px;color:${z.muted};margin-top:3px">${B(e.countLine)}</div> 35<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-top:12px"><tr> 36<td class="ts-half" valign="top" width="50%" style="padding-right:5px"><div style="background:#ffffff;border-radius:12px;padding:12px 14px"> 37<div style="font-family:${oe};font-size:11px;line-height:14px;letter-spacing:0.9px;text-transform:uppercase;font-weight:700;color:${z.rose}">${B(Es.did)}</div> 38<div style="font-family:${oe};font-size:13.5px;line-height:20px;margin-top:5px;color:${z.ink}">${B(e.did)}</div></div></td> 39<td class="ts-half" valign="top" width="50%" style="padding-left:5px"><div style="background:#ffffff;border-radius:12px;padding:12px 14px"> 40<div style="font-family:${oe};font-size:11px;line-height:14px;letter-spacing:0.9px;text-transform:uppercase;font-weight:700;color:${z.link}">${B(Es.instead)}</div> 41<div style="font-family:${xt};font-style:italic;font-size:14.5px;line-height:21px;margin-top:5px;color:${z.ink}">${B(e.instead)}</div></div></td> 42</tr></table> 43${bi(o,e.kind)} 44</div>`}const Ol=e=>e.reduce((n,i)=>n+i.count,0);function Fl(e,n){const i=e.record?`<div style="margin-top:30px"><span style="display:inline-block;background:${z.gold};color:#4a3200;font-family:${oe};font-size:12.5px;line-height:16px;font-weight:700;padding:5px 12px;border-radius:999px">${B(yl)}</span></div>`:"",o=Dl(e),a=`<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-top:${e.record?"14px":"30px"}"><tr> 45<td class="ts-hero" valign="middle" style="padding-right:${o?"22px":"0"}"> 46<h1 style="margin:0;font-family:${xt};font-size:38px;line-height:43px;font-weight:600;color:#ffffff;letter-spacing:-0.2px">${B(e.headline)}</h1> 47<p style="margin:10px 0 0;font-family:${oe};font-size:16px;line-height:25px;color:${z.tealText}">${Xn(e.intro)}</p> 48</td> 49${o} 50</tr></table>`,d=e.wins.some(N=>N.matched),c=e.wins.length?`<tr><td class="ts-pad" style="padding:30px 40px 0">${Ls("★",z.tint,z.link,vl,B(wl(d,e.orgName,e.span)))}${e.wins.map(N=>Ml(N,e.noteBy,n)).join("")}</td></tr>`:"",b=e.loop?`<div style="margin-top:16px;
50background:${e.loop.done||e.loop.now<e.loop.before?z.greenBg:z.amberBg};border-radius:12px;padding:11px 14px;font-family:${oe};font-size:13.5px;line-height:20px;color:${e.loop.done||e.loop.now<e.loop.before?z.green:z.amberChip}"><b>${B(Il(e.period,e.loop.done,e.loop.now<e.loop.before,e.deskName??null))}</b> ${B(e.loop.line)}</div>`:"",f=`<tr><td class="ts-pad" style="padding:32px 40px 0">${Ls("↑","#f5ead6",z.amber,zl,B(Cl(e.improve.length,e.moments,Ol(e.improve),e.span,e.deskName??null)))}${b}${e.improve.map((N,W)=>_l(N,W+1,n)).join("")}</td></tr>`,j=(e.noteBy||"M").trim().charAt(0).toUpperCase()||"M",g=e.note?`<div style="margin-bottom:18px;padding:18px 20px;border-radius:16px;background:${z.cream}"><table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%"><tr> 51<td width="40" valign="top" style="width:40px"><div style="width:40px;height:40px;line-height:40px;border-radius:20px;background:${z.gold};color:${z.goldInk};text-align:center;font-family:${xt};font-weight:600;font-size:15px">${B(j)}</div></td> 52<td valign="top" style="padding-left:14px"><div style="font-family:${xt};font-size:16.5px;line-height:25px;color:${z.ink}">${Xn(e.note)}</div><div style="font-family:${oe};font-size:12.5px;line-height:17px;color:${z.muted};margin-top:6px">${B(gi(e.noteBy))}</div></td> 53</tr></table></div>`:"",p=n.ack?`<a href="${B(n.ack)}" style="display:inline-block;margin-top:16px;background:${z.gold};color:${z.goldInk};font-family:${oe};font-size:15.5px;line-height:20px;font-weight:700;padding:13px 24px;border-radius:12px;text-decoration:none">${B(Rs)}</a>`:`<span style="display:inline-block;margin-top:16px;background:${z.gold};color:${z.goldInk};font-family:${oe};font-size:15.5px;line-height:20px;font-weight:700;padding:13px 24px;border-radius:12px">${B(Rs)}</span>`,v=`<!--ack--><div style="background:${z.teal};border-radius:18px;padding:24px 24px 22px;text-align:center"> 54<div style="font-family:${xt};font-size:22px;line-height:28px;font-weight:600;color:#ffffff">${B(Wl)}</div> 55<div style="font-family:${oe};font-size:14px;line-height:21px;color:${z.tealSub};margin-top:6px">${B(e.deskName?El:Al)}</div> 56${p} 57</div><!--/ack-->`;return`<!doctype html> 58<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="light"><title>${B(e.headline)}</title> 59<style> 60@media (max-width:620px){ 61.ts-pad{padding-left:20px !important;padding-right:20px !important} 62.ts-head{padding:26px 20px 28px !important} 63.ts-hero,.ts-score{display:block !important;width:100% !important;padding:0 !important} 64.ts-score{padding-top:18px !important} 65.ts-stat,.ts-half{display:block !important;width:100% !important;padding:0 0 10px !important} 66h1{font-size:30px !important;line-height:35px !important} 67} 68</style></head> 69<body style="margin:0;padding:0;background:${z.page}"> 70<div style="display:none;max-height:0;overflow:hidden;opacity:0;color:transparent">${B(e.preheader)}</div> 71<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:${z.page}"><tr><td align="center" style="padding:20px 12px 40px"> 72<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="max-width:680px;background:${z.card};border-radius:20px;border:1px solid ${z.line};border-collapse:separate;overflow:hidden"> 73<tr><td class="ts-head" style="background:${z.teal};padding:34px 40px 36px;border-radius:20px 20px 0 0"> 74<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0"><tr> 75<td style="font-family:${oe};font-size:12px;line-height:16px;letter-spacing:2.6px;font-weight:700;color:#ffffff">${B(gl)}</td> 76<td align="right" style="font-family:${oe};font-size:11.5px;line-height:16px;letter-spacing:1.1px;text-transform:uppercase;color:${z.tealSoft}">${B(e.head)} · ${B(e.range)}</td> 77</tr></table> 78${i} 79${a} 80</td></tr> 81${Ll(e)} 82${c} 83${f} 84<tr><td class="ts-pad" style="padding:32px 40px 36px"> 85${g} 86${v} 87<div style="font-family:${oe};font-size:12px;line-height:19px;color:${z.soft};text-align:center;margin-top:18px">${B(e.footer)}</div> 88</td></tr> 89</table> 90</td></tr></table> 91</body></html>`}const On=90,Pl=100,Hl=7;function Bl(e,n){const i=e?Date.parse(e):NaN;return Number.isFinite(i)?n-i>=Hl*864e5:!1}const Ms=e=>{const n=Date.parse(e);return Number.isFinite(n)?n:0},_s=e=>e.flags.length>0||(typeof e.sentiment=="number"?e.sentiment<=-.1:!1);function Kl(e,n=Pl){const i=(d,c)=>Ms(c.occurred_at)-Ms(d.occurred_at),o=e.filter(_s).sort(i),a=e.filter(d=>_s(d)===!1).sort(i);return[...o,...a].slice(0,Math.max(0,n))}function Os(e,n){const i=new Date(e);try{return new Intl.DateTimeFormat("en-US",{timeZone:n,weekday:"long",month:"long",day:"numeric"}).format(i)}catch{return new Intl.DateTimeFormat("en-US",{weekday:"long",month:"long",day:"numeric"}).format(i)}}const Ul=e=>`${e} ${e===1?"call":"calls"}`,_e={title:e=>`${e}'s summary`,strengths:"Strengths",improvements:"Areas to work on",noImprovements:"Nothing stands out to work on.",updated:(e,n)=>`Updated ${e} from ${Ul(n)} in the last ${On} days.`,checked:e=>`Checked ${e}: no new calls since.`,opening:"Opening the summary.",beingWritten:e=>`${e}'s summary is being written. It appears within the hour.`,firstComes:e=>`${e}'s first summary comes once they have a week of calls.`,noCalls:e=>`${e} has no calls in the last ${On} days, so there is no summary yet.`,rehearsal:"Summaries are not written for a rehearsal company.",refresh:"Refresh",refreshing:"Refreshingâ¦",refreshTitle:e=>`Write ${e}'s summary again now from their last ${On} days of calls`,refreshSlow:"The new summary is taking longer than usual. It shows here once it is written.",tooSoon:"Refreshed a few minutes ago. Try again later."},ql=2,Yl=240,Vl=60,Gl=new RegExp(`[.?\\x21]["'ââ)]*(?=\\s+["'ââ(]?\\p{Lu}|\\s*$)`,"gu");function Zl(e,n=Yl){const i=String(e??"").trim();if(i.length<=n)return i;let o=0,a=0;for(const b of i.matchAll(Gl)){const f=(b.index??0)+b[0].length;if(f>n){a=f;break}o=f}if(o>0)return i.slice(0,o);if(a>0&&a<=n+Vl)return i.slice(0,a);const d=i.slice(0,n),c=d.lastIndexOf(" ");return`${(c>n/2?d.slice(0,c):d).replace(/[\s,;:]+$/,"")}â¦`}const Fs=e=>(e??[]).slice(0,ql).map(n=>({...n,detail:Zl(n.detail)}));function Qn(e){return{...e,strengths:Fs(e.strengths),improvements:Fs(e.improvements)}}function jt(e){const n=Math.max(0,Math.round(e));if(n<60)return`${n}m`;if(n<1440){const a=Math.floor(n/60),d=n%60;return d?`${a}h ${d}m`:`${a}h`}const i=Math.floor(n/1440),o=Math.floor(n%1440/60);return o?`${i}d ${o}h`:`${i}d`}const zt=120,Xl=An({method:"POST"}).middleware([En]).handler(Rn("62303c739936bbb26ce3d14f6cd54e849f44fe9a3d358777098f17e87135953a")),Jl=An({method:"POST"}).middleware([En]).handler(Rn("f6079e9f9af0a822d30de9d1901f6205f8e5755865f799578c454d253f8da2c1")),Ql=An({method:"POST"}).middleware([En]).handler(Rn("dd502b47011fdc05350befb63e2aeb87cdedba98de82418e48d30ab9e1db6c52")),ea=220,ta='<base target="_blank">';function na(e,n){return Fl(xi(e,n),{ack:null,call:o=>`/calls?period=all&call=${o}`}).replace(/<head[^>]*>/i,`$&${ta}`)}function sa({summary:e,edits:n,from:i,to:o}){const a=h.useMemo(()=>na(e,n),[e,n]),[d,c]=h.useState(a);return h.useEffect(()=>{if(a===d)return;const b=window.setTimeout(()=>c(a),ea);return()=>window.clearTimeout(b)},[a,d]),t.jsxs("div",{style:{minWidth:0},children:[t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,flexWrap:"wrap",fontSize:12.5,color:"color-mix(in srgb, #201e1d 55%, transparent)",padding:"0 4px 8px"},children:[t.jsxs("span",{children:["From ",t.jsx("b",{style:{color:"#201e1d"},children:i})]}),t.jsx("span",{children:o})]}),t.jsx("div",{style:{borderRadius:20,overflow:"hidden",border:"1px solid var(--color-divider)",background:"#f3f2f2"},children:t.jsx(si,{html:d,title:"Weekly summary preview",popups:!0})})]})}const ia=700,vi="#201e1d",Ps="#0088b0",Hs="#a86a16",ve=e=>`color-mix(in srgb, ${vi} ${e}%, transparent)`,vn={fontSize:11,letterSpacing:".09em",textTransform:"uppercase",fontWeight:700,color:ve(52)},Bs={display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",fontSize:11.5,color:ve(55),marginTop:4},ps={display:"inline-block",fontSize:11,lineHeight:"15px",fontWeight:700,padding:"1px 8px",borderRadius:999,whiteSpace:"nowrap"},oa={...ps,background:"#e3f4fb",color:"#004961"},la={...ps,background:"#fff",color:"#8a5510",border:"1px solid #ecd9b5"},aa={...ps,background:"#fbe7ef",color:"#aa0b56"},wn={border:`1px solid ${ve(16)}`,borderRadius:10,padding:"9px 11px",fontSize:13,lineHeight:1.5,color:vi,background:"#fff",width:"100%",boxSizing:"border-box",fontFamily:"inherit"},Ks=e=>({width:18,height:18,borderRadius:5,border:`1.5px solid ${e?Ps:ve(30)}`,background:e?Ps:"#fff",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"none",marginTop:1,padding:0,cursor:"pointer"});function ra(e){const{summary:n}=e,[i,o]=h.useState(()=>e.edits??{}),[a,d]=h.useState(()=>e.edits?.savedAt?{kind:"saved",at:e.edits.savedAt}:{kind:"idle"}),[c,b]=h.useState(null),f=h.useRef(null),j=h.useRef(void 0),g=h.useRef(0),p=h.useCallback(async()=>{f.current&&(clearTimeout(f.current),f.current=null);const w=j.current;if(w===void 0)return;j.current=void 0;const P=++g.current;d({kind:"saving"});try{const D=await Ql({data:{id:e.id,edits:w?{headline:w.headline,intro:w.intro,confetti:w.confetti,wins:w.wins,winNotes:w.winNotes,improve:w.improve,note:w.note}:null}});P===g.current&&d(D.savedAt?{kind:"saved",at:D.savedAt}:{kind:"idle"})}catch(D){P===g.current&&d({kind:"error",text:D instanceof Error?D.message:"Couldn't save the change."})}},[e.id]),v=h.useCallback(w=>{j.current=w,f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{p()},ia)}
91,[p]);h.useEffect(()=>()=>{j.current!==void 0&&p()},[p]);const N=w=>o(P=>{const D={...P,...w};return v(D),D}),W=h.useMemo(()=>xi(n,i),[n,i]),T=W.wins.map(w=>w.id),_=W.improve.map(w=>w.id),O=w=>{if(T.includes(w)){N({wins:T.filter(P=>P!==w)}),b(null);return}if(T.length>=an){b(`Up to ${an} wins go in. Untick one first.`);return}b(null),N({wins:[...T,w]})},U=w=>{if(_.includes(w)){N({improve:_.filter(P=>P!==w)}),b(null);return}if(_.length>=rn){b(`Up to ${rn} habits go in. Untick one first.`);return}b(null),N({improve:[..._,w]})},ce=(w,P)=>{const D=[..._],Z=D.indexOf(w),te=Z+P;Z<0||te<0||te>=D.length||([D[Z],D[te]]=[D[te],D[Z]],N({improve:D}))},K=(w,P)=>N({winNotes:{...i.winNotes??{},[w]:P}}),q=async()=>{await zn({title:"Go back to TeleServ's draft?",body:"Your headline, intro, picks, words and note come out of this summary. TeleServ's draft goes back in as it was written.",confirmLabel:"Use TeleServ's draft"})&&(o({}),b(null),j.current=null,p())},Te=a.kind==="saving"?"Savingâ¦":a.kind==="saved"?`Saved ${e.fmtSaved(a.at)}`:a.kind==="error"?a.text:"Changes save as you go",ee=Object.keys(i).some(w=>w!=="savedAt"&&w!=="noteBy"),F=w=>w==="email"?"Email":"Call";return t.jsxs("div",{children:[t.jsxs("button",{className:"sc-back",onClick:()=>{p().then(e.onBack)},style:{padding:"0 0 12px"},children:[t.jsx("i",{className:"ph-duotone ph-arrow-left"}),"All summaries"]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(320px, 1fr))",gap:20,alignItems:"start"},children:[t.jsxs("div",{style:{position:"sticky",top:12,background:"#fbfbfb",border:`1px solid ${ve(14)}`,borderRadius:16,overflow:"hidden",display:"flex",flexDirection:"column",maxHeight:"calc(100vh - 24px)",minWidth:0},children:[t.jsxs("div",{style:{padding:"16px 18px 12px",borderBottom:`1px solid ${ve(10)}`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[t.jsx("span",{className:"serif",style:{fontSize:19,fontWeight:600},children:"Edit before it sends"}),t.jsx("span",{style:{fontSize:11.5,fontWeight:600,padding:"2px 9px",borderRadius:999,background:"#eef3f7",color:"#4e6579"},children:ee?"Draft, edited":"Draft"})]}),t.jsxs("div",{style:{fontSize:12.5,color:ve(55),marginTop:3},children:["TeleServ drafted this from ",e.first,"'s ",n.period==="week"?"week":n.period==="month"?"month":"two weeks",". Change anything; the preview updates."]})]}),t.jsxs("div",{style:{overflowY:"auto",padding:"14px 18px 18px",display:"flex",flexDirection:"column",gap:20},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.jsx("span",{style:vn,children:"Headline"}),t.jsx("input",{"aria-label":"Headline",value:i.headline??n.headline,placeholder:n.headline,maxLength:Ct.headline,onChange:w=>N({headline:w.target.value}),style:{...wn,fontSize:14,fontWeight:600,fontFamily:"'Source Serif 4', Georgia, serif"}}),t.jsx("textarea",{"aria-label":"Intro",value:i.intro??n.intro,placeholder:n.intro,maxLength:Ct.intro,rows:4,onChange:w=>N({intro:w.target.value}),style:{...wn,resize:"vertical"}}),t.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:8,fontSize:12.5,cursor:"pointer"},children:[t.jsx(cs,{checked:W.confettiOn,label:"Confetti",onChange:w=>N({confetti:w})}),"Confetti"]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8},children:[t.jsx("span",{style:{...vn,color:"#006786"},children:"Celebrate"}),t.jsxs("span",{style:{fontSize:12,color:ve(50)},children:[T.length," of ",an," picked"]})]}),n.wins.length===0&&t.jsx("div",{style:{fontSize:12.5,color:ve(50),lineHeight:1.5},children:"Nothing stood out to celebrate from these calls yet."}),n.wins.map(w=>{const P=T.includes(w.id),D=i.winNotes?.[w.id]??"";return t.jsxs("div",{style:{border:`1px solid ${P?"rgba(0,136,176,.35)":ve(10)}`,background:P?"#fff":"transparent",borderRadius:11,padding:"10px 11px"},children:[t.jsxs("div",{style:{display:"flex",gap:9,alignItems:"flex-start"},children:[t.jsx("button",{type:"button",role:"checkbox","aria-checked":P,"aria-label":`Celebrate: ${w.title}`,onClick:()=>O(w.id),style:Ks(P),children:P&&t.jsx("i",{className:"ph-bold ph-check",style:{fontSize:11}})}),t.jsxs("div",{style:{minWidth:0,flex:1,cursor:"pointer"},onClick:()=>O(w.id),children:[t.jsx("div",{style:{fontSize:13,fontWeight:600,lineHeight:1.35},children:w.title}),t.jsxs("div",{style:Bs,children:[t.jsx("span",{style:oa,children:ui(w)}
91),t.jsx("span",{children:[F(w.kind),w.meta].filter(Boolean).join(" · ")})]})]})]}),P&&t.jsxs(t.Fragment,{children:[t.jsx("input",{"aria-label":`A word from you on ${w.title}`,value:D,maxLength:Ct.winNote,onChange:Z=>K(w.id,Z.target.value),placeholder:"Add a word from you (shown in the email)",style:{...wn,marginTop:8,padding:"7px 9px",fontSize:12.5,borderRadius:8}}),w.praise&&!D.trim()&&t.jsxs("button",{type:"button",className:"sc-link",onClick:()=>K(w.id,w.praise),style:{marginTop:6,fontSize:12,textAlign:"left",lineHeight:1.45},children:[t.jsx("i",{className:"ph-duotone ph-quotes"}),"Use your note on this call: â",w.praise.length>90?`${w.praise.slice(0,90)}â¦`:w.praise,"â"]})]})]},w.id)})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8},children:[t.jsx("span",{style:{...vn,color:Hs},children:"Where to improve"}),t.jsxs("span",{style:{fontSize:12,color:ve(50)},children:[_.length," of ",rn," picked"]})]}),n.improve.length===0&&t.jsx("div",{style:{fontSize:12.5,color:ve(50),lineHeight:1.5},children:"No coaching moments in these calls."}),n.improve.map(w=>{const P=_.includes(w.id);return t.jsxs("div",{style:{border:`1px solid ${P?"#ecd9b5":ve(10)}`,background:P?"#fffaf0":"transparent",borderRadius:11,padding:"10px 11px",display:"flex",gap:9,alignItems:"flex-start"},children:[t.jsx("button",{type:"button",role:"checkbox","aria-checked":P,"aria-label":`Work on: ${w.title}`,onClick:()=>U(w.id),style:Ks(P),children:P&&t.jsx("i",{className:"ph-bold ph-check",style:{fontSize:11}})}),t.jsxs("div",{style:{minWidth:0,flex:1,cursor:"pointer"},onClick:()=>U(w.id),children:[t.jsx("div",{style:{fontSize:13,fontWeight:600,lineHeight:1.35},children:w.title}),t.jsxs("div",{style:Bs,children:[w.priority&&t.jsx("span",{style:la,children:w.priority}),w.matched&&t.jsx("span",{style:aa,children:fi}),t.jsx("span",{children:w.countLine})]})]}),P&&t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[t.jsx("button",{type:"button",title:"Move up","aria-label":`Move ${w.title} up`,onClick:()=>ce(w.id,-1),style:{border:"none",background:"transparent",padding:0,cursor:"pointer",color:ve(50),display:"inline-flex"},children:t.jsx("i",{className:"ph-duotone ph-caret-up",style:{fontSize:14}})}),t.jsx("button",{type:"button",title:"Move down","aria-label":`Move ${w.title} down`,onClick:()=>ce(w.id,1),style:{border:"none",background:"transparent",padding:0,cursor:"pointer",color:ve(50),display:"inline-flex"},children:t.jsx("i",{className:"ph-duotone ph-caret-down",style:{fontSize:14}})})]})]},w.id)}),t.jsx("div",{style:{fontSize:11.5,color:ve(50),lineHeight:1.45},children:"Ticked by TeleServ: the habits that came up most. Untick to soften the week; everything stays in the Feedback tab."})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[t.jsx("span",{style:vn,children:"A note from you"}),t.jsx("textarea",{"aria-label":"A note from you",value:i.note??"",maxLength:Ct.note,rows:3,placeholder:"Shown above the button, signed with your name.",onChange:w=>N({note:w.target.value}),style:{...wn,resize:"vertical"}})]}),c&&t.jsx("div",{style:{fontSize:12,color:Hs},children:c})]}),t.jsxs("div",{style:{padding:"12px 18px",borderTop:`1px solid ${ve(10)}`,display:"flex",gap:8,alignItems:"center",flexWrap:"wrap",background:"#fff"},children:[t.jsx("button",{className:"primary",onClick:()=>{p().then(e.onSend)},disabled:e.busy!==null||!e.canSend||a.kind==="saving",style:{padding:"9px 14px"},children:e.busy==="send"?"Sendingâ¦":"Send now"}),e.onRebuild&&t.jsxs("button",{className:"ghostbtn",onClick:e.onRebuild,disabled:e.busy!==null,title:"Build this week again from the latest calls. Your edits stay.",style:{padding:"8px 12px"},children:[t.jsx("i",{className:"ph-duotone ph-arrows-clockwise"}),e.busy==="rebuild"?"Rebuildingâ¦":"Rebuild"]}),ee&&t.jsx("button",{className:"sc-quiet",onClick:()=>{q()},disabled:e.busy!==null,children:"Use TeleServ's draft"}),t.jsx("span",{style:{marginLeft:"auto",fontSize:12,color:a.kind==="error"?"#aa0b56":ve(50)},children:Te})]}),e.sendHint&&t.jsx("div",{style:{padding:"0 18px 12px",fontSize:12,color:ve(55),background:"#fff",lineHeight:1.5},children:e.sendHint}),e.schedule&&t.jsx("div",{className:"sc-ed-sched",style:{padding:"12px 18px",borderTop:`1px solid ${ve(10)}`,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap",background:"#fff"},children:e.schedule})]}),t.jsx(sa,{summary:n,edits:i,from:e.from,to:e.to})]})]})}const ca="Policy issue",da=(e,n)=>n?.kind==="policy"||e.some(i=>!!i.slip||String(i.habit??"").startsWith("policy:")),hs={callIds:new Set,habits:new Set},pa="Other good calls",Us=2,ha={low:1,medium:2,high:3,critical:4},Ft=e=>e?ha[e]??0:0,qt=(e,n,i)=>`${e} ${e===1?n:i}`,Ht=e=>e.match?{kind:e.match.source.kind,id:e.match.source.id,label:e.match.source.label}:e.own??null,Sn=e=>e?`${e.kind}:${e.id}`:null,wi=(e,n)=>[e||!n?qt(e,"call","calls"):"",n?qt(n,"email","emails"):""].filter(
91Boolean).join(" · "),ma=(e,n,i)=>`${e} of ${qt(n,"moment","moments")}${i?" · a manager flagged it too":""}`,ua=e=>e>0?`+${e} more`:null,ji=(e,n)=>{const i=new Map;for(const o of e)for(const a of o.examples)(n==="all"||a.channel===n)&&!i.has(a.id)&&i.set(a.id,a);return[...i.values()].sort((o,a)=>a.at-o.at||o.id.localeCompare(a.id))},ki=(e,n)=>n==="all"?e:e.map(i=>({...i,examples:i.examples.filter(o=>o.channel===n)})).filter(i=>i.examples.length>0),Si=(e,n,i)=>n.some(o=>i.callIds.has(o.id))||e.some(o=>!!o.habit&&i.habits.has(o.habit)),$i=e=>({calls:e.filter(n=>n.channel==="call").length,emails:e.filter(n=>n.channel==="email").length});function qs(e,n={}){const i=n.channel??"all",o=n.summary??hs,a=new Map,d=[];for(const j of ki(e,i)){const g=Sn(Ht(j));if(!g){d.push(j);continue}a.set(g,[...a.get(g)??[],j])}const c=(j,g)=>+!!g.praise-+!!j.praise||+!!g.title-+!!j.title||g.at-j.at,b=(j,g,p)=>{const v=[...g].sort(c),N=ji(v,i),W=$i(N),T=v.find(O=>O.praise),_=v.find(O=>O.title);return{key:j,side:"keep",n:null,other:p,priority:p?null:Ht(v[0]),title:p?pa:_?.title??n.handledTitle??"Handled the way the company asks",calls:W.calls,emails:W.emails,countLine:wi(W.calls,W.emails),momentsLine:null,manager:v.some(O=>O.manager),matched:!p,happened:null,tryLine:null,quote:T?.praise?{text:T.praise,at:T.at}:null,items:v,examples:N,inSummary:Si(v,N,o),severity:null,at:Math.max(...v.map(O=>O.at)),slip:!1,reply:null,policyIssue:!1}},f=[...a.entries()].map(([j,g])=>b(`keep:${j}`,g,!1));return f.sort((j,g)=>+!!g.quote-+!!j.quote||g.examples.length-j.examples.length||g.at-j.at||j.key.localeCompare(g.key)),d.length&&f.push(b("keep:other",d,!0)),f}function Ys(e,n={}){const i=n.channel??"all",o=n.summary??hs,a=ki(e,i),d=new Map,c=new Map;for(const g of a.filter(p=>p.habit&&!p.slip)){const p=Sn(Ht(g)),v=`${p??"none"}|${g.habit}`;d.set(v,[...d.get(v)??[],g]),p&&!c.has(p)&&c.set(p,v)}for(const g of a.filter(p=>p.habit&&p.slip)){const p=Sn(Ht(g)),v=p&&c.get(p)||`${p??"none"}|${g.habit}`;d.set(v,[...d.get(v)??[],g]),p&&!c.has(p)&&c.set(p,v)}for(const g of a.filter(p=>!p.habit)){const p=Sn(Ht(g)),v=p&&c.get(p)||`${p??`own:${g.id}`}|manager`;d.set(v,[...d.get(v)??[],g]),p&&!c.has(p)&&c.set(p,v)}const b=(g,p)=>+!!(p.did&&p.instead)-+!!(g.did&&g.instead)||+!!p.did-+!!g.did||Ft(p.severity)-Ft(g.severity)||p.at-g.at,f=[...d.entries()].map(([g,p])=>{const v=[...p].sort(b),N=ji(v,i),W=$i(N),T=v[0],_=v.map(Ht).find(Boolean)??null,O=v.some(K=>K.manager)||_?.kind==="coaching",U=v.find(K=>K.did),ce=v.find(K=>K.quote&&K.quote.trim());return{key:`imp:${g}`,side:"imp",n:null,other:!1,priority:_,title:v.find(K=>K.title)?.title??"Coaching moment",calls:W.calls,emails:W.emails,countLine:wi(W.calls,W.emails),momentsLine:null,manager:O,matched:!!_,happened:U?.did??(ce?`Said â${ce.quote.trim()}â`:null),tryLine:(U??T).instead??v.find(K=>K.instead)?.instead??null,quote:null,items:v,examples:N,inSummary:Si(v,N,o),severity:v.reduce((K,q)=>Ft(q.severity)>Ft(K)?q.severity:K,null),at:Math.max(...v.map(K=>K.at)),slip:v.some(K=>!!K.slip),reply:v.find(K=>K.reply)?.reply??null,policyIssue:da(v,_)}});f.sort((g,p)=>p.examples.length-g.examples.length||Number(p.manager)-Number(g.manager)||Number(p.matched)-Number(g.matched)||Ft(p.severity)-Ft(g.severity)||p.at-g.at||g.key.localeCompare(p.key));const j=f.reduce((g,p)=>g+p.examples.length,0);return f.forEach((g,p)=>{g.n=p+1,g.momentsLine=ma(g.examples.length,j,g.manager)}),f}const fa=e=>e.reduce((n,i)=>n+i.examples.length,0),ga=(e,n,i)=>["Feedback",e,qt(n,"call","calls"),i!=null?qt(i,"email","emails"):""].filter(Boolean).join(" · "),xa=e=>{const n=String(e??"").replace(/\s+/g," ").trim();if(!n)return null;const i=n.match(/^.+?[.?!](?=\s+[A-Z0-9"â]|$)/);return(i?i[0]:n).trim()},Vs=e=>/\d|\bpercent\b|\bout of (a |one )?hundred\b/i.test(e);function ya(e){const n=xa(e);if(!n)return null;if(!Vs(n))return n;const i=n.replace(/[.?!]+$/,""),o=i.search(/,?\s+(?:with|across|at|for|on|scoring|and)\b[^,]*\d|,[^,]*\d|\s+\d/i),a=(o>0?i.slice(0,o):"").replace(/[\s,;:]+$/,"").replace(/\s+(?:and|with|at|across|for|on)$/i,"").trim();return!a||Vs(a)||a.split(/\s+/).length<5?null:`${a}.`}function ba(e){const n=String(e.weekly??"").replace(/\s+/g," ").trim();if(n)return n;const i=ya(e.summary);return i||`${qt(e.keep,"habit","habits")} to keep, ${e.improve} to work on, ${e.periodWords}.`}function va(e){const n=String(e.label??"").replace(/\s+/g," ").trim();return!n||e.last==null||e.now==null||!Number.isFinite(e.last)||!Number.isFinite(e.now)?null:`${e.now<e.last?"Last week's focus done":"Last week's focus"}: ${n}, ${e.last} â ${e.now}`}const cn=e=>e?.facts&&typeof e.facts=="object"?e.facts:{},es=864e5,dn=e=>Date.parse(`${String(e).slice(0,10)}T00:00:00Z`),wa=21,ja=(e,n)=>{const i=e[0];return i&&Number.isFinite(dn(i.periodStart))&&n-dn(i.periodStart)<=wa*es?i:null},ka=(e,n)=>{if(!n)return null;const i=dn(n.periodStart);return e.find(o=>o!==n&&i-dn(o.periodStart)>=5*es&&i-dn(o.periodStart)<=16*es)??null},Sa=e=>e?e.headline??cn(e).rendered?.opener??null:null;function $a(e){if(!e)return hs;const n=cn(e),i=[...(e.wins??[]).map(a=>a?.callId),...(e.improvements??[]).map(a=>a?.callId),...(n.celebrated??[]).map(a=>a?.callId),...(n.strengths?.chosen??[]).map(a=>a?.example?.callId),n.featured?.callId].filter(a=>
91typeof a=="string"&&a.length>0),o=n.featured?.ruleKey?[n.featured.ruleKey]:[];return{callIds:new Set(i),habits:new Set(o)}}function Na(e,n){const i=cn(n).featured,o=i?.ruleKey;if(!o)return null;const a=cn(n).thisWeek?.byKey,d=cn(e).thisWeek?.byKey;return!a||!d?null:va({label:i?.label??null,last:a[o]??0,now:d[o]??0})}const Ta=e=>`color-mix(in srgb, #201e1d ${e}%, transparent)`,za="var(--color-link-hover)",Ca="var(--color-rose)";function Ia({card:e,example:n,extra:i,rating:o,quoteBy:a}){const[d,c]=h.useState(!1),b=e.side==="imp",f=b?"var(--color-amber)":"var(--color-accent-500)",j=d?e.examples:e.examples.slice(0,Us),g=ua(e.examples.length-j.length),p=e.priority,v=p?p.kind==="policy"?t.jsxs(gt,{to:"/policies",search:{policy:p.id},className:"sc-prio",title:`Matched to: ${p.label}`,children:[t.jsx("i",{className:"ph-duotone ph-target",style:{fontSize:13,flex:"none"}}),t.jsx("span",{children:p.label})]}):t.jsxs("span",{className:"sc-prio",title:`Matched to: ${p.label}`,children:[t.jsx("i",{className:"ph-duotone ph-target",style:{fontSize:13,flex:"none"}}),t.jsx("span",{children:p.label})]}):e.other?t.jsxs("span",{className:"sc-prio",children:[t.jsx("i",{className:"ph-duotone ph-thumbs-up",style:{fontSize:13,flex:"none"}}),t.jsx("span",{children:"Good calls"})]}):null;return t.jsxs("div",{className:`sc-habit${b?" imp":""}${b&&e.n===1?" fb-first":""}`,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",minWidth:0},children:[e.n!=null&&t.jsx("span",{className:"sc-num",children:e.n}),v,e.policyIssue&&t.jsxs("span",{className:"fb-policy",title:e.slip?"A policy slip note is behind this":"This goes against one of the company's Policies",children:[t.jsx("i",{className:"ph-duotone ph-warning-circle",style:{fontSize:13}}),ca]}),e.inSummary&&t.jsxs("span",{className:"fb-insum",title:"The weekly summary names this",children:[t.jsx("i",{className:"ph-duotone ph-paper-plane-tilt",style:{fontSize:13}}),"In summary"]})]}),t.jsx("div",{className:"sc-habit-t",children:e.title}),t.jsxs("div",{className:"sc-habit-m",children:[t.jsxs("span",{children:[t.jsx("i",{className:`ph-duotone ${e.calls||!e.emails?"ph-phone":"ph-envelope-simple"}`,style:{fontSize:13}}),e.countLine]}),e.momentsLine&&t.jsx("span",{children:e.momentsLine})]}),i,e.quote&&t.jsxs("div",{className:"fb-quote",children:[t.jsx("i",{className:"ph-duotone ph-chat-circle-text",style:{fontSize:16,color:"var(--color-amber)",flex:"none",marginTop:2}}),t.jsxs("div",{style:{fontSize:13.5,lineHeight:1.45,minWidth:0},children:[t.jsxs("span",{className:"serif",style:{fontStyle:"italic"},children:["â",e.quote.text,"â"]}),a&&t.jsx("div",{style:{fontSize:12,color:Ta(55),marginTop:2},children:a})]})]}),b&&(e.happened||e.tryLine)&&t.jsxs("div",{className:"sc-try",children:[e.happened&&t.jsxs(t.Fragment,{children:[t.jsx("b",{style:{color:Ca},children:"Happened"}),t.jsx("span",{style:{textWrap:"pretty"},children:e.happened})]}),e.tryLine&&t.jsxs(t.Fragment,{children:[t.jsx("b",{style:{color:za},children:"Try"}),t.jsxs("span",{className:"try",children:["â",e.tryLine,"â"]})]})]}),b&&e.reply&&t.jsxs("div",{className:"fb-reply",children:[t.jsx("i",{className:"ph-duotone ph-chat-circle-dots",style:{fontSize:14,flex:"none",marginTop:1}}),t.jsx("span",{children:e.reply})]}),t.jsx("div",{className:"sc-moms",children:j.map(N=>n(N,f))}),g&&t.jsx("button",{type:"button",className:"fb-more",onClick:()=>c(!0),children:g}),d&&Us<e.examples.length&&t.jsx("button",{type:"button",className:"fb-more",onClick:()=>c(!1),children:"Show fewer"}),t.jsx("div",{style:{flex:1,minHeight:8}}),o&&t.jsx("div",{className:"sc-vote",children:o})]})}const Wa=` 92.fb-insum{display:inline-flex;align-items:center;gap:5px;font-size:11.5px;font-weight:700;padding:3px 10px;border-radius:999px;background:#fff3cc;color:#7a5200;white-space:nowrap} 93.fb-policy{display:inline-flex;align-items:center;gap:5px;font-size:11.5px;font-weight:700;padding:3px 10px;border-radius:999px;background:#fbe7ef;color:#aa0b56;white-space:nowrap} 94.fb-reply{display:flex;gap:7px;margin-top:8px;font-size:12.5px;line-height:1.45;color:var(--color-link-hover)} 95.fb-quote{display:flex;gap:10px;margin-top:10px;background:#fff8e6;border-radius:10px;padding:9px 12px} 96.fb-more{display:inline-block;align-self:flex-start;border:none;background:none;padding:0;margin-top:4px;font:inherit;font-size:12.5px;font-weight:600;color:var(--color-link);cursor:pointer} 97.sc-habit.imp.fb-first{background:#fdf6e8;border-color:#ecd9b5} 98.sc-habit.imp:not(.fb-first){background:var(--color-card);border-color:rgba(32,30,29,.12)} 99.fb-mom-who{font-weight:600} 100.fb-seg{display:inline-flex;gap:2px;background:#eef3f7;border:1px solid #c9d6e0;border-radius:999px;padding:3px} 101.fb-seg button{display:inline-flex;align-items:center;gap:6px;border:none;background:transparent;color:rgba(32,30,29,.6);font:inherit;font-size:13px;padding:6px 13px;border-radius:999px;cursor:pointer;white-space:nowrap} 102.fb-seg button.on{background:#2d2b2b;color:#fff} 103.fb-hero-in{position:relative;max-width:72%} 104.fb-confetti{position:absolute;opacity:.9;pointer-events:none} 105.fb-hchip-ok{display:inline-flex;align-items:center;gap:7px;background:rgba(167,240,196,.16);color:#c9f5da;border-radius:999px;padding:7px 13px;font-size:13px;font-weight:600} 106.fb-hlink{display:inline-flex;align-items:center;gap:6px;border:1px solid rgba(255,255,255,.22);background:rgba(255,255,255,.1);color:#fff;border-radius:999px;padding:6px 12px;font:inherit;font-size:12.5px;font-weight:600;cursor:pointer} 107.fb-hlink:hover{background:rgba(255,255,255,.18)} 108@media (max-width:820px){ 109 .fb-hero-in{max-width:none} 110 .fb-confetti{display:none} 111 .fb-seg button,.fb-more,.fb-hlink{min-height:40px} 112} 113`,Aa=An({method:"POST"}
113).middleware([En]).handler(Rn("d0993f41285baf85503919d65c531b9c1abe2690553f7f842a7069b8379adf4a")),Qt=e=>`color-mix(in srgb, #201e1d ${e}%, transparent)`,Ea="#201e1d",Ra="var(--color-link)",Da="var(--color-amber)",La="var(--color-amber-bg)",Fn=e=>e.flags.filter(n=>!n.dismissed),Gs=(e,n)=>new Date(e).toLocaleString("en-US",{timeZone:n,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),Ma=(e,n)=>new Date(e).toLocaleDateString("en-US",{timeZone:n,month:"short",day:"numeric"}),Pn=(e,n)=>{const i=e.replace(/\s+/g," ").trim();if(i.length<=n)return i;const o=i.slice(0,n);return`${o.slice(0,Math.max(o.lastIndexOf(" "),Math.floor(n*.6))).trim()}â¦`},_a=e=>e.split(" ")[0],en=e=>e.role==="Dispatch desk",Oa=30,Zs=.3,Fa=(()=>{let e=11;const n=()=>(e=(e*9301+49297)%233280)/233280,i=["#ffd166","#ff8fb8","#62c5ee","#a7f0c4","#ffb36b"],o=[];for(let a=0;a<4;a++)for(let d=0;d<4;d++){const c=a*4+d,b=c%3===2;o.push({left:`${78+d*5.2+(n()-.5)*3}%`,top:`${10+a*24+(n()-.5)*10}%`,width:b?7:5,height:b?7:11,borderRadius:b?"999px":"2px",transform:`rotate(${Math.round(n()*180)}deg)`,background:i[c%i.length]})}return o})();function Pa({ag:e,period:n,range:i,tz:o,orgName:a,digests:d,emails:c,summaryState:b,summaryHeadline:f,fullSummary:j,onSummaries:g}){const p=Yt(),v=_a(e.name),[N,W]=h.useState({calls:[]});h.useEffect(()=>{let s=!0;return W({calls:[]}),ii({data:{agentName:e.name,sinceIso:i.sinceIso,toIso:i.toIso}}).then(r=>{s&&W(r)}).catch(()=>{}),()=>{s=!1}},[e.name,i.sinceIso,i.toIso]);const T=N.calls,_=h.useMemo(()=>(N.staff??[]).map(s=>({name:s})),[N.staff]),O=h.useMemo(()=>{const s=new Set((N.noteLent??[]).map(k=>`${k.callId}:${k.ruleKey}`)),r=new Set(T.map(k=>k.id));return[...e.calls.map(k=>({c:k,lent:!1,flags:un(Fn(k),e.name,!1)})),...T.filter(k=>!e.calls.some(G=>G.id===k.id)).map(k=>({c:k,lent:!0,flags:un(Fn(k),e.name,!0)})).filter(k=>k.flags.length>0),...(N.noteCalls??[]).filter(k=>!r.has(k.id)&&!e.calls.some(G=>G.id===k.id)).map(k=>({c:k,lent:!0,flags:Fn(k).filter(G=>!G.person&&s.has(`${k.id}:${G.rule?.key??""}`))})).filter(k=>k.flags.length>0)]},[e.calls,e.name,T,N]),[U,ce]=h.useState(new Map);h.useEffect(()=>{Fi().then(s=>ce(new Map(s.options.map(r=>[r.id,r.title])))).catch(()=>{})},[]);const[K,q]=h.useState([]);h.useEffect(()=>{let s=!0;return q([]),Aa({data:{sinceIso:i.sinceIso,toIso:i.toIso}}).then(r=>{s&&q(r.promises)}).catch(()=>{}),()=>{s=!1}},[i.sinceIso,i.toIso]);const[Te,ee]=h.useState([]);h.useEffect(()=>{let s=!0;return ee([]),Pi({data:{name:e.name}}).then(r=>{s&&ee(r.notes)}).catch(()=>{}),()=>{s=!1}},[e.name]);const[F,w]=h.useState("all"),[P,D]=h.useState(!1);h.useEffect(()=>{D(!1)},[e.name]);const{ratings:Z,setRating:te}=Wo(()=>O.map(s=>s.c.id),[e.name,n,T.length,N.noteCalls?.length??0]),[Y,H]=h.useState(new Map),V=h.useMemo(()=>O.flatMap(s=>s.flags.filter(r=>ci.has(r.rule?.key??"")).map(r=>ks(s.c,r))),[O]);h.useEffect(()=>{let s=!0;if(V.length===0){H(new Map);return}const r=[];for(let k=0;k<V.length;k+=200)r.push(V.slice(k,k+200));return Promise.all(r.map(k=>po({data:{agentName:e.name,items:k,cachedOnly:!0}}).then(G=>G.explanations).catch(()=>[]))).then(k=>{if(!s)return;const G=new Map;for(const xe of k.flat()){const pe=Jo(xe);pe&&G.set(Zt(xe.callId,xe.ruleKey),pe)}H(G)}),()=>{s=!1}},[e.name,V]);const me=h.useMemo(()=>O.map(s=>({...s,moments:s.flags.filter(r=>Ns({key:r.rule?.key??"",quote:r.quote,speaker:r.speaker,severity:r.severity,note:Y.get(Zt(s.c.id,r.rule?.key??""))}))})),[O,Y]),{notes:Ee,pending:Ue}=Ao(e.name,()=>me.flatMap(s=>s.moments.map(r=>ks(s.c,r))).slice(0,200),[e.name,n,T.length,N.noteCalls?.length??0,Y],{window:Oa,batch:8,canWrite:s=>nl({key:s.ruleKey,quote:s.quote,speaker:s.speaker??null,severity:s.severity??null})}),[qe,Re]=h.useState([]);h.useEffect(()=>{let s=!0;return Hi().then(r=>{s&&Re(r.learnings)}).catch(()=>{}),()=>{s=!1}},[]);const X=Ho,re=[...U.entries()].map(([s,r])=>({id:s,title:r})),ke=[],it=[];for(const{c:s,lent:r,moments:k}of me){const G=[],xe=Eo(k).map(S=>{const I=S.rule?.key??"";return{fl:S,ruleKey:I,severity:S.severity,pf:Bi(I,S.quote,re),note:Ee.get(Zt(s.id,I)),rated:Z.has(Zt(s.id,I))}}),pe=xe.reduce((S,I)=>!S||mi({key:I.ruleKey,quote:I.fl.quote,severity:I.severity},{key:S.ruleKey,quote:S.fl.quote,severity:S.severity})?I:S,null),Lt=xe.length?[{key:"call",policy:!1,shown:Ro(xe)??xe[0],rows:xe}]:[];for(const S of Lt){const I=S.shown,L=I.note;if(!I.fl.person&&Ws({owner:e.name,ownerIsDesk:en(e),did:L?.did??null,quote:I.fl.quote,staff:_})!==e.name)continue;const R=!Ln(L)&&Ue.has(Zt(s.id,I.ruleKey)),ft=Ss(s.id,$s(S),Z),Rt={source:"ai",ruleKey:I.ruleKey,groupKey:S.key,rateKeys:$s(S),kind:Mo(L),covers:S.policy||!(Ln(L)||R)?null:Lo(S.rows.map(vt=>Mt(vt.ruleKey))),subject:L?.subject||X(I.fl),did:L?.did||null,instead:Do(I.ruleKey,L?.instead||null,ft),policyId:I.pf?.policy?.id??null,policyLine:I.pf?.label??null,who:null,callId:s.id,when:s.occurred_at,loading:R,habit:pe?ll({key:pe.ruleKey,quote:pe.fl.quote}):I.ruleKey,severity:pe?.severity??I.severity??null,quote:pe?.fl.quote??I.fl.quote,speaker:pe?.fl.speaker??I.fl.speaker??null,momentKey:pe?.ruleKey??I.ruleKey};G.push({row:Rt,words:Ln(L)?_o({subject:Rt.subject,did:Rt.did,instead:Rt.instead,kind:Rt.kind??"miss"},ft):null})}const yn=s.followups.filter(S=>S.kind==="train_employee"&&qn(S.owner,e.name,s.handledBy,r)),l=Oo(yn.map(S=>({id:S.id,words:Po(S),name:Fo(S.owner,en(e)?e.name:null)})),G.map(S=>({key:S.row.groupKey??"",words:S.words}))),A=new Map;for(const{row:S}of G){const I=l.get(S.groupKey??"");I&&A.set(I,S)}for(const S of yn){const I=ai(S.whatDid),L=A.get(S.id),R={source:"coach",ruleKey:"",subject:S.subject||"Coaching note",policyId:S.policyId,who:S.owner,callId:s.id,when:s.occurred_at,stepId:S.id},ft=L?{rate:{ruleKey:L.ruleKey,rateKeys:L.rateKeys??[L.ruleKey],subject:L.subject,did:L.did,instead:L.instead},covers:L.covers}:{};I.wentWell&&ke.push({...R,groupKey:`${S.id}:praise`,kind:"praise",did:I.wentWell,instead:I.whatDid?null:S.shouldHave,...I.whatDid?{}:ft}),(!I.wentWell||I.whatDid)&&ke.push({...R,groupKey:S.id,did:I.wentWell?I.whatDid:S.whatDid,instead:S.shouldHave,...ft})}for(const{row:S}of G)l.has(S.groupKey??"")||(ke.push(S),S.kind!=="praise"&&it.push(S))}
113ke.sort((s,r)=>+new Date(r.when)-+new Date(s.when));const Se=[...re.map(s=>({kind:"policy",id:s.id,label:s.title,policyTitle:s.title})),...O.flatMap(s=>s.c.followups.filter(r=>r.kind==="train_employee"&&qn(r.owner,e.name,s.c.handledBy,s.lent)).map(r=>({kind:"coaching",id:r.id,label:`Coaching note: ${(r.subject||"Coaching note").trim()}`,text:`${r.whatDid??""} ${r.shouldHave??""}`,policyTitle:r.policyId?U.get(r.policyId)??null:null}))),...qe.filter(s=>s.polarity==="is"&&(s.why??"").trim()).map(s=>({kind:"learning",id:s.id,label:`AI Training: ${Pn(s.why??"",70)}`,text:`${s.why??""} ${s.quote??""}`,ruleKey:s.ruleKey,polarity:s.polarity}))],ue=new Set;for(const s of al(it.map(r=>({callId:r.callId,person:e.name,at:+new Date(r.when),habit:r.habit??r.ruleKey,shown:{callId:r.callId,key:r.momentKey??r.ruleKey,quote:r.quote??"",severity:r.severity??null,speaker:"dispatcher",at:+new Date(r.when),person:e.name},flags:[],row:r})))){const r=s.lead.row;r.count=s.count,r.habitCallIds=s.moments.map(G=>G.callId);const k=r.momentKey??r.ruleKey;r.match=Xt({key:k,quote:r.quote??"",label:Mt(k),person:e.name},Se),ue.add(r)}const ht=ke.filter(s=>s.kind==="praise"),ze=new Set,Ye=ke.filter(s=>s.kind!=="praise").filter(s=>s.source==="coach"||ue.has(s)).filter(s=>{const r=s.source==="ai"?`ai:${s.callId}:${s.groupKey}`:`coach:${s.callId}:${(s.subject||"").trim().toLowerCase()}`;return ze.has(r)?!1:(ze.add(r),!0)}),yt=pl(Ye.map(s=>({r:s,matched:s.source==="coach"||!!s.match,count:s.count??1,severity:s.severity??null,at:+new Date(s.when)}))).map(s=>s.r),Ve=new Map(O.map(s=>[s.c.id,s.c])),he=(s,r)=>+new Date(Ve.get(s)?.occurred_at??r),Fe=(s,r)=>({id:s,channel:"call",at:he(s,r)}),Le=s=>s.policyId?{kind:"policy",id:s.policyId,label:U.get(s.policyId)??"Policy"}:{kind:"coaching",id:s.stepId??s.groupKey??s.callId,label:`Coaching note: ${(s.subject||"Coaching note").trim()}`},ye=yt.map(s=>s.source==="ai"?{id:`ai:${s.callId}:${s.groupKey}`,ref:s,examples:(s.habitCallIds?.length?s.habitCallIds:[s.callId]).map(r=>Fe(r,s.when)),at:+new Date(s.when),match:s.match??null,manager:!1,habit:s.habit??s.ruleKey,title:s.subject,did:s.did,instead:s.instead,quote:Ts({quote:s.quote??null,speaker:s.speaker??null}),severity:s.severity??null}:{id:`coach:${s.groupKey}`,ref:s,examples:[Fe(s.callId,s.when)],at:+new Date(s.when),match:null,own:Le(s),manager:!0,habit:null,title:s.subject,did:s.did,instead:s.instead,severity:null}),Je=(s,r)=>s.trim().toLowerCase()===r.trim().toLowerCase(),ot=new Map,Me=new Map;for(const s of K){const r=s.promise;if(!r||!Je(r.owner.name,e.name)||!Ns(hl({callId:s.flagCallId,severity:s.severity,at:+new Date(s.flagAt)},r)))continue;ot.set(r.callId,r.call);const k=Me.get(r.callId);k?k.flags.push(s):Me.set(r.callId,{p:s,flags:[s]})}for(const{p:s,flags:r}of Me.values()){const k=s.promise,G=r.reduce((xe,pe)=>pe.flagAt>xe?pe.flagAt:xe,s.flagAt);ye.push({id:`promise:${k.callId}`,ref:null,examples:[{id:k.callId,channel:"call",at:+new Date(k.call.at)}],at:+new Date(G),match:Xt({key:ln,quote:k.line,label:Mt(ln),person:e.name},Se),manager:!1,habit:ln,title:"Call back when you said you would",did:`Promised â${Pn(Ts({quote:k.line,speaker:"dispatcher"})??k.line,160)}â and the caller had to call back (${Gs(G,o)}).`,instead:null,severity:s.severity})}const Qe=new Set(ye.flatMap(s=>s.examples.map(r=>r.id)));for(const s of e.calls){const r=s.handling;if(!r||!ul(r)||Qe.has(s.id))continue;const k=fl(r);if(Ws({owner:e.name,ownerIsDesk:en(e),did:k,quote:null,staff:_})!==e.name)continue;const G=+new Date(s.occurred_at);ye.push({id:`handling:${s.id}`,ref:null,examples:[{id:s.id,channel:"call",at:G}],at:G,match:Xt({key:Pt,quote:`${k??""} ${r.try??""}`,label:Mt(Pt),person:e.name},Se),manager:!1,habit:Pt,title:Mt(Pt),did:k,instead:r.try,severity:"medium"})}const De=s=>(!i.sinceIso||s>=i.sinceIso)&&(!i.toIso||s<=i.toIso);for(const s of Te){if(s.status==="discarded")continue;const r=Ve.get(s.callId)?.occurred_at??s.createdAt;if(!De(new Date(r).toISOString()))continue;const k=((s.policyId?U.get(s.policyId):null)??s.policyTitle??"Policy").trim();ye.push({id:`slip:${s.id}`,ref:null,examples:[{id:s.callId,channel:"call",at:+new Date(r)}],at:+new Date(r),match:null,own:{kind:"policy",id:s.policyId??`title:${k.toLowerCase()}`,label:k},manager:s.source==="manager",habit:`policy:${k.toLowerCase()}`,title:k,did:s.whatHappened?.trim()||null,instead:s.tryThis?.trim()||null,severity:null,slip:!0,reply:Ki(s)})}const de=new Set(e.calls.filter(s=>s.sentiment!=null&&s.sentiment>=Zs).map(s=>s.id)),Pe=new Set(ye.flatMap(s=>s.examples.map(r=>r.id))),mt=new Map;for(const s of ht)de.has(s.callId)&&mt.set(s.callId,[...mt.get(s.callId)??[],s]);const lt=Se.filter(s=>s.kind!=="learning").map(s=>({...s,text:null})),Q=lt.map(s=>`${s.kind}:${s.id}:${s.label}`).join("|"),Ge=h.useMemo(()=>{const s=new Map;for(const r of e.calls)r.sentiment!=null&&r.sentiment>=Zs&&s.set(r.id,Xt({key:"",quote:r.summary??"",label:r.topic??""},lt));return s},[e.calls,Q]),le=s=>s.source==="coach"?{id:`coach:${s.groupKey}`,ref:s,examples:[Fe(s.callId,s.when)],at:+new Date(s.when),match:null,own:Le(s),manager:!0,habit:null,title:s.subject,did:s.did,instead:s.instead,praise:s.did,severity:null}:{id:`ai:${s.callId}:${s.groupKey}`,ref:s,examples:[Fe(s.callId,s.when)],at:+new Date(s.when),match:Xt({key:s.momentKey??s.ruleKey,quote:s.quote??"",label:Mt(s.momentKey??s.ruleKey),person:e.name},Se),manager:!1,habit:null,title:s.subject,did:s.did,instead:s.instead,severity:null},ne=s=>({id:`win:${s.id}`,ref:null,examples:[{id:s.id,channel:"call",at:+new Date(s.occurred_at)}],at:+new Date(s.occurred_at),match:Ge.get(s.id)??null,manager:!1,habit:null,title:null,did:null,instead:null,severity:null}),et=[...e.calls.filter(s=>de.has(s.id)&&!Pe.has(s.id)).flatMap(s=>mt.get(s.id)?.map(r=>le(r))??[ne(s)]),...ht.filter(s=>!de.has(s.callId)).map(s=>le(s))],He=Date.now(),Be=ja(d,He),tt=ka(d,Be),ge=$a(Be),bt=a.trim()||"the company",$=qs(et,{channel:F,summary:ge,handledTitle:`Handled the way ${bt} asks`}),M=Ys(ye,{channel:F,summary:ge}),E=fa(M),fe=F==="all"?$:qs(et,{summary:ge}),be=F==="all"?M:Ys(ye,{summary:ge}),at=ba({weekly:Sa(Be),summary:f,keep:fe.length,improve:be.length,periodWords:we(n)}),rt=Na(Be,tt),Ze=(s,r)=>{const k=Ve.get(s.id),G=k?null:ot.get(s.id),xe=k?k.client?.name||k.caller_name||k.detectedCompany||k.topic||"Caller":G?.caller||"Call",pe=k?.summary??G?.summary??null,Lt=k?.occurred_at??G?.at??null;return t.jsxs("div",{className:"sc-mom",children:[t.jsx("i",{className:`ph-duotone ${s.channel==="email"?"ph-envelope-simple":"ph-phone"}`,style:{color:r}}),t.jsxs("span",{style:{lineHeight:1.45,textWrap:"pretty",minWidth:0},children:[t.jsx("b",{className:"fb-mom-who",children:xe}),pe?t.jsxs("span",{style:{color:Qt(68)},children:[" ",Pn(pe,120)]}):null]}),t.jsxs(gt,{to:"/calls",search:{period:"all",call:s.id},title:"Review call",children:[Lt?Gs(Lt,o):"Review call",t.jsx("i",{className:"ph-duotone ph-arrow-up-right",style:{fontSize:11}})]})]},s.id)},kt=s=>{if(!s)return null;const r=s.source==="ai"?{ruleKey:s.ruleKey,rateKeys:s.rateKeys??[s.ruleKey],subject:s.subject,did:s.did,instead:s.instead}:s.rate;return r?.instead?t.jsx(Uo,{row:{callId:s.callId,ruleKey:r.ruleKey,subject:r.subject,did:r.did,instead:r.instead}
113,agentName:e.name,fb:Ss(s.callId,r.rateKeys,Z),policyTitles:U,onChange:k=>te(`${s.callId}:${r.ruleKey}`,k)}):null},ut=s=>s.items.find(r=>r.ref)?.ref??null,$e=s=>{const r=ut(s),k=s.side==="imp"&&r?t.jsxs(t.Fragment,{children:[t.jsx(Bo,{text:r.covers??null}),t.jsx(Ko,{loading:r.loading,did:null,instead:null,kind:r.kind})]}):null;return t.jsx(Ia,{card:s,example:Ze,extra:k,rating:kt(r),quoteBy:s.quote?`Coach and train note · ${Ma(s.quote.at,o)}`:null},s.key)},Ie=F==="email",se=(s,r)=>t.jsx("div",{className:"sc-habit",style:{fontSize:12.5,color:"var(--color-label)",lineHeight:1.5},children:r},s),Et=en(e)?"the desk":v,St=$.length?$.map($e):[se("keep-empty",Ie?"Replies are not graded yet, so there are no email moments. The Emails tab lists every reply.":`No standout calls ${we(n)}. Calls that went well show here.`)],$t=M.length?M.map($e):[se("imp-empty",Ie?"Replies are not graded yet, so there are no email moments to work on.":"Nothing to work on in this period.")],u=t.jsxs("div",{className:"sc-h3row",children:[t.jsx("span",{className:"sc-htile",style:{background:"var(--color-accent-100)",color:Ra},children:t.jsx("i",{className:"ph-duotone ph-star"})}),t.jsx("h3",{className:"sc-h3",children:"Keep doing this"}),t.jsxs("span",{style:{marginLeft:"auto",fontSize:12.5,color:Qt(55),whiteSpace:"nowrap"},children:[$.length," ",$.length===1?"habit":"habits"]})]},"keep-head"),x=t.jsxs("div",{className:"sc-h3row",children:[t.jsx("span",{className:"sc-htile",style:{background:La,color:Da},children:t.jsx("i",{className:"ph-duotone ph-arrow-fat-lines-up"})}),t.jsx("h3",{className:"sc-h3",children:"Where to improve"}),t.jsxs("span",{style:{marginLeft:"auto",fontSize:12.5,color:Qt(55),whiteSpace:"nowrap"},children:[E," ",E===1?"moment":"moments",", most common first"]})]},"imp-head"),ie=Math.max(St.length,$t.length),C=[{v:"all",label:"All",icon:"ph-stack"},{v:"call",label:"Calls",icon:"ph-phone"},{v:"email",label:"Emails",icon:"ph-envelope-simple"}];return t.jsxs(t.Fragment,{children:[t.jsx("style",{children:Wa}),t.jsxs("div",{className:"sc-hero",style:{marginTop:20},children:[Fa.map((s,r)=>t.jsx("span",{className:"fb-confetti","aria-hidden":"true",style:s},r)),t.jsxs("div",{className:"fb-hero-in",children:[t.jsxs("div",{className:"sc-hero-k",children:[t.jsx("i",{className:"ph-duotone ph-sparkle",style:{fontSize:15}}),ga(we(n),e.total,en(e)?null:c)]}),t.jsx("p",{className:"sc-hero-h",children:at})]}),t.jsxs("div",{style:{position:"relative",display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,marginTop:16},children:[rt&&t.jsxs("span",{className:"fb-hchip-ok",children:[t.jsx("i",{className:"ph-duotone ph-check-circle",style:{fontSize:15}}),rt]}),t.jsxs("button",{type:"button",className:"sc-hchip",onClick:g,title:"Open the weekly summaries",children:[t.jsx("i",{className:"ph-duotone ph-paper-plane-tilt",style:{fontSize:15}}),"Weekly summary · ",b]}),j&&t.jsxs("button",{type:"button",className:"fb-hlink","aria-expanded":P,onClick:()=>D(s=>!s),children:[t.jsx("i",{className:`ph-duotone ${P?"ph-caret-up":"ph-caret-down"}`,style:{fontSize:14}}),P?"Hide full summary":"Full summary"]})]})]}),P&&j,t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap",marginTop:18},children:[t.jsx("div",{className:"fb-seg",role:"group","aria-label":"Calls or emails",children:C.map(s=>t.jsxs("button",{type:"button",className:F===s.v?"on":"","aria-pressed":F===s.v,onClick:()=>w(s.v),children:[t.jsx("i",{className:`ph-duotone ${s.icon}`,style:{fontSize:14}}),s.label]},s.v))}),t.jsxs("span",{style:{fontSize:12.5,color:Qt(55)},children:["From calls and emails, grouped by what ",bt," asks for"]})]}),t.jsxs("div",{style:{fontSize:12,color:Qt(50),marginTop:6,lineHeight:1.5,maxWidth:"110ch"},children:["Follows the period above (",t.jsx("b",{style:{color:Ea,fontWeight:600},children:we(n)}),"). Where to improve counts how ",Et," handled a call: calls graded Could do better, conduct flags, policy issues and saved coaching notes, one moment per call, and Coach and train notes from the Call Explorer. A service problem, like a late driver or a billing dispute, goes to operations."]}),p?t.jsxs("div",{className:"sc-fbgrid",style:{marginTop:14},children:[u,St,t.jsx("div",{style:{marginTop:10},children:x}),$t]}):t.jsxs("div",{className:"sc-fbgrid",style:{marginTop:14},children:[u,x,Array.from({length:ie},(s,r)=>t.jsxs(h.Fragment,{children:[t.jsx("div",{style:{minWidth:0},children:St[r]??null}),t.jsx("div",{style:{minWidth:0},children:$t[r]??null})]},r))]})]})}const y=e=>`color-mix(in srgb, #201e1d ${e}%, transparent)`,It="#201e1d",ae="var(--color-link)",At="var(--color-link-hover)",Ne="var(--color-amber)",pn="var(--color-amber-bg)",je="var(--color-rose)",ts="var(--color-rose-hover)",Ae="var(--color-muted)",Oe="rgba(0,136,176,0.12)",nn="var(--color-accent-400)",sn="#c3d1db",$n="var(--color-accent-2-500)",fn=e=>e.flags.filter(n=>
113!n.dismissed),pt=(e,n)=>new Date(e).toLocaleString("en-US",{timeZone:n,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}),Ke=(e,n)=>new Date(e).toLocaleDateString("en-US",{timeZone:n,month:"short",day:"numeric"}),Ha=(e,n)=>Number(new Intl.DateTimeFormat("en-US",{timeZone:n,hour:"numeric",hourCycle:"h23"}).formatToParts(e).find(i=>i.type==="hour")?.value??"0")%24,Nn=e=>`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`,on=e=>e.split(" ").filter(n=>/[A-Za-z]/.test(n[0]??"")).map(n=>n[0]).slice(0,2).join("").toUpperCase(),Bt=(e,n)=>n?Math.round(e/n*100):0,hn=e=>e.split(" ")[0],jn=e=>{const n=[e.zoom?`${e.zoom} named by Zoom`:"",e.greeting?`${e.greeting} from the greeting`:"",e.person?`${e.person} picked by hand`:""].filter(Boolean);return`${e.passed} passed to people${n.length?`: ${n.join(", ")}`:""}`},Ce=e=>e.role==="Dispatch desk",Ni=e=>/\bteam$/i.test(e)?e:`${e} team`,Tn=500,Xs=2e3;async function Ti(e,n,i){const o=[];let a=0;for(let d=0;d<Xs;d+=Tn){const c=await io({data:{sinceIso:e.sinceIso??void 0,toIso:e.toIso??void 0,agent:n,sort:"recent",limit:Tn,offset:d}});if(o.push(...c.calls),a=c.total,i(o.length,Math.min(a,Xs)),c.calls.length<Tn||o.length>=a)break}return{calls:o,total:a}}const gn=e=>e>=65?ae:e>=45?It:je,zi=e=>!e.scoreReady,Ba=e=>zi(e)?Ae:gn(e.score),Js=(e,n)=>Qi(e,n),In=e=>e.scoreKnown&&oo({ready:e.scoreReady,calls:e.scoreCalls,emails:e.scoreEmails}),Wn=({a:e})=>In(e)?t.jsx("span",{className:"sc-chip",title:ao(e.scoreCalls,e.scoreEmails),style:{background:y(6),color:y(55),fontWeight:500},children:lo}):null,Ka=`a score needs ${Hn} calls and emails`,ms="The 30-day score could not be read. Refresh to try again.";function ns({a:e,fontSize:n=22}){if(!e.scoreKnown)return t.jsx("span",{title:ms,style:{fontSize:12,color:Ae,lineHeight:1.3},children:"Score not available"});if(!e.scoreReady){const[i,o]=Kn(e.scoreCalls+e.scoreEmails);return t.jsxs("span",{title:rs(e.scoreCalls,e.scoreEmails),style:{display:"inline-flex",flexDirection:"column",fontSize:12,fontWeight:500,color:Ae,lineHeight:1.3,whiteSpace:"nowrap"},children:[t.jsx("span",{children:i}),t.jsx("span",{style:{fontWeight:400,fontSize:11.5},children:o})]})}return t.jsx("span",{className:"serif",style:{fontSize:n,fontWeight:600,lineHeight:1,color:gn(e.score),fontVariantNumeric:"tabular-nums"},children:e.score})}function Ua({a:e,period:n}){if(Ce(e))return t.jsx("span",{title:"Replies signed by a desk, or by nobody, stay with the shared inbox."});if(!e.emails)return t.jsx("span",{title:"The replies could not be read just now. Refresh to try again.",style:{fontSize:12,color:Ae},children:"Not available"});const i=e.emails,o=`${i.replies} ${i.replies===1?"reply":"replies"} in ${we(n)}${i.avgWaitMin!=null?`. Average first reply ${jt(i.avgWaitMin)} over ${i.firstReplies} first ${i.firstReplies===1?"reply":"replies"}${i.covered?`, ${i.covered} picked up from an earlier shift`:""}.`:"."}`;return t.jsxs("div",{style:{lineHeight:1.2},title:o,children:[t.jsx("div",{className:"serif",style:{fontSize:18,fontWeight:600,fontVariantNumeric:"tabular-nums",color:i.replies?It:Ae},children:i.replies}),i.avgWaitMin!=null&&t.jsxs("div",{style:{fontSize:11.5,color:i.avgWaitMin>zt?Ne:y(55),marginTop:3,whiteSpace:"nowrap"},children:[jt(i.avgWaitMin)," reply"]})]})}function qa({score:e,tone:n,size:i=68,stroke:o=6,fontSize:a=22,label:d,title:c}){const b=i/2,f=b-o/2-2,j=2*Math.PI*f*Math.max(0,Math.min(100,e))/100;return t.jsxs("div",{role:"img",style:{position:"relative",width:i,height:i,flex:"none"},"aria-label":d,title:c,children:[t.jsxs("svg",{viewBox:`0 0 ${i} ${i}`,"aria-hidden":"true",style:{width:i,height:i,display:"block",transform:"rotate(-90deg)"},children:[t.jsx("circle",{cx:b,cy:b,r:f,style:{fill:"none",stroke:y(9),strokeWidth:o}}),t.jsx("circle",{cx:b,cy:b,r:f,style:{fill:"none",stroke:n,strokeWidth:o,strokeLinecap:"round",strokeDasharray:`${j.toFixed(1)} 999`}})]}),t.jsx("span",{className:"serif","aria-hidden":"true",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",fontSize:a,fontWeight:600,color:n,fontVariantNumeric:"tabular-nums"},children:e})]})}const Qs=[["var(--color-rose-fill)",je],[Oe,At],[pn,Ne],["var(--color-accent-100)",ae]],Ci=(e,n)=>Ce(e)?["var(--color-ink-chip)","#fff"]:Qs[n%Qs.length];function Ya(e,n){const[i,o,a]=mn(new Date(e),n).split("-").map(Number),d=new Date(Date.UTC(i,o-1,a));return d.setUTCDate(d.getUTCDate()-(d.getUTCDay()+6)%7),d.toISOString().slice(0,10)}const Va=(e,n)=>{const i=new Date(`${e}T00:00:00`),o=new Date(i);return o.setDate(i.getDate()+n),`${Ke(i.toISOString())} to ${Ke(o.toISOString())}`},Vt=e=>jo(e?.facts),Ii=e=>!Vt(e)&&Vn(e.facts?.v),xn=(e,n)=>{const i=Vt(e);return i?js(i.window):Ii(e)?n:js(void 0)},ss=(e,n,i)=>{const o=Vt(e);return o?`${Ke(o.window.startAt,n)} to ${Ke(o.window.endAt,n)}`:Va(e.periodStart,Ii(e)?st[i.key].days??7:6)},Ga={week:"Create this week's summary",two_weeks:"Create the summary for these two weeks",month:"Create this month's summary",custom:"Create the summary"},is="teleserv:open-digest-schedule",Wi={week:"One week",two_weeks:"Two weeks",month:"One month",custom:"Summary"},ei={week:"seven",two_weeks:"fourteen",month:"twenty-eight",custom:"chosen"},os=(e,n)=>n.key==="week"?e:e==="no calls this week"?`no calls ${n.key==="two_weeks"?"in the last two weeks":st[n.key].span}`:e==="already sent this week"?`already sent for ${st[n.key].span}`:e,ls=e=>{const n=Vt(e);if(n?.v===3){const i=n.strengths?.chosen?.length??e.wins.length;return{good:`${i} strength${i===1?"":"s"}
113`,focus:e.improvements.length?"1 to focus on":"nothing to focus on"}}return{good:`${e.wins.length} ${n?"worth celebrating":"doing well"}`,focus:`${e.improvements.length} to work on`}},Ai=e=>new Promise(n=>setTimeout(n,e));async function Ei(e,n){let i=await vs({data:{agentId:e,fresh:n}});for(let o=0;i.pending&&o<2;o++)await Ai(2e4),i=await vs({data:{agentId:e}});return i.pending?{kind:"pending"}:{kind:"built",due:i.due,dueReason:i.dueReason,reused:i.reused,digestId:i.digest?.id??null,builtAt:i.digest?.facts?.builtAt??null}}async function Za(e,n){const i=e.scope==="company"?{company:!0}:{managerEmail:e.email};let o=await ws({data:{...i,fresh:n}});for(let a=0;o.pending&&a<2;a++)await Ai(2e4),o=await ws({data:i});return o.pending?{kind:"pending"}:{kind:"built",due:o.due,dueReason:o.dueReason,reused:o.reused,digestId:o.digest?.id??null,builtAt:o.digest?.facts?.builtAt??null}}const as=e=>e==="acknowledged"?{bg:Oe,fg:At,icon:"ph-seal-check",label:"Acknowledged"}:e==="sent"?{bg:pn,fg:Ne,icon:"ph-paper-plane-tilt",label:"Sent"}:{bg:y(8),fg:y(55),icon:"ph-pencil-simple",label:"Draft"},Xa=` 114.sc-page{display:flex;flex-direction:column;min-width:0;min-height:0;flex:1} 115.sc-body{flex:1;overflow-y:auto;min-height:0;padding:0 32px 48px;position:relative} 116.sc-kpis{display:grid;grid-template-columns:repeat(var(--kpi-n,4),minmax(0,1fr));border:1px solid var(--color-divider);border-radius:var(--radius-card);overflow:hidden;background:var(--color-card)} 117.sc-kpi{padding:14px 20px;border-right:1px solid var(--color-border);min-width:0} 118.sc-kpi:last-child{border-right:none} 119.sc-kpi-l{font-size:11px;letter-spacing:.09em;text-transform:uppercase;color:var(--color-label)} 120.sc-kpi-n{font-family:var(--font-serif);font-size:26px;font-weight:600;line-height:1.1;margin-top:4px;font-variant-numeric:tabular-nums} 121.sc-kpi-s{font-size:12px;color:rgba(32,30,29,.5);margin-top:3px} 122.sc-ic{width:26px;height:26px;border-radius:8px;display:inline-flex;align-items:center;justify-content:center;flex:none;font-size:15px} 123.sc-card{background:var(--color-card);border:1px solid var(--color-divider);border-radius:var(--radius-card);padding:18px 20px;min-width:0} 124.sc-tbl{background:var(--color-card);border:1px solid var(--color-divider);border-radius:var(--radius-card);overflow:hidden;overflow-x:auto} 125/* A team block: one card, a tinted heading band on top of the team's table, so each team reads as its own block. */ 126.sc-teamblk{margin-bottom:22px;background:var(--color-card);border:1px solid var(--color-divider);border-radius:var(--radius-card);overflow:hidden} 127.sc-teamblk>.sc-tbl{border:none;border-radius:0} 128/* The heading: the name over the count and manager at the left, the score at the right across both lines. On a phone the 129 score sits beside the name and the count and manager take the full width under both. */ 130.sc-teamhd{display:grid;grid-template-columns:minmax(0,1fr) auto;grid-template-areas:"name score" "meta score";align-items:center;column-gap:16px;padding:14px 18px;background:var(--color-accent-100);border-bottom:1px solid var(--color-border)} 131.sc-teamnm{grid-area:name;align-self:end;font-family:var(--font-serif);font-size:22px;font-weight:600;line-height:1.15;letter-spacing:-.01em;margin:0;color:var(--color-text);overflow-wrap:anywhere} 132.sc-teammeta{grid-area:meta;align-self:start;display:flex;align-items:center;gap:8px;min-width:0;margin-top:5px;font-size:12.5px;color:var(--color-text-secondary);white-space:nowrap} 133.sc-teammeta>*{flex:none} 134/* A long manager name shortens with an ellipsis instead of wrapping under a dangling dot. */ 135.sc-teammeta>.sc-teammgr{flex:0 1 auto;display:inline-flex;align-items:center;gap:6px;min-width:0} 136.sc-nomgr{display:inline-flex;align-items:center;gap:5px;color:var(--color-text-secondary);text-decoration:none;font-weight:500} 137.sc-nomgr:hover{color:var(--color-link);text-decoration:underline} 138.sc-teamsc{grid-area:score;display:flex;align-items:center;gap:12px} 139.sc-quietlink{color:inherit;text-decoration:underline;text-decoration-color:var(--color-control-border);text-underline-offset:2px} 140.sc-quietlink:hover{color:var(--color-link)} 141/* The ranked grid is about 960px wide as drawn (the Emails column since 2026-10-08); narrower windows scroll it inside the card instead of clipping the Wins and misses column. */ 142.sc-grid{display:grid;grid-template-columns:26px 40px minmax(180px,1.3fr) 120px 64px 84px minmax(150px,1fr) 120px 18px;gap:14px;align-items:center;padding:13px 18px;min-width:930px} 143.sc-th{padding:9px 18px;border-bottom:1px solid var(--color-border);background:#f4f7f9;font-size:12px;color:rgba(32,30,29,.55);font-weight:500} 144/* Column headers sort on click (desktop only: the header row is hidden on phones, where the Sort menu does the job). The Find an agent pill matches the Call Explorer search f
144ield. */ 145.sc-thb{display:inline-flex;align-items:center;gap:4px;border:none;background:transparent;padding:0;font:inherit;color:inherit;cursor:pointer;border-radius:4px;white-space:nowrap} 146.sc-thb:hover{color:var(--color-text)} 147.sc-thb:focus-visible{outline:2px solid var(--color-accent);outline-offset:2px} 148.sc-thb[aria-pressed="true"]{color:var(--color-text);font-weight:600} 149.sc-thb i{font-size:11px} 150.sc-find{width:220px;max-width:100%;border:1px solid var(--color-control-border);background:#fff;border-radius:999px;padding:6px 30px 6px 32px;font:inherit;font-size:12.5px;color:var(--color-text);outline:none;box-sizing:border-box;min-height:34px} 151.sc-find:focus{border-color:var(--color-accent);box-shadow:0 0 0 3px rgba(0,136,176,.13)} 152.sc-find::placeholder{color:#7f93a3} 153.sc-team{width:auto;max-width:220px;min-height:34px;border-radius:999px;padding:6px 32px 6px 14px;font-size:12.5px;border-color:var(--color-control-border);background-color:#fff} 154.sc-row{width:100%;text-align:left;font:inherit;color:inherit;background:transparent;border:none;border-bottom:1px solid var(--color-hairline-soft);cursor:pointer;box-sizing:border-box} 155.sc-row:hover{background:rgba(0,136,176,.04)} 156.sc-row:last-child{border-bottom:none} 157.sc-av{border-radius:50%;display:inline-flex;align-items:center;justify-content:center;font-family:var(--font-serif);font-weight:600;flex:none} 158.sc-chip{display:inline-flex;align-items:center;gap:4px;font-size:11px;font-weight:600;padding:2px 8px;border-radius:999px;white-space:nowrap} 159.sc-sbar{display:flex;height:7px;border-radius:999px;overflow:hidden;gap:2px;background:#e2ebf1} 160.sc-sbar>span{display:block} 161.sc-menu{position:absolute;top:calc(100% + 6px);right:0;z-index:50;
161min-width:200px;background:#fff;border:1px solid var(--color-divider);border-radius:10px;box-shadow:0 12px 34px rgba(32,30,29,.16);padding:6px} 162.sc-mi{display:flex;align-items:center;justify-content:space-between;gap:10px;width:100%;border:none;background:transparent;color:var(--color-text);text-align:left;font:inherit;font-size:13px;padding:8px 10px;border-radius:7px;cursor:pointer} 163.sc-mi:hover{background:var(--color-control-bg)} 164.sc-back{display:inline-flex;align-items:center;gap:7px;border:none;background:transparent;padding:4px 0;font:inherit;font-size:13px;font-weight:500;color:rgba(32,30,29,.62);cursor:pointer} 165.sc-back:hover{color:var(--color-text)} 166.sc-back i{font-size:15px} 167.sc-link{display:inline-flex;align-items:center;gap:5px;font-size:12.5px;font-weight:600;color:var(--color-link);text-decoration:none;cursor:pointer;border:none;background:transparent;padding:0;font-family:inherit} 168.sc-link:hover{color:var(--color-link-hover)} 169.sc-date{flex:1;min-width:0;border:1px solid rgba(32,30,29,.16);background:#fff;border-radius:9px;padding:7px 10px;font:inherit;font-size:13px;color:var(--color-text);color-scheme:light;box-sizing:border-box} 170.sc-date:focus{outline:none;border-color:var(--color-accent);box-shadow:0 0 0 3px rgba(0,136,176,.13)} 171.sc-ta{width:100%;box-sizing:border-box;border:1px solid rgba(32,30,29,.16);background:#fff;border-radius:9px;padding:10px 12px;font:inherit;font-size:14px;line-height:1.6;color:var(--color-text);resize:vertical} 172.sc-ta:focus{outline:none;border-color:var(--color-accent);box-shadow:0 0 0 3px rgba(0,136,176,.13)} 173.sc-erow{display:flex;align-items:center;gap:14px;padding:13px 18px;border:none;border-bottom:1px solid var(--color-hairline-soft);cursor:pointer;width:100%;text-align:left;font:inherit;background:transparent;color:inherit;box-sizing:border-box} 174.sc-erow:hover:not(:disabled){background:rgba(0,136,176,.04)} 175.sc-erow:disabled{cursor:default} 176.sc-erow:last-child{border-bottom:none} 177.sc-crow{display:flex;align-items:flex-start;gap:13px;background:var(--color-card);border:1px solid var(--color-hairline-soft);border-radius:12px;padding:13px 18px;text-decoration:none;color:inherit} 178.sc-crow:hover{border-color:rgba(0,136,176,.45)} 179.sc-quiet{border:none;background:transparent;padding:9px 10px;font:inherit;font-size:13px;color:rgba(32,30,29,.5);cursor:pointer} 180.sc-quiet:hover{color:var(--color-rose)} 181.sc-bars{display:flex;align-items:flex-end;gap:12px;height:180px;padding:0 6px;margin-top:16px;border-bottom:1px solid rgba(32,30,29,.12)} 182.sc-bar{flex:1;min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;gap:6px;height:100%;padding-bottom:8px} 183.sc-bar-stack{width:100%;max-width:52px;display:flex;flex-direction:column-reverse;border-radius:6px;overflow:hidden} 184.sc-chipbtn{min-height:32px} 185/* The report-card tab strip scrolls inside its own box when it must; the wrapper paints a right-edge fade while more is hidden. */ 186.sc-rail{position:relative;min-width:0} 187.sc-rail[data-more]::after{content:"";position:absolute;top:0;right:0;bottom:1px;width:44px;pointer-events:none;background:linear-gradient(to right,transparent,var(--color-canvas))} 188.sc-tabs{position:relative;display:flex;align-items:center;gap:4px;border-bottom:1px solid var(--color-divider);overflow-x:auto;scrollbar-width:none;-webkit-overflow-scrolling:touch} 189.sc-tabs::-webkit-scrollbar{display:none} 190/* The report card's overall score (the owner's design, 2026-10-07): a 96px ring in the score's colour band over its label. */ 191.sc-ring{display:flex;flex-direction:column;align-items:center;gap:8px;min-width:170px} 192.sc-ring-c{width:96px;height:96px;border-radius:50%;border:4px solid currentColor;display:flex;align-items:center;justify-content:center;box-sizing:border-box;text-align:center} 193.sc-ring-n{font-family:var(--font-serif);font-size:40px;font-weight:600;line-height:1;font-variant-numeric:tabular-nums} 194/* Calls and emails: one card per channel. Picking one sets the tiles and the chart under it. */ 195.sc-chans{display:grid;grid-template-columns:repeat(var(--chan-n,2),minmax(0,1fr));gap:12px;margin-top:14px} 196.sc-chan{position:relative;border:1px solid var(--color-divider);background:transparent;border-radius:12px;padding:14px 16px;cursor:pointer;text-align:left;font:inherit;color:inherit;min-width:0} 197.sc-chan:hover{border-color:rgba(0,136,176,.5)} 198.sc-chan.on{border-color:var(--color-accent);background:#fff;box-shadow:0 6px 18px rgba(0,136,176,.1)} 199.sc-chan.on::before{content:"";position:absolute;top:-1px;left:16px;right:16px;height:2px;background:var(--color-accent);border-radius:0 0 2px 2px} 200.sc-chan:focus-visible{outline:2px solid var(--color-accent);outline-offset:2px} 201/* The dark banner at the top of the Feedback and Summaries tabs. */ 202.sc-hero{position:relative;overflow:hidden;background:var(--color-accent-800);color:#fff;border-radius:18px;padding:22px 26px 20px}
203.sc-hero-k{display:flex;align-items:center;gap:8px;font-size:11.5px;letter-spacing:.1em;text-transform:uppercase;color:#a8dcef;font-weight:600} 204.sc-hero-h{font-family:var(--font-serif);font-size:23px;font-weight:600;line-height:1.3;margin:8px 0 0;max-width:72ch;text-wrap:pretty} 205.sc-hero-s{font-size:13px;color:#c6e6f2;line-height:1.5} 206.sc-hero-foot{display:flex;align-items:center;gap:12px;flex-wrap:wrap;margin:18px -26px -20px;padding:14px 26px 16px;border-top:1px solid rgba(255,255,255,.14);background:color-mix(in srgb,var(--color-accent-800) 82%,#000)} 207.sc-hero .ghostbtn{background:rgba(255,255,255,.1);border-color:rgba(255,255,255,.22);color:#fff} 208.sc-hero .ghostbtn:hover:not(:disabled){background:rgba(255,255,255,.18)} 209.sc-hchip{display:inline-flex;align-items:center;gap:7px;border:none;border-radius:999px;padding:7px 13px;font:inherit;font-size:13px;font-weight:700;background:#ffd166;color:#3d2900;cursor:pointer;text-decoration:none} 210.sc-hbtn{display:inline-flex;align-items:center;gap:7px;border:none;border-radius:10px;padding:9px 15px;font:inherit;font-size:13.5px;font-weight:700;background:#ffd166;color:#3d2900;cursor:pointer} 211.sc-hbtn:disabled{opacity:.6;cursor:default} 212.sc-dkseg{display:inline-flex;gap:2px;background:rgba(255,255,255,.08);border-radius:999px;padding:3px;flex-wrap:wrap} 213.sc-dkseg button{border:none;background:transparent;color:#c6e6f2;font:inherit;font-size:12.5px;padding:5px 11px;border-radius:999px;cursor:pointer;white-space:nowrap} 214.sc-dkseg button.on{background:#fff;color:var(--color-accent-800)} 215.sc-dkseg button:disabled{cursor:default} 216.sc-ed-sched .sc-dkseg{background:#eef3f7;border:1px solid #c9d6e0} 217.sc-ed-sched .sc-dkseg button{color:rgba(32,30,29,.6)} 218.sc-ed-sched .sc-dkseg button.on{background:#2d2b2b;color:#fff} 219/* Section headings inside a tab: an icon tile, the serif title, a count at the right. */ 220.sc-h3row{display:flex;align-items:center;gap:10px;min-height:36px;flex-wrap:wrap} 221.sc-h3{font-family:var(--font-serif);font-size:22px;font-weight:600;margin:0;line-height:1.2} 222.sc-htile{width:32px;height:32px;border-radius:10px;display:inline-flex;align-items:center;justify-content:center;flex:none;font-size:18px} 223/* Keep doing this and Where to improve: one card per habit, side by side in rows. */ 224.sc-fbgrid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px 18px;min-width:0} 225.sc-habit{background:var(--color-card);border:1px solid rgba(32,30,29,.12);border-radius:14px;padding:14px 16px;min-width:0;height:100%;box-sizing:border-box;display:flex;flex-direction:column} 226.sc-habit.imp{background:var(--color-amber-banner);border-color:var(--color-amber-border)} 227.sc-habit-t{font-size:15.5px;font-weight:650;margin-top:8px;line-height:1.35} 228.sc-habit-m{display:flex;gap:12px;flex-wrap:wrap;font-size:12.5px;color:rgba(32,30,29,.55);margin-top:3px} 229.sc-habit-m>span{display:inline-flex;align-items:center;gap:4px} 230.sc-prio{display:inline-flex;align-items:center;gap:5px;font-size:11.5px;font-weight:700;padding:3px 10px;border-radius:999px;background:var(--color-accent-100);color:var(--color-accent-800);max-width:100%;min-width:0;text-decoration:none} 231.sc-prio>span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0} 232.sc-habit.imp .sc-prio{background:#fff;color:#8a5510;border:1px solid #ecd9b5} 233.sc-num{width:22px;height:22px;border-radius:999px;background:var(--color-amber);color:#fff;font-size:12px;font-weight:700;display:inline-flex;align-items:center;justify-content:center;flex:none} 234.sc-try{background:#fff;border-radius:10px;padding:10px 12px;margin-top:10px;display:grid;grid-template-columns:auto minmax(0,1fr);gap:6px 10px;font-size:13px;line-height:1.45} 235.sc-try>b{font-weight:700} 236.sc-try>.try{font-family:var(--font-serif);font-style:italic;font-size:14px;text-wrap:pretty} 237.sc-moms{margin-top:10px} 238.sc-mom{display:grid;grid-template-columns:16px minmax(0,1fr) auto;gap:10px;align-items:baseline;padding:6px 0;font-size:13px;border-top:1px solid rgba(32,30,29,.06)} 239.sc-mom>i{font-size:13px;transform:translateY(2px)} 240.sc-mom a{font-size:12px;color:rgba(32,30,29,.5);white-space:nowrap;display:inline-flex;align-items:center;gap:4px;text-decoration:none} 241.sc-mom a:hover{color:var(--color-link)} 242.sc-vote{padding-top:10px;margin-top:10px;border-top:1px dashed rgba(32,30,29,.14)} 243.sc-vote>div:first-child{margin-top:0!important} 244@keyframes sc-spin{to{transform:rotate(360deg)}} 245/* Phones: one column everywhere, every tap target at least 40px tall. */ 246@media (max-width:820px){ 247 .sc-body{padding:0 16px var(--tsv-pill-clearance,96px)} 248 .sc-kpis{grid-template-columns:1fr 1fr} 249 .sc-kpi{padding:12px 16px;border-bottom:1px solid var(--color-border)} 250 .sc-kpi:nth-child(2n){border-right:none} 251 .sc-kpi:last-child,.sc-kpi:nth-last-child(2):nth-child(odd){border-bottom:none} 252 .sc-kpi:last-child:nth-child(odd){grid-column:1/-1;border-right:none} 253 .sc-chans,.sc-fbgrid{grid-template-columns:1fr} 254 .sc-ring{min-width:0} 255 .sc-hero{padding:18px 18px 16px} 256 .sc-hero-h{font-size:20px} 257 .sc-hero-foot{margin:16px -18px -16px;padding:12px 18px 14px} 258 .sc-page .sc-hchip,.sc-page .sc-hbtn,.sc-page .sc-dkseg button,.sc-page .sc-chan{min-height:40px} 259 .sc-page .sc-card{padding:16px!important} 260 .sc-page .ghostbtn,.sc-page .primary,.sc-page .tr-seg,.sc-page .tr-tabbt
260n,.sc-page .sc-mi,.sc-page .sc-back,.sc-page .sc-date,.sc-page .sc-link,.sc-page .sc-quiet,.sc-page .sc-chipbtn{min-height:40px} 261 .sc-page .sc-linkbtn{display:inline-flex;align-items:center;min-height:40px} 262 .sc-page .sc-row,.sc-page .sc-erow{min-height:56px} 263 .sc-th{display:none} 264 .sc-page .sc-find{width:100%;min-height:40px;padding-right:40px} 265 .sc-page .sc-team{max-width:none;width:100%;min-height:40px} 266 .sc-teamhd{grid-template-areas:"name score" "meta meta";column-gap:12px;padding:12px 14px} 267 .sc-teamnm{font-size:19px;align-self:center} 268 .sc-teammeta{gap:4px 8px;margin-top:6px} 269 .sc-teamsc{gap:10px} 270 .sc-page .sc-nomgr,.sc-page .sc-quietlink{display:inline-flex;align-items:center;min-height:40px} 271 .sc-bars{gap:4px;padding:0 2px} 272 /* iOS zooms any field under 16px on focus and the page never shrinks back; !important beats the inline sizes in CoachRate. */ 273 .sc-body input:not([type=checkbox]),.sc-body select,.sc-body textarea{font-size:16px!important} 274 .sc-page .tr-tabbtn{padding:9px 10px 11px} 275 .sc-page .tr-tabbtn>i{display:none} 276 .sc-page .sc-freq .tr-seg{padding:5px 8px} 277} 278`;function Ja(e){const[n,i]=h.useState(null),[o,a]=h.useState(!1);return h.useEffect(()=>{if(!n)return;const d=()=>a(n.scrollWidth-n.clientWidth-n.scrollLeft>4);d(),n.addEventListener("scroll",d,{passive:!0});const c=typeof ResizeObserver>"u"?null:new ResizeObserver(d);return c?.observe(n),()=>{n.removeEventListener("scroll",d),c?.disconnect()}},[n]),h.useEffect(()=>{if(!n)return;const d=n.querySelector(".on");if(d){const c=d.offsetLeft,b=c+d.offsetWidth;c<n.scrollLeft?n.scrollLeft=Math.max(0,c-12):b>n.scrollLeft+n.clientWidth&&(n.scrollLeft=b-n.clientWidth+12)}a(n.scrollWidth-n.clientWidth-n.scrollLeft>4)},[n,e]),{ref:i,more:o}}const Xe=({size:e=16})=>t.jsx("i",{className:"ph-duotone ph-circle-notch",style:{fontSize:e,animation:"sc-spin .8s linear infinite"}}),We=({label:e,value:n,sub:i,icon:o,iconBg:a,iconFg:d,color:c})=>t.jsxs("div",{className:"sc-kpi",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[t.jsx("span",{className:"sc-kpi-l",children:e}),t.jsx("span",{className:"sc-ic",style:{background:a,color:d},children:t.jsx("i",{className:`ph-duotone ${o}`})})]}),t.jsx("div",{className:"sc-kpi-n",style:c?{color:c}:void 0,children:n}),t.jsx("div",{className:"sc-kpi-s",children:i})]}),ti=({a:e,height:n=7})=>t.jsxs("div",{className:"sc-sbar",style:{height:n},children:[t.jsx("span",{style:{width:`${e.posPct}%`,background:nn}}),t.jsx("span",{style:{width:`${e.neuPct}%`,background:sn}}),t.jsx("span",{style:{width:`${e.negPct}%`,background:$n}})]}),Ri=e=>e?e.kind==="desk"?{email:e.managerEmail,name:e.managerName}:{email:e.email,name:e.name}:{email:null,name:null};function kr(){const{summary:e,scoreAgents:n,range:i,loadedAt:o,hiddenAgents:a,rosterMeta:d,groups:c,handoffs:b,emails:f,phoneNames:j}=Wt.useLoaderData(),g=Wt.useSearch(),p=Wt.useRouteContext().org.timezone,v=oi(p),N=Ui(),W=qi(),T=Yt(),[_,O]=h.useState(!1),[U,ce]=h.useState(null),K=async()=>{O(!0);try{await Promise.all([W.invalidate(),new Promise(l=>setTimeout(l,700))]),ce(new Date)}finally{O(!1)}},q=g.period,Te=`${q}|${g.from??""}|${g.to??""}`,ee=l=>N({to:"/scorecards",search:A=>({...A,period:l.period,from:l.from,to:l.to})}),F=g.team?c.find(l=>l.key===g.team)??null:null,w=c.some(l=>l.isTeam),P=l=>N({to:"/scorecards",search:{...g,team:l||void 0},replace:!0}),[D,Z]=h.useState("score"),[te,Y]=h.useState(""),[H,V]=h.useState(!1),[me,Ee]=h.useState(null),[Ue,qe]=h.useState("overview"),[Re,X]=h.useState("");h.useEffect(()=>{Yi().then(l=>X(l.orgName||"")).catch(()=>{})},[]);const[re,ke]=h.useState(new Map),[it,Se]=h.useState(!1),[ue,ht]=h.useState({enabled:!1,dayOfWeek:5,hour:17}),[ze,Ye]=h.useState(!1),[yt,Ve]=h.useState(!1),[he,Fe]=h.useState(!1),[Le,ye]=h.useState(!1),[Je,ot]=h.useState([]);h.useEffect(()=>{Xl().then(l=>ke(new Map(l.agents.map(A=>[A.name,A])))).catch(()=>{}).finally(()=>Se(!0)),yo().then(ht).catch(()=>{}).finally(()=>Ye(!0)),bo().then(l=>ot(l.teams)).catch(()=>{})},[]);const Me=async l=>{const A={...ue,...l};ht(A),Ve(!0);try{await vo({data:{enabled:A.enabled,dayOfWeek:A.dayOfWeek,hour:A.hour}}),Fe(!0),setTimeout(()=>Fe(!1),1600)}catch{}finally{Ve(!1)}},Qe=[{v:1,l:"Monday"},{v:2,l:"Tuesday"},{v:3,l:"Wednesday"},{v:4,l:"Thursday"},{v:5,l:"Friday"},{v:6,l:"Saturday"},{v:7,l:"Sunday"}],De=l=>`${l%12||12}:00 ${l<12?"AM":"PM"}`,de=h.useCallback((l,A)=>{ke(S=>{const I=new Map(S),L=I.get(l);return L&&I.set(l,{...L,frequency:A}),I})}
278,[]),Pe=new Set(a),mt=l=>!F||!Ce(l)&&d[l.name]?.group?.key===F.key,lt=!!f?.available,Q=h.useMemo(()=>n?Vi(n,f?.available?f.scoreReplies:null):null,[n,f]),le=h.useMemo(()=>e.agents.map(l=>{const A=Gi(Q,l.name),S=f?.available?f.byName[l.name]??{replies:0,firstReplies:0,avgWaitMin:null,covered:0}:null;return{...l,score:A.score,scoreCalls:A.calls,scoreEmails:A.emails,scoreReady:!!Q&&A.ready,scoreKnown:!!Q,emails:S}}),[e.agents,Q,f]).filter(mt),ne=le.filter(l=>!Pe.has(l.name)).sort((l,A)=>D==="az"?l.name.localeCompare(A.name):D==="volume"?A.total-l.total:D==="attention"?A.misses-l.misses||A.coach-l.coach||l.score-A.score:Js(l,A)),et=l=>l.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase(),He=et(te.trim()),Be=He?ne.filter(l=>et(l.name).includes(He)):ne,tt=me?ne.find(l=>l.name===me)??null:null,ge=l=>d[l.name],bt=l=>ge(l)?.group?.key??null,$=c.some(l=>ne.some(A=>!Ce(A)&&bt(A)===l.key)),M=l=>Ce(l)?"desks":$?`group:${bt(l)??""}`:"people",E=new Map,fe=new Map;for(const l of[...ne].sort(Js)){const A=M(l),S=(fe.get(A)??0)+1;fe.set(A,S),E.set(l.name,S)}const be=l=>ys(l),at=l=>`weighted by ${so(l).toLocaleString("en-US")} ${l.some(A=>A.scoreReady&&A.scoreEmails>0)?"calls and emails":"calls"}`,rt=le.reduce((l,A)=>l+A.total,0),Ze=ys(le),kt=Bt(le.reduce((l,A)=>l+A.pos,0),rt),ut=le.reduce((l,A)=>l+(A.graded??0),0),$e=ut>0?Bt(le.reduce((l,A)=>l+(A.well??0),0),ut):null,Ie=le.reduce((l,A)=>l+A.misses,0),se=(()=>{if(!lt||!f)return null;const l=[...le.filter(L=>!Ce(L)).map(L=>L.emails).filter(L=>!!L),...F?[]:[f.shared]],A=l.reduce((L,R)=>L+R.replies,0),S=l.filter(L=>L.avgWaitMin!=null&&L.firstReplies>0),I=S.reduce((L,R)=>L+R.firstReplies,0);return{replies:A,avgWaitMin:I?S.reduce((L,R)=>L+(R.avgWaitMin??0)*R.firstReplies,0)/I:null}})(),Et=l=>l.scoreKnown?l.scoreReady?l.score:no(l.scoreCalls+l.scoreEmails):"",St=l=>l.emails?[l.emails.replies,l.emails.avgWaitMin??""]:["",""],$t=()=>{const A=(w?[["Name","Title","Team","Team manager","Role","Score","Calls","Emails","Average first reply (minutes)","Positive %","Negative %","Misses","Wins","Flagged"],...ne.map(R=>[R.name,ge(R)?.title??"",ge(R)?.group?.name??"",ge(R)?.group?.manager??"",R.role,Et(R),R.total,...St(R),R.posPct,R.negPct,R.misses,R.wins,R.coach])]:[["Name","Title","Location","Role","Score","Calls","Emails","Average first reply (minutes)","Positive %","Negative %","Misses","Wins","Flagged"],...ne.map(R=>[R.name,ge(R)?.title??"",ge(R)?.location??"",R.role,Et(R),R.total,...St(R),R.posPct,R.negPct,R.misses,R.wins,R.coach])]).map(R=>R.map(ft=>`"${String(ft).replace(/"/g,'""')}"`).join(",")).join(` 279`),S=URL.createObjectURL(new Blob([A],{type:"text/csv;charset=utf-8"})),I=F?`-${F.name.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}`:"",L=document.createElement("a");L.href=S,L.download=`teleserv-scorecards-${q}${I}.csv`,L.click(),URL.revokeObjectURL(S)},[u,x]=h.useState(!1),[ie,C]=h.useState(null),s=async()=>{if(!await zn({title:"Send the coaching digests now?",body:"TeleServ builds a digest for every reservationist and each desk's manager from the calls in their own period (the last week, two weeks or month, as their Summaries tab is set), then sends them from your Outlook. Anyone whose digest already went out for that period, or who had no calls, is skipped.",confirmLabel:"Send digests"}))return;const l=[...re.values()].filter(I=>I.frequency!=="off");x(!0),C(null);let A=0;const S=[];try{if(l.length===0){C("Nobody is set to receive a digest. Turn one on in a person's Summaries tab.");return}for(let I=0;I<l.length;I++){const L=l[I];C(`Building ${I+1} of ${l.length}: ${L.name}â¦`);try{const R=await Ei(L.agentId,!1);if(R.kind==="pending"){S.push(`${L.name}: still building, try again in a minute`);continue}if(!R.due||!R.digestId){S.push(`${L.name}: ${R.dueReason?os(R.dueReason,ds(L.frequency)):"not due"}`);continue}await Bn({data:{id:R.digestId}}),A++}catch(R){S.push(`${L.name}: ${R instanceof Error?R.message:"could not send"}`)}}C(`Sent ${A} of ${l.length}.${S.length?` 280${S.join(` 281`)}`:""}`)}finally{x(!1)}},r=async l=>{const A=`${l.agents} ${l.agents===1?"person":"people"}`,S=l.scope==="company"?`the whole company (${A})`:`${l.name||l.email}'s team (${A})`;if(await zn({title:"Send the team email?",body:`TeleServ builds this week's team email about ${S} from the last seven days of calls, then sends it to ${l.email} from your Outlook. If this week's team email already went out, it is skipped.`,confirmLabel:"Send team email"})){x(!0),C(`Building the team email for ${l.email}â¦`);try{const I=await Za(l,!1);if(I.kind==="pending"){C(`${l.email}: still building, try again in a minute`);return}if(!I.due||!I.digestId){C(`${l.email}: ${I.dueReason??"not due"}`);return}await Bn({data:{id:I.digestId}}),C(`Team email sent to ${l.email}.`)}catch(I){C(`${l.email}: ${I instanceof Error?I.message:"could not send"}`)}finally{x(!1)}}},k=l=>{ye(l),!l&&!u&&C(null)};h.useEffect(()=>{const l=()=>{window.scrollTo({top:0,behavior:"smooth"}),ye(!0)};return window.addEventListener(is,l),()=>window.removeEventListener(is,l)},[]);const G=new Date,xe=[G.toLocaleDateString("en-US",{timeZone:p,weekday:"long"}),G.toLocaleDateString("en-US",{timeZone:p,month:"short",day:"numeric",year:"numeric"}
281),Re].filter(Boolean).join(" · "),pe=[{v:"score",label:"Score"},{v:"attention",label:"Most misses"},{v:"volume",label:"Call volume"},{v:"az",label:"A to Z"}],Lt=pe.find(l=>l.v===D)?.label??"Score",yn=t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,flexWrap:"wrap",minWidth:0},children:[t.jsx(So,{period:q,from:g.from,to:g.to,onChange:ee}),t.jsxs("button",{className:"ghostbtn",onClick:$t,disabled:ne.length===0,children:[t.jsx("i",{className:"ph-duotone ph-download-simple"}),"CSV"]}),t.jsxs("button",{className:"ghostbtn",onClick:K,disabled:_,children:[t.jsx("i",{className:"ph-duotone ph-arrows-clockwise",style:_?{animation:"sc-spin .8s linear infinite"}:void 0}),_?"Refreshingâ¦":"Refresh"]}),t.jsxs("div",{style:{position:"relative"},children:[t.jsxs("button",{className:"primary",onClick:()=>k(!Le),"aria-haspopup":"dialog","aria-expanded":Le,title:"Send the coaching digests now, or set the company auto-send schedule",children:[u?t.jsx(Xe,{size:15}):t.jsx("i",{className:"ph-duotone ph-paper-plane-tilt",style:{fontSize:15}}),ue.enabled?`Weekly digest · Auto ${(Qe.find(l=>l.v===ue.dayOfWeek)?.l??"Friday").slice(0,3)} ${De(ue.hour)} ${v}`:"Weekly digest",t.jsx("i",{className:"ph-duotone ph-caret-down",style:{fontSize:12}})]}),Le&&t.jsxs("div",{className:"sc-menu",role:"dialog","aria-label":"Weekly coaching digest",style:{minWidth:340,maxWidth:"calc(100vw - 32px)",padding:"14px 16px",textAlign:"left",cursor:"default"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9},children:[t.jsx("span",{style:{width:30,height:30,borderRadius:9,background:Oe,color:"var(--color-accent-800)",display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"none"},children:t.jsx("i",{className:"ph-duotone ph-calendar-check",style:{fontSize:16}})}),t.jsx("div",{className:"serif",style:{fontSize:15.5,fontWeight:600,lineHeight:1.2},children:"Weekly coaching digest"})]}),t.jsxs("button",{className:"primary",onClick:s,disabled:u,style:{width:"100%",justifyContent:"center",marginTop:12},children:[u?t.jsx(Xe,{size:15}):t.jsx("i",{className:"ph-duotone ph-paper-plane-tilt",style:{fontSize:15}}),u?"Sendingâ¦":"Send now"]}),ie&&t.jsx("div",{style:{fontSize:12,color:y(50),marginTop:6,lineHeight:1.5,whiteSpace:"pre-line"},children:ie}),Je.length>0&&t.jsxs("div",{style:{marginTop:10},children:[t.jsx("div",{style:{fontSize:11,letterSpacing:".08em",textTransform:"uppercase",color:y(50),fontWeight:600},children:"Team email"}),Je.map(l=>t.jsxs("button",{className:"ghostbtn",onClick:()=>{r(l)},disabled:u,title:`Build this week's team email and send it to ${l.email} from your Outlook`,style:{width:"100%",justifyContent:"flex-start",marginTop:6,textAlign:"left"},children:[t.jsx("i",{className:"ph-duotone ph-users-three",style:{fontSize:15,flex:"none"}}),t.jsxs("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[l.scope==="company"?"Whole company":l.name||l.email,t.jsxs("span",{style:{color:y(50),fontWeight:400},children:[" · ",l.agents," ",l.agents===1?"person":"people",l.name||l.scope==="company"?` · ${l.email}`:""]})]})]},`${l.scope}:${l.email}`))]}),t.jsx("div",{style:{borderTop:"1px solid var(--color-divider)",marginTop:12}}),t.jsxs("label",{style:{display:"flex",alignItems:"center",gap:10,cursor:"pointer",fontSize:13.5,fontWeight:600,minHeight:40,marginTop:6,opacity:ze?1:.55},children:[t.jsx(cs,{checked:ue.enabled,onChange:l=>{Me({enabled:l})},label:"Auto-send every week",disabled:!ze}),"Auto-send every week"]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:6,opacity:ue.enabled?1:.45,flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:12.5,color:y(55)},children:"on"}),t.jsx("select",{className:"fld-in","aria-label":"Day of the week",value:ue.dayOfWeek,disabled:!ue.enabled,onChange:l=>{Me({dayOfWeek:Number(l.target.value)})},style:{width:"auto",minHeight:36},children:Qe.map(l=>t.jsx("option",{value:l.v,children:l.l},l.v))}),t.jsx("span",{style:{fontSize:12.5,color:y(55)},children:"at"}),t.jsx("select",{className:"fld-in","aria-label":"Hour",value:ue.hour,disabled:!ue.enabled,onChange:l=>{Me({hour:Number(l.target.value)})},style:{width:"auto",minHeight:36},children:Array.from({length:24},(l,A)=>t.jsx("option",{value:A,children:De(A)},A))}),t.jsx("span",{style:{fontSize:12.5,color:y(55)},title:"The company time zone, set in Account management",children:v}),yt?t.jsx("span",{style:{fontSize:12,color:y(45)},children:"Savingâ¦"}):he?t.jsxs("span",{style:{fontSize:12,color:"var(--color-accent-700)",display:"inline-flex",alignItems:"center",gap:4},children:[t.jsx("i",{className:"ph-duotone ph-check-circle"}),"Saved"]}):null]}),t.jsxs("div",{style:{fontSize:12,color:y(50),marginTop:10,lineHeight:1.5,display:"flex",alignItems:"flex-start",ga
281p:6},children:[t.jsx("i",{className:"ph-duotone ph-info",style:{fontSize:14,flex:"none",marginTop:2}}),t.jsxs("span",{children:["This is the company schedule and master switch. Each person's own Summaries tab decides whether they get one and how often (weekly, every two weeks, monthly).",ue.enabled?" Automatic sends go out from a TeleServ system sender, so they don't need you online.":""]})]})]})]}),U&&t.jsxs("span",{style:{fontSize:11.5,color:y(45),whiteSpace:"nowrap"},children:["Updated ",U.toLocaleTimeString("en-US",{timeZone:p,hour:"numeric",minute:"2-digit"})]})]});return t.jsxs("div",{className:"sc-page",children:[t.jsx("style",{children:Xa}),Le&&t.jsx("div",{onClick:()=>k(!1),style:{position:"fixed",inset:0,zIndex:45}}),t.jsx(Zi,{kicker:xe,title:"Agent Scorecards",right:yn}),me?tt?t.jsx(er,{ag:tt,rankIndex:(E.get(tt.name)??1)-1,teamScore:Ze,period:q,search:g,viewKey:Te,range:i,loadedAt:o,tab:Ue,setTab:qe,onBack:()=>Ee(null),pref:re.get(tt.name),prefsLoaded:it,onPref:de,schedule:ue,orgName:Re,meta:ge(tt)}):t.jsxs("div",{className:"sc-body",children:[t.jsxs("button",{className:"sc-back",onClick:()=>Ee(null),style:{marginTop:18},children:[t.jsx("i",{className:"ph-duotone ph-arrow-left"}),"All agents"]}),t.jsxs("div",{style:{textAlign:"center",padding:"60px 0",color:y(45),fontSize:14},children:[me," has no attributed calls in ",we(q),". Try a wider range."]})]}):t.jsxs("div",{className:"sc-body",children:[H&&t.jsx("div",{onClick:()=>V(!1),style:{position:"fixed",inset:0,zIndex:45}}),t.jsxs("div",{className:"sc-kpis",style:{"--kpi-n":5},children:[t.jsx(We,{label:"Team score",value:Ze??t.jsx("span",{style:{fontSize:14,fontWeight:500,color:Ae},children:Q?"Not enough yet":"Not available"}),sub:Ze!=null?`last 30 days, ${at(le)}`:Q?`${Ka} per person`:"refresh to try again",icon:"ph-medal",iconBg:Oe,iconFg:"var(--color-accent)",color:Ze!=null?gn(Ze):void 0}),t.jsx(We,{label:"Calls handled",value:rt.toLocaleString("en-US"),sub:`across ${ne.length} ${ne.length===1?"agent":"agents"}`,icon:"ph-phone-call",iconBg:"var(--color-control-bg)",iconFg:"var(--color-control-text)"}),t.jsx(We,{label:"Emails answered",value:se?se.replies.toLocaleString("en-US"):t.jsx("span",{style:{fontSize:14,fontWeight:500,color:Ae},children:"Not available"}),sub:se?se.avgWaitMin!=null?`${jt(se.avgWaitMin)} average first reply`:se.replies?"no first replies in the period":`none in ${we(q)}`:"refresh to try again",icon:"ph-envelope-open",iconBg:"var(--color-control-bg)",iconFg:"var(--color-control-text)"}),$e!=null?t.jsx(We,{label:"Handled well",value:`${$e}%`,sub:`of ${ut.toLocaleString("en-US")} graded ${ut===1?"call":"calls"}`,icon:"ph-thumbs-up",iconBg:Oe,iconFg:ae,color:ae}):t.jsx(We,{label:"Positive",value:`${kt}%`,sub:"of analyzed calls",icon:"ph-thumbs-up",iconBg:Oe,iconFg:ae,color:ae}),t.jsx(We,{label:"Misses",value:Ie,sub:"calls where our side slipped",icon:"ph-warning-circle",iconBg:ts,iconFg:je,color:Ie>0?je:void 0})]}),t.jsxs("div",{style:{fontSize:12,color:y(50),marginTop:8},children:[li," The period above sets the calls and counts. ",Xi]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:16,margin:"22px 0 14px",flexWrap:"wrap"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,fontSize:13,color:y(60)},children:[t.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:"var(--color-accent)",flex:"none"}}),t.jsxs("span",{children:["Calls from ",j.length?Ji(j):"your phone system"," · ",!f||!lt?"emails not available just now":f.mailboxes>0?t.jsxs(t.Fragment,{children:["emails from ",t.jsxs("b",{style:{color:It},children:[f.mailboxes," ",f.mailboxes===1?"mailbox":"mailboxes"]}),", matched to who replied"]}):f.shared.replies>0||Object.keys(f.byName).length>0?"emails matched to who replied":"no mailbox connected"," · ",t.jsxs("b",{style:{color:It},children:[ne.length," ",ne.length===1?"agent":"agents"]}),F?` in ${F.name}`:""," · ",we(q),lt&&f&&f.shared.replies>0&&!F&&t.jsxs("span",{title:"A reply whose signature names nobody on the team, sent from a shared inbox, is never pinned on a person.",children:[" · ",f.shared.replies," ",f.shared.replies===1?"reply":"replies"," with no name stay with the shared inbox",f.shared.avgWaitMin!=null?`, ${jt(f.shared.avgWaitMin)} average first reply`:""]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:T?"1 1 100%":"
2810 0 auto",flexWrap:T&&c.length>0?"wrap":"nowrap"},children:[c.length>0&&t.jsxs("select",{className:"fld-in sc-team","aria-label":"Show one team",title:"Show one team: the numbers, the rows and the CSV cover that team only",value:F?.key??"",onChange:l=>P(l.target.value),style:{flex:T?"1 1 100%":void 0},children:[t.jsx("option",{value:"",children:"All teams"}),c.map(l=>t.jsx("option",{value:l.key,children:l.name},l.key))]}),t.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",flex:T?"1 1 160px":void 0},children:[t.jsx("i",{className:"ph-duotone ph-magnifying-glass",style:{position:"absolute",left:11,fontSize:14,color:"#7f93a3",pointerEvents:"none"}}),t.jsx("input",{className:"sc-find",value:te,onChange:l=>Y(l.target.value),placeholder:"Find an agent","aria-label":"Find an agent by name",autoComplete:"off",spellCheck:!1,onKeyDown:l=>{l.key==="Escape"&&Y("")}}),te&&t.jsx("button",{type:"button",onClick:()=>Y(""),title:"Clear","aria-label":"Clear",style:{position:"absolute",right:T?0:4,border:"none",background:"transparent",cursor:"pointer",color:"#7f93a3",padding:0,width:T?40:28,height:T?40:28,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:14},children:t.jsx("i",{className:"ph ph-x"})})]}),He&&t.jsxs("span",{style:{fontSize:12.5,color:y(55),whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:[t.jsx("b",{style:{color:It},children:Be.length})," of ",ne.length]}),t.jsxs("div",{style:{position:"relative",marginLeft:T?"auto":void 0},children:[t.jsxs("button",{className:"ghostbtn",onClick:()=>V(l=>!l),"aria-haspopup":"menu","aria-expanded":H,style:{borderRadius:999,padding:"6px 10px 6px 12px",fontSize:12.5},children:[t.jsx("span",{style:{color:Ae},children:"Sort"}),t.jsx("span",{style:{fontWeight:600},children:Lt}),t.jsx("i",{className:"ph-duotone ph-caret-down",style:{fontSize:12,color:Ae}})]}),H&&t.jsx("div",{className:"sc-menu",role:"menu",children:pe.map(l=>t.jsxs("button",{role:"menuitemradio","aria-checked":D===l.v,className:"sc-mi",style:D===l.v?{background:"var(--color-control-bg)"}:void 0,onClick:()=>{Z(l.v),V(!1)},children:[t.jsx("span",{children:l.label}),D===l.v&&t.jsx("i",{className:"ph-duotone ph-check",style:{fontSize:13,color:ae}})]},l.v))})]})]})]}),(()=>{const l=Be.filter(m=>!Ce(m)),A=Be.filter(Ce),S=new Map(b.map(m=>[m.deskName,m])),I=F?[]:b.filter(m=>!Pe.has(m.deskName)&&!ne.some(J=>Ce(J)&&J.name===m.deskName)),L=He?I.filter(m=>et(m.deskName).includes(He)):I,R=ne.filter(m=>!Ce(m)),ft=R.length,Rt=ne.length-ft,vt=m=>ge(m)?.group??null,us=c.filter(m=>R.some(J=>vt(J)?.key===m.key)),Di=us.length>0,fs=(m,J)=>He?`${J} of ${m.length} ${m.length===1?"person":"people"}`:`${m.length} ${m.length===1?"person":"people"}`,Li=E,gs=m=>{Ee(m.name),qe("overview")},Mi=m=>{const J=Li.get(m.name)??1,[nt,Nt]=Ci(m,J-1),Tt=m.misses>0?je:Ae,bn=`${m.misses} ${m.misses===1?"miss":"misses"}`,ct=zi(m);return T?t.jsxs("button",{className:"sc-row",onClick:()=>gs(m),style:{padding:"14px 16px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[t.jsx("span",{style:{fontSize:12.5,fontWeight:600,color:Ae,fontVariantNumeric:"tabular-nums",width:18},children:J}),t.jsx("span",{className:"sc-av",style:{width:40,height:40,fontSize:14,background:nt,color:Nt},children:on(m.name)}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{className:"serif",style:{fontSize:16,fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:m.name}),t.jsx("div",{style:{fontSize:12,color:y(52),marginTop:1},children:ge(m)?.title||m.role}),Ce(m)&&S.get(m.name)&&t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,alignSelf:"flex-start",maxWidth:"100%",fontSize:12,fontWeight:600,color:"#006786",background:Oe,borderRadius:999,padding:"2px 9px",marginTop:4},children:[t.jsx("i",{className:"ph-duotone ph-arrow-bend-down-right","aria-hidden":"true"}),jn(S.get(m.name))]})]}),t.jsxs("div",{style:{textAlign:"right"},children:[t.jsx("div",{style:{maxWidth:120},children:t.jsx(ns,{a:m})}),In(m)&&t.jsx("div",{style:{marginTop:4},children:t.jsx(Wn,{a:m})}),t.jsxs("div",{style:{fontSize:11.5,color:y(50),marginTop:3,fontVariantNumeric:"tabular-nums",display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6},children:[t.jsxs("span",{children:[m.total," calls"]}),m.emails&&!Ce(m)&&t.jsxs("span",{children:["· ",m.emails.replies," ",m.emails.replies===1?"email":"emails",m.emails.avgWaitMin!=null?`, ${jt(m.emails.avgWaitMin)} reply`:""]})]})]})]}),t.jsxs("div",{style:{marginTop:12},children:[t.jsx(ti,{a:m}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:6,fontSize:11.5,color:y(55),fontVariantNumeric:"tabular-nums"},children:[t.jsxs("span",{children:[m.posPct,"% positive"]}),t.jsxs("span",{style:{color:m.negPct>0?je:void 0},children:[m.negPct,"% negative"]})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,marginTop:10,fontSize:12.5,flexWrap:"wrap"},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,color:ae},children:[t.jsx("i",{className:"ph-duotone ph-star"}),m.wins," wins"]}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,color:Tt}
281,children:[t.jsx("i",{className:"ph-duotone ph-warning-circle"}),bn]})]})]},m.name):t.jsxs("button",{className:"sc-row sc-grid",onClick:()=>gs(m),children:[t.jsx("span",{style:{fontSize:12.5,fontWeight:600,color:Ae,fontVariantNumeric:"tabular-nums"},children:J}),t.jsx("span",{className:"sc-av",style:{width:40,height:40,fontSize:14,background:nt,color:Nt},children:on(m.name)}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{className:"serif",style:{fontSize:16,fontWeight:600,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:m.name}),t.jsx("div",{style:{fontSize:12,color:y(52),marginTop:1},children:ge(m)?.title||m.role}),Ce(m)&&S.get(m.name)&&t.jsxs("div",{title:jn(S.get(m.name)),style:{display:"inline-flex",alignItems:"center",gap:5,alignSelf:"flex-start",maxWidth:"100%",fontSize:12,fontWeight:600,color:"#006786",background:Oe,borderRadius:999,padding:"2px 9px",marginTop:4},children:[t.jsx("i",{className:"ph-duotone ph-arrow-bend-down-right","aria-hidden":"true",style:{flex:"none"}}),t.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:jn(S.get(m.name))})]})]}),t.jsxs("div",{children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:6},children:t.jsx(ns,{a:m})}),!ct&&t.jsx("div",{style:{height:4,borderRadius:999,background:y(8),marginTop:7,overflow:"hidden"},children:t.jsx("span",{style:{display:"block",height:"100%",width:`${m.score}%`,background:Ba(m),borderRadius:999}})}),In(m)&&t.jsx("div",{style:{marginTop:5},children:t.jsx(Wn,{a:m})})]}),t.jsxs("div",{style:{lineHeight:1.2},children:[t.jsx("div",{className:"serif",style:{fontSize:18,fontWeight:600,fontVariantNumeric:"tabular-nums"},children:m.total}),m.total>0&&t.jsxs("div",{title:"Average call length",style:{fontSize:11.5,color:y(55),marginTop:3,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:[Nn(m.avgDur)," avg"]})]}),t.jsx(Ua,{a:m,period:q}),t.jsxs("div",{children:[t.jsx(ti,{a:m}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:6,fontSize:11.5,color:y(55),fontVariantNumeric:"tabular-nums"},children:[t.jsxs("span",{children:[m.posPct,"% positive"]}),t.jsxs("span",{style:{color:m.negPct>0?je:void 0},children:[m.negPct,"% negative"]})]})]}),t.jsxs("div",{style:{display:"flex",gap:12,fontSize:12.5,whiteSpace:"nowrap"},children:[t.jsxs("span",{title:`${m.wins} wins`,style:{display:"inline-flex",alignItems:"center",gap:5,color:ae},children:[t.jsx("i",{className:"ph-duotone ph-star"}),m.wins]}),t.jsxs("span",{title:bn,style:{display:"inline-flex",alignItems:"center",gap:5,color:Tt},children:[t.jsx("i",{className:"ph-duotone ph-warning-circle"}),m.misses]})]}),t.jsx("i",{className:"ph-duotone ph-caret-right",style:{fontSize:14,color:"#8fa3b3"}})]},m.name)},Dt=(m,J,nt)=>t.jsx("span",{title:J?void 0:nt,children:J?t.jsxs("button",{type:"button",className:"sc-thb","aria-pressed":D===J,title:nt,onClick:()=>Z(J),children:[m,D===J&&t.jsx("i",{className:`ph ${J==="az"?"ph-caret-up":"ph-caret-down"}`,"aria-hidden":"true"})]}):m}),xs=(m,J=[])=>t.jsxs("div",{className:"sc-tbl",children:[t.jsxs("div",{className:"sc-grid sc-th",children:[Dt("#",void 0,"Rank by score"),t.jsx("span",{}),Dt("Agent","az","Sort by name, A to Z"),Dt("Score · 30 days","score","Sort by score, highest first"),Dt("Calls","volume","Sort by calls, most first"),Dt("Emails",void 0,"Replies each person wrote in the period, matched by their signature, and their average first reply"),Dt("Sentiment"),Dt("Wins · misses","attention","Sort by most misses"),t.jsx("span",{})]}),m.map(Mi),J]}),Dn=(m,J,nt,Nt=[])=>nt.length===0&&Nt.length===0?null:t.jsxs("div",{style:{marginBottom:22},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:9,margin:"0 0 10px 2px",flexWrap:"wrap"},children:[t.jsx("span",{className:"seclbl",children:m}),t.jsx("span",{style:{fontSize:12,color:"var(--color-label)"},children:J})]}),xs(nt,Nt)]}),_i=(m,J,nt)=>{if(nt.length===0)return null;const Nt=J.reduce((ct,Gt)=>ct+Gt.total,0),Tt=be(J),bn=Tt!=null?gn(Tt):Ae;return t.jsxs("section",{className:"sc-teamblk","aria-label":m.isTeam?Ni(m.name):m.name,children:[t.jsxs("div",{className:"sc-teamhd",children:[t.jsx("h3",{className:"sc-teamnm",children:m.name}),t.jsxs("div",{className:"sc-teammeta",children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,fontVariantNumeric:"tabular-nums"},children:[t.jsx("i",{className:"ph-duotone ph-users-three","aria-hidden":"true",style:{fontSize:14}}),fs(J,nt.length)]}),m.isTeam&&t.jsx("span",{"aria-hidden":"true",style:{color:y(30)},children:"·"}),m.isTeam&&(m.manager?t.jsxs("span",{className:"sc-teammgr",children:[t.jsx("span",{children:"Manager"}),t.jsx("span",{className:"sc-av","aria-hidden":"true",style:{width:22,height:22,fontSize:10,background:"var(--color-field)",color:At,border:"1px solid var(--color-accent-200)"},children:on(m.manager)}),t.jsx("b",{style:{color:It,fontWeight:600,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m.manager})]}):t.jsxs(gt,{to:"/settings/team",search:{tab:"team"},className:"sc-nomgr",title:"Pick this team's manager on the Team tab",children:[t.jsx("i",{className:"ph-duotone ph-user-circle-plus","aria-hidden":"true",style:{fontSize:15}}),"No manager yet"]}))]}),t.jsxs("div",{className:"sc-teamsc",children:[t.jsxs("div",{style:{textAlign:"right"},children:[t.jsx("div",{className:"seclbl",children:"Team score"}),t.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:6,marginTop:3,fontSize:12,color:y(50),fontVariantNumeric:"tabular-nums",whiteSpace:"nowrap"}
281,children:t.jsxs("span",{children:[Nt.toLocaleString("en-US")," ",Nt===1?"call":"calls"]})})]}),Tt!=null?t.jsx(qa,{score:Tt,tone:bn,size:T?50:56,stroke:5,fontSize:T?18:20,label:`Team score ${Tt}`,title:`Last 30 days, ${at(J)}`}):t.jsx("span",{title:J.some(ct=>ct.scoreKnown)?rs(J.reduce((ct,Gt)=>ct+Gt.scoreCalls,0),J.reduce((ct,Gt)=>ct+Gt.scoreEmails,0)):ms,style:{fontSize:12,color:Ae,maxWidth:90,textAlign:"right",lineHeight:1.3},children:J.some(ct=>ct.scoreKnown)?"Not enough yet":"Score not available"})]})]}),xs(nt)]})},Oi=m=>t.jsxs("div",{className:"sc-row",title:jn(m),style:{cursor:"default",display:"flex",alignItems:"center",gap:12,padding:T?"10px 16px":"9px 18px"},children:[t.jsx("span",{className:"sc-av",style:{width:28,height:28,fontSize:11,background:"var(--color-ink-chip)",color:"#fff",marginLeft:T?30:40},children:on(m.deskName)}),t.jsx("span",{style:{fontSize:14,fontWeight:600},children:m.deskName}),t.jsxs("span",{style:{fontSize:12.5,color:y(55)},children:["all ",m.passed," ",m.passed===1?"call":"calls"," passed to people"]})]},`slim-${m.deskId}`);return t.jsxs(t.Fragment,{children:[Di?t.jsxs(t.Fragment,{children:[us.map(m=>t.jsx(h.Fragment,{children:_i(m,R.filter(J=>vt(J)?.key===m.key),l.filter(J=>vt(J)?.key===m.key))},m.key)),R.some(m=>!vt(m))&&Dn(w?"No team yet":"No location yet",t.jsxs(t.Fragment,{children:[fs(R.filter(m=>!vt(m)),l.filter(m=>!vt(m)).length)," · ",t.jsx(gt,{to:"/settings/team",search:{tab:"team"},className:"sc-quietlink",children:w?"Pick their team on the Team tab":"Type their location on the Team tab"})]}),l.filter(m=>!vt(m)))]}):Dn("Reservationists and agents",He?`${l.length} of ${ft}`:`${l.length}`,l),F?ne.length>0&&t.jsx("div",{style:{fontSize:12.5,color:y(55),margin:"-8px 2px 22px"},children:"Shared dispatch desks are not in a team, so they are hidden while one team is picked."}):Dn("Shared dispatch desks",`${He?`${A.length+L.length} of ${Rt+I.length}`:A.length+L.length} · staffed by a team; feedback goes to the manager`,A,L.map(Oi)),ne.length===0&&(F?t.jsxs("div",{style:{textAlign:"center",padding:"50px 0",color:y(45),fontSize:14},children:["Nobody in ",F.name," has calls in ",we(q),".",t.jsx("div",{style:{marginTop:12},children:t.jsx("button",{type:"button",className:"ghostbtn",onClick:()=>P(""),children:"Show all teams"})})]}):t.jsx("div",{style:{textAlign:"center",padding:"50px 0",color:y(45),fontSize:14},children:e.agents.length>0?"Every line with calls in this period is switched off on the Team tab.":"No agent-attributed calls in this period."})),ne.length>0&&Be.length===0&&L.length===0&&t.jsxs("div",{style:{textAlign:"center",padding:"50px 0",color:y(45),fontSize:14},children:['No agent or desk matches "',te.trim(),'" for ',we(q),".",t.jsx("div",{style:{marginTop:12},children:t.jsx("button",{type:"button",className:"ghostbtn",onClick:()=>Y(""),children:"Show everyone"})})]})]})})()]})]})}const Qa=[{v:"all",label:"All"},{v:"first",label:"First replies"},{v:"slow",label:"Slow replies"},{v:"followup",label:"Follow-ups"}];function er({ag:e,rankIndex:n,teamScore:i,period:o,search:a,viewKey:d,range:c,loadedAt:b,tab:f,setTab:j,onBack:g,pref:p,prefsLoaded:v,onPref:N,schedule:W,orgName:T,meta:_}){const O=Yt(),U=Wt.useRouteContext().org.timezone,[ce,K]=h.useState("all"),[q,Te]=h.useState("all"),[ee,F]=h.useState("calls");h.useEffect(()=>{F("calls"),Te("all")},[e.name]);const[w,P]=h.useState(null),D=Ja(f),Z=`${e.name}|${d}`,[te,Y]=h.useState(null),[H,V]=h.useState(null),[me,Ee]=h.useState(null),[Ue,qe]=h.useState(0),{sinceIso:Re,toIso:X}=c;h.useEffect(()=>{let u=!0;return Ee(null),V(null),P(null),Ti({sinceIso:Re,toIso:X},e.name,(x,ie)=>{u&&V({loaded:x,total:ie})}).then(x=>{u&&Y({view:Z,calls:x.calls,total:x.total})}).catch(x=>{u&&Ee(x instanceof Error?x.message:"Couldn't load this agent's calls.")}),()=>{u=!1}},[e.name,Z,Re,X,b,Ue]);const re=Ce(e),[ke,it]=h.useState(null),[Se,ue]=h.useState(null),ht=f==="replies"||f==="overview"&&ee==="emails";h.useEffect(()=>{if(!ht||re)return;let u=!0;return ue(null),eo({data:{sinceIso:Re,toIso:X,agentName:e.name}}).then(x=>{u&&it({view:Z,r:x})}).catch(x=>{u&&ue(x instanceof Error?x.message:"Couldn't load these replies.")}),()=>{u=!1}},[ht,re,e.name,Z,Re,X,b,Ue]);const ze=te&&te.view===Z?te.calls:null,Ye=te&&te.view===Z?te.total:0,yt=h.useMemo(()=>ze?{...e,calls:ze}:null,[e,ze]),Ve=ze??[],he=hn(e.name),[Fe,Le]=h.useState([]),[ye,Je]=h.useState(!1),ot=h.useCallback(()=>wo({data:{agentName:e.name}}).then(u=>Le(u.digests)).catch(()=>{}).finally(()=>Je(!0)),[e.name]);h.useEffect(()=>{Je(!1),ot()},[ot]);const Me=t.jsxs("div",{style:{marginTop:20,fontSize:13,display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx("span",{style:{color:je},children:me}),t.jsxs("button",{className:"ghostbtn",onClick:()=>qe(u=>u+1),style:{padding:"6px 12px",fontSize:12.5},children:[t.jsx("i",{className:"ph-duotone ph-arrows-clockwise"}),"Try again"]})]}),Qe=me?Me:t.jsxs("div",{style:{marginTop:20,fontSize:13,color:y(52),display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xe,{}),"Loading ",he,"'s callsâ¦",H&&H.total>
281Tn?` ${H.loaded.toLocaleString("en-US")} of ${H.total.toLocaleString("en-US")}`:""]}),De=o==="today"||o==="yesterday"?"hour":o==="7d"||o==="14d"?"day":"week",de=u=>{const x=new Date(u);if(De==="hour"){const C=Ha(x,U);return{key:String(C).padStart(2,"0"),label:`${C%12||12}${C<12?"a":"p"}`}}if(De==="day")return{key:mn(x,U),label:o==="14d"?x.toLocaleDateString("en-US",{timeZone:U,month:"numeric",day:"numeric"}):x.toLocaleDateString("en-US",{timeZone:U,weekday:"short"})};const ie=Ya(u,U);return{key:ie,label:new Date(`${ie}T00:00:00`).toLocaleDateString("en-US",{month:"short",day:"numeric"})}},Pe=(u,x,ie)=>{const C=new Map;for(const s of u){const{key:r,label:k}=de(x(s)),G=C.get(r)??{a:0,b:0,c:0,total:0,label:k,sort:r};G.total++,G[ie(s)]++,C.set(r,G)}return[...C.values()].sort((s,r)=>s.sort.localeCompare(r.sort))},mt=u=>u.sentiment!=null&&u.sentiment>=.1?"a":u.sentiment!=null&&u.sentiment<=-.1?"c":"b",lt=u=>u.first?u.waitMin!=null&&u.waitMin>zt?"c":"a":"b",Q=ee==="emails"&&!re,Ge=ke&&ke.view===Z?ke.r:null,le=Q?Ge?.available?Pe(Ge.rows,u=>u.sentAt,lt):[]:Pe(Ve,u=>u.occurred_at,mt),ne=Q?[["On time",nn],["Follow-up",sn],["Slow","var(--color-amber-dot)"]]:[["Positive",nn],["Neutral",sn],["Negative",$n]],et=Math.max(1,...le.map(u=>u.total)),He=140,Be=O?Math.max(1,Math.ceil(le.length/7)):1,tt=!(O&&le.length>12),ge=u=>Q?`${u.label}: ${u.total} ${u.total===1?"reply":"replies"} · ${u.a} first on time · ${u.b} follow-up · ${u.c} slow`:`${u.label}: ${u.total} ${u.total===1?"call":"calls"} · ${u.a} positive · ${u.b} neutral · ${u.c} negative · ${Bt(u.a,u.total)}% positive`;Ve.filter(u=>u.sentiment!=null&&u.sentiment>=.3).sort((u,x)=>(x.sentiment??0)-(u.sentiment??0)).slice(0,6);const[bt,$]=Ci(e,Math.max(0,n)),M=Ri(p),E=Fe[0]??null,fe=ds(p?.frequency),be=(u,x,ie)=>t.jsxs("button",{className:`tr-tabbtn${f===u?" on":""}`,onClick:()=>j(u),children:[t.jsx("i",{className:`ph-duotone ${x}`}),ie]}),at=nr(e.name,re||!1),rt=at?.summary?Qn(at.summary).improvements[0]??null:null,Ze=gn(e.score),kt=Ze===ae?{fg:"var(--color-accent-500)",bg:"rgba(98,197,238,.12)"}:Ze===je?{fg:$n,bg:ts}:{fg:"#7f93a3",bg:"var(--color-control-bg)"},ut=e.scoreKnown&&e.scoreReady,$e=`Last 30 days, ${e.scoreCalls.toLocaleString("en-US")} calls${e.scoreEmails?` and ${e.scoreEmails.toLocaleString("en-US")} ${e.scoreEmails===1?"email":"emails"}`:""}. Emails are not graded yet, so the score is the call score.`,Ie=re?"the desk":he,se=e.emails,Et=Ge?.available?Ge.rows.filter(u=>u.first&&u.waitMin!=null&&u.waitMin>zt).length:null,St=Se?t.jsxs("div",{style:{marginTop:16,fontSize:13,display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx("span",{style:{color:je},children:Se}),t.jsxs("button",{className:"ghostbtn",onClick:()=>qe(u=>u+1),style:{padding:"6px 12px",fontSize:12.5},children:[t.jsx("i",{className:"ph-duotone ph-arrows-clockwise"}),"Try again"]})]}):t.jsxs("div",{style:{marginTop:16,fontSize:13,color:y(52),display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xe,{}),"Loading ",he,"'s repliesâ¦"]}),$t=(u,x,ie,C,s,r,k,G)=>{const xe=ee===u;return t.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":xe,className:`sc-chan${xe?" on":""}`,onClick:()=>F(u),onKeyDown:pe=>{(pe.key==="Enter"||pe.key===" ")&&(pe.preventDefault(),F(u))},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,flexWrap:"wrap"},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:8,fontSize:13.5,fontWeight:600},children:[t.jsx("span",{className:"sc-ic",style:{background:xe?Oe:"var(--color-control-bg)",color:xe?At:"var(--color-control-text)"},children:t.jsx("i",{className:`ph-duotone ${ie}`})}),x]}),t.jsxs("button",{type:"button",className:"sc-link",onClick:pe=>{pe.stopPropagation(),j(s)},children:[C,t.jsx("i",{className:"ph-duotone ph-arrow-right",style:{fontSize:13}})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"flex-end",justifyContent:"space-between",gap:12,marginTop:12,flexWrap:"wrap"},children:[t.jsxs("div",{style:{minWidth:0},children:[r,t.jsx("div",{style:{fontSize:12,color:y(55),marginTop:5},children:k})]}),t.jsx("div",{style:{fontSize:12.5,color:y(55),textAlign:"right"},children:G})]})]},u)};return t.jsxs("div",{className:"sc-body",children:[t.jsxs("button",{className:"sc-back",onClick:g,style:{marginTop:18},children:[t.jsx("i",{className:"ph-duotone ph-arrow-left"}),"All agents"]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,marginTop:12,flexWrap:"wrap"},children:[t.jsx("span",{className:"sc-av",style:{width:56,height:56,fontSize:19,background:bt,color:$},children:on(e.name)}),t.jsxs("div",{style:{flex:O?"1 1 180px":1,minWidth:0},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:t.jsx("h2",{className:"serif",style:{fontSize:26,fontWeight:600,margin:0,letterSpacing:"-.01em"},children:e.name})}),t.jsxs("div",{style:{fontSize:13,color:y(55),marginTop:3},children:[_?.title||e.role,_?.group?` · ${_.group.isTeam?Ni(_.group.name):_.group.name}`:"",_?.group?.manager?` · manager ${_.group.manager}`:""," · report card · ",we(o),M.email&&t.jsxs(t.Fragment,{children:[" · ",t.jsx("a",{href:`mailto:${M.email}`,style:{color:ae},children:M.email}),Ce(e)?" (desk manager)":""]})]})]}),t.jsxs("div",{className:"sc-ring",style:O?{flex:"1 1 100%"}:void 0,children:[ut?t.jsx("div",{className:"sc-ring-c",role:"img","aria-label":`Overall score ${e.score}`,title:$e,style:{color:kt.fg,background:kt.bg},children:t.jsx("span",{className:"sc-ring-n",children:e.score})}):t.jsx("div",{className:"sc-ring-c",title:e.scoreKnown?rs(e.scoreCalls,e.scoreEmails):ms,style:{color:Ae,borderStyle:"dashed",borderWidth:2,padding:8,flexDirection:"column",fontSize:11.5,fontWeight:500,lineHeight:1.3},children:e.scoreKnown?t.jsxs(t.Fragment,{children:[t.jsx("span",{children:Kn(e.scoreCalls+e.scoreEmails)[0]}),t.jsx("span",{style:{fontWeight:400},children:Kn(e.scoreCalls+e.scoreEmails)[1]})]}):"Score not available"}),t.jsxs("div",{style:{textAlign:"center",lineHeight:1.4},children:[t.jsx("div",{className:"seclbl",style:{fontSize:11},children:"Overall score"}),t.jsx("div",{style:{fontSize:12,color:y(50),marginTop:2},children:Ce(e)?"Whole desk · last 30 days":i!=null?`Last 30 days · team ${i}`:"Last 30 days"}),In(e)&&t.jsx("div",{style:{marginTop:5},children:t.jsx(Wn,{a:e})})]})]})]}),t.jsx("div",{className:"sc-rail","data-more":D.more||void 0,style:{marginTop:20},children:t.jsxs("div",{ref:D.ref,className:"sc-tabs",children:[be("overview","ph-chart-bar","Overview"),be("feedback","ph-chats-circle","Feedback"),be("emails","ph-paper-plane-tilt","Summaries"),be("calls","ph-waveform",t.jsxs(t.Fragment,{children:["Calls · ",e.total]})),!re&&be("replies","ph-envelope-open",e.emails?t.jsxs(t.Fragment,{children:["Emails · ",e.emails.replies]}):"Emails")]})}),ze&&me&&Me,ze&&Ye>ze.length&&t.jsxs("div",{style:{fontSize:11.5,color:y(45),marginTop:10}
281,children:["Showing the ",ze.length.toLocaleString("en-US")," most recent of ",Ye.toLocaleString("en-US")," calls in this period. The tiles cover all of them, and the score covers the last 30 days."]}),f==="overview"&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"sc-card",style:{marginTop:20,padding:"18px 22px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[t.jsx("span",{className:"seclbl",children:re?"Calls":"Calls and emails"}),t.jsxs("span",{style:{fontSize:12.5,color:y(55)},children:["Scores cover the last 30 days.",re?"":` Pick one to see ${we(o)} below.`]})]}),t.jsxs("div",{className:"sc-chans",style:{"--chan-n":re?1:2},children:[$t("calls","Calls","ph-phone",`All ${e.total} calls`,"calls",t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsx(ns,{a:e,fontSize:34}),t.jsx(Wn,{a:e})]}),e.wellPct!=null?`${e.wellPct}% handled well · ${e.couldBetter} could do better`:`${e.posPct}% positive · ${e.misses} ${e.misses===1?"miss":"misses"} by ${Ie}`,`${e.total} ${e.total===1?"call":"calls"} · ${we(o)}`),!re&&$t("emails","Emails","ph-envelope-simple",se?`All ${se.replies} emails`:"All emails","replies",t.jsx("span",{title:"Email grading has not shipped yet. Replies count toward the sample a score needs.",style:{fontSize:15,fontWeight:600,color:Ae,lineHeight:"34px"},children:"Not graded yet"}),se?se.avgWaitMin!=null?`${jt(se.avgWaitMin)} average first reply`:"no first replies in the period":"not available just now",se?`${se.replies} ${se.replies===1?"email":"emails"} · ${we(o)}`:"")]})]}),Q?se?t.jsxs("div",{className:"sc-kpis",style:{marginTop:16,"--kpi-n":5},children:[t.jsx(We,{label:"Replies",value:se.replies,sub:we(o),icon:"ph-envelope-open",iconBg:"var(--color-control-bg)",iconFg:"var(--color-control-text)"}),t.jsx(We,{label:"First replies",value:se.firstReplies,sub:"answered a new customer email",icon:"ph-check-circle",iconBg:Oe,iconFg:ae,color:ae}),t.jsx(We,{label:"First reply",value:se.avgWaitMin!=null?jt(se.avgWaitMin):"None",sub:"from arrival or their shift start, whichever is later",icon:"ph-timer",iconBg:"var(--color-control-bg)",iconFg:"var(--color-control-text)",color:se.avgWaitMin!=null&&se.avgWaitMin>zt?Ne:void 0}),t.jsx(We,{label:"Slow replies",value:Et??(Se?"None":t.jsx(Xe,{size:18})),sub:Ge?.capped?"first replies past 2 hours, in the 500 most recent":"first replies past 2 hours",icon:"ph-hourglass",iconBg:pn,iconFg:Ne,color:Et?Ne:void 0}),t.jsx(We,{label:"Picked up",value:se.covered,sub:"from an earlier shift, never late",icon:"ph-users-three",iconBg:Oe,iconFg:ae})]}):t.jsx("div",{style:{marginTop:16,fontSize:13,color:y(52)},children:"The replies could not be read just now. Refresh to try again."}):t.jsxs("div",{className:"sc-kpis",style:{marginTop:16,"--kpi-n":5},children:[e.wellPct!=null?t.jsx(We,{label:"Handled well",value:`${e.wellPct}%`,sub:`${e.well} of ${e.graded} graded ${e.graded===1?"call":"calls"}`,icon:"ph-thumbs-up",iconBg:Oe,iconFg:ae,color:ae}):t.jsx(We,{label:"Positive",value:`${e.posPct}%`,sub:`${e.pos} ${e.pos===1?"call":"calls"}`,icon:"ph-thumbs-up",iconBg:Oe,iconFg:ae,color:ae}),t.jsx(We,{label:"Negative",value:`${e.negPct}%`,sub:"caller mood, never lowers the score",icon:"ph-thumbs-down",iconBg:ts,iconFg:je,color:e.negPct>0?je:void 0}),t.jsx(We,{label:"Calls",value:e.total,sub:we(o),icon:"ph-phone-call",iconBg:"var(--color-control-bg)",iconFg:"var(--color-control-text)"}),t.jsx(We,{label:"Avg handle",value:Nn(e.avgDur),sub:"minutes per call",icon:"ph-timer",iconBg:"var(--color-control-bg)",iconFg:"var(--color-control-text)"}),t.jsx(We,{label:"Misses",value:e.misses,sub:"calls where our side slipped",icon:"ph-flag",iconBg:pn,iconFg:Ne,color:e.misses>0?Ne:void 0})]}),Q?t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:7,margin:"10px 4px 0",fontSize:12,color:y(55),lineHeight:1.5},children:[t.jsx("i",{className:"ph-duotone ph-users-three",style:{fontSize:14,marginTop:2,flex:"none"}}),t.jsxs("span",{children:["Shared inbox: the clock starts when an email arrives or when ",he,"'s shift starts, whichever is later. The shift start is ",he,"'s first call or reply of the day. Nothing to set up. Replies are not graded yet, so they do not move the score; they count toward the ",Hn," calls and emails a score needs."]})]}):t.jsxs("div",{style:{fontSize:12,color:y(50),marginTop:8}
281,children:[li," The tiles follow the period above. ",to(Ce(e)?null:he)]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:O?"1fr":"minmax(0,1fr) 360px",gap:16,marginTop:16,alignItems:"start"},children:[t.jsxs("div",{className:"sc-card",style:{padding:"18px 22px 16px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[t.jsxs("div",{children:[t.jsxs("div",{className:"seclbl",children:[Q?"Emails":"Calls"," · ",we(o)]}),t.jsxs("div",{className:"serif",style:{fontSize:18,fontWeight:600,marginTop:3},children:[Q?"Emails":"Calls"," by ",De]})]}),t.jsx("div",{style:{display:"flex",gap:12,fontSize:11.5,color:y(55),whiteSpace:"nowrap",paddingTop:4,flexWrap:"wrap"},children:ne.map(([u,x])=>t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5},children:[t.jsx("span",{style:{width:8,height:8,borderRadius:2,background:x}}),u]},u))})]}),(Q?Ge===null:ze===null)?Q?St:Qe:Q&&!Ge?.available?t.jsx("div",{style:{fontSize:12.5,color:y(48),marginTop:12},children:"The replies could not be read just now. Refresh to try again."}):le.length>=1?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"sc-bars",children:le.map((u,x)=>{const ie=Math.max(4,Math.round(u.total/et*He));return t.jsxs("div",{className:"sc-bar",title:ge(u),onClick:O?()=>P(w===x?null:x):void 0,style:O?{cursor:"pointer",borderRadius:6,background:w===x?Oe:void 0}:void 0,children:[tt&&t.jsx("span",{style:{fontSize:11.5,fontWeight:600,color:y(60),fontVariantNumeric:"tabular-nums"},children:u.total}),t.jsxs("div",{className:"sc-bar-stack",style:{height:ie},children:[t.jsx("span",{style:{flex:u.a,background:ne[0][1]}}),t.jsx("span",{style:{flex:u.b,background:ne[1][1]}}),t.jsx("span",{style:{flex:u.c,background:ne[2][1]}})]})]},u.sort)})}),t.jsx("div",{style:{display:"flex",gap:O?4:12,padding:"8px 6px 0"},children:le.map((u,x)=>t.jsx("div",{style:{flex:1,minWidth:0,textAlign:"center",fontSize:O?10:11.5,color:y(50),overflow:O?"visible":"hidden",whiteSpace:"nowrap"},children:x%Be===0?u.label:""},u.sort))}),O&&w!=null&&le[w]&&t.jsx("div",{style:{fontSize:12.5,color:y(55),marginTop:8,lineHeight:1.5},children:ge(le[w])})]}):t.jsx("div",{style:{fontSize:12.5,color:y(48),marginTop:12},children:Q?`No replies signed by ${he} in ${we(o)}.`:"Not enough data in this range to chart a trend yet. Widen the range."}),(()=>{const u=le.reduce((ie,C)=>ie+C.total,0),x=Q?{a:Bt(le.reduce((ie,C)=>ie+C.a,0),u),b:Bt(le.reduce((ie,C)=>ie+C.b,0),u),c:Bt(le.reduce((ie,C)=>ie+C.c,0),u)}:{a:e.posPct,b:e.neuPct,c:e.negPct};return Q&&u===0||!Q&&e.total===0?null:t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"sc-sbar",style:{height:9,marginTop:18},children:[t.jsx("span",{style:{width:`${x.a}%`,background:ne[0][1]}}),t.jsx("span",{style:{width:`${x.b}%`,background:ne[1][1]}}),t.jsx("span",{style:{width:`${x.c}%`,background:ne[2][1]}})]}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8,marginTop:8,fontSize:12,color:y(60),fontVariantNumeric:"tabular-nums",flexWrap:"wrap"},children:[t.jsxs("span",{children:[t.jsxs("b",{style:{color:ae},children:[x.a,"%"]})," ",Q?"first on time":"positive"]}),t.jsxs("span",{children:[t.jsxs("b",{children:[x.b,"%"]})," ",Q?"follow-up":"neutral"]}),t.jsxs("span",{children:[t.jsxs("b",{style:{color:Q?Ne:je},children:[x.c,"%"]})," ",Q?"slow":"negative"]})]})]})})()]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[t.jsxs("div",{className:"sc-card",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[t.jsx("span",{className:"seclbl",children:"Feedback"}),t.jsx("button",{className:"sc-link",onClick:()=>j("feedback"),children:"See all"})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",marginTop:6},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 0"},children:[t.jsx("span",{className:"sc-ic",style:{background:"var(--color-control-bg)",color:"var(--color-control-text)"},children:t.jsx("i",{className:"ph-duotone ph-phone",style:{fontSize:14}})}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:13.5,fontWeight:600},children:"Calls"}),t.jsxs("div",{style:{display:"flex",gap:10,fontSize:12,marginTop:1,flexWrap:"wrap"},children:[t.jsxs("span",{style:{color:ae},children:[e.wins," doing well"]}),t.jsxs("span",{style:{color:e.misses>0?Ne:y(45)},children:[e.misses," to work on"]})]})]})]}),!re&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 0",borderTop:"1px solid var(--color-hairline-soft)"},children:[t.jsx("span",{className:"sc-ic",style:{background:"var(--color-control-bg)",color:"var(--color-control-text)"},children:t.jsx("i",{className:"ph-duotone ph-envelope-simple",style:{fontSize:14}})}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:13.5,fontWeight:600},children:"Emails"}),t.jsx("div",{style:{fontSize:12,marginTop:1,color:y(45)},children:"No email feedback yet. Replies are not graded yet."})]})]})]}),rt&&t.jsxs("div",{style:{borderTop:"1px solid var(--color-hairline-soft)",paddingTop:10,marginTop:2},children:[t.jsxs("div",{style:{fontSize:11,letterSpacing:".08em",textTransform:"uppercase",color:Ne,fontWeight:600},children:["Next to work on · from ",he,"'s summary"]}),t.jsx("div",{style:{fontSize:13,fontWeight:600,marginTop:4},children:rt.title}),t.jsx("div",{style:{fontSize:12.5,color:y(62),lineHeight:1.5,marginTop:2},children:rt.detail})]})]}),t.jsxs("div",{className:"sc-card",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[t.jsx("span",{className:"seclbl",children:"Weekly summary"}),E&&(()=>{const u=as(E.status);return t.jsxs("span",{className:"sc-chip",style:{background:u.bg,color:u.fg},children:[t.jsx("i",{className:`ph-duotone ${u.icon}`}),u.label]})})()]}),E?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{fontSize:13.5,fontWeight:600,marginTop:10},children:[ss(E,U,fe),t.jsxs("span",{style:{fontWeight:400,color:y(50)},children:[" · ",Wi[xn(E,fe).key]]})]}),t.jsx("div",{style:{fontSize:12.5,color:y(58),marginTop:3,lineHeight:1.5},children:E.status==="draft"?`Built from ${st[xn(E,fe).key].builtFrom}. Review it, then send.`:`${ls(E).good} · ${ls(E).focus} · ${E.status==="acknowledged"?`read ${E.acknowledgedAt?Ke(E.acknowledgedAt,U):""}`.trim():"awaiting acknowledgement"}`})]}):t.jsxs("div",{style:{fontSize:12.5,color:y(58),marginTop:10,lineHeight:1.5},children:["No summary drafted yet. TeleServ drafts one ",st[fe.key].every," from ",he,"'s calls."]}),t.jsxs("button",{className:"sc-link",onClick:()=>j("emails"),style:{marginTop:10},children:["All summaries",t.jsx("i",{className:"ph-duotone ph-arrow-right",style:{fontSize:13}})]})]})]})]})]}),f==="feedback"&&(yt?t.jsx(Pa,{ag:yt,period:o,range:{sinceIso:Re,toIso:X},tz:U,orgName:T,digests:Fe,emails:re?null:e.emails?.replies??null,summaryState:E?`${ss(E,U,fe)} · ${E.status==="draft"?"Draft, review it":as(E.status).label}`:"none yet",summaryHeadline:at?.summary?Qn(at.summary).headline:null,fullSummary:re?null:t.jsx(or,{ag:yt,eyebrow:_e.title(he)}),onSummaries:()=>j("emails")}):Qe),f==="emails"&&t.jsx(dr,{ag:e,digests:Fe,digestsReady:ye,reloadDigests:ot,pref:p,prefsLoaded:v,onPref:N,schedule:W,orgName:T,search:a}),f==="replies"&&!re&&(()=>{const u=ke&&ke.view===Z?ke.r:null;return u?u.available?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginTop:20,flexWrap:"wrap"},children:[t.jsx("div",{className:"segtrack",role:"radiogroup","aria-label":"Show",children:Qa.map(x=>t.jsx("button",{role:"radio","aria-checked":q===x.v,className:`tr-seg${q===x.v?" on":""}`,onClick:()=>Te(x.v),children:x.label},x.v))}),t.jsxs("span",{style:{fontSize:12.5,color:y(55)},children:["Replies sent by ",he," · ",we(o),u.avgWaitMin!=null&&t.jsxs(t.Fragment,{children:[" · average first reply ",t.jsx("b",{style:{color:u.avgWaitMin>zt?Ne:It},children:jt(u.avgWaitMin)})]})]}),t.jsxs(gt,{to:"/emails",className:"sc-link",children:["Open in Emails",t.jsx("i",{className:"ph-duotone ph-arrow-right",style:{fontSize:13}})]})]}),t.jsxs("div",{style:{fontSize:12,color:y(50),marginTop:6,lineHeight:1.5},children:["A reply counts as ",he,"'s when the signature names ",he," or the mailbox is ",he,"'s own. The clock starts when the email arrives, or at the start of ",he,"'s shift (the first call or reply that day) for an email left from before it. Replies are not graded yet, so they do not move the score; they count toward the ",Hn," calls and emails a score needs."]}),u.capped&&t.jsx("div",{style:{fontSize:11.5,color:y(45),marginTop:8},children:"Showing the 500 most recent replies."}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginTop:14},children:[u.rows.filter(x=>q==="all"||(q==="first"?x.first:q==="followup"?!x.first:x.first&&x.waitMin!=null&&x.waitMin>zt)).map(x=>{const ie=x.waitMin!=null&&x.waitMin>zt,C=t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{width:9,height:9,borderRadius:"50%",marginTop:7,flex:"none",background:x.first?ie?"var(--color-amber-dot)":nn:sn}}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,flexWrap:"wrap"},children:[t.jsx("span",{className:"serif",style:{fontSize:16,fontWeight:600,minWidth:0},children:x.subject?.trim()||"No subject"}),(x.customer||x.mailbox)&&t.jsx("span",{style:{fontSize:12,color:y(50)},children:[x.customer?`to ${x.customer}`:null,x.mailbox?`from ${x.mailbox}
281`:null].filter(Boolean).join(" · ")})]}),x.snippet&&t.jsx("div",{style:{fontSize:13,lineHeight:1.5,color:y(70),marginTop:5,maxWidth:"100ch"},children:x.snippet})]}),t.jsxs("div",{style:{textAlign:"right",flex:"none",maxWidth:O?130:260},children:[t.jsx("div",{style:{fontSize:12.5,color:y(50),whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:pt(x.sentAt,U)}),t.jsx("div",{style:{fontSize:12,fontWeight:600,color:x.first?ie?Ne:At:y(50),marginTop:2,whiteSpace:"nowrap"},children:x.first&&x.waitMin!=null?`First reply in ${jt(x.waitMin)}`:"Follow-up"}),x.covered&&x.arrivedAt&&x.shiftStart&&t.jsxs("div",{style:{fontSize:12,color:"#006786",marginTop:2,lineHeight:1.4},title:`The email arrived ${pt(x.arrivedAt,U)}, before ${he}'s shift started at ${pt(x.shiftStart,U)}. The clock starts at the shift start.`,children:["Picked up from an earlier shift · shift start ",new Date(x.shiftStart).toLocaleTimeString("en-US",{timeZone:U,hour:"numeric",minute:"2-digit"})]})]})]});return x.emailId?t.jsx(gt,{to:"/emails/$emailId",params:{emailId:x.emailId},search:{},className:"sc-crow",children:C},x.id):t.jsx("div",{className:"sc-crow",style:{cursor:"default"},children:C},x.id)}),u.rows.length===0&&t.jsxs("div",{style:{padding:30,textAlign:"center",color:y(50),fontSize:13},children:["No replies signed by ",he," in ",we(o),"."]}),u.rows.length>0&&q!=="all"&&!u.rows.some(x=>q==="first"?x.first:q==="followup"?!x.first:x.first&&x.waitMin!=null&&x.waitMin>zt)&&t.jsx("div",{style:{padding:30,textAlign:"center",color:y(50),fontSize:13},children:"No emails in this view."})]})]}):t.jsx("div",{style:{marginTop:20,fontSize:13,color:y(52)},children:"The replies could not be read just now. Refresh to try again."}):Se?t.jsxs("div",{style:{marginTop:20,fontSize:13,display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx("span",{style:{color:je},children:Se}),t.jsxs("button",{className:"ghostbtn",onClick:()=>qe(x=>x+1),style:{padding:"6px 12px",fontSize:12.5},children:[t.jsx("i",{className:"ph-duotone ph-arrows-clockwise"}),"Try again"]})]}):t.jsxs("div",{style:{marginTop:20,fontSize:13,color:y(52),display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xe,{}),"Loading ",he,"'s repliesâ¦"]})})(),f==="calls"&&(ze===null?Qe:(()=>{const u=[{v:"all",label:"All"},{v:"positive",label:"Positive"},{v:"negative",label:"Negative"},{v:"neutral",label:"Neutral"},{v:"flagged",label:"Flagged"}],x=[...Ve].filter(C=>ce==="flagged"?fn(C).length>0:ce==="positive"?C.sentiment!=null&&C.sentiment>=.1:ce==="negative"?C.sentiment!=null&&C.sentiment<=-.1:ce==="neutral"?!(C.sentiment!=null&&(C.sentiment>=.1||C.sentiment<=-.1)):!0).sort((C,s)=>+new Date(s.occurred_at)-+new Date(C.occurred_at)),ie=C=>{if(fn(C).length>0)return{label:"Flagged",bg:pn,fg:Ne,dot:"var(--color-amber-dot)"};const s=C.sentiment;return s!=null&&s<=-.1?{label:"Negative",bg:"var(--color-rose-fill)",fg:je,dot:$n}:s!=null&&s>=.1?{label:"Positive",bg:Oe,fg:At,dot:nn}:{label:"Neutral",bg:y(6),fg:y(52),dot:sn}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginTop:20,flexWrap:"wrap"},children:[t.jsx("div",{className:"segtrack",role:"radiogroup","aria-label":"Show",children:u.map(C=>t.jsx("button",{role:"radio","aria-checked":ce===C.v,className:`tr-seg${ce===C.v?" on":""}`,onClick:()=>K(C.v),children:C.label},C.v))}),t.jsxs(gt,{to:"/calls",className:"sc-link",children:["Open in Call Explorer",t.jsx("i",{className:"ph-duotone ph-arrow-right",style:{fontSize:13}})]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginTop:14},children:[x.map(C=>{const s=ie(C);return t.jsxs(gt,{to:"/calls",search:{period:"all",call:C.id},className:"sc-crow",children:[t.jsx("span",{style:{width:9,height:9,borderRadius:"50%",marginTop:7,flex:"none",background:s.dot}}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,flexWrap:"wrap"},children:[t.jsx("span",{className:"serif",style:{fontSize:16,fontWeight:600,minWidth:0},children:C.topic??"Call"}),t.jsx("span",{className:"sc-chip",style:{background:s.bg,color:s.fg,fontSize:11.5,padding:"2px 9px"},children:s.label}),t.jsx($o,{direction:C.direction}),O&&t.jsxs("span",{style:{fontSize:12,color:y(50),fontVariantNumeric:"tabular-nums",marginLeft:"auto"},children:[pt(C.occurred_at,U)," · ",Nn(C.duration_sec)]})]}),C.summary&&t.jsx("div",{style:{fontSize:13,lineHeight:1.5,color:y(70),marginTop:5,maxWidth:"100ch"},children:C.summary})]}),!O&&t.jsxs("span",{style:{fontSize:12.5,color:y(50),whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:[pt(C.occurred_at,U)," · ",Nn(C.duration_sec)]})]},C.id)}),x.length===0&&t.jsx("div",{style:{padding:30,textAlign:"center",color:y(50),fontSize:13},children:"No calls in this status."})]})]})})())]})}function tr(e,n,i=[]){const o=e.map(d=>({topic:d.topic,sentiment:d.sentiment,summary:d.summary,flags:un(fn(d),n,!1).map(c=>c.rule?.key??"flag"),occurred_at:d.occurred_at})),a=i.filter(d=>!e.some(c=>
281c.id===d.id)).map(d=>({topic:d.topic,sentiment:d.sentiment,summary:d.summary,flags:un(fn(d),n,!0).map(c=>c.rule?.key??"flag"),occurred_at:d.occurred_at})).filter(d=>d.flags.length>0);return Kl([...o,...a])}const wt=new Map;function nr(e,n){const{orgId:i}=Wt.useRouteContext().org,o=`${i}|${e}`,[a,d]=h.useState(()=>n?null:wt.get(o)??null);return h.useEffect(()=>{if(n){d(null);return}let c=!0;return d(wt.get(o)??null),Yn({data:{agentName:e}}).then(b=>{c&&(wt.set(o,b),d(b))}).catch(()=>{}),()=>{c=!1}},[o,e,n]),a}const tn=new Map,sr=8e3,ir=15;function or({ag:e,eyebrow:n,chips:i}){const o=Yt(),{timezone:a,orgId:d}=Wt.useRouteContext().org,c=`${d}|${e.name}`,b=hn(e.name),[f,j]=h.useState(()=>wt.get(c)??null),[g,p]=h.useState(()=>wt.has(c)?"idle":"checking"),[v,N]=h.useState(null),[W,T]=h.useState(()=>tn.has(c)),[_,O]=h.useState(!1),U=h.useRef(0),ce=h.useRef(c),K=h.useRef(!0);h.useEffect(()=>(K.current=!0,()=>{K.current=!1}),[]),h.useEffect(()=>{ce.current=c;const D=++U.current,Z=wt.get(c)??null;j(Z),N(null),O(!1);const te=tn.get(c);return T(!!te),te&&te.then(()=>{if(!K.current||ce.current!==c)return;T(!1);const Y=wt.get(c);Y&&j(Y)}),p(Z?"idle":"checking"),(async()=>{try{const Y=await Yn({data:{agentName:e.name}});if(D!==U.current)return;wt.set(c,Y),j(Y),p("idle")}catch(Y){if(D!==U.current)return;p("idle"),Z||N(Y instanceof Error?Y.message:"Couldn't open the summary.")}})(),()=>{U.current++}},[c]);const q=()=>{const D=c;if(tn.has(D))return;const Z=f?.summary?.generatedAt??null,te=f?.rehearsal??!1,Y=()=>K.current&&ce.current===D,H=me=>{wt.set(D,me),Y()&&j(me)};T(!0),N(null),O(!1);const V=(async()=>{try{const me=await xo({data:{agentName:e.name}});if(me.status==="written"&&me.summary){H({summary:me.summary,recentCalls:null,firstCallAt:null,rehearsal:te});return}for(let Ee=0;Ee<ir;Ee++){await new Promise(qe=>setTimeout(qe,sr));const Ue=await Yn({data:{agentName:e.name}}).catch(()=>null);if(Ue?.summary&&Ue.summary.generatedAt!==Z){H(Ue);return}}Y()&&O(!0)}catch(me){Y()&&N(me instanceof Error?me.message:"Couldn't refresh the summary.")}finally{tn.delete(D),Y()&&T(!1)}})();tn.set(D,V)},Te=t.jsxs("button",{className:"ghostbtn",onClick:q,disabled:W,"aria-busy":W,title:_e.refreshTitle(b),style:{padding:"5px 11px",fontSize:12.5,flex:"none"},children:[t.jsx("i",{className:"ph-duotone ph-arrows-clockwise",style:W?{animation:"sc-spin .8s linear infinite"}:void 0}),W?_e.refreshing:_e.refresh]}),ee=f?.summary?Qn(f.summary):null,F={fontSize:13.5,color:"#c6e6f2",marginTop:10,lineHeight:1.5},w={fontSize:11.5,fontWeight:600,textTransform:"uppercase",letterSpacing:".08em"},P=D=>D.map((Z,te)=>t.jsxs("div",{style:{marginTop:8},children:[t.jsx("div",{style:{fontSize:13.5,fontWeight:600,color:"#fff"},children:Z.title}),t.jsx("div",{style:{fontSize:12.5,color:"#c6e6f2",marginTop:2,lineHeight:1.5},children:Z.detail})]},te));return t.jsxs("div",{className:"sc-hero",style:{marginTop:20},children:[t.jsxs("div",{className:"sc-hero-k",children:[t.jsx("i",{className:"ph-duotone ph-sparkle",style:{fontSize:15}}),n]}),ee?t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"sc-hero-h",children:ee.headline}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:o?"1fr":"1fr 1fr",gap:o?12:24,marginTop:14},children:[t.jsxs("div",{children:[t.jsx("div",{style:{...w,color:"#a7f0c4"},children:_e.strengths}),P(ee.strengths)]}),t.jsxs("div",{children:[t.jsx("div",{style:{...w,color:"#ffd166"},children:_e.improvements}),ee.improvements.length?P(ee.improvements):t.jsx("div",{style:{fontSize:12.5,color:"#c6e6f2",marginTop:8,lineHeight:1.5},children:_e.noImprovements})]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:"8px 12px",marginTop:16},children:[i,t.jsxs("div",{style:{fontSize:11.5,color:"#a8dcef",minWidth:0,flex:"1 1 220px"},children:[_e.updated(Os(ee.generatedAt,a),ee.callCount),ee.checkedAt?` ${_e.checked(Os(ee.checkedAt,a))}`:""]}),Te]})]}):g==="checking"?t.jsx("div",{style:F,children:_e.opening}):f?.rehearsal?t.jsx("div",{style:F,children:_e.rehearsal}):f&&f.recentCalls===0?t.jsx("div",{style:F,children:_e.noCalls(b)}):f&&Bl(f.firstCallAt,Date.now())?t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",flexWrap:"wrap",gap:"8px 12px",marginTop:10},children:[t.jsx("div",{style:{...F,marginTop:0},children:_e.beingWritten(b)}),Te]}):f?t.jsx("div",{style:F,children:_e.firstComes(b)}):null,!ee&&i&&t.jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,marginTop:14},children:i}),_&&!v&&t.jsx("div",{style:{fontSize:12.5,color:"#c6e6f2",marginTop:8,lineHeight:1.5},children:_e.refreshSlow}),v&&t.jsx("div",{style:{fontSize:12.5,color:"#ffc0d0",marginTop:8,lineHeight:1.5},children:v})]})}const lr=["Sunday","Monday","Tuesday","Wednesday","Thursday","Frid
281ay","Saturday"],ni=e=>`${e%12||12} ${e<12?"AM":"PM"}`,kn=(e,n)=>e.toLocaleDateString("en-US",{timeZone:n,weekday:"short",month:"short",day:"numeric"});function ar(e,n,i){const o=new Date(Date.UTC(e,n-1,i)),a=o.getUTCDay()||7;o.setUTCDate(o.getUTCDate()+4-a);const d=new Date(Date.UTC(o.getUTCFullYear(),0,1));return Math.ceil(((o.getTime()-d.getTime())/864e5+1)/7)}function rr(e,n,i,o,a=new Date){if(e==="off")return null;const d=n%7,[c,b,f]=mn(a,o).split("-").map(Number),j=(p,v=b)=>new Date(Date.UTC(c,v-1,p)),g=p=>co(p.getUTCFullYear(),p.getUTCMonth()+1,p.getUTCDate(),i,0,o);if(e==="monthly"){for(let p=0;p<3;p++){const v=j(1,b+p);for(;v.getUTCDay()!==d;)v.setUTCDate(v.getUTCDate()+1);const N=g(v);if(N>a)return N}return null}for(let p=0;p<8;p++){const v=j(f+p);if(v.getUTCDay()===d&&!(g(v)<=a))return e==="biweekly"&&ar(v.getUTCFullYear(),v.getUTCMonth()+1,v.getUTCDate())%2===1&&v.setUTCDate(v.getUTCDate()+7),g(v)}return null}const cr=[{v:"weekly",label:"Every week"},{v:"biweekly",label:"Every two weeks"},{v:"monthly",label:"Every month"}];function dr({ag:e,digests:n,digestsReady:i,reloadDigests:o,pref:a,prefsLoaded:d,onPref:c,schedule:b,orgName:f,search:j}){const g=Yt(),p=Wt.useRouteContext().org.timezone,v=hn(e.name),N=Ri(a),W=Ce(e),T=a?.frequency??"weekly",_=ds(T),[O,U]=h.useState(!1),[ce,K]=h.useState(null),q=h.useRef(null),Te=async $=>{if(!a||O||$===T)return;U(!0),K(null);const M=T;c(e.name,$);try{await Jl({data:{agentId:a.agentId,frequency:$}}),q.current&&clearTimeout(q.current),q.current=$==="off"?null:setTimeout(()=>{q.current=null,mt.current(!1,!1)},1500)}catch(E){c(e.name,M),K(E instanceof Error?E.message:"Couldn't save the frequency.")}finally{U(!1)}},ee=lr[b.dayOfWeek%7],F=rr(T,b.dayOfWeek,b.hour,p),w=N.email?`to ${N.email}`:`to nobody yet (add ${W?"a manager email for this desk":`${v}'s email`} in Account management)`,P=d?a?T==="off"?"Paused. Nothing goes out unless you send it yourself.":`${T==="weekly"?`${ee}s`:T==="biweekly"?`Every other ${ee}`:`First ${ee} of the month`} at ${ni(b.hour)} ${oi(p)} ${w}.${F?` Next: ${kn(F,p)}.`:""}`:`Not available yet: ${e.name} has no roster entry in Account management, so there is nowhere to save a cadence.`:"Loadingâ¦",D=new Date,Z=j.period==="custom"&&j.from?j.from.slice(0,10):mn(new Date(D.getTime()-30*864e5),p),te=j.period==="custom"&&j.to?j.to.slice(0,10):mn(D,p),[Y,H]=h.useState(Z),[V,me]=h.useState(te),[Ee,Ue]=h.useState(!1),[qe,Re]=h.useState(null),[X,re]=h.useState(null),[ke,it]=h.useState(null),Se=h.useRef(0);h.useEffect(()=>{re(null),it(null),Re(null)},[e.name]);const ue=($,M)=>`${Ke(`${$}T00:00:00`)} to ${Ke(`${M}T00:00:00`)}`,ht=($,M)=>({from:Ke(`${$}T00:00:00`),to:Ke(`${M}T00:00:00`)}),ze=async $=>{if(!Y||!V||Ee)return;if(V<Y){Re("The end date is before the start date.");return}const M=++Se.current;Ue(!0),Re(null),it(null);try{const E=ro("custom",Y,V,p),{calls:fe}=await Ti(E,e.name,()=>{});if(fe.length===0){M===Se.current&&(re(null),Re(`No calls for ${v} between ${ue(Y,V)}.`));return}const be=await ii({data:{agentName:e.name,sinceIso:E.sinceIso,toIso:E.toIso}}).then($e=>$e.calls).catch(()=>[]),at=await go({data:{agentName:e.name,role:e.role,period:"custom",force:$,calls:tr(fe,e.name,be)}});if(M!==Se.current)return;const rt=fe.filter($e=>$e.sentiment!=null&&$e.sentiment>=.3).sort(($e,Ie)=>(Ie.sentiment??0)-($e.sentiment??0)).slice(0,6),Ze=bs(W,Un)?fe.flatMap($e=>$e.followups.filter(Ie=>Ie.kind==="train_employee"&&qn(Ie.owner,e.name,$e.handledBy,!1)).flatMap(Ie=>{const se=ai(Ie.whatDid);return se.wentWell&&!se.whatDid?[]:[{subject:Ie.subject||"Coaching note",did:se.wentWell?se.whatDid:Ie.whatDid,instead:Ie.shouldHave}]})):[],kt=fe.filter($e=>un(fn($e),e.name,!1).length>0).length,ut=Ze.length?Ze:Array.from({length:kt},()=>({subject:"Flagged call",did:null,instead:null}));re({label:ue(Y,V),...ht(Y,V),count:fe.length,wins:rt,coach:ut,text:at.headline})}catch(E){M===Se.current&&Re(E instanceof Error?E.message:"Couldn't draft the summary.")}finally{M===Se.current&&Ue(!1)}},Ye=X?No(X.from,X.to):null,yt=W?N.name?hn(N.name):null:v,Ve=Ye?To(yt,W?e.name:null,Ye):"",he=(()=>
281{if(!X||!Ye)return"";const $=f?`The ${f} team, via TeleServ`:"Via TeleServ",M=[Ve,"",X.text.trim()];if(X.wins.length){M.push("","Calls worth celebrating:");for(const be of X.wins.slice(0,3))M.push(`- ${be.topic??"Positive call"}${be.summary?`: ${be.summary}`:""}`)}const E=X.coach.find(be=>be.did||be.instead);E&&(M.push("","One thing for next time:",E.subject),E.did&&M.push(`What happened: ${E.did}`),E.instead&&M.push(`Better: ${E.instead}`)),M.push("",$);const fe=zo[W?"desk":"agent"](f||null,X.from,X.to,Ye);return`mailto:${N.email?encodeURIComponent(N.email).replace(/%40/g,"@"):""}?subject=${encodeURIComponent(fe)}&body=${encodeURIComponent(M.join(` 282`).slice(0,1800))}`})(),[Fe,Le]=h.useState(null),[ye,Je]=h.useState(null),[ot,Me]=h.useState(null),[Qe,De]=h.useState(null);h.useEffect(()=>{Le(null),De(null)},[e.name]);const de=Fe?n.find($=>$.id===Fe)??null:null,Pe=async($,M=!0)=>{if(!(!a||ye)){Je($?"rebuild":"preview"),Me(null),De(null);try{const E=await Ei(a.agentId,$);if(E.kind==="pending"){De("Still building. Try again in a minute.");return}if(await o(),!E.digestId&&E.dueReason==="no calls this week"){et(!0);return}if(!E.digestId){De(E.dueReason?`Nothing to show: ${os(E.dueReason,_)}.`:"Nothing was built.");return}et(!1),M&&Le(E.digestId),De([E.builtAt?`Built ${pt(E.builtAt,p)}`:null,E.reused?"reused from an earlier build":null,E.due?null:`${E.dueReason?os(E.dueReason,_):"not due"}, so the automatic send will skip it`].filter(Boolean).join(" · ")||null)}catch(E){Me(E instanceof Error?E.message:"Couldn't build the digest.")}finally{Je(null)}}},mt=h.useRef(Pe);mt.current=Pe,h.useEffect(()=>()=>{q.current&&(clearTimeout(q.current),q.current=null)},[e.name]);const lt=async $=>{if(await zn({title:`Send ${st[xn($,_).key].digest} to "${$.recipientName||$.recipientEmail||"the recipient"}"?`,body:`The email goes out to ${$.recipientEmail||"the recipient"} from your Outlook right away and cannot be recalled once it is sent.`,confirmLabel:"Send digest"})){Je("send"),Me(null);try{await Bn({data:{id:$.id}}),await o()}catch(M){Me(M instanceof Error?M.message:"Couldn't send it from your mailbox.")}finally{Je(null)}}},Q=n[0]?.status==="draft"?n[0]:null,Ge=$=>$.facts?.v===3&&!!$.facts.summary,le=Ga[_.key],[ne,et]=h.useState(!1);h.useEffect(()=>{et(!1)},[e.name]);const He=()=>{const $=document.getElementById("sc-custom-summary");$?.scrollIntoView({behavior:"smooth",block:"start"}),$?.querySelector('input[type="date"]')?.focus({preventScroll:!0})},Be=$=>t.jsxs(t.Fragment,{children:[t.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:8,fontSize:13,fontWeight:600,cursor:a?"pointer":"default"},children:[t.jsx(cs,{checked:T!=="off",disabled:!a||O,label:"Send automatically",onChange:M=>{Te(M?"weekly":"off")}}),"Send automatically"]}),t.jsx("div",{className:"sc-dkseg sc-freq",role:"radiogroup","aria-label":"Frequency",style:{opacity:T==="off"?.45:1},children:cr.map(M=>t.jsx("button",{role:"radio","aria-checked":T===M.v,className:T===M.v?"on":"",disabled:!a||O||T==="off",onClick:()=>{Te(M.v)},children:M.label},M.v))}),t.jsx("span",{style:{fontSize:12.5,color:$?"#a8dcef":y(55),lineHeight:1.5,flex:"1 1 260px",minWidth:0},children:P}),!b.enabled&&T!=="off"&&t.jsxs("span",{className:"sc-coff",style:{fontSize:12.5,color:$?"#ffe3a3":Ne,lineHeight:1.5},children:["Automatic sends are off for the whole company. ",t.jsx("button",{type:"button",className:"sc-link",onClick:()=>window.dispatchEvent(new Event(is)),style:{fontSize:12.5,color:"inherit",textDecoration:"underline"},children:"Turn them on"})]}),ce&&t.jsx("span",{style:{fontSize:12,color:$?"#ffc0d0":je},children:ce})]}),tt=$=>{if($.status==="draft"&&!$.sentAt&&!Ge($)&&a&&N.email){Pe(!0);return}Le($.id)},ge=!N.email,bt=T==="off"?"paused":T==="weekly"?`every ${ee}`:T==="biweekly"?`every other ${ee}`:`the first ${ee} of the month`;return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:26,marginTop:20,minWidth:0},children:[ot&&t.jsx("div",{style:{fontSize:12.5,color:je},children:ot}),de&&de.status==="draft"&&!de.sentAt&&Ge(de)&&de.facts?.summary?t.jsx(ra,{id:de.id,summary:de.facts.summary,edits:de.edits,first:W?e.name:v,from:`TeleServ for ${f||"your company"}`,to:`To ${de.recipientEmail??"no email on file"} · ${T!=="off"&&b.enabled&&F?`${kn(F,p)}, ${ni(b.hour)}`:"Draft"}`,canSend:!!de.recipientEmail,sendHint:de.recipientEmail?T!=="off"&&b.enabled&&F?`If you don't send it now, it goes out on its own ${kn(F,p)} as you leave it.`:null:W?"Add a manager email for this desk in Account management to send.":`Add ${v}'s email in Account management to send.`,busy:ye,onSend:()=>lt(de),onRebuild:a?()=>{Pe(!0)}:void 0,onBack:()=>{Le(null),De(null),o()},fmtSaved:$=>pt($,p),schedule:Be(!1)},`${de.id}:${de.facts.builtAt}`):de?t.jsx(pr,{digest:de,cadence:_,busy:ye,orgName:f,note:Qe,onSend:()=>lt(de),onRebuild:a?()=>{Pe(!0)}:void 0,onBack:()=>{Le(null),De(null),o()}}):t.jsxs(t.Fragment,{children:[ge?t.jsxs("div",{className:"sc-card sc-noemail",style:{padding:"20px 22px",display:"flex",alignItems:"center",gap:14,flexWrap:"wrap"},children:[t.jsx("span",{className:"sc-htile",style:{background:"var(--color-accent-100)",color:ae,flex:"none"},children:t.jsx("i",{className:"ph-duotone ph-envelope-simple"})}),t.jsxs("div",{style:{flex:"1 1 260px",minWidth:0},children:[t.jsx("div",{className:"serif",style:{fontSize:18,fontWeight:600,lineHeight:1.25},children:"Add an email to start these summaries"}),t.jsx("div",{style:{fontSize:13,color:y(60),marginTop:4,lineHeight:1.5},children:W?`They go to the desk manager. Add a manager email for ${e.name} and the summaries start.`:`They go to ${v}. Add ${v}'s email and the summaries start.`})]}),t.jsxs(gt,{to:"/settings/team",search:{tab:"team"},hash:a?`line-${a.agentId}`:void 0,className:"primary",style:{padding:"9px 16px",textDecoration:"none",whiteSpace:"nowrap"},children:[t.jsx("i",{className:"ph-duotone ph-arrow-right"}),"Add an email in Account management"]})]}):t.jsx(t.Fragment,{children:t.jsxs("div",{className:"sc-hero",style:{padding:"22px 26p
282x"},children:[t.jsxs("div",{className:"sc-hero-k",children:[t.jsx("i",{className:"ph-duotone ph-paper-plane-tilt",style:{fontSize:15}}),"Up next"]}),t.jsx("div",{className:"serif",style:{fontSize:26,fontWeight:600,lineHeight:1.2,marginTop:8},children:T==="off"?"Paused":F?`Next summary ${kn(F,p)}`:`Next summary ${st[_.key].span}`}),t.jsxs("div",{className:"sc-hero-s",style:{fontSize:14,marginTop:4},children:["Goes to ",N.email??(W?"the desk manager (no email set)":"no email on file")," · ",bt]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap",marginTop:16},children:[Q&&t.jsxs("button",{className:"sc-hbtn",onClick:()=>tt(Q),disabled:ye!==null,children:[t.jsx("i",{className:"ph-duotone ph-pencil-simple",style:{fontSize:15}}),"Review and edit"]}),t.jsxs("button",{className:Q?"ghostbtn":"sc-hbtn",onClick:()=>{Pe(!1)},disabled:!a||ye!==null,title:a?`Create the summary for ${st[_.key].span} from the last ${ei[_.key]} days of calls and open it to edit, without sending it`:`${e.name} has no roster entry, so there is nothing to create it for`,style:Q?{padding:"8px 12px"}:void 0,children:[ye==="preview"?t.jsx(Xe,{size:14}):t.jsx("i",{className:"ph-duotone ph-sparkle",style:{fontSize:15}}),ye==="preview"?"Creating itâ¦":le]})]}),ne&&t.jsxs("div",{className:"sc-empty-period",style:{marginTop:12,background:"rgba(255,255,255,.1)",borderRadius:12,padding:"11px 14px",fontSize:13.5,lineHeight:1.5,display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsxs("span",{style:{flex:"1 1 260px"},children:["No calls or replies ",st[_.key].span,", so there is nothing to summarize yet. Pick a longer period."]}),t.jsxs("button",{type:"button",className:"fb-hlink",onClick:He,children:[t.jsx("i",{className:"ph-duotone ph-calendar-blank",style:{fontSize:14}}),"Custom summary"]})]}),Qe&&t.jsx("div",{className:"sc-hero-s",style:{fontSize:12.5,marginTop:10},children:Qe}),t.jsx("div",{className:"sc-hero-foot",children:Be(!0)})]})}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[t.jsxs("div",{className:"sc-h3row",children:[t.jsx("span",{className:"sc-htile",style:{background:"var(--color-control-bg)",color:"var(--color-control-text)"},children:t.jsx("i",{className:"ph-duotone ph-clock-counter-clockwise"})}),t.jsx("h3",{className:"sc-h3",children:"History"}),t.jsx("span",{style:{marginLeft:"auto",fontSize:12.5,color:y(55)},children:"Every summary is kept, sent or not"})]}),t.jsx("div",{className:"sc-tbl",children:!i&&n.length===0?t.jsxs("div",{style:{padding:"22px 18px",fontSize:12.5,color:y(52),display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xe,{}),"Loading ",v,"'s digestsâ¦"]}):n.length===0?t.jsxs("div",{style:{padding:"22px 18px",fontSize:12.5,color:y(48),lineHeight:1.5},children:["No summary created for ",W?e.name:v," yet. ",le," creates one from the last ",ei[_.key]," days of calls and opens it to edit, without sending it."]}):n.map($=>{const M=as($.status),E=Vt($),fe=ls($),be=$.status==="acknowledged"?`Sent ${$.sentAt?Ke($.sentAt,p):""}${$.acknowledgedAt?` · read ${Ke($.acknowledgedAt,p)}`:""}`.replace(/\s+·/," ·").trim():$.status==="sent"?`Sent ${$.sentAt?Ke($.sentAt,p):""}`.trim():E?.builtAt?`Built ${pt(E.builtAt,p)}`:"Not sent yet";return t.jsxs("button",{className:"sc-erow",onClick:()=>tt($),style:g?{flexWrap:"wrap",gap:10}:void 0,children:[t.jsx("span",{style:{width:34,height:34,borderRadius:10,background:M.bg,color:M.fg,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"none"},children:t.jsx("i",{className:"ph-duotone ph-envelope-simple",style:{fontSize:16}})}),t.jsxs("div",{style:{flex:g?"1 1 170px":1,minWidth:0},children:[t.jsxs("div",{style:{fontSize:14,fontWeight:600},children:[ss($,p,_),t.jsxs("span",{style:{fontWeight:400,color:y(50)},children:[" · ",Wi[xn($,_).key]]})]}),t.jsxs("div",{style:{display:"flex",gap:12,fontSize:12.5,marginTop:2},children:[t.jsx("span",{style:{color:ae},children:fe.good}),t.jsx("span",{style:{color:Ne},children:fe.focus})]})]}),t.jsx("span",{style:{fontSize:12.5,color:y(50),whiteSpace:"nowrap",textAlign:"right"},children:be}),t.jsxs("span",{className:"sc-chip",style:{background:M.bg,color:M.fg,fontSize:11.5,fontWeight:700,padding:"3px 10px"},children:[t.jsx("i",{className:`ph-duotone ${M.icon}`}),M.label]})]},$.id)})})]}),ge?null:t.jsxs("div",{id:"sc-custom-summary",style:{display:"flex",flexDirection:"column",gap:10,scrollMarginTop:80},children:[t.jsxs("div",{className:"sc-h3row",children:[t.jsx("span",{className:"sc-htile",style:{background:"#fff3cc",color:"#7a5200"},children:t.jsx("i",{className:"ph-duotone ph-book-open-text"})}),t.jsx("h3",{className:"sc-h3",children:"Custom summary"}),t.jsx("span",{style:{marginLeft:"auto",fontSize:12.5,color:y(55)},children:"Any date range, drafted as an email"})]}),t.jsxs("div",{className:"sc-card",style:{padding:"16px 18px"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsx("input",{type:"date",className:"sc-date",value:Y,max:V||void 0,onChange:$=>H($.target.value),"aria-label":"From",style:{flex:"0 1 170px"}}),t.jsx("span",{style:{fontSize:12,color:y(50)},children:"to"}),t.jsx("input",{type:"date",className:"sc-date",value:V,min:Y||void 0,onChange:$=>me($.target.value),"aria-label":"To",style:{flex:"0 1 170px"}}),t.jsxs("button",{className:"primary",onClick:()=>{ze(!!X)},disabled:Ee||!Y||!V,style:X?{background:"var(--color-ink-chip)",padding:"8px 14px",whiteSpace:"nowrap"}:{padding:"8px 14px",whiteSpace:"nowrap"},children:[Ee?t.jsx(Xe,{size:14}):t.jsx("i",{className:"ph-duotone ph-sparkle"}
282),Ee?"Reading callsâ¦":X?"Regenerate":"Generate summary"]})]}),t.jsxs("div",{style:{fontSize:12.5,color:y(55),marginTop:10,lineHeight:1.5},children:[Y&&V?ue(Y,V):"Pick a range",X?` · ${X.count} ${X.count===1?"call":"calls"}`:"",". TeleServ reads the calls and drafts the email; you review, edit, and send."]}),qe&&t.jsx("div",{style:{fontSize:12,color:je,marginTop:6},children:qe})]}),X&&t.jsxs("div",{className:"sc-card",style:{padding:"18px 22px 20px",borderColor:"rgba(0,136,176,.3)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[t.jsxs("span",{className:"seclbl",children:["Draft · ",Ye?Co[W?"desk":"agent"](X.from,X.to,Ye):X.label]}),t.jsxs("div",{style:{display:"flex",gap:12,fontSize:12},children:[t.jsxs("span",{style:{color:ae},children:[X.wins.length," ",X.wins.length===1?"call":"calls"," worth celebrating"]}),t.jsxs("span",{style:{color:Ne},children:[X.coach.length," to work on"]})]})]}),t.jsx("div",{className:"serif",style:{fontSize:22,fontWeight:600,marginTop:12},children:Ve}),t.jsx("textarea",{className:"sc-ta",value:X.text,onChange:$=>re({...X,text:$.target.value}),rows:4,style:{marginTop:8},"aria-label":"Summary text"}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:12,flexWrap:"wrap"},children:[N.email?t.jsxs("a",{className:"primary",href:he,onClick:()=>it(`Opened in your mail app, addressed to ${N.email}.`),style:{padding:"9px 16px",textDecoration:"none"},children:[t.jsx("i",{className:"ph-duotone ph-paper-plane-tilt"}),"Send to ",W?N.name?hn(N.name):"the manager":v]}):t.jsxs("button",{className:"primary",disabled:!0,style:{padding:"9px 16px"},children:[t.jsx("i",{className:"ph-duotone ph-paper-plane-tilt"}),"Send to ",v]}),t.jsx("button",{className:"sc-quiet",onClick:()=>{re(null),it(null)},children:"Discard"}),t.jsx("span",{style:{marginLeft:g?0:"auto",fontSize:12,color:y(50)},children:N.email?bs(W,Un)?ho:mo:W?"Set a manager email for this desk in Account management to send.":`Add ${v}'s email in Account management to send.`})]})]}),ke&&t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,fontSize:12.5,color:At,fontWeight:600},children:[t.jsx("i",{className:"ph-duotone ph-check-circle",style:{fontSize:15}}),t.jsx("span",{children:ke})]})]})]})]})}function pr({digest:e,cadence:n,busy:i,orgName:o,note:a,onSend:d,onRebuild:c,onBack:b}){const f=Yt(),j=Wt.useRouteContext().org.timezone,g=Vt(e),p=e.facts?.v===3&&!!g,v=e.status==="draft"&&!Un&&uo(e.audience,e.facts),[N,W]=h.useState(e.html),[T,_]=h.useState(!1),[O,U]=h.useState(0),ce=g?.builtAt??null;h.useEffect(()=>{if(W(e.html),_(!1),!p||e.html)return;let H=!0;return ko({data:{id:e.id}}).then(V=>{H&&(V.html?W(V.html):_(!0))}).catch(()=>{H&&_(!0)}),()=>{H=!1}},[e.id,e.html,p,ce,O]);const K=!g&&Vn(e.facts?.v)&&typeof e.facts?.error=="string"?e.facts.error:null,q=!g&&!K&&Vn(e.facts?.v),Te=(e.recipientName||e.agentName||"").trim().split(/\s+/)[0],ee=Te?Te.charAt(0).toUpperCase()+Te.slice(1).toLowerCase():"there",F=xn(e,n),w=g?g.rendered.eyebrow:`${e.isDesk?st[F.key].deskHead.charAt(0).toUpperCase()+st[F.key].deskHead.slice(1):`Your ${st[F.key].noun}`} · ${new Date(`${e.periodStart}T00:00:00`).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}).toUpperCase()}`,P=(H,V=!1)=>t.jsxs(gt,{to:"/calls",search:{period:"all",call:H},className:"sc-link",style:V?{fontSize:13,verticalAlign:"baseline"}:{fontSize:12,marginTop:9},children:[t.jsx("i",{className:"ph-duotone ph-play-circle"}),"Listen back"]}),D=H=>{const V=/[?&]call=([0-9a-f-]{36})/i.exec(H.href??"")?.[1];return V?P(V,!0):H.href?t.jsx("a",{href:H.href,target:"_blank",rel:"noopener noreferrer",className:"sc-link",style:{fontSize:13},children:H.linkLabel||"Open"}):null},Z=e.status==="acknowledged"?`${e.sentAt?`Sent ${Ke(e.sentAt,j)}`:"Sent"}${e.acknowledgedAt?` · read ${Ke(e.acknowledgedAt,j)}`:""}`:e.status==="sent"?`Sent ${e.sentAt?pt(e.sentAt,j):""}`.trim():"Draft",te={border:"1px solid var(--color-divider)",borderRadius:12,padding:"14px 16px",background:"#fff"},Y=e.audience==="team"?"Set the manager email for this team to send.":e.isDesk?"Set a manager email for this desk in Settings, Account management, to send.":"Add this agent's email in Settings, Account management, to send.";return t.jsxs("div",{children:[t.jsxs("button",{className:"sc-back",onClick:b,style:{padding:"0 0 12px"},children:[t.jsx("i",{className:"ph-duotone ph-arrow-left"}),"All summaries"]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:10,padding:"0 4px 10px",fontSize:12.5,color:y(55),flexWrap:"wrap"},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[t.jsx("i",{className:"ph-duotone ph-envelope-simple",style:{color:ae}}),"From ",t.jsx("b",{style:{color:It},children:"TeleServ"})]}),t.jsxs("span",{children:["To ",e.recipientEmail??(e.isDesk?"the desk manager (no email set)":"no email on file")," · ",Z]})]}),p&&g?t.jsx("div",{className:"sc-tbl",children:N?t.jsx(si,{html:N,title:"Email preview",popups:!0}):T?t.jsxs("div",{style:{padding:f?"24px 18px 26px":"28px 32px 30px",display:"flex",alignItems:"center",gap:12,flexWrap:"wrap"},children:[t.jsx("span",{style:{fontSize:13.5,color:y(55),lineHeight:1.5},children:"The email could not be loaded."}),t.jsxs("button",{className:"ghostbtn",onClick:()=>U(H=>H+1),style:{padding:"8px 12px"},children:[t.jsx("i",{className:"ph-duotone ph-arrows-clockwise"}),"Try again"]})]}):t.jsxs("p",{style:{fontSize:13.5,color:y(55),margin:0,padding:f?"24px 18px 26px":"28px 32px 30px",lineHeight:1.5,display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xe,{}),"Loading the emailâ¦"]})}):t.jsxs("div",{className:"sc-tbl",children:[t.jsxs("div",{style:{padding:"16px 24px",borderBottom:"1px solid var(--color-border)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[t.jsx("img",{src:"/teleserv-logo.png",alt:"TeleServ",style:{height:22,width:"auto",display:"block"}}),t.jsx("span",{style:{fontSize:11,letterSpacing:".12em",textTransform:"uppercase",color:Ae},children:w})]}),t.jsx("div",{style:{padding:f?"24px 18px 26px":"28px 32px 30px",maxWidth:620,marginInline:"auto"},children:g?t.jsx(Io,{rendered:g.rendered,link:D,showEyebrow:!1,button:"static"}):K?t.jsxs("p",{style:{fontSize:13.5,color:je,margin:0,lineHeight:1.5},children:["The last build of this email did not finish (",K,"). Rebuild to try again."]}):q?t.jsxs("p",{style:{fontSize:13.5,color:y(55),margin:0,lineHeight:1.5,display:"flex",alignItems:"center",gap:8},children:[t.jsx(Xe,{}),"This email is still being built. Open it again in a minute."]}):t.jsxs(t.Fragment,{children:[t.jsxs("h3",{className:"serif",style:{fontSize:26,fontWeight:600,margin:0,letterSpacing:"-.01em"},children:["Hi ",ee,","]}),e.headline&&t.jsx("p",{style:{fontSize:15,lineHeight:1.65,color:y(75),margin:"14px 0 0",textWrap:"pretty"},children:e.headline}),e.wins.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h4",{className:"serif",style:{fontSize:19,fontWeight:600,margin:"26px 0 0"},children:"Calls worth celebrating"}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,marginTop:12},children:e.wins.map((H,V)=>t.jsxs("div",{style:te,children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",ga
282p:8},children:[t.jsx("i",{className:"ph-duotone ph-phone-call",style:{color:ae,fontSize:15,marginTop:2,flex:"none"}}),t.jsx("span",{style:{fontSize:14,fontWeight:600},children:H.title})]}),H.note&&t.jsx("p",{style:{fontSize:12.5,color:y(62),lineHeight:1.5,margin:"6px 0 0"},children:H.note}),P(H.callId)]},V))})]}),e.improvements.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("h4",{className:"serif",style:{fontSize:19,fontWeight:600,margin:"26px 0 0"},children:"One thing for next week"}),e.improvements.slice(0,2).map((H,V)=>t.jsxs("div",{style:{...te,marginTop:12},children:[t.jsx("div",{style:{fontSize:14,fontWeight:600},children:H.subject}),H.did&&t.jsxs("div",{style:{fontSize:12.5,color:y(62),marginTop:5,lineHeight:1.5},children:[t.jsx("b",{style:{color:y(75)},children:"What happened:"})," ",H.did]}),H.instead&&t.jsxs("div",{style:{fontSize:12.5,color:At,marginTop:2,lineHeight:1.5},children:[t.jsx("b",{children:"Better:"})," ",H.instead]}),H.policy&&t.jsxs("div",{style:{fontSize:12,color:ae,marginTop:6,display:"inline-flex",alignItems:"center",gap:4},children:[t.jsx("i",{className:"ph-duotone ph-link-simple"}),H.policy]}),P(H.callId)]},V))]}),e.wins.length===0&&e.improvements.length===0&&t.jsx("p",{style:{fontSize:13.5,color:y(50),marginTop:22,lineHeight:1.5},children:"A quiet week. No standout wins or coaching notes were logged."}),t.jsxs("p",{style:{fontSize:13,color:y(55),margin:"26px 0 0"},children:[o?`The ${o} team`:"Your team",", via TeleServ"]})]})})]}),t.jsxs("div",{className:"sc-card",style:{marginTop:12,borderRadius:12,padding:"12px 16px"},children:[v&&t.jsx("div",{style:{fontSize:12.5,color:Ne,marginBottom:10,lineHeight:1.5},children:fo}),e.status==="draft"&&t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:12.5,color:y(55),fontWeight:600},children:[t.jsx("i",{className:"ph-duotone ph-pencil-simple"}),"TeleServ built this. Review it, then send",e.recipientName?` to ${e.recipientName}`:"","."]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(g||K)&&c&&t.jsxs("button",{className:"ghostbtn",onClick:c,disabled:i!==null,style:{padding:"8px 12px"},children:[i==="rebuild"?t.jsx(Xe,{size:14}):t.jsx("i",{className:"ph-duotone ph-arrows-clockwise"}),i==="rebuild"?"Rebuildingâ¦":"Rebuild"]}),t.jsxs("button",{className:"primary",onClick:d,disabled:i!==null||!e.recipientEmail||v,style:{padding:"8px 14px"},children:[i==="send"?t.jsx(Xe,{size:14}):t.jsx("i",{className:"ph-duotone ph-paper-plane-tilt"}),i==="send"?"Sendingâ¦":"Review and send now"]})]})]}),e.status==="sent"&&t.jsxs("div",{style:{fontSize:12.5,color:Ne,fontWeight:600,display:"inline-flex",alignItems:"center",gap:6},children:[t.jsx("i",{className:"ph-duotone ph-paper-plane-tilt"}),"Sent",e.sentAt?` ${pt(e.sentAt,j)}`:""," · awaiting acknowledgement"]}),e.status==="acknowledged"&&t.jsxs("div",{children:[t.jsxs("div",{style:{fontSize:12.5,color:ae,fontWeight:600,display:"inline-flex",alignItems:"center",gap:6},children:[t.jsx("i",{className:"ph-duotone ph-seal-check"}),"Acknowledged",e.acknowledgedAt?` ${pt(e.acknowledgedAt,j)}`:"",e.recipientName?` by ${e.recipientName}`:""]}),e.reply&&t.jsxs("div",{style:{marginTop:10,background:"var(--color-control-bg)",borderRadius:10,padding:"11px 13px",fontSize:13,lineHeight:1.5},children:[t.jsx("div",{className:"seclbl",children:"Their reply"}),t.jsx("div",{style:{marginTop:4},children:e.reply})]})]}),e.status==="draft"&&a&&t.jsx("div",{style:{fontSize:12,color:y(55),marginTop:8,lineHeight:1.5},children:a}),e.status==="draft"&&!e.recipientEmail&&t.jsx("div",{style:{fontSize:11.5,color:je,marginTop:8},children:Y})]})]})}export{kr as component};
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.