1import{u as pt,j as e,g as de,bH as ye,bG as me,bb as Re,bJ as ut,bX as mt}from"./index-D_txwql1.js";import{u as se,a as g}from"./i18n-vendor-DYmPQ2cw.js";import{g as Qe,b as Ze,c as xt}from"./fleetLogsApi-BGLDgrAK.js";import{g as xe}from"./StaffLayout-BFoWGoLl.js";import{C as Z,E as ze,L as ft,F as ue,i as ce,P as ke,b as ge,a as Ce,T as et,c as he}from"./VehicleShared-CLEzS6na.js";import{i as tt,b as Se,d as Ee,j as gt,F as Te,f as Ie,v as We,g as ht,k as vt,l as yt,p as nt,m as at,n as bt,e as Ke,c as jt,w as ve,o as it,G as kt,q as St,r as we,t as Ct,u as Ft,x as rt,s as Ne,y as Ae,z as Be,A as Bt,B as Dt,h as Et,C as De,D as Pe,E as wt,H as At,I as Rt,a as Tt}from"./vehicleFlows-CbxaRnOW.js";import{u as Le}from"./useFleetActivity-DZMqlEiq.js";import{k as _t}from"./fleetActivityView-BFO9cgmP.js";import{S as Fe,L as zt,V as $e}from"./VehicleBlueprint-CKyXYd84.js";import{f as Me,c as _e,d as Nt,D as He,s as Kt,a as Lt,b as ot,p as It}from"./damageFlags-CdFK-mZk.js";import{g as st}from"./pickupRules-Mcj6Bso8.js";import{b as be,u as lt,e as Wt}from"./react-vendor-DY_e76sx.js";import{b as Pt,c as Oe}from"./vehicleSwap-BaiRD7_y.js";import{R as $t,L as Mt,C as Ht,X as Ot,Y as Vt,T as Gt,a as Ut}from"./chart-vendor-CXblTV89.js";import{D as qt}from"./DamageViewer-BQkICe9g.js";import{m as Yt}from"./damageSnapshot-ROp3UQst.js";import{b as Xt,c as Jt,r as Qt,l as Zt,p as en}from"./activityText-DYRY2xL0.js";import{f as tn,s as nn}from"./fleetFilters-CyON-tuL.js";import{V as an}from"./VehicleQuickCheckSheet-C4bFkWPA.js";import"./firebase-vendor-DAxoB6-T.js";import"./constants-CtIx5Olh.js";import"./rentalPayment-ByuZDfU_.js";import"./customerName-B0mVkVZf.js";/* empty css */import"./PortalSwitcher-Cx5J51-Q.js";import"./vignetteHelpers-D21SmO0n.js";import"./returnHandover-0YDmv5qY.js";import"./VehicleActivityBadge-DM3BFv-V.js";const rn={name:"ì°¨ëëª
",category:"ì¹´í
ê³ ë¦¬",licensePlate:"ë²í¸í",vin:"VIN",color:"ìì",ownerCompany:"ìì ì¬",fuelType:"ì°ë£",notes:"ë©ëª¨",year:"ì°ì",seats:"ì¢ì",hasGpsTracker:"GPS",currentKm:"KM",nextServiceKm:"ì ë¹ KM",regularInspectionDate:"ì 기ê²ì¬ì¼",seasonalTireType:"íì´ì´",kgfbPolicy:"KGFB ì¦ë²",kgfbExpiry:"KGFB ë§ë£",cascoPolicy:"CASCO ì¦ë²",cascoExpiry:"CASCO ë§ë£",...Object.fromEntries(Object.entries(ze).map(([t,a])=>[`eq_${t}`,a]))},Ve={name:"fleet.colName",category:"fleet.colCategory",licensePlate:"fleet.colPlate",ownerCompany:"fleet.colOwner",fuelType:"fleet.colFuel",year:"fleet.colYear",seats:"fleet.colSeatsShort",color:"vinfo.color",notes:"vinfo.cardNotes",currentKm:"vinfo.currentKm",nextServiceKm:"vinfo.nextMaintKm",regularInspectionDate:"fleet.colInspection",seasonalTireType:"vinfo.tireType",kgfbPolicy:"vinfo.kgfbPolicy",kgfbExpiry:"vinfo.kgfbExpiry",cascoPolicy:"vinfo.cascoPolicy",cascoExpiry:"vinfo.cascoExpiry"},on=["name","category","licensePlate","vin","color","ownerCompany","fuelType","notes"],Ge={kgfbPolicy:"kgfb.policyNumber",kgfbExpiry:"kgfb.expiryDate",cascoPolicy:"casco.policyNumber",cascoExpiry:"casco.expiryDate"},Ue=t=>typeof t=="boolean"?t?"ìì":"ìì":t===""||t==null?"미ì
ë ¥":String(t);function sn({vehicle:t,loadLogs:a}){const{t:n}=se(),{vehicleCategories:o}=pt()||{},{byId:i}=Le(),[h,B]=g.useState(!1),[u,j]=g.useState(!1),[d,f]=g.useState(!1),F=xe()?.name||"",[m,A]=g.useState({}),[p,v]=g.useState(null),[l,c]=g.useState(null),[D,I]=g.useState(""),b=()=>{const r=We(t);A(r),v(r),c(null),I(""),B(!0)},O=()=>{B(!1),A({}),v(null),c(null),I("")},E=(r,S)=>{A(x=>({...x,[r]:S})),c(null),I("")},H=async({overwrite:r=!1,confirmedKm:S=null}={})=>{if(u||!p)return;const x=de(),w=vt(m,p),V=We(t);if(!r){const C=yt(w,p,V);if(C.length>0){c({conflicts:C});return}}const X=w.includes("nextServiceKm")?nt(m.nextServiceKm):null;if(Number.isNaN(X)){I(n("vrepair.nextKmInvalid"));return}const ne=at(i?.get(String(t.id)),t),L=bt({liveKm:t.currentKm,formKm:m.currentKm,kmEdited:w.includes("currentKm"),confirmed:!!m.kmConfirmed,today:x,onRent:ne,confirmedKm:S});if(L.action==="error"){I(n("activity.errKmInvalid"));return}if(L.action==="confirm"){c({kmIssue:L.issue,km:L.km,overwrite:r});return}const K={},G=[],y=(C,W,pe)=>G.push(`${rn[C]||C}: ${Ue(W)} â ${Ue(pe)}`);for(const C of w)if(on.includes(C))K[C]=m[C],y(C,p[C],m[C]);else if(C==="year"||C==="seats")K[C]=Number(m[C]),y(C,p[C],m[C]);else if(C==="hasGpsTracker")K.hasGpsTracker=!!m.hasGpsTracker,y(C,!!p.hasGpsTracker,!!m.hasGpsTracker);else if(C==="nextServiceKm"){if(X===null)continue;Object.assign(K,Ke(X)),y(C,p.nextServiceKm,X)}else C==="regularInspectionDate"?(K.regularInspectionDate=m.regularInspectionDate,y(C,p.regularInspectionDate,m.regularInspectionDate)):C==="seasonalTireType"&&m.seasonalTireType?(Object.assign(K,jt(m.seasonalTireType)),y(C,p.seasonalTireType||Se(t),m.seasonalTireType)):Ge[C]?(K[Ge[C]]=m[C],y(C,p[C],m[C])):C.startsWith("eq_")&&(K[`equipment.${C.slice(3)}
1`]=!!m[C],y(C,!!p[C],!!m[C]));if(Object.assign(K,L.updates),L.change==="changed"?G.push(`KM: ${(Number(t.currentKm)||0).toLocaleString()} â ${L.km.toLocaleString()}`):L.change==="confirmed"&&G.push(`KM íì¸: ${L.km.toLocaleString()} km (ë³ë ìì)`),G.length===0){alert(n("common.noChange","ë³ê²½ë ë´ì©ì´ ììµëë¤."));return}j(!0);try{const C=L.seenSource?ye(L.seenSource,F):{};await ve(()=>me(t,{...K,...C},{type:"info_update",title:`ì°¨ë ì ë³´ ìì (${G.length}ê±´)`,date:x,description:G.join(` 2`),staffName:F},F),f),alert(n("vinfo.savedCount",{count:G.length})),B(!1),v(null),c(null),a&&a()}catch(C){alert(n("dashboard.saveFailed")+C.message)}finally{j(!1)}},ae=r=>Ve[r]?n(Ve[r]):r.startsWith("eq_")?n(`vshared.eq.${r.slice(3)}`):r==="hasGpsTracker"?"GPS":r.toUpperCase(),P=(r,S)=>typeof S=="boolean"?n(S?"vinfo.yes":"vinfo.no"):r==="fuelType"?Ie(n,S)||"â":S===""||S==null?"â":String(S),N=({label:r,value:S})=>e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"10px 0",borderBottom:"1px solid #F3F4F6"},children:[e.jsx("span",{style:{fontSize:"0.8rem",color:"#6B7280",fontWeight:"500"},children:r}),e.jsx("span",{style:{fontSize:"0.8rem",color:"#1A1A2E",fontWeight:"700",textAlign:"right",maxWidth:"55%",wordBreak:"break-all"},children:S||"â"})]}),T={width:"100%",padding:"10px 12px",borderRadius:"8px",border:"1px solid #D1D5DB",fontSize:"0.82rem",background:"#fff",boxSizing:"border-box",minHeight:"44px"},_={fontSize:"0.72rem",fontWeight:"700",color:"#6B7280",marginBottom:"4px",marginTop:"10px",display:"block"},U={summer:"dashboard.tireSummer",winter:"dashboard.tireWinter","all-season":"dashboard.tireAllSeason"},Y=tt(t),q=Y?n("tires.conflictLabel",{a:n(U[Y[0]]),b:n(U[Y[1]])}):U[Se(t)]?n(U[Se(t)]):n("tires.tireMissing"),J=Ee(t),ee=gt(o,m.category||""),te=m.fuelType&&!Te.some(r=>r.value===m.fuelType)?[...Te,{value:m.fuelType,raw:!0}]:Te;return h?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.jsxs("div",{style:{background:"#FFFBEB",border:"2px solid #F59E0B",borderRadius:"10px",padding:"12px 14px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{style:{fontSize:"0.85rem",fontWeight:"700",color:"#92400E"},children:n("vinfo.editMode")}),e.jsxs("button",{onClick:O,style:{fontSize:"0.75rem",fontWeight:"700",color:"#DC2626",background:"none",border:"none",cursor:"pointer"},children:["â ",n("common.cancel","ì·¨ì")]})]}),e.jsxs(Z,{title:n("vinfo.cardBasic"),children:[e.jsx("label",{style:_,children:n("fleet.colName")}),e.jsx("input",{style:T,value:m.name,onChange:r=>E("name",r.target.value),placeholder:n("vinfo.namePlaceholder")}),e.jsx("label",{style:_,children:n("fleet.colCategory")}),e.jsxs("select",{style:T,value:m.category,onChange:r=>E("category",r.target.value),children:[e.jsx("option",{value:"",children:n("vinfo.select")}),ee.map(r=>e.jsx("option",{value:r,children:r},r))]}),e.jsx("label",{style:_,children:n("fleet.colPlate")}),e.jsx("input",{style:T,value:m.licensePlate,onChange:r=>E("licensePlate",r.target.value),placeholder:n("vinfo.platePlaceholder")}),e.jsx("label",{style:_,children:"VIN"}),e.jsx("input",{style:T,value:m.vin,onChange:r=>E("vin",r.target.value),placeholder:n("vinfo.vinPlaceholder")}),e.jsx("label",{style:_,children:n("fleet.colOwner")}),e.jsx("input",{style:T,value:m.ownerCompany,onChange:r=>E("ownerCompany",r.target.value),placeholder:"JOAJO"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:_,children:n("fleet.colYear")}),e.jsx("input",{type:"number",style:T,value:m.year,onChange:r=>E("year",r.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{style:_,children:n("fleet.colSeatsShort")}),e.jsx("input",{type:"number",style:T,value:m.seats,onChange:r=>E("seats",r.target.value)})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:_,children:n("vinfo.color")}),e.jsx("input",{style:T,value:m.color,onChange:r=>E("color",r.target.value),placeholder:n("vinfo.colorPlaceholder")})]}),e.jsxs("div",{children:[e.jsx("label",{style:_,children:n("fleet.colFuel")}
2),e.jsx("select",{style:T,value:m.fuelType,onChange:r=>E("fuelType",r.target.value),children:te.map(r=>e.jsx("option",{value:r.value,children:r.raw?r.value:n(r.labelKey)},r.value))})]})]}),e.jsxs("div",{style:{marginTop:"10px",display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("input",{type:"checkbox",id:"gps",checked:m.hasGpsTracker,onChange:r=>E("hasGpsTracker",r.target.checked),style:{width:"20px",height:"20px",cursor:"pointer"}}),e.jsx("label",{htmlFor:"gps",style:{fontSize:"0.82rem",fontWeight:"600",color:"#374151",cursor:"pointer"},children:n("vinfo.gpsTracker")})]})]}),e.jsxs(Z,{title:n("vinfo.cardKm"),children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:[e.jsxs("div",{children:[e.jsx("label",{style:_,children:n("vinfo.currentKm")}),e.jsx("input",{type:"text",inputMode:"numeric",style:T,value:m.currentKm,onChange:r=>E("currentKm",r.target.value),placeholder:"0"})]}),e.jsxs("div",{children:[e.jsx("label",{style:_,children:n("vinfo.nextMaintKm")}),e.jsx("input",{type:"number",inputMode:"numeric",style:T,value:m.nextServiceKm,onChange:r=>E("nextServiceKm",r.target.value),placeholder:"250000"})]})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",minHeight:"44px",marginTop:"6px",fontSize:"0.8rem",fontWeight:"600",color:"var(--color-text)",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:!!m.kmConfirmed,onChange:r=>E("kmConfirmed",r.target.checked),style:{width:"20px",height:"20px",flexShrink:0,cursor:"pointer",accentColor:"var(--color-success)"}}),e.jsx("span",{children:n("activity.flows.kmConfirmLabel")})]}),e.jsx("label",{style:_,children:n("fleet.colInspection")}),e.jsx("input",{type:"date",style:T,value:m.regularInspectionDate,onChange:r=>E("regularInspectionDate",r.target.value)}),e.jsx("label",{style:_,children:n("vinfo.tireType")}),Y&&e.jsx("div",{style:{fontSize:"0.75rem",fontWeight:"600",lineHeight:1.45,color:"var(--color-warning)",marginBottom:"4px"},children:n("vinfo.tireConflictHint",{a:n(U[Y[0]]),b:n(U[Y[1]])})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"6px",marginTop:"4px"},children:[{key:"summer",label:n("dashboard.tireSummer"),color:"#D97706"},{key:"winter",label:n("dashboard.tireWinter"),color:"#2563EB"},{key:"all-season",label:n("dashboard.tireAllSeason"),color:"#059669"}].map(r=>e.jsx("button",{type:"button",onClick:()=>E("seasonalTireType",r.key),style:{padding:"10px",borderRadius:"8px",fontSize:"0.78rem",fontWeight:"700",cursor:"pointer",minHeight:"44px",border:m.seasonalTireType===r.key?`2px solid ${r.color}`:"1px solid #D1D5DB",background:m.seasonalTireType===r.key?r.color:"#fff",color:m.seasonalTireType===r.key?"#fff":r.color},children:r.label},r.key))})]}),e.jsxs(Z,{title:n("vinfo.cardInsurance"),children:[e.jsx("label",{style:_,children:n("vinfo.kgfbPolicy")}),e.jsx("input",{style:T,value:m.kgfbPolicy,onChange:r=>E("kgfbPolicy",r.target.value),placeholder:n("vinfo.policyPlaceholder")}),e.jsx("label",{style:_,children:n("vinfo.kgfbExpiry")}),e.jsx("input",{type:"date",style:T,value:m.kgfbExpiry,onChange:r=>E("kgfbExpiry",r.target.value)}),e.jsx("label",{style:_,children:n("vinfo.cascoPolicy")}),e.jsx("input",{style:T,value:m.cascoPolicy,onChange:r=>E("cascoPolicy",r.target.value),placeholder:n("vinfo.policyPlaceholder")}),e.jsx("label",{style:_,children:n("vinfo.cascoExpiry")}),e.jsx("input",{type:"date",style:T,value:m.cascoExpiry,onChange:r=>E("cascoExpiry",r.target.value)})]}),e.jsx(Z,{title:n("vinfo.cardEquipChecklist"),children:e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px"},children:Object.entries(ze).map(([r,S])=>e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"8px",fontSize:"0.78rem",fontWeight:"600",color:"#374151",cursor:"pointer",padding:"6px 0"},children:[e.jsx("input",{type:"checkbox",checked:m[`eq_${r}`]||!1,onChange:x=>E(`eq_${r}`,x.target.checked),style:{width:"20px",height:"20px",cursor:"pointer",accentColor:"#059669"}}),n(`vshared.eq.${r}`,{defaultValue:S})]},r))})}),e.jsx(Z,{title:n("vinfo.cardNotes"),children:e.jsx("textarea",{value:m.notes,onChange:r=>E("notes",r.target.value),placeholder:n("vinfo.notesPlaceholder"),rows:3,style:{...T,resize:"vertical",fontFamily:"inherit",minHeight:"80px"}})}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px",position:"sticky",bottom:"70px",background:"#fff",padding:"12px 0",borderTop:"1px solid #E5E7EB",zIndex:10},children:[D&&e.jsx("div",{role:"alert",style:{fontSize:"0.8rem",fontWeight:"700",color:"var(--color-error)"},children:D}),l?.conflicts&&e.jsxs("div",{role:"alert",style:{padding:"10px 12px",borderRadius:"10px",border:"1.5px solid var(--color-warning)",background:"var(--color-surface-light)",fontSize:"0.8rem",lineHeight:1.5,color:"var(--color-text)"},children:[e.jsx("div",{style:{fontWeight:"800",marginBottom:"4px"},children:n("vinfo.conflictTitle")}),l.conflicts.map(r=>e.jsx("div",{children:n("vinfo.conflictLine",{field:ae(r.key),before:P(r.key,r.before),now:P(r.key,r.now),mine:P(r.key,m[r.key])})},r.key)),e.jsx("div",{style:{marginTop:"4px"},children:n("vinfo.conflictAsk")})]}),l?.kmIssue&&e.jsx("div",{role:"alert",style:{padding:"10px 12px",borderRadius:"10px",border:"1.5px solid var(--color-warning)",background:"var(--color-surface-light)",fontSize:"0.8rem",fontWeight:"600",lineHeight:1.5,color:"var(--color-text)"},children:_t(n,l.kmIssue,l.km,t.currentKm)}),d&&e.jsx("div",{role:"status",style:{fontSize:"0.78rem",fontWeight:"600",color:"var(--color-text-secondary)"},children:n("activity.savePending")}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("button",{onClick:l?()=>c(null):O,style:{flex:1,padding:"14px",borderRadius:"10px",border:"1px solid #D1D5DB",background:"#fff",fontSize:"0.85rem",fontWeight:"700",cursor:"pointer",color:"#6B7280",minHeight:"48px"},children:l?n("vinfo.backToEdit"):n("common.cancel","ì·¨ì")}),e.jsx("button",{onClick:()=>l?.conflicts?H({overwrite:!0}):l?.kmIssue?H({overwrite:!!l.overwrite,confirmedKm:l.km}):H(),disabled:u,style:{flex:2,padding:"14px",borderRadius:"10px",border:"none",background:l?"var(--color-warning)":"#059669",color:"#fff",fontSize:"0.85rem",fontWeight:"700",cursor:"pointer",minHeight:"48px",opacity:u?.5:1},children:u?n("dashboard.savingShort"):l?.conflicts?n("vinfo.overwriteSave"):l?.kmIssue?n("activity.btnConfirmSave"):n("vinfo.saveAll")})]})]})]}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.jsx("button",{onClick:b,style:{width:"100%",padding:"14px",borderRadius:"10px",border:"2px s
2olid #F59E0B",background:"#FFFBEB",color:"#92400E",fontSize:"0.85rem",fontWeight:"700",cursor:"pointer",minHeight:"48px",display:"flex",alignItems:"center",justifyContent:"center",gap:"6px"},children:n("vinfo.editAll")}),e.jsxs(Z,{title:n("vinfo.cardBasic"),children:[e.jsx(N,{label:n("fleet.colName"),value:t.name}),e.jsx(N,{label:n("fleet.colCategory"),value:t.category}),e.jsx(N,{label:n("fleet.colPlate"),value:t.licensePlate}),e.jsx(N,{label:"VIN",value:t.vin}),e.jsx(N,{label:n("fleet.colOwner"),value:t.ownerCompany}),e.jsx(N,{label:n("fleet.colYear"),value:t.year}),e.jsx(N,{label:n("vinfo.color"),value:t.color}),e.jsx(N,{label:n("fleet.colFuel"),value:Ie(n,t.fuelType)}),e.jsx(N,{label:n("fleet.colSeatsShort"),value:t.seats}),e.jsx(N,{label:"GPS",value:t.hasGpsTracker?n("vinfo.yes"):n("vinfo.no")})]}),e.jsxs(Z,{title:n("vinfo.cardKm"),children:[e.jsx(N,{label:n("vinfo.currentKm"),value:t.currentKm?`${t.currentKm.toLocaleString()} km`:""}),e.jsx(N,{label:n("dashboard.lastChecked"),value:t.lastKmCheckDate}),e.jsx(N,{label:n("vinfo.nextMaintKm"),value:J?`${J.toLocaleString()} km`:""}),e.jsx(N,{label:n("fleet.colInspection"),value:t.regularInspectionDate}),e.jsx(N,{label:n("fleet.colTireShort"),value:q})]}),e.jsxs(Z,{title:n("vinfo.cardInsurance"),children:[e.jsx(N,{label:"KGFB",value:t.kgfb?.policyNumber}),e.jsx(N,{label:n("fleet.colKgfb"),value:t.kgfb?.expiryDate}),e.jsx(N,{label:"CASCO",value:t.casco?.policyNumber}),e.jsx(N,{label:n("fleet.colCasco"),value:t.casco?.expiryDate})]}),e.jsx(ln,{vehicle:t}),e.jsx(Z,{title:n("vinfo.cardEquipment"),children:e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px"},children:Object.entries(ze).map(([r,S])=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"0.75rem",color:t.equipment?.[r]?"#059669":"#DC2626",fontWeight:"600"},children:[e.jsx("span",{children:t.equipment?.[r]?"â
":"â"}),n(`vshared.eq.${r}`,{defaultValue:S})]},r))})}),t.notes&&e.jsx(Z,{title:n("vinfo.cardNotes"),children:e.jsx("div",{style:{fontSize:"0.82rem",color:"#374151",whiteSpace:"pre-wrap",lineHeight:1.5},children:t.notes})})]})}function ln({vehicle:t}){const{t:a}=se(),[n,o]=g.useState(!1),[i,h]=g.useState(!1),B=xe(),u=t.tires||{},j=Se(t),d=tt(t),f=ht(t),z={winter:"âï¸ ê²¨ì¸",summer:"âï¸ ì¬ë¦","all-season":"ð ì¬ê³ì "},F={winter:"tires.tireWinter",summer:"tires.tireSummer","all-season":"tires.tireAllSeason"},m=v=>F[v]?a(F[v]):a("tires.tireMissing"),A=async v=>{if(i)return;const l=de(),c=it(t,v,{km:t.currentKm,date:l});if(!c.update){o(!1);return}h(!0);try{const D=B?.name||"",I=d?`${m(d[0])}/${m(d[1])}`:m(j),b=c.kind==="change"?{type:"tire_change",title:`${a("tires.logTitlePrefix")}${I} â ${m(c.type)}`,description:`${I} â ${m(c.type)}`,date:l,km:t.currentKm||0,staffName:D}:{type:"info_update",title:a("tires.logCorrection",{from:I,to:m(c.type)}),description:`${I} â ${m(c.type)}`,date:l,staffName:D};await me(t,{...c.update,...c.kind==="change"?ye("tire",D):{}},b,D),alert(a("vinfo.tireChangeSaved")),o(!1)}catch(D){alert(a("vinfo.failedPrefix")+D.message)}h(!1)},p=["winter","summer","all-season"].filter(v=>d||v!==j);return e.jsxs(Z,{title:a("vinfo.cardTire"),children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"8px 0"},children:[e.jsx("span",{style:{fontSize:"0.8rem",color:"#6B7280"},children:a("vinfo.currentTire")}),e.jsxs("div",{style:{display:"flex",gap:"6px",alignItems:"center",flexWrap:"wrap",justifyContent:"flex-end"},children:[e.jsx("span",{style:{fontSize:"0.85rem",fontWeight:"700",color:"#1A1A2E"},children:d?`${m(d[0])} / ${m(d[1])}`:j?a(`dashboard.tireName_${j}`,{defaultValue:z[j]}):a("tires.tireMissing")}),f==="mismatch"&&e.jsx("span",{style:{background:"#FEE2E2",color:"#DC2626",padding:"2px 6px",borderRadius:"4px",fontSize:"0.6rem",fontWeight:"700"},children:a("vinfo.seasonMismatch")}),f==="conflict"&&e.jsx("span",{style:{background:"#FEF3C7",color:"#92400E",padding:"2px 6px",borderRadius:"4px",fontSize:"0.6rem",fontWeight:"700"},children:a("tires.statusConflict")})]})]}),d&&e.jsx("div",{style:{fontSize:"0.72rem",color:"var(--color-text-secondary)",lineHeight:1.45,padding:"0 0 8px"},children:a("vinfo.tireConflictHint",{a:m(d[0]),b:m(d[1])})}),u.lastChangeDate&&e.jsxs("div",{style:{fontSize:"0.7rem",color:"#9
2CA3AF",padding:"0 0 8px"},children:[a("vinfo.lastChange"),": ",u.lastChangeDate,u.lastChangeKm!=null?` (${Number(u.lastChangeKm).toLocaleString()} km)`:""]}),n?e.jsxs("div",{style:{display:"flex",gap:"6px",marginTop:"8px",flexWrap:"wrap"},children:[p.map(v=>e.jsx("button",{onClick:()=>A(v),disabled:i,style:{flex:1,padding:"10px",borderRadius:"8px",border:"none",background:"#1A1A2E",color:"#fff",fontSize:"0.75rem",fontWeight:"700",cursor:"pointer",minHeight:"44px"},children:m(v)},v)),e.jsx("button",{onClick:()=>o(!1),style:{padding:"10px",borderRadius:"8px",border:"1px solid #E5E7EB",background:"#fff",fontSize:"0.75rem",cursor:"pointer",color:"#6B7280",minHeight:"44px"},children:a("common.cancel","ì·¨ì")})]}):e.jsx("button",{onClick:()=>o(!0),style:{width:"100%",padding:"10px",borderRadius:"8px",border:"1px solid #E5E7EB",background:"#F9FAFB",fontSize:"0.8rem",fontWeight:"600",cursor:"pointer",color:"#374151",marginTop:"4px",minHeight:"44px"},children:a(d?"vinfo.tireConfirmBtn":"vinfo.tireChangeBtn")})]})}function dn({vehicle:t,supplementBookingId:a="",onSupplementConsumed:n}){const{t:o}=se(),{bookings:i=[]}=Re(),h=be(),u=xe()?.name||"",[j,d]=g.useState([]),[f,z]=g.useState(null),F=f!==t.id,[m,A]=g.useState(!1),[p,v]=g.useState(!1),[l,c]=g.useState(!1),[D,I]=g.useState(null),[b,O]=g.useState({notes:"",cost:"",insuranceClaim:!1}),[E,H]=g.useState(!1),[ae,P]=g.useState(null),[N,T]=g.useState(!1),[_,U]=g.useState(null),Y=g.useRef(null),[q,J]=g.useState(""),[ee,te]=g.useState(0);g.useEffect(()=>{const s=t.id;let R=!0;return(async()=>{try{const Q=await Qe(s);if(!R)return;d(Q),A(!1)}catch(Q){if(console.error(Q),!R)return;d([]),A(!0)}z(s)})(),()=>{R=!1}},[t.id,ee]);const r=()=>{z(null),te(s=>s+1)},[S,x]=g.useState("");if(a&&a!==S&&!F&&!m){x(a);const s=Me(j,a);s?U(s):J(a)}g.useEffect(()=>{S&&S===a&&n?.()},[S,a,n]);const w=j.filter(s=>s.resolved===!1),V=j.filter(s=>s.resolved!==!1),X=w.filter(_e).length,ne=()=>U(null),L=w.reduce((s,R)=>s+(Number(R.estimatedRepairCost)||0),0),K=j.reduce((s,R)=>s+(Number(R.customerCharged)||0),0),G=V.reduce((s,R)=>s+(Number(R.actualRepairCost)||0),0),y=async s=>{if(!b.notes.trim()){alert(o("vrepair.descRequired"));return}if(!E){H(!0);try{await ve(()=>me(t,null,null,u,{logUpdates:[{id:s.id,updates:{resolved:!0,resolvedAt:new Date().toISOString(),resolvedBy:u,repairNotes:b.notes,actualRepairCost:Number(b.cost)||0,insuranceClaim:b.insuranceClaim}}]}),v)}catch(R){alert(o("vdetail.failedPrefix")+R.message),H(!1);return}I(null),O({notes:"",cost:"",insuranceClaim:!1});try{const{cleared:R}=await ot(t,u);alert(o(R?"vdamage.allResolved":"vdamage.resolved"))}catch(R){console.error("[VehicleDamageTab] damage flag check failed:",R),alert(o("vdamage.flagCheckFailed"))}r(),H(!1)}},C=async(s,R)=>{if(!E){H(!0);try{await ve(()=>Kt(t,s,R,u),v),ne(),T(!1),alert(o("vdamage.supplemented")),r()}catch(Q){alert(o("vdamage.reportFailed")+Q.message)}H(!1)}},W=async(s,R,{mergeLogId:Q=""}={})=>{const le=Q?j.find(M=>M.id===Q):null;if(le){await C(le,s);return}if(!E){H(!0);try{let M="";if(R){const je=i.find(k=>k.id===R);je&&(M=`${je.customerInfo?.lastName||""} ${je.customerInfo?.firstName||""}`.trim())}const re=Lt(s);await ve(()=>me(t,{hasDamage:!0,...ye("damage",u)},{type:"damage",title:"ì ê· ì¬ê³ /ìì ìë ë³´ê³ ",date:de(),description:re,blueprintData:s,damagePhotoUrls:[],resolved:!1,staffName:u,bookingId:R||null,customerName:M||null,estimatedRepairCost:0,customerCharged:0},u),v),T(!1),alert(o("vdamage.reported")),r()}catch(M){alert(o("vdamage.reportFailed")+M.message)}H(!1)}},pe=Nt(i,t.id,de()),fe=s=>{if(!s)return null;const R=i.find(Q=>Q.id===s);return R?{pickupSignature:R.pickup?.signatureUrl,pickupPdf:R.pickup?.pdfUrl,pickupKm:R.pickup?.km,returnKm:R.returnData?.km}:null},ie={background:"#fff",borderRadius:"12px",border:"1px solid #E5E7EB",padding:"14px"};return F?e.jsx("div",{style:{padding:"40px 0",textAlign:"center",color:"#9CA3AF"},children:o("staffCommon.loading","ë¡ë© ì¤...")}):m?e.jsxs("div",{role:"alert",style:{...ie,background:"#FEF2F2",borderColor:"#FECACA",color:"#991B1B",fontSize:"0.8rem",lineHeight:1.5},children:[e.jsx("div",{children:o("vdamage.loadFailed")}),e.jsx("button",{type:"button",onClick:r,style:{marginTop:"8px",minHeight:"44px",padding:"0 14px",borderRadius:"8px",border:"1px solid #FECACA",background:"#fff",color:"#991B1B",fontSize:"0.78rem",fontWeight:"700",cursor:"pointer"},children:o("vdamage.loadRetry")})]}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"14px"},children:[p&&e.jsx("div",{role:"status",style:{...ie,background:"var(--color-surface-light)",color:"var(--color-text-secondary)",fontSize:"0.78rem",fontWeight:"600",lineHeight:1.5},children:o("activity.savePending")}),q&&!_&&e.jsxs("div",{role:"status",style:{...ie,background:"#FFFBEB",borderColor:"#FDE68A",color:"#92400E",fontSize:"0.8rem",lineHeight:1.5},children:[e.jsx("div",{children:o("vdamage.supplementMissing",{id:q})}),e.jsx("button",{type:"button",onClick:()=>J(""),style:{marginTop:"8px",minHeight:"44px",padding:"0 14px",borderRadius:"8px",border:"1px solid #FDE68A",background:"#fff",color:"#92400E",fontSize:"0.78rem",fontWeight:"700",cursor:"pointer"},children:o("vdamage.supplementMissingClose")})]}),e.jsx("div",{ref:Y,style:ie,children:_?e.jsx(He,{supplementLog:_,onSubmit:s=>C(_,s),onCancel:ne,saving:E},`supplement-${_.id}`):N?e.jsxs(e.Fragment,{children:[X>0&&e.jsx("div",{role:"status",style:{marginBottom:"12px",padding:"10px 12px",borderRadius:"8px",background:"#FFFBEB",border:"1px solid #FDE68A",color:"#92400E",fontSize:"0.78rem",lineHeight:1.5},children:o("vdamage.placeholderNotice",{count:X})}),e.jsx(He,{bookings:pe,onSubmit:W,onCancel:()=>T(!1),saving:E,findMergeTarget:s=>Me(j,s)})]}):e.jsx("button",{onClick:()=>T(!0),style:{width:"100%",padding:"14px",borderRadius:"8px",border:"2px dashed #DC2626",background:"#FEF2F2",color:"#991B1B",fontSize:"0.9rem",fontWeight:"800",cursor:"pointer"},children:o("vdamage.newReport")})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"6px"},children:[e.jsxs("div",{style:{background:"#FEF2F2",borderRadius:"10px",padding:"10px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"0.6rem",fontWeight:"600",color:"#6B7280"},children:o("vdamage.unresolvedLabel")}),e.jsxs("div",{style:{fontSize:"1.1rem",fontWeight:"800",color:"#DC2626"},children:[w.length,o("common.cases","ê±´")]})]}),e.jsxs("div",{style:{background:"#F0FDF4",borderRadius:"10px",padding:"10px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"0.6rem",fontWeight:"600",color:"#6B7280"},children:o("vdamage.resolvedLabel")}),e.jsxs("div",{style:{fontSize:"1.1rem",fontWeight:"800",color:"#059669"},children:[V.length,o("common.cases","ê±´")]})]}),e.jsxs("div",{style:{background:"#EFF6FF",borderRadius:"10px",padding:"10px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"0.6rem",fontWeight:"600",color:"#6B7280"},children:o("vdamage.totalRepairCost")}),e.jsxs("div",{style:{fontSize:"1.1rem",fontWeight:"800",color:"#2563EB"}
2,children:["â¬",G.toLocaleString()]})]})]}),(L>0||K>0)&&e.jsxs("div",{style:{...ie,background:"#FFFBEB",borderColor:"#FDE68A"},children:[e.jsx("div",{style:{fontSize:"0.75rem",fontWeight:"700",color:"#92400E",marginBottom:"6px"},children:o("vdamage.costSummary")}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"4px",fontSize:"0.72rem",color:"#374151"},children:[e.jsxs("div",{children:[o("vdamage.estimatedCost"),": ",e.jsxs("strong",{children:["â¬",L.toLocaleString()]})]}),e.jsxs("div",{children:[o("vdamage.chargedToCustomer"),": ",e.jsxs("strong",{children:["â¬",K.toLocaleString()]})]}),e.jsxs("div",{children:[o("vdamage.actualCost"),": ",e.jsxs("strong",{children:["â¬",G.toLocaleString()]})]}),e.jsxs("div",{children:[o("vdamage.unrecovered"),": ",e.jsxs("strong",{style:{color:K-G<0?"#DC2626":"#059669"},children:["â¬",Math.abs(K-G).toLocaleString()]})]})]})]}),e.jsxs("div",{style:ie,children:[e.jsx("div",{style:{fontWeight:"700",fontSize:"0.85rem",color:"#DC2626",marginBottom:"10px"},children:o("vdamage.unresolvedSection",{count:w.length})}),w.length===0?e.jsx("div",{style:{textAlign:"center",padding:"20px",color:"#9CA3AF",fontSize:"0.82rem"},children:o("vdamage.noUnresolved")}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"10px"},children:w.map(s=>{const R=Fe[s.severity]||Fe.minor,Q=ae===s.id,le=D===s.id;return fe(s.bookingId),e.jsxs("div",{style:{borderRadius:"10px",border:`1px solid ${R.color}20`,background:R.bg+"40",overflow:"hidden"},children:[e.jsxs("div",{onClick:()=>P(Q?null:s.id),style:{padding:"10px 12px",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{background:R.bg,color:R.color,padding:"2px 6px",borderRadius:"4px",fontSize:"0.65rem",fontWeight:"700"},children:o(`dmgc.sv_${s.severity||"minor"}`,{defaultValue:R.label})}),e.jsx("span",{style:{fontWeight:"700",fontSize:"0.82rem",color:"#1A1A2E"},children:s.title}),_e(s)&&e.jsx("span",{style:{background:"#FEF3C7",color:"#92400E",padding:"2px 6px",borderRadius:"4px",fontSize:"0.62rem",fontWeight:"700",whiteSpace:"nowrap"},children:o("vdamage.needsBlueprint")})]}),e.jsx("span",{style:{fontSize:"0.65rem",color:"#9CA3AF"},children:s.date})]}),e.jsxs("div",{style:{fontSize:"0.72rem",color:"#6B7280",marginTop:"4px"},children:[s.description?.substring(0,80),s.description?.length>80?"...":""]}),s.damageLocations?.length>0&&e.jsx("div",{style:{display:"flex",gap:"4px",marginTop:"4px",flexWrap:"wrap"},children:s.damageLocations.map(M=>e.jsx("span",{style:{background:"#E5E7EB",padding:"1px 6px",borderRadius:"4px",fontSize:"0.6rem",fontWeight:"600",color:"#374151"},children:o(`dmgc.loc_${M}`,{defaultValue:zt[M]||M})},M))})]}),Q&&e.jsxs("div",{style:{padding:"0 12px 12px",borderTop:"1px solid #E5E7EB"},children:[e.jsx("div",{style:{fontSize:"0.75rem",color:"#374151",marginTop:"10px"},children:s.description}),s.customerName&&e.jsxs("div",{style:{fontSize:"0.7rem",color:"#6B7280",marginTop:"4px"},children:["ð¤ ",s.customerName," ",s.bookingId&&`· #${s.bookingId.slice(0,8)}`]}),s.estimatedRepairCost>0&&e.jsxs("div",{style:{fontSize:"0.7rem",color:"#92400E",marginTop:"2px"},children:[o("vdamage.estRepairCostShort"),": â¬",s.estimatedRepairCost]}),s.blueprintData?.length>0&&e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{fontSize:"0.7rem",fontWeight:"600",color:"#6B7280",marginBottom:"8px"},children:o("vdamage.blueprintTitle")}),e.jsx("div",{style:{width:"120px"},children:e.jsx($e,{markers:s.blueprintData,readOnly:!0})})]}),s.damagePhotoUrls?.length>0&&e.jsxs("div",{style:{marginTop:"12px"},children:[e.jsx("div",{style:{fontSize:"0.7rem",fontWeight:"600",color:"#6B7280",marginBottom:"4px"},children:o("vdamage.photos")}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"4px"},children:s.damagePhotoUrls.map((M,re)=>e.jsx("img",{src:M,alt:"",style:{width:"100%",aspectRatio:"1",objectFit:"cover",borderRadius:"6px",cursor:"pointer"},onClick:()=>window.open(M,"_blank")},re))})]}),s.bookingId&&e.jsx("button",{onClick:()=>h(st(i.find(M=>String(M.id)===String(s.bookingId)),s.bookingId)),style:{marginTop:"8px",width:"100%",padding:"8px",borderRadius:"8px",border:"1px solid #D1D5DB",background:"#F8FAFC",fontSize:"0.72rem",fontWeight:"600",cursor:"pointer",color:"#374151"},children:o("vdamage.viewBooking")}),_e(s)&&e.jsx("button",{onClick:()=>{T(!1),U(s),Y.current?.scrollIntoView?.({behavior:"smooth",block:"start"})},style:{marginTop:"8px",width:"100%",minHeight:"44px",padding:"10px",borderRadius:"8px",border:"1px solid #DC2626",background:"#FEF2F2",color:"#991B1B",fontSize:"0.78rem",fontWeight:"700",cursor:"pointer"},children:o("vdamage.supplementBtn")}),le?e.jsxs("div",{style:{marginTop:"8px",padding:"10px",borderRadius:"8px",background:"#F0FDF4",border:"1px solid #BBF7D0"},children:[e.jsx("div",{style:{fontSize:"0.75rem",fontWeight:"700",color:"#065F46",marginBottom:"6px"},children:o("vdamage.resolveSection")}),e.jsx("textarea",{value:b.notes,onChange:M=>O(re=>({...re,notes:M.target.value})),placeholder:o("vdamage.repairNotesPlaceholder"),rows:2,style:{width:"100%",padding:"8px",borderRadius:"6px",border:"1px solid #D1D5DB",fontSize:"0.82rem",boxSizing:"border-box",marginBottom:"6px",fontFamily:"inherit"}}),e.jsx("input",{type:"number",value:b.cost,onChange:M=>O(re=>({...re,cost:M.target.value})),placeholder:o("vdamage.actualCostPlaceholder"),style:{width:"100%",padding:"8px",borderRadius:"6px",border:"1px solid #D1D5DB",fontSize:"0.82rem",boxSizing:"border-box",marginBottom:"6px"}}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"0.75rem",color:"#374151",marginBottom:"8px",cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:b.insuranceClaim,onChange:M=>O(re=>({...re,insuranceClaim:M.target.checked}))}),o("vdamage.insuranceClaim")]}),e.jsxs("div",{style:{display:"flex",gap:"6px"},children:[e.jsx("button",{onClick:()=>I(null),style:{flex:1,padding:"8px",borderRadius:"6px",border:"1px solid #D1D5DB",background:"#fff",fontSize:"0.75rem",fontWeight:"600",cursor:"pointer"},children:o("common.cancel","ì·¨ì")}),e.jsx("button",{onClick:()=>y(s),disabled:E,style:{flex:2,padding:"8px",borderRadius:"6px",border:"none",background:"#059669",color:"#fff",fontSize:"0.75rem",fontWeight:"700",cursor:"pointer",opacity:E?.5:1},children:o(E?"active.processing":"vdamage.resolveDone")})]})]}):e.jsx("button",{onClick:()=>{I(s.id),O({notes:"",cost:String(s.estimatedRepairCost||""),insuranceClaim:!1})},style:{marginTop:"6px",width:"100%",padding:"10px",borderRadius:"8px",border:"none",background:"#059669",color:"#fff",fontSize:"0.78rem",fontWeight:"700",cursor:"pointer"},children:o("vdamage.resolveThis")})]})]},s.id)})})]}),V.length>0&&e.jsxs("div",{style:ie,children:[e.jsxs("button",{onClick:()=>c(!l),style:{width:"100%",background:"none",border:"none",padding:0,cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("span",{style:{fontWeight:"700",fontSize:"0.82rem",color:"#059669"},children:o("vdamage.resolvedSection",{count:V.length})}
2),e.jsx("span",{style:{fontSize:"0.7rem",color:"#9CA3AF"},children:o(l?"vdamage.collapse":"vdamage.expand")})]}),l&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px",marginTop:"10px"},children:V.map(s=>{const R=Fe[s.severity]||Fe.minor,Q=ae===`resolved_${s.id}`;return e.jsxs("div",{style:{borderRadius:"8px",background:"#F8FAFC",border:"1px solid #E5E7EB",overflow:"hidden"},children:[e.jsxs("div",{onClick:()=>P(Q?null:`resolved_${s.id}`),style:{padding:"10px 12px",cursor:"pointer"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx("span",{style:{background:"#D1FAE5",color:"#065F46",padding:"1px 6px",borderRadius:"3px",fontSize:"0.6rem",fontWeight:"700"},children:o("vdamage.resolvedLabel")}),e.jsx("span",{style:{background:R.bg,color:R.color,padding:"1px 5px",borderRadius:"3px",fontSize:"0.6rem",fontWeight:"600"},children:o(`dmgc.sv_${s.severity||"minor"}`,{defaultValue:R.label})}),e.jsx("span",{style:{fontSize:"0.78rem",fontWeight:"600",color:"#6B7280",textDecoration:"line-through"},children:s.title})]}),e.jsx("span",{style:{fontSize:"0.6rem",color:"#9CA3AF"},children:Q?"â²":"â¼"})]}),e.jsxs("div",{style:{fontSize:"0.68rem",color:"#6B7280",marginTop:"4px"},children:[o("vdamage.repairShort"),": ",s.repairNotes||"â",s.actualRepairCost>0&&` · â¬${s.actualRepairCost}`,s.insuranceClaim&&` · ${o("vdamage.insuranceShort")}`]}),e.jsxs("div",{style:{fontSize:"0.6rem",color:"#9CA3AF",marginTop:"2px"},children:[o("vdamage.resolvedShort"),": ",s.resolvedAt?new Date(s.resolvedAt).toLocaleDateString("ko"):"â"," · ",s.resolvedBy||"â"]})]}),Q&&e.jsxs("div",{style:{padding:"0 12px 12px",borderTop:"1px solid #E5E7EB"},children:[s.description&&e.jsx("div",{style:{fontSize:"0.75rem",color:"#374151",marginTop:"10px",padding:"8px",background:"#fff",borderRadius:"6px",border:"1px solid #F1F5F9"},children:s.description}),s.customerName&&e.jsxs("div",{style:{fontSize:"0.7rem",color:"#6B7280",marginTop:"6px"},children:["ð¤ ",s.customerName,s.bookingId&&` · #${s.bookingId.slice(0,8)}`]}),s.blueprintData?.length>0&&e.jsxs("div",{style:{marginTop:"10px"},children:[e.jsx("div",{style:{fontSize:"0.7rem",fontWeight:"600",color:"#6B7280",marginBottom:"6px"},children:o("vdamage.blueprintTitle")}),e.jsx("div",{style:{width:"140px"},children:e.jsx($e,{markers:s.blueprintData,readOnly:!0})})]}),s.damagePhotoUrls?.length>0&&e.jsxs("div",{style:{marginTop:"10px"},children:[e.jsx("div",{style:{fontSize:"0.7rem",fontWeight:"600",color:"#6B7280",marginBottom:"4px"},children:o("vdamage.photos")}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"4px"},children:s.damagePhotoUrls.map((le,M)=>e.jsx("img",{src:le,alt:"",style:{width:"100%",aspectRatio:"1",objectFit:"cover",borderRadius:"6px",cursor:"pointer"},onClick:()=>window.open(le,"_blank")},M))})]}),e.jsxs("div",{style:{marginTop:"10px",padding:"8px",background:"#F0FDF4",borderRadius:"6px",border:"1px solid #BBF7D0"},children:[e.jsx("div",{style:{fontSize:"0.7rem",fontWeight:"700",color:"#065F46",marginBottom:"4px"},children:o("vdamage.repairDetails")}),e.jsx("div",{style:{fontSize:"0.72rem",color:"#374151"},children:s.repairNotes||"â"}),s.actualRepairCost>0&&e.jsxs("div",{style:{fontSize:"0.7rem",color:"#059669",marginTop:"2px"},children:[o("vdamage.repairCostShort"),": â¬",s.actualRepairCost]}),s.insuranceClaim&&e.jsx("div",{style:{fontSize:"0.7rem",color:"#6B7280",marginTop:"2px"},children:o("vdamage.insuranceClaimed")}),e.jsxs("div",{style:{fontSize:"0.65rem",color:"#9CA3AF",marginTop:"4px"},children:[s.resolvedAt?new Date(s.resolvedAt).toLocaleDateString("ko",{year:"numeric",month:"long",day:"numeric"}):""," · ",s.resolvedBy]})]})]})]},s.id)})})]}),j.length===0&&e.jsx("div",{style:{...ie,textAlign:"center",color:"#9CA3AF",fontSize:"0.82rem",padding:"40px 16px"},children:o("vdamage.noDamageRecords")})]})}function cn({active:t,payload:a}){if(!t||!a?.length)return null;const n=a[0].payload;return e.jsxs("div",{style:{background:"#fff",border:"1px solid #E5E7EB",borderRadius:"8px",padding:"8px 12px",fontSize:"0.75rem",boxShadow:"0 2px 8px rgba(0,0,0,0.1)"},children:[e.jsxs("div",{style:{fontWeight:"700",color:"#1A1A2E",marginBottom:"2px"},children:[n.label," ",n.customerName]}),e.jsx("div",{style:{color:"#6B7280"},children:n.date}),e.jsxs("div",{style:{fontWeight:"800",color:"#2563EB",fontSize:"0.85rem"}
2,translate:"no",children:[n.km?.toLocaleString()," km"]})]})}const qe={pickup:"dashboard.tagPickup",return:"dashboard.tagReturn",swapIn:"vchart.pointSwapIn",swapOut:"vchart.pointSwapOut"},Ye=t=>t==="pickup"||t==="swapIn";function pn(t,a){if(!t||!a)return null;const n=Math.round((Date.parse(`${a}T00:00:00Z`)-Date.parse(`${t}T00:00:00Z`))/864e5);return Number.isFinite(n)?Math.max(1,n):null}function un({vehicle:t}){const{t:a}=se(),{bookings:n=[]}=Re(),o=be(),[i,h]=g.useState(null),B=g.useMemo(()=>Pt(n,t.id),[n,t.id]),{chartData:u,rentals:j}=g.useMemo(()=>{const p=[],v=[];for(const l of B){const c=l.booking,D=`${c.customerInfo?.lastName||""} ${c.customerInfo?.firstName||c.customerName||""}`.trim()||a("dashboard.customerFallback"),I={bookingId:c.id,segKey:l.key,customerName:D,pickupDate:l.startDate,returnDate:l.endDate};if(l.startKm!==null&&l.startDate&&p.push({...I,date:l.startDate,km:l.startKm,type:l.startKind,label:a(qe[l.startKind])}),l.endKind&&l.endKm!==null&&l.endDate&&p.push({...I,date:l.endDate,km:l.endKm,type:l.endKind,label:a(qe[l.endKind])}),l.endKind){const b=pn(l.startDate,l.endDate);v.push({key:l.key,bookingId:c.id,customerName:D,pickupDate:l.startDate,returnDate:l.endDate,startKm:l.startKm,endKm:l.endKm,driven:l.drivenKm,days:b,dailyAvg:l.drivenKm!==null&&b?Math.round(l.drivenKm/b):null,swapped:l.startKind==="swapIn"||l.endKind==="swapOut"})}}return p.sort((l,c)=>l.date.localeCompare(c.date)),v.sort((l,c)=>(c.pickupDate||"").localeCompare(l.pickupDate||"")),{chartData:p,rentals:v}},[B,a]),d=j.filter(p=>p.driven!==null),f=d.reduce((p,v)=>p+v.driven,0),z=d.reduce((p,v)=>p+(v.days||0),0),F=z>0?Math.round(f/z):0,m=new Set(j.map(p=>p.bookingId)).size,A=p=>{h(i?.segKey===p.segKey&&i?.type===p.type?null:p)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"14px"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"6px"},children:[e.jsxs("div",{style:{background:"#F0FDF4",borderRadius:"10px",padding:"10px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"0.6rem",fontWeight:"600",color:"#6B7280"},children:a("vchart.totalRentals")}),e.jsx("div",{style:{fontSize:"1.1rem",fontWeight:"800",color:"#059669"},children:a("vchart.times",{count:m})})]}),e.jsxs("div",{style:{background:"#EFF6FF",borderRadius:"10px",padding:"10px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"0.6rem",fontWeight:"600",color:"#6B7280"},children:a("vchart.totalDriven")}),e.jsxs("div",{style:{fontSize:"1.1rem",fontWeight:"800",color:"#2563EB"},children:[f.toLocaleString(),e.jsx("span",{style:{fontSize:"0.6rem"},children:" km"})]})]}),e.jsxs("div",{style:{background:"#FDF4FF",borderRadius:"10px",padding:"10px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"0.6rem",fontWeight:"600",color:"#6B7280"},children:a("vchart.dailyAvg")}),e.jsxs("div",{style:{fontSize:"1.1rem",fontWeight:"800",color:"#7C3AED"},children:[F.toLocaleString(),e.jsx("span",{style:{fontSize:"0.6rem"},children:" km"})]})]})]}),u.length>=2?e.jsxs("div",{style:{background:"#fff",borderRadius:"12px",border:"1px solid #E5E7EB",padding:"12px 4px 4px 0"},children:[e.jsx("div",{style:{fontSize:"0.78rem",fontWeight:"700",color:"#1A1A2E",marginBottom:"8px",paddingLeft:"12px"},children:a("vchart.kmTrend")}),e.jsx($t,{width:"100%",height:220,children:e.jsxs(Mt,{data:u,margin:{top:5,right:15,left:5,bottom:5},children:[e.jsx(Ht,{strokeDasharray:"3 3",stroke:"#F1F5F9"}),e.jsx(Ot,{dataKey:"date",tick:{fontSize:10,fill:"#9CA3AF"},tickFormatter:p=>p?`${p.slice(5,7)}/${p.slice(8,10)}`:""}),e.jsx(Vt,{tick:{fontSize:10,fill:"#9CA3AF"},tickFormatter:p=>`${(p/1e3).toFixed(0)}k`,width:35}),e.jsx(Gt,{content:e.jsx(cn,{})}),e.jsx(Ut,{type:"monotone",dataKey:"km",stroke:"#2563EB",strokeWidth:2.5,dot:p=>{const{cx:v,cy:l,payload:c}=p,D=Ye(c.type),I=i?.segKey===c.segKey&&i?.type===c.type;return e.jsx("circle",{cx:v,cy:l,r:I?8:5,fill:D?"#059669":"#2563EB",stroke:"#fff",strokeWidth:2,style:{cursor:"pointer",transition:"r 0.2s"},onClick:()=>A(c)},`${c.segKey}-${c.type}`)},activeDot:!1})]})}),e.jsxs("div",{style:{display:"flex",justifyContent:"center",gap:"16px",padding:"4px 0 8px",fontSize:"0.65rem",color:"#6B7280"},children:[e.jsxs("span",{children:["ð¢ ",a("calendar.etPickup")]}),e.jsxs("span",{children:["ðµ ",a("calendar.etReturn")]}
2),e.jsx("span",{style:{color:"#9CA3AF"},children:a("vchart.clickHint")})]})]}):e.jsxs("div",{style:{background:"#fff",borderRadius:"12px",border:"1px solid #E5E7EB",padding:"40px 16px",textAlign:"center",color:"#9CA3AF",fontSize:"0.82rem"},children:[a("vchart.notEnoughData"),e.jsx("div",{style:{fontSize:"0.7rem",marginTop:"4px"},children:a("vchart.notEnoughDataHint")})]}),i&&(()=>{const p=n.find(l=>l.id===i.bookingId);if(!p)return null;const v=j.find(l=>l.key===i.segKey);return e.jsxs("div",{style:{background:"#fff",borderRadius:"12px",border:"2px solid #2563EB",padding:"14px",animation:"fadeIn 0.2s"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"8px"},children:[e.jsxs("div",{style:{fontSize:"0.82rem",fontWeight:"700",color:"#1A1A2E"},children:[i.label," â ",i.customerName]}),e.jsx("button",{onClick:()=>h(null),"aria-label":a("vchart.closeDetail"),style:{background:"none",border:"none",fontSize:"1rem",cursor:"pointer",color:"#9CA3AF",minWidth:"44px",minHeight:"44px"},children:"â"})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",fontSize:"0.75rem",color:"#374151"},children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"#9CA3AF",fontWeight:"600"},children:a("vchart.bookingId")}),e.jsx("br",{}),e.jsxs("span",{translate:"no",children:["#",p.id?.slice(0,10)]})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"#9CA3AF",fontWeight:"600"},children:a("timeline.period")}),e.jsx("br",{}),p.pickupDate," ~ ",p.returnDate]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"#9CA3AF",fontWeight:"600"},children:a("timeline.email")}),e.jsx("br",{}),p.customerInfo?.email||"â"]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"#9CA3AF",fontWeight:"600"},children:a("vchart.phone")}),e.jsx("br",{}),p.customerInfo?.phone||"â"]}),p.paymentType==="corporate"&&p.corporateInfo&&e.jsxs("div",{style:{gridColumn:"1 / -1",background:"#F8FAFC",padding:"8px",borderRadius:"6px",border:"1px solid #E2E8F0",marginTop:"4px"},children:[e.jsx("div",{style:{fontSize:"0.7rem",fontWeight:"700",color:"#1E40AF",marginBottom:"4px"},children:a("vchart.corpInfo")}),e.jsxs("div",{children:[e.jsxs("span",{style:{color:"#9CA3AF",fontWeight:"600"},children:[a("vchart.companyName"),":"]})," ",p.corporateInfo.companyName]}),e.jsxs("div",{children:[e.jsxs("span",{style:{color:"#9CA3AF",fontWeight:"600"},children:[a("timeline.email"),":"]})," ",p.corporateInfo.invoiceEmail]})]}),v&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:"#9CA3AF",fontWeight:"600"},children:a("vchart.startKm")}),e.jsx("br",{}),e.jsx("span",{translate:"no",children:v.startKm!==null?`${v.startKm.toLocaleString()} km`:"â"})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:"#9CA3AF",fontWeight:"600"},children:a("vchart.endKm")}),e.jsx("br",{}),e.jsx("span",{translate:"no",children:v.endKm!==null?`${v.endKm.toLocaleString()} km`:"â"})]}),e.jsx("div",{style:{gridColumn:"1 / -1",background:"#EFF6FF",borderRadius:"8px",padding:"8px",textAlign:"center"},children:v.driven!==null?e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{fontWeight:"800",color:"#2563EB",fontSize:"0.9rem"},translate:"no",children:[v.driven.toLocaleString()," km"]}),e.jsxs("span",{style:{color:"#6B7280",fontSize:"0.7rem"},children:[" ",a("vchart.drivenSummary",{days:v.days??"?",avg:v.dailyAvg?.toLocaleString()||"?"})]})]}):e.jsx("span",{style:{color:"#6B7280",fontSize:"0.72rem",fontWeight:"600"},children:a("vchart.drivenUnknown")})})]})]}),e.jsx("button",{onClick:()=>o(`/staff/pickup/${p.id}`),style:{marginTop:"10px",width:"100%",padding:"10px",minHeight:"44px",borderRadius:"8px",border:"1px solid #D1D5DB",background:"#F8FAFC",fontSize:"0.75rem",fontWeight:"700",cursor:"pointer",color:"#374151"},children:a("vchart.viewBookingFlow")})]})})(),j.length>0&&e.jsxs("div",{style:{background:"#fff",borderRadius:"12px",border:"1px solid #E5E7EB",padding:"14px"},children:[e.jsx("div",{style:{fontSize:"0.82rem",fontWeight:"700",color:"#1A1A2E",marginBottom:"10px"},children:a("vchart.perRentalRecords")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:j.map(p=>e.jsxs("div",{onClick:()=>{const v=u.find(l=>l.segKey===p.key&&Ye(l.type))||u.find(l=>l.segKey===p.key);v&&A(v)},style:{padding:"10px 12px",borderRadius:"10px",background:"#F8FAFC",border:"1px solid #F1F5F9",cursor:"pointer",transition:"background 0.15s",fontSize:"0.78rem",color:"#1A1A2E"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:"700"},children:p.customerName}
2),e.jsxs("span",{style:{fontSize:"0.65rem",color:"#9CA3AF",marginLeft:"6px"},translate:"no",children:["#",p.bookingId?.slice(0,6)]}),p.swapped&&e.jsx("span",{style:{fontSize:"0.65rem",color:"#7C3AED",fontWeight:"700",marginLeft:"6px"},children:a("vchart.swapSegment")})]}),e.jsx("span",{style:{fontWeight:"800",color:p.driven!==null?"#2563EB":"#9CA3AF",fontSize:"0.82rem"},translate:"no",children:p.driven!==null?`${p.driven.toLocaleString()} km`:"â"})]}),e.jsxs("div",{style:{fontSize:"0.68rem",color:"#6B7280",marginTop:"2px"},translate:"no",children:[p.pickupDate||"â"," ~ ",p.returnDate||"â"," · ",p.days??"?",a("active.days","ì¼")," · ",p.startKm!==null?p.startKm.toLocaleString():"â"," â ",p.endKm!==null?p.endKm.toLocaleString():"â"," km"]})]},p.key))})]})]})}function mn({vehicleId:t,logs:a,loading:n,onRefresh:o}){const{t:i}=se(),h=be();if(n)return e.jsx("div",{style:{padding:"40px 0",textAlign:"center",color:"#9CA3AF",fontSize:"0.85rem"},children:i("staffCommon.loading","ë¡ë© ì¤...")});const B={minHeight:"44px",background:"none",border:"1px solid #E5E7EB",borderRadius:"6px",padding:"4px 12px",fontSize:"0.75rem",color:"#6B7280",cursor:"pointer"};return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:"8px",marginBottom:"12px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"0.8rem",color:"#6B7280",fontWeight:"600"},children:i("vdetail.historyCount",{count:a.length})}),e.jsxs("div",{style:{display:"flex",gap:"6px"},children:[t&&e.jsx("button",{type:"button",onClick:()=>h(`/staff/logs?doc=${encodeURIComponent(t)}`),style:B,children:i("vdetail.auditLink")}),e.jsx("button",{type:"button",onClick:o,style:B,children:i("vdetail.historyRefresh")})]})]}),a.length===0?e.jsx("div",{style:{padding:"40px 0",textAlign:"center",color:"#9CA3AF",fontSize:"0.85rem"},children:i("vdetail.historyEmpty")}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:a.map(u=>{const j=ft[u.type]||{icon:"ð",label:u.type,color:"#6B7280"},d=j.labelKey?i(j.labelKey):j.label,f=u.createdAt?.toDate?ut(u.createdAt.toDate()):"",z=u.date||f||"",F=u.type==="tire_change"?d:u.title;return e.jsxs("div",{style:{background:"#fff",borderRadius:"10px",padding:"12px",border:"1px solid #E5E7EB",borderLeft:`4px solid ${j.color}`},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("span",{style:{fontSize:"0.8rem",fontWeight:"700",color:j.color},children:[j.icon," ",d]}),e.jsx("span",{style:{fontSize:"0.7rem",color:"#9CA3AF"},children:z})]}),F&&e.jsx("div",{style:{fontSize:"0.85rem",fontWeight:"600",color:"#1A1A2E",marginTop:"4px"},children:F}),u.description&&e.jsx("div",{style:{fontSize:"0.75rem",color:"#6B7280",marginTop:"2px",whiteSpace:"pre-line"},children:u.description}),e.jsxs("div",{style:{display:"flex",gap:"12px",marginTop:"6px",fontSize:"0.7rem",color:"#9CA3AF",flexWrap:"wrap"},children:[u.km>0&&e.jsxs("span",{children:["ð ",Number(u.km).toLocaleString()," km"]}),u.cost>0&&e.jsxs("span",{children:["ð° â¬",Number(u.cost).toLocaleString()]}),u.staffName&&e.jsxs("span",{children:["ð¤ ",u.staffName]})]})]},u.id)})})]})}const xn=t=>[t?.customerInfo?.lastName,t?.customerInfo?.firstName].filter(Boolean).join(" ").trim()||t?.customerName||"â";function dt({guard:t,busy:a=!1,onGoReturn:n,onConfirm:o,onCancel:i}){const{t:h}=se(),[B,u]=g.useState("");if(!t)return null;const j=t.action==="forceRelease",d=j&&!!t.conflict,f=B.trim(),z=!a&&(!t.requireReason||!!f),F=t.onRentBooking,m=j?h(d?"activity.flows.guard.conflictTitle":"activity.flows.guard.onRentTitle",{id:F?.id}):h("activity.flows.guard.assignedTitle",{count:t.bookings.length}),A=h(j?d?"activity.flows.guard.conflictDesc":"activity.flows.guard.onRentDesc":t.action==="retire"?"activity.flows.guard.assignedDescRetire":"activity.flows.guard.assignedDescCorporate"),p=l=>l.conflict?h("activity.flows.guard.statusConflict"):l.onRent?h("activity.flows.guard.statusOnRent"):h("activity.flows.guard.statusBeforePickup"),v={forceRelease:"activity.flows.guard.btnForce",retire:"activity.flows.guard.btnRetire",endCorporate:"activity.flows.guard.btnEndCorporate"}[t.action];return e.jsxs("section",{className:`vsg ${j?"vsg--danger":"vsg--warn"}`,role:"alert",children:[e.jsx("div",{className:"vsg__title",children:m}),e.jsx("p",{className:"vsg__desc",children:A}
2),e.jsx("ul",{className:"vsg__list",children:t.bookings.map(l=>{const c=l.booking;return e.jsxs("li",{className:"vsg__item",children:[e.jsxs("span",{className:"vsg__item-main",children:["#",c.id," · ",xn(c)]}),e.jsxs("span",{className:"vsg__item-sub",children:[c.pickupDate||"?"," ~ ",c.returnDate||c.dropoffDate||"?"," · ",p(l)]})]},c.id)})}),j&&F&&e.jsx("button",{type:"button",className:"vsg__btn vsg__btn--primary",onClick:()=>n(F.id),children:h(d?"activity.btnReopenConflict":"activity.flows.guard.btnGoReturn",{id:F.id})}),t.requireReason&&e.jsxs("label",{className:"vsg__field",children:[e.jsx("span",{className:"vsg__label",children:h("activity.flows.guard.reasonLabel")}),e.jsx("textarea",{className:"vsg__textarea",value:B,maxLength:kt,rows:2,onChange:l=>u(l.target.value),placeholder:h("activity.flows.guard.reasonPlaceholder")})]}),e.jsxs("div",{className:"vsg__actions",children:[e.jsx("button",{type:"button",className:"vsg__btn",onClick:i,disabled:a,children:h("common.cancel")}),e.jsx("button",{type:"button",className:"vsg__btn vsg__btn--danger",disabled:!z,onClick:()=>o(f),children:h(a?"activity.btnSaving":v)})]})]})}function fn({vehicle:t,onSaved:a}){const{t:n}=se(),o=xe(),i=lt(),h=be(),{bookings:B=[]}=Re()||{},{byId:u,loading:j}=Le(),d=i.state?.preLogType||"maintenance",[f,z]=g.useState(d),[F,m]=g.useState(!1),[A,p]=g.useState(!1),[v,l]=g.useState(null),[c,D]=g.useState(null),I=de(),[b,O]=g.useState({title:"",description:"",date:I,cost:0,km:t?.currentKm||"",newStatus:t?.status||"available",oilLiters:""}),E=o?.name||"",H=(y,C)=>{O(W=>({...W,[y]:C})),(y==="km"||y==="newStatus")&&(l(null),D(null))},ae=y=>{z(y),l(null),D(null)},P=at(u.get(String(t?.id)),t),N=f==="status_change"?St(t?.status,b.newStatus):null,T=c&&c===N?we(c,t.id,B):null,_=!!N&&j,U=[{value:"maintenance",label:n("vaction.tMaintenance"),color:"#3B82F6"},{value:"inspection",label:n("vaction.tInspection"),color:"#059669"},{value:"damage",label:n("vaction.tDamage"),color:"#DC2626"},{value:"km_update",label:"ð KM",color:"#8B5CF6"},{value:"status_change",label:n("vaction.tStatus"),color:"#F59E0B"}],Y=[{value:"oil_topup",label:n("vaction.tOil"),color:"#92400E"},{value:"battery_replace",label:n("vaction.tBatteryReplace"),color:"#7C3AED"},{value:"battery_drain",label:n("vaction.tBatteryDrain"),color:"#DC2626"},{value:"coolant",label:n("vaction.tCoolant"),color:"#0EA5E9"},{value:"wiper",label:n("vaction.tWiper"),color:"#6B7280"},{value:"brake_pad",label:n("vaction.tBrakePad"),color:"#B91C1C"}],q=Y.some(y=>y.value===f),J=t?.status||"available",ee={hasOnRentBooking:Ct(B,t?.id)},{options:te,repairVia:r}=Ft(J,ee),S=f==="status_change"?rt(J,b.newStatus,ee):null,x=S?.input==="reason",w=Number(t?.currentKm)||0,V=Number(b.km)>0&&Number(b.km)<w,X={marginTop:"6px",fontSize:"0.75rem",fontWeight:"600",lineHeight:1.45,color:"color-mix(in srgb, var(--color-warning) 70%, var(--color-primary))"},ne={margin:0,padding:"10px 12px",borderRadius:"var(--radius-md)",border:"1.5px solid var(--color-warning)",background:"color-mix(in srgb, var(--color-warning) 8%, var(--color-white))",fontSize:"0.8rem",fontWeight:"600",lineHeight:1.5,color:"var(--color-text)"},L=v?v.issue==="sameOnRent"?n("activity.warnSameOnRent",{km:w.toLocaleString()}):n("activity.warnJump",{diff:(v.km-w).toLocaleString()}):"",K=()=>{if(!b.title.trim()&&f!=="km_update"&&f!=="status_change"&&!q){alert(n("vaction.titleRequired"));return}if(f==="km_update"&&!(Number(b.km)>0)){alert(n("activity.errKmRequired"));return}if(f==="status_change"){if(b.newStatus===J||!S||S.input==="repair"){alert(n("vaction.statusSame"));return}if(x&&!b.description.trim()){alert(n("vaction.reasonRequired"));return}}if(_||F)return;const y=Number(b.km),C=Dt({vehicle:t,logType:f,km:b.km,onRent:P});if(C&&!(v?.issue===C&&v.km===y)){l({issue:C,km:y});return}if(N&&we(N,t.id,B)){D(N);return}G()},G=async(y=null,C="")=>{m(!0);try{const W={type:f,date:b.date,title:b.title||U.find(s=>s.value===f)?.label||f,description:b.description,km:Number(b.km)||0,staffName:E};if((f==="maintenance"||q)&&(W.cost=Number(b.cost)||0),f==="damage"&&(W.resolved=!1,W.severity="minor"),f==="status_change"){const s=b.description.trim().slice(0,Ae);W.description=[`${t.status} â ${b.newStatus}`,s?`ì¬ì : ${s}
2`:"",...Be(y,C)].filter(Boolean).join(" | ")}if(f==="oil_topup"){const s=Number(b.oilLiters)||0;W.title=`ìì§ì¤ì¼ ë³´ì¶©: ${s}L`,W.oilLiters=s,W.description=`${s}L ë³´ì¶© (${Number(b.km).toLocaleString()} km)${b.description?" â "+b.description:""}`}f==="battery_replace"&&(W.title=b.title||"ë°°í°ë¦¬ êµì²´"),f==="battery_drain"&&(W.title="ë°°í°ë¦¬ ë°©ì "),f==="coolant"&&(W.title=b.title||"ëê°ì ë³´ì¶©"),f==="wiper"&&(W.title=b.title||"ìì´í¼ êµì²´"),f==="brake_pad"&&(W.title=b.title||"ë¸ë ì´í¬í¨ë êµì²´");const{updates:pe,seenSource:fe}=Bt({vehicle:t,logType:f,km:b.km,date:b.date,newStatus:b.newStatus,today:de()}),ie=fe?{...pe,...ye(fe,E)}:pe;await ve(()=>me(t,ie,W,E),p),l(null),D(null),alert(n("vaction.saved")),a&&a()}catch(W){alert(n("dashboard.saveFailed")+W.message)}finally{m(!1)}};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"14px"},children:[e.jsx("div",{style:{fontSize:"0.85rem",fontWeight:"700",color:"#1A1A2E"},children:n("vaction.newLog")}),e.jsx("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:U.map(y=>e.jsx("button",{onClick:()=>ae(y.value),style:{padding:"10px 14px",borderRadius:"10px",border:"none",cursor:"pointer",fontSize:"0.8rem",fontWeight:"700",minHeight:"44px",background:f===y.value?y.color:"#F1F5F9",color:f===y.value?"#fff":"#64748B"},children:y.label},y.value))}),e.jsx("div",{style:{fontSize:"0.72rem",fontWeight:"700",color:"#6B7280",marginBottom:"-6px"},children:n("dashboard.partsSection")}),e.jsx("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:Y.map(y=>e.jsx("button",{onClick:()=>ae(y.value),style:{padding:"8px 12px",borderRadius:"10px",border:"none",cursor:"pointer",fontSize:"0.72rem",fontWeight:"700",minHeight:"40px",background:f===y.value?y.color:"#F1F5F9",color:f===y.value?"#fff":"#64748B"},children:y.label},y.value))}),e.jsxs(ue,{label:n("vaction.fDate"),children:[e.jsx("input",{type:"date",value:b.date,onChange:y=>H("date",y.target.value),style:ce}),b.date&&b.date!==I&&e.jsx("div",{style:X,children:n("activity.flows.notTodayNote")})]}),e.jsxs(ue,{label:n("vaction.fKm"),children:[e.jsx("input",{type:"number",inputMode:"numeric",value:b.km,onChange:y=>H("km",y.target.value),style:ce}),P&&f==="km_update"&&e.jsx("div",{style:X,children:n("activity.kmHintRent")}),V&&e.jsx("div",{style:X,children:n("activity.flows.kmLowerNote",{km:w.toLocaleString()})})]}),f!=="km_update"&&f!=="status_change"&&e.jsxs(e.Fragment,{children:[e.jsx(ue,{label:n("vaction.fTitle"),children:e.jsx("input",{type:"text",value:b.title,onChange:y=>H("title",y.target.value),placeholder:n(f==="maintenance"?"vaction.phMaint":f==="damage"?"vaction.phDamage":"vaction.phInspection"),style:ce})}),e.jsx(ue,{label:n("vaction.fDesc"),children:e.jsx("textarea",{value:b.description,onChange:y=>H("description",y.target.value),rows:3,placeholder:n(f==="damage"?"vaction.phDamageDesc":"vaction.phDesc"),style:{...ce,resize:"vertical"}})})]}),(f==="maintenance"||q)&&e.jsx(ue,{label:n("vaction.fCost"),children:e.jsx("input",{type:"number",value:b.cost,onChange:y=>H("cost",y.target.value),placeholder:"0",style:ce})}),f==="oil_topup"&&e.jsx(ue,{label:n("vaction.fLiters"),children:e.jsx("input",{type:"number",step:"0.1",value:b.oilLiters,onChange:y=>H("oilLiters",y.target.value),placeholder:n("vaction.phLiters"),style:ce})}),f==="status_change"&&e.jsxs(ue,{label:n("vaction.fNewStatus"),children:[e.jsxs("select",{value:b.newStatus,onChange:y=>H("newStatus",y.target.value),style:ce,children:[e.jsx("option",{value:J,children:n("vaction.statusCurrent",{status:Ne(n,J)})}),te.map(y=>e.jsx("option",{value:y,children:Ne(n,y)},y))]}),r&&e.jsx("div",{style:{marginTop:"6px",fontSize:"0.75rem",lineHeight:1.45,color:"var(--color-text-secondary)"},children:n("vaction.repairViaInfo",{tab:n("vdetail.tabInfo"),button:n(J==="maintenance"?"vdetail.maintDoneBtn":"vdetail.repairDone")})})]}),f==="status_change"&&x&&e.jsx(ue,{label:n("vaction.fReason"),children:e.jsx("textarea",{value:b.description,onChange:y=>H("description",y.target.value),rows:2,maxLength:Ae,placeholder:n("vaction.phReason"),style:{...ce,resize:"vertical"}})}
2),e.jsxs("div",{style:{fontSize:"0.75rem",color:"#9CA3AF"},children:[n("vaction.recorder"),": ",E]}),_&&e.jsx("div",{style:X,role:"status",children:n("activity.flows.guard.loading")}),v&&e.jsx("p",{style:ne,role:"alert",children:L}),A&&e.jsx("div",{style:X,role:"status",children:n("activity.savePending")}),T?e.jsx(dt,{guard:T,busy:F,onGoReturn:y=>h(`/staff/return/${encodeURIComponent(y)}`),onConfirm:y=>G(T,y),onCancel:()=>D(null)},`${T.action}-${t.id}`):e.jsx("button",{onClick:K,disabled:F||_,style:{width:"100%",padding:"14px",borderRadius:"12px",border:"none",background:"#1A1A2E",color:"#fff",fontSize:"0.95rem",fontWeight:"700",cursor:"pointer",minHeight:"52px",opacity:F||_?.6:1},children:n(F?"dashboard.savingShort":v?"activity.btnConfirmSave":"vaction.saveLog")})]})}const Xe=t=>et.find(a=>De(a.v)===t);function gn({vehicle:t,onCancel:a,onComplete:n,onGoDamageTab:o}){const{t:i}=se(),B=xe()?.name||"",[u,j]=g.useState(0),[d,f]=g.useState(t.currentKm||0),z=Ee(t),[F,m]=g.useState(z||""),[A,p]=g.useState(t.lastFuelLevel||"8/8"),v=Et(t),[l,c]=g.useState(()=>v?"":Se(t)),[D,I]=g.useState(()=>{if(t.equipment&&typeof t.equipment=="object")return{...t.equipment};const x={};return ke.forEach(w=>{x[w.key]=!0}),x}),[b,O]=g.useState(!1),[E,H]=g.useState(!1),[ae,P]=g.useState(!1),N=Number(t.currentKm)||0,T=Number(d)>0&&Number(d)<N,_=()=>{if(!Pe({prevKm:t.currentKm,km:d,today:de()}).valid){P(!0);return}j(2)},[U,Y]=g.useState([]),[q,J]=g.useState(!0),[ee,te]=g.useState(!1);g.useEffect(()=>{async function x(){try{const w=await Qe(t.id),V=Yt(w);if(V.length===0&&t.damages){const X=t.damages.filter(ne=>ne.status!=="resolved");Y(X)}else Y(V)}catch(w){console.error(w),te(!0)}J(!1)}x()},[t.id,t.damages]);const r=async()=>{const x=de(),w=Pe({prevKm:t.currentKm,km:d,today:x});if(!w.valid){P(!0),j(1);return}if(!b){O(!0);try{const V=ke.filter(L=>!D[L.key]).map(L=>L.label),X=[`KM: ${d}`,F?`ì ë¹KM: ${F}`:"",`ì°ë£: ${A}`,l?`íì´ì´: ${Xe(l)?.l||l}`:"","ì¸ê´: ìì íìì ë³ë ê´ë¦¬",V.length>0?`ë¯¸ë¹ ë¹í: ${V.join(", ")}`:""].filter(Boolean).join(" | "),ne={status:"ready",...w.updates,lastInspectionDate:x,equipment:D,lastFuelLevel:A,...ye("prepare",B),...wt()};if(F&&Number(F)!==z&&Object.assign(ne,Ke(F)),l){const L=it(t,l,{km:w.effectiveKm,date:x});L.update&&Object.assign(ne,L.update)}await ve(()=>me(t,ne,[{type:"inspection",title:"ë í¸ ì¤ë¹ ì ê² ìë£",date:x,description:X,km:Number(d),staffName:B,inspectionData:{equipment:D,fuel:A,tireType:l||null,maintenanceKm:F?Number(F):null}},{type:"status_change",title:"ê°ì© â ë°°ì ë기",date:x,description:`ë í¸ ì¤ë¹ ì ê² ìë£ (ì¤íí: ${B})`,km:Number(d),staffName:B}],B),H),alert(i("vprep.done")),n&&n()}catch(V){alert(i("dashboard.saveFailed")+V.message)}O(!1)}},S=[{num:0,label:i("vprep.step0")},{num:1,label:i("vprep.step1")},{num:2,label:i("vprep.step2")},{num:3,label:i("vprep.step3")}];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.jsxs("div",{style:{background:"linear-gradient(135deg, #8B5CF6, #6D28D9)",borderRadius:"12px",padding:"14px 16px",color:"#fff"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"10px"},children:[e.jsx("span",{style:{fontSize:"0.85rem",fontWeight:"700"},children:i("vprep.title")}),e.jsx("button",{onClick:a,style:{background:"rgba(255,255,255,0.2)",border:"none",color:"#fff",padding:"4px 12px",borderRadius:"6px",fontSize:"0.75rem",cursor:"pointer",fontWeight:"600"},children:i("common.cancel","ì·¨ì")})]}),e.jsx("div",{style:{display:"flex",gap:"4px"},children:S.map(x=>e.jsxs("div",{style:{flex:1,textAlign:"center"},children:[e.jsx("div",{style:{height:"4px",borderRadius:"2px",marginBottom:"4px",background:u>=x.num?"#fff":"rgba(255,255,255,0.3)"}}),e.jsx("span",{style:{fontSize:"0.55rem",opacity:u>=x.num?1:.5},children:x.label})]},x.num))})]}),u===0&&e.jsxs(e.Fragment,{children:[e.jsxs(Z,{title:i("vprep.cardDamage"),children:[e.jsx("div",{style:{padding:"8px 0 16px 0"},children:q?e.jsx("div",{style:{textAlign:"center",padding:"20px",color:"#9
2CA3AF",fontSize:"0.8rem"},children:i("vprep.loadingDamage")}):ee?e.jsx("div",{style:{padding:"12px",borderRadius:"10px",background:"var(--color-surface-light)",color:"var(--color-warning)",fontSize:"0.82rem",fontWeight:"600"},children:i("vprep.damageLoadFailed")}):e.jsx(qt,{markers:U,emptyMessage:i("vprep.noUnresolved")})}),e.jsx("div",{style:{textAlign:"center",marginBottom:"8px",marginTop:"8px"},children:e.jsx("button",{onClick:o,style:{padding:"10px 20px",borderRadius:"8px",border:"1px solid #FECACA",background:"#FEF2F2",color:"#DC2626",fontSize:"0.8rem",fontWeight:"700",cursor:"pointer"},children:i("vprep.goRecordDamage")})})]}),e.jsx("button",{onClick:()=>j(1),style:{...ge,background:"#8B5CF6"},children:i("vprep.startInspection")})]}),u===1&&e.jsxs(e.Fragment,{children:[e.jsxs(Z,{title:i("vprep.cardKm"),children:[e.jsx("input",{type:"number",inputMode:"numeric",value:d,onChange:x=>{f(x.target.value),P(!1)},style:ce,placeholder:i("vinfo.currentKm"),"aria-invalid":ae||void 0}),t.currentKm&&e.jsxs("div",{style:{fontSize:"0.7rem",color:"#9CA3AF",marginTop:"4px"},children:[i("vprep.existingRecord"),": ",t.currentKm?.toLocaleString()," km"]}),ae&&e.jsx("div",{role:"alert",style:{marginTop:"6px",fontSize:"0.78rem",fontWeight:"700",color:"var(--color-error)"},children:i("activity.errKmRequired")}),T&&e.jsx("div",{style:{marginTop:"6px",fontSize:"0.75rem",fontWeight:"600",lineHeight:1.45,color:"color-mix(in srgb, var(--color-warning) 70%, var(--color-primary))"},children:i("activity.flows.kmLowerNote",{km:N.toLocaleString()})})]}),e.jsxs(Z,{title:i("vprep.cardMaintKm"),children:[e.jsx("input",{type:"number",value:F,onChange:x=>m(x.target.value),style:ce,placeholder:i("vprep.maintKmPlaceholder")}),z>0&&e.jsxs("div",{style:{fontSize:"0.7rem",color:"#9CA3AF",marginTop:"4px"},children:[i("vprep.existingRecord"),": ",z.toLocaleString()," km"]})]}),e.jsxs(Z,{title:i("vprep.cardFuel"),children:[e.jsx("div",{style:{display:"flex",gap:"4px",flexWrap:"wrap"},children:Ce.map(x=>e.jsx("button",{onClick:()=>p(x.v),style:{padding:"10px 0",borderRadius:"8px",border:"none",cursor:"pointer",fontSize:"0.75rem",fontWeight:"700",minHeight:"44px",flex:"1 0 calc(11.1% - 4px)",minWidth:"36px",background:A===x.v?"#8B5CF6":"#F1F5F9",color:A===x.v?"#fff":"#64748B",textAlign:"center"},children:x.l},x.v))}),e.jsx("div",{style:{marginTop:"8px",background:"#E5E7EB",borderRadius:"6px",height:"16px",overflow:"hidden",position:"relative"},children:e.jsx("div",{style:{height:"100%",borderRadius:"6px",width:`${Ce.findIndex(x=>x.v===A)/8*100}%`,background:Ce.findIndex(x=>x.v===A)<=2?"#EF4444":Ce.findIndex(x=>x.v===A)<=4?"#F59E0B":"#22C55E",transition:"width 0.3s"}})})]}),e.jsxs(Z,{title:i("vprep.cardTire"),children:[v&&e.jsx("div",{style:{fontSize:"0.75rem",fontWeight:"600",lineHeight:1.45,color:"var(--color-warning)",marginBottom:"6px"},children:i("vprep.tireConflictHint")}),e.jsx("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap"},children:et.map(x=>e.jsx("button",{onClick:()=>c(De(x.v)),style:{flex:1,padding:"12px 8px",borderRadius:"8px",border:"none",cursor:"pointer",fontSize:"0.8rem",fontWeight:"700",minHeight:"48px",background:l===De(x.v)?"#8B5CF6":"#F1F5F9",color:l===De(x.v)?"#fff":"#64748B"},children:i(x.lKey)},x.v))})]}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("button",{onClick:()=>j(0),style:{...ge,background:"#6B7280",flex:1},children:i("vprep.prevBtn")}),e.jsx("button",{onClick:_,style:{...ge,background:"#8B5CF6",flex:2},children:i("vprep.nextEquipBtn")})]}),t.damages&&t.damages.length>0&&e.jsxs(Z,{title:i("vprep.cardDamageRef"),children:[e.jsxs("div",{style:{fontSize:"0.72rem",color:"#D97706",marginBottom:"8px",display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{children:"â¹ï¸"})," ",i("vprep.damageEditHint")]}),t.damages.map((x,w)=>e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"8px 0",borderBottom:"1px solid #F3F4F6"},children:[e.jsxs("div",{children:[e.jsx("span",{style:{fontSize:"0.8rem",fontWeight:"700",color:"#1A1A2E"},children:x.zone||x.location||"?"}),e.jsx("span",{style:{fontSize:"0.72rem",color:"#64748B",marginLeft:"6px"},children:x.type||""})]}),e.jsx("span",{style:{fontSize:"0.7rem",fontWeight:"700",padding:"2px 8px",borderRadius:"10px",background:x.status==="resolved"?"#D1FAE5":"#FEE2E2",color:x.status==="resolved"?"#065F46":"#991B1B"},children:x.status==="resolved"?i("vprep.repaired"):x.severity||i("vprep.unrepaired")})]},w))]})]}),u===2&&e.jsxs(e.Fragment,{children:[e.jsx(Z,{title:i("vprep.cardEquip"),children:ke.map(x=>e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 0",borderBottom:"1px solid #F3F4F6"},children:[e.jsx("span",{style:{fontSize:"0.8rem",fontWeight:"600",color:"#1A1A2E"},children:i(x.labelKey)}),e.jsx("button",{onClick:()=>I(w=>({...w,[x.key]:!w[x.key]})),style:{padding:"6px 16px",borderRadius:"6px",border:"none",cursor:"pointer",fontSize:"0.75rem",fontWeight:"700",minHeight:"36px",background:D[x.key]?"#D1FAE5":"#FEE2E2",color:D[x.key]?"#065F46":"#991B1B"},children:D[x.key]?i("vinfo.yes"):i("vinfo.no")})]},x.key))}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("button",{onClick:()=>j(1),style:{...ge,background:"#6B7280",flex:1},children:i("vprep.prevBtn")}),e.jsx("button",{onClick:()=>j(3),style:{...ge,background:"#8B5CF6",flex:2},children:i("vprep.nextFinalBtn")})]})]}),u===3&&e.jsxs(e.Fragment,{children:[e.jsx(Z,{title:i("vprep.cardSummary"),children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:[e.jsx(he,{label:i("fleet.colName"),value:`${t.licensePlate} (${t.name})`}
2),e.jsx(he,{label:"KM",value:`${Number(d).toLocaleString()} km`}),F&&e.jsx(he,{label:i("vprep.cardMaintKmShort"),value:`${Number(F).toLocaleString()} km`}),e.jsx(he,{label:i("fleet.colFuel"),value:A}),e.jsx(he,{label:i("fleet.colTireShort"),value:(()=>{const x=Xe(l);return i(x?x.lKey:"tires.tireMissing")})()}),e.jsx(he,{label:i("vprep.equipShort"),value:`${ke.filter(x=>D[x.key]).length}/${ke.length}`}),e.jsx(he,{label:i("vprep.inspector"),value:B})]})}),E&&e.jsx("div",{role:"status",style:{padding:"10px 12px",borderRadius:"10px",background:"var(--color-surface-light)",color:"var(--color-text-secondary)",fontSize:"0.8rem",fontWeight:"600"},children:i("activity.savePending")}),e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsx("button",{onClick:()=>j(2),style:{...ge,background:"#6B7280",flex:1},children:i("vprep.prevBtn")}),e.jsx("button",{onClick:r,disabled:b,style:{...ge,flex:2,background:b?"#9CA3AF":"linear-gradient(135deg, #8B5CF6, #6D28D9)"},children:i(b?"dashboard.savingShort":"vprep.submitBtn")})]})]})]})}function hn({vehicle:t,mode:a="damage",onCancel:n,onComplete:o}){const{t:i}=se(),B=xe()?.name||"",u=a==="maintenance",[j,d]=g.useState(""),[f,z]=g.useState(""),[F,m]=g.useState(()=>{const S=Ee(t);return S>0?String(S):""}),[A,p]=g.useState(!1),[v,l]=g.useState(!1),[c,D]=g.useState(!1),[I,b]=g.useState(""),[O,E]=g.useState([]),[H,ae]=g.useState(u?t.id:null),[P,N]=g.useState(!1),T=H!==t.id,[_,U]=g.useState(0);g.useEffect(()=>{if(u)return;const S=t.id;let x=!0;return(async()=>{try{const w=await Ze(S);if(!x)return;E(w),N(!1)}catch(w){if(console.error("Load damage logs failed:",w),!x)return;E([]),N(!0)}ae(S)})(),()=>{x=!1}},[t.id,u,_]);const Y=()=>{ae(null),U(S=>S+1)},q=!u&&(T||P),J=async()=>{if(A||q)return;if(!j.trim()){b(i("vrepair.descRequired"));return}const S=nt(F);if(u&&Number.isNaN(S)){b(i("vrepair.nextKmInvalid"));return}if(b(""),!c){D(!0);return}p(!0);const x=de(),w=new Date().toISOString(),V={status:"available",...ye("repair",B)};u||(V.lastDamageZones={}),u&&S!==null&&S!==Ee(t)&&Object.assign(V,Ke(S));const X=u?{type:"maintenance",title:"ì ë¹ ìë£",date:x,description:[j.trim(),S?`ë¤ì ì ë¹ KM: ${S.toLocaleString()} km`:""].filter(Boolean).join(" | "),cost:Number(f)||0,km:t.currentKm||0,staffName:B,statusFrom:t.status||""}:{type:"maintenance",title:"ìì ì리 ìë£",date:x,description:j,cost:Number(f)||0,km:t.currentKm||0,staffName:B,resolvedDamageCount:O.length},ne=u?[]:O.map(G=>({id:G.id,updates:{resolved:!0,resolvedAt:w,resolvedBy:B,repairNotes:j}}));try{await ve(()=>me(t,V,X,B,{logUpdates:ne}),l)}catch(G){alert(i("vrepair.failed")+G.message),p(!1);return}let L=!0;const K={...t,status:"available"};if(It(K))try{await ot(K,B)}catch(G){console.error("[VehicleRepairFlow] damage flag check failed:",G),L=!1}alert(i(L?u?"vrepair.maintDone":"vrepair.done":"vdamage.flagCheckFailed")),p(!1),o&&o()},ee={background:"#fff",borderRadius:"12px",padding:"14px",border:"1px solid #E5E7EB"},te={width:"100%",padding:"12px",borderRadius:"8px",border:"1px solid #E5E7EB",fontSize:"16px",boxSizing:"border-box",minHeight:"44px"},r={padding:"10px 12px",borderRadius:"10px",fontSize:"0.8rem",fontWeight:"600",lineHeight:1.5,whiteSpace:"pre-line"};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"12px"},children:[e.jsxs("div",{style:{...ee,background:u?"#FFFBEB":"#FEF2F2",borderColor:u?"#FDE68A":"#FECACA"},children:[e.jsx("div",{style:{fontWeight:"800",fontSize:"0.95rem",color:u?"#92400E":"#991B1B",marginBottom:"8px"},children:i(u?"vrepair.maintTitle":"vdetail.repairDone")}),e.jsx("div",{style:{fontSize:"0.78rem",color:"#6B7280"},children:u?i("vrepair.maintDesc"):i("vrepair.desc",{count:O.length})})]}),!u&&(T?e.jsx("div",{style:{textAlign:"center",padding:"20px",color:"#9CA3AF"},children:i("staffCommon.loading","ë¡ë© ì¤...")}):P?e.jsxs("div",{role:"alert",style:{...ee,background:"#FEF2F2",borderColor:"#FECACA",color:"#991B1B",fontSize:"0.8rem",lineHeight:1.5},children:[e.jsx("div",{children:i("vrepair.loadFailed")}),e.jsx("button",{type:"button",onClick:Y,style:{marginTop:"8px",minHeight:"44px",padding:"0 14px",borderRadius:"8px",border:"1px solid #FECACA",background:"#fff",color:"#991B1B",fontSize:"0.78rem",fontWeight:"700",cursor:"pointer"},children:i("vdamage.loadRetry")})]}):O.length>0&&e.jsxs("div",{style:ee,children:[e.jsx("div",{style:{fontWeight:"700",fontSize:"0.82rem",color:"#1A1A2E",marginBottom:"8px"},children:i("vrepair.unresolvedCount",{count:O.length})}),O.map((S,x)=>e.jsxs("div",{style:{padding:"8px 0",borderBottom:x<O.length-1?"1px solid #F1F5F9":"none"},children:[e.jsx("div",{style:{fontSize:"0.82rem",fontWeight:"600"},children:S.title}),e.jsxs("div",{style:{fontSize:"0.72rem",color:"#6B7280"},children:[S.date," · ",S.description?.substring(0,60),S.description?.length>60?"...":""]}),S.bookingId&&e.jsxs("div",{style:{fontSize:"0.65rem",color:"#9
2CA3AF"},children:[i("vrepair.bookingRef"),": #",String(S.bookingId).slice(0,8)]})]},S.id))]})),e.jsxs("div",{style:ee,children:[e.jsxs("div",{style:{fontWeight:"700",fontSize:"0.82rem",color:"#1A1A2E",marginBottom:"8px"},children:[i(u?"vrepair.maintDescLabel":"vrepair.repairDesc")," *"]}),e.jsx("textarea",{value:j,onChange:S=>{d(S.target.value),D(!1),b("")},rows:3,placeholder:i(u?"vrepair.maintDescPlaceholder":"vrepair.repairDescPlaceholder"),style:{...te,resize:"vertical",fontFamily:"inherit"}})]}),e.jsxs("div",{style:ee,children:[e.jsx("div",{style:{fontWeight:"700",fontSize:"0.82rem",color:"#1A1A2E",marginBottom:"8px"},children:i("vrepair.repairCost")}),e.jsx("input",{type:"number",inputMode:"decimal",value:f,onChange:S=>{z(S.target.value),D(!1)},placeholder:"0",style:te})]}),u&&e.jsxs("div",{style:ee,children:[e.jsx("div",{style:{fontWeight:"700",fontSize:"0.82rem",color:"#1A1A2E",marginBottom:"8px"},children:i("vinfo.nextMaintKm")}),e.jsx("input",{type:"text",inputMode:"numeric",value:F,onChange:S=>{m(S.target.value),D(!1),b("")},placeholder:i("vprep.maintKmPlaceholder"),style:te})]}),I&&e.jsx("div",{role:"alert",style:{...r,background:"#FEF2F2",color:"#991B1B"},children:I}),c&&!I&&e.jsx("div",{role:"alert",style:{...r,border:"1.5px solid var(--color-warning)",background:"var(--color-surface-light)",color:"var(--color-text)"},children:u?i("vrepair.maintConfirm",{plate:t.licensePlate}):i("vrepair.confirm",{plate:t.licensePlate})}),v&&e.jsx("div",{role:"status",style:{...r,background:"var(--color-surface-light)",color:"var(--color-text-secondary)"},children:i("activity.savePending")}),e.jsxs("div",{style:{display:"flex",gap:"8px",marginTop:"4px"},children:[e.jsx("button",{onClick:n,disabled:A,style:{flex:1,padding:"14px",borderRadius:"12px",border:"1px solid #E5E7EB",background:"#fff",fontSize:"0.85rem",fontWeight:"700",cursor:"pointer",color:"#6B7280",minHeight:"48px"},children:i("common.cancel","ì·¨ì")}),e.jsx("button",{onClick:J,disabled:A||q,style:{flex:2,padding:"14px",borderRadius:"12px",border:"none",background:A||q?"#9CA3AF":"#059669",color:"#fff",fontSize:"0.85rem",fontWeight:"700",cursor:A||q?"not-allowed":"pointer",minHeight:"48px"},children:i(A?"active.processing":c?"vrepair.confirmBtn":u?"vrepair.maintSubmitBtn":"vrepair.submitBtn")})]})]})}function vn({vehicle:t,result:a,onCheck:n}){const{t:o}=se(),i=be(),[h,B]=g.useState(!1),[u,j]=g.useState("");if(!a||a.kind==="retired")return null;const d=Xt(o,a),f=Jt(o,a),z=a.booking||null,F=z?z.returnDate||z.dropoffDate||"â":"",m=Qt(a),A=async()=>{if(!h){B(!0),j("");try{await mt(t,xe()?.name||"staff")}catch(p){console.error("[VehicleActivityPanel] release failed:",p),j(o("activity.errSave"))}finally{B(!1)}}};return e.jsxs("section",{className:`vap vap--${a.tone||"muted"}`,"aria-label":o("activity.colLastSeen"),children:[e.jsxs("div",{className:"vap__head",children:[e.jsx("span",{className:"vap__title",children:d}),a.lease&&e.jsx("span",{className:"vap__tag",children:o("activity.leaseTag")})]}),e.jsx("p",{className:"vap__line",children:Zt(o,a)}),z&&e.jsx("p",{className:"vap__line vap__line--strong",children:m?o("activity.rentLine",{id:z.id,days:m,date:F}):o("activity.rentLineNoDays",{id:z.id,date:F})}),z&&a.statusBehind&&e.jsx("p",{className:"vap__line vap__line--strong",children:o("activity.statusBehindLine",{id:z.id})}),a.conflictBooking&&e.jsx("p",{className:"vap__line vap__line--strong",children:o("activity.conflictLine",{id:a.conflictBooking.id,date:a.conflictBooking.returnDate||a.conflictBooking.dropoffDate||"â"})}),a.returnPending&&e.jsx("p",{className:"vap__line vap__line--strong",children:o("activity.returnPendingLine",{id:a.returnPending.id})}),a.kind==="parked"&&e.jsxs("p",{className:"vap__line vap__line--strong",children:[o("activity.parkedLine",{date:a.parkedUntil,reason:en(o,a.parkedReason)}),a.parkedNote&&e.jsx("span",{className:"vap__note",children:a.parkedNote})]}),f&&e.jsx("p",{className:"vap__desc",children:f}),e.jsxs("div",{className:"vap__actions",children:[a.conflictBooking&&e.jsx("button",{type:"button",className:"vap__btn vap__btn--primary",onClick:()=>i(`/staff/return/${encodeURIComponent(a.conflictBooking.id)}`),children:o("activity.btnReopenConflict",{id:a.conflictBooking.id})}),e.jsx("button",{type:"button",className:`vap__btn${a.conflictBooking?"":" vap__btn--primary"}`,onClick:n,children:o("activity.btnCheckNow")}),a.kind==="parked"&&e.jsx("button",{type:"button",className:"vap__btn",onClick:A,disabled:h,children:o(h?"activity.btnSaving":"activity.btnUnpark")})]}),u&&e.jsx("p",{className:"vap__error",role:"alert",children:u})]})}const Je=t=>t?String(t).slice(5):"",yn={kgfb:"fleet.colKgfb",casco:"fleet.colCasco",inspection:"fleet.colInspection"};function bn({vehicle:t,bookings:a=[],today:n,onGoTab:o,onNavigate:i}){const{t:h}=se(),B=`${t.id}|${t.hasDamage?1:0}|${t.status||""}`,[u,j]=g.useState({key:null,count:0,failed:!1});g.useEffect(()=>{let c=!0;return(async()=>{try{const D=await Ze(t.id);c&&j({key:B,count:D.length,failed:!1})}catch(D){console.error("[VehicleSummaryCard] damage count failed:",D),c&&j({key:B,count:0,failed:!0})}})(),()=>{c=!1}},[t.id,B]);const{current:d,next:f,tire:z}=At(t,a,n),F=Rt(t,c=>tn(c,nn())),m=u.key!==B,A=t.status==="damaged",p=c=>c<0?h("fleet.daysOver",{days:-c}):c===0?h("fleet.dueToday"):h("fleet.daysLeft",{days:c}),v=[];
2if(d?.conflict)v.push({key:"now",tone:"alert",label:h("vdetail.sumNow"),value:h("vdetail.sumConflict",{id:d.booking.id}),link:{text:h("vdetail.sumGoReopen"),onClick:()=>i(`/staff/return/${encodeURIComponent(d.booking.id)}`)}});else if(d){const c=d.booking;v.push({key:"now",tone:"info",label:h("vdetail.sumNow"),value:h("vdetail.sumOnRent",{name:Oe(c)||c.customerName||h("dashboard.customerFallback"),date:Je(c.returnDate||c.dropoffDate),time:c.returnTime||""}),tag:d.lease?h("vdetail.sumLeaseTag"):"",link:d.lease?null:{text:h("vdetail.sumGoReturn"),onClick:()=>i(`/staff/return/${encodeURIComponent(c.id)}`)}})}else v.push({key:"now",label:h("vdetail.sumNow"),value:h("vdetail.sumNotOnRent")});v.push(f?{key:"next",label:h("vdetail.sumNext"),value:h("vdetail.sumNextValue",{id:f.id,date:Je(f.pickupDate),time:f.pickupTime||"",name:Oe(f)||f.customerName||h("dashboard.customerFallback")}),link:{text:h("vdetail.sumGoPickup"),onClick:()=>i(st(f,f.id))}}:{key:"next",label:h("vdetail.sumNext"),value:h("vdetail.sumNoNext")}),v.push({key:"prep",label:h("vdetail.sumPrep"),value:t.lastInspectionDate?h("vdetail.sumPrepValue",{date:t.lastInspectionDate,fuel:t.lastFuelLevel||"â"}):h("vdetail.sumNoPrep")});const l=m?h("staffCommon.loading","ë¡ë© ì¤..."):u.failed?h("vdetail.sumDamageUnknown"):u.count>0||t.hasDamage||A?h(A?"vdetail.sumDamageOpenRepair":"vdetail.sumDamageOpen",{count:u.count}):h("vdetail.sumDamageNone");return v.push({key:"damage",label:h("vdetail.sumDamage"),value:l,tone:!m&&(u.failed||u.count>0||t.hasDamage||A)?"warn":"",link:{text:h("vdetail.sumGoDamage"),onClick:()=>o("damage")}}),F&&v.push({key:"deadline",label:h("vdetail.sumDeadline"),value:`${h(yn[F.key])} ${F.date} · ${p(F.days)}`,tone:F.days<0?"alert":F.days<=30?"warn":""}),z&&v.push({key:"tire",label:h("vdetail.sumTire"),value:h(z==="mismatch"?"vdetail.sumTireMismatch":"vdetail.sumTireConflict"),tone:z==="mismatch"?"alert":"warn",link:{text:h("vdetail.sumGoTires"),onClick:()=>i("/staff/tires")}}),e.jsxs("section",{className:"vsc","aria-label":h("vdetail.sumTitle"),children:[e.jsx("h3",{className:"vsc__title",children:h("vdetail.sumTitle")}),e.jsx("ul",{className:"vsc__rows",children:v.map(c=>e.jsxs("li",{className:`vsc__row${c.tone?` vsc__row--${c.tone}`:""}`,children:[e.jsx("span",{className:"vsc__label",children:c.label}),e.jsxs("span",{className:"vsc__value",children:[c.value,c.tag&&e.jsx("span",{className:"vsc__tag",children:c.tag})]}),c.link&&e.jsx("button",{type:"button",className:"vsc__link",onClick:c.link.onClick,children:c.link.text})]},c.key))})]})}function Yn(){const{t}=se(),{id:a}=Wt(),n=be(),o=lt(),{fleetVehicles:i=[],bookings:h=[],fleetLoading:B=!1,fleetError:u=!1,retrySubscriptions:j}=Re()||{},d=i.find(k=>k.id===a),[f,z]=g.useState(o.state?.tab||"info"),[F,m]=g.useState(o.state?.supplementBookingId||""),A=g.useCallback(()=>{m(""),n(`${o.pathname}${o.search}`,{replace:!0,state:{...o.state||{},supplementBookingId:null}})},[n,o.pathname,o.search,o.state]),[p,v]=g.useState({forId:null,logs:[]}),[l,c]=g.useState(!1),[D,I]=g.useState(null),[b,O]=g.useState(!1),{byId:E,loading:H}=Le(),ae=E.get(String(a)),P=H,[N,T]=g.useState(null),[_,U]=g.useState(!1),[Y,q]=g.useState(null),[J,ee]=g.useState(""),te=N&&N.vehicleId===a?we(N.action,a,h):null,r=Y&&Y.vehicleId===a?Y:null,[S,x]=g.useState(0);g.useEffect(()=>{if(f!=="history"||!a)return;let k=!0;return(async()=>{try{const $=await xt(a);k&&v({forId:a,logs:$})}catch($){console.error("Failed to load logs:",$),k&&v({forId:a,logs:[]})}})(),()=>{k=!1}},[f,a,S]);const w=()=>{v(k=>({...k,forId:null})),x(k=>k+1),z("history")},V=()=>{v(k=>({...k,forId:null})),x(k=>k+1)},X=p.forId!==a;if(!d)return B?e.jsx("div",{className:"svd__state",role:"status",children:t("staffCommon.loading","ë¡ë© ì¤...")}):u?e.jsxs("div",{className:"svd__state",role:"alert",children:[e.jsx("p",{className:"svd__state-text",children:t("vdetail.loadFailed")}),j&&e.jsx("button",{type:"button",className:"svd__state-btn",onClick:()=>j(),children:t("vdetail.retry")})]}):e.jsx("div",{className:"svd__state",children:t("vdetail.notFound")});const ne=Tt(d.status),L=!!D,K=!l&&!L&&f==="info",G=["damaged","ready","corporate","rented","available","maintenance","sale_pending"].includes(d.status),y=()=>xe()?.name||"staff",C=(k,$)=>{if(!P){if(q(null),we(k,d.id,h)){T({action:k,vehicleId:d.id});return}$()}},W=(k,$)=>{const oe=y();return me(d,k,{type:"status_change",date:de(),staffName:oe,...$},oe)},pe=async(k=null,$="")=>{try{return await W({status:"available"}
2,{title:"ì´íì¤ ê°ì í´ì ",description:[`ì´íì¤ â ê°ì©ì¼ë¡ ê°ì ë³ê²½ (ì¤íí: ${y()})`,...Be(k,$)].join(" | "),km:d.currentKm||0}),alert(t("vdetail.forceAvailDone")),!0}catch(oe){return alert(t("vdetail.changeFailedPrefix")+oe.message),!1}},fe=async(k=null)=>{try{return await W({status:"available"},{title:"ë²ì¸ ì´í ì¢
ë£",description:[`ë²ì¸ ì´í â ê°ì©ì¼ë¡ ë³ê²½ (ì¤íí: ${y()})`,...Be(k)].join(" | "),km:d.currentKm||0}),alert(t("vdetail.toAvailDone")),!0}catch($){return alert(t("vdetail.changeFailedPrefix")+$.message),!1}},ie=async(k=null)=>{try{return await W({status:"retired"},{title:"ì°¨ë í´ì ì²ë¦¬",description:[`${d.status} â í´ì (ì¤íí: ${y()})`,...Be(k)].join(" | ")}),alert(t("vdetail.retireDone")),!0}catch($){return alert(t("vdetail.failedPrefix")+$.message),!1}},s=async(k,$)=>{if(_)return;U(!0);const oe={forceRelease:pe,endCorporate:fe,retire:ie}[k.action],ct=await oe(k,$);U(!1),ct&&T(null)},R=k=>{T(null),ee(""),q({to:k,vehicleId:d.id})},Q=async()=>{if(_||!r)return;const k=rt(d.status,r.to);if(!k){q(null);return}const $=J.trim().slice(0,Ae);if(!(k.input==="reason"&&!$)){U(!0);try{const oe=r.to==="maintenance"?"ì ë¹ ì
ê³ ":"í매 ë기 í´ì ";await W({status:r.to},{title:oe,description:[`${d.status} â ${r.to} (ì¤íí: ${y()})`,$?`ì¬ì : ${$}`:""].filter(Boolean).join(" | "),km:d.currentKm||0}),alert(t(r.to==="maintenance"?"vdetail.toMaintDone":"vdetail.toAvailDone")),q(null)}catch(oe){alert(t("vdetail.changeFailedPrefix")+oe.message)}U(!1)}},le=k=>e.jsx(dt,{guard:k,busy:_,onGoReturn:$=>n(`/staff/return/${encodeURIComponent($)}`),onConfirm:$=>s(k,$),onCancel:()=>T(null)},`${k.action}-${d.id}`),M=()=>{const k=r.to==="maintenance",$=!_&&(!k||!!J.trim());return e.jsxs("div",{className:"svd__confirm",role:"group","aria-label":t(k?"vdetail.toMaintBtn":"vdetail.salePendingToAvailBtn"),children:[e.jsx("p",{className:"svd__confirm-text",children:t(k?"vdetail.toMaintConfirm":"vdetail.salePendingToAvailConfirm",{plate:d.licensePlate})}),k&&e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"svd__confirm-label",htmlFor:"svd-maint-reason",children:t("vdetail.toMaintReason")}),e.jsx("textarea",{id:"svd-maint-reason",className:"svd__confirm-input",rows:2,maxLength:Ae,value:J,onChange:oe=>ee(oe.target.value),placeholder:t("vdetail.toMaintReasonPlaceholder")})]}),e.jsxs("div",{className:"svd__confirm-actions",children:[e.jsx("button",{type:"button",className:"svd__confirm-btn",onClick:()=>q(null),disabled:_,children:t("common.cancel","ì·¨ì")}),e.jsx("button",{type:"button",className:"svd__confirm-btn svd__confirm-btn--primary",onClick:Q,disabled:!$,children:t(_?"dashboard.savingShort":k?"vdetail.toMaintSubmit":"vdetail.salePendingToAvailSubmit")})]})]})},re=k=>{k==="history"&&V(),z(k),c(!1),I(null),T(null),q(null)},je=[{key:"info",label:t("vdetail.tabInfo")},{key:"damage",label:t("vdetail.tabDamage")},{key:"km_chart",label:t("vdetail.tabChart")},{key:"history",label:t("vdetail.tabHistory")},{key:"action",label:t("vdetail.tabAction")}];return e.jsxs("div",{style:{paddingBottom:"20px"},children:[e.jsxs("div",{style:{padding:"12px 16px",background:"#fff",borderBottom:"1px solid #E5E7EB"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[e.jsx("button",{onClick:()=>n(-1),className:"svd__back","aria-label":t("vdetail.back"),children:"â"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:"1.15rem",fontWeight:"800",color:"#1A1A2E",letterSpacing:"0.5px"},children:d.licensePlate}),e.jsx("span",{style:{background:ne.bg,color:ne.color,padding:"2px 8px",borderRadius:"4px",fontSize:"0.7rem",fontWeight:"700"},children:Ne(t,d.status)}),(d.hasDamage||d.status==="damaged")&&e.jsx("span",{style:{background:"#FEF3C7",color:"#D97706",padding:"2px 8px",borderRadius:"4px",fontSize:"0.7rem",fontWeight:"700"},children:t("vdetail.damageTag")})]}),e.jsxs("div",{style:{fontSize:"0.8rem",color:"#6B7280"},children:[d.name," · ",d.ownerCompany||""]})]})]}),e.jsx("div",{className:"svd__tabs",role:"tablist",children:je.map(k=>{const $=f===k.key&&!l&&!L;return e.jsx("button",{type:"button",role:"tab","aria-selected":$,className:`svd__tab${$?" svd__tab--active":""}`,onClick:()=>re(k.key),children:k.label},k.key)})})]}),e.jsxs("div",{style:{padding:"16px"},children:[K&&e.jsx(vn,{vehicle:d,result:ae,onCheck:()=>O(!0)}),K&&e.jsx(bn,{vehicle:d,bookings:h,today:de(),onGoTab:re,onNavigate:k=>n(k)}),K&&d.status==="available"&&e.jsx("button",{onClick:()=>c(!0),style:{width:"100%",padding:"16px",borderRadius:"12px",border:"none",background:"linear-gradient(135deg, #8B5CF6, #6D28D9)",color:"#fff",fontSize:"0.9rem",fontWeight:"700",cursor:"pointer",marginBottom:"12px",minHeight:"52px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:t("vdetail.startPrep")}),K&&d.status==="damaged"&&e.jsx("button",{onClick:()=>I("damage"),style:{width:"100%",padding:"16px",borderRadius:"12px",border:"none",background:"linear-gradient(135deg, #059669, #047857)",color:"#fff",fontSize:"0.9rem",fontWeight:"700",cursor:"pointer",marginBottom:"8px",minHeight:"52px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:t("vdetail.repairDone")}),K&&d.status==="maintenance"&&e.jsx("button",{onClick:()=>I("maintenance"),style:{width:"100%",padding:"16px",borderRadius:"12px",border:"none",background:"linear-gradient(135deg, #059669, #047857)",color:"#fff",fontSize:"0.9rem",fontWeight:"700",cursor:"pointer",marginBottom:"8px",minHeight:"52px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},children:t("vdetail.maintDoneBtn")}),K&&d.status==="retired"&&e.jsx("button",{onClick:async()=>
2{if(confirm(t("vdetail.unretireConfirm",{plate:d.licensePlate})))try{await W({status:"available"},{title:"í´ì 복구",description:`í´ì â ê°ì©ì¼ë¡ 복구 (ì¤íí: ${y()})`}),alert(t("vdetail.unretireDone"))}catch(k){alert(t("vdetail.failedPrefix")+k.message)}},style:{width:"100%",padding:"14px",borderRadius:"12px",border:"none",background:"linear-gradient(135deg, #059669, #047857)",color:"#fff",fontSize:"0.9rem",fontWeight:"700",cursor:"pointer",marginBottom:"12px",minHeight:"52px"},children:t("vdetail.unretireBtn")}),K&&G&&e.jsx("div",{className:"svd__manual-title",children:t("activity.flows.manualStatusTitle")}),K&&P&&["corporate","rented","available","maintenance","damaged","sale_pending"].includes(d.status)&&e.jsx("div",{className:"svd__manual-pending",role:"status",children:t("activity.flows.guard.loading")}),K&&d.status==="sale_pending"&&(r?.to==="available"?M():e.jsx("button",{onClick:()=>R("available"),style:{width:"100%",padding:"14px",borderRadius:"12px",border:"2px solid #059669",background:"#ECFDF5",color:"#065F46",fontSize:"0.85rem",fontWeight:"700",cursor:"pointer",marginBottom:"12px",minHeight:"48px"},children:t("vdetail.salePendingToAvailBtn")})),K&&d.status==="available"&&(r?.to==="maintenance"?M():e.jsx("button",{onClick:()=>R("maintenance"),style:{width:"100%",padding:"14px",borderRadius:"12px",border:"2px solid #D97706",background:"#FFFBEB",color:"#92400E",fontSize:"0.85rem",fontWeight:"700",cursor:"pointer",marginBottom:"12px",minHeight:"48px"},children:t("vdetail.toMaintBtn")})),K&&d.status==="damaged"&&e.jsx("button",{onClick:async()=>{if(confirm(t("vdetail.toAvailKeepDamageConfirm",{plate:d.licensePlate})))try{await W({status:"available",hasDamage:!0},{title:"ê°ì©ì¼ë¡ ì í (ìì ì ì§)",description:`ìì â ê°ì© ì í (ìì íê·¸ ì ì§, ì¤íí: ${y()})`}),alert(t("vdetail.toAvailKeepDamageDone"))}catch(k){alert(t("vdetail.failedPrefix")+k.message)}},style:{width:"100%",padding:"12px",borderRadius:"12px",border:"2px solid #D97706",background:"#FFFBEB",color:"#92400E",fontSize:"0.82rem",fontWeight:"700",cursor:"pointer",marginBottom:"12px",minHeight:"44px"},children:t("vdetail.toAvailKeepDamageBtn")}),K&&d.status==="ready"&&e.jsx("button",{onClick:async()=>{if(confirm(t("vdetail.cancelReadyConfirm",{plate:d.licensePlate})))try{await W({status:"available"},{title:"ë°°ì ë기 ì·¨ì",description:`ë°°ì ë기 â ê°ì©ì¼ë¡ ë³ê²½ (ì¤íí: ${y()})`,km:d.currentKm||0}),alert(t("vdetail.toAvailDone"))}catch(k){alert(t("vdetail.changeFailedPrefix")+k.message)}},style:{width:"100%",padding:"14px",borderRadius:"12px",border:"2px solid #DC2626",background:"#FEF2F2",color:"#991B1B",fontSize:"0.85rem",fontWeight:"700",cursor:"pointer",marginBottom:"12px",minHeight:"48px"},children:t("vdetail.cancelReadyBtn")}),K&&d.status==="corporate"&&(te?.action==="endCorporate"?le(te):e.jsx("button",{onClick:()=>C("endCorporate",()=>{confirm(t("vdetail.endCorporateConfirm",{plate:d.licensePlate}))&&fe()}),disabled:P,style:{width:"100%",padding:"14px",borderRadius:"12px",border:"2px solid #EC4899",background:"#FDF2F8",color:"#9D174D",fontSize:"0.85rem",fontWeight:"700",cursor:P?"not-allowed":"pointer",opacity:P?.55:1,marginBottom:"12px",minHeight:"48px"},children:t("vdetail.endCorporateBtn")})),K&&d.status==="rented"&&(te?.action==="forceRelease"?le(te):e.jsx("button",{onClick:()=>C("forceRelease",()=>{confirm(t("vdetail.forceAvailConfirm",{plate:d.licensePlate}))&&pe()}),disabled:P,style:{width:"100%",padding:"14px",borderRadius:"12px",border:"2px solid #DC2626",background:"#FEF2F2",color:"#991B1B",fontSize:"0.85rem",fontWeight:"700",cursor:P?"not-allowed":"pointer",opacity:P?.55:1,marginBottom:"12px",minHeight:"48px"},children:t("vdetail.forceAvailBtn")})),K&&["available","maintenance","damaged","sale_pending"].includes(d.status)&&(te?.action==="retire"?le(te):e.jsx("button",{onClick:()=>C("retire",()=>{confirm(t("vdetail.retireConfirm",{plate:d.licensePlate}))&&ie()}),disabled:P,style:{width:"100%",padding:"12px",borderRadius:"12px",border:"1px solid #9CA3AF",background:"#F9FAFB",color:"#6B7280",fontSize:"0.8rem",fontWeight:"600",cursor:P?"not-allowed":"pointer",opacity:P?.55:1,marginBottom:"12px",minHeight:"44px"},children:t("vdetail.retireBtn")})),l&&e.jsx(gn,{vehicle:d,onCancel:()=>c(!1),onComplete:()=>{c(!1),w()},onGoDamageTab:()=>{c(!1),z("damage")}}),L&&e.jsx(hn,{vehicle:d,mode:D,onCancel:()=>I(null),onComplete:()=>{I(null),w()}},`${D}
2-${d.id}`),!l&&!L&&f==="info"&&e.jsx(sn,{vehicle:d}),!l&&!L&&f==="damage"&&e.jsx(dn,{vehicle:d,supplementBookingId:F,onSupplementConsumed:A}),!l&&!L&&f==="km_chart"&&e.jsx(un,{vehicle:d}),!l&&!L&&f==="history"&&e.jsx(mn,{vehicleId:d.id,logs:p.logs,loading:X,onRefresh:V}),!l&&!L&&f==="action"&&e.jsx(fn,{vehicle:d,onSaved:w})]}),b&&e.jsx(an,{vehicle:d,result:ae,onClose:()=>O(!1)})]})}export{Yn 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.