import{n as u,I as l,_ as o}from"./index-009d300e.js";const d={mixins:[l],props:{node:Object},components:{NodeScheduler:()=>o(()=>import("./NodeScheduler-a13bf24e.js"),["./NodeScheduler-a13bf24e.js","./index-009d300e.js","./index-fe507b7b.css"],import.meta.url)},data(){return{statuses:[{text:"Available",value:0},{text:"Enabled",value:1},{text:"Disabled",value:2}],loading:!1,newCode:"",newStatus:-1}},computed:{headers(){const s=[{text:"User Id",value:"id"},{text:"Code",value:"code"},{text:"Status",value:"status"}];return this.node.schedule&&s.push({text:"Scheduling",value:"schedule"}),s},values(){var s;return((s=this.node.values)==null?void 0:s.filter(e=>e.commandClass===99))||[]},userCodes(){if(!this.values)return[];const s=[];for(const e of this.values){const t=e.propertyKey,n=s[t]||this.getBaseItem(t),a=e.property;if(a==="userCode")n.code=e.value;else if(a==="userIdStatus")n.status=e.value;else continue;s[t]=n}return s}},methods:{async setEnabled(s){const e=!s.schedule.enabled;(await this.app.apiRequest("setEnabledSchedule",[this.node.id,e,s.id])).success||this.showSnackbar(`User ID ${s.id} ${e?"enabled":"disabled"}`,"success")},getStatus(s){var e;return(e=this.statuses.find(t=>t.value===s))==null?void 0:e.text},getSlots(s){const e=[];for(const t in this.node.schedule)e.push(...this.node.schedule[t].slots.filter(n=>n.userId===s).map(n=>({...n,type:t})));return e},getBaseItem(s){var t;const e={id:s};if(this.node.schedule){const n=this.getSlots(s);e.schedule={type:((t=n.find(a=>a.enabled))==null?void 0:t.type)||"daily",slots:n,enabled:this.node.userCodes.enabled.includes(s)}}return e},getValueId(s,e){return this.values.find(t=>t.propertyKey===s&&t.property===e)},async setUserCode(s){const e=this.newCode,t=this.getValueId(s.id,"userCode");t&&(t.newValue=e,this.$emit("updateValue",t))},async setUserStatus(s){const e=this.newStatus,t=this.getValueId(s.id,"userIdStatus");t&&(t.newValue=e,this.$emit("updateValue",t))}}};var r=function(){var e=this,t=e._self._c;return t("v-data-table",{attrs:{headers:e.headers,items:e.userCodes,"items-per-page":-1,"mobile-breakpoint":0,"footer-props":{showFirstLastPage:!0},dense:"","show-expand":!!e.node.schedule},scopedSlots:e._u([{key:"item.code",fn:function(n){return[t("v-edit-dialog",{attrs:{large:""},on:{open:function(a){e.newCode=n.item.code},close:function(a){e.newCode=""},save:function(a){return e.setUserCode(n.item)}},scopedSlots:e._u([{key:"input",fn:function(){return[t("v-text-field",{attrs:{label:"Code","single-line":""},model:{value:e.newCode,callback:function(a){e.newCode=a},expression:"newCode"}})]},proxy:!0}],null,!0)},[e._v(" "+e._s(n.item.code||"-------")+" ")])]}},{key:"item.status",fn:function(n){return[t("v-edit-dialog",{attrs:{large:""},on:{open:function(a){e.newStatus=n.item.status},close:function(a){e.newStatus=-1},save:function(a){return e.setUserStatus(n.item)}},scopedSlots:e._u([{key:"input",fn:function(){return[t("v-select",{attrs:{items:e.statuses,label:"Status","single-line":""},model:{value:e.newStatus,callback:function(a){e.newStatus=a},expression:"newStatus"}})]},proxy:!0}],null,!0)},[e._v(" "+e._s(e.getStatus(n.item.status)||"-------")+" ")])]}},{key:"item.schedule",fn:function({item:n}){return[t("v-btn",{attrs:{"x-small":"",color:n.schedule.enabled?"success":"error"},on:{click:function(a){return e.setEnabled(n)}}},[e._v(e._s(n.schedule.enabled?"Enabled":"Disabled"))]),t("p",{staticClass:"mb-0"},[e._v(" Mode: "),t("b",{staticClass:"text-capitalize"},[e._v(e._s(n.schedule.type||"---"))]),e._v(" Slots:"),t("b",[e._v(" "+e._s(n.schedule.slots.filter(a=>a.type===n.schedule.type).length))])])]}},{key:"expanded-item",fn:function({headers:n,item:a}){return[t("td",{attrs:{colspan:n.length}},[e.node.userCodes.available.includes(a.id)?t("node-scheduler",{attrs:{node:e.node,user:a,activeMode:a.schedule.type}}):t("p",{staticClass:"text-center ma-3"},[t("b",[e._v("Enable this User Id in order to set schedules")])])],1)]}}],null,!0)})},i=[],c=u(d,r,i,!1,null,null,null,null);const p=c.exports;export{p as default};
