"use strict";(self["webpackChunkplatypush"]=self["webpackChunkplatypush"]||[]).push([[1949],{1949:function(e,t,a){a.r(t),a.d(t,{default:function(){return f}});var l=a(6252);const i={key:2,class:"alarms-container"},n={class:"alarms items"};function s(e,t,a,s,d,o){const r=(0,l.up)("Loading"),m=(0,l.up)("NoItems"),u=(0,l.up)("Entity"),c=(0,l.up)("EntityModal"),p=(0,l.up)("AlarmEditor"),h=(0,l.up)("Modal"),y=(0,l.up)("FloatingButton");return(0,l.wg)(),(0,l.iD)(l.HY,null,[d.loading?((0,l.wg)(),(0,l.j4)(r,{key:0})):Object.keys(d.alarms).length?((0,l.wg)(),(0,l.iD)("div",i,[(0,l._)("div",n,[((0,l.wg)(!0),(0,l.iD)(l.HY,null,(0,l.Ko)(d.alarms,(e=>((0,l.wg)(),(0,l.iD)("div",{class:"item",key:e.external_id},[(0,l.Wm)(u,{value:e,onShowModal:t=>d.selectedAlarm=e.external_id},null,8,["value","onShowModal"])])))),128))])])):((0,l.wg)(),(0,l.j4)(m,{key:1},{default:(0,l.w5)((()=>[(0,l.Uk)(" No alarms configured ")])),_:1})),o.modalVisible?((0,l.wg)(),(0,l.j4)(c,{key:3,entity:d.alarms[d.selectedAlarm],visible:o.modalVisible,"config-values":{},onClose:t[0]||(t[0]=e=>d.selectedAlarm=null)},null,8,["entity","visible"])):(0,l.kq)("",!0),(0,l.Wm)(h,{title:"Add Alarm",visible:d.addAlarmModalVisible,onClose:t[1]||(t[1]=e=>d.addAlarmModalVisible=!1)},{default:(0,l.w5)((()=>[d.addAlarmModalVisible?((0,l.wg)(),(0,l.j4)(p,{key:0,value:d.newAlarm,"new-alarm":"",onInput:o.addAlarm},null,8,["value","onInput"])):(0,l.kq)("",!0)])),_:1},8,["visible"]),(0,l.Wm)(y,{"icon-class":"fa fa-stopwatch",text:"Add Alarm",onClick:t[2]||(t[2]=e=>d.addAlarmModalVisible=!0)})],64)}var d=a(1869),o=a(6791),r=a(1999),m=a(4558),u=a(3901),c=a(3493),p=a(3222),h=a(8637),y={components:{AlarmEditor:d["default"],Entity:m["default"],EntityModal:r["default"],FloatingButton:u.Z,Loading:o.Z,Modal:c.Z,NoItems:p.Z},mixins:[h.Z],props:{pluginName:{type:String},config:{type:Object,default:()=>{}}},data(){return{loading:!1,addAlarmModalVisible:!1,alarms:{},selectedAlarm:null,newAlarm:{condition_type:"cron",when:"* * * * *",audio_volume:this.$root.config?.alarm?.audio_volume??100,media_repeat:!0}}},computed:{modalVisible(){return null!=this.alarms[this.selectedAlarm]}},methods:{addAlarm(e){null!=e.external_id&&(e.name=e?.meta?.name_override||e.name,e.meta={...e.meta,icon:{class:e.meta?.icon?.["class"]||"fas fa-stopwatch"}},this.alarms[e.external_id]=e,this.addAlarmModalVisible=!1)},async refresh(){this.$emit("loading",!0);try{await this.request("alarm.status"),(await this.request("entities.get",{plugins:[this.pluginName]})).forEach((e=>this.addAlarm(e)))}finally{this.$emit("loading",!1)}},async onEntityUpdate(e){const t=e?.entity;t?.plugin===this.pluginName&&this.addAlarm(t)},async onEntityDelete(e){const t=e?.entity;t?.plugin===this.pluginName&&(this.selectedAlarm===t.external_id&&(this.selectedAlarm=null),this.alarms[t.external_id]&&delete this.alarms[t.external_id])}},mounted(){this.refresh(),this.subscribe(this.onEntityUpdate,"on-alarm-entity-update","platypush.message.event.entities.EntityUpdateEvent"),this.subscribe(this.onEntityDelete,"on-alarm-entity-delete","platypush.message.event.entities.EntityDeleteEvent")},unmounted(){this.unsubscribe("on-alarm-entity-update"),this.unsubscribe("on-alarm-entity-delete")}},g=a(3744);const b=(0,g.Z)(y,[["render",s],["__scopeId","data-v-52431f4a"]]);var f=b}}]);
//# sourceMappingURL=1949.78095338.js.map