import{d as P}from"./index-a9uUi1ey.js";import{_ as V,j as T,b as U,n as G,g as h,c as k,w as a,a as s,e as q,f as d,B as D,l as n,t as m,m as x,F as w,i as y,o as u}from"./index-CTxlYqj4.js";import{_ as S}from"./MenuItems-CaGz5Av4.js";import{V as N}from"./VMenu-DTm7W1Hp.js";import{V as M,d as H}from"./VAvatar-x_79C0tA.js";import{V as L}from"./VChip-Def9BYoN.js";import{V as E,a as J}from"./VToolbar-Cd2iSn8H.js";import{V as K}from"./VTextField-CWm47OUI.js";import{V as Q}from"./forwardRefs-BSESyuUp.js";import{V as W}from"./VDataTableServer-DyIOcZiN.js";import{b as X}from"./VCard-DRptUN8Y.js";import"./VProgressCircular-ubzZW5PC.js";import"./tag-Dx3OexMp.js";import"./ssrBoot-DGgZQEVC.js";import"./VDataTable-CYPG0MtF.js";import"./VSelect-tV4GZAtn.js";import"./VCheckboxBtn-xrhfoOlo.js";import"./VSelectionControl-Bdgm37Tl.js";import"./VTable-B-HE2nmK.js";import"./filter-DaBUD6Rp.js";const b="alarms",v={getAll(i){return V.get(`${b}/`,{params:i})},switchStatus(i,e){return V.patch(`${b}/${i}/switch/`,e)},delete(i){return V.delete(`${b}/${i}/`)},bulkDelete(i){return V.delete(`${b}/bulk_delete/`,{params:{ids:i}})}},Y={class:"text-right"},Z={__name:"AlarmList",setup(i){const{$gettext:e}=U(),p=G(),$=h([]),A=h(!1),f=h(""),_=h([]),C=h(0),z=[{title:e("Triggered"),key:"created"},{title:e("Status"),key:"status"},{title:e("Domain"),key:"domain.name",sortable:!1},{title:e("Mailbox"),key:"mailbox",sortable:!1},{title:e("Message"),key:"title"},{title:e("Actions"),key:"actions",sortable:!1,align:"right"}];function B(){const l=[];return _.value.length>0&&l.push({label:e("Delete"),icon:"mdi-delete-outline",onClick:R,color:"red"}),l.push({label:e("Reload"),icon:"mdi-reload",onClick:r}),l}function I(l){const o=[];return o.push({label:e("Delete"),icon:"mdi-delete-outline",onClick:O,color:"red"}),l.status===y.ALARM_OPENED?o.push({label:e("Close alarm"),icon:"mdi-check",onClick:j,color:"green"}):o.push({label:e("Reopen alarm"),icon:"mdi-alert-circle-outline",onClick:F,color:"orange"}),o}function r({page:l,itemsPerPage:o,sortBy:t}){const g={page:l||1,page_size:o||10};t&&t.length&&(g.ordering=t.map(c=>c.order!=="asc"?`-${c.key}`:c.key).join(",")),f.value!==""&&(g.search=f.value),A.value=!0,v.getAll(g).then(c=>{$.value=c.data.results,C.value=c.data.count,A.value=!1})}async function O(l,o=!0){v.delete(l.id).then(()=>{o&&(p.displayNotification({msg:e("Alarm deleted")}),r({}))})}async function R(){await v.bulkDelete(_.value.map(l=>l.id)),p.displayNotification({msg:e("Alarms deleted")}),_.value=[],r({})}async function j(l){v.switchStatus(l.id,{status:y.ALARM_CLOSED}).then(()=>{p.displayNotification({msg:e("Alarm closed")}),r({})})}async function F(l){v.switchStatus(l.id,{status:y.ALARM_OPENED}).then(()=>{p.displayNotification({msg:e("Alarm re-opened")}),r({})})}return r=P(r,500),(l,o)=>(u(),k(X,{class:"mt-6"},{default:a(()=>[s(W,{modelValue:_.value,"onUpdate:modelValue":o[1]||(o[1]=t=>_.value=t),headers:z,items:$.value,search:f.value,"item-value":"id","items-length":C.value,loading:A.value,elevation:"0","show-select":"","onUpdate:options":r},{top:a(()=>[s(E,{color:"white",flat:""},{default:a(()=>[s(K,{modelValue:f.value,"onUpdate:modelValue":o[0]||(o[0]=t=>f.value=t),"prepend-inner-icon":"mdi-magnify",placeholder:d(e)("Search"),density:"compact",variant:"outlined","hide-details":"",flat:"","single-line":"",class:"flex-grow-0 w-33 mr-4"},null,8,["modelValue","placeholder"]),s(N,{location:"bottom"},{activator:a(({props:t})=>[s(M,D(t,{size:"small"}),{default:a(()=>[n(m(d(e)("Actions"))+" ",1),s(H,{right:""},{default:a(()=>o[2]||(o[2]=[n("mdi-chevron-down")])),_:1,__:[2]})]),_:2},1040)]),default:a(()=>[s(Q,{density:"compact"},{default:a(()=>[s(d(S),{items:B()},null,8,["items"])]),_:1})]),_:1})]),_:1})]),"item.status":a(({item:t})=>[t.status===1?(u(),k(L,{key:0,color:"warning",size:"small"},{default:a(()=>[n(m(d(e)("Opened")),1)]),_:1})):(u(),k(L,{key:1,color:"info",size:"small"},{default:a(()=>[n(m(d(e)("Closed")),1)]),_:1}))]),"item.mailbox":a(({item:t})=>[t.mailbox?(u(),x(w,{key:0},[n(m(t.mailbox.address)+"@"+m(t.domain.name),1)],64)):(u(),x(w,{key:1},[n(" / ")],64))]),"item.created":a(({item:t})=>[n(m(l.$date(t.created)),1)]),"item.actions":a(({item:t})=>[q("div",Y,[s(N,{location:"bottom"},{activator:a(({props:g})=>[s(M,D({icon:"mdi-dots-horizontal"},g,{variant:"text"}),null,16)]),default:a(()=>[s(d(S),{items:I(t),obj:t},null,8,["items","obj"])]),_:2},1024)])]),_:2},1032,["modelValue","items","search","items-length","loading"])]),_:1}))}},ee=T(Z,[["__scopeId","data-v-43da963f"]]),te={__name:"AlarmsView",setup(i){return(e,p)=>(u(),x(w,null,[s(E,{flat:""},{default:a(()=>[s(J,null,{default:a(()=>[n(m(e.$gettext("Opened alarms")),1)]),_:1})]),_:1}),s(ee)],64))}},ke=T(te,[["__scopeId","data-v-d7e4ea18"]]);export{ke as default};
