PageSourceSearch

https://sentinel-365-c9d4f.web.app/assets/VeiculosList-6YtGL9AS.js

js sentinel-365-c9d4f.web.app collected 2026-10-03 12:38:17 UTC 28,864 bytes, 1 lines download raw bytes

1import{j as e,r as E}from"./react-vendor-pafHdoJx.js";import{c as ae,b as y,d as N,u as se,E as _}from"./index-Db0fDLGN.js";import{E as re}from"./EntityList-DHyuL9ql.js";import{V as O}from"./ComplianceBadges-B6KO2l0w.js";import{O as ie}from"./ObjectDrawer-DyT69DrE.js";import{A as oe}from"./AdaInline-Ct5kRNHe.js";import{C as le}from"./Comments-C_vFA2mA.js";import{A as ne}from"./ActivityFeed-DAmzN5j6.js";import{N as ce}from"./NovoVeiculoForm-CdRTU1SS.js";import{C as de}from"./ConciliacaoDoFeed-CaKlaxaz.js";import{E as ue}from"./ErrorState-B9i6eo2M.js";import{w as me,au as xe,a8 as z,W as P,F as q,K as U,v as W,al as pe}from"./ui-vendor-DLXJn6s3.js";import"./map-vendor-Dr8zbd0c.js";import"./firebase-vendor-D3UzkAhn.js";import"./ConsultaFrotaWidget-DBZvdU9H.js";import"./primitives-DOiVg4wH.js";const ve={critical:{label:"Intervir",bg:"#fef2f2",fg:"#b91c1c",dot:"#dc2626"},warning:{label:"Inspecionar",bg:"#fff7ed",fg:"#9a3412",dot:"#ea580c"},monitor:{label:"Observar",bg:"#fefce8",fg:"#854d0e",dot:"#ca8a04"},ok:{label:"Saudável",bg:"transparent",fg:"var(--page-text-muted, #94a3b8)",dot:"var(--page-text-muted, #94a3b8)"}};function ge({health:a,hideOk:s=!0,showScore:r=!1,className:u}){if(s&&a.tier==="ok")return null;const i=ve[a.tier],n=a.topReasons.length>0?a.topReasons.join(" · "):`Score ${a.score}`;return e.jsxs("span",{role:"status","aria-label":`Saúde ${i.label}: ${n}`,title:n,"data-testid":"vehicle-health-badge","data-tier":a.tier,className:ae("inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[10px] font-semibold",u),style:{background:i.bg,color:i.fg},children:[e.jsx("span",{"aria-hidden":"true",className:"inline-block h-1.5 w-1.5 rounded-full",style:{background:i.dot}}),i.label,r&&e.jsxs("span",{className:"opacity-70","data-testid":"vehicle-health-score",children:["(",a.score,")"]})]})}const h={compliance:30,maintenance:25,utilization:15,cost:15,tires:15},M={critical:70,warning:40,monitor:20},fe=2e4;function he(a){const s=[],r={compliance:0,maintenance:0,utilization:0,cost:0,tires:0},u=[{name:"CRLV",days:a.crlvDaysToExpire,weight:1},{name:"IPVA",days:a.ipvaDaysToExpire,weight:.9},{name:"Apólice",days:a.apoliceDaysToExpire,weight:.8}];for(const m of u){if(typeof m.days!="number")continue;const g=h.compliance*m.weight;if(m.days<0){const d=g;d>r.compliance&&(r.compliance=d),s.push({text:`${m.name} VENCIDO`,weight:d})}else if(m.days<=7){const d=g*.7;d>r.compliance&&(r.compliance=d),s.push({text:`${m.name} vence em ${m.days}d`,weight:d})}else if(m.days<=30){const d=g*.35;d>r.compliance&&(r.compliance=d)}}const i=a.predictiveSignals??0;i>=4?(r.maintenance=h.maintenance,s.push({text:`${i} sinais preditivos`,weight:h.maintenance})):i>=2&&(r.maintenance=h.maintenance*.6,s.push({text:`${i} sinais preditivos`,weight:r.maintenance}));const n=a.serviceIntervalKm??fe;if(typeof a.kmSinceLastService=="number"&&n>0&&a.kmSinceLastService>n){const m=a.kmSinceLastService-n,g=Math.min(1,m/n);r.utilization=h.utilization*(.5+g*.5),s.push({text:`${Math.round(m/1e3)}k km além da revisão`,weight:r.utilization})}if(typeof a.daysIdle=="number"&&a.daysIdle>=30){const m=h.utilization*.5;m>r.utilization&&(r.utilization=m),s.push({text:`Parado há ${a.daysIdle} dias`,weight:m})}if(typeof a.consumoMedioKmL=="number"&&typeof a.fleetAverageKmL=="number"&&a.fleetAverageKmL>0&&a.consumoMedioKmL>0){const m=(a.fleetAverageKmL-a.consumoMedioKmL)/a.fleetAverageKmL;m>=.2?(r.cost=h.cost,s.push({text:`Consumo ${Math.round(m*100)}% pior que frota`,weight:h.cost})):m>=.1&&(r.cost=h.cost*.5,s.push({text:`Consumo ${Math.round(m*100)}% pior`,weight:r.cost}))}if(typeof a.correctiveMaintenanceRatio=="number"&&a.correctiveMaintenanceRatio>.7){const m=h.cost*.7;m>r.cost&&(r.cost=m),s.push({text:`Manutenção corretiva ${Math.round(a.correctiveMaintenanceRatio*100)}%`,weight:m})}typeof a.tireLifePercent=="number"&&(a.tireLifePercent<=15?(r.tires=h.tires,s.push({text:`Pneus ${a.tireLifePercent}% vida útil`,weight:h.tires})):a.tireLifePercent<=30&&(r.tires=h.tires*.5,s.push({text:`Pneus ${a.tireLifePercent}% vida útil`,weight:r.tires})));const t=r.compliance+r.maintenance+r.utilization+r.cost+r.tires,c=Math.min(100,Math.round(t)),l=c>=M.critical?"critical":c>=M.warning?"warning":c>
1=M.monitor?"monitor":"ok",x=s.sort((m,g)=>g.weight-m.weight).slice(0,3).map(m=>m.text);return{score:c,tier:l,components:r,topReasons:x}}function w({label:a}){return e.jsxs("div",{className:"text-xs text-center py-8",style:{color:"var(--page-text-muted)"},children:["Carregando ",a,"…"]})}function C({icon:a,title:s,body:r}){return e.jsxs("div",{className:"text-center py-10",style:{color:"var(--page-text-muted)"},children:[e.jsx(a,{className:"w-8 h-8 mx-auto mb-3 opacity-50"}),e.jsx("p",{className:"text-sm",children:s}),r&&e.jsx("p",{className:"text-[11px] mt-1",children:r})]})}function T({message:a}){return e.jsxs("div",{className:"text-center py-8 text-sm",style:{color:"#EF4444"},children:[e.jsx(pe,{className:"w-6 h-6 mx-auto mb-2"}),"Erro ao carregar: ",a]})}function S(a){if(!a)return"—";const s=new Date(a);return isNaN(s.getTime())?"—":s.toLocaleDateString("pt-BR")}function J(a){if(!a)return"—";const s=new Date(a);return isNaN(s.getTime())?"—":s.toLocaleString("pt-BR",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}function b(a){return a==null?"—":a.toLocaleString("pt-BR",{style:"currency",currency:"BRL",maximumFractionDigits:0})}function f(a,s=0){return a==null?"—":a.toLocaleString("pt-BR",{minimumFractionDigits:s,maximumFractionDigits:s})}function je(a){if(!a)return"—";const s=Math.floor(a/3600),r=Math.floor(a%3600/60);return s>0?`${s}h${r.toString().padStart(2,"0")}`:`${r}min`}function j({label:a,value:s,sub:r}){return e.jsxs("div",{className:"rounded-lg px-3 py-2 flex-1 min-w-0",style:{background:"var(--surface-secondary)",border:"1px solid var(--border-primary)"},children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide truncate",style:{color:"var(--page-text-muted)"},children:a}),e.jsx("div",{className:"text-sm font-semibold truncate",style:{color:"var(--page-text)"},children:s}),r&&e.jsx("div",{className:"text-[10px] truncate",style:{color:"var(--page-text-muted)"},children:r})]})}const be={truck:"Caminhão",carreta:"Carreta / Cavalo",bitrem:"Bitrem",van:"Van / Furgão",utilitario:"Utilitário",reboque:"Reboque"},R={ok:"#10B981",warn:"#F59E0B",expired:"#EF4444",missing:"#9CA3AF"};function ye(a){if(!a)return{label:"não cadastrado",color:R.missing};const s=Math.ceil((new Date(a).getTime()-Date.now())/864e5);return isNaN(s)?{label:"não cadastrado",color:R.missing}:s<0?{label:`venceu ${Math.abs(s)}d atrás`,color:R.expired}:s<=30?{label:`vence em ${s}d`,color:R.warn}:{label:S(a),color:R.ok}}function Ne({vehicleId:a,onEdit:s}){const{data:r,loading:u,error:i}=y(()=>N.vehicleDetail(a),[a]),{data:n}=y(()=>N.averbacaoApolices(),[]);if(u)return e.jsx(w,{label:"dados do veículo"});if(i)return e.jsx(T,{message:i});if(!r)return e.jsx(C,{icon:me,title:"Veículo não encontrado."});const t=r,c=Date.now(),l=(n||[]).filter(d=>{if(d.tipo!=="rc_v"||d.status==="cancelada"||d.status==="inativa")return!1;if(d.vigenciaFim){const L=new Date(d.vigenciaFim).getTime();if(!isNaN(L)&&L<c)return!1}return!d.vehicleId||d.vehicleId===a}),x=l.find(d=>d.vehicleId===a),m=l.find(d=>!d.vehicleId),g=x||m;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:()=>s(t),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs hover-surface",style:{border:"1px solid var(--border-primary)",color:"var(--page-text)"},children:[e.jsx(xe,{className:"w-3 h-3"}),"Editar"]})]}),e.jsxs(k,{title:"Identificação",children:[e.jsx(v,{label:"Placa",value:t.plate,mono:!0}),e.jsx(v,{label:"Marca / Modelo",value:[t.brand,t.model].filter(Boolean).join(" ")||"—"}),e.jsx(v,{label:"Apelido",value:t.nickname||"—"}),e.jsx(v,{label:"Ano",value:t.year?String(t.year):"—"}),e.jsx(v,{label:"Cor",value:t.color||"—"}),e.jsx(v,{label:"Tipo",value:(t.vehicleType?be[t.vehicleType]||t.vehicleType:null)||"—"}),e.jsx(v,{label:"Combustível",value:t.fuel||t.fuelAcronym||"—"}),e.jsx(v,{label:"Eixos",value:t.quantidadeEixos!=null?String(t.quantidadeEixos):t.axles?String(t.axles):"—"})]}),e.jsxs(k,{title:"Hodômetro",children:[e.jsx(v,{label:"Cadastrado",value:t.currentKm?`${f(t.currentKm)} km`:"—",sub:t.lastKmUpdate?`Atualizado em ${S(t.lastKmUpdate)}`:void 0}),e.jsx(v,{label:"App do motorista",value:t.odometerFromApp?`${f(t.odometerFromApp)} km`:"—",sub:t.lastOdometerFromAppAt?`Sincronizado em ${S(t.lastOdometerFromAppAt)}`:"Sem registro do app"})]}),e.jsxs(k,{title:"Fiscal / regulatório",children:[e.jsx(v,{label:"RNTRC",value:t.rntrc||"—",mono:!0}),e.jsx(v,{label:"ANTT-TP",value:t.anttTp||"—"}),e.jsx(v,{label:"RENAVAM",value:t.renavam||"—",mono:!0}),e.jsx(v,{label:"Chassi",value:t.chassis||"—",mono:!0}),e.jsx(v,{label:"UF / Município",value:[t.uf,t.municipality].filter(
1Boolean).join(" / ")||"—"}),e.jsx(v,{label:"Tara / Capacidade",value:[t.tara&&`${f(t.tara)} kg`,t.capacidadeKg&&`${f(t.capacidadeKg)} kg`].filter(Boolean).join(" / ")||"—"})]}),e.jsx(k,{title:"Apólice RC-V (Lei 14.599/2023)",children:g?e.jsxs(e.Fragment,{children:[e.jsx(v,{label:"Cobertura",value:x?"este veículo (nomeada)":"frota toda",sub:x?void 0:"Apólice cobre todos os veículos da org"}),e.jsx(v,{label:"Seguradora",value:g.seguradora||"—"}),e.jsx(v,{label:"Número",value:g.numero||"—",mono:!0}),e.jsx(v,{label:"Vigência",value:[g.vigenciaInicio,g.vigenciaFim].filter(Boolean).map(S).join(" → ")||"—"}),e.jsx(v,{label:"Capital",value:g.limiteCobertura?b(g.limiteCobertura):"—"})]}):e.jsxs("div",{className:"text-xs",style:{color:"#D97706"},children:["⚠ Sem apólice RC-V vigente cobrindo este veículo. Lei 14.599/2023 exige RC-V ativa (nomeada ou pra frota toda) pra emissão de CIOT."," ",e.jsx("a",{href:"/configuracoes",className:"underline",children:"Cadastrar em Configurações → Apólices"}),"."]})}),e.jsxs(k,{title:"Documentos",children:[e.jsx(D,{label:"CRLV",validade:t.crlvValidade}),e.jsx(D,{label:"IPVA",validade:t.ipvaValidade}),e.jsx(D,{label:"Seguro",validade:t.seguroValidade,extra:t.seguroSeguradora||void 0}),e.jsx(D,{label:"Tacógrafo",validade:t.tacografoValidade})]}),((t.fipePriceNumeric??0)>0||t.codeFipe)&&e.jsxs(k,{title:"FIPE",children:[e.jsx(v,{label:"Código",value:t.codeFipe||"—",mono:!0}),e.jsx(v,{label:"Preço",value:t.fipePrice||(t.fipePriceNumeric?b(t.fipePriceNumeric):"—"),sub:t.fipeReferenceMonth||void 0})]}),e.jsxs(k,{title:"Manutenção (resumo)",children:[e.jsx(v,{label:"Ordens abertas",value:String(t.openWorkOrders||0),sub:`${t.totalWorkOrders||0} no total`}),e.jsx(v,{label:"Custo acumulado",value:b(t.totalMaintenanceCost||0)})]}),e.jsx(k,{title:"Motoristas vinculados",children:(t.linkedDrivers||[]).length===0?e.jsxs("div",{className:"text-sm",style:{color:"var(--page-text-muted)"},children:["Nenhum motorista com este veículo como veículo atual.",e.jsx("div",{className:"text-[10px] mt-0.5",children:"Defina no drawer do motorista (V3 → Motoristas → Resumo) para auto-atribuir viagens novas."})]}):e.jsx("div",{className:"space-y-1",children:t.linkedDrivers.map(d=>e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{style:{color:"var(--page-text)"},children:d.driverName}),d.since&&e.jsxs("span",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:["desde ",S(d.since)]})]},d.driverId))})})]})}function k({title:a,children:s}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide mb-1.5",style:{color:"var(--page-text-muted)"},children:a}),e.jsx("div",{className:"space-y-1",children:s})]})}function v({label:a,value:s,sub:r,mono:u}){return e.jsxs("div",{className:"flex items-start justify-between gap-3 text-sm",children:[e.jsx("span",{style:{color:"var(--page-text-muted)"},children:a}),e.jsxs("div",{className:"text-right min-w-0",children:[e.jsx("div",{className:u?"font-mono":"",style:{color:"var(--page-text)"},children:s}),r&&e.jsx("div",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:r})]})]})}function D({label:a,validade:s,extra:r}){const u=ye(s);return e.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"var(--page-text-muted)"},children:a}),r&&e.jsxs("span",{className:"ml-1.5 text-[10px]",style:{color:"var(--page-text-muted)"},children:["· ",r]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{background:u.color}}),e.jsx("span",{className:"text-xs",style:{color:u.color},children:u.label})]})]})}function ke({vehicleId:a}){const{data:s,loading:r,error:u}=y(()=>N.vehicleFuel(a,50),[a]);if(r)return e.jsx(w,{label:"abastecimentos"});if(u)return e.jsx(T,{message:u});if(!s||s.records.length===0)return e.jsx(C,{icon:q,title:"Sem abastecimentos registrados.",body:"Registros aparecem aqui quando o motorista abastecer pelo app ou um gestor lançar manualmente."});const{records:i,summary:n}=s;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{label:"Custo total",value:b(n.totalCost),sub:`${n.totalRecords} abast.`}),e.jsx(j,{label:"Litros",value:f(n.totalLiters,1),sub:`R$ ${f(n.avgPricePerLiter,2)}/L`}),e.jsx(j,{label:"Consumo médio",value:n.avgKmPerLiter!=null?`${f(n.avgKmPerLiter,2)} km/L`:"—",sub:n.avgKmPerLiter==null?"Sem odômetro":void 0})]}),e.jsx("div",{className:"space-y-1",children:i.map(t=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg",style:{background:"var(--surface-secondary)"},children:[e.jsx(q,{className:"w-4 h-4 shrink-0",style:{color:"#F59E0B"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-sm",style:{color:"var(--page-text)"},children:[f(t.liters,1)," L · ",b(t.totalCost)," ",e.jsxs("span",{style:{color:"var(--page-text-muted)"},children:["· R$ ",f(t.pricePerLiter,2),"/L"]})]}),e.jsxs("div",{className:"text-[10px] truncate",style:{color:"var(--page-text-muted)"},children:[J(t.date)," ",t.driverName?`· ${t.driverName}`:""," ",t.station?`· ${t.station}`:""]})]}),t.odometer&&e.jsxs("div",{className:"text-[10px] shrink-0",style:{color:"var(--page-text-muted)"},children:[f(t.odometer)," km"]})]},t.id))})]})}function Se({vehicleId:a}){const{data:s,loading:r,error:u}=y(()=>N.vehicleTrips(a,50),[a]);if(r)return e.jsx(w,{label:"viagens"});if(u)return e.jsx(T,{message:u});if(!s||s.trips.length===0)return e.jsx(C,{icon:z,title:"Sem viagens registradas.",body:"As viagens deste veículo aparecem aqui assim que um motorista vincular o app."});const{trips:i,summary:n}=s;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{label:"Viagens",value:String(n.totalTrips)}),e.jsx(j,{label:"Distância",value:`${f(n.totalDistance)} km`}),e.jsx(j,{label:"Score médio",value:n.avgScore!=null?f(n.avgScore,1):"—"})]}),e.jsx("div",{className:"space-y-1",children:i.map(t=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg",style:{background:"var(--surface-secondary)"},children:[e.jsx(z,{className:"w-4 h-4 shrink-0",style:{color:"#3B82F6"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-sm",style:{color:"var(--page-text)"},children:[f(t.distance,1)," km · ",je(t.duration),t.score>0&&e.jsxs("span",{style:{color:"var(--page-text-muted)"},children:[" · score ",f(t.score,0)]})]}),e.jsxs("div",{className:"text-[10px] truncate",style:{color:"var(--page-text-muted)"},children:[J(t.startTime)," ",t.driverName?`· ${t.driverName}`:""]})]}),t.eventCount>0&&e.jsxs("div",{className:"text-[10px] shrink-0 px-1.5 py-0.5 rounded",style:{background:"#F59E0B22",color:"#F59E0B"},children:[t.eventCount," ev"]})]},t.id))})]})}function we({vehicleId:a}){const s=y(()=>N.vehicleMaintenancePlan(a),[a]),r=y(()=>N.vehicleDetail(a),[a]);if(s.loading||r.loading)return e.jsx(w,{label:"manutenção"});if(s.error&&r.error)return e.jsx(T,{message:s.error||r.error||""});const u=s.data,i=r.data,n=(i==null?void 0:i.workOrders)||[],t=n.filter(x=>["pendente_triagem","aberta","em_andamento","aguardando_pecas"].includes(x.status)),c=((u==null?void 0:u.services)||[]).filter(x=>x.status==="vencido"),l=((u==null?void 0:u.services)||[]).filter(x=>x.status==="proximo");
1return n.length===0&&c.length===0&&l.length===0?e.jsx(C,{icon:P,title:"Tudo em dia.",body:"Sem ordens de serviço abertas nem serviços preventivos vencidos."}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{label:"OS abertas",value:String(t.length),sub:`${n.length} total`}),e.jsx(j,{label:"Preventivas vencidas",value:String(c.length)}),e.jsx(j,{label:"Custo total",value:b((i==null?void 0:i.totalMaintenanceCost)||0)})]}),c.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs font-semibold mb-2",style:{color:"#EF4444"},children:["Preventivas vencidas (",c.length,")"]}),e.jsx("div",{className:"space-y-1",children:c.slice(0,5).map(x=>e.jsx(H,{service:x,color:"#EF4444"},x.id))})]}),l.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs font-semibold mb-2",style:{color:"#F59E0B"},children:["Próximas (",l.length,")"]}),e.jsx("div",{className:"space-y-1",children:l.slice(0,5).map(x=>e.jsx(H,{service:x,color:"#F59E0B"},x.id))})]}),t.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs font-semibold mb-2",style:{color:"var(--page-text)"},children:["Ordens de serviço abertas (",t.length,")"]}),e.jsx("div",{className:"space-y-1",children:t.map(x=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg",style:{background:"var(--surface-secondary)"},children:[e.jsx(P,{className:"w-4 h-4 shrink-0",style:{color:"#F59E0B"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm truncate",style:{color:"var(--page-text)"},children:x.title||x.category||"Ordem de serviço"}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:[x.status," ",x.priority?`· ${x.priority}`:""," ",x.dueDate?`· vence ${S(x.dueDate)}`:""]})]}),x.estimatedCost>0&&e.jsx("div",{className:"text-[10px] shrink-0",style:{color:"var(--page-text-muted)"},children:b(x.estimatedCost)})]},x.id))})]})]})}function H({service:a,color:s}){var r;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg",style:{background:"var(--surface-secondary)"},children:[e.jsx(P,{className:"w-4 h-4 shrink-0",style:{color:s}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm truncate",style:{color:"var(--page-text)"},children:a.name}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:["A cada ",f(a.intervalKm)," km · ",a.severity]})]}),e.jsx("div",{className:"text-[10px] shrink-0",style:{color:"var(--page-text-muted)"},children:b(((r=a.estimatedCostBRL)==null?void 0:r.min)||0)})]})}function Ce({plate:a}){const{data:s,loading:r,error:u}=y(()=>N.tiresByVehicle(a),[a]);if(r)return e.jsx(w,{label:"pneus"});if(u)return e.jsx(T,{message:u});const i=(s==null?void 0:s.tires)||[];if(i.length===0)return e.jsx(C,{icon:U,title:"Sem pneus cadastrados.",body:"Instale pneus no estoque pelo módulo de Pneus para vê-los aqui."});const n=i.filter(c=>c.status==="em_uso"),t=n.length>0?n.reduce((c,l)=>
1c+(l.treadDepth||0),0)/n.length:0;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{label:"Instalados",value:String(n.length),sub:`${i.length} total`}),e.jsx(j,{label:"Sulco médio",value:t>0?`${f(t,1)} mm`:"—"}),(s==null?void 0:s.rotationRecommendation)&&e.jsx(j,{label:"Rodízio",value:"Recomendado",sub:s.rotationRecommendation.reason})]}),e.jsx("div",{className:"space-y-1",children:i.map(c=>{var l;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg",style:{background:"var(--surface-secondary)"},children:[e.jsx(U,{className:"w-4 h-4 shrink-0",style:{color:"#A855F7"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-sm truncate",style:{color:"var(--page-text)"},children:[c.position||"Estoque"," · ",c.brand," ",c.size]}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:[c.status," ",c.treadDepth?`· ${f(c.treadDepth,1)} mm`:""," ",c.currentKm?`· ${f(c.currentKm)} km`:""]})]}),((l=c.prediction)==null?void 0:l.estimatedRemainingKm)!=null&&e.jsxs("div",{className:"text-[10px] shrink-0",style:{color:c.prediction.estimatedRemainingKm<5e3?"#EF4444":"var(--page-text-muted)"},children:["~",f(c.prediction.estimatedRemainingKm)," km"]})]},c.id)})})]})}const G={ok:"#10B981",warn:"#F59E0B",expired:"#EF4444",missing:"#9CA3AF"},Te={ok:"Em dia",warn:"Vencendo",expired:"Vencido",missing:"Não cadastrado"};function Ee({vehicleId:a}){const{data:s,loading:r,error:u}=y(()=>N.vehicleDocuments(a),[a]);if(r)return e.jsx(w,{label:"documentos"});if(u)return e.jsx(T,{message:u});if(!s)return e.jsx(C,{icon:W,title:"Sem dados de documento."});const{documents:i,apolicesCarga:n}=s;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(A,{label:"CRLV / Licenciamento",doc:i.crlv,extra:i.crlv.numero?`RENAVAM ${i.crlv.numero}`:void 0}),e.jsx(A,{label:"ANTT (RNTRC)",doc:{status:i.antt.status,validade:null,daysToExpire:null},extra:i.antt.numero||"Não cadastrado"}),e.jsx(A,{label:"Seguro",doc:i.seguro,extra:i.seguro.seguradora?`${i.seguro.seguradora}${i.seguro.apolice?` · ${i.seguro.apolice}`:""}`:void 0}),e.jsx(A,{label:"IPVA",doc:i.ipva}),e.jsx(A,{label:"Tacógrafo",doc:i.tacografo}),n.length>0&&e.jsxs("div",{className:"pt-2 border-t",style:{borderColor:"var(--border-primary)"},children:[e.jsxs("div",{className:"text-xs font-semibold mb-2",style:{color:"var(--page-text)"},children:["Apólices de carga (",n.length,")"]}),e.jsx("div",{className:"space-y-1",children:n.map(t=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg text-sm",style:{background:"var(--surface-secondary)"},children:[e.jsx(W,{className:"w-4 h-4 shrink-0",style:{color:"#0EA5E9"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"truncate",style:{color:"var(--page-text)"},children:[t.seguradora||"Apólice"," ",t.numero?`· ${t.numero}`:""]}),e.jsxs("div",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:[t.tipo||"rctr_c"," · vence ",S(t.vigenciaFim)]})]}),(t.limiteCobertura??0)>0&&e.jsx("div",{className:"text-[10px] shrink-0",style:{color:"var(--page-text-muted)"},children:b(t.limiteCobertura)})]},t.id))})]})]})}function A({label:a,doc:s,extra:r}){const u=G[s.status]||G.missing,i=Te[s.status]||s.status;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-lg",style:{background:"var(--surface-secondary)"},children:[e.jsx("span",{className:"w-2 h-2 rounded-full shrink-0",style:{background:u}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm",style:{color:"var(--page-text)"},children:a}),r&&e.jsx("div",{className:"text-[10px] truncate",style:{color:"var(--page-text-muted)"},children:r})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("div",{className:"text-xs",style:{color:u},children:i}),s.validade&&e.jsxs("div",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:[S(s.validade),s.daysToExpire!=null&&s.daysToExpire>=0&&s.daysToExpire<=60&&` · ${s.daysToExpire}d`]})]})]})}function Ue({onNovo:a}){const{data:s,loading:r,error:u,refetch:i}=y(()=>N.vehicles(),[]),{toast:n}=se(),[t,c]=E.useState("todos"),[l,x]=E.useState(null),[m,g]=E.useState(null),d=E.useMemo(()=>(s||[]).map(p=>{const F=p.crlvVencimento||p.crlvExpiresAt,V=F?Math.ceil((new Date(F).getTime()-Date.now())/864e5):null,I=p.ipvaVencimento||p.ipvaExpiresAt,Y=I?Math.ceil((new Date(I).getTime()-Date.now())/864e5):null,K=p.seguroVencimento||p.apoliceVencimento,$=K?Math.ceil((new Date(K).getTime()-Date.now())/864e5):null,Z=V==null?"unknown":V<0?"error":V<=30?"warn":"ok",ee=(p.placa||p.plate||"—").toUpperCase(),te=he({id:p.id,crlvDaysToExpire:V,ipvaDaysToExpire:Y,apoliceDaysToExpire:$,predictiveSignals:Array.isArray(p.predictiveSignals)?p.predictiveSignals.length:p.predictiveSignals,kmSinceLastService:p.kmSinceLastService??null,daysIdle:p.daysIdle??null,consumoMedioKmL:p.consumoMedioKmL??null,correctiveMaintenanceRatio:p.correctiveMaintenanceRatio??null,tireLifePercent:p.tireLifePercent??null});return{id:p.id,placa:ee,modelo:p.modelo||p.model||"—",rntrc:p.rntrc,eixos:p.quantidadeEixos||p.eixos,tipo:p.tipo,status:p.status==="maintenance"?"manutencao":p.status==="on_trip"?"em_rota":p.status==="inactive"?"inativo":"disponivel",crlvStatus:Z,anttStatus:p.anttRegular===!1?"error":"ok",seguroStatus:p.seguroAtivo===!1?"error":$!=null&&$<=30?"warn":"ok",crlvVencimento:F,health:te}}),[s]),L=E.useMemo(()=>t==="todos"?d:t==="em_rota"?d.filter(o=>o.status==="em_rota"):t==="disponivel"?d.filter(o=>o.status==="disponivel"):t==="manutencao"?d.filter(o=>o.status==="manutencao"):t==="crlv_vencendo"?d.filter(o=>o.crlvStatus==="warn"||o.crlvStatus==="error"):t==="saude"?d.filter(o=>o.health.tier!=="ok").sort((o,p)=>p.health.score-o.health.score):d,[d,t]),X=[{key:"placa",label:"Placa",width:100,render:o=>e.jsx("span",{className:"font-mono font-bold",children:o.placa}),sortValue:o=>o.placa}
1,{key:"modelo",label:"Modelo",width:"1.5fr",render:o=>o.modelo,sortValue:o=>o.modelo},{key:"status",label:"Status",width:120,render:o=>e.jsx(Q,{status:o.status}),sortValue:o=>o.status},{key:"eixos",label:"Eixos",width:70,align:"right",render:o=>o.eixos||"—"},{key:"rntrc",label:"RNTRC",width:100,render:o=>o.rntrc||"—"},{key:"compliance",label:"Compliance",width:160,render:o=>e.jsx(O,{c:{crlv:o.crlvStatus,antt:o.anttStatus,seguro:o.seguroStatus}})},{key:"saude",label:"Saúde",width:130,render:o=>e.jsx(ge,{health:o.health}),sortValue:o=>o.health.score}],B=d.filter(o=>o.crlvStatus==="warn"||o.crlvStatus==="error").length;return u&&!r?e.jsx(_,{children:e.jsx(ue,{error:u,onRetry:i,title:"Não foi possível carregar os veículos"})}):e.jsxs(_,{children:[e.jsx(de,{eixo:"veiculos",onCadastrarItem:o=>a(o)}),e.jsx(re,{rows:L,rowKey:o=>o.id,columns:X,loading:r,filterChips:[{key:"todos",label:"Todos",active:t==="todos",onClick:()=>c("todos")},{key:"em_rota",label:"Em rota",active:t==="em_rota",onClick:()=>c("em_rota")},{key:"disponivel",label:"Disponíveis",active:t==="disponivel",onClick:()=>c("disponivel")},{key:"manutencao",label:"Em manutenção",active:t==="manutencao",onClick:()=>c("manutencao")},{key:"crlv_vencendo",label:"CRLV vencendo",active:t==="crlv_vencendo",onClick:()=>c("crlv_vencendo")},{key:"saude",label:"Por saúde",active:t==="saude",onClick:()=>c("saude")}],onRowOpen:o=>x(o),onCreate:()=>a(),createLabel:"Novo veículo",emptyTitle:"Sem veículos cadastrados.",emptyBody:"Importe via planilha ou clique em 'Novo veículo' para cadastrar manualmente.",adaCard:B>=3?e.jsx(oe,{variant:"warn",title:`${B} veículos com CRLV vencendo.`,body:"Filtre por CRLV vencendo e edite cada veículo para registrar a renovação.",actions:[{label:"Ver lista",onClick:()=>c("crlv_vencendo"),variant:"primary"}]}):void 0}),e.jsx(ie,{open:!!l,onClose:()=>x(null),title:l?`${l.placa} — ${l.modelo}`:"",subtitle:l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{status:l.status}),e.jsx(O,{c:{crlv:l.crlvStatus,antt:l.anttStatus,seguro:l.seguroStatus}})]}),tabs:[{key:"resumo",label:"Resumo",content:l&&e.jsx(Ne,{vehicleId:l.id,onEdit:g})},{key:"viagens",label:"Viagens",content:l&&e.jsx(Se,{vehicleId:l.id})},{key:"manutencao",label:"Manutenção",content:l&&e.jsx(we,{vehicleId:l.id})},{key:"combustivel",label:"Combustível",content:l&&e.jsx(ke,{vehicleId:l.id})},{key:"pneus",label:"Pneus",content:l&&e.jsx(Ce,{plate:l.placa})},{key:"documentos",label:"Documentos",content:l&&e.jsx(Ee,{vehicleId:l.id})},{key:"atividade",label:"Atividade",content:l&&e.jsx(ne,{objectType:"veiculo",objectId:l.id})},{key:"comentarios",label:"Comentários",content:l&&e.jsx(le,{objectType:"veiculo",objectId:l.id})}],size:"lg"}),m&&e.jsx(ce,{open:!0,onClose:()=>g(null),editVehicle:m,onCreated:()=>{g(null),n({title:"Veículo atualizado",kind:"success"}),i()}})]})}function Q({status:a}){const s={em_rota:{label:"Em rota",color:"#3B82F6"},disponivel:{label:"Disponível",color:"#10B981"},manutencao:{label:"Manutenção",color:"#F59E0B"},inativo:{label:"Inativo",color:"#9CA3AF"}},r=s[a]||s.disponivel;return e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full",style:{background:r.color}}),r.label]})}export{Ue as VeiculosList};

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.