const t=async(t,e)=>{e||(e={}),e.credentials="same-origin";const n=await fetch(t,e);if(!n.ok)throw new Error(`Request not successful (${n.status})`);return"application/json"===n.headers.get("content-type")?n.json():n.text()};let e,n;const s=[],a=t=>{s.push(t);const a=()=>{const a=s.indexOf(t);-1!==a&&(s.splice(a),0===s.length&&(clearTimeout(e),e=void 0,n=void 0))};if(s.length>1){if(n){const e=n;setTimeout((()=>t(e)),0)}return a}return e=window.setTimeout(o,2e3),a},o=async()=>{const a=(new Date).getTime()+2e3;try{n=await t("./ping");for(const t of s)t(n)}finally{if(void 0!==e){const t=Math.max(0,a-(new Date).getTime());e=window.setTimeout(o,t)}}},i=()=>import("./install-update-dialog-2d54a593.js"),c=async t=>{i();const e=document.createElement("esphome-install-dialog");e.filename=t.target.dataset.filename,document.body.append(e)},d=()=>import("./wizard-dialog-1b42d055.js"),l=async()=>{d(),document.body.append(document.createElement("esphome-wizard-dialog"))};document.querySelectorAll("[data-action='wizard']").forEach((t=>{t.addEventListener("click",l),t.addEventListener("mouseover",d,{once:!0})})),a((t=>{for(let e in t){let n=document.querySelector(`#nodes .card[data-filename="${e}"]`);if(null===n)continue;let s,a=t[e];if(null===a)s="status-unknown";else if(!0===a)s="status-online",n.setAttribute("data-last-connected",Date.now().toString());else if(n.hasAttribute("data-last-connected")){const t=parseInt(n.getAttribute("data-last-connected"));s=Date.now()-t<=5e3?"status-not-responding":"status-offline"}else s="status-offline";n.classList.contains(s)||(n.classList.remove("status-unknown","status-online","status-offline","status-not-responding"),n.classList.add(s))}})),document.querySelectorAll("[data-action='upload']").forEach((t=>{t.addEventListener("click",c),t.addEventListener("mouseover",i,{once:!0})}));export{t as f,a as s};
