"use strict";(self["webpackChunkplatypush"]=self["webpackChunkplatypush"]||[]).push([[2164],{2164:function(e,t,r){r.r(t),r.d(t,{default:function(){return P}});var s=r(6252),n=r(9963);const o={class:"procedures-container"},i={key:2,class:"procedures-list"},l={class:"procedures items"};function u(e,t,r,u,d,c){const a=(0,s.up)("Loading"),p=(0,s.up)("NoItems"),h=(0,s.up)("Procedure"),m=(0,s.up)("ProcedureEditor"),g=(0,s.up)("FloatingButton");return(0,s.wg)(),(0,s.iD)("div",o,[(0,s._)("header",null,[(0,s.wy)((0,s._)("input",{type:"search",class:"filter",title:"Filter procedures",placeholder:"🔎","onUpdate:modelValue":t[0]||(t[0]=e=>d.filter=e)},null,512),[[n.nr,d.filter]])]),(0,s._)("main",null,[d.loading?((0,s.wg)(),(0,s.j4)(a,{key:0})):Object.keys(d.procedures||{}).length?((0,s.wg)(),(0,s.iD)("div",i,[(0,s._)("div",l,[((0,s.wg)(!0),(0,s.iD)(s.HY,null,(0,s.Ko)(c.displayedProcedures,(e=>((0,s.wg)(),(0,s.iD)("div",{class:"item",key:e.name},[(0,s.Wm)(h,{value:e,selected:d.selectedProcedure===e.name,collapseOnHeaderClick:!0,onClick:t=>c.toggleProcedure(e),onInput:t=>c.updateProcedure(e),onDelete:()=>delete d.procedures[e.name]},null,8,["value","selected","onClick","onInput","onDelete"])])))),128))]),d.showNewProcedureEditor?((0,s.wg)(),(0,s.j4)(m,{key:0,value:d.newProcedure,title:"Add Procedure","with-name":!0,"with-save":!0,"read-only":!1,visible:d.showNewProcedureEditor,onInput:t[1]||(t[1]=e=>c.updateProcedure(d.newProcedure)),onClose:c.resetNewProcedure},null,8,["value","visible","onClose"])):(0,s.kq)("",!0)])):((0,s.wg)(),(0,s.j4)(p,{key:1},{default:(0,s.w5)((()=>[(0,s.Uk)(" No Procedures Configured ")])),_:1})),(0,s.Wm)(g,{"icon-class":"fa fa-plus",text:"Add Procedure",onClick:t[2]||(t[2]=e=>d.showNewProcedureEditor=!0)})])])}var d=r(6791),c=r(3825),a=r(3222),p=r(5144),h=r(6577),m=r(8637),g={components:{FloatingButton:c.Z,Loading:d.Z,NoItems:a.Z,Procedure:p["default"],ProcedureEditor:h.Z},mixins:[m.Z],props:{pluginName:{type:String},config:{type:Object,default:()=>{}}},data(){return{filter:"",loading:!1,newProcedure:null,newProcedureTemplate:{name:"",actions:[],meta:{icon:{class:"fas fa-cogs",url:null,color:null}}},procedures:{},selectedProcedure:null,showConfirmClose:!1,showNewProcedureEditor:!1}},computed:{displayedProcedures(){return Object.values(this.procedures).filter((e=>e.name.toLowerCase().includes(this.filter.toLowerCase())))}},methods:{mergeArgs(e,t){return{...Object.fromEntries(Object.entries(e||{}).map((([e,r])=>{const s=t?.[e];return null!=s?"object"!==typeof r||Array.isArray(r)?[e,s]:[e,this.mergeArgs(r,s)]:[e,r]}))),...Object.fromEntries(Object.entries(t||{}).filter((([t])=>null==e?.[t])))}},updateProcedure(e){if(!e?.name?.length)return;const t=this.procedures[e.name];this.procedures[e.name]={...this.mergeArgs(t,e),name:e?.meta?.name_override||e.name},this.showNewProcedureEditor=!1},async refresh(){const e=this.getUrlArgs();e.filter&&(this.filter=e.filter),this.loading=!0;try{this.procedures=await this.request("procedures.status")}finally{this.loading=!1}},onEntityUpdate(e){const t=e?.entity;t?.plugin===this.pluginName&&t?.name?.length&&this.updateProcedure(t)},onEntityDelete(e){const t=e?.entity;t?.plugin===this.pluginName&&(this.selectedProcedure===t.name&&(this.selectedProcedure=null),this.procedures[t.name]&&delete this.procedures[t.name])},resetNewProcedure(){this.showNewProcedureEditor=!1,this.newProcedure=JSON.parse(JSON.stringify(this.newProcedureTemplate))},toggleProcedure(e){this.selectedProcedure=this.selectedProcedure===e.name?null:e.name}},watch:{filter(){this.filter?.length?this.setUrlArgs({filter:this.filter}):this.setUrlArgs({filter:null})},showNewProcedureEditor(e){e||this.resetNewProcedure()}},async mounted(){this.resetNewProcedure(),await this.refresh(),this.subscribe(this.onEntityUpdate,"on-procedure-entity-update","platypush.message.event.entities.EntityUpdateEvent"),this.subscribe(this.onEntityDelete,"on-procedure-entity-delete","platypush.message.event.entities.EntityDeleteEvent")},unmounted(){this.unsubscribe("on-procedure-entity-update"),this.unsubscribe("on-procedure-entity-delete"),this.setUrlArgs({filter:null})}},w=r(3744);const f=(0,w.Z)(g,[["render",u],["__scopeId","data-v-d1fc8572"]]);var P=f}}]);
//# sourceMappingURL=2164.345ae71f.js.map