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