import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,vt as n}from"./mui-BgU4WrXF.js";import{n as r}from"./MenuItem-BNgF7Xqv.js";import{n as i,t as a}from"./SearchHeader-CjrB_H_O.js";import{t as o}from"./TableHead-DZPVxfXH.js";import{t as s}from"./dayjs.min-C4hTNXA3.js";import{B as c,St as l,T as u,W as d,dt as f,l as p,pt as m,st as h,vt as g,w as _,wt as v,xt as y}from"./index-bel1r0Sr.js";import{t as b}from"./CollectionActions-Be6ZPRyC.js";import{t as x}from"./TableShimmer-CBuxG-nx.js";import{n as S,t as C}from"./useSettingsStyles-Bugi6oTj.js";var w=e(t(),1),T=e(s(),1),E=n(),D=()=>{let{classes:e}=C(),t=m(),n=p(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=u(`speedUnit`),F=u(`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=f(()=>I(O.length));h(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 d(i,P,t);case`distance`:return c(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)(v,{className:e.table,children:[(0,E.jsx)(o,{children:(0,E.jsxs)(g,{children:[(0,E.jsx)(y,{children:t(`sharedName`)}),(0,E.jsx)(y,{children:t(`sharedType`)}),(0,E.jsx)(y,{children:t(`maintenanceStart`)}),(0,E.jsx)(y,{children:t(`maintenancePeriod`)}),(0,E.jsx)(y,{className:e.columnAction})]})}),(0,E.jsxs)(l,{children:[O.map(t=>(0,E.jsxs)(g,{children:[(0,E.jsx)(y,{children:t.name}),(0,E.jsx)(y,{children:t.type}),(0,E.jsx)(y,{children:R(t.type,!0,t.start)}),(0,E.jsx)(y,{children:R(t.type,!1,t.period)}),(0,E.jsx)(y,{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};