1import{u as v,r as j,j as e,L as N,a2 as u,d as _,c as g}from"./main-DX7XzkoU.js";import{S as k}from"./skeleton-DN2cjZOe.js";import{h as w}from"./useSalesCrm-BbMwVkcj.js";import{p as b,i as C,m as S,s as h,f as y}from"./goals-W4goCnrL.js";import{j as L,P,K as f,S as A,f as $}from"./stages-mBi-FRq5.js";import{b as m,c as R}from"./format-jANIzc1h.js";import{P as B}from"./PaceBar-DhA8wGPg.js";import{A as z}from"./arrow-up-right-BkEMUkZ0.js";import{T as E}from"./target-JN3xQfTR.js";import{C as M}from"./chevron-left-B_lb0x5L.js";import{C as T}from"./chevron-right-D27HfhtL.js";const D=s=>s.charAt(0).toUpperCase()+s.slice(1);function I(s){const t=new Map,o=(a,r)=>({id:a,email:r,name:D($(null,r)),position:null,lines:[],revenue:0});for(const a of s.salespeople){const r=t.get(a.salesperson_id)??o(a.salesperson_id,a.email);t.set(a.salesperson_id,{...r,position:a.position??r.position,lines:[...r.lines,a],revenue:r.revenue+Number(a.revenue_brl)})}for(const a of s.activity){const r=t.get(a.salesperson_id)??o(a.salesperson_id,a.email);t.set(a.salesperson_id,{...r,activity:a})}return[...t.values()].sort((a,r)=>r.revenue-a.revenue||a.name.localeCompare(r.name))}const K=s=>s.share_pct>0||s.sales>0||s.created>0||s.in_conversation>0;function l({label:s,value:t,tone:o,hint:a}){return e.jsxs("div",{className:"min-w-0",title:a,children:[e.jsx("p",{className:"text-[10px] uppercase leading-tight tracking-wide text-muted-foreground",children:s}),e.jsx("p",{className:u("font-mono text-sm tabular-nums",o==="bad"&&"text-destructive",o==="good"&&"text-emerald-700 dark:text-emerald-300"),children:t})]})}function O({line:s,daysPassed:t,daysTotal:o}){const a=Number(s.revenue_brl),r=Number(s.target_revenue_brl),i=b(a,r,t,o);return e.jsxs("div",{className:"grid grid-cols-[3.5rem_1fr] gap-x-3",children:[e.jsx("span",{"aria-hidden":!0,className:"grid h-14 w-14 place-items-center rounded-full border border-border bg-background",children:e.jsx(E,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:[f[s.kind],s.share_pct>0?` · ${Number(s.share_pct)}% da meta da empresa`:""]}),e.jsx("p",{className:"font-mono text-3xl tabular-nums leading-tight",children:m(a)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[r>0?e.jsxs(e.Fragment,{children:["de ",m(r)," · ",R(i.pct)]}):"sem fatia da meta neste mês",r>0&&t>0&&e.jsxs(e.Fragment,{children:[" · projeção ",m(i.projection)]})]}),e.jsx(B,{realized:a,target:r,daysPassed:t,daysTotal:o,className:"mt-2"})]}),e.jsxs("div",{className:"col-span-2 mt-4 grid grid-cols-4 gap-2",children:[e.jsx(l,{label:"Criadas",value:s.created,hint:"Oportunidades criadas no mês"}),e.jsx(l,{label:"Conversa",value:s.in_conversation,hint:"Em respondeu ou negociando agora"}),e.jsx(l,{label:"Vendas",value:s.target_sales>0?`${s.sales} / ${s.target_sales}`:s.sales,tone:s.sales>0?"good":void 0,hint:"Convertidas no mês, sobre a meta em vendas (R$ ÷ ticket médio)"}),e.jsx(l,{label:"Perdidas",value:s.lost,tone:s.lost>0?"bad":void 0})]})]})}function U({realized:s,target:t,daysPassed:o,daysTotal:a}){const r=b(s,t,o,a),i=o>0,c=t<=0?"none":i?r.remaining===0?"done":r.onTrack?"ok":"behind":"soon",d={none:"bg-muted-foreground/50",soon:"bg-muted-foreground/50",done:"bg-emerald-500",ok:"bg-emerald-500",behind:"bg-amber-500"}[c],x={none:"Sem meta",soon:`Começa com ${m(r.perDayNeeded)} por dia útil`,done:"Meta batida",ok:`No ritmo · faltam ${m(r.perDayNeeded)} por dia útil`,behind:`Atrás · faltam ${m(r.perDayNeeded)} por dia útil`}[c];return e.jsxs("p",{className:"flex min-w-0 items-center gap-2 rounded-full border border-border bg-background px-3 py-2 text-xs",children:[e.jsx("span",{"aria-hidden":!0,className:u("h-2 w-2 shrink-0 rounded-full",d)}),e.jsx("span",{className:"truncate",children:x})]})}function V({seller:s,daysPassed:t,daysTotal:o,isMe:a}){const r=L.map(n=>s.lines.find(p=>p.kind===n)).filter(n=>!!n&&K(n)),i=r.reduce((n,p)=>n+Number(p.revenue_brl),0),c=r.reduce((n,p)=>n+Number(p.target_revenue_brl),0),d=s.activity,x=[s.position&&P[s.position],...r.map(n=>
1f[n.kind])].filter(Boolean).join(" · ");return e.jsxs(N,{to:`${A}/vendedores/${s.id}`,"aria-label":`Página de ${s.name}`,className:u("group relative flex flex-col gap-6 rounded-[28px] p-5 pt-6 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40",a?"bg-primary/10 ring-1 ring-primary/30 hover:bg-primary/15":"bg-muted/60 hover:bg-muted"),children:[e.jsx("span",{"aria-hidden":!0,className:"absolute -right-2 -top-2 grid h-14 w-14 place-items-center rounded-full border border-border bg-background ring-[10px] ring-background transition-colors group-hover:bg-muted",children:e.jsx(z,{className:"h-5 w-5"})}),e.jsxs("header",{className:"grid grid-cols-[3.5rem_1fr] items-center gap-x-3 pr-12",children:[e.jsx("span",{"aria-hidden":!0,className:u("grid h-14 w-14 place-items-center rounded-full font-mono text-base font-semibold",a?"bg-primary text-primary-foreground":"bg-primary/15 text-primary"),children:s.name.slice(0,2).toUpperCase()}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"truncate text-2xl font-semibold leading-tight tracking-tight",children:[s.name,a&&e.jsx("span",{className:"ml-2 align-middle text-xs font-normal text-muted-foreground",children:"você"})]}),e.jsx("p",{className:"truncate text-sm text-muted-foreground",title:s.email,children:x||s.email})]})]}),r.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sem meta, venda ou oportunidade neste mês."}),r.map(n=>e.jsx(O,{line:n,daysPassed:t,daysTotal:o},n.kind)),d&&e.jsxs("div",{className:"grid grid-cols-5 gap-2 border-t border-border/60 pt-3",children:[e.jsx(l,{label:"WhatsApp",value:d.whatsapp_clicks}),e.jsx(l,{label:"Ligações",value:d.calls}),e.jsx(l,{label:"Notas",value:d.notes}),e.jsx(l,{label:"Feitas",value:d.tasks_done,hint:"Tarefas concluÃdas no mês"}),e.jsx(l,{label:"Vencidas",value:d.tasks_overdue,tone:d.tasks_overdue>0?"bad":void 0,hint:"Tarefas abertas com prazo vencido"})]}),e.jsx("footer",{className:"mt-auto",children:e.jsx(U,{realized:i,target:c,daysPassed:t,daysTotal:o})})]})}function F({data:s}){const{user:t}=v(),o=j.useMemo(()=>I(s),[s]),{total:a,passed:r}=s.business_days;return o.length===0?e.jsx("p",{className:"rounded-[28px] border border-dashed border-border px-4 py-6 text-center text-xs text-muted-foreground",children:"Nenhum vendedor com meta, venda ou atividade neste mês."}):e.jsx("div",{className:"grid gap-5 pt-2 md:grid-cols-2 xl:grid-cols-3",children:o.map(i=>e.jsx(V,{seller:i,daysPassed:r,daysTotal:a,isMe:i.id===(t==null?void 0:t.id)},i.id))})}function ae(){const[s,t]=_(),o=C(s.get("mes"))?s.get("mes"):S(),a=w(o),r=i=>{const c=new URLSearchParams(s);c.set("mes",i),t(c,{replace:!0})};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"Vendedores"}),e.jsxs("div",{className:"inline-flex items-center rounded-lg bg-muted p-0.5",children:[e.jsx(g,{variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":"Mês anterior",onClick:()=>r(h(o,-1)),children:e.jsx(M,{className:"h-4 w-4"})}),e.jsx("span",{className:"min-w-[10rem] text-center text-sm font-medium first-letter:uppercase",children:y(o)}),e.jsx(g,{variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":"Próximo mês",onClick:()=>r(h(o,1)),children:e.jsx(T,{className:"h-4 w-4"})})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Realizado = oportunidades convertidas no mês. Clique no card para abrir a página da pessoa."}),a.isLoading&&!a.data&&e.jsx(k,{className:"h-64 w-full rounded-[28px]"}),a.error&&e.jsxs("p",{className:"text-sm text-destructive",children:["Não deu para carregar: ",a.error.message]}),a.data&&e.jsx(F,{data:a.data})]})}export{ae as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.