1import{i as E,A as S}from"./AlertsDialog-D9bH4YML.js";import{o as m,b as y,s as i,n as v,a as P}from"./schemas-BdgNnLKl.js";import{l as h,c as T}from"./Logger-D_qtsJjD.js";const I=`<button 2 type="button" 3 class="alert-badge ss-button" 4 aria-label="View Active Alerts" 5 aria-haspopup="true" 6 aria-controls="ss-alert-preview" 7 tabindex="2" 8> 9 <i class="fa-solid fa-triangle-exclamation" aria-hidden="true"></i> 10</button> 11`;class b extends HTMLElement{button;constructor(){super(),this.className="alert-badge-container hideAlertBadge",this.append(E(I)),this.button=this.querySelector(".alert-badge")}setOnRecall(e){this.button.addEventListener("click",e)}setVisible(e){this.classList.toggle("hideAlertBadge",!e)}}customElements.get("ss-alert-badge")||customElements.define("ss-alert-badge",b);const R=m({id:v(),title:i(),message:i(),link:i(),linkText:i().nullable(),timeSince:i(),forceDistrictRedirect:y()}),D=m({alerts:P(R),districtUrl:i().nullable()});class p extends Error{details;constructor(e,t){super(e),this.name="InvalidSchemaError",this.details=t,Error.captureStackTrace&&Error.captureStackTrace(this,p)}}class u extends Error{details;constructor(e,t){super(e),this.name="RequestError",this.details=t,Error.captureStackTrace&&Error.captureStackTrace(this,u)}}class L{async fetchActiveAlerts(e=[]){const t=new URL("/api/popup-alerts",window.location.origin);e.forEach(o=>t.searchParams.append("prevId[]",String(o)));const r=await fetch(t.toString(),{method:"GET",headers:{Accept:"application/json"}});if(!r.ok)throw new u(`Popup alerts request failed with status ${r.status}`);const s=await r.json(),n=D.safeParse(s);if(!n.success)throw new p("Invalid popup alerts API response",n.error);return n.data}}const f="ss-popup-alerts-viewed",U=1440*60*1e3,g="PopUpAlerts";class k{getUnviewed(e){const t=this.readAndPrune();return e.filter(r=>!(String(r.id)in t))}markViewed(e){if(e.length===0)return;const t=this.readAndPrune(),r=Date.now();e.forEach(s=>{t[String(s)]=r}),this.write(t)}readAndPrune(){const e=this.read(),t=Date.now(),r={};let s=!1;return Object.entries(e).forEach(([n,o])=>{t-o<U?r[n]=o:s=!0}),s&&this.write(r),r}read(){try{const e=window.localStorage.getItem(f);if(!e)return{};const t=JSON.parse(e);return this.isViewedMap(t)?t:{}}catch(e){return h(g,"Unable to read viewed alerts from localStorage",e),{}}}write(e){try{window.localStorage.setItem(f,JSON.stringify(e))}catch(t){h(g,"Unable to persist viewed alerts to localStorage",t)}}isViewedMap(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.values(e).every(t=>typeof t=="number")}}const A=T("PopUpAlerts"),O="ss-alert-modal-area",M=()=>typeof window.customElements<"u"&&typeof HTMLDialogElement<"u"&&typeof HTMLDialogElement.prototype.showModal=="function",N=a=>{const e=a.searchParams.get("previewAlertID");return e?e.split(",").map(t=>Number.parseInt(t.trim(),10)).filter(t=>Number.isInteger(t)&&t>0):[]},V=a=>{let e;try{e=new URL(a,window.location.origin)}catch{return!0}return e.origin===window.location.origin||window.location.pathname==="/login"?!0:new URL(window.location.href).searchParams.has("adminArea")},x=(a,e)=>!e||!a.some(t=>t.forceDistrictRedirect)||V(e)?!1:(window.location.assign(e),!0),j=async()=>{if(!M())return;const a=new URL(window.location.href),e=N(a),t=e.length>0,r=a.searchParams.has("showActiveAlerts");let s;try{s=await new L().fetchActiveAlerts(e)}catch(d){A.error("Failed to fetch active alerts",d);return}if(x(s.alerts,s.districtUrl))return;const n=document.getElementById(O)??document.body,o=new S(n),c=new b;c.setVisible(s.alerts.length>0),c.setOnRecall(()=>o.open(s.alerts)),document.body.append(c);const w=new k,l=t||r?s.alerts:w.getUnviewed(s.alerts);l.length!==0&&(!t&&!r&&w.markViewed(l.map(d=>d.id)),o.open(l))};j().catch(a=>A.error("Unexpected error initializing popup alerts",a)); 12//# sourceMappingURL=PopUpAlertsComponent-DXDEh6ZV.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.