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

export function startScanProgress(){if(!scanInProgress){scanInProgress=!0,document.getElementById("progress-bar").style.width="0%",document.getElementById("progress-bar").style.height="0%",startTime=Date.now(),endTime=startTime+1e4,app.lightScan.start(),document.body.classList.add("search-active"),function(min,pollState){pollState!==SEARCH_SENSORS_ENABLED&&(app.lightsBeforeSearch=[],app.lights.forEach(l=>{isFlsPpWhite(l)||app.lightsBeforeSearch.push(l.id)}));void 0===min&&(min=app.config.get("networkopenduration")/60);if(min>0&&app.timerSeconds>0)return;if(!(min>0))return document.body.classList.remove("search-active"),$(".empty-div").removeClass("search"),void(app.timerSeconds>0&&(app.timerSeconds=0,console.log("stop scan")));$("#c_newLi_la").html(translate("txt_noLight")),document.body.classList.add("search-active"),$(".empty-div").addClass("search"),app.timerSeconds=60*min;app.$time=$("#time"),app.$timeLabels=app.$time.find("span"),min<=1?void 0===app.$timeLabels[1]?app.$timeLabels.prevObject[0].textContent="":app.$timeLabels[1].textContent=translate("text_1min_remaining"):(app.$time.removeClass("hidden"),app.$time.css("opacity","1"),app.$timeLabels[0].textContent=min+" ",app.$timeLabels[1].textContent=translate("text_min_remaining"),setTimeout(setTimeLabel,1e3));var elem=document.getElementById("progressBar");if(null===elem){let elem=document.getElementById("quickDeviceListView");if(null===elem)return void console.error("Element 'progressBarQuickBar' not found.");let startTime=Date.now(),endTime=startTime+1e3*app.timerSeconds,lastWidth=0;if(app.searchRaf)return;function frame(ms){app.searchRaf=null;const isMobile=window.innerWidth<=767;let pos=(Date.now()-startTime)/(endTime-startTime),width=Math.floor(100*pos),value=Math.floor(100*pos);if(width>=100||0===app.timerSeconds){app.timerSeconds=0,app.$time.css("opacity","0"),disableSensorSearch(),stopScanning();const iconUse=document.getElementById("iconUse");iconUse.setAttribute("xlink:href","#add-icon-sm"),scanInProgress=!1,document.body.classList.contains("search-active")&&setTimeout(()=>{document.body.classList.remove("search-active")},5e3)}else{const progressBar=document.getElementById("progress-bar");let targetValue;isMobile?(document.getElementById("progress-bar").style.width="1px",(targetValue=value)!==lastHeight&&(enableSensorSearch(),smoothTransition(progressBar,"height",lastHeight,targetValue),lastHeight=targetValue)):(document.getElementById("progress-bar").style.height="1px",(targetValue=value)!==lastWidth&&(enableSensorSearch(),smoothTransition(progressBar,"width",lastWidth,targetValue),lastWidth=targetValue)),scanInProgress&&(app.searchRaf=requestAnimationFrame(frame))}}app.searchRaf=requestAnimationFrame(frame)}app.searchRaf=null;let startTime=Date.now(),endTime=startTime+1e3*app.timerSeconds,lastWidth=0;if(app.searchRaf)return;function frame(ms){app.searchRaf=null;let pos=(Date.now()-startTime)/(endTime-startTime),width=Math.floor(100*pos);width>=100||0===app.timerSeconds?(app.timerSeconds=0,app.$time.css("opacity","0"),disableSensorSearch(),document.body.classList.contains("search-active")&&setTimeout(()=>{document.body.classList.remove("search-active")},5e3)):(width!==lastWidth&&(elem.style.width=width+"%",enableSensorSearch(),lastWidth=width),app.searchRaf=requestAnimationFrame(frame))}app.searchRaf=requestAnimationFrame(frame)}(void 0,SEARCH_SENSORS_DISABLED)}function stopScanning(){scanInProgress&&(scanInProgress=!1,min=void 0,app.timerSeconds=0,cancelAnimationFrame(app.searchRaf),document.getElementById("progress-bar").style.width="0%",document.getElementById("progress-bar").style.height="0%",app.$time.css("opacity","0"),disableSensorSearch(),document.body.classList.remove("search-active"))}function smoothTransition(element,property,fromValue,toValue){let start=null;const duration=200,difference=toValue-fromValue;requestAnimationFrame(function step(timestamp){start||(start=timestamp);const progress=timestamp-start,value=fromValue+difference*(progress/duration);element.style[property]="height"===property?value+"vh":value+"%",progress<duration?requestAnimationFrame(step):element.style[property]="height"===property?toValue+"vh":toValue+"%"})}function setTimeLabel(){if(0!==app.timerSeconds){app.timerSeconds--;var min=Math.round(app.timerSeconds/60);app.timerSeconds;app.timerSeconds>60?app.$timeLabels[0].textContent=min+" ":(app.$timeLabels[0].textContent=" ",app.$timeLabels[1].textContent=translate("text_1min_remaining")),app.timerSeconds>60&&setTimeout(setTimeLabel,1e3)}}function enableSensorSearch(){pollState!==SEARCH_SENSORS_ENABLED&&(pollState=SEARCH_SENSORS_ENABLED,console.log("enable sensor search"))}function disableSensorSearch(){pollState!==SEARCH_SENSORS_DISABLED&&(pollState=SEARCH_SENSORS_DISABLED,console.log("disable sensor search"))}};