import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,wt as n}from"./mui-B6lh3XSP.js";import{t as r}from"./EditAttributesAccordion-BaG0aySx.js";import{i,n as a,r as o,t as s}from"./ExpandMore-BvigPYWL.js";import{t as c}from"./TextField-DOdnjCrL.js";import{t as l}from"./Typography-DfQXhGTT.js";import{t as u}from"./dayjs.min-C4hTNXA3.js";import{Bt as d,Ft as f,Gt as p,Nt as m,R as h,at as g,ct as _,it as v,l as y,st as b,tt as x,yt as S}from"./index-KVuxnkWj.js";import{n as C,t as w}from"./useSettingsStyles-X3caKosH.js";import{t as T}from"./EditItemView-BNkSnNuu.js";var E=e(t(),1),D=e(u(),1),O=n(),k=()=>{let{classes:e}=w(),t=S(),n=y(t),[u,k]=(0,E.useState)(),[A,j]=(0,E.useState)({start:``,period:``}),M=h(`speedUnit`,`kn`),N=h(`distanceUnit`,`km`),P=e=>{let t=[];return Object.keys(e).forEach(n=>{let r=e[n];(r.type===`number`||n.endsWith(`Time`))&&t.push({key:n,name:r.name,type:r.type})}),t};(0,E.useEffect)(()=>{let e=n[u?.type];if(u?.type?.endsWith(`Time`))j({start:null,period:t(`sharedDays`)});else if(e&&e.dataType)switch(e.dataType){case`speed`:j({start:t(x(`shared`,M)),period:t(x(`shared`,M))});break;case`distance`:j({start:t(x(`shared`,N)),period:t(x(`shared`,N))});break;case`hours`:j({start:t(`sharedHours`),period:t(`sharedHours`)});break;default:j({start:null,period:null});break}else j({start:null,period:null})},[u?.type,n,M,N,t]);let F=(e,t)=>{let r=n[u.type];if(u.type?.endsWith(`Time`))return e?(0,D.default)(t).locale(`en`).format(`YYYY-MM-DD`):t/864e5;if(r&&r.dataType)switch(r.dataType){case`speed`:return b(t,M);case`distance`:return v(t,N);case`hours`:return t/36e5;default:return t}return t},I=(e,t)=>{let r=n[u.type];if(u.type?.endsWith(`Time`))return e?(0,D.default)(t,`YYYY-MM-DD`).valueOf():t*864e5;if(r&&r.dataType)switch(r.dataType){case`speed`:return _(t,M);case`distance`:return g(t,N);case`hours`:return t*36e5;default:return t}return t};return(0,O.jsx)(T,{endpoint:`maintenance`,item:u,setItem:k,validate:()=>u&&u.name&&u.type&&u.start&&u.period,menu:(0,O.jsx)(C,{}),breadcrumbs:[`settingsTitle`,`sharedMaintenance`],children:u&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(i,{defaultExpanded:!0,children:[(0,O.jsx)(a,{expandIcon:(0,O.jsx)(s,{}),children:(0,O.jsx)(l,{variant:`subtitle1`,children:t(`sharedRequired`)})}),(0,O.jsxs)(o,{className:e.details,children:[(0,O.jsx)(c,{value:u.name||``,onChange:e=>k({...u,name:e.target.value}),label:t(`sharedName`)}),(0,O.jsxs)(p,{children:[(0,O.jsx)(d,{children:t(`sharedType`)}),(0,O.jsx)(m,{label:t(`sharedType`),value:u.type||``,onChange:e=>k({...u,type:e.target.value,start:0,period:0}),children:P(n).map(({key:e,name:t})=>(0,O.jsx)(f,{value:e,children:t},e))})]}),(0,O.jsx)(c,{type:u.type?.endsWith(`Time`)?`date`:`number`,value:F(!0,u.start)||``,onChange:e=>k({...u,start:I(!0,e.target.value)}),label:A.start?`${t(`maintenanceStart`)} (${A.start})`:t(`maintenanceStart`)}),(0,O.jsx)(c,{type:`number`,value:F(!1,u.period)||``,onChange:e=>k({...u,period:I(!1,e.target.value)}),label:A.period?`${t(`maintenancePeriod`)} (${A.period})`:t(`maintenancePeriod`)})]})]}),(0,O.jsx)(r,{attributes:u.attributes,setAttributes:e=>k({...u,attributes:e}),definitions:{}})]})})};export{k as default};