/*! phoscon-app 2025-10-13 */

import{KeyEvents}from"./state-constants.js";export function startProgressbar(elem,sec){return new Promise((resolve,reject)=>{if(!elem||!sec)return reject(new Error("param is missing"));elem=document.getElementById(elem);var width=0===sec?100:0,i=1/(sec||1),id=setInterval(function(){if(width>=100||0===sec)return sec=0,width=0,elem.style.width=width+"%",clearInterval(id),resolve("success");width+=i,elem.style.width=width+"%"},10)})};export function configAccessPoint(wifi,type,name,password){return new Promise((resolve,reject)=>{if(!(wifi&&type&&name&&password))return reject(new TypeError("parameter is missing"));const xhr=new XMLHttpRequest,params=JSON.stringify({wifi:wifi,type:type,name:name,password:password}),url="//"+app.session.gw+"/api/"+app.apikey+"/config/wifi";xhr.open("PUT",url,!0),xhr.setRequestHeader("Content-type","application/json; charset=utf-8"),xhr.setRequestHeader("Accept",apiversion),xhr.send(params),xhr.onreadystatechange=(e=>{4===xhr.readyState&&200===xhr.status?resolve(xhr.status):4===xhr.readyState&&200!==xhr.status&&reject(new Error(xhr.status))}),xhr.onerror=function(){}})};export function deactivateSettings(wifi){return new Promise((resolve,reject)=>{if(!wifi)return reject(new TypeError("parameter is missing"));const xhr=new XMLHttpRequest,params=JSON.stringify({wifi:wifi}),url="//"+app.session.gw+"/api/"+app.apikey+"/config/wifi";xhr.open("PUT",url,!0),xhr.setRequestHeader("Content-type","application/json; charset=utf-8"),xhr.setRequestHeader("Accept",apiversion),xhr.send(params),xhr.onreadystatechange=(e=>{4===xhr.readyState&&200===xhr.status?resolve(xhr.status):4===xhr.readyState&&200!==xhr.status&&reject(new Error(xhr.status))}),xhr.onerror=function(){}})};export function configClientMode(wifi,type,name,password){return new Promise((resolve,reject)=>{if(!(wifi&&type&&name&&password))return reject(new TypeError("parameter is missing"));const xhr=new XMLHttpRequest,params=JSON.stringify({wifi:wifi,type:type,name:name,password:password}),url="//"+app.session.gw+"/api/"+app.apikey+"/config/wifi";xhr.open("PUT",url,!0),xhr.setRequestHeader("Content-type","application/json; charset=utf-8"),xhr.setRequestHeader("Accept",apiversion),xhr.send(params),xhr.onreadystatechange=(e=>{4===xhr.readyState&&200===xhr.status?resolve(xhr.status):4===xhr.readyState&&200!==xhr.status&&reject(new Error(xhr.status))}),xhr.onerror=function(){}})};export function wifiPageActiveIndication(){return new Promise((resolve,reject)=>{const xhr=new XMLHttpRequest,params=JSON.stringify({pageactive:!0}),url="//"+app.session.gw+"/api/"+app.apikey+"/config/wifi/";xhr.open("PUT",url,!0),xhr.setRequestHeader("Content-type","application/json; charset=utf-8"),xhr.setRequestHeader("Accept",apiversion),xhr.send(params),xhr.onreadystatechange=(e=>{4===xhr.readyState&&200===xhr.status?resolve(xhr.status):4===xhr.readyState&&200!==xhr.status&&reject(new Error(xhr.status))}),xhr.onerror=function(){}})};export function addClassToAll(elemList,classToAdd){if(elemList&&classToAdd)for(let elem of elemList)elem.classList.add(classToAdd)};export function removeClassFromAll(elemList,classToRemove){if(elemList&&classToRemove)for(let elem of elemList)elem.classList.remove(classToRemove)};document.addEventListener("keyup",function(e){"Escape"===e.code&&app.stateEventHandler(KeyEvents.ESC_PRESSED),"Enter"===e.code&&app.stateEventHandler(KeyEvents.ENTER_PRESSED)});