PageSourceSearch

https://www.quickcapitaloffers.com/assets/AgentPerformanceDashboard-m7IDMie2.js

js quickcapitaloffers.com collected 2026-10-09 22:06:20 UTC 36,722 bytes, 6 lines download raw bytes

1import{c as me,r as m,f as Q,j as e,B as v,g as ue,e as U,s as q,k as he,a as A,R as xe,C as z,G as pe}from"./index-CiYeuz0N.js";import{u as de}from"./useQuery-DDBuj9h-.js";import{I}from"./input-D314iH3y.js";import{t as oe}from"./tvApi-p9Y2YlK8.js";import{B as Y}from"./badge-vdvaIFAH.js";import{S as fe}from"./skeleton-uEYaQCK0.js";import{A as ee}from"./AgentAvatar-DFKU9Yir.js";import{p as Z,a as ge}from"./useCompanyPerformance-BpleUoep.js";import{u as be,a as ve,h as je}from"./useHiddenReps-DPAqKpAM.js";import{v as ne,r as we,p as ye}from"./companyPerformance-CzxNH-KV.js";import{D as Ne,P as X,v as Ce,a as Se,C as _e}from"./CelebrationPreferences-BJmSJUcb.js";import{u as te}from"./useMutation-BIVTJNYP.js";import{P as ke}from"./party-popper-By8rLBZA.js";import{P as Pe}from"./pencil-CfXL2ajK.js";import{P as le}from"./plus-nGcDYAPD.js";import{X as Fe}from"./x-Dbso6HhZ.js";import{L as B}from"./label-Dm2MMzuh.js";import{D as Ee,f as Te,a as Re,b as $e,c as qe,d as Me}from"./dialog-B5tpbFY2.js";import{S as De}from"./settings-2-DmkQ4pBk.js";import{S as Le}from"./search-CKERWwVe.js";import{T as J}from"./trophy-wCsMVfk1.js";import{S as Ae}from"./send-DIp21oOB.js";import{C as Ie}from"./circle-check-5M5KvzHg.js";import{D as Oe}from"./dollar-sign-CJhoZxCc.js";import{M as ze}from"./medal-BLRGMW2b.js";import{E as ce}from"./eye-off-USLrUbnG.js";import{E as Ue}from"./eye-CysgaSrb.js";import{T as Ge}from"./target-di2ibI-t.js";import{S as Ke}from"./sparkles-DRJhCLLh.js";import{A as Ve}from"./arrow-up-right-DVydq4aH.js";import"./switch-DX29oGYf.js";import"./index-l_Lcklqs.js";import"./FundingCelebrationCard-DYOmgOHz.js";import"./volume-x-Br7qULZA.js";import"./rotate-ccw-Bi9YD835.js";import"./index-pJfIofiV.js";import"./Combination-B4zPcfIW.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Qe=me("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);function Ye(){var R;const[x,u]=m.useState(!1),[o,p]=m.useState("Office TV"),[t,j]=m.useState(null),[a,N]=m.useState(!1),[i,g]=m.useState(""),k=Q(),_=de({queryKey:["performance-tv-links"],enabled:x,queryFn:()=>oe({action:"list"})}),T=ue(),P=new URL(T).host,F=h=>h.short_code?`${T}/tv/${h.short_code}`:`${T}/performance/tv/${h.id}`,n=async(h,E)=>{N(!0),g("");try{const C=await oe({action:h,id:E,label:o});h==="create"?j(C):((t==null?void 0:t.id)===E&&j(null),await k.cancelQueries({queryKey:["performance-tv-links"]}),k.setQueryData(["performance-tv-links"],S=>S&&{...S,links:S.links.filter(b=>b.id!==E)})),await k.invalidateQueries({queryKey:["performance-tv-links"]})}catch(C){g(C instanceof Error?C.message:"Could not update display access.")}finally{N(!1)}};return e.jsxs("section",{className:"rounded-xl border p-4 bg-card text-card-foreground",children:[e.jsx(v,{variant:"outline",onClick:()=>u(!x),"aria-expanded":x,children:"Office TV display"}),x&&e.jsxs("div",{className:"space-y-4 mt-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Create a private, read-only scoreboard. The link lasts 90 days; entering its PIN unlocks this browser tab for up to 30 days. Revoke access here at any time. Customer details are excluded."}),e.jsxs("form",{className:"flex flex-wrap gap-2",onSubmit:h=>{h.preventDefault(),n("create")},children:[e.jsx(I,{"aria-label":"Display name",value:o,maxLength:80,onChange:h=>p(h.target.value),className:"max-w-xs"}),e.jsx(v,{disabled:a||!o.trim(),children:"Create link and PIN"})]}),i&&e.jsx("p",{role:"alert",children:i}),t&&e.jsxs("div",{className:"rounded-lg border p-4 space-y-2",children:[e.jsx("p",{className:"font-semibold",children:"Save this PIN now; it is shown only here."}),e.jsx("a",{className:"block underline break-all",href:F(t),target:"_blank",rel:"noreferrer",children:F(t)}),e.jsxs("p",{children:[t.short_code&&e.jsxs(e.Fragment,{children:["Display code: ",e.jsx("strong",{className:"font-mono tracking-widest",children:t.short_code}),e.jsx("br",{})]}),"PIN:"," ",e.jsx("strong",{className:"font-mono text-2xl tracking-widest",children:t.pin})]}),e.jsxs("p",{className:"text-sm",children:["Open the short link, or type ",P,"/tv and enter the display code and PIN. Choose Full screen and Enable sound once for automatic victory videos. Keep the PIN separate from the URL."]}),e.jsx(v,{variant:"outline",onClick:()=>j(null),children:"Hide PIN"})]}),_.isError&&e.jsxs("p",{role:"alert",children:["Could not load display links."," ",e.jsx(v,{variant:"link",onClick:()=>_.refetch(),children:"Retry"})]}),(R=_.data)==null?void 0:R.links.filter(h=>!h.revoked_at).map(h=>e.jsxs("div",{className:"flex flex-wrap justify-between gap-3 border-t pt-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:h.label}),e.jsxs("p",{className:"text-sm",children:["Expires ",new Date(h.expires_at).toLocaleDateString()]}),e.jsx("a",{className:"text-sm underline break-all",href:F(h),target:"_blank",rel:"noreferrer",children:h.short_code?`${P}/tv/${h.short_code}`:"Open private display"})]}),e.jsx(v,{variant:"outline",disabled:a,onClick:()=>void n("revoke",h.id),children:"Revoke"})]}
6,h.id))]})]})}const W=["company-goal-poll"];function se(x){var o;const u=(o=(x??"").split("@")[0])==null?void 0:o.replace(/[._-]+/g," ").trim();return u?u.split(/\s+/).map(p=>p.charAt(0).toUpperCase()+p.slice(1).toLowerCase()).join(" "):"Teammate"}function Be(){return de({queryKey:W,queryFn:async()=>{const{data:x,error:u}=await q.from("company_goal_polls").select("id, question, is_open").eq("is_active",!0).order("created_at",{ascending:!1}).limit(1);if(u)throw u;const o=x==null?void 0:x[0];if(!o)return null;const[p,t]=await Promise.all([q.from("company_goal_poll_options").select("id, label, position").eq("poll_id",o.id).order("position",{ascending:!0}),q.from("company_goal_poll_votes").select("option_id, user_id, voter_name, voter_email").eq("poll_id",o.id)]);if(p.error)throw p.error;if(t.error)throw t.error;return{...o,options:p.data??[],votes:t.data??[]}},staleTime:2e4,refetchInterval:6e4,retry:1})}function He(){const x=Q(),u=U(o=>o.user);return te({mutationFn:async({pollId:o,optionId:p,name:t})=>{if(!u)throw new Error("Sign in to vote.");const{error:j}=await q.from("company_goal_poll_votes").upsert({poll_id:o,option_id:p,user_id:u.id,voter_name:t||se(u.email),voter_email:(u.email??"").toLowerCase(),updated_at:new Date().toISOString()},{onConflict:"poll_id,user_id"});if(j)throw j},onSuccess:()=>x.invalidateQueries({queryKey:W})})}function We(){const x=Q(),u=U(o=>o.user);return te({mutationFn:async({question:o,choices:p,pollId:t})=>{const j=p.map(i=>i.trim()).filter(Boolean);if(!o.trim())throw new Error("Add a poll question.");if(j.length<2)throw new Error("Add at least two choices.");let a=t??null;if(a){const{error:i}=await q.from("company_goal_polls").update({question:o.trim()}).eq("id",a);if(i)throw i;const{error:g}=await q.from("company_goal_poll_options").delete().eq("poll_id",a);if(g)throw g}else{await q.from("company_goal_polls").update({is_active:!1}).eq("is_active",!0);const{data:i,error:g}=await q.from("company_goal_polls").insert({question:o.trim(),created_by:(u==null?void 0:u.id)??null}).select("id").single();if(g)throw g;a=i.id}const{error:N}=await q.from("company_goal_poll_options").insert(j.map((i,g)=>({poll_id:a,label:i,position:g})));if(N)throw N},onSuccess:()=>x.invalidateQueries({queryKey:W})})}function Ze(){const x=Q();return te({mutationFn:async({pollId:u,isOpen:o,isActive:p})=>{const t={};typeof o=="boolean"&&(t.is_open=o),typeof p=="boolean"&&(t.is_active=p);const{error:j}=await q.from("company_goal_polls").update(t).eq("id",u);if(j)throw j},onSuccess:()=>x.invalidateQueries({queryKey:W})})}function Xe({nameByEmail:x,photoByEmail:u,voterEmails:o,goalReached:p}){const t=U(l=>l.user),j=U(l=>l.isAdmin),{data:a,isLoading:N}=Be(),i=He(),g=We(),k=Ze(),[_,T]=m.useState(!1),[P,F]=m.useState(""),[n,R]=m.useState(["",""]),h=((t==null?void 0:t.email)??"").trim().toLowerCase(),E=!!(a!=null&&a.is_open)&&(!o||o.size===0||o.has(h)),C=a==null?void 0:a.votes.find(l=>l.user_id===(t==null?void 0:t.id)),S=m.useMemo(()=>{const l=new Map;for(const f of(a==null?void 0:a.votes)??[])l.set(f.option_id,[...l.get(f.option_id)??[],f]);return l},[a==null?void 0:a.votes]),b=(a==null?void 0:a.votes.length)??0,L=()=>{F((a==null?void 0:a.question)??"Where should we celebrate if we hit goal?"),R(a&&a.options.length>=2?a.options.map(l=>l.label):["Team dinner","Day outing",""]),T(!0)},r=()=>g.mutate({question:P,choices:n,pollId:(a==null?void 0:a.id)??null},{onSuccess:()=>{T(!1),A.success("Poll saved.")},onError:l=>A.error(l instanceof Error?l.message:"Could not save the poll.")}),d=l=>{a&&i.mutate({pollId:a.id,optionId:l,name:(x==null?void 0:x.get(h))??se(t==null?void 0:t.email)},{onSuccess:()=>A.success("Your vote is in."),onError:()=>A.error("Could not save your vote. Please try again.")})};return N||!a&&!j?null:e.jsxs("div",{className:"relative rounded-2xl border border-white/10 bg-white/5 p-5",children:[e.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[e.jsxs("p",{className:"flex items-center gap-2 text-xs font-bold uppercase tracking-[0.16em] text-amber-300",children:[e.jsx(ke,{className:"h-4 w-4"})," If we hit goal"]}),j&&!_&&e.jsxs("div",{className:"flex items-center gap-1",children:[a&&e.jsx(v,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs text-slate-300 hover:bg-white/10 hover:text-white",onClick:()=>k.mutate({pollId:a.id,isOpen:!a.is_open}),children:a.is_open?"Close voting":"Reopen"}),e.jsx(v,{size:"icon",variant:"ghost","aria-label":a?"Edit poll":"Create poll",className:"h-7 w-7 text-slate-300 hover:bg-white/10 hover:text-white",onClick:L,children:a?e.jsx(Pe,{className:"h-3.5 w-3.5"}):e.jsx(le,{className:"h-4 w-4"})})]})]}),_?e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{"aria-label":"Poll question",value:P,onChange:l=>F(l.target.value),placeholder:"Where should we celebrate if we hit goal?",className:"border-white/20 bg-white/10 text-white placeholder:text-slate-400"}),n.map((l,f)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{"aria-label":`Choice ${f+1}
6`,value:l,onChange:w=>R(n.map(($,y)=>y===f?w.target.value:$)),placeholder:`Choice ${f+1}`,className:"border-white/20 bg-white/10 text-white placeholder:text-slate-400"}),n.length>2&&e.jsx(v,{size:"icon",variant:"ghost","aria-label":`Remove choice ${f+1}`,className:"h-8 w-8 shrink-0 text-slate-300 hover:bg-white/10 hover:text-white",onClick:()=>R(n.filter((w,$)=>$!==f)),children:e.jsx(Fe,{className:"h-4 w-4"})})]},f)),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:[e.jsxs(v,{size:"sm",variant:"ghost",className:"text-slate-300 hover:bg-white/10 hover:text-white",onClick:()=>R([...n,""]),children:[e.jsx(le,{className:"mr-1 h-3.5 w-3.5"})," Add choice"]}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[e.jsx(v,{size:"sm",variant:"ghost",className:"text-slate-300 hover:bg-white/10 hover:text-white",onClick:()=>T(!1),children:"Cancel"}),e.jsx(v,{size:"sm",onClick:r,disabled:g.isPending,children:"Save poll"})]})]})]}):a?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"mb-3 text-lg font-bold leading-snug text-white",children:a.question}),e.jsx("ul",{className:"space-y-2",children:a.options.map(l=>{const f=S.get(l.id)??[],w=b>0?f.length/b*100:0,$=(C==null?void 0:C.option_id)===l.id;return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!E||i.isPending,onClick:()=>d(l.id),"aria-pressed":$,className:`group relative w-full overflow-hidden rounded-xl border px-3 py-2.5 text-left transition ${$?"border-amber-300/60 bg-amber-300/10":"border-white/10 bg-white/5"} ${E?"hover:border-white/30 hover:bg-white/10":"cursor-default"}`,children:[e.jsx("span",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 bg-gradient-to-r from-amber-400/20 to-amber-300/5 transition-[width]",style:{width:`${w}%`}}),e.jsxs("span",{className:"relative flex items-center gap-3",children:[e.jsxs("span",{className:"flex-1 text-sm font-semibold text-white",children:[l.label,$&&e.jsx(he,{className:"ml-1.5 inline h-3.5 w-3.5 text-amber-300"})]}),e.jsxs("span",{className:"flex -space-x-2",children:[f.slice(0,5).map(y=>e.jsx(ee,{userId:y.user_id,photoUrl:(u==null?void 0:u.get((y.voter_email??"").toLowerCase()))??void 0,name:y.voter_name??se(y.voter_email),size:24,className:"ring-2 ring-slate-900"},y.user_id)),f.length>5&&e.jsxs("span",{className:"flex h-6 items-center rounded-full bg-white/10 px-1.5 text-[10px] font-bold text-white ring-2 ring-slate-900",children:["+",f.length-5]})]}),e.jsx("span",{className:"w-6 text-right text-sm font-bold tabular-nums text-amber-200",children:f.length})]})]})},l.id)})}),e.jsx("p",{className:"mt-3 text-xs text-slate-400",children:a.is_open?E?p?"Goal reached — the winning plan is on.":`${b} ${b===1?"vote":"votes"} so far. ${C?"Tap another choice to change yours.":"Pick yours."}`:"Only reps on the board can vote.":"Voting is closed."})]}):e.jsx("p",{className:"text-sm text-slate-300",children:"Add a poll so the team can vote on how we celebrate hitting the monthly goal."})]})}function Je(){const[x,u]=m.useState(!1),[o,p]=m.useState(Ne),[t,j]=m.useState("submissions"),[a,N]=m.useState({submissions:"",approvals:"",fundings:"true"}),[i,g]=m.useState([]),[k,_]=m.useState(!1),[T,P]=m.useState(!1),[F,n]=m.useState(""),R=Q(),h=async r=>{if(u(r),!!r){_(!0),P(!1),n("");try{const d=await Z({action:"configuration"});p(d.config),N(Object.fromEntries(X.map(l=>[l,d.config.sources[l].statusValues.join(", ")]))),P(!0)}catch(d){n(d instanceof Error?d.message:"Could not load setup")}finally{_(!1)}}},E=(r,d)=>p(l=>({...l,sources:{...l.sources,[t]:{...l.sources[t],[r]:d}}})),C=async()=>{_(!0),n(""),g([]);try{const r=await Z({action:"discover",object:o.sources[t].object});g(r.fields)}catch(r){n(r instanceof Error?r.message:"Could not load Salesforce fields")}finally{_(!1)}},S=async()=>{_(!0),n("");try{const r={...o,sources:Object.fromEntries(X.map(d=>[d,{...o.sources[d],statusValues:a[d].split(",").map(l=>l.trim()).filter(Boolean)}]))};Ce(r),await Z({action:"configure",config:r}),await R.invalidateQueries({queryKey:["company-performance"]}),A.success("Salesforce sources validated and saved"),u(!1)}catch(r){n(r instanceof Error?r.message:"Could not save setup")}finally{_(!1)}},b=o.sources[t],L=[["dateField",`${t==="submissions"?"Submission":t==="approvals"?"Approval":"Funding"} date field`],["newBusinessField","New-business filter field"],["newBusinessValue","Exact new-business value"],["repIdField","Credited rep ID field"],["repNameField","Credited rep name field"],["repEmailField","Credited rep email field"],["businessField","Business name field"],...t==="fundings"?[["amountField","Funded amount field"],["commissionField","Commission field"]]:[],["statusField","Status field (optional)"]];return e.jsxs(Ee,{open:x,onOpenChange:h,children:[e.jsx(Te,{asChild:!0,children:e.jsxs(v,{variant:"ghost",className:"gap-2",children:[e.jsx(De,{className:"h-4 w-4"})," Dashboard setup"]})}),e.jsxs(Re,{className:"sm:max-w-2xl max-h-[90dvh] overflow-y-auto",children:[e.jsxs($e,{children:[e.jsx(qe,{children:"Connect company performance"}),e.jsx(Me,{children:"Read directly from the existing Salesforce connection. Count one unique source record per event, on its event date. Renewals are excluded by the required new-business filter."})]}),F&&e.jsx("p",{role:"alert",className:"rounded-lg bg-destructive/10 p-3 text-sm text-destructive",children:F}),e.jsxs("fieldset",{disabled:k||!T,className:"space-y-4 disabled:opacity-60",children:[e.jsx("div",{className:"grid gap-3 sm:grid-cols-3",children:[["timeZone","Company timezone"],["currency","Currency"],["monthlyGoal","Monthly commission goal"]].map(([r,d])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(B,{htmlFor:`perf-${r}`,children:d}),e.jsx(I,{id:`perf-${r}`,value:o[r],type:r==="monthlyGoal"?"number":"text",min:0,onChange:l=>p(f=>({...f,[r]:r==="monthlyGoal"?Number(l.target.value):l.target.value}))})]},r))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The monthly goal bar measures company commission, not funded volume. Set the goal to 0 to hide it. Currency must match the source amounts; mixed currencies aren’t added together."}),e.jsx("div",{className:"rounded-lg bg-muted p-3 text-sm leading-relaxed",children:"The QCF preset counts each new-business opportunity once when submitted, approved, and funded. Credit goes to its current Salesforce owner. Review the mapping below if your team credits a different rep or counts individual lender submissions."}),e.jsxs("details",{className:"space-y-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-semibold",children:"Review Salesforce field mapping"}),e.jsx("div",{className:"flex gap-2","aria-label":"Metric source",children:X.map(r=>e.jsx(v,{size:"sm",variant:t===r?"default":"outline","aria-pressed":t===r,onClick:()=>{j(r),g([])},className:"capitalize",children:r},r))}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(B,{htmlFor:"perf-object",children:"Salesforce object"}),e.jsx(I,{id:"perf-object",value:b.object,onChange:r=>{E("object",r.target.value),g([])}})]}),e.jsxs(v,{variant:"outline",onClick:C,className:"gap-2",children:[e.jsx(Le,{className:"h-4 w-4"})," Find fields"]})]}),i.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i.length," ","Salesforce fields loaded. Type a field name to see matches. Rep relationship fields can use paths such as Owner.Email."]}),e.jsx("datalist",{id:"performance-fields",children:i.map(r=>e.jsxs("option",{value:r.name,children:[r.label," (",r.type,")"]},r.name))}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[L.map(([r,d])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(B,{htmlFor:`perf-${r}`,children:d}),e.jsx(I,{id:`perf-${r}`,list:r.endsWith("Field")?"performance-fields":void 0,value:String(b[r]??""),onChange:l=>E(r,l.target.value)})]},r)),e.jsxs("div",{className:"space-y-1",children:[e.jsx(B,{htmlFor:"perf-statuses",children:"Allowed statuses (comma-separated)"}),e.jsx(I,{id:"perf-statuses",value:a[t],onChange:r=>N(d=>({...d,[t]:r.target.value}))})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use the actual submission or approval timestamp, not CreatedDate or the current stage. Choose the rep who should receive credit; their Salesforce email must match their app login for their celebration video to appear."})]})]}),e.jsx(v,{onClick:S,disabled:k||!T,children:k?"Checking Salesforce…":"Validate with Salesforce & save"})]})]})}const K={today:"Today",week:"This week",month:"This month",quarter:"This quarter",year:"This year"},V={volume:"Funded volume",commission:"Commission",fundings:"Fundings",submissions:"Submissions",approvals:"Approvals"},H=new Intl.NumberFormat("en-US");function Ls({embedded:x=!1}={}){const u=x?"h2":"h1",[o,p]=m.useState("month"),[t,j]=m.useState("volume"),a=U(s=>s.user),N=U(s=>s.isAdmin),{data:i,isLoading:g,isError:k,isFetching:_,refetch:T}=ge(),{data:P}=be(),F=ve(),n=i==null?void 0:i.snapshot,R=m.useMemo(()=>new Map(Object.entries((i==null?void 0:i.agentPhotos)??{}).map(([s,c])=>[s.trim().toLowerCase(),c])),[i==null?void 0:i.agentPhotos]),h=m.useMemo(()=>{var s;return new Map((((s=i==null?void 0:i.snapshot)==null?void 0:s.periods.year.reps)??[]).filter(c=>c.email).map(c=>[c.email.trim().toLowerCase(),c.name]))},[i==null?void 0:i.snapshot]),E=s=>s?R.get(s.trim().toLowerCase())??null:null,C=m.useMemo(()=>je(P),[P]),S=m.useMemo(()=>new Set(((i==null?void 0:i.boardEmails)??[]).map(s=>s.trim().toLowerCase())),[i==null?void 0:i.boardEmails]),b=m.useMemo(()=>ne(n==null?void 0:n.periods[o],C,S),[n,o,C,S]),L=m.useMemo(()=>ne(n==null?void 0:n.periods.month,C,S),[n,C,S]),r=m.useMemo(()=>S.size===0?[]:((n==null?void 0:n.periods[o].reps)??[]).filter(s=>{const c=(s.email??"").trim().toLowerCase();return!S.has(c)&&!C.has(c)&&s.volume>0}).map(s=>({name:s.name,volume:s.volume})).sort((s,c)=>c.volume-s.volume),[n,o,S,C]),d=m.useMemo(()=>we((b==null?void 0:b.reps)??[],t),[b,t]),l=m.useMemo(()=>{const s=new Map(((n==null?void 0:n.periods.year.reps)??[]).map(c=>[(c.email??"").trim().toLowerCase(),c]));return(P??[]).map(c=>{var D,G;return{email:c.email,name:c.displayName||((D=s.get(c.email))==null?void 0:D.name)||c.email,volume:((G=s.get(c.email))==null?void 0:G.volume)??0}}).sort((c,D)=>D.volume-c.volume||c.name.localeCompare(D.name))},[P,n]),f=(s,c,D)=>{F.mutate({email:s,hidden:D,displayName:c},{onSuccess:()=>A.success(D?`${c} is off the board.`:`${c} is back on the board.`),onError:G=>A.error(G instanceof Error&&/forbidden/i.test(G.message)?"Only an administrator can change who appears.":"C
6ould not update the board. Please try again.")})},w=d.find(s=>{var c;return s.email&&s.email===((c=a==null?void 0:a.email)==null?void 0:c.trim().toLowerCase())}),$=w?[...d].reverse().find(s=>s[t]>w[t]):null,y=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:(n==null?void 0:n.currency)??"USD",maximumFractionDigits:0}).format(s),ae=s=>t==="volume"||t==="commission"?y(s):H.format(s),re=w?ye(w):[],O=(L==null?void 0:L.totals.commission)??0,M=(n==null?void 0:n.monthlyGoal)??0,ie=d.filter(s=>s[t]>0).slice(0,3);return e.jsxs("div",{className:"space-y-6 pb-8",children:[e.jsxs("header",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.jsxs("div",{children:[!x&&e.jsx("p",{className:"mb-2 text-xs font-semibold uppercase tracking-[0.14em] text-primary",children:"Team results"}),e.jsx(u,{className:x?"text-xl font-semibold tracking-tight":"text-3xl font-semibold tracking-tight",children:"Company performance"}),e.jsx("p",{className:"mt-3 max-w-2xl text-sm leading-relaxed text-muted-foreground",children:"Follow new-business results, compare progress, and plan your next move."})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 text-sm font-medium",children:[e.jsx("a",{href:"#team-goal",className:"rounded text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"Team goal & celebration"}),N&&e.jsx("a",{href:"#performance-tv",className:"rounded text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"Office TV display"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1 rounded-xl bg-muted p-1","aria-label":"Performance period",children:Se.map(s=>e.jsx(v,{size:"sm",variant:o===s?"default":"ghost","aria-pressed":o===s,onClick:()=>p(s),children:K[s]},s))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(_e,{}),N&&e.jsx(Je,{}),e.jsx(v,{variant:"ghost",size:"icon","aria-label":"Refresh company performance",onClick:()=>T(),disabled:_,children:e.jsx(xe,{className:`h-4 w-4 ${_?"animate-spin motion-reduce:animate-none":""}`})})]})]}),g?e.jsx("div",{"aria-label":"Loading company performance",className:"grid grid-cols-[repeat(auto-fit,minmax(min(100%,220px),1fr))] gap-4",children:[0,1,2,3,4].map(s=>e.jsx(fe,{className:"h-32"},s))}):n?e.jsxs(e.Fragment,{children:[((i==null?void 0:i.stale)||k)&&e.jsx("p",{role:"alert",className:"rounded-lg border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900 dark:bg-amber-950 dark:text-amber-100",children:"Salesforce couldn’t refresh. These are the last successful totals; new wins may be missing."}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(min(100%,220px),1fr))] gap-4",children:[{label:"Submissions",value:H.format(b.totals.submissions),hint:"New business submitted",icon:Ae,tone:"text-blue-500"},{label:"Approvals",value:H.format(b.totals.approvals),hint:"Salesforce approvals",icon:Ie,tone:"text-violet-500"},{label:"Fundings",value:H.format(b.totals.fundings),hint:"Deals across the finish line",icon:J,tone:"text-amber-500"},{label:"Funded volume",value:y(b.totals.volume),hint:`${K[o]} · ${n.currency}`,icon:Oe,tone:"text-emerald-500"},{label:"Commission",value:y(b.totals.commission??0),hint:"Earned on funded deals",icon:pe,tone:"text-teal-500"}].map(s=>e.jsxs(z,{className:"p-4 sm:p-5",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground sm:text-sm",children:s.label}),e.jsx(s.icon,{className:`h-5 w-5 shrink-0 ${s.tone}`})]}),e.jsx("p",{className:"whitespace-nowrap text-2xl font-semibold tracking-tight tabular-nums",children:s.value}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:s.hint})]},s.label))}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Totals add up only the ",b.reps.length," ","reps on the board below.",N&&r.length>0&&e.jsxs(e.Fragment,{children:[" ","Not counted: ",r.slice(0,4).map(s=>`${s.name} (${y(s.volume)})`).join(", "),r.length>4?` +${r.length-4} more`:"","."]})]}),e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold",children:"The leaderboard"}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[K[o]," · ranked by"," ",V[t].toLowerCase()]})]}),e.jsx("div",{className:"flex flex-wrap gap-1","aria-label":"Rank agents by",children:Object.keys(V).map(s=>e.jsx(v,{size:"sm",variant:t===s?"secondary":"ghost","aria-pressed":t===s,onClick:()=>j(s),children:V[s]},s))})]}),ie.length>0&&e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:ie.map((s,c)=>e.jsxs(z,{className:`relative overflow-hidden p-5 ${c===0?"border-amber-400/60 bg-gradient-to-br from-amber-50 to-card dark:from-amber-950/40":"bg-card"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(Y,{variant:"outline",className:"gap-1",children:[e.jsx(ze,{className:`h-3.5 w-3.5 ${s.rank===1?"text-amber-500":"text-muted-foreground"}`}),s.rank===1?"Setting the pace":`Rank ${s.rank}
6`]}),e.jsxs("span",{className:"text-3xl font-black text-muted-foreground/20",children:["#",s.rank]})]}),e.jsxs("div",{className:"mt-5 flex items-center gap-3",children:[e.jsx(ee,{photoUrl:E(s.email),name:s.name,size:44}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate font-bold",children:s.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.fundings," funded · ",s.approvals," approved"]})]})]}),e.jsx("p",{className:"mt-4 text-2xl font-black tabular-nums",children:ae(s[t])}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:V[t]})]},s.id))}),e.jsxs("div",{className:"grid items-start gap-5 xl:grid-cols-[minmax(0,1fr)_300px]",children:[e.jsxs(z,{className:"overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsxs("caption",{className:"sr-only",children:["New-business rep rankings for ",K[o]]}),e.jsx("thead",{className:"border-b bg-muted/50 text-xs text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"p-4 text-left",children:"Rank / rep"}),["submissions","approvals","fundings","volume","commission"].map(s=>e.jsx("th",{scope:"col",className:"whitespace-nowrap px-3 py-4 text-right",children:V[s]},s)),N&&e.jsx("th",{scope:"col",className:"px-2 py-4 text-right",children:e.jsx("span",{className:"sr-only",children:"Hide rep"})})]})}),e.jsx("tbody",{className:"divide-y",children:d.map(s=>{var c;return e.jsxs("tr",{className:s.id===(w==null?void 0:w.id)?"bg-primary/5":"hover:bg-muted/30",children:[e.jsx("th",{scope:"row",className:"p-4 text-left",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-5 shrink-0 text-xs font-bold text-muted-foreground",children:s.rank}),e.jsx(ee,{photoUrl:E(s.email),name:s.name,size:32,className:"ring-1 ring-border"}),e.jsxs("div",{className:"min-w-[120px]",children:[e.jsxs("p",{className:"font-semibold",children:[s.name," ",s.id===(w==null?void 0:w.id)&&e.jsx("span",{className:"ml-1 text-xs text-primary",children:"You"})]}),e.jsx("div",{className:"mt-1.5 h-1 max-w-40 overflow-hidden rounded-full bg-muted","aria-hidden":"true",children:e.jsx("div",{className:"h-full rounded-full bg-primary/60",style:{width:`${(c=d[0])!=null&&c[t]?s[t]/d[0][t]*100:0}%`}})})]})]})}),e.jsx("td",{className:"px-3 py-4 text-right tabular-nums",children:s.submissions}),e.jsx("td",{className:"px-3 py-4 text-right tabular-nums",children:s.approvals}),e.jsx("td",{className:"px-3 py-4 text-right font-semibold tabular-nums",children:s.fundings}),e.jsx("td",{className:"whitespace-nowrap px-3 py-4 text-right font-bold tabular-nums text-emerald-700 dark:text-emerald-400",children:y(s.volume)}),e.jsx("td",{className:"whitespace-nowrap px-3 py-4 text-right font-bold tabular-nums text-teal-700 dark:text-teal-300",children:y(s.commission??0)}),N&&e.jsx("td",{className:"px-2 py-4 text-right",children:e.jsx(v,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground",title:s.email?`Hide ${s.name} from the board`:"This rep has no email in Salesforce, so they can’t be hidden","aria-label":`Hide ${s.name} from the board`,disabled:!s.email||F.isPending,onClick:()=>f(s.email,s.name,!0),children:e.jsx(ce,{className:"h-4 w-4"})})})]},s.id)})})]})}),d.length===0&&e.jsxs("p",{className:"p-8 text-center text-sm text-muted-foreground",children:["No new-business activity"," ",K[o].toLowerCase(),". The next submission starts the board."]}),N&&e.jsxs("div",{className:"border-t bg-muted/30 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(ce,{className:"h-4 w-4 text-muted-foreground"})," ","Hidden from the board",l.length>0&&e.jsx(Y,{variant:"secondary",children:l.length})]}),l.length===0?e.jsx("p",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:"Everyone with activity appears. Use the hide button on a row to take a shared account or former rep off the board — their deals leave the company totals too."}):e.jsx("ul",{className:"mt-3 space-y-1.5",children:l.map(s=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 text-sm",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:[s.email,s.volume>0&&e.jsxs(e.Fragment,{children:[" · ",y(s.volume)," funded this year"]})]})]}),e.jsxs(v,{variant:"outline",size:"sm",className:"h-8 gap-1.5",disabled:F.isPending,onClick:()=>f(s.email,s.name,!1),children:[e.jsx(Ue,{className:"h-3.5 w-3.5"})," Show"]})]},s.email))}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"This list is just for the company scoreboard. The agent leaderboard has its own switches in Admin settings."})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs(z,{className:"p-5",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-bold",children:[e.jsx(Ge,{className:"h-4 w-4 text-primary"})," Your next move"]}),w?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"mt-4 text-3xl font-black",children:["#",w.rank,e.jsxs("span",{className:"ml-2 text-sm font-normal text-muted-foreground",children:["of ",d.length," active reps"]})]}),e.jsx("p",{className:"mt-3 text-sm leading-relaxed text-muted-foreground",children:$?e.jsxs(e.Fragment,{children:[ae($[t]-w[t])," to tie"," ",$.name,". Your next"," ",t==="submissions"?"submission":t==="approvals"?"approval":"funding"," could change the board."]}):w[t]>0?"You’re setting the pace. Keep building your lead.":"Your first result in this category starts the climb."})]}):e.jsx("p",{className:"mt-4 text-sm leading-relaxed text-muted-foreground",children:"Your personal rank appears after your first new-business result this period. Your Salesforce rep email should match your app login."})]}),e.jsxs(z,{className:"p-5",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-bold",children:[e.jsx(Ke,{className:"h-4 w-4 text-amber-500"})," ","Earned this period"]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:re.length?re.map(s=>e.jsx(Y,{variant:"secondary",children:s},s)):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Fund a deal to earn your first funding badge."})}),e.jsxs("p",{className:"mt-4 text-xs leading-relaxed text-muted-foreground",children:["Milestones: 1 or 5 fundings, ",y(1e5)," ","funded, 10 submissions, or 10 approvals. Badges reset with the selected period."]})]}),e.jsxs("div",{className:"rounded-xl border border-dashed p-4 text-sm",children:[e.jsxs("p",{className:"flex items-center gap-2 font-semibold",children:[e.jsx(Ve,{className:"h-4 w-4"})," Make your win yours"]}),e.jsx("p",{className:"mt-2 text-xs leading-relaxed text-muted-foreground",children:"Pick your YouTube victory video in My celebration. When your deal funds, the whole team gets a moment to celebrate."})]})]})]}),e.jsxs("p",{className:"text-xs leading-relaxed text-muted-foreground",children:["Salesforce verified"," ",new Date(n.updatedAt).toLocaleStr
6ing([],{timeZone:n.timeZone})," ·"," ",n.timeZone,". Counts follow each event’s own date and credited rep. Submissions and approvals are activity totals, not a conversion funnel. Exact ties share a rank."]})]}):e.jsxs(z,{className:"p-10 text-center",children:[e.jsx(J,{className:"mx-auto mb-4 h-10 w-10 text-muted-foreground"}),e.jsx("h2",{className:"text-xl font-bold",children:k?"Salesforce results are unavailable":(i==null?void 0:i.configured)===!1?"Connect the company scoreboard":"Refreshing Salesforce results"}),e.jsx("p",{className:"mx-auto mt-3 max-w-lg text-sm text-muted-foreground",children:k?"Please try Refresh. Your team’s totals will appear when Salesforce is available.":(i==null?void 0:i.configured)===!1?"An administrator can connect the submission, approval, and funding fields in Dashboard setup. Results will appear here after the first successful sync.":"The first sync is underway. This page will update automatically."})]}),e.jsxs("section",{id:"team-goal","aria-labelledby":"team-goal-heading",className:"scroll-mt-24 relative overflow-hidden rounded-2xl bg-gradient-to-br from-slate-900 via-slate-900 to-blue-950 p-6 text-white sm:p-8",children:[e.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute -right-20 -top-24 h-80 w-80 rounded-full bg-blue-500/15 blur-3xl"}),e.jsxs("div",{className:"relative grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,22rem)]",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"mb-3 flex items-center gap-2 text-xs font-bold uppercase tracking-[0.2em] text-blue-200",children:[e.jsx(J,{className:"h-4 w-4"})," Team goal & celebration"]}),e.jsx("h2",{id:"team-goal-heading",className:"text-2xl font-semibold tracking-tight",children:"Every deal moves the team."}),e.jsx("p",{className:"mt-3 max-w-xl text-sm leading-relaxed text-slate-300",children:"New business. Real Salesforce results. See who’s setting the pace—and make your next move."})]}),M>0&&n&&e.jsxs("div",{className:"mt-7 max-w-2xl border-t border-white/10 pt-5",children:[e.jsxs("div",{className:"mb-2 flex flex-wrap justify-between gap-2 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-2 text-slate-300",children:[e.jsx(Qe,{className:"h-4 w-4"})," Company monthly commission goal"]}),e.jsxs("span",{className:"font-bold tabular-nums",children:[y(O)," ",e.jsxs("span",{className:"font-normal text-slate-400",children:["/ ",y(M)]})]})]}),e.jsx("div",{role:"progressbar","aria-label":"Company monthly commission goal","aria-valuenow":Math.min(100,Math.round(O/M*100)),"aria-valuemin":0,"aria-valuemax":100,className:"h-2 overflow-hidden rounded-full bg-white/10",children:e.jsx("div",{className:"h-full rounded-full bg-gradient-to-r from-teal-400 to-emerald-300",style:{width:`${Math.min(100,O/M*100)}%`}})}),e.jsx("p",{className:"mt-2 text-xs text-slate-400",children:O>=M?"Goal reached. Keep the momentum going.":`${y(M-O)} in commission to the monthly finish line.`})]})]}),e.jsxs("div",{className:"flex flex-col items-start gap-4",children:[e.jsx(Y,{className:"border-white/20 bg-white/10 px-3 py-1.5 text-white hover:bg-white/10 lg:self-end",children:"New business only"}),e.jsx("div",{className:"w-full",children:e.jsx(Xe,{nameByEmail:h,photoByEmail:R,voterEmails:S,goalReached:M>0&&O>=M})})]})]})]}),N&&e.jsx("div",{id:"performance-tv",className:"scroll-mt-24",children:e.jsx(Ye,{})})]})}export{Ls as AgentPerformanceDashboard};

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.