import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,Nt as n,vt as r}from"./mui-BgU4WrXF.js";import{l as i,u as a}from"./IconButton-oialqkv3.js";import{t as o}from"./Container-fY8-hTkD.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{n as f}from"./MenuItem-BNgF7Xqv.js";import{t as p}from"./TextField-DctlzLY-.js";import{$ as m,Q as h,T as g,Ut as _,ct as v,et as y,pt as b,w as x}from"./index-bel1r0Sr.js";import{n as S,t as C}from"./useSettingsStyles-Bugi6oTj.js";var w=e(t(),1),T=r(),E=()=>{let e=i(),{classes:t}=C(),r=b(),E=g(`distanceUnit`),{deviceId:D}=a(),O=n(e=>e.session.positions[D]),[k,A]=(0,w.useState)();(0,w.useEffect)(()=>{O&&!k&&A({deviceId:parseInt(D,10),hours:O.attributes.hours||0,totalDistance:O.attributes.totalDistance||0})},[D,O,k]);let j=v(async()=>{await x(`/api/devices/${D}/accumulators`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(k)}),e(-1)});return(0,T.jsx)(f,{menu:(0,T.jsx)(S,{}),breadcrumbs:[`sharedDeviceAccumulators`],children:k&&(0,T.jsxs)(o,{maxWidth:`xs`,className:t.container,children:[(0,T.jsxs)(s,{defaultExpanded:!0,children:[(0,T.jsx)(c,{expandIcon:(0,T.jsx)(u,{}),children:(0,T.jsx)(d,{variant:`subtitle1`,children:r(`sharedRequired`)})}),(0,T.jsxs)(l,{className:t.details,children:[(0,T.jsx)(p,{type:`number`,value:k.hours/36e5,onChange:e=>A({...k,hours:Number(e.target.value)*36e5}),label:r(`positionHours`)}),(0,T.jsx)(p,{type:`number`,value:h(k.totalDistance,E),onChange:e=>A({...k,totalDistance:m(Number(e.target.value),E)}),label:`${r(`deviceTotalDistance`)} (${y(E,r)})`})]})]}),(0,T.jsxs)(`div`,{className:t.buttons,children:[(0,T.jsx)(_,{type:`button`,color:`primary`,variant:`outlined`,onClick:()=>e(-1),children:r(`sharedCancel`)}),(0,T.jsx)(_,{type:`button`,color:`primary`,variant:`contained`,onClick:j,children:r(`sharedSave`)})]})]})})};export{E as default};