"use strict";(self["webpackChunkplatypush"]=self["webpackChunkplatypush"]||[]).push([[9636],{9636:function(e,t,r){r.r(t),r.d(t,{default:function(){return y}});var s=r(641),o=r(3751);const n={class:"procedures-container"},i={key:2,class:"procedures-list"},u={class:"procedures items"};function l(e,t,r,l,d,c){const a=(0,s.g2)("Loading"),h=(0,s.g2)("NoItems"),p=(0,s.g2)("Procedure"),m=(0,s.g2)("ProcedureEditor"),g=(0,s.g2)("FloatingButton");return(0,s.uX)(),(0,s.CE)("div",n,[(0,s.Lk)("header",null,[(0,s.bo)((0,s.Lk)("input",{type:"search",class:"filter",title:"Filter procedures",placeholder:"🔎","onUpdate:modelValue":t[0]||(t[0]=e=>d.filter=e)},null,512),[[o.Jo,d.filter]])]),(0,s.Lk)("main",null,[d.loading?((0,s.uX)(),(0,s.Wv)(a,{key:0})):Object.keys(d.procedures||{}).length?((0,s.uX)(),(0,s.CE)("div",i,[(0,s.Lk)("div",u,[((0,s.uX)(!0),(0,s.CE)(s.FK,null,(0,s.pI)(c.displayedProcedures,(e=>((0,s.uX)(),(0,s.CE)("div",{class:"item",key:e.name},[(0,s.bF)(p,{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))])])):((0,s.uX)(),(0,s.Wv)(h,{key:1},{default:(0,s.k6)((()=>t[3]||(t[3]=[(0,s.eW)(" No Procedures Configured ")]))),_:1})),d.showNewProcedureEditor?((0,s.uX)(),(0,s.Wv)(m,{key:3,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.Q3)("",!0),(0,s.bF)(g,{"icon-class":"fa fa-plus",text:"Add Procedure",onClick:t[2]||(t[2]=e=>d.showNewProcedureEditor=!0)})])])}var d=r(9828),c=r(656),a=r(6561),h=r(6923),p=r(5829),m=r(2002),g={components:{FloatingButton:c.A,Loading:d.A,NoItems:a.A,Procedure:h["default"],ProcedureEditor:p.A},mixins:[m.A],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})}},f=r(6262);const P=(0,f.A)(g,[["render",l],["__scopeId","data-v-627349c3"]]);var y=P}}]);
//# sourceMappingURL=9636.4268e1ce.js.map