import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,vt as n}from"./mui-BgU4WrXF.js";import{a as r,r as i,t as a}from"./Select-Bu2vmaew.js";import{t as o}from"./EditAttributesAccordion-J3XCwwrK.js";import{i as s,n as c,r as l,t as u}from"./ExpandMore-D0ycvrdR.js";import{t as d}from"./Typography-7EcQ2i3p.js";import{t as f}from"./TextField-DctlzLY-.js";import{t as p}from"./dayjs.min-C4hTNXA3.js";import{$ as m,Dt as h,Q as g,T as _,Y as v,l as y,nt as b,pt as x,tt as S}from"./index-bel1r0Sr.js";import{n as C,t as w}from"./useSettingsStyles-Bugi6oTj.js";import{t as T}from"./EditItemView-BPUZddYO.js";var E=e(t(),1),D=e(p(),1),O=n(),k=()=>{let{classes:e}=w(),t=x(),n=y(t),[p,k]=(0,E.useState)(),[A,j]=(0,E.useState)({start:``,period:``}),M=_(`speedUnit`,`kn`),N=_(`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[p?.type];if(p?.type?.endsWith(`Time`))j({start:null,period:t(`sharedDays`)});else if(e&&e.dataType)switch(e.dataType){case`speed`:j({start:t(v(`shared`,M)),period:t(v(`shared`,M))});break;case`distance`:j({start:t(v(`shared`,N)),period:t(v(`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})},[p?.type,n,M,N,t]);let F=(e,t)=>{let r=n[p.type];if(p.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 S(t,M);case`distance`:return g(t,N);case`hours`:return t/36e5;default:return t}return t},I=(e,t)=>{let r=n[p.type];if(p.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 b(t,M);case`distance`:return m(t,N);case`hours`:return t*36e5;default:return t}return t};return(0,O.jsx)(T,{endpoint:`maintenance`,item:p,setItem:k,validate:()=>p&&p.name&&p.type&&p.start&&p.period,menu:(0,O.jsx)(C,{}),breadcrumbs:[`settingsTitle`,`sharedMaintenance`],children:p&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(s,{defaultExpanded:!0,children:[(0,O.jsx)(c,{expandIcon:(0,O.jsx)(u,{}),children:(0,O.jsx)(d,{variant:`subtitle1`,children:t(`sharedRequired`)})}),(0,O.jsxs)(l,{className:e.details,children:[(0,O.jsx)(f,{value:p.name||``,onChange:e=>k({...p,name:e.target.value}),label:t(`sharedName`)}),(0,O.jsxs)(r,{children:[(0,O.jsx)(i,{children:t(`sharedType`)}),(0,O.jsx)(a,{label:t(`sharedType`),value:p.type||``,onChange:e=>k({...p,type:e.target.value,start:0,period:0}),children:P(n).map(({key:e,name:t})=>(0,O.jsx)(h,{value:e,children:t},e))})]}),(0,O.jsx)(f,{type:p.type?.endsWith(`Time`)?`date`:`number`,value:F(!0,p.start)||``,onChange:e=>k({...p,start:I(!0,e.target.value)}),label:A.start?`${t(`maintenanceStart`)} (${A.start})`:t(`maintenanceStart`)}),(0,O.jsx)(f,{type:`number`,value:F(!1,p.period)||``,onChange:e=>k({...p,period:I(!1,e.target.value)}),label:A.period?`${t(`maintenancePeriod`)} (${A.period})`:t(`maintenancePeriod`)})]})]}),(0,O.jsx)(o,{attributes:p.attributes,setAttributes:e=>k({...p,attributes:e}),definitions:{}})]})})};export{k as default};