/*! phoscon-app 2024-10-07 */

export function addClassToAll(elemList,c){elemList.forEach(el=>el.classList.add(c))};export function removeClassToAll(elemList,c){elemList.forEach(el=>el.classList.remove(c))};export function callFunc(context,event){event.data&&context[event.data](context,event)};export function searchInput(searchViews,searchString){""!==(searchString=searchString.toLowerCase())?searchViews.forEach(view=>{let model=view.model,values=[],el=view.el;for(let[key,value]of Object.entries(model.attributes))if("string"==typeof value&&values.push(value),"object"==typeof value)for(let[key,val]of Object.entries(value))"string"==typeof val?values.push(val):values.push(key);view.el.querySelectorAll("td").forEach(td=>{""!==td.innerText&&values.push(td.innerText.toLowerCase())}),fuzzySearch(values=[...new Set(values)],searchString)?el.classList.remove("hide"):el.classList.add("hide")}):searchViews.forEach(view=>view.el.classList.remove("hide"))};function fuzzySearch(searchArr,searchString){var searchStringArray=searchString.split(""),found=!1;return searchArr.forEach(s=>{let arr=searchStringArray;arr.filter(a=>1==s.includes(a)).length>=arr.length&&(found=!0)}),found}var slideUp=!1,slideDown=!1;export function slideBlindUp(context,event){let btnElemUp=context.view.el.querySelector(".btn-length-up-stop")||document.querySelector(".btn-length-up-stop"),btnElemDown=context.view.el.querySelector(".btn-length-down-stop")||document.querySelector(".btn-length-down-stop");slideUp=!slideUp&&!slideDown,slideDown=!1,btnElemUp&&btnElemUp.blur(),slideUp?(btnElemUp&&btnElemUp.classList.add("active-slide-btn"),slideBlind("up")):(btnElemUp&&btnElemUp.classList.remove("active-slide-btn"),btnElemDown&&btnElemDown.classList.remove("active-slide-btn"),slideBlind("stop"))};export function slideBlindDown(context,event){let btnElemDown=context.view.el.querySelector(".btn-length-down-stop")||document.querySelector(".btn-length-down-stop"),btnElemUp=context.view.el.querySelector(".btn-length-up-stop")||document.querySelector(".btn-length-up-stop");slideDown=!slideDown&&!slideUp,slideUp=!1,btnElemDown&&btnElemDown.blur(),slideDown?(btnElemDown&&btnElemDown.classList.add("active-slide-btn"),slideBlind("down")):(btnElemDown&&btnElemDown.classList.remove("active-slide-btn"),btnElemUp&&btnElemUp.classList.remove("active-slide-btn"),slideBlind("stop"))};function slideBlind(direction){if(!app.session.blid)return;let val;"up"===direction?val=1:"down"===direction?val=100:"stop"===direction&&(val="stop"),updateBlindHeight(val)}function updateBlindHeight(val){if(!val)return;const xhr=new XMLHttpRequest,url="//"+app.session.gw+"/api/"+app.apikey+"/lights/"+app.session.blid+"/state";xhr.open("PUT",url,!0),xhr.setRequestHeader("Content-type","application/json; charset=utf-8"),xhr.setRequestHeader("Accept",app.apiversion),xhr.send(JSON.stringify({lift:val})),xhr.onreadystatechange=(e=>{if((4!==xhr.readyState||200!==xhr.status)&&4===xhr.readyState&&200!==xhr.status)throw new Error("slide blind request: "+xhr.status)})}const iDevices=["iPad Simulator","iPhone Simulator","iPad","iPhone","MacIntel","Mac68K","MacPPC"];export const iOS=!(!navigator.platform||!iDevices.includes(navigator.platform));