import{c as Gt,a as w,d as cs,f as k,s as p,r as us}from"../chunks/DktbhmWA.js";import{f as Wt,p as ds,d as h,e as we,o as fs,a5 as vs,u as Ft,c as l,s as c,t as X,a as ms,g as r,b as a,h as Re,r as o}from"../chunks/CPWcrcMP.js";import{i as M}from"../chunks/0jvM7PZf.js";import{I as Xt,h as Yt,m as H,A as O,a as Vt,r as ps,e as qt,i as Qt}from"../chunks/CNDZS43m.js";import{b as Ut}from"../chunks/CFyEX9sq.js";import{b as bs}from"../chunks/CX78IQmC.js";import{T as hs,p as _s}from"../chunks/P-kzdO9z.js";import{G as gs}from"../chunks/hnRDlRMB.js";import{A as dt}from"../chunks/CzZhYwF2.js";import"../chunks/CvCfPjaJ.js";import{l as Kt,s as Zt}from"../chunks/DBypTyp2.js";function ys(R,_){const y=Kt(_,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const I=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0"}],["path",{d:"M22 8c0-2.3-.8-4.3-2-6"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"}],["path",{d:"M4 2C2.8 3.7 2 5.7 2 8"}]];Xt(R,Zt({name:"bell-ring"},()=>y,{get iconNode(){return I},children:(S,u)=>{var j=Gt(),J=Wt(j);Yt(J,_,"default",{}),w(S,j)},$$slots:{default:!0}}))}function ws(R,_){const y=Kt(_,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const I=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"}]];Xt(R,Zt({name:"bell"},()=>y,{get iconNode(){return I},children:(S,u)=>{var j=Gt(),J=Wt(j);Yt(J,_,"default",{}),w(S,j)},$$slots:{default:!0}}))}function xs(R,_,y,I){const S=_();if(!S.length){a(y,"Select at least one unacknowledged alarm.");return}I(S)}function As(R,_,y,I,S,u,j,J){if(!r(_)){if(!r(y)){a(I,"No alarm selected.");return}if(!r(S).trim()){a(I,"Comment is required.");return}if(!O.username.trim()){a(I,"Unable to identify active user.");return}a(u,!0),a(I,""),j(J()),H.publish("Alarms/Comments/Add",JSON.stringify({alarmId:r(y).alarmId,sourceTopic:r(y).sourceTopic,commentText:r(S).trim(),commentBy:O.username}),!1)}}var Ts=(R,_)=>_("active"),ks=(R,_)=>_("history"),Ss=(R,_)=>R.key==="Enter"&&_(),Is=(R,_,y)=>{a(_,""),y()},Ls=k('<button class="btn btn-sm btn-primary w-full sm:w-auto">Acknowledge selected</button>'),Cs=k('<div class="alert alert-warning py-2"><span> </span></div>'),$s=k('<div class="alert alert-error py-2"><span> </span></div>'),Ds=k('<div class="text-xs opacity-70 -mt-1">Swipe table horizontally to view all columns.</div>'),Ns=k('<div class="card bg-base-200 border border-base-300 p-3 gap-3"><div class="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-2"><div class="flex flex-col sm:flex-row sm:items-center gap-2 w-full lg:w-auto"><input type="text" class="input input-bordered input-sm w-full sm:w-72" placeholder="Search device, source, text..."/> <div class="flex items-center gap-2"><button class="btn btn-sm btn-outline flex-1 sm:flex-none">Search</button> <button class="btn btn-sm btn-ghost flex-1 sm:flex-none">Clear</button></div></div> <div class="flex flex-wrap items-center gap-2 justify-between lg:justify-end"><span class="badge badge-ghost"> </span> <!></div></div> <!> <!> <div class="alarm-table-wrap"><div class="alarm-tabulator"></div></div> <!></div>'),Ms=k('<h1 class="text-4xl text-error font-semibold">No access</h1>'),Rs=k('<div class="opacity-70">Loading history...</div>'),Es=k('<div class="opacity-70">No history points available.</div>'),Ps=k("<tr><td> </td><td> </td></tr>"),Hs=k('<div class="overflow-auto max-h-80 border border-base-300 rounded-lg"><table class="table table-xs"><thead><tr><th>Timestamp</th><th>Value</th></tr></thead><tbody></tbody></table></div>'),Os=k('<div class="flex flex-col gap-2 mb-3"><textarea class="textarea textarea-bordered w-full h-20" placeholder="Add comment to this alarm source..."></textarea> <div class="flex justify-end"><button class="btn btn-sm btn-primary"> </button></div></div>'),js=k('<div class="alert alert-error py-2 mb-2"><span> </span></div>'),zs=k('<div class="opacity-70">Loading comments...</div>'),Bs=k('<div class="opacity-70">No comments yet for this source.</div>'),Js=k("<tr><td> </td><td> </td><td> </td></tr>"),Fs=k('<div class="overflow-auto max-h-56 border border-base-300 rounded-lg"><table class="table table-xs"><thead><tr><th>Timestamp</th><th>User</th><th>Comment</th></tr></thead><tbody></tbody></table></div>'),Vs=(R,_,y)=>r(_)&&y([r(_).alarmId]),qs=k('<button class="btn btn-primary">Acknowledge</button>'),Qs=k('<div class="modal modal-open"><div class="modal-box w-[calc(100%-1rem)] sm:w-11/12 max-w-6xl max-h-[92vh] overflow-y-auto"><div class="flex flex-wrap justify-between items-start gap-3"><div><h3 class="text-2xl font-semibold">Alarm Details</h3> <p class="opacity-80 text-sm break-all"> </p></div> <div class="flex items-center gap-2"><!> <span class="text-sm font-medium"> </span></div></div> <div class="grid grid-cols-1 md:grid-cols-2 gap-3 mt-3 text-sm"><div class="card bg-base-200 border border-base-300 p-3"><div><span class="font-semibold">Device:</span> </div> <div><span class="font-semibold">Device ID:</span> </div> <div><span class="font-semibold">Source:</span> </div> <div><span class="font-semibold">Text:</span> </div> <div><span class="font-semibold">Triggered:</span> </div> <div><span class="font-semibold">Last seen:</span> </div> <div><span class="font-semibold">Cleared:</span> </div> <div><span class="font-semibold">Ack by:</span> </div> <div><span class="font-semibold">Ack at:</span> </div> <div><span class="font-semibold">Ack comment:</span> </div></div> <div class="card bg-base-200 border border-base-300 p-3"><div class="font-semibold mb-2"> </div> <!></div></div> <div class="card bg-base-200 border border-base-300 p-3 mt-3 text-sm"><div class="flex items-center justify-between gap-2 mb-2"><div class="font-semibold break-all"> </div></div> <!> <!> <!></div> <div class="modal-action flex-col-reverse sm:flex-row"><!> <button class="btn btn-outline">Close</button></div></div> <form method="dialog" class="modal-backdrop"><button>close</button></form></div>'),Us=k('<section><div class="container mx-auto px-2 sm:px-4"><div class="flex items-center gap-2 sticky bg-base-100 z-40 pb-2" style="top:4.11rem"><!></div> <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-3"><h2 class="text-3xl sm:text-4xl font-semibold">Alarms</h2> <div class="join w-full sm:w-auto"><button>Active / Unacked</button> <button>Historical</button></div></div> <!></div> <!></section>');function na(R,_){ds(_,!0);const y=Re(()=>!O.canEditAlarms),I=Re(()=>O.canViewAlarms);let S=h(null),u=null,j=null,J=!1,pe=null,Y=h("active"),L=h(!1),xe=h(""),F=h(we([])),ft=h(0),Ee=h(!1),se=h(""),K=h(""),ae=h(we([])),Pe=h(we([])),He=h(0),Oe=h(we([])),je=h(!1),v=h(null),ne=h(we([])),ze=h(!1),V=h(we([])),ie=h(!1),Ae=h(""),re=h(""),Te=h(!1),oe=h(""),le="",q=null,ke="",be=[],vt=0,ce=null,ue=null,mt=[],Be=0,z=null;const Se=()=>H.getClientId(),er="Alarms/#",Je=()=>`${Se()}/Alarms/Query_Response`,pt=()=>`${Se()}/Alarms/Ack_Response`,bt=()=>`${Se()}/Alarms/TablePrefs/Query_Response`,ht=()=>`${Se()}/Alarms/Comments/Add_Response`,tr=()=>[bt()],rr=new Set(["_select","statusRank","sourceDisplay","triggeredAt","messageText","alarmId","sourceTopic"]),sr={_select:36,statusRank:88,triggeredAt:118,sourceDisplay:210,messageText:180};fs(()=>{r(I)&&(ar(),_t(),ur(),H.addMessageHandler(yt),Ie({clearSelection:!0}),At())}),vs(()=>{H.removeMessageHandler(yt);for(const e of be)H.unsubscribe(e);ce&&(clearTimeout(ce),ce=null),ue&&(clearTimeout(ue),ue=null),q&&(clearTimeout(q),q=null),u&&(u.destroy(),u=null),z&&(z(),z=null),nr()}),Ft(()=>{!r(I)||O.userId<=0||O.userId===vt||At()}),Ft(()=>{dt.value,u&&$e()});function _t(){r(S)&&(u=new hs(r(S),{data:r(Oe),layout:"fitDataTable",responsiveLayout:!1,height:r(L)?"56vh":"68vh",index:"alarmId",movableColumns:!0,selectableRows:!r(y),placeholder:"No alarms found for this view.",renderVertical:"virtual",columns:[{title:"",field:"_select",formatter:"rowSelection",titleFormatter:"rowSelection",hozAlign:"center",headerHozAlign:"center",headerSort:!1,frozen:!r(L),width:r(L)?36:44,visible:!r(y)},{title:"Status",field:"statusRank",width:r(L)?90:96,minWidth:r(L)?86:92,hozAlign:"center",headerHozAlign:"center",sorter:"number",formatter:e=>Rr(e.getRow().getData())},{title:"Source",field:"sourceDisplay",minWidth:r(L)?210:270},{title:"Timestamp",field:"triggeredAt",width:r(L)?120:146,minWidth:r(L)?116:140,sorter:"datetime",formatter:e=>Er(e.getValue())},{title:"Text",field:"messageText",minWidth:r(L)?220:300},{title:"ID",field:"alarmId",visible:!1},{title:"SourceTopic",field:"sourceTopic",visible:!1}],rowFormatter:e=>{const t=e.getData(),s=e.getElement();s.classList.toggle("alarm-row-active",t.isActive),s.classList.toggle("alarm-row-normal",!t.isActive)}}),u.on("rowSelectionChanged",e=>{a(F,e.map(t=>t.alarmId),!0)}),u.on("rowMouseDown",()=>{mt=[...r(F)]}),u.on("rowClick",(e,t)=>{const s=e.target;s!=null&&s.closest('.tabulator-cell[tabulator-field="_select"]')||Date.now()<Be||(lr(),$r(t.getData()))}),r(L)||(u.on("columnMoved",Ve),u.on("columnResized",Ve),u.on("columnVisibilityChanged",Ve)),j&&!J&&!r(L)&&Tt(j),or(),$e())}function ar(){typeof window>"u"||(pe=window.matchMedia("(max-width: 640px)"),a(L,pe.matches,!0),pe.addEventListener("change",gt))}function nr(){pe&&(pe.removeEventListener("change",gt),pe=null)}function gt(e){const t=e.matches;t!==r(L)&&(a(L,t,!0),ir())}function ir(){r(S)&&(u&&(u.destroy(),u=null),z&&(z(),z=null),J=!1,_t())}function or(){if(!r(S))return;z&&(z(),z=null);const e=r(S).querySelector(".tabulator-tableholder");if(!(e instanceof HTMLDivElement))return;const t=r(S);let s=0,i=0,n=0,d=!1,x=null;const E=(A,C)=>{s=A,i=C,n=e.scrollLeft,d=!1},Q=(A,C,$)=>{const g=A-s,fe=C-i;if(!d){if(Math.abs(g)<7||Math.abs(g)<=Math.abs(fe))return;d=!0,e.classList.add("alarm-pan-dragging")}e.scrollLeft=n-g,Be=Date.now()+250,$==null||$.preventDefault()},U=()=>{d&&(Be=Date.now()+250),d=!1,e.classList.remove("alarm-pan-dragging")};if(typeof window<"u"&&"PointerEvent"in window){const A=g=>{if(g.isPrimary!==!1&&g.pointerType!=="mouse"){x=g.pointerId,E(g.clientX,g.clientY);try{t.setPointerCapture(g.pointerId)}catch{}}},C=g=>{x==null||g.pointerId!==x||Q(g.clientX,g.clientY,g)},$=g=>{if(!(x==null||g.pointerId!==x)){x=null,U();try{t.releasePointerCapture(g.pointerId)}catch{}}};t.addEventListener("pointerdown",A,{passive:!0,capture:!0}),t.addEventListener("pointermove",C,{passive:!1,capture:!0}),t.addEventListener("pointerup",$,{passive:!0,capture:!0}),t.addEventListener("pointercancel",$,{passive:!0,capture:!0}),z=()=>{t.removeEventListener("pointerdown",A,!0),t.removeEventListener("pointermove",C,!0),t.removeEventListener("pointerup",$,!0),t.removeEventListener("pointercancel",$,!0),x=null,U()};return}let Z=!1;const _e=A=>{if(A.touches.length!==1)return;const C=A.touches[0];E(C.clientX,C.clientY),Z=!0},ee=A=>{if(!Z||A.touches.length!==1)return;const C=A.touches[0];Q(C.clientX,C.clientY,A)},G=()=>{Z=!1,U()};t.addEventListener("touchstart",_e,{passive:!0,capture:!0}),t.addEventListener("touchmove",ee,{passive:!1,capture:!0}),t.addEventListener("touchend",G,{passive:!0,capture:!0}),t.addEventListener("touchcancel",G,{passive:!0,capture:!0}),z=()=>{t.removeEventListener("touchstart",_e,!0),t.removeEventListener("touchmove",ee,!0),t.removeEventListener("touchend",G,!0),t.removeEventListener("touchcancel",G,!0),Z=!1,U()}}function $e(){u&&(ue&&clearTimeout(ue),ue=setTimeout(()=>{u==null||u.redraw(!0),ue=null},30))}function lr(){if(!u)return;const t=u.getSelectedData().map(i=>i.alarmId),s=mt;cr(t,s)||(u.deselectRow(),s.length>0&&u.selectRow(s),a(F,[...s],!0))}function cr(e,t){if(e.length!==t.length)return!1;const s=new Set(e);for(const i of t)if(!s.has(i))return!1;return!0}function ur(){de(er);for(const e of tr())de(e)}function dr(e){ke!==e&&(ke&&De(ke),ke=e,de(e))}function de(e){!e||be.includes(e)||(be.push(e),H.subscribe(e))}function De(e){!e||!be.includes(e)||(H.unsubscribe(e),be=be.filter(t=>t!==e))}function fr(){de(Je())}function yt(e,t,s){const i=vr(e);if(i!=null){_r(i,t);return}if(e===Je()){Ar(t);return}if(e===pt()){Tr(t);return}if(e===bt()){kr(t);return}if(!br(e,t)){if(e===ht()){Ir(t);return}e===ke&&Sr(t)}}function vr(e){const t=/^Alarms\/([1-9]\d*)\/?$/.exec(e);if(!t)return null;const s=Number.parseInt(t[1],10);return Number.isFinite(s)&&s>0?s:null}function mr(e){if(!e.startsWith("AlarmComments/"))return null;const t=e.slice(14),s=t.lastIndexOf("/");if(s<=0||s>=t.length-1)return null;const i=t.slice(0,s),n=t.slice(s+1);if(n==="$meta")return{sourceTopic:i,id:null,isMeta:!0};const d=Number.parseInt(n,10);return!Number.isFinite(d)||d<=0?null:{sourceTopic:i,id:d,isMeta:!1}}function pr(e){const t=e.id??0;if(t<=0)return;const s=r(V).filter(i=>i.id!==t);a(V,[e,...s].sort((i,n)=>(n.id??0)-(i.id??0)),!0)}function br(e,t){const s=mr(e);if(!s||!r(oe)||s.sourceTopic!==r(oe))return!1;if(s.isMeta)return a(ie,!1),!0;const i=s.id??0;if(i<=0)return!0;if(!t.trim())return a(V,r(V).filter(n=>n.id!==i),!0),a(ie,!1),!0;try{const n=JSON.parse(t);if(!n||typeof n!="object")return!0;const d=typeof n.commentText=="string"?n.commentText.trim():"";if(!d)return!0;const x=typeof n.sourceTopic=="string"&&n.sourceTopic.trim()?n.sourceTopic.trim():r(oe),E=typeof n.createdAt=="string"&&n.createdAt.trim()?n.createdAt:new Date().toISOString(),Q=typeof n.createdBy=="string"&&n.createdBy.trim()?n.createdBy.trim():"unknown";pr({id:i,commentId:`${x}/${i}`,alarmId:null,sourceTopic:x,commentText:d,createdAt:E,createdBy:Q}),a(ie,!1)}catch{}return!0}function hr(e){if(!e.trim())return null;try{const t=JSON.parse(e);if(!t||typeof t!="object")return null;const s=t,i=s.alarm&&typeof s.alarm=="object"?s.alarm:t;if(!i||typeof i!="object")return null;const n=typeof s.uuid=="string"&&s.uuid.trim()?s.uuid.trim():i.alarmId,d=typeof i.sourceTopic=="string"?i.sourceTopic.trim():"";return!n||!d?null:Ge({...i,alarmId:n})}catch{return null}}function _r(e,t,s){if(!t){yr(e);return}const i=hr(t);i&&gr(e,i)}function gr(e,t){const s=Ge({...t,topicId:e}),i=r(ae).filter(n=>n.alarmId!==s.alarmId&&n.topicId!==e);a(ae,[s,...i],!0),Ie(),r(v)&&r(v).alarmId===s.alarmId&&a(v,s,!0)}function yr(e){var i;const t=r(ae).filter(n=>n.topicId===e).map(n=>n.alarmId);if(t.length===0)return;a(ae,r(ae).filter(n=>n.topicId!==e),!0),a(F,r(F).filter(n=>!t.includes(n)),!0);const s=((i=r(v))==null?void 0:i.alarmId)??"";if(s&&t.includes(s)){const n=r(ae).find(d=>d.alarmId===s);n&&a(v,n,!0)}Ie()}function wr(e,t){const s=t.trim().toLowerCase();return s?[e.alarmId,e.deviceLabel,e.sourceLabel,e.messageText,e.sourceTopic,e.sourceDisplay].some(n=>(n??"").toLowerCase().includes(s)):!0}function wt(e){const t=e?Date.parse(e):NaN;return Number.isFinite(t)?t:0}function xr(){return r(Y)==="history"?[...r(Pe)]:r(ae).filter(e=>e.isActive||!e.isAcknowledged).filter(e=>wr(e,r(xe)))}function Ie(e={}){const t=e.clearSelection??!1,s=xr().sort((i,n)=>wt(n.triggeredAt)-wt(i.triggeredAt));if(a(Oe,s,!0),a(ft,r(Y)==="history"&&r(He)>0?r(He):s.length,!0),!!u){if(u.setData(s),t)u.deselectRow(),a(F,[],!0);else{const i=r(F).filter(n=>s.some(d=>d.alarmId===n));i.length!==r(F).length&&(a(F,i,!0),u.deselectRow(),i.length>0&&!r(y)&&u.selectRow(i))}$e()}}function Ar(e){a(Ee,!1);try{const t=JSON.parse(e);if(!t.success){a(se,t.error??"Failed to query alarms.",!0);return}a(se,""),a(Pe,(t.alarms??[]).map(Ge),!0),a(He,t.total??r(Pe).length,!0),r(Y)==="history"&&Ie({clearSelection:!0})}catch(t){a(se,`Failed to parse alarm response: ${t}`)}}function Tr(e){try{const t=JSON.parse(e);if(!t.success){a(K,t.error??"Failed to acknowledge alarms.",!0);return}a(K,""),r(Y)==="history"&&xt()}catch(t){a(K,`Ack response parse error: ${t}`)}}function kr(e){var t;try{const s=JSON.parse(e);if(!s.success||!s.prefs)return;vt=s.prefs.userId;const i=(t=s.prefs.columnLayoutJson)==null?void 0:t.trim();if(!i)return;const n=JSON.parse(i);if(Array.isArray(n)){const d=Cr(n);if(d.length===0)return;j=d,Tt(d)}}catch{}}function Sr(e){a(ze,!1);try{let t=e;if(Pr(e)){const i=Uint8Array.from(atob(e),n=>n.charCodeAt(0));t=_s.inflate(i,{to:"string"})}const s=JSON.parse(t);if(!Array.isArray(s)){a(ne,[],!0);return}a(ne,s.slice(-500),!0)}catch{a(ne,[],!0)}}function Ir(e){a(Te,!1);try{const t=JSON.parse(e);if(!t.success){a(re,t.error??"Failed to save comment.",!0);return}a(re,""),a(Ae,"")}catch(t){a(re,`Comment response parse error: ${t}`)}}function Fe(){if(r(I)){if(r(Y)==="history"){xt();return}a(Ee,!1),a(se,""),Ie({clearSelection:!0})}}function xt(){fr(),a(Ee,!0),a(se,"");const e=JSON.stringify({scope:"history",limit:5e3,offset:0,search:r(xe).trim()||null});H.publish("Alarms/Query",e,!1)}function At(){!r(I)||O.userId<=0||H.publish("Alarms/TablePrefs/Query",JSON.stringify({userId:O.userId}),!1)}function Lr(){if(!r(I)||r(L)||O.userId<=0||!u)return;const e=u.getColumnLayout;if(!e)return;const t=e.call(u);H.publish("Alarms/TablePrefs/Set",JSON.stringify({userId:O.userId,columnLayoutJson:JSON.stringify(t)}),!1)}function Ve(){ce&&clearTimeout(ce),ce=setTimeout(()=>{Lr(),ce=null},300)}function Tt(e){if(!u||J)return;const t=u.setColumnLayout;t&&(t.call(u,e),J=!0,$e())}function Cr(e){const t=[],s=new Set;for(const i of e){if(!i||typeof i!="object")continue;const n=i,d=typeof n.field=="string"?n.field:"";if(!rr.has(d)||s.has(d))continue;const x={...n};if(typeof x.width=="number"){const E=sr[d]??36;x.width<E&&(x.width=E)}t.push(x),s.add(d)}return t.length>=5?t:[]}function kt(){const e=new Set(r(F));return r(Oe).filter(t=>e.has(t.alarmId)&&!t.isAcknowledged).map(t=>t.alarmId)}function St(e){if(!e.length){a(K,"No alarms selected.");return}if(!O.username.trim()){a(K,"Unable to identify active user.");return}a(K,""),de(pt()),H.publish("Alarms/Ack",JSON.stringify({alarmIds:e,ackBy:O.username,ackComment:null}),!1)}function $r(e){a(v,e,!0),a(je,!0),a(ne,[],!0),a(V,[],!0),a(re,""),a(Ae,""),a(Te,!1),Dr(e),Nr(e.sourceTopic)}function Dr(e){if(!e.sourceTopic){a(ne,[],!0);return}a(ze,!0);const t=`${Se()}/${e.sourceTopic}_History`;dr(t);const s=Date.parse(e.triggeredAt),i=Number.isFinite(s)?new Date(s-24*60*60*1e3):new Date(Date.now()-24*60*60*1e3),n=Number.isFinite(s)?new Date(s+24*60*60*1e3):new Date;H.publish(`${e.sourceTopic}/History`,JSON.stringify({format:"object",startTime:i.toISOString(),endTime:n.toISOString(),gzip:!0}),!1)}function Nr(e){if(!e){a(V,[],!0),a(oe,"");return}const t=e.trim().replace(/^\/+|\/+$/g,"");if(!t){a(V,[],!0),a(oe,"");return}const s=`AlarmComments/${t}/#`;le&&le!==s&&De(le),a(oe,t,!0),le=s,de(s),a(ie,!0),a(re,""),a(V,[],!0),q&&clearTimeout(q),q=setTimeout(()=>{a(ie,!1),q=null},350)}function It(e){return e?e.replace(/\s*\(ID\s+\d+\)\s*$/i,"").trim():""}function Lt(e){const t=It(e.deviceLabel)||e.deviceLabel||(e.deviceId!=null?`Device ${e.deviceId}`:"Unknown"),s=(e.sourceLabel??"").trim();return s?`${t}/${s}`:t}function qe(e){return e.isActive&&!e.isAcknowledged?"active_unacked":e.isActive&&e.isAcknowledged?"active_acked":!e.isActive&&!e.isAcknowledged?"normal_unacked":"normal_acked"}function Mr(e){switch(qe(e)){case"active_unacked":return 4;case"active_acked":return 3;case"normal_unacked":return 2;default:return 1}}function Ct(e){switch(qe(e)){case"active_unacked":return"Active, unacknowledged alarm";case"active_acked":return"Active, acknowledged alarm";case"normal_unacked":return"Normal, awaiting acknowledgement";default:return"Historical alarm"}}function Qe(e){switch(qe(e)){case"active_unacked":case"active_acked":return"alarm-status-error";case"normal_unacked":return"alarm-status-success";default:return"alarm-status-muted"}}function Ue(e){return e.isActive&&!e.isAcknowledged}function Rr(e){const t=Ct(e),s=Qe(e),i=Ue(e)&&!dt.value?"alarm-status-blink-off":"",d=Ue(e)?'<path d="M6.26 6.26A17.9 17.9 0 0 0 6 8" /><path d="M18 8c0-0.61-.09-1.19-.26-1.74" />':"";return`
			<span class="alarm-status-cell" role="img" aria-label="${t}" title="${t}">
				<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="alarm-status-icon ${s} ${i}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
					${d}
					<path d="M10.27 21a2 2 0 0 0 3.46 0" />
					<path d="M3.26 15.33A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.67C19.41 13.96 18 12.5 18 8A6 6 0 0 0 6 8c0 4.5-1.41 5.96-2.74 7.33" />
				</svg>
			</span>
		`}function Ge(e){return{...e,sourceDisplay:Lt(e),statusRank:Mr(e)}}function he(e){if(!e)return"-";const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Er(e){if(!e)return"-";const t=new Date(e);return Number.isNaN(t.getTime())?e:r(L)?t.toLocaleString(void 0,{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}):he(e)}function Pr(e){try{return btoa(atob(e))===e}catch{return!1}}function $t(){a(je,!1),a(ie,!1),a(oe,""),le&&(De(le),le=""),q&&(clearTimeout(q),q=null)}function Dt(e){r(Y)!==e&&(a(Y,e,!0),e==="active"&&De(Je()),Fe())}function Nt(){Fe()}var We=Us(),Xe=l(We),Ye=l(Xe),Hr=l(Ye);gs(Hr,{}),o(Ye);var Ke=c(Ye,2),Mt=c(l(Ke),2),Ze=l(Mt);Ze.__click=[Ts,Dt];var Rt=c(Ze,2);Rt.__click=[ks,Dt],o(Mt),o(Ke);var Or=c(Ke,2);{var jr=e=>{var t=Ns(),s=l(t),i=l(s),n=l(i);ps(n),n.__keydown=[Ss,Nt];var d=c(n,2),x=l(d);x.__click=Nt;var E=c(x,2);E.__click=[Is,xe,Fe],o(d),o(i);var Q=c(i,2),U=l(Q),Ne=l(U);o(U);var Z=c(U,2);{var _e=b=>{var D=Ls();D.__click=[xs,kt,K,St],X(B=>D.disabled=B,[()=>kt().length===0]),w(b,D)};M(Z,b=>{r(y)||b(_e)})}o(Q),o(s);var ee=c(s,2);{var G=b=>{var D=Cs(),B=l(D),Le=l(B,!0);o(B),o(D),X(()=>p(Le,r(se))),w(b,D)};M(ee,b=>{r(se)&&b(G)})}var A=c(ee,2);{var C=b=>{var D=$s(),B=l(D),Le=l(B,!0);o(B),o(D),X(()=>p(Le,r(K))),w(b,D)};M(A,b=>{r(K)&&b(C)})}var $=c(A,2),g=l($);bs(g,b=>a(S,b),()=>r(S)),o($);var fe=c($,2);{var et=b=>{var D=Ds();w(b,D)};M(fe,b=>{r(L)&&b(et)})}o(t),X(()=>p(Ne,`${r(ft)??""} alarms`)),Ut(n,()=>r(xe),b=>a(xe,b)),w(e,t)},zr=e=>{var t=Ms();w(e,t)};M(Or,e=>{r(I)?e(jr):e(zr,!1)})}o(Xe);var Br=c(Xe,2);{var Jr=e=>{var t=Qs(),s=l(t),i=l(s),n=l(i),d=c(l(n),2),x=l(d,!0);o(d),o(n);var E=c(n,2),Q=l(E);{var U=f=>{const m=Re(()=>`w-5 h-5 ${Qe(r(v))} ${dt.value?"":"alarm-status-blink-off"}`);ys(f,{get class(){return r(m)}})},Ne=f=>{const m=Re(()=>`w-5 h-5 ${Qe(r(v))}`);ws(f,{get class(){return r(m)}})};M(Q,f=>{Ue(r(v))?f(U):f(Ne,!1)})}var Z=c(Q,2),_e=l(Z,!0);o(Z),o(E),o(i);var ee=c(i,2),G=l(ee),A=l(G),C=c(l(A));o(A);var $=c(A,2),g=c(l($));o($);var fe=c($,2),et=c(l(fe));o(fe);var b=c(fe,2),D=c(l(b));o(b);var B=c(b,2),Le=c(l(B));o(B);var tt=c(B,2),Fr=c(l(tt));o(tt);var rt=c(tt,2),Vr=c(l(rt));o(rt);var st=c(rt,2),qr=c(l(st));o(st);var at=c(st,2),Qr=c(l(at));o(at);var Et=c(at,2),Ur=c(l(Et));o(Et),o(G);var Pt=c(G,2),nt=l(Pt),Gr=l(nt);o(nt);var Wr=c(nt,2);{var Xr=f=>{var m=Rs();w(f,m)},Yr=(f,m)=>{{var P=T=>{var N=Es();w(T,N)},W=T=>{var N=Hs(),te=l(N),Ce=c(l(te));qt(Ce,21,()=>r(ne),Qt,(lt,ge)=>{var ve=Ps(),me=l(ve),ct=l(me,!0);o(me);var ye=c(me),ut=l(ye,!0);o(ye),o(ve),X(Me=>{p(ct,r(ge).T),p(ut,Me)},[()=>String(r(ge).V)]),w(lt,ve)}),o(Ce),o(te),o(N),w(T,N)};M(f,T=>{r(ne).length===0?T(P):T(W,!1)},m)}};M(Wr,f=>{r(ze)?f(Xr):f(Yr,!1)})}o(Pt),o(ee);var it=c(ee,2),ot=l(it),Ht=l(ot),Kr=l(Ht);o(Ht),o(ot);var Ot=c(ot,2);{var Zr=f=>{var m=Os(),P=l(m);us(P);var W=c(P,2),T=l(W);T.__click=[As,y,v,re,Ae,Te,de,ht];var N=l(T,!0);o(T),o(W),o(m),X(()=>{T.disabled=r(Te),p(N,r(Te)?"Saving...":"Add comment")}),Ut(P,()=>r(Ae),te=>a(Ae,te)),w(f,m)};M(Ot,f=>{r(y)||f(Zr)})}var jt=c(Ot,2);{var es=f=>{var m=js(),P=l(m),W=l(P,!0);o(P),o(m),X(()=>p(W,r(re))),w(f,m)};M(jt,f=>{r(re)&&f(es)})}var ts=c(jt,2);{var rs=f=>{var m=zs();w(f,m)},ss=(f,m)=>{{var P=T=>{var N=Bs();w(T,N)},W=T=>{var N=Fs(),te=l(N),Ce=c(l(te));qt(Ce,21,()=>r(V),Qt,(lt,ge)=>{var ve=Js(),me=l(ve),ct=l(me,!0);o(me);var ye=c(me),ut=l(ye,!0);o(ye);var Me=c(ye),os=l(Me,!0);o(Me),o(ve),X(ls=>{p(ct,ls),p(ut,r(ge).createdBy),p(os,r(ge).commentText)},[()=>he(r(ge).createdAt)]),w(lt,ve)}),o(Ce),o(te),o(N),w(T,N)};M(f,T=>{r(V).length===0?T(P):T(W,!1)},m)}};M(ts,f=>{r(ie)?f(rs):f(ss,!1)})}o(it);var zt=c(it,2),Bt=l(zt);{var as=f=>{var m=qs();m.__click=[Vs,v,St],w(f,m)};M(Bt,f=>{!r(y)&&!r(v).isAcknowledged&&f(as)})}var ns=c(Bt,2);ns.__click=$t,o(zt),o(s);var Jt=c(s,2),is=l(Jt);is.__click=$t,o(Jt),o(t),X((f,m,P,W,T,N,te)=>{p(x,r(v).alarmId),p(_e,f),p(C,` ${m??""}`),p(g,` ${r(v).deviceId??"-"??""}`),p(et,` ${P??""}`),p(D,` ${r(v).messageText??""}`),p(Le,` ${W??""}`),p(Fr,` ${T??""}`),p(Vr,` ${N??""}`),p(qr,` ${r(v).acknowledgedBy??"-"??""}`),p(Qr,` ${te??""}`),p(Ur,` ${r(v).ackComment??"-"??""}`),p(Gr,`Trend history (${r(v).sourceTopic??""}, -24h/+24h)`),p(Kr,`Comments for this source (${r(v).sourceTopic??""})`)},[()=>Ct(r(v)),()=>It(r(v).deviceLabel)||r(v).deviceLabel||"-",()=>r(v).sourceDisplay??Lt(r(v)),()=>he(r(v).triggeredAt),()=>he(r(v).lastSeenAt),()=>he(r(v).clearedAt),()=>he(r(v).acknowledgedAt)]),w(e,t)};M(Br,e=>{r(je)&&r(v)&&e(Jr)})}o(We),X(()=>{Vt(Ze,1,`btn btn-sm join-item flex-1 sm:flex-none ${r(Y)==="active"?"btn-primary":"btn-outline"}`),Vt(Rt,1,`btn btn-sm join-item flex-1 sm:flex-none ${r(Y)==="history"?"btn-primary":"btn-outline"}`)}),w(R,We),ms()}cs(["click","keydown"]);export{na as component};
