import{p as I,l as O,r as i,m as l,B as S,ay as N,P as $,q as k,D,w as r,H as b,J as U,I as u,$ as p,F as R,G as x,E as K,R as B}from"./index-5ee1411a.js";import{b as E,a as P,V as j}from"./VCard-8ba7cfc2.js";import{m as q,c as G}from"./transition-cd9cc606.js";import{e as H,f as J,d as v}from"./VTextField-a8ac4f44.js";import{f as L}from"./forwardRefs-2fb8bd5a.js";import{a as T}from"./VBtn-1e45aba2.js";import{V as W}from"./VTable-3f843f69.js";import"./VImg-71612e97.js";import"./index-a55adddd.js";import"./VProgressCircular-4762adb7.js";import"./resizeObserver-5499429a.js";const z=I({...q(),...H()},"VForm"),A=O()({name:"VForm",props:z(),emits:{"update:modelValue":f=>!0,submit:f=>!0},setup(f,V){let{slots:y,emit:w}=V;const s=J(f),d=i();function _(t){t.preventDefault(),s.reset()}function c(t){const n=t,o=s.validate();n.then=o.then.bind(o),n.catch=o.catch.bind(o),n.finally=o.finally.bind(o),w("submit",n),n.defaultPrevented||o.then(C=>{var e;let{valid:m}=C;m&&((e=d.value)==null||e.submit())}),n.preventDefault()}return G(()=>{var t;return l("form",{ref:d,class:["v-form",f.class],style:f.style,novalidate:!0,onReset:_,onSubmit:c},[(t=y.default)==null?void 0:t.call(y,s)])}),L(s,d)}}),M={class:"border px-6 py-4"},Q={class:"border px-6 py-4"},ue=S({__name:"EditDeviceConfig",props:{deviceId:{}},setup(f){const V=N(),y=i({}),w=i({}),s=i(""),d=i(0),_=i(0),c=i(0),t=i(0),n=i(0),o=f;$(()=>o.deviceId,async m=>{if(m){console.log("Edit Device: "+m);const e=await B.getDeviceConfig(m);y.value=e,s.value=e.name,d.value=parseFloat(e.nominal_power),_.value=parseFloat(e.switch_on_delay)/60,c.value=parseFloat(e.switch_off_delay)/60,t.value=parseFloat(e.min_on_duration)/60,n.value=parseFloat(e.max_on_per_day)/60;const a=new Set(["id","name","type","nominal_power","switch_on_delay","switch_off_delay","min_on_duration","max_on_per_day"]),g=Object.keys(e).filter(F=>!a.has(F)),h={};g.forEach(F=>{h[F]=e[F]}),w.value=h}},{immediate:!0});const C=async function(){const m={name:s.value,nominal_power:d.value,switch_on_delay:_.value*60,switch_off_delay:c.value*60,min_on_duration:t.value*60,max_on_per_day:n.value*60};await B.saveDeviceConfig(o.deviceId,m),V.push({name:"devicessettings"})};return(m,e)=>(k(),D(U,null,[l(E,{class:"elevation-2 m-4 rounded-md p-4"},{default:r(()=>[l(P,null,{default:r(()=>[l(A,null,{default:r(()=>[l(v,{modelValue:s.value,"onUpdate:modelValue":e[0]||(e[0]=a=>s.value=a),label:u(p)("settings.name"),type:"input"},null,8,["modelValue","label"]),l(v,{modelValue:d.value,"onUpdate:modelValue":e[1]||(e[1]=a=>d.value=a),label:u(p)("settings.nominal_power")+" [W]",type:"number"},null,8,["modelValue","label"]),l(v,{modelValue:_.value,"onUpdate:modelValue":e[2]||(e[2]=a=>_.value=a),label:u(p)("settings.switch_on_delay")+" [min]",type:"number"},null,8,["modelValue","label"]),l(v,{modelValue:c.value,"onUpdate:modelValue":e[3]||(e[3]=a=>c.value=a),label:u(p)("settings.switch_off_delay")+" [min]",type:"number"},null,8,["modelValue","label"]),l(v,{modelValue:t.value,"onUpdate:modelValue":e[4]||(e[4]=a=>t.value=a),label:u(p)("settings.min_on_duration")+" [min]",type:"number"},null,8,["modelValue","label"]),l(v,{modelValue:n.value,"onUpdate:modelValue":e[5]||(e[5]=a=>n.value=a),label:u(p)("settings.max_on_per_day")+" [min]",type:"number"},null,8,["modelValue","label"]),l(T,{block:"",color:"primary",onClick:C},{default:r(()=>[R(x(u(p)("settings.save")),1)]),_:1})]),_:1}),e[7]||(e[7]=b("br",null,null,-1)),l(T,{block:"",onClick:e[6]||(e[6]=a=>u(V).back())},{default:r(()=>[R(x(u(p)("close")),1)]),_:1})]),_:1})]),_:1}),e[9]||(e[9]=b("br",null,null,-1)),l(E,{class:"elevation-2 m-4 rounded-md p-4"},{default:r(()=>[l(j,null,{default:r(()=>e[8]||(e[8]=[R("Values which can only be edit in the energy_assistant.yaml file")])),_:1}),l(P,null,{default:r(()=>[l(W,{class:"m-4 rounded-md border"},{default:r(()=>[b("tbody",null,[(k(!0),D(U,null,K(w.value,(a,g)=>(k(),D("tr",{key:g,class:"border text-left"},[b("td",M,x(g),1),b("td",Q,x(a),1)]))),128))])]),_:1})]),_:1})]),_:1})],64))}});export{ue as default};
