PageSourceSearch

https://sentinel-365-c9d4f.web.app/assets/FuelPage-ZX-NywOG.js

js sentinel-365-c9d4f.web.app collected 2026-10-03 12:38:21 UTC 29,803 bytes, 1 lines download raw bytes

1import{r as c,j as e}from"./react-vendor-pafHdoJx.js";import{b as K,d as S,u as de,j as me,k as je,a as Ne,X as H,n as Ce}from"./index-Db0fDLGN.js";import{f as F,a as we,e as ke,b as Se}from"./export-utils-BHX8wKd9.js";import{E as Pe}from"./ExportMenu-kt6fodhv.js";import{E as Le}from"./ErrorState-B9i6eo2M.js";import{E as Te}from"./EntityList-DHyuL9ql.js";import{O as Fe}from"./ObjectDrawer-DyT69DrE.js";import{N as _}from"./NumeroComBase-CssBMGes.js";import{a as A,S as W,F as $e,B as Me,T as De}from"./primitives-DOiVg4wH.js";import{L as Y,n as Ie,aP as Ae,bm as Ee,f as Re,a5 as Ve,T as Oe,F as Be,l as J,b7 as Ge,Z as ze,r as Ue,cj as Ke,a6 as Ye,g as qe,aE as _e,ae as ie,q as We,aD as ne,cF as Ze,an as Qe,au as Xe,c as He}from"./ui-vendor-DLXJn6s3.js";import{O as Je}from"./OrigemDoDado-ChhhMO_H.js";import"./map-vendor-Dr8zbd0c.js";import"./firebase-vendor-D3UzkAhn.js";function et({data:d}){if(!d.length)return null;const y=d.map(n=>n.avgPricePerLiter),C=Math.min(...y)*.98,f=Math.max(...y)*1.02-C||1,w=100,v=48,i=d.map((n,m)=>({x:m/Math.max(d.length-1,1)*w,y:v-(n.avgPricePerLiter-C)/f*v})),$=i.map((n,m)=>`${m===0?"M":"L"}${n.x.toFixed(1)},${n.y.toFixed(1)}`).join(" "),I=`${$} L${w},${v} L0,${v} Z`,l=y[y.length-1]>y[0];return e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{viewBox:`0 0 ${w} ${v+4}`,className:"w-full h-32",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"fuelGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:l?"#ef4444":"#22c55e",stopOpacity:"0.3"}),e.jsx("stop",{offset:"100%",stopColor:l?"#ef4444":"#22c55e",stopOpacity:"0"})]})}),e.jsx("path",{d:I,fill:"url(#fuelGrad)"}),e.jsx("path",{d:$,fill:"none",stroke:l?"#ef4444":"#22c55e",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),i.map((n,m)=>e.jsx("circle",{cx:n.x,cy:n.y,r:"2.5",fill:l?"#ef4444":"#22c55e",stroke:"white",strokeWidth:"1"},m))]}),e.jsx("div",{className:"flex justify-between text-[10px] px-1 -mt-1",style:{color:"var(--page-text-muted)"},children:d.map((n,m)=>m===0||m===d.length-1?e.jsx("span",{children:n.week.slice(5)},m):e.jsx("span",{},m))})]})}function tt(){const{data:d,loading:y}=K(()=>S.fuelIntelligence(),[]),[C,E]=c.useState(!1);if(y)return e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(Y,{className:"w-6 h-6 animate-spin",style:{color:"var(--accent-brand)"}})});if(!(d!=null&&d.summary))return null;const{weeklyTrend:f,driverRanking:w,anomalies:v,summary:i}=d,$=i.priceChangePercent>0,I=i.priceChangePercent>0?Ie:i.priceChangePercent<0?Ae:Ee;return e.jsxs("div",{className:"space-y-4 mt-6",children:[e.jsxs("h2",{className:"text-sm font-semibold uppercase tracking-wider flex items-center gap-2",style:{color:"var(--page-text-muted)"},children:[e.jsx(Re,{className:"w-4 h-4"})," Inteligência de Combustível"]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Ve,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Preço Médio/L"})]}),e.jsxs("p",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:["R$ ",i.avgPricePerLiter.toFixed(2)]}),e.jsxs("div",{className:`flex items-center gap-1 mt-1 text-xs font-medium ${$?"text-red-500":"text-green-500"}`,children:[e.jsx(I,{className:"w-3 h-3"}),Math.abs(i.priceChangePercent).toFixed(1),"% em 6 semanas"]})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Oe,{className:"w-4 h-4 text-green-500"}),e.jsx("span",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Economia Potencial"})]}),e.jsxs("p",{className:"text-xl font-bold text-green-600",children:["R$ ",i.potentialSavings.toLocaleString("pt-BR",{minimumFractionDigits:0})]}),e.jsx("p",{className:"text-[10px] mt-1",style:{color:"var(--page-text-muted)"},children:"Se todos pagassem como o melhor motorista"})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Be,{className:"w-4 h-4 text-amber-500"}),e.jsx("span",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Total 6 Semanas"})]}),e.jsxs("p",{className:"text-xl font-bold",style:{color:"var(--page-text)"}
1,children:[i.totalLiters.toLocaleString("pt-BR")," L"]}),e.jsxs("p",{className:"text-[10px] mt-1",style:{color:"var(--page-text-muted)"},children:[i.totalRecords," abastecimentos"]})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(J,{className:"w-4 h-4 text-red-500"}),e.jsx("span",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Anomalias"})]}),e.jsx("p",{className:"text-xl font-bold",style:{color:i.anomalyCount>0?"#ef4444":"var(--page-text)"},children:i.anomalyCount}),e.jsx("p",{className:"text-[10px] mt-1",style:{color:"var(--page-text-muted)"},children:"Acima de 1,5σ da média"})]})]}),f.length>1&&e.jsxs("div",{className:"card p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:"Tendência de Preço — Diesel (R$/L)"}),e.jsx("div",{className:"flex items-center gap-2",children:f.map((l,n)=>e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-[10px] font-bold",style:{color:"var(--page-text)"},children:["R$ ",l.avgPricePerLiter.toFixed(2)]}),e.jsxs("p",{className:"text-[8px]",style:{color:"var(--page-text-muted)"},children:[l.count," abast."]})]},n))})]}),e.jsx(et,{data:f})]}),w.length>1&&e.jsxs("div",{className:"card p-4",children:[e.jsxs("button",{onClick:()=>E(!C),className:"w-full flex items-center justify-between text-sm font-semibold",style:{color:"var(--page-text)"},children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ge,{className:"w-4 h-4 text-amber-500"})," Ranking: Quem Paga Menos por Litro"]}),e.jsx("span",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:C?"Ocultar":"Ver ranking"})]}),C&&e.jsx("div",{className:"mt-3 space-y-2",children:w.slice(0,8).map((l,n)=>e.jsxs("div",{className:"flex items-center gap-3 py-2 border-b last:border-0",style:{borderColor:"var(--border-primary)"},children:[e.jsx("span",{className:`w-6 h-6 rounded-full flex items-center justify-center text-xs font-bold text-white ${n===0?"bg-amber-500":n===1?"bg-slate-400":n===2?"bg-amber-700":"bg-slate-600"}`,children:n+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",style:{color:"var(--page-text)"},children:l.driverName}),e.jsxs("p",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:[l.count," abast. · ",l.totalLiters,"L"]})]}),e.jsxs("p",{className:"text-sm font-bold",style:{color:n<3?"#22c55e":"var(--page-text)"},children:["R$ ",l.avgPricePerLiter.toFixed(2),"/L"]})]},l.driverId))})]}),v.length>0&&e.jsxs("div",{className:"card p-4 border-red-500/20",style:{borderColor:"rgba(239,68,68,0.2)"},children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2 mb-3",style:{color:"#ef4444"},children:[e.jsx(J,{className:"w-4 h-4"})," Abastecimentos Acima da Média"]}),e.jsx("div",{className:"space-y-2",children:v.slice(0,5).map(l=>e.jsxs("div",{className:"flex items-center justify-between py-1.5 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",style:{color:"var(--page-text)"},children:l.driverName}),e.jsx("span",{className:"mx-1",style:{color:"var(--page-text-muted)"},children:"·"}),e.jsxs("span",{style:{color:"var(--page-text-muted)"},children:[l.vehiclePlate," · ",l.station]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("span",{className:"font-bold text-red-500",children:["R$ ",l.pricePerLiter.toFixed(2),"/L"]}),e.jsxs("span",{className:"ml-1 px-1.5 py-0.5 rounded bg-red-500/10 text-red-500 text-[10px] font-medium",children:["+",l.deviation,"%"]})]})]},l.id))})]})]})}const z="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium disabled:opacity-50",Z={border:"1px solid var(--border-primary)",color:"var(--page-text)"};function st({isAdmin:d,onSyncComplete:y}){const[C,E]=c.useState(!1),[f,w]=c.useState(!1),[v,i]=c.useState(!1),[$,I]=c.useState(!1),[l,n]=c.useState(!1),[m,R]=c.useState(null),[M,D]=c.useState({clientId:"",clientSecret:"",contract:""}),{toast:j}=de(),{confirmar:B}=me(),{data:x,refetch:r}=K(()=>S.veloeStatus().catch(()=>({configured:!1})),[]),U=c.useCallback(async()=>{I(!0);try{const o=await S.veloeTestConnection();j({title:o.success?"Conexão Veloe OK":"A conexão Veloe falhou",description:o.message,kind:o.success?"success":"error"})}catch(o){j({title:"Não consegui testar a conexão",description:o==null?void 0:o.message,kind:"error"})}finally{I(!1)}},[j]),Q=c.useCallback(async()=>
1{if(!M.clientId||!M.clientSecret||!M.contract){j({title:"Preencha os três campos",kind:"warning"});return}n(!0);try{await S.veloeSaveConfig(M),w(!1),D({clientId:"",clientSecret:"",contract:""}),j({title:"Credenciais Veloe salvas",kind:"success"}),r()}catch(o){j({title:"Não consegui salvar",description:o==null?void 0:o.message,kind:"error"})}finally{n(!1)}},[M,r,j]),V=c.useCallback(async o=>{i(!0),R(null);try{const b=await S.veloeSync(o);R(b),y(),r()}catch(b){j({title:"A sincronização falhou",description:b==null?void 0:b.message,kind:"error"})}finally{i(!1)}},[y,r,j]),G=async()=>{if(await B({titulo:"Remover a integração Veloe Go?",descricao:"As credenciais são apagadas. Os abastecimentos já importados ficam.",confirmar:"Remover integração"}))try{await S.veloeDeleteConfig(),j({title:"Integração Veloe removida",kind:"success"}),r()}catch(o){j({title:"Não consegui remover",description:o==null?void 0:o.message,kind:"error"})}},k=!!(x!=null&&x.configured),s=x==null?void 0:x.analytics;return e.jsxs("section",{className:"rounded-xl overflow-hidden",style:{border:"1px solid var(--border-primary)"},"aria-label":"Integração Veloe Go",children:[e.jsxs("button",{type:"button",onClick:()=>E(o=>!o),"aria-expanded":C,className:"w-full flex items-center gap-3 p-3 text-left hover-surface",children:[e.jsx(ze,{className:"w-4 h-4 shrink-0",style:{color:"#7C3AED"},"aria-hidden":"true"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:"Veloe Go"}),e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-semibold",style:k?{background:"rgba(5,150,105,0.12)",color:"#059669"}:{background:"var(--surface-secondary)",color:"var(--page-text-muted)"},children:k?"Conectado":"Não configurado"})]}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:k?`${(x==null?void 0:x.totalRecords)||0} abastecimentos importados do cartão`:"Importe abastecimentos do cartão Veloe/Alelo automaticamente"})]}),k&&(s==null?void 0:s.deviationAlerts)>0&&e.jsxs("span",{className:"text-xs inline-flex items-center gap-1",style:{color:"#DC2626"},children:[e.jsx(J,{className:"w-3 h-3","aria-hidden":"true"}),s.deviationAlerts," desvios"]}),e.jsx(Ue,{className:`w-4 h-4 shrink-0 transition-transform ${C?"rotate-180":""}`,style:{color:"var(--page-text-muted)"},"aria-hidden":"true"})]}),C&&e.jsxs("div",{className:"p-4 space-y-4",style:{borderTop:"1px solid var(--border-primary)"},children:[k&&s&&(x==null?void 0:x.totalRecords)>0&&e.jsx("dl",{className:"grid grid-cols-2 md:grid-cols-5 gap-2 text-center",children:[["km/L real",s.avgConsumption||"—"],["Custo/km",s.avgCostPerKm>0?`R$ ${s.avgCostPerKm.toFixed(2)}`:"—"],["km total",Number(s.totalKm||0).toLocaleString("pt-BR")],["Desvio de rendimento",`${s.avgDeviation>0?"+":""}${s.avgDeviation}%`],["Alertas de desvio",s.deviationAlerts]].map(([o,b])=>e.jsxs("div",{className:"rounded-lg p-2",style:{background:"var(--surface-secondary)"},children:[e.jsx("dd",{className:"text-base font-bold tabular-nums",style:{color:"var(--page-text)"},children:b}),e.jsx("dt",{className:"text-[10px]",style:{color:"var(--page-text-muted)"},children:o})]},String(o)))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[k&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>V(30),disabled:v,className:`${z} text-white`,style:{background:"#7C3AED"},children:[v?e.jsx(Y,{className:"w-3.5 h-3.5 animate-spin","aria-hidden":"true"}):e.jsx(Ke,{className:"w-3.5 h-3.5","aria-hidden":"true"})," Sincronizar 30 dias"]}),e.jsx("button",{type:"button",onClick:()=>V(90),disabled:v,className:z,style:Z,children:"90 dias"}),e.jsxs("button",{type:"button",onClick:U,disabled:$,className:z,style:Z,children:[$?e.jsx(Y,{className:"w-3.5 h-3.5 animate-spin","aria-hidden":"true"}):e.jsx(Ye,{className:"w-3.5 h-3.5","aria-hidden":"true"})," Testar"]})]}),d&&e.jsxs("button",{type:"button",onClick:()=>w(o=>!o),className:z,style:Z,children:[e.jsx(qe,{className:"w-3.5 h-3.5","aria-hidden":"true"})," ",k?"Reconfigurar":"Configurar Veloe Go"]}),k&&d&&e.jsxs("button",{type:"button",onClick:G,className:`${z} ml-auto`,style:{color:"#DC2626"},children:[e.jsx(_e,{className:"w-3.5 h-3.5","aria-hidden":"true"})," Remover"]})]}),m&&e.jsxs("div",{className:"rounded-lg p-3 text-xs space-y-0.5",style:{border:"1px solid rgba(5,150,105,0.35)",background:"rgba(5,150,105,0.06)",color:"var(--page-text)"},role:"status",children:[e.jsxs("p",{className:"font-semibold inline-flex items-center gap-1",style:{color:"#059669"},children:[e.jsx(ie,{className:"w-3.5 h-3.5","aria-hidden":"true"})," Sincronização concluída"]}),e.jsxs("p",{children:[m.totalFromVeloe," transações · ",m.created," novas · ",m.updated," atualizadas"]}),e.jsxs("p",{style:{color:"var(--page-text-muted)"},children:[m.plates," placas · ",m.period]})]}),(x==null?void 0:x.lastSyncError)&&e.jsxs("div",{className:"rounded-lg p-3 text-xs",style:{border:"1px solid rgba(220,38,38,0.35)",background:"rgba(220,38,38,0.06)"},role:"alert",children:[e.jsx("p",{className:"font-semibold",style:{color:"#DC2626"},children:"A última sincronização falhou"}),e.jsx("p",{style:{color:"var(--page-text-muted)"},children:x.lastSyncError})]}),f&&d&&e.jsxs("div",{className:"rounded-lg p-4 space-y-3",style:{background:"var(--surface-secondary)",border:"1px solid var(--border-primary)"},children:[e.jsxs("h4",{className:"text-sm font-semibold inline-flex items-center gap-2",style:{color:"var(--page-text)"},children:[e.jsx(We,{className:"w-4 h-4",style:{color:"#7C3AED"},"aria-hidden":"true"})," Credenciais Veloe Go (Alelo)"]}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Peça à Alelo os três valores: Client ID, Client Secret e o número do contrato."}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsx(A,{label:"Client ID",value:M.clientId,onChange:o=>D(b=>({...b,clientId:o}))}),e.jsx(A,{label:"Client Secret",type:"password",value:M.clientSecret,onChange:o=>D(b=>({...b,clientSecret:o}))}),e.jsx(A,{label:"Nº do contrato",value:M.contract,onChange:o=>D(b=>({...b,contract:o})),inputMode:"numeric"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",onClick:Q,disabled:l,className:`${z} text-white`,style:{background:"#7C3AED"},children:[l?e.jsx(Y,{className:"w-3.5 h-3.5 animate-spin","aria-hidden":"true"}):e.jsx(ie,{className:"w-3.5 h-3.5","aria-hidden":"true"})," Salvar"]}),e.jsx("button",{type:"button",onClick:()=>w(!1),className:z,style:Z,children:"Cancelar"})]})]}),!k&&!f&&e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Conecte a conta Veloe Go para importar transações com hodômetro, média de consumo, custo por km e detecção de desvio de rendimento."})]})]})}const at=["Gasolina","Etanol","Diesel","Diesel S10","GNV"],ce={driverId:"",vehiclePlate:"",date:new Date().toISOString().slice(0,16),fuelType:"",liters:"",totalCost:"",pricePerLiter:"",odometer:"",station:"",fullTank:!1,notes:""};function vt(){var oe;const d=je("abastecimento"),{role:y,orgName:C,user:E}=Ne(),{toast:f}
1=de(),{confirmar:w}=me(),v=y==="fleet_admin"||y==="super_admin",{data:i,loading:$,error:I,refetch:l}=K(()=>S.fuel({limit:500}),[]),{data:n}=K(()=>S.drivers().catch(()=>[]),[]),{data:m}=K(()=>S.vehicles().catch(()=>[]),[]),[R,M]=c.useState(""),[D,j]=c.useState(""),[B,x]=c.useState(""),[r,U]=c.useState(null),[Q,V]=c.useState(!1),[G,k]=c.useState(null),[s,o]=c.useState(ce),[b,ee]=c.useState(!1),P=c.useMemo(()=>(i||[]).filter(a=>{if(D&&a.driverId!==D||B&&a.fuelType!==B)return!1;if(R){const g=R.toLowerCase();if(![a.driverName,a.station,a.fuelType,a.notes,a.vehiclePlate].some(u=>u==null?void 0:u.toLowerCase().includes(g)))return!1}return!0}),[i,D,B,R]),p=c.useMemo(()=>{const t=P.reduce((h,T)=>h+(T.liters||0),0),a=P.reduce((h,T)=>h+(T.totalCost||0),0),g=P.filter(h=>(h.pricePerLiter||0)>0),u=g.length?g.reduce((h,T)=>h+(T.pricePerLiter||0),0)/g.length:null,N=new Date,O=(h,T,ye)=>h.getMonth()===T&&h.getFullYear()===ye,re=new Date(N.getFullYear(),N.getMonth()-1,1),le=P.filter(h=>O(new Date(h.date),N.getMonth(),N.getFullYear())).reduce((h,T)=>h+(T.totalCost||0),0),X=P.filter(h=>O(new Date(h.date),re.getMonth(),re.getFullYear())).reduce((h,T)=>h+(T.totalCost||0),0),fe=X>0?(le-X)/X*100:null;return{registros:P.length,litros:t,custo:a,precoMedio:u,comPreco:g.length,tendencia:fe,custoMes:le}},[P]),xe=c.useMemo(()=>Array.from(new Set((i||[]).map(t=>t.fuelType).filter(Boolean))).sort(),[i]),pe=c.useMemo(()=>{const t=new Map;return(i||[]).forEach(a=>{a.driverId&&!t.has(a.driverId)&&t.set(a.driverId,a.driverName||"Motorista")}),Array.from(t.entries()).sort((a,g)=>
1a[1].localeCompare(g[1]))},[i]),ue=c.useMemo(()=>[{key:"motorista",label:"Motorista",width:"1.2fr",render:t=>t.driverName||"Motorista",sortValue:t=>t.driverName||""},{key:"data",label:"Data",width:100,render:t=>H(t.date),sortValue:t=>t.date},{key:"combustivel",label:"Combustível",width:100,render:t=>t.fuelType||"—",sortValue:t=>t.fuelType||""},{key:"litros",label:"Litros",width:80,align:"right",render:t=>{var a;return e.jsx("span",{className:"tabular-nums",children:((a=t.liters)==null?void 0:a.toFixed(1))??"—"})},sortValue:t=>t.liters||0},{key:"preco",label:"R$/L",width:90,align:"right",render:t=>e.jsx("span",{className:"tabular-nums",style:{color:"var(--page-text-secondary)"},children:t.pricePerLiter?F(t.pricePerLiter):"—"}),sortValue:t=>t.pricePerLiter||0},{key:"total",label:"Total",width:110,align:"right",render:t=>e.jsx("span",{className:"tabular-nums font-semibold",style:{color:"#059669"},children:t.totalCost?F(t.totalCost):"—"}),sortValue:t=>t.totalCost||0},{key:"km",label:"Km",width:90,align:"right",render:t=>e.jsx("span",{className:"tabular-nums",children:t.odometer?t.odometer.toLocaleString("pt-BR"):"—"}),sortValue:t=>t.odometer||0},{key:"posto",label:"Posto",width:"1fr",render:t=>e.jsxs("span",{children:[t.station||"—",t.vehiclePlate&&e.jsx("span",{className:"ml-1.5 font-mono text-[11px]",style:{color:"var(--page-text-muted)"},children:t.vehiclePlate})]}),sortValue:t=>t.station||""},{key:"origem",label:"Origem",width:90,render:t=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px]",style:{color:"var(--page-text-muted)"},children:[t.source==="manual"?"manual":"app",t.photoUrl&&e.jsx(ne,{className:"w-3.5 h-3.5","aria-label":"com comprovante"}),t.notes&&e.jsx(Ze,{className:"w-3.5 h-3.5","aria-label":"com observação"})]})}],[]),L=(t,a)=>{o(g=>{const u={...g,[t]:a};if((t==="liters"||t==="totalCost")&&u.liters&&u.totalCost){const N=parseFloat(u.liters),O=parseFloat(u.totalCost);N>0&&O>0&&(u.pricePerLiter=(O/N).toFixed(3))}if(t==="pricePerLiter"&&u.liters&&a){const N=parseFloat(u.liters),O=parseFloat(a);N>0&&O>0&&(u.totalCost=(N*O).toFixed(2))}return u})},he=()=>{k(null),o(ce),V(!0)},ge=t=>{var a,g,u,N;k(t.id),o({driverId:t.driverId||"",vehiclePlate:t.vehiclePlate||"",date:t.date?new Date(t.date).toISOString().slice(0,16):"",fuelType:t.fuelType||"",liters:((a=t.liters)==null?void 0:a.toString())||"",totalCost:((g=t.totalCost)==null?void 0:g.toString())||"",pricePerLiter:((u=t.pricePerLiter)==null?void 0:u.toString())||"",odometer:((N=t.odometer)==null?void 0:N.toString())||"",station:t.station||"",fullTank:!!t.fullTank,notes:t.notes||""}),V(!0)},ve=async()=>{if(!s.driverId||!s.date||!s.liters||!s.totalCost){f({title:"Motorista, data, litros e valor total são obrigatórios",kind:"warning"});return}ee(!0);try{const t={driverId:s.driverId,vehiclePlate:s.vehiclePlate||null,date:new Date(s.date).toISOString(),fuelType:s.fuelType||null,liters:parseFloat(s.liters),totalCost:parseFloat(s.totalCost),pricePerLiter:s.pricePerLiter?parseFloat(s.pricePerLiter):void 0,odometer:s.odometer?parseInt(s.odometer):void 0,station:s.station||null,fullTank:s.fullTank,notes:s.notes||null};G?await S.updateFuel(G,t):await S.createFuel(t),V(!1),U(null),f({title:G?"Abastecimento atualizado":"Abastecimento registrado",kind:"success"}),l()}catch(t){f({title:"Não consegui salvar",description:(t==null?void 0:t.message)||"Tente novamente.",kind:"error"})}finally{ee(!1)}},be=async t=>{var a;if(await w({titulo:"Excluir este abastecimento?",descricao:`${t.driverName||"Motorista"} · ${H(t.date)} · ${((a=t.liters)==null?void 0:a.toFixed(1))??"—"} L · ${F(t.totalCost||0)}. Não dá para desfazer.`,confirmar:"Excluir"}))try{await S.deleteFuel(t.id),f({title:"Abastecimento excluído",kind:"success"}),U(null),l()}catch(g){f({title:"Não consegui excluir",description:g==null?void 0:g.message,kind:"error"})}},te=["Motorista","Data","Combustível","Litros","Valor Total","Preço/L","Km","Posto"],se=()=>P.map(t=>{var a;return[t.driverName||"—",Se(t.date),t.fuelType||"—",((a=t.liters)==null?void 0:a.toFixed(1))??"—",F(t.totalCost),F(t.pricePerLiter),t.odometer??t.currentKm??"—",t.station||"—"]}
1);if(I&&!$)return e.jsx(Le,{error:I,onRetry:l,title:"Não foi possível carregar os abastecimentos"});const q=!!(R||D||B),ae=`${q?"no filtro":"últimos 500"} · app e cadastro manual`;return e.jsxs("div",{className:"space-y-5 max-w-7xl",children:[d.modo==="conectado"&&e.jsx(Je,{origem:d.origem,mesmoConectado:d.mesmoConectado}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[e.jsx(_,{rotulo:"Abastecimentos",valor:p.registros,base:ae}),e.jsx(_,{rotulo:"Litros",valor:`${p.litros.toFixed(0)} L`,base:ae}),e.jsx(_,{rotulo:"Custo",valor:F(p.custo),base:p.tendencia==null?"sem mês anterior para comparar":`${p.tendencia>0?"+":""}${p.tendencia.toFixed(0)}% no mês vs. o anterior`,tom:p.tendencia!=null&&p.tendencia>10?"atencao":"neutro"}),e.jsx(_,{rotulo:"Preço médio por litro",valor:p.precoMedio==null?"—":F(p.precoMedio),base:p.comPreco?`${p.comPreco} abastecimento${p.comPreco===1?"":"s"} com preço`:"nenhum abastecimento informa o preço"})]}),e.jsx(tt,{}),e.jsx(st,{isAdmin:v,onSyncComplete:l}),e.jsxs("div",{className:"flex items-end gap-2 flex-wrap",children:[e.jsxs("label",{className:"relative flex-1 min-w-[220px]",children:[e.jsx(Qe,{className:"w-4 h-4 absolute left-3 top-[30px]",style:{color:"var(--page-text-muted)"},"aria-hidden":"true"}),e.jsx("span",{className:"block text-[10px] mb-1",style:{color:"var(--page-text-muted)"},children:"Buscar"}),e.jsx("input",{value:R,onChange:t=>M(t.target.value),placeholder:"Motorista, posto, placa, observação","aria-label":"Buscar abastecimentos",className:"w-full pl-9 pr-3 py-1.5 rounded-lg text-sm",style:{background:"var(--surface-primary)",color:"var(--page-text)",border:"1px solid var(--border-primary)"}})]}),e.jsx("div",{className:"w-56",children:e.jsx(W,{label:"Motorista",value:D,onChange:j,options:[{value:"",label:"Todos os motoristas"},...pe.map(([t,a])=>({value:t,label:a}))]})}),e.jsx(Pe,{onExportExcel:()=>ke({filename:`combustivel-${new Date().toISOString().slice(0,10)}`,sheetName:"Combustível",headers:te,rows:se()}),onExportPdf:()=>we({filename:`combustivel-${new Date().toISOString().slice(0,10)}`,title:"Relatório de Abastecimentos",subtitle:`${P.length} registros${q?" (filtrado)":""}`,orgName:C||void 0,headers:te,rows:se(),kpis:[{label:"Registros",value:p.registros},{label:"Litros",value:`${p.litros.toFixed(0)} L`},{label:"Custo",value:F(p.custo)},{label:"Preço médio/L",value:p.precoMedio==null?"—":F(p.precoMedio)}],generatedBy:(E==null?void 0:E.email)||void 0}),disabled:!P.length})]}),e.jsx(Te,{rows:P,rowKey:t=>t.id,columns:ue,loading:$&&!i,filterChips:[{key:"",label:"Todos"},...xe.map(t=>({key:t,label:t}))].map(t=>({key:t.key||"todos",label:t.label,active:B===t.key,onClick:()=>x(t.key)})),onRowOpen:U,onCreate:v&&d.podeCriar?he:void 0,createLabel:"Novo abastecimento",emptyTitle:q?"Nenhum abastecimento com esses filtros.":"Nenhum abastecimento registrado.",emptyBody:q?"Ajuste a busca ou as pílulas.":"Os registros chegam do app do motorista ou do cadastro manual."}),e.jsx(Fe,{open:!!r,onClose:()=>U(null),title:r?`${r.driverName||"Motorista"} · ${H(r.date)}`:"",subtitle:r&&e.jsxs("span",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:[r.fuelType||"combustível não informado"," · ",r.source==="manual"?"cadastro manual":"app do motorista"]}),actions:r&&v&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>ge(r),className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-lg text-xs font-semibold",style:{border:"1px solid var(--border-primary)",color:"var(--page-text)"},children:[e.jsx(Xe,{className:"w-3.5 h-3.5","aria-hidden":"true"})," Editar"]}),e.jsxs("button",{type:"button",onClick:()=>be(r),className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-lg text-xs font-semibold",style:{border:"1px solid var(--border-primary)",color:"#DC2626"},"aria-label":"Excluir abastecimento",children:[e.jsx(He,{className:"w-3.5 h-3.5","aria-hidden":"true"})," Excluir"]})]}),tabs:[{key:"resumo",label:"Resumo",content:r&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3 text-sm",children:[["Quando",Ce(r.date)],["Veículo",r.vehiclePlate||"—"],["Litros",((oe=r.liters)==null?void 0:oe.toFixed(1))??"—"],["Preço por litro",r.pricePerLiter?F(r.pricePerLiter):"—"],["Valor total",r.totalCost?F(r.totalCost):"—"],["Odômetro",r.odometer?`${r.odometer.toLocaleStr
1ing("pt-BR")} km`:"—"],["Posto",r.station||"—"],["Tanque cheio",r.fullTank?"sim":"não"],["Observações",r.notes||"—"]].map(([t,a])=>e.jsxs("div",{className:t==="Observações"?"col-span-2":"",children:[e.jsx("dt",{className:"text-[11px] uppercase tracking-wide",style:{color:"var(--page-text-muted)"},children:t}),e.jsx("dd",{style:{color:"var(--page-text)"},children:a})]},String(t)))}),r.photoUrl&&(r.photoUrl.startsWith("http")?e.jsx("a",{href:r.photoUrl,target:"_blank",rel:"noopener noreferrer",className:"block",children:e.jsx("img",{src:r.photoUrl,alt:"Comprovante do abastecimento",className:"rounded-lg max-h-64 object-contain",style:{border:"1px solid var(--border-primary)"}})}):e.jsxs("p",{className:"text-xs inline-flex items-center gap-1.5",style:{color:"var(--page-text-muted)"},children:[e.jsx(ne,{className:"w-3.5 h-3.5","aria-hidden":"true"})," Comprovante ainda no aparelho do motorista — sobe quando o app sincronizar."]}))]})}]}),e.jsx($e,{open:Q,onClose:()=>V(!1),title:G?"Editar abastecimento":"Novo abastecimento",footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>V(!1),className:"px-3 py-2 rounded-lg text-sm hover-surface",style:{color:"var(--page-text)"},children:"Cancelar"}),e.jsxs("button",{type:"button",onClick:ve,disabled:b,className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-lg text-sm font-semibold text-white disabled:opacity-60",style:{background:"#F59E0B"},children:[b&&e.jsx(Y,{className:"w-4 h-4 animate-spin","aria-hidden":"true"})," ",G?"Salvar":"Cadastrar"]})]}),children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(W,{label:"Motorista *",value:s.driverId,onChange:t=>L("driverId",t),options:[{value:"",label:"Selecione…"},...(n||[]).map(t=>({value:t.driverId,label:t.name}))]}),e.jsx(W,{label:"Veículo",value:s.vehiclePlate,onChange:t=>L("vehiclePlate",t),options:[{value:"",label:"Selecione…"},...(m||[]).map(t=>({value:t.plate,label:`${t.plate} — ${t.brand||""} ${t.model||""}`.trim()}))]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(A,{label:"Data e hora *",type:"datetime-local",value:s.date,onChange:t=>L("date",t)}),e.jsx(W,{label:"Combustível",value:s.fuelType,onChange:t=>L("fuelType",t),options:[{value:"",label:"Selecione…"},...at.map(t=>({value:t,label:t}))]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(A,{label:"Litros *",type:"number",inputMode:"decimal",value:s.liters,onChange:t=>L("liters",t),placeholder:"0.0"}),e.jsx(A,{label:"R$ por litro",type:"number",inputMode:"decimal",value:s.pricePerLiter,onChange:t=>L("pricePerLiter",t),placeholder:"0.000",hint:"calculado dos outros dois"}),e.jsx(A,{label:"Valor total *",type:"number",inputMode:"decimal",value:s.totalCost,onChange:t=>L("totalCost",t),placeholder:"0.00"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(A,{label:"Odômetro (km)",type:"number",inputMode:"numeric",value:s.odometer,onChange:t=>L("odometer",t),placeholder:"45230"}),e.jsx(A,{label:"Posto",value:s.station,onChange:t=>L("station",t),placeholder:"Nome do posto"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm",style:{color:"var(--page-text)"},children:"Tanque cheio"}),e.jsx(Me,{value:s.fullTank,onChange:t=>L("fullTank",t)})]}),e.jsx(De,{label:"Observações",value:s.notes,onChange:t=>L("notes",t)})]})})]})}export{vt as FuelPage};

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.