"use strict";(self["webpackChunkplatypush"]=self["webpackChunkplatypush"]||[]).push([[1949],{2797:function(t,e,a){a.d(e,{Z:function(){return m}});var l=a(6252),i=a(3577);const n=["title"];function s(t,e,a,s,o,r){const d=(0,l.up)("Icon");return(0,l.wg)(),(0,l.iD)("div",{class:(0,i.C_)(["floating-btn",r.className])},[(0,l._)("button",{type:"button",class:"btn btn-primary",title:a.title,onClick:e[0]||(e[0]=e=>t.$emit("click",e))},[(0,l.Wm)(d,{class:(0,i.C_)(a.iconClass),url:a.iconUrl},null,8,["class","url"])],8,n)],2)}var o=a(657),r={name:"FloatingButton",components:{Icon:o.Z},emits:["click"],props:{iconClass:{type:String},iconUrl:{type:String},class:{type:String},title:{type:String}},computed:{className(){return this.class}}},d=a(3744);const u=(0,d.Z)(r,[["render",s],["__scopeId","data-v-f812ef1c"]]);var m=u},1949:function(t,e,a){a.r(e),a.d(e,{default:function(){return b}});var l=a(6252);const i={key:2,class:"alarms-container"},n={class:"alarms items"};function s(t,e,a,s,o,r){const d=(0,l.up)("Loading"),u=(0,l.up)("NoItems"),m=(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,[o.loading?((0,l.wg)(),(0,l.j4)(d,{key:0})):Object.keys(o.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)(o.alarms,(t=>((0,l.wg)(),(0,l.iD)("div",{class:"item",key:t.external_id},[(0,l.Wm)(m,{value:t,onShowModal:e=>o.selectedAlarm=t.external_id},null,8,["value","onShowModal"])])))),128))])])):((0,l.wg)(),(0,l.j4)(u,{key:1},{default:(0,l.w5)((()=>[(0,l.Uk)(" No alarms configured ")])),_:1})),r.modalVisible?((0,l.wg)(),(0,l.j4)(c,{key:3,entity:o.alarms[o.selectedAlarm],visible:r.modalVisible,"config-values":{},onClose:e[0]||(e[0]=t=>o.selectedAlarm=null)},null,8,["entity","visible"])):(0,l.kq)("",!0),(0,l.Wm)(h,{title:"Add Alarm",visible:o.addAlarmModalVisible,onClose:e[1]||(e[1]=t=>o.addAlarmModalVisible=!1)},{default:(0,l.w5)((()=>[o.addAlarmModalVisible?((0,l.wg)(),(0,l.j4)(p,{key:0,value:o.newAlarm,"new-alarm":"",onInput:r.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:e[2]||(e[2]=t=>o.addAlarmModalVisible=!0)})],64)}var o=a(9381),r=a(6791),d=a(1999),u=a(4558),m=a(2797),c=a(5166),p=a(3222),h=a(8637),y={components:{AlarmEditor:o["default"],Entity:u["default"],EntityModal:d["default"],FloatingButton:m.Z,Loading:r.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(t){null!=t.external_id&&(t.name=t?.meta?.name_override||t.name,t.meta={...t.meta,icon:{class:t.meta?.icon?.["class"]||"fas fa-stopwatch"}},this.alarms[t.external_id]=t,this.addAlarmModalVisible=!1)},async refresh(){this.$emit("loading",!0);try{await this.request("alarm.status"),(await this.request("entities.get",{plugins:[this.pluginName]})).forEach((t=>this.addAlarm(t)))}finally{this.$emit("loading",!1)}},async onEntityUpdate(t){const e=t?.entity;e?.plugin===this.pluginName&&this.addAlarm(e)},async onEntityDelete(t){const e=t?.entity;e?.plugin===this.pluginName&&(this.selectedAlarm===e.external_id&&(this.selectedAlarm=null),this.alarms[e.external_id]&&delete this.alarms[e.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 f=(0,g.Z)(y,[["render",s],["__scopeId","data-v-52431f4a"]]);var b=f}}]);
//# sourceMappingURL=1949.3baca6d5.js.map