PageSourceSearch

https://www.chargeops.net/assets/wizard-v7rvIie5.js

js chargeops.net collected 2026-10-02 02:02:55 UTC 61,434 bytes, 1 lines download raw bytes

1import{r,j as e}from"./vendor-react-QE7wLE3r.js";import{a as Oe,r as Nt,s as Rt,t as Ct,v as It,w as St,a7 as Ne,bk as Le,I as Ke,h as Fe,eg as $s,fN as Vs,fM as Pe,fO as zs,gx as st,gy as Bs,fL as ft,fU as pt,fP as zt,fW as Ls,fT as ht,g1 as Bt,f_ as Ve,g6 as xt,gz as W,fY as Ks,fZ as Hs,go as yt,g5 as Lt,g4 as qs,fR as Ws,fG as ts,f$ as ss,g0 as Gs,g2 as Kt,gA as Qs,gB as Js,m as qe,p as z,o as E,X as Ht,G as Ae,fA as Ys,dB as Zs,fQ as rt,eB as qt,x as oe,E as Z,O as Xs,$ as ea,aZ as ze,T as ta,D as sa,d as aa,Q as ra,e as na,gC as ia,ar as ca,aM as as,aN as rs,aO as ns,aP as is,aQ as cs,aR as os,aS as ls,aT as ds,_ as us,Z as ms,z as ke,a$ as oa,b as q,aK as la,y as da,eJ as ua,aI as ma,eK as fa,az as pa,cw as Wt,b9 as ha,bq as xa,gD as ga,gE as Gt,gF as He,gG as va,gH as ba,J as fe,c5 as ya,gI as ja,gw as at,bJ as wa,gJ as gt,gK as ka,gq as Na,ep as Ra,gh as Qt,gL as Ca}from"./index-C5UqyXey.js";import{d as Ia}from"./consumption-warnings-KnJ5F1lS.js";import{R as Sa,u as Da,m as Ta,O as Pa,p as Aa,D as Oa,a as Fa,b as Ua}from"./report-firmware-field-B2gztoqI.js";import{u as vt,O as _a}from"./offline-snapshot-notice-T7w8LdhW.js";import{u as Ea}from"./use-record-recent-site-CbWqOl9s.js";import{T as jt}from"./textarea-m8PrGo4r.js";import{D as Ma}from"./date-picker--gdUBypS.js";import{C as Jt}from"./checkbox-Cy_UnEBk.js";import{M as $a}from"./minus-D98egxfh.js";import{u as Va}from"./recorded-upload-BX_8hggB.js";import{P as za}from"./photo-lightbox-BR6lmMhr.js";import{I as Ba}from"./image-Dk9T2m9G.js";import{C as wt}from"./cloud-off-BzXnW65n.js";import{I as La}from"./image-plus-Cu56_4CN.js";import{P as Ka}from"./pencil-B7Zk3_70.js";import{B as Ha,C as qa,V as Wa,u as Ga,a as Qa,b as Ja,S as Ya}from"./contractor-prefill-panel-CgkeeSX0.js";import{F as Za}from"./filter-uy2roOg9.js";import{S as Xa}from"./signoff-panel-ROjKo8np.js";import{R as er}from"./rotate-ccw-BUSrY0yl.js";import{C as tr}from"./chevron-left-CK2Rvbln.js";import{S as sr}from"./send-Cs9i8Pdt.js";import{f as bt}from"./format-CFPfhZhq.js";import"./vendor-radix-C7HJG0re.js";import"./vendor-motion-DpnOviVe.js";import"./file-x-B1sxSXXF.js";import"./cpu-CAMU4Rqr.js";import"./snapshot-DOtajWEt.js";import"./calendar-DRqKz0s_.js";import"./subDays-D42H25x2.js";import"./calendar-DGIc7ly4.js";import"./photo-lightbox-CQnE4nM4.js";import"./use-coarse-pointer-By70CtKw.js";import"./tab-swipe-cMLS5UTJ.js";import"./chart-column-D_QJgl1c.js";import"./chart-pie-BI3T6FA2.js";import"./attachment-upload-Cm_5N_gJ.js";import"./attachments-XIeiqPHL.js";import"./paperclip-DSb_w-Os.js";import"./work-orders-B3p8MkLw.js";import"./badge-check-C-NuBBAp.js";import"./status-badge-DTVMtRly.js";import"./signature-pad-6Dvl3x41.js";import"./switch-GFOdBmHE.js";import"./pen-line-Cg0b3TJY.js";import"./user-x-I3QGHVxx.js";const ar=[{value:"ok",labelKey:"maintenanceReports.resultOk",icon:Le,active:"border-emerald-600 bg-emerald-600 text-white shadow-sm shadow-emerald-600/25 ring-1 ring-inset ring-white/25",idle:"border-slate-200 bg-white text-slate-700 hover:border-emerald-300 hover:bg-emerald-50 hover:text-emerald-700 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200 dark:hover:border-emerald-700 dark:hover:bg-emerald-950/40 dark:hover:text-emerald-300",idleIcon:"text-emerald-500",ring:"focus-visible:ring-emerald-500"},{value:"na",labelKey:"maintenanceReports.resultNa",icon:$a,active:"border-slate-600 bg-slate-600 text-white shadow-sm shadow-slate-600/25 ring-1 ring-inset ring-white/25",idle:"border-slate-200 bg-white text-slate-700 hover:border-slate-300 hover:bg-slate-100 hover:text-slate-800 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200 dark:hover:bg-slate-800",idleIcon:"text-slate-400",ring:"focus-visible:ring-slate-400"},{value:"issue",labelKey:"maintenanceReports.resultIssue",icon:Ne,active:"border-rose-600 bg-rose-600 text-white shadow-sm shadow-rose-600/25 ring-1 ring-inset ring-white/25",idle:"border-slate-200 bg-white text-slate-700 hover:border-rose-300 hover:bg-rose-50 hover:text-rose-700 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-200 dark:hover:border-rose-700 dark:hover:bg-rose-950/40 dark:hover:text-rose-300",idleIcon:"text-rose-500",ring:"focus-visible:ring-rose-500"}];function Yt({ownerId:i,results:a,checklistTemplateId:s,templates:l,equipmentClass:h,disabled:A,onSelectTemplate:x,onPersistResults:S}){const{language:M}=Oe(),R=n=>Fe(M,n),[O,K]=r.useState(a),B=`${i}:${s??""}:${a.length}`,P=r.useRef(B);r.useEffect(()=>{P.current!==B&&(P.current=B,K(a))},[B,a]);const V=n=>{K(n),S(n)},$=(n,d)=>{V(O.map(w=>w.itemId===n?{...w,result:d}:w))},g=(n,d)=>{K(w=>w.map(U=>U.itemId===n?{...U,note:d}:U))},F=()=>{S(O)},v=n=>{x(n||void 0)},_=h==="chrgpk",f=l.filter(n=>(_?n.appliesTo==="chrgpk":n.appliesTo!=="chrgpk")||n._id===s),u=n=>n===h?0:n?2:1,D=[...f].sort((n,d)=>u(n.appliesTo)-u(d.appliesTo)),H=l.find(n=>n._id===s),L=!!H?.appliesTo&&!!h&&H.appliesTo!==h;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:[R("maintenanceReports.template"),":"]}),e.jsxs(Nt,{value:s??"",onValueChange:v,disabled:A,children:[e.jsx(Rt,{className:"h-9 w-[260px]",children:e.jsx(Ct,{placeholder:R("maintenanceReports.selectTemplate")})}),e.jsx(It,{children:D.map(n=>e.jsxs(St,{value:n._id,children:[n.name,n.appliesTo?` (${n.appliesTo.toUpperCase()})`:""]},n._id))})]})]}),L&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-amber-600 dar
1k:text-amber-400",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 shrink-0"}),R("maintenanceReports.templateClassMismatch")]}),O.length===0?e.jsx("p",{className:"rounded-lg border border-dashed p-4 text-center text-sm text-muted-foreground",children:R("maintenanceReports.pickTemplatePrompt")}):e.jsx("ul",{className:"divide-y rounded-xl border",children:O.map((n,d)=>e.jsxs("li",{className:"p-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("span",{className:"text-sm text-foreground",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[d+1,"."]}),n.label]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:ar.map(w=>{const U=w.icon,C=n.result===w.value;return e.jsxs("button",{type:"button",disabled:A,onClick:()=>$(n.itemId,w.value),"aria-pressed":C,className:`flex h-11 min-w-[72px] items-center justify-center gap-1.5 rounded-xl border px-4 text-[13px] font-semibold transition-all duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 active:scale-[0.97] disabled:cursor-not-allowed disabled:opacity-50 ${w.ring} ${C?w.active:w.idle}`,children:[e.jsx(U,{className:`h-4 w-4 ${C?"":w.idleIcon}`}),R(w.labelKey)]},w.value)})})]}),n.result==="issue"&&e.jsx(Ke,{value:n.note??"",onChange:w=>g(n.itemId,w.target.value),onBlur:F,disabled:A,placeholder:R("maintenanceReports.itemNote"),className:"mt-2 h-9"})]},n.itemId))})]})}const rr=1e3,nr=1500,ir=1e4;function cr(i){return i.conflict?"conflict":i.enabled?i.ops.some(s=>s.status==="needs-attention")?"blocked":i.debouncePending||i.draftUnsynced||i.ops.length>0?i.paused?"signin":i.online?"saving":"device":i.bound?"saved":"idle":i.legacy}function or(i){return i.conflict?{key:"conflict"}:i.online?i.queued>0||i.debouncePending||i.draftUnsynced?{key:"pending",count:Math.max(1,i.queued)}:null:{key:"offline"}}const fs=r.createContext(null),lr=fs.Provider;function dr(){return r.useContext(fs)}function ur(i,a){return i.length===a.length&&i.every((s,l)=>s.id===a[l].id&&s.status===a[l].status&&s.attempts===a[l].attempts)}function mr(i,a){return i.length===a.length&&i.every((s,l)=>s.key===a[l].key)}function fr(i,a){return i.kind===a.kind&&(i.chargerId??null)===(a.chargerId??null)&&(i.defectId??null)===(a.defectId??null)}function pr(i){const a=$s(),{db:s,scope:l,syncNow:h}=a,A=!!s&&!!l,x=a.connectivity==="online",[S,M]=r.useState(null),[R,O]=r.useState(!1),[K,B]=r.useState(!1),[P,V]=r.useState(!1),[$,g]=r.useState(void 0),[F,v]=r.useState([]),[_,f]=r.useState([]),u=r.useRef(null);u.current=S;const D=r.useRef(null),H=r.useRef(i.getForm);H.current=i.getForm;const L=r.useRef(i.reportId);L.current=i.reportId;const n=r.useRef(i.getServerVersion);n.current=i.getServerVersion;const d=r.useRef(i.isPristine);d.current=i.isPristine,r.useEffect(()=>{const c=setTimeout(()=>B(!0),nr),m=setTimeout(()=>V(!0),ir);return()=>{clearTimeout(c),clearTimeout(m)}},[]);const w=l?`${l.tenantId}:${l.userId}`:null,U=r.useRef(w);r.useEffect(()=>{U.current!==w&&(U.current=w,u.current=null,D.current=null,M(null),g(void 0),v([]),f([]),O(!1))},[w]),r.useEffect(()=>{if(!s||!l||S)return;let c=!1;return(async()=>{let m=null;if(i.draftParam){const b=Vs(l,i.draftParam);await Pe(s,b)&&(m={clientDraftId:i.draftParam,key:b})}else if(i.reportId){const k=(await zs(s,l)).find(N=>N.kind===st&&(N.serverId===i.reportId||N.form?.reportId===i.reportId));k&&(m={clientDraftId:k.clientDraftId,key:k.key})}c||(m&&(M(m),g(await Pe(s,m.key))),O(!0))})().catch(m=>{console.warn("Could not read the offline draft",m),c||O(!0)}),()=>{c=!0}},[s,l,S,i.draftParam,i.reportId]);const C=r.useCallback(async()=>{const c=u.current;if(!s||!c)return;const[m,b,k]=await Promise.all([Pe(s,c.key),s.getAllFromIndex("outbox","by_draft",c.key),Bs(s,c.key)]);b.sort((N,ne)=>(N.id??0)-(ne.id??0)),g(N=>N?.updatedAt===m?.updatedAt&&N?.syncedAt===m?.syncedAt&&N?.serverId===m?.serverId&&N?.baseUpdatedAt===m?.baseUpdatedAt&&N?.conflict?.serverUpdatedAt===m?.conflict?.serverUpdatedAt?N:m),v(N=>ur(N,b)?N:b),f(N=>mr(N,k)?N:k)},[s]);r.useEffect(()=>{if(!S)return;C();const c=setInterval(()=>{C()},rr);return()=>clearInterval(c)},[S,C]);const le=r.useCallback(async()=>
1{if(u.current)return u.current;if(!s||!l)throw new Error("Offline store unavailable");return D.current||(D.current=(async()=>{const c=ft(),m=H.current(),b=L.current??void 0,k=!!b&&(d.current?.(m)??!1),N=await pt(s,l,{clientDraftId:c,kind:st,form:{...m,reportId:b}});b&&await zt(s,N.key,b,n.current?.()??void 0),b&&k&&await Ls(s,N.key,N.updatedAt);const ne={clientDraftId:c,key:N.key};return u.current=ne,M(ne),ne})().finally(()=>{D.current=null})),D.current},[s,l]),te=r.useCallback(async c=>{if(!s||!l)return;const m=await le(),b=L.current??c.reportId;await pt(s,l,{clientDraftId:m.clientDraftId,kind:st,form:{...c,reportId:b}})},[s,l,le]),se=r.useCallback(async(c,m,b=!1)=>{if(!s||!l)return;const N={draftKey:(await le()).key,op:c,args:m};b?await ht(s,l,N):await Bt(s,l,N),await C(),h()},[s,l,le,C,h]),Re=r.useCallback(async c=>{if(!s||!l)throw new Error("Offline store unavailable");const m=ft(),b=await pt(s,l,{clientDraftId:m,kind:st,form:c}),k={clientDraftId:m,key:b.key};return await ht(s,l,{draftKey:k.key,op:W.sync,args:{}}),u.current=k,M(k),g(b),k},[s,l]),pe=r.useCallback(async()=>{const c=u.current;if(!s||!l||!c)return;const m=await s.getAllFromIndex("outbox","by_draft",c.key);for(const b of m)b.id!==void 0&&await Ve(s,b.id);await xt(s,l,c.clientDraftId),u.current=null,M(null),g(void 0),v([])},[s,l]),X=r.useCallback(async()=>{const c=u.current;if(!s||!c)return{draft:void 0,ops:[]};const[m,b]=await Promise.all([Pe(s,c.key),s.getAllFromIndex("outbox","by_draft",c.key)]);return{draft:m,ops:b}},[s]),We=r.useCallback(async()=>{const c=u.current;if(!s||!l||!c)return{draftDeleted:!1};const b=(await s.getAllFromIndex("outbox","by_draft",c.key)).filter(N=>N.status==="needs-attention");for(const N of b)N.id!==void 0&&await Ve(s,N.id);const k=b.some(N=>N.op===W.sync);return k&&(await xt(s,l,c.clientDraftId),g(void 0)),await C(),h(),{draftDeleted:k}},[s,l,C,h]),Ge=r.useCallback(async()=>{const c=u.current;!s||!l||!c||(await xt(s,l,c.clientDraftId),g(void 0))},[s,l]),Qe=r.useCallback(async(c,m)=>{const b=u.current;if(!s||!b)return;const k=await Pe(s,b.key);!k||k.syncedAt===void 0||k.conflict||k.baseUpdatedAt===m||await zt(s,b.key,c,m)},[s]),Je=r.useCallback(async(c,m,b,k)=>{const N=u.current;!s||!N||(Ks(N.key,{serverId:c,version:b,coversUpTo:k,form:{...m,reportId:c},syncOp:W.sync}),await Hs(s,N.key),await C())},[s,C]),de=r.useCallback(async()=>{const c=u.current;if(!s||!c)return;const m=await Pe(s,c.key);if(!m?.conflict||yt(m.form,m.conflict.server).length>0)return;await Lt(s,c.key,m.form);const b=await s.getAllFromIndex("outbox","by_draft",c.key);for(const k of b)k.op===W.sync&&k.id!==void 0&&await Ve(s,k.id);await C()},[s,C]),Ce=r.useCallback(async()=>{const c=u.current;!s||!l||!c||(await qs(s,c.key),await ht(s,l,{draftKey:c.key,op:W.sync,args:{}}),await C(),await h(),await C())},[s,l,C,h]),ae=r.useCallback(async c=>{const m=u.current;if(!s||!m)return;await Lt(s,m.key,c);const b=await s.getAllFromIndex("outbox","by_draft",m.key);for(const k of b)k.op===W.sync&&k.id!==void 0&&await Ve(s,k.id);await C()},[s,C]),G=r.useCallback(async()=>{if(s){for(const c of F)c.status==="needs-attention"&&c.id!==void 0&&await Ws(s,c.id);await C(),await h(),await C()}},[s,F,C,h]),Q=r.useCallback(async(c,m)=>{if(!s||!l)return;const b=await le();for(const k of c){const N=ft(),ne=await ts(k);let Ie;try{Ie=await ss(k)}catch{}await Gs(s,l,{draftKey:b.key,clientPhotoId:N,fileName:k.name,full:ne,thumbnail:Ie});const nt={clientPhotoId:N,...m,reportId:L.current??void 0};try{await Bt(s,l,{draftKey:b.key,op:W.addPhoto,args:nt})}catch(it){throw await Kt(s,l,N).catch(()=>{}),it}await C()}h()},[s,l,le,C,h]),Ue=r.useCallback(async c=>{if(!(!s||!l)){await Kt(s,l,c);for(const m of F)m.op===W.addPhoto&&m.args.clientPhotoId===c&&m.id!==void 0&&await Ve(s,m.id);await C()}},[s,l,F,C]),p=r.useCallback(c=>se(W.removePhoto,{photoId:c}),[se]),re=r.useCallback((c,m)=>se(W.updatePhotoCaption,{photoId:c,caption:m}),[se]),J=r.useRef(new Map),_e=r.useMemo(()=>{const c=new Map;for(const m of _){const b=J.current.get(m.clientPhotoId)??URL.createObjectURL(Qs(m)??Js(m));c.set(m.clientPhotoId,b)}for(const[m,b]of J.current)c.has(m)||URL.revokeObjectURL(b);return J.current=c,c},[_]);r.useEffect(()=>()=>{for(const c of J.current.values())URL.revokeObjectURL(c);
1J.current=new Map},[]);const y=r.useCallback(c=>{const m=[];for(const b of F){if(b.op!==W.addPhoto)continue;const k=b.args;if(!fr(k,c))continue;const N=_.find(Ie=>Ie.clientPhotoId===k.clientPhotoId),ne=_e.get(k.clientPhotoId);N&&ne&&m.push({clientPhotoId:k.clientPhotoId,fileName:N.fileName,url:ne,status:b.status})}return m},[F,_,_e]),he=r.useMemo(()=>new Set(F.filter(c=>c.op===W.removePhoto).map(c=>c.args.photoId)),[F]),ge=r.useMemo(()=>{const c=new Map;for(const m of F)if(m.op===W.updatePhotoCaption){const b=m.args;c.set(b.photoId,b.caption)}return c},[F]),Dt=r.useMemo(()=>A?{online:x,paused:a.paused,devicePhotosFor:y,pendingRemovals:he,pendingCaptions:ge,addPhotos:Q,removeDevicePhoto:Ue,removeServerPhoto:p,captionServerPhoto:re}:null,[A,x,a.paused,y,he,ge,Q,Ue,p,re]);return{enabled:A,online:x,paused:a.paused,resolved:a.dbStatus==="unavailable"?!0:a.dbStatus==="opening"?P:A?R:K,draftKey:S?.key??null,draft:$,ops:F,saveForm:te,queue:se,startReport:Re,abandonStartedReport:pe,inspect:X,retryParked:G,discardParked:We,forgetDraft:Ge,conflict:$?.conflict??null,rebaseSynced:Qe,recordDirectSave:Je,resolveIdentical:de,keepDeviceVersion:Ce,takeServerVersion:ae,refresh:C,syncNow:h,context:Dt}}function kt({reportId:i,kind:a,chargerId:s,defectId:l,photos:h,disabled:A}){const{language:x}=Oe(),S=(d,w)=>Fe(x,d,w),{toast:M}=qe(),R=dr(),O={kind:a,chargerId:s,defectId:l},K=R?R.devicePhotosFor(O):[],B=R?h.filter(d=>!R.pendingRemovals.has(d.id)).map(d=>R.pendingCaptions.has(d.id)?{...d,caption:R.pendingCaptions.get(d.id)}:d):h,P=z(E.maintenanceReports.mutations.generateUploadUrl),V=Va("reportPhoto",()=>P({})),$=z(E.maintenanceReports.mutations.addPhoto),g=z(E.maintenanceReports.mutations.removePhoto),F=z(E.maintenanceReports.mutations.updatePhotoCaption),[v,_]=r.useState([]),[f,u]=r.useState(null),D=r.useRef(null),H=r.useRef(null),L=async d=>{if(!d||d.length===0)return;const w=Array.from(d).filter(U=>{const C=Zs(U);return C==="invalid-type"?(M({title:`${U.name}: ${S("maintenanceReports.notAnImage")}`,variant:"destructive"}),!1):C==="too-large"?(M({title:`${U.name}: ${S("maintenanceReports.exceedsMaxSize")}`,variant:"destructive"}),!1):!0});if(R){if(w.length===0)return;try{await R.addPhotos(w,O)}catch(U){if(U instanceof rt)return;M({title:S("maintenanceReports.offline.photoNotSaved",{name:w.map(C=>C.name).join(", ")}),variant:"destructive"})}return}for(const U of w){const C=`${U.name}-${U.size}-${U.lastModified}`,le=URL.createObjectURL(U);_(te=>[...te,{key:C,previewUrl:le,progress:10}]);try{const te=await ts(U);_(pe=>pe.map(X=>X.key===C?{...X,progress:40}:X));const se=await qt(V.getUploadUrl,te,"image/jpeg",{headers:V.headers});let Re;try{const pe=await ss(U);Re=await qt(V.getUploadUrl,pe,"image/jpeg",{headers:V.headers})}catch{}_(pe=>pe.map(X=>X.key===C?{...X,progress:85}:X)),await $({reportId:i,kind:a,chargerId:s||void 0,defectId:l||void 0,storageId:se,thumbnailStorageId:Re,fileName:U.name,mimeType:"image/jpeg",fileSize:te.size})}catch(te){M({title:`${U.name}: ${oe(te,"Upload failed")}`,variant:"destructive"})}finally{URL.revokeObjectURL(le),_(te=>te.filter(se=>se.key!==C))}}},n=async d=>{try{if(R){await R.removeServerPhoto(d);return}await g({id:d})}catch(w){M({title:oe(w,"Delete failed"),variant:"destructive"})}};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("input",{ref:D,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:d=>{L(d.target.files),d.target.value=""}}),e.jsx("input",{ref:H,type:"file",accept:"image/*",capture:"environment",className:"hidden",onChange:d=>{L(d.target.files),d.target.value=""}}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-5",children:[B.map((d,w)=>e.jsxs("button",{type:"button",onClick:()=>u(w),className:"group relative aspect-square cursor-zoom-in overflow-hidden rounded-lg bg-muted",children:[d.thumbnailUrl||d.url?e.jsx("img",{src:d.thumbnailUrl??d.url??"",alt:d.caption??d.fileName??"photo",className:"h-full w-full object-cover"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center",children:e.jsx(Ba,{className:"h-6 w-6 text-muted-foreground"})}),d.caption&&e.jsx("span",{className:"absolute inset-x-0 bottom-0 truncate bg-gradient-to-t from-black/70 to-transparent px-1.5 pb-1 pt-3 text-left text-[10px] text-white",children:d.caption}),!A&&e.jsx("span",{role:"button",tabIndex:-1,onClick:U=>{U.stopPropagation(),n(d.id)},className:"absolute right-1 top-1 flex h-6 w-6 items-center justify-center rounded-full bg-black/55 text-white opacity-0 transition-opacity hover:bg-black/75 group-hover:opacity-100",children:e.jsx(Ht,{className:"h-3.5 w-3.5"})})]},d.id)),K.map(d=>e.jsxs("div",{className:"group relative aspect-square overflow-hidden rounded-lg bg-muted",children:[e.jsx("img",{src:d.url,alt:d.fileName,className:"h-full w-full object-cover"}),e.jsx("span",{className:"absolute inset-x-0 bottom-0 flex items-center gap-1 bg-gradient-to-t from-black/70 to-transparent px-1.5 pb-1 pt-3 text-[10px] text-white",children:R?.online&&!R.paused&&d.status==="pending"?e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"h-3 w-3 animate-spin"}),S("maintenanceReports.offline.photoUploading")]}):e.jsxs(e.Fragment,{children:[e.jsx(wt,{className:"h-3 w-3"}),S("maintenanceReports.offline.photoOnDevice")]})}),!A&&e.jsx("button",{type:"button","aria-label":S("common.delete"),onClick:()=>{R?.removeDevicePhoto(d.clientPhotoId)},className:"absolute right-1 top-1 flex h-6 w-6 items-center justify-center rounded-full bg-black/55 text-white opacity-0 transition-opacity hover:bg-black/75 focus:opacity-100 group-hover:opacity-100",children:e.jsx(Ht,{className:"h-3.5 w-3.5"})})]},d.clientPhotoId)),v.map(d=>e.jsxs("div",{className:"relative aspect-square overflow-hidden rounded-lg bg-muted",children:[e.jsx("img",{src:d.previewUrl,alt:"uploading",className:"h-full w-full object-cover opacity-60"}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-1 bg-black/10",children:e.jsx("div",{className:"h-full bg-brand-500 transition-[width] duration-300",style:{width:`${d.progress}%`}})})]},d.key)),!A&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>H.current?.click(),className:"flex aspect-square flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed border-border bg-background text-muted-foreground transition-colors hover:border-brand-400 hover:text-brand-500 dark:hover:text-brand-200",children:[e.jsx(Ys,{className:"h-6 w-6"}),e.jsx("span",{className:"text-[10px]",children:S("maintenanceReports.takePhoto")})]}),e.jsxs("button",{type:"button",onClick:()=>D.current?.click(),className:"flex aspect-square flex-col items-center justify-center gap-1 rounded-lg border-2 border-dashed border-border bg-background text-muted-foreground transition-colors hover:border-brand-400 hover:text-brand-500 dark:hover:text-brand-200",children:[e.jsx(La,{className:"h-6 w-6"}),e.jsx("span",{className:"text-[10px]",children:S("maintenanceReports.addPhoto")})]})]})]}),e.jsx(za,{photos:B.map(d=>({id:d.id,url:d.url??d.thumbnailUrl??null,caption:d.caption,fileName:d.fileName})),index:f,onClose:()=>u(null),onNavigate:u,onSaveCaption:A?void 0:(d,w)=>
1{R?R.captionServerPhoto(d,w):F({id:d,caption:w})}})]})}const Zt={categoryId:"",severity:"defect",description:"",correctiveAction:""};function hr({reportId:i,chargerId:a,defects:s,categories:l,disabled:h}){const{language:A}=Oe(),x=n=>Fe(A,n),{toast:S}=qe(),M=z(E.maintenanceReports.defects.addDefect),R=z(E.maintenanceReports.defects.updateDefect),O=z(E.maintenanceReports.defects.removeDefect),[K,B]=r.useState(!1),[P,V]=r.useState(Zt),[$,g]=r.useState(!1),[F,v]=r.useState(null),[_,f]=r.useState(!1),u=()=>{V({...Zt,categoryId:l[0]?._id??""}),B(!0)},D=n=>{V({id:n._id,categoryId:n.categoryId,severity:n.severity,description:n.description,correctiveAction:n.correctiveAction??""}),B(!0)},H=async()=>{if(!(!P.categoryId||!P.description.trim())){g(!0);try{P.id?await R({id:P.id,categoryId:P.categoryId,severity:P.severity,description:P.description,correctiveAction:P.correctiveAction||void 0}):await M({reportId:i,chargerId:a,categoryId:P.categoryId,severity:P.severity,description:P.description,correctiveAction:P.correctiveAction||void 0}),B(!1)}catch(n){S({title:oe(n,x("maintenanceReports.saveFailed")),variant:"destructive"})}finally{g(!1)}}},L=async()=>{if(F){f(!0);try{await O({id:F._id}),v(null)}catch(n){S({title:oe(n,x("maintenanceReports.deleteFailed")),variant:"destructive"})}finally{f(!1)}}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"text-sm font-semibold text-foreground",children:[x("maintenanceReports.defects"),s.length>0&&e.jsxs("span",{className:"ml-1.5 text-muted-foreground",children:["(",s.length,")"]})]}),!h&&e.jsxs(Z,{size:"sm",variant:"outline",onClick:u,children:[e.jsx(Xs,{className:"mr-1 h-4 w-4"}),x("maintenanceReports.addDefect")]})]}),s.length===0?e.jsx("p",{className:"rounded-lg border border-dashed p-3 text-center text-xs text-muted-foreground",children:x("maintenanceReports.noDefects")}):e.jsx("div",{className:"space-y-3",children:s.map(n=>e.jsxs("div",{className:"rounded-xl border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n.category&&e.jsx(ea,{variant:"outline",style:{borderColor:n.category.color??"#94a3b8",color:n.category.color??void 0},children:n.category.name}),e.jsx("span",{className:"rounded-full px-2 py-0.5 text-[11px] font-medium text-white",style:{backgroundColor:ze[n.severity]},children:x(`maintenanceReports.severity.${n.severity}`)}),e.jsx("div",{className:"ml-auto flex gap-1",children:!h&&e.jsxs(e.Fragment,{children:[e.jsx(Z,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>D(n),title:x("maintenanceReports.editDefect"),"aria-label":x("maintenanceReports.editDefect"),children:e.jsx(Ka,{className:"h-3.5 w-3.5"})}),e.jsx(Z,{size:"icon",variant:"ghost",className:"h-7 w-7 co-text-negative",onClick:()=>v(n),title:x("maintenanceReports.deleteDefect"),"aria-label":x("maintenanceReports.deleteDefect"),children:e.jsx(ta,{className:"h-3.5 w-3.5"})})]})})]}),e.jsx("p",{className:"mt-2 text-sm text-foreground",children:n.description}),n.correctiveAction&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"font-medium",children:[x("maintenanceReports.pdfRecommendation"),":"]})," ",n.correctiveAction]}),e.jsx("div",{className:"mt-3",children:e.jsx(kt,{reportId:i,kind:"defect",chargerId:a,defectId:n._id,photos:n.photos,disabled:h})})]},n._id))}),e.jsx(sa,{open:K,onOpenChange:B,children:e.jsxs(aa,{className:"max-w-lg",children:[e.jsx(ra,{children:e.jsx(na,{children:P.id?x("maintenanceReports.editDefect"):x("maintenanceReports.addDefect")})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:x("maintenanceReports.defectCategory")}),e.jsxs(Nt,{value:P.categoryId,onValueChange:n=>V(d=>({...d,categoryId:n})),children:[e.jsx(Rt,{children:e.jsx(Ct,{placeholder:x("maintenanceReports.selectCategory")})}),e.jsx(It,{children:l.map(n=>e.jsx(St,{value:n._id,children:n.name},n._id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:x("maintenanceReports.defectSeverity")}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ia.map(n=>{const d=P.severity===n;return e.jsx("button",{type:"button",onClick:()=>V(w=>({...w,severity:n})),className:"rounded-lg border px-2.5 py-1.5 text-xs font-medium transition-colors",style:d?{backgroundColor:ze[n],borderColor:ze[n],color:"white"}:{borderColor:ze[n],color:ze[n]},children:x(`maintenanceReports.severity.${n}`)},n)})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:x("maintenanceReports.defectDescription")}),e.jsx(jt,{value:P.description,onChange:n=>V(d=>({...d,description:n.target.value})),placeholder:x("maintenanceReports.descriptionPlaceholder"),rows:3})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:x("maintenanceReports.defectCorrectiveAction")}),e.jsx(jt,{value:P.correctiveAction,onChange:n=>V(d=>({...d,correctiveAction:n.target.value})),placeholder:x("maintenanceReports.correctiveActionPlaceholder"),rows:3})]})]}),e.jsxs(ca,{children:[e.jsx(Z,{variant:"outline",onClick:()=>B(!1),children:x("maintenanceReports.cancel")}
1),e.jsx(Z,{onClick:H,disabled:$||!P.categoryId||!P.description.trim(),children:x("maintenanceReports.save")})]})]})}),e.jsx(as,{open:F!==null,onOpenChange:n=>!n&&!_&&v(null),children:e.jsxs(rs,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:x("maintenanceReports.deleteDefect")}),e.jsx(cs,{children:x("maintenanceReports.confirmDeleteDefect")})]}),e.jsxs(os,{children:[e.jsx(ls,{disabled:_,children:x("maintenanceReports.cancel")}),e.jsxs(ds,{onClick:n=>{n.preventDefault(),L()},disabled:_,variant:"destructive",children:[_&&e.jsx(Ae,{className:"mr-1 h-4 w-4 animate-spin"}),x("maintenanceReports.delete")]})]})]})})]})}function xr(i){return!!i.charger?.spec?.isDc}const Be="__chrgpk__";function gr({row:i,disabled:a}){const{language:s}=Oe(),l=(O,K)=>Fe(s,O,K),{toast:h}=qe(),A=z(E.maintenanceReports.mutations.setChargerFirmware),x=i.firmwareVersion??"",[S,M]=r.useState(x);r.useEffect(()=>M(x),[x]);const R=async()=>{if(S.trim()!==x.trim())try{await A({reportChargerId:i._id,firmwareVersion:S})}catch(O){h({title:oe(O,l("firmware.saveFailed")),variant:"destructive"})}};return e.jsxs("div",{className:q("space-y-1 p-3","co-card-inset"),"data-testid":"maintenance-report-firmware",children:[e.jsx(Sa,{label:l("firmware.reportField"),lastKnown:i.charger?.firmwareVersion??null,value:S,onChange:M,onCommit:()=>{R()},disabled:a}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("firmware.reportFinalHint")})]})}function vr({report:i,templates:a,categories:s,chrgpkIncluded:l,disabled:h}){const{language:A}=Oe(),x=(u,D)=>Fe(A,u,D),{chrgpkLabel:S}=us(),{toast:M}=qe(),R=z(E.maintenanceReports.mutations.setChargerFilterReplaced),O=z(E.maintenanceReports.mutations.setChargerTemplate),K=z(E.maintenanceReports.mutations.updateChecklistResults),B=z(E.maintenanceReports.mutations.setChrgpkPerformed),P=z(E.maintenanceReports.mutations.setChrgpkTemplate),V=z(E.maintenanceReports.mutations.updateChrgpkResults),$=i.chargers,[g,F]=r.useState($[0]?._id??Be);r.useEffect(()=>{g!==Be&&($.length===0?F(Be):$.some(u=>u._id===g)||F($[0]._id))},[$,g]);const v=$.find(u=>u._id===g)??null,_=g===Be,f=i.chrgpk?.results.filter(u=>u.result==="issue").length??0;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"-mx-1 flex gap-2 overflow-x-auto px-1 pb-1 [-webkit-overflow-scrolling:touch]",children:[e.jsxs("button",{type:"button",onClick:()=>F(Be),className:`flex shrink-0 items-center gap-2 rounded-xl border px-3 py-2 text-sm transition-colors ${_?"border-brand-500 bg-brand-50 dark:border-brand-300 text-brand-700 dark:bg-brand-950/40 dark:text-brand-300":"border-border bg-background text-muted-foreground hover:bg-muted"}`,children:[e.jsx(Ha,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[140px] truncate font-medium",children:S}),f>0&&e.jsx("span",{className:"flex h-5 min-w-5 items-center justify-center rounded-full bg-amber-500 px-1 text-[11px] font-semibold text-white",children:f})]}),$.map(u=>{const D=u._id===g,H=u.results.filter(d=>d.result==="issue").length,L=u.defects.length,n=H+L;return e.jsxs("button",{type:"button",onClick:()=>F(u._id),className:`flex shrink-0 items-center gap-2 rounded-xl border px-3 py-2 text-sm transition-colors ${D?"border-brand-500 bg-brand-50 dark:border-brand-300 text-brand-700 dark:bg-brand-950/40 dark:text-brand-300":"border-border bg-background text-muted-foreground hover:bg-muted"}`,children:[e.jsx(ms,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"max-w-[140px] truncate font-medium",children:u.charger?.name??"—"}),n>0&&e.jsx("span",{className:"flex h-5 min-w-5 items-center justify-center rounded-full bg-amber-500 px-1 text-[11px] font-semibold text-white",children:n})]},u._id)})]}),_&&e.jsxs(ke,{className:q("space-y-5 p-4 sm:p-5","co-card"),children:[e.jsx("div",{className:"flex flex-wrap items-baseline justify-between gap-2 border-b pb-3",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:S}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[x("maintenanceReports.chrgpkSubtitle"),i.site?.chrgpkType&&e.jsxs(e.Fragment,{children:[" · ",i.site.chrgpkType]}),i.site?.chrgpkSerialNumber&&e.jsxs(e.Fragment,{children:[" ","· ",x("maintenanceReports.pdfSerial"),":"," ",i.site.chrgpkSerialNumber]})]})]})}),l!==!0&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-amber-600 dar
1k:text-amber-400",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 shrink-0"}),x("maintenanceReports.chrgpkNotIncluded",{chrgpkLabel:S})]}),e.jsxs("label",{className:q("flex items-start gap-3 p-3","co-card-inset",h?"cursor-default opacity-80":"cursor-pointer"),children:[e.jsx(Jt,{checked:i.chrgpk?.performed===!0,disabled:h,onCheckedChange:async u=>{try{await B({reportId:i._id,performed:u===!0})}catch(D){M({title:oe(D,"Failed"),variant:"destructive"})}},className:"mt-0.5"}),e.jsxs("span",{className:"space-y-0.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-sm font-medium text-foreground",children:[e.jsx(oa,{className:"h-3.5 w-3.5 text-brand-600 dark:text-brand-300"}),x("maintenanceReports.chrgpkPerformed",{chrgpkLabel:S})]}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:x("maintenanceReports.chrgpkPerformedHint",{chrgpkLabel:S})})]})]}),i.chrgpk?.performed&&e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground",children:x("maintenanceReports.checklist")}),e.jsx(Yt,{ownerId:`${i._id}:chrgpk`,results:i.chrgpk.results,checklistTemplateId:i.chrgpk.checklistTemplateId,templates:a,equipmentClass:"chrgpk",disabled:h,onSelectTemplate:u=>{P({reportId:i._id,checklistTemplateId:u||void 0,seedResults:!0})},onPersistResults:u=>{V({reportId:i._id,results:u})}})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground",children:x("maintenanceReports.chrgpkPhotos",{chrgpkLabel:S})}),e.jsx(kt,{reportId:i._id,kind:"chrgpk",photos:i.chrgpkPhotos,disabled:h})]})]})]}),!_&&v&&e.jsxs(ke,{className:q("space-y-5 p-4 sm:p-5","co-card"),children:[e.jsx("div",{className:"flex flex-wrap items-baseline justify-between gap-2 border-b pb-3",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:v.charger?.name??"—"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[v.charger?.serialNumber&&e.jsxs(e.Fragment,{children:[x("maintenanceReports.pdfSerial"),":"," ",v.charger.serialNumber]}),v.charger?.chargerClass&&e.jsxs(e.Fragment,{children:[" · ",v.charger.chargerClass.toUpperCase()]})]})]})}),xr(v)&&e.jsxs("label",{className:q("flex items-start gap-3 p-3","co-card-inset",h?"cursor-default opacity-80":"cursor-pointer"),children:[e.jsx(Jt,{checked:v.filterReplaced===!0,disabled:h,onCheckedChange:async u=>{try{await R({reportChargerId:v._id,filterReplaced:u===!0})}catch(D){M({title:oe(D,"Failed"),variant:"destructive"})}},className:"mt-0.5"}),e.jsxs("span",{className:"space-y-0.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-sm font-medium text-foreground",children:[e.jsx(Za,{className:"h-3.5 w-3.5 text-brand-600 dark:text-brand-300"}),x("maintenanceReports.filterReplaced")]}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:x("maintenanceReports.filterReplacedHint")})]})]}),e.jsx(gr,{row:v,disabled:h},v._id),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground",children:x("maintenanceReports.checklist")}),e.jsx(Yt,{ownerId:v._id,results:v.results,checklistTemplateId:v.checklistTemplateId,templates:a,equipmentClass:v.charger?.chargerClass??void 0,disabled:h,onSelectTemplate:u=>{O({reportChargerId:v._id,checklistTemplateId:u||void 0,seedResults:!0})},onPersistResults:u=>{K({reportChargerId:v._id,results:u})}})]}),e.jsx("section",{className:"space-y-2",children:e.jsx(qa,{reportChargerId:v._id,value:v.partsUsed??[],disabled:h},v._id)}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground",children:x("maintenanceReports.chargerPhotos")}),e.jsx(kt,{reportId:i._id,kind:"charger",chargerId:v.chargerId,photos:v.photos,disabled:h})]}),e.jsxs("section",{className:"space-y-2 border-t pt-4",children:[e.jsx(hr,{reportId:i._id,chargerId:v.chargerId,defects:v.defects,categories:s,disabled:h}),v.defects.length===0&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Ne,{className:"h-3.5 w-3.5"}),x("maintenanceReports.noDefects")]})]})]}),e.jsx(ke,{className:q("space-y-2 p-4 sm:p-5","co-card"),"data-testid":"maintenance-visit-parts-editor",children:e.jsx(Wa,{reportId:i._id,value:i.visitPartsUsed??[],disabled:h},i._id)})]})}const Xt=900,br=2500;function ce(i,a){const s={...He,...a},l=Object.fromEntries(Object.keys(s).sort().map(h=>[h,s[h]]));return JSON.stringify([yr(i),l])}const we=["maintenanceReports.stepSite","maintenanceReports.stepCh
1argers","maintenanceReports.stepInspection","maintenanceReports.stepReview"];function yr(i){return JSON.stringify({visitDate:i.visitDate,startTime:i.startTime,endTime:i.endTime,title:i.title,summaryNotes:i.summaryNotes,authorUserId:i.authorUserId,electricianName:i.electricianName,callOutType:i.callOutType,electricianCost:i.electricianCost,internalHours:i.internalHours})}function es(i,a){const s=i.filter(A=>A.isDefault&&A.appliesTo!=="chrgpk"),l=s.find(A=>A.appliesTo===a),h=s.find(A=>!A.appliesTo);return(l??h??s[0])?._id}function pn(){const{language:i}=Oe(),a=(t,o)=>Fe(i,t,o),{user:s}=la(),{can:l}=da(),{toast:h}=qe(),{chrgpkLabel:A}=us(),x=ua(),S=ma(),M=fa(),[,R]=pa(),[O]=Wt("/maintenance-reports/new"),[K,B]=Wt("/maintenance-reports/:reportId/edit"),P=ha(),V=O?new URLSearchParams(P).get("draft"):null,$=r.useRef(null),g=(K?B.reportId:null)??$.current;xa(a(K?"maintenanceReports.editReport":"maintenanceReports.newReport"),void 0,!0,!0);const F=s?.role==="technician",[v,_]=r.useState(0),[f,u]=r.useState({siteId:"",visitDate:bt(new Date,"yyyy-MM-dd"),startTime:Gt(),endTime:"",title:"",summaryNotes:"",authorUserId:"",...ga()}),[D,H]=r.useState(He),[L,n]=r.useState(!1),[d,w]=r.useState("idle"),[U,C]=r.useState(!1),[le,te]=r.useState(!1),[se,Re]=r.useState(!1),[pe,X]=r.useState(!1),[We,Ge]=r.useState(!1),[Qe,Je]=r.useState(!1),[de,Ce]=r.useState(!1),ae=r.useRef(""),G=r.useRef(()=>({meta:f,sections:D,isTechnician:F,viewFinancials:l.viewFinancials}));G.current=()=>({reportId:g??void 0,meta:f,sections:D,isTechnician:F,viewFinancials:l.viewFinancials});const Q=r.useRef(null),Ue=r.useRef(null),p=pr({reportId:g,draftParam:V,getForm:()=>G.current(),getServerVersion:()=>Q.current,isPristine:t=>Q.current!==null&&ce(t.meta,t.sections)===Ue.current}),re=!!g||!!p.draftKey,J=p.enabled&&!le;r.useEffect(()=>{const t=setTimeout(()=>Re(!0),br);return()=>clearTimeout(t)},[]);const _e=Da(E.maintenanceReports.queries.getById,g?{id:g}:"skip",{online:p.online}),y=_e.data??null,he=!!g&&_e.unavailable,ge=vt(E.maintenanceReports.queries.getFormOptions,{siteId:f.siteId?f.siteId:void 0}),c=ge.data??{sites:[],assignableUsers:[],chargers:[],siteChrgpk:null};Ea(f.siteId,c.sites.find(t=>t.id===f.siteId)?.name);const m=c.siteChrgpk?.included===!0,k=vt(E.maintenanceReports.templates.list,{}).data??[],ne=vt(E.maintenanceReports.categories.list,{}).data??[],Ie=z(E.maintenanceReports.mutations.createDraft),nt=z(E.maintenanceReports.mutations.updateDraft),it=z(E.maintenanceReports.mutations.addCharger),ps=z(E.maintenanceReports.mutations.removeCharger),hs=z(E.maintenanceReports.mutations.finalize),Tt=z(E.maintenanceReports.mutations.updateVisitCosts),{upload:xs,removeInvoice:gs,uploading:vs}=Ga(g),ct={updateDraft:t=>nt(t),updateVisitCosts:t=>Tt(t)},Se=t=>{if(t instanceof rt){p.online&&te(!0);return}h({title:a("maintenanceReports.offline.deviceSaveFailed"),variant:"destructive"})},Pt=t=>t instanceof rt&&p.online,At=r.useRef(!1);r.useEffect(()=>{if(!O||V||At.current)return;const t=c.siteElectricianName;t&&(At.current=!0,u(o=>o.electricianName?o:{...o,electricianName:t}))},[c.siteElectricianName]),r.useEffect(()=>{O&&!l.createMaintenanceReport&&R("/maintenance-reports")},[O,l.createMaintenanceReport,R]);const De=r.useRef("");r.useEffect(()=>{if(L||!p.resolved||he)return;const t=p.draft,o=!y&&se&&!p.online;if(t&&(!t.syncedAt||o)){u({...t.form.meta}),H({...He,...t.form.sections});const I=ce(t.form.meta,t.form.sections);ae.current=I,De.current=t.syncedAt?I:"",n(!0),O&&_(1);return}if(!y)return;const j={siteId:y.siteId,visitDate:y.visitDate||bt(new Date,"yyyy-MM-dd"),startTime:y.startTime??"",endTime:y.endTime??"",title:y.title??"",summaryNotes:y.summaryNotes??"",authorUserId:y.authorUserId,electricianName:y.visitCosts?.electricianName??"",callOutType:y.visitCosts?.callOutType??"none",electricianCost:y.visitCosts?.electricianCost==null?"":String(y.visitCosts.electricianCost),internalHours:y.visitCosts?.internalHours==null?"":String(y.visitCosts.internalHours)};u(j),Q.current=y.draftVersion??null,g&&Q.current!==null&&p.rebaseSynced(g,Q.current).catch(()=>{}),H({...He,...y.sections});const T=ce(j,{...He,...y.sections});ae.current=T,De.current=T,Ue.current=T,n(!0)},[y,L,p.resolved,p.draft,O,se,p.online,he]),r.useEffect(()=>{y?.status==="final"&&R(`/maintenance-reports/${y.id}`)},[y?.status,y?.id,R]);const Ye=p.draft?.serverId;r.useEffect(()=>{!O||!Ye||($.current=Ye,R(`/maintenance-reports/${Ye}/edit`,{replace:!0}))},[O,Ye,R]);const Ze=r.useMemo(()=>ce(f,D),[D,f.visitDate,f.startTime,f.endTime,f.title,f.summaryNotes,f.authorUserId,f.electricianName,f.callOutType,f.electricianCost,f.internalHours]),ee=r.useRef(null),ot=r.useRef(Promise.resolve(!0)),Ee=r.useRef(p);Ee.current=p;const Ot=()=>{ee.current&&clearTimeout(ee.current),ee.current=null,C(!1);const t=Ee.current;ot.current.then(o=>o?t.queue(W.sync,{},!0):void 0).catch(Se)},lt=r.useRef(Ot);lt.current=Ot,r.useEffect(()=>()=>{ee.current&&lt.current()},[]);const[ue,bs]=r.useState(null),Ft=r.useRef(null),Te=t=>{Ft.current=t,bs(t)},Ut=r.useRef(Promise.resolve()),_t=t=>{const o=Ut.current.then(t,t);return Ut.current=o.catch(()=>{}),o},ys=async()=>{const t=Ee.current;let o;t.enabled&&(await t.syncNow().catch(()=>{}),o=(await t.inspect().catch(()=>null))?.draft?.baseUpdatedAt);const j=[Q.current,o].filter(T=>typeof T=="number");return j.length>0?Math.max(...j):void 0},Xe=(t,o,j,T)=>{const I=Ee.current;
1j===void 0||!I.enabled||I.recordDirectSave(t,o,j,T).catch(()=>{})},js=async t=>{const o=Ee.current;if(!o.enabled)return!1;const j=(await o.inspect().catch(()=>null))?.draft;return!!j&&yt(j.form,t).length===0},ws=t=>_t(async()=>{if(Ft.current)return;const o=G.current();if(ce(o.meta,o.sections)===ae.current){w("saved");return}w("saving");try{const j=await ys(),T=Date.now(),I=G.current(),me=ce(I.meta,I.sections);let Y=await gt(ct,I,t,j);if(Y.version!==void 0&&(Q.current=Y.version),Y.kind==="conflict"&&await js(Y.server)&&(Y=await gt(ct,I,t,Y.server.updatedAt),Y.version!==void 0&&(Q.current=Y.version)),Y.kind==="conflict"){Te(Y.server),w("idle");return}ae.current=me,Xe(t,I,Y.version,T),w("saved")}catch{w("error")}});r.useEffect(()=>{if(!L||he)return;if(J){if(!re||Ze===De.current)return;De.current=Ze,ot.current=p.saveForm(G.current()).then(()=>!0,o=>(Se(o),!1)),ee.current&&clearTimeout(ee.current),C(!0),ee.current=setTimeout(()=>lt.current(),Xt);return}if(ee.current&&(clearTimeout(ee.current),ee.current=null,C(!1)),!g||ue||Ze===ae.current)return;w("saving");const t=setTimeout(()=>{ws(g)},Xt);return()=>clearTimeout(t)},[Ze,g,L,J,re,he,ue]);const Me=r.useMemo(()=>(y?.chargers??[]).map(t=>t.chargerId),[y]),xe=r.useMemo(()=>p.enabled?va(Me,p.ops):new Set(Me),[p.enabled,Me,p.ops]),Et=r.useMemo(()=>p.enabled?ba(Me,p.ops):[],[p.enabled,Me,p.ops]),ks=r.useMemo(()=>y&&p.enabled?{...y,chargers:y.chargers.filter(t=>xe.has(t.chargerId))}:y,[y,p.enabled,xe]),Ns=async()=>{if(!f.siteId){h({title:a("maintenanceReports.errorSiteRequired"),variant:"destructive"});return}Ge(!0);try{if(J){let I=null;try{I=await p.startReport({...G.current(),reportId:void 0})}catch(me){if(!Pt(me))throw me;Se(me)}if(I){const{clientDraftId:me}=I;ae.current=ce(f,D),De.current=ce(f,D),n(!0),await p.syncNow();const{draft:Y,ops:Es}=await p.inspect();if(Y?.serverId)$.current=Y.serverId,R(`/maintenance-reports/${Y.serverId}/edit`,{replace:!0});else if(Es.some(Ms=>Ms.status==="needs-attention")){await p.abandonStartedReport(),n(!1),h({title:a("maintenanceReports.offline.createRefused"),variant:"destructive"});return}else R(`/maintenance-reports/new?draft=${me}`,{replace:!0});_(1);return}}const t=Qt(await Ie({siteId:f.siteId,visitDate:f.visitDate,startTime:f.startTime||void 0,endTime:f.endTime||void 0,title:f.title||void 0,summaryNotes:f.summaryNotes||void 0,authorUserId:!F&&f.authorUserId?f.authorUserId:void 0,sections:D,returnVersion:!0})),o=t.id;let j=t.conflict?void 0:t.updatedAt;const T=Ca(G.current(),o);if(T!==void 0)try{const I=Qt(await Tt({...T,...j!==void 0?{baseUpdatedAt:j}:{returnVersion:!0}}));I.conflict?yt(G.current(),I.server).length>0?Te(I.server):j=I.server.updatedAt:I.updatedAt!==void 0&&(j=I.updatedAt)}catch{w("error")}Q.current=j??null,$.current=o,ae.current=ce(f,D),n(!0),R(`/maintenance-reports/${o}/edit`,{replace:!0}),_(1)}catch(t){t instanceof rt?Se(t):h({title:oe(t,"Failed"),variant:"destructive"})}finally{Ge(!1)}},Rs=(t,o,j)=>t==="add"?p.queue(W.addCharger,{chargerId:o,checklistTemplateId:es(k,j),reportId:g??void 0}):p.queue(W.removeCharger,{chargerId:o,reportId:g??void 0}),dt=async t=>{let o=J;const j=T=>h({title:a("maintenanceReports.offline.chargersNotSaved",{count:T}),variant:"destructive"});for(let T=0;T<t.length;T++){const I=t[T];if(o)try{await Rs(I.op,I.chargerId,I.chargerClass);continue}catch(me){if(Se(me),!Pt(me)){j(t.length-T);return}o=!1,await p.syncNow().catch(()=>{})}if(!g){j(t.length-T);return}I.op==="remove"?await ps({reportId:g,chargerId:I.chargerId}):await it({reportId:g,chargerId:I.chargerId,checklistTemplateId:es(k,I.chargerClass)})}},Cs=async(t,o)=>{if(!(J&&!re))try{await dt([{op:xe.has(t)?"remove":"add",chargerId:t,chargerClass:o}])}catch(j){h({title:oe(j,"Failed"),variant:"destructive"})}},ut=async t=>{if(!re||de)return;const o=c.chargers.filter(j=>(t==="all"||j.chargerClass===t)&&!xe.has(j.id));if(o.length!==0){Ce(!0);try{await dt(o.map(j=>({op:"add",chargerId:j.id,chargerClass:j.chargerClass})))}catch(j){h({title:oe(j,"Failed"),variant:"destructive"})}finally{Ce(!1)}}},Is=async()=>{if(de)return;const t=[...xe];if(t.length!==0){Ce(!0);try{await dt(t.map(o=>({op:"remove",chargerId:o})))}catch(o){h({title:oe(o,"Failed"),variant:"destructive"})}finally{Ce(!1)}}},Mt=J&&!!p.draft&&!p.draft.syncedAt,ve=J?p.conflict:null,ie=ve?.server??ue,[Ss,$e]=r.useState(!1),[Ds,et]=r.useState(!1),$t=r.useRef(null),tt=ve?.serverUpdatedAt??ue?.updatedAt,mt=!ve&&!!ue;r.useEffect(()=>{if(!mt)return;const t=o=>{o.preventDefault(),o.returnValue=""};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[mt]);const be=or({online:p.online,debouncePending:U||d==="saving",draftUnsynced:Mt,queued:p.enabled?p.ops.length:0,conflict:!!ie}),ye=cr({enabled:J,legacy:d,online:p.online,paused:p.paused,bound:!!p.draftKey,debouncePending:U,draftUnsynced:Mt,ops:p.ops,conflict:!!ie}),je=r.useMemo(()=>ie?Ta({...G.current(),meta:f,sections:D},ie,a,{chrgpkLabel:A}
1):null,[ie,f,D,i,A]);r.useEffect(()=>{if(!(!je||tt===void 0)){if(je.identical){ve?p.resolveIdentical().catch(()=>{}):ue&&(Q.current=ue.updatedAt,g&&Xe(g,G.current(),ue.updatedAt,Date.now()),ae.current=ce(f,D),Te(null),w("saved"));return}$t.current!==tt&&($t.current=tt,$e(!0))}},[je,tt]);const Ts=async()=>{et(!0);try{if(ve)await p.keepDeviceVersion();else if(ue&&g){const t=ue;if(!await _t(async()=>{const j=Date.now(),T=G.current(),I=await gt(ct,T,g,t.updatedAt);return I.version!==void 0&&(Q.current=I.version),I.kind==="conflict"?(Te(I.server),!1):(ae.current=ce(T.meta,T.sections),Xe(g,T,I.version,j),Te(null),w("saved"),!0)}))return}$e(!1),h({title:a("offlineSync.conflict.keptMine")})}catch{h({title:a("offlineSync.conflict.failed"),variant:"destructive"})}finally{et(!1)}},Ps=async()=>{if(ie){et(!0);try{ee.current&&(clearTimeout(ee.current),ee.current=null,C(!1)),await ot.current.catch(()=>!1);const t=!!ve,o=ka(ie,f),j=Na(ie),T=ce(o,j);ae.current=T,De.current=T,u(o),H(j),ve?await p.takeServerVersion({...G.current(),meta:o,sections:j}):(Q.current=ie.updatedAt,g&&Xe(g,{...G.current(),meta:o,sections:j},ie.updatedAt,Date.now()),Te(null),w("saved")),$e(!1),h({title:a(t?"offlineSync.conflict.tookServer":"offlineSync.conflict.tookServerWindow")})}catch{h({title:a("offlineSync.conflict.failed"),variant:"destructive"})}finally{et(!1)}}},As=async()=>{X(!1);try{const{draftDeleted:t}=await p.discardParked();if(!t)return;g?n(!1):R("/maintenance-reports")}catch(t){Se(t)}},Os=async()=>{if(!(!g||be)){Je(!0);try{const t=await hs({id:g,sections:D,endTime:Gt()});Ra("success"),h({title:a("maintenanceReports.finalized")});const o=Ia(t?.warnings,a);o&&h({title:a("partsConsumption.warningTitle"),description:o,variant:"destructive"}),await p.forgetDraft().catch(()=>{}),R(`/maintenance-reports/${g}`)}catch(t){h({title:oe(t,"Failed"),variant:"destructive"})}finally{Je(!1)}}};if(!O&&!K)return null;if(he)return e.jsx("div",{className:"relative z-10 mx-auto max-w-[1100px] px-3 pb-28 pt-4 sm:px-5",children:e.jsx(Ua,{t:a,backLabel:a("maintenanceReports.backToList"),onBack:()=>R("/maintenance-reports"),pendingOnDevice:p.enabled&&(p.ops.length>0||!!p.draft&&!p.draft.syncedAt),onOpenPending:()=>R("/pending-sync")})});const Fs=v===0?!!f.siteId&&(re||p.resolved):re,Vt=v===we.length-1,Us=!y&&!!p.draftKey,_s=()=>{v===0&&!re?Ns():_(t=>Math.min(t+1,we.length-1))};return e.jsxs("div",{className:"relative z-10 mx-auto max-w-[1100px] px-3 pb-28 pt-4 sm:px-5 max-lg:pb-4",children:[e.jsx(_a,{stale:ge.stale,savedAt:ge.savedAt,missing:ge.missing,className:"mx-auto mb-4 max-w-2xl"}),e.jsx(Pa,{keys:Aa("maintenance",p.draftKey,g),className:"mx-auto mb-4 max-w-2xl"}),ie&&je&&!je.identical&&e.jsx("div",{className:"mx-auto mb-4 max-w-2xl",children:e.jsx(Oa,{t:a,onChoose:()=>$e(!0),where:mt?"window":"device"})}),e.jsx(Fa,{t:a,open:Ss&&!!ie,onOpenChange:$e,rows:je?.rows??[],identical:je?.identical??!1,busy:Ds,onKeepMine:Ts,onUseServer:Ps}),S?e.jsxs("div",{className:"mb-5",children:[e.jsxs("p",{className:"text-sm font-medium text-muted-foreground",children:[a("maintenanceReports.stepOf",{n:v+1,total:we.length})," · ",a(we[v])]}),e.jsx("div",{className:"mt-2 h-1.5 w-full overflow-hidden rounded-full bg-muted",role:"progressbar","aria-valuenow":v+1,"aria-valuemin":1,"aria-valuemax":we.length,children:e.jsx("div",{className:"h-full rounded-full bg-brand-600 transition-all duration-300",style:{width:`${(v+1)/we.length*100}%`}})})]}):e.jsx("div",{className:"mb-5 flex items-center justify-center gap-1.5 sm:gap-3",children:we.map((t,o)=>{const j=o===0||re,T=o<v,I=o===v;return e.jsxs("button",{type:"button",disabled:!j,onClick:()=>j&&_(o),className:`flex items-center gap-2 rounded-full px-3 py-1.5 text-sm transition-colors ${I?"bg-brand-600 text-white":T?"bg-brand-100 text-brand-700 dark:bg-brand-950/50 dark:text-brand-300":"text-muted-foreground"} ${j?"":"opacity-40"}`,children:[e.jsx("span",{className:`flex h-5 w-5 items-center justify-center rounded-full text-xs ${I?"bg-white/20":T?"bg-brand-600 text-white":"bg-muted"}`,children:T?e.jsx(Le,{className:"h-3 w-3"}):o+1}),e.jsx("span",{className:"hidden sm:inline",children:a(t)})]},t)})}),v===0&&e.jsxs(ke,{className:q("mx-auto max-w-2xl space-y-4 p-5","co-card"),
1children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(fe,{children:a("maintenanceReports.site")}),e.jsx(ya,{sites:c.sites,value:f.siteId,onChange:t=>u(o=>({...o,siteId:t})),placeholder:a("maintenanceReports.selectSite"),disabled:re,className:"h-10 w-full"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(fe,{children:a("maintenanceReports.visitDate")}),e.jsx(Ma,{date:f.visitDate?new Date(f.visitDate+"T00:00:00"):void 0,onDateChange:t=>u(o=>({...o,visitDate:t?bt(t,"yyyy-MM-dd"):""}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(fe,{children:a("maintenanceReports.author")}),F?e.jsx(Ke,{value:s?`${s.firstName??""} ${s.lastName??""}`.trim()||s.email:"",readOnly:!0,disabled:!0,className:"bg-muted"}):e.jsxs(Nt,{value:f.authorUserId||s?._id||"",onValueChange:t=>u(o=>({...o,authorUserId:t})),children:[e.jsx(Rt,{children:e.jsx(Ct,{placeholder:a("maintenanceReports.selectAuthor")})}),e.jsx(It,{children:c.assignableUsers.map(t=>e.jsx(St,{value:t.id,children:t.displayName},t.id))})]})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(fe,{children:a("maintenanceReports.startTime")}),e.jsx(Ke,{type:"time",value:f.startTime,onChange:t=>u(o=>({...o,startTime:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(fe,{children:a("maintenanceReports.endTime")}),e.jsx(Ke,{type:"time",value:f.endTime,onChange:t=>u(o=>({...o,endTime:t.target.value}))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f.startTime&&f.endTime?a("maintenanceReports.durationValue",{duration:ja(f.startTime,f.endTime)}):a("maintenanceReports.endTimeHint")})]})]}),e.jsxs("div",{className:"co-card-inset space-y-3 p-4",children:[e.jsx(fe,{children:a("maintenanceReports.costs.title")}),e.jsx(Qa,{value:{electricianName:f.electricianName,callOutType:f.callOutType,electricianCost:f.electricianCost,internalHours:f.internalHours},onChange:t=>u(o=>({...o,...t})),showMoney:l.viewFinancials,invoice:y?.visitCosts?.invoice??null,onUploadInvoice:g?xs:void 0,onRemoveInvoice:g?gs:void 0,uploading:vs}),e.jsx(Ja,{reportId:g,value:{electricianName:f.electricianName,electricianCost:f.electricianCost},onFill:t=>u(o=>({...o,...t})),canSeeMoney:l.viewFinancials})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(fe,{children:a("maintenanceReports.reportTitle")}),e.jsx(Ke,{value:f.title,onChange:t=>u(o=>({...o,title:t.target.value})),placeholder:a("maintenanceReports.titlePlaceholder")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(fe,{children:a("maintenanceReports.summaryNotes")}),e.jsx(jt,{value:f.summaryNotes,onChange:t=>u(o=>({...o,summaryNotes:t.target.value})),placeholder:a("maintenanceReports.summaryPlaceholder"),rows:3})]})]}),v===1&&e.jsxs(ke,{className:q("space-y-3 p-5","co-card"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(fe,{children:a("maintenanceReports.selectChargers")}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[xe.size," / ",c.chargers.length]})]}),c.chargers.length===0?e.jsx("p",{className:"p-4 text-center text-sm text-muted-foreground",children:a("maintenanceReports.noChargersAtSite")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(Z,{type:"button",size:"sm",variant:"outline",disabled:de,onClick:()=>ut("all"),children:[de?e.jsx(Ae,{className:"mr-1 h-3.5 w-3.5 animate-spin"}):e.jsx(Le,{className:"mr-1 h-3.5 w-3.5"}),a("maintenanceReports.selectAll")]}),e.jsx(Z,{type:"button",size:"sm",variant:"outline",disabled:de||!c.chargers.some(t=>t.chargerClass==="ac"),onClick:()=>ut("ac"),children:a("maintenanceReports.selectAc")}),e.jsx(Z,{type:"button",size:"sm",variant:"outline",disabled:de||!c.chargers.some(t=>t.chargerClass==="dc"),onClick:()=>ut("dc"),children:a("maintenanceReports.selectDc")}),e.jsx(Z,{type:"button",size:"sm",variant:"ghost",disabled:de||xe.size===0,onClick:Is,children:a("maintenanceReports.clearAll")})]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:c.chargers.map(t=>
1{const o=xe.has(t.id),j=[t.brandName,t.modelName].filter(Boolean).join(" · ");return e.jsxs("button",{type:"button",disabled:de,onClick:()=>Cs(t.id,t.chargerClass),className:`flex items-center gap-3 rounded-xl border p-3 text-left transition-colors disabled:opacity-60 ${o?"border-brand-500 bg-brand-50 dark:border-brand-300 dark:bg-brand-950/40":"border-border bg-background hover:bg-muted"}`,children:[e.jsx("span",{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg ${o?"bg-brand-600 text-white":"bg-muted text-muted-foreground"}`,children:o?e.jsx(Le,{className:"h-4 w-4"}):e.jsx(ms,{className:"h-4 w-4"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:t.name}),j&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",children:j}),t.serialNumber&&e.jsx("span",{className:"block truncate text-[11px] text-muted-foreground/80",children:t.serialNumber})]}),t.chargerClass&&e.jsx("span",{className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold ${t.chargerClass==="dc"?"bg-purple-100 text-purple-700 dark:bg-purple-950/50 dark:text-purple-300":"bg-sky-100 text-sky-700 dark:bg-sky-950/50 dark:text-sky-300"}`,children:t.chargerClass.toUpperCase()})]},t.id)})})]})]}),v===2&&y&&e.jsxs("div",{className:"space-y-3",children:[p.enabled&&!p.online&&e.jsxs("p",{className:"co-card-inset flex items-start gap-2 p-3 text-xs text-muted-foreground",children:[e.jsx(wt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),a("maintenanceReports.offline.inspectionHint")]}),Et.length>0&&e.jsxs("p",{className:"co-card-inset flex items-center gap-2 p-3 text-xs text-muted-foreground",children:[e.jsx(at,{className:"h-3.5 w-3.5 shrink-0"}),a("maintenanceReports.offline.chargersWaiting",{count:Et.length})]}),e.jsx(lr,{value:J?p.context:null,children:e.jsx(vr,{report:ks??y,templates:k,categories:ne,chrgpkIncluded:m})})]}),v>=2&&Us&&e.jsx(ke,{className:q("mx-auto max-w-2xl p-5","co-card"),children:e.jsxs("p",{className:"flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(at,{className:"mt-0.5 h-4 w-4 shrink-0"}),a("maintenanceReports.offline.notOnServerYet")]})}),v===3&&y&&e.jsxs(ke,{className:q("mx-auto max-w-2xl space-y-4 p-5","co-card"),children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold",children:a("maintenanceReports.reviewTitle")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("maintenanceReports.reviewSubtitle")})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[e.jsxs("div",{className:q("p-3","co-card-inset"),children:[e.jsx("div",{className:q("text-2xl font-semibold","co-nums"),children:y.chargers.length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a("maintenanceReports.chargers")})]}),e.jsxs("div",{className:q("p-3","co-card-inset"),children:[e.jsx("div",{className:q("text-2xl font-semibold text-amber-600","co-nums"),children:y.chargers.reduce((t,o)=>t+o.defects.length,0)}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a("maintenanceReports.defects")})]}),e.jsxs("div",{className:q("p-3","co-card-inset"),children:[e.jsx("div",{className:q("text-2xl font-semibold","co-nums"),children:y.chargers.reduce((t,o)=>t+o.photos.length,0)+y.chargers.reduce((t,o)=>t+o.defects.reduce((j,T)=>j+T.photos.length,0),0)+(y.chrgpkPhotos?.length??0)}),e.jsx("div",{className:"text-xs text-muted-foreground",children:a("maintenanceReports.photos")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(fe,{children:a("maintenanceReports.pdfSections")}),e.jsx(Ya,{value:D,onChange:H,showChrgpk:y.chrgpk?.performed===!0})]}),e.jsx(Xa,{reportType:"maintenance",reportId:y.id,variant:"inset"}),y.chargers.length===0&&y.chrgpk?.performed!==!0&&e.jsxs("p",{className:"flex items-center gap-1.5 rounded-lg bg-amber-50 p-3 text-sm text-amber-700 dark:bg-amber-950/40",children:[e.jsx(Ne,{className:"h-4 w-4"}),a("maintenanceReports.selectChargers")]})]}),e.jsx(as,{open:pe,onOpenChange:X,children:e.jsxs(rs,{children:[e.jsxs(ns,{children:[e.jsx(is,{children:a("maintenanceReports.offline.discardConfirmTitle")}),e.jsx(cs,{children:a("maintenanceReports.offline.discardConfirmBody")})]}),e.jsxs(os,{children:[e.jsx(ls,{children:a("common.cancel")}),e.jsx(ds,{onClick:()=>{As()},variant:"destructive",children:a("maintenanceReports.offline.discardConfirm")})]})]})}),!(S&&M)&&e.jsxs("div",{ref:x,className:q("fixed left-[var(--rail-w)] right-0 z-40 border-t bg-background/95 backdrop-blur",S?"bottom-[var(--tabbar-h)] pb-[var(--safe-bottom)]":"bottom-0"),style:S?void 0:{paddingBottom:"env(safe-area-inset-bottom)"},children:[Vt&&be&&e.jsx("p",{id:"finalize-blocked-reason",role:"status",className:"mx-auto max-w-[1100px] px-4 pt-2 text-right text-xs text-muted-foreground",children:be.key==="conflict"?a("offlineSync.conflict.finalBlocked"):be.key==="offline"?a("maintenanceReports.offline.finalizeOffline"):a("maintenanceReports.offline.finalizePending",{count:be.count})}),e.jsxs("div",{className:"mx-auto flex max-w-[1100px] items-center justify-between gap-2 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[ye==="saving"&&e.jsxs(e.Fragment,{children:[e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}),a("maintenanceReports.saving")]}),ye==="saved"&&e.jsxs(e.Fragment,{children:[e.jsx(Le,{className:"h-3.5 w-3.5 text-emerald-500"}),a("maintenanceReports.saved")]}),ye==="device"&&e.jsxs(e.Fragment,{children:[e.jsx(at,{className:"h-3.5 w-3.5 text-amber-600"}),a("maintenanceReports.offline.savedOnDevice")]}),ye==="signin"&&e.jsxs(e.Fragment,{children:[e.jsx(at,{className:"h-3.5 w-3.5 text-amber-600"}),a("maintenanceReports.offline.signInToSync")]}),ye==="blocked"&&e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"h-3.5 w-3.5 text-destructive"}),a("maintenanceReports.offline.blocked"),e.jsxs(Z,{type:"button",size:"sm",variant:"ghost",className:"h-7 px-2",onClick:()=>{p.retryParked()},children:[e.jsx(er,{className:"mr-1 h-3.5 w-3.5"}),a("maintenanceReports.offline.retry")]}),e.jsx(Z,{type:"button",size:"sm",variant:"ghost",className:"h-7 px-2 co-text-negative",onClick:()=>X(!0),children:a("maintenanceReports.offline.discard")})]}),ye==="conflict"&&e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"h-3.5 w-3.5 text-amber-600"}),a("offlineSync.status.conflict")]}),ye==="error"&&e.jsxs(e.Fragment,{children:[e.jsx(wt,{className:"h-3.5 w-3.5 text-destructive"}),a("maintenanceReports.saveError")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v>0&&e.jsxs(Z,{variant:"outline",onClick:()=>_(t=>Math.max(t-1,0)),children:[e.jsx(tr,{className:"mr-1 h-4 w-4"}),a("maintenanceReports.back")]}),Vt?e.jsxs(Z,{onClick:Os,"aria-describedby":be?"finalize-blocked-reason":void 0,disabled:Qe||!!be||!y||y.chargers.length===0&&y.chrgpk?.performed!==!0,className:"settings-cta",children:[Qe?e.jsx(Ae,{className:"mr-1 h-4 w-4 animate-spin"}):e.jsx(sr,{className:"mr-1 h-4 w-4"}),a("maintenanceReports.finalize")]}):e.jsxs(Z,{onClick:_s,disabled:!Fs||We,children:[We?e.jsx(Ae,{className:"mr-1 h-4 w-4 animate-spin"}):null,a("maintenanceReports.next"),e.jsx(wa,{className:"ml-1 h-4 w-4"})]})]})]})]})]})}export{pn 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.