1import{r as d,j as e}from"./react-vendor-pafHdoJx.js";import{b as S,d as C}from"./index-Db0fDLGN.js";import{C as w}from"./shared-DWiYwVXx.js";import{bo as F,n as B,bp as k,aG as A,G as $,bq as O,D as y,B as P}from"./ui-vendor-DLXJn6s3.js";import{L as T,E as D,c as L}from"./shared-DHvo53EK.js";import"./map-vendor-Dr8zbd0c.js";import"./firebase-vendor-D3UzkAhn.js";const q={A:"#10B981",B:"#3B82F6",C:"#F59E0B",D:"#F97316",F:"#EF4444"};function f(l){const n=new Date;return n.setDate(15),n.setMonth(n.getMonth()-l),`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}`}const z=l=>{const[n,c]=l.split("-");return`${["jan","fev","mar","abr","mai","jun","jul","ago","set","out","nov","dez"][Number(c)-1]}/${n.slice(2)}`},b=[{key:"harshBraking",label:"Frenagens bruscas",icon:F},{key:"harshAcceleration",label:"Acelerações",icon:B},{key:"harshCornering",label:"Curvas agressivas",icon:k},{key:"speeding",label:"Excesso de velocidade",icon:A},{key:"phoneUse",label:"Celular ao volante",icon:$},{key:"fatigue",label:"Fadiga",icon:O}];function V(){var g;const[l,n]=d.useState(f(0)),c=S(()=>C.connectScorecard(l,6),[l]),j=d.useMemo(()=>[0,1,2,3,4,5].map(f),[]),i=d.useMemo(()=>{var a;return(((a=c.data)==null?void 0:a.shippers)||[]).filter(s=>s.safety)},[c.data]),N=((g=c.data)==null?void 0:g.history)||{},m=d.useMemo(()=>{const a=i.filter(t=>{var r;return((r=t.safety)==null?void 0:r.score)!=null&&t.safety.tripsMonitored>0}),s=a.reduce((t,r)=>t+r.safety.tripsMonitored,0);return s===0?null:Math.round(a.reduce((t,r)=>t+r.safety.score*r.safety.tripsMonitored,0)/s*10)/10},[i]),p=d.useMemo(()=>{var s,t;const a={};for(const r of i)for(const{key:o}of b)a[o]=(a[o]||0)+(((t=(s=r.safety)==null?void 0:s.events)==null?void 0:t[o])??0);return a},[i]),x=(p.phoneUse||0)+(p.fatigue||0);return e.jsx(w,{icon:y,title:"Safety da minha frota",subtitle:"O score de direção que os embarcadores enxergam â medido pelo app, sem hardware embarcado",right:e.jsx("select",{value:l,onChange:a=>n(a.target.value),className:"text-sm rounded-lg px-2.5 py-1.5",style:{background:"var(--surface-secondary)",color:"var(--page-text)",border:"1px solid var(--border-primary)"},"aria-label":"Mês do safety",children:j.map(a=>e.jsx("option",{value:a,children:z(a)},a))}),children:c.loading&&!c.data?e.jsx(T,{}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2.5",children:[{label:"Score da frota",value:m??"â",hint:"média ponderada por viagens",color:m!=null&&m<80?"#F59E0B":"#10B981"},{label:"Eventos crÃticos",value:x,hint:"celular ao volante + fadiga",color:x>0?"#EF4444":"#10B981"},{label:"Excesso de velocidade",value:p.speeding||0,hint:"no mês, em viagens da rede",color:(p.speeding||0)>0?"#F59E0B":"#10B981"}].map(a=>e.jsx("div",{className:"rounded-xl border p-4",style:{borderColor:"var(--border-primary)",background:"var(--surface-secondary)"},children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg grid place-items-center",style:{background:`${a.color}22`},children:e.jsx(y,{size:18,style:{color:a.color}})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold tabular-nums leading-none",style:{color:"var(--page-text)"},children:a.value}),e.jsxs("p",{className:"text-xs mt-1",style:{color:"var(--page-text-secondary)"},children:[a.label," · ",a.hint]})]})]})},a.label))}),i.length===0&&e.jsx(D,{text:"Sem dados de safety neste mês â o score agrega os eventos do app dentro das viagens dos embarcadores."}),i.map(a=>{const s=a.safety,t=(N[a.networkId]||[]).map(o=>o.safetyScore),r=q[s.grade]||"#9CA3AF";return e.jsxs("div",{className:"rounded-xl border p-4",style:{borderColor:"var(--border-primary)",background:"var(--surface-secondary)"},children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:"w-11 h-11 rounded-xl grid place-items-center text-lg font-black shrink-0",style:{background:`${r}1c`,color:r,border:`1px solid ${r}40`},"aria-label":`Nota ${s.grade??"â"}`,children:s.grade??"â"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm font-bold truncate flex items-center gap-1.5",style:{color:"var(--page-text)"},children:[e.jsx(P,{size:13,style:{color:"var(--page-text-secondary)"}}),a.shipperName||a.shipperOrgId]}),e.jsxs("p",{className:"text-[11px]",style:{color:"var(--page-text-secondary)"},children:[s.tripsMonitored," viagens monitoradas · ",s.totalEvents," eventos",s.eventsPerTrip!=null?` (${s.eventsPerTrip}/viagem)`:"",s.eventsPer100Km!=null?` · ${s.eventsPer100Km}/100 km`:""]})]})]}),e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-2xl font-bold tabular-nums leading-none",style:{color:r},children:s.score??"â"}),e.jsx("p",{className:"text-[10px]",style:{color:"var(--page-text-secondary)"},children:"score do mês"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx(L,{points:t,color:r}),e.jsx("p",{className:"text-[10px]",style:{color:"var(--page-text-secondary)"},children:"Safety 6m"})]})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:b.map(({key:o,label:E,icon:M})=>{var h;const u=((h=s.events)==null?void 0:h[o])??0,v=(o==="phoneUse"||o==="fatigue")&&u>0;return e.jsxs("span",{className:"text-[11px] px-2 py-1 rounded font-medium flex items-center gap-1.5",style:{background:"var(--surface-primary)",border:"1px solid var(--border-primary)",color:"var(--page-text-secondary)"},children:[e.jsx(M,{size:11,style:{color:v?"#EF4444":"var(--page-text-secondary)"}}),E," ",e.jsx("strong",{style:{color:v?"#EF4444":"var(--page-text)"},children:u})]},o)})})]},a.networkId)}),e.jsx("p",{className:"text-[11px]",style:{color:"var(--page-text-secondary)"}
1,children:"Score 0-100: parte de 100 e desconta a penalidade média por viagem â celular ao volante e fadiga pesam mais, porque são os que mais preveem acidente. Os eventos contam só dentro das viagens da rede: a telemetria liga e desliga com a viagem. Para o coaching individual, o detalhe por motorista está em Motoristas."})]})})}export{V 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.