"use strict";(self["webpackChunkplatypush"]=self["webpackChunkplatypush"]||[]).push([[5771],{45771:function(e,t,a){a.r(t),a.d(t,{default:function(){return b}});var l=a(20641);const i={key:2,class:"alarms-container"},n={class:"alarms items"};function s(e,t,a,s,d,o){const r=(0,l.g2)("Loading"),u=(0,l.g2)("NoItems"),m=(0,l.g2)("Entity"),c=(0,l.g2)("EntityModal"),h=(0,l.g2)("AlarmEditor"),p=(0,l.g2)("Modal"),y=(0,l.g2)("FloatingButton");return(0,l.uX)(),(0,l.CE)(l.FK,null,[d.loading?((0,l.uX)(),(0,l.Wv)(r,{key:0})):Object.keys(d.alarms).length?((0,l.uX)(),(0,l.CE)("div",i,[(0,l.Lk)("div",n,[((0,l.uX)(!0),(0,l.CE)(l.FK,null,(0,l.pI)(d.alarms,e=>((0,l.uX)(),(0,l.CE)("div",{class:"item",key:e.external_id},[(0,l.bF)(m,{value:e,onShowModal:t=>d.selectedAlarm=e.external_id},null,8,["value","onShowModal"])]))),128))])])):((0,l.uX)(),(0,l.Wv)(u,{key:1},{default:(0,l.k6)(()=>[...t[3]||(t[3]=[(0,l.eW)(" No alarms configured ",-1)])]),_:1})),o.modalVisible?((0,l.uX)(),(0,l.Wv)(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.Q3)("",!0),(0,l.bF)(p,{title:"Add Alarm",visible:d.addAlarmModalVisible,onClose:t[1]||(t[1]=e=>d.addAlarmModalVisible=!1)},{default:(0,l.k6)(()=>[d.addAlarmModalVisible?((0,l.uX)(),(0,l.Wv)(h,{key:0,value:d.newAlarm,"new-alarm":"",onInput:o.addAlarm},null,8,["value","onInput"])):(0,l.Q3)("",!0)]),_:1},8,["visible"]),(0,l.bF)(y,{"icon-class":"fa fa-stopwatch",text:"Add Alarm",onClick:t[2]||(t[2]=e=>d.addAlarmModalVisible=!0)})],64)}a(18111),a(7588);var d=a(63698),o=a(81350),r=a(7569),u=a(12367),m=a(30656),c=a(354),h=a(73072),p=a(91387),y={components:{AlarmEditor:d["default"],Entity:u["default"],EntityModal:r["default"],FloatingButton:m.A,Loading:o.A,Modal:c.A,NoItems:h.A},mixins:[p.A],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(66262);const A=(0,g.A)(y,[["render",s],["__scopeId","data-v-52431f4a"]]);var b=A}}]);
//# sourceMappingURL=5771.ad00b193.js.map