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

export function injectSwitchWizzardSvg(images){return new Promise((resolve,reject)=>{0===images.length&&resolve();const promises=[];images.forEach((img,idx)=>{promises.push(SVGInject(img,injectSwitchWizzardOptions))}),Promise.all(promises).then(()=>{resolve()})})};const injectSwitchWizzardOptions=SVGInject.setOptions({useCache:!1,copyAttributes:!0,makeIdsUnique:!1,beforeLoad:function(img){let pages=img.getAttribute("data-Channel-dependent");if(!pages)return;pages=pages.split(",");let channelSvgPage="0";switch(app.config.get("zigbeechannel")||0){case 11:channelSvgPage=pages[0];break;case 15:channelSvgPage=pages[1];break;case 20:channelSvgPage=pages[2];break;case 25:channelSvgPage=pages[3]}img.setAttribute("data-wiz-page",channelSvgPage)},afterInject:function(img,svg){if(img.classList.contains("svg-icon"))return;if(img.classList.contains("item-icon"))return;var wizPage=svg.getAttribute("data-wiz-page");const svgId=getSvgId(svg);if(!svgId)return;img.classList.contains("interactive")&&!img.classList.contains("interactive-blind")&&setSwTargets(svg,svgId);const boxElem=getWizardViewboxElem(svg,wizPage,svgId)||getDeviceViewboxElem(svg,svgId);if(!boxElem)return;svg.removeAttribute("width"),svg.removeAttribute("height");let paddingBottom=0;if("none"!==wizPage&&(svg.classList.add("view-box-show"),showWizzard(svg,svgId,wizPage),paddingBottom=50),!boxElem)return;const viewBox=getViewBox(boxElem);svg.parentElement.getBoundingClientRect();svg.setAttribute("viewBox",viewBox.x+" "+viewBox.y+" "+viewBox.width+" "+viewBox.height)},onFail:function(img,status){console.log(status,`failed ${img.src}`)}});function getDeviceViewboxElem(svg,svgId){return svg.querySelector(svgId)}function getWizardViewboxElem(svg,wizPage,svgId){if("none"===wizPage||void 0===wizPage)return null;const topElem=svg.querySelector(svgId+" .sw-wizzard"),subElem=svg.querySelector(svgId+" [data-wizzard-page='"+wizPage+"']");return subElem&&subElem.hasAttribute("viewbox")?subElem:topElem}function getViewBox(boxElem){var box,x,y,width,height;return boxElem.hasAttribute("viewbox")?(x=(box=boxElem.getAttribute("viewbox").split(" "))[0],y=box[1],width=box[2],height=box[3]):(x=(box=boxElem.getBBox()).x-2,y=box.y-2,height=box.height+4,width=box.width+4),{x:x,y:y,height:height,width:width}}function showWizzard(svg,svgId,wizPage){let elem=svg.querySelector(svgId+" [data-wizzard-page='"+wizPage+"']");elem&&(elem.parentElement.style.display="inline",elem.style.display="inline",elem.setAttribute("display","inline"),showTargets(elem,svg,svgId),showLeds(elem,svg,svgId))}function showTargets(elem,svg,svgId){let targets=elem.querySelectorAll(".sw-target, .sw-corner")||[];if(0===(targets=Array.prototype.slice.call(targets)).length&&elem.querySelector("use")){let roots=[];elem.querySelectorAll("use").forEach(elem=>roots.push(elem.getAttribute("xlink:href"))),roots.forEach(root=>targets.push(svg.querySelector(svgId+" "+root)))}targets&&targets.forEach(target=>{target&&target.classList.add("animate-target")})}function showLeds(elem,svg,svgId){let leds=elem.querySelectorAll(".sw-led")||[];if(0===(leds=Array.prototype.slice.call(leds)).length&&elem.querySelector("use")){let roots=[];elem.querySelectorAll("use").forEach(elem=>roots.push(elem.getAttribute("xlink:href"))),roots.forEach(root=>leds.push(svg.querySelector(svgId+" "+root)))}if(leds&&leds.forEach(led=>{led&&led.classList.remove("sw-hidden")}),svg.getAttribute("data-led")){let d=svg.getAttribute("data-led"),led=svg.querySelector("#sLED")||svg.querySelector("#lLED");if(!led)return;(led=led.querySelector('path[data-led="'+d+'"]'))&&led.classList.remove("sw-hidden")}}function getSvgId(svg){let svgId="",svgPath=svg.getAttribute("data-inject-url");return(svgPath=svgPath.split("#")).length>1&&(svgId="#"+svgPath[1]),svgId}function setSwTargets(svg,svgId){let targets=svg.querySelectorAll(svgId+" .sw-target")||[],swid=app.session.swid,svgSwid=svg.getAttribute("data-swid");if(svgSwid&&(swid=svgSwid),app.sw=app.switches.get(swid)||app.switches.where({uniqueid:swid})[0],!app.sw)return;let swEventMap=getDeviceEventMap(app.sw);if(!swEventMap)return;let events=swEventMap.buttonEvents;swEventMap.buttonExtra;targets.forEach((t,idx)=>{t.setAttribute("data-buttonEvent",events[idx])}),targets.length>0&&targets[0].parentNode&&(targets[0].parentNode.style.display="block")}