import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,wt as n}from"./mui-B6lh3XSP.js";import{n as r}from"./MenuItem-HQNtf0LG.js";import{n as i,t as a}from"./SearchHeader-CmohWzoP.js";import{t as o}from"./TableHead-_KJlbpnj.js";import{t as s}from"./dayjs.min-C4hTNXA3.js";import{At as c,Dt as l,K as u,Ot as d,R as f,X as p,_t as m,l as h,pt as g,w as _,wt as v,yt as y}from"./index-KVuxnkWj.js";import{t as b}from"./CollectionActions-CDxOJIb6.js";import{t as x}from"./TableShimmer-f7Cf4NTV.js";import{n as S,t as C}from"./useSettingsStyles-X3caKosH.js";var w=e(t(),1),T=e(s(),1),E=n(),D=()=>{let{classes:e}=C(),t=y(),n=h(t),[s,D]=(0,w.useReducer)(e=>e+1,0),[O,k]=(0,w.useState)([]),[A,j]=(0,w.useState)(``),[M,N]=(0,w.useState)(!0),P=f(`speedUnit`),F=f(`distanceUnit`),I=(0,w.useCallback)(async(e,t)=>{let n=new URLSearchParams({limit:50,offset:e});A&&n.append(`keyword`,A);let r=await(await _(`/api/maintenance?${n.toString()}`,{signal:t})).json();k(t=>e?[...t,...r]:r),N(r.length>=50)},[A]),L=m(()=>I(O.length));g(async({signal:e})=>{k([]),await I(0,e)},[s,I]);let R=(e,r,i)=>{let a=n[e];if(e.endsWith(`Time`))return r?(0,T.default)(i).locale(`en`).format(`YYYY-MM-DD`):`${i/864e5} ${t(`sharedDays`)}`;if(a&&a.dataType)switch(a.dataType){case`speed`:return p(i,P,t);case`distance`:return u(i,F,t);case`hours`:return`${i/36e5} ${t(`sharedHours`)}`;default:return i}return i};return(0,E.jsxs)(r,{menu:(0,E.jsx)(S,{}),breadcrumbs:[`settingsTitle`,`sharedMaintenance`],children:[(0,E.jsx)(a,{keyword:A,setKeyword:j}),(0,E.jsxs)(c,{className:e.table,children:[(0,E.jsx)(o,{children:(0,E.jsxs)(v,{children:[(0,E.jsx)(l,{children:t(`sharedName`)}),(0,E.jsx)(l,{children:t(`sharedType`)}),(0,E.jsx)(l,{children:t(`maintenanceStart`)}),(0,E.jsx)(l,{children:t(`maintenancePeriod`)}),(0,E.jsx)(l,{className:e.columnAction})]})}),(0,E.jsxs)(d,{children:[O.map(t=>(0,E.jsxs)(v,{children:[(0,E.jsx)(l,{children:t.name}),(0,E.jsx)(l,{children:t.type}),(0,E.jsx)(l,{children:R(t.type,!0,t.start)}),(0,E.jsx)(l,{children:R(t.type,!1,t.period)}),(0,E.jsx)(l,{className:e.columnAction,padding:`none`,children:(0,E.jsx)(b,{itemId:t.id,editPath:`/settings/maintenance`,endpoint:`maintenance`,onReload:D})})]},t.id)),M&&(0,E.jsx)(x,{ref:O.length>0?L:null,columns:5,endAction:!0})]})]}),(0,E.jsx)(i,{editPath:`/settings/maintenance`})]})};export{D as default};