window.renderCredentialTabs=()=>{const e=$("wifi-cred-tabs");if(!e)return;e.innerHTML="";const t=$("wifi-box").offsetWidth||Math.min(window.innerWidth,840),i=Math.floor((t-60)/140);if(window.matchMedia("(max-width: 608px)").matches){const t=newEl("select",{class:"opt-input",style:"margin-bottom:10px"});wifiCredentials.forEach(((e,i)=>{const d=newEl("option",{value:i});d.textContent=e.ssid||"(empty SSID)",i===selectedCredentialIndex&&(d.selected=!0),t.appendChild(d)})),t.addEventListener("change",(e=>{selectedCredentialIndex=parseInt(e.target.value),window.applyCredential(wifiCredentials[selectedCredentialIndex])})),e.appendChild(t)}else if(wifiCredentials.length>i){const t=newEl("select",{class:"opt-input",style:"margin-bottom:10px"});wifiCredentials.forEach(((e,i)=>{const d=newEl("option",{value:i});d.textContent=e.ssid||"(empty SSID)",i===selectedCredentialIndex&&(d.selected=!0),t.appendChild(d)})),t.addEventListener("change",(e=>{selectedCredentialIndex=parseInt(e.target.value),window.applyCredential(wifiCredentials[selectedCredentialIndex])})),e.appendChild(t)}else wifiCredentials.forEach(((t,i)=>{const d=newEl("button",{class:"cred-tab"});d.textContent=t.ssid||"(empty SSID)",i===selectedCredentialIndex&&d.classList.add("active"),d.onclick=d=>{e.querySelectorAll(".cred-tab").forEach((e=>e.classList.remove("active"))),d.target.classList.add("active"),selectedCredentialIndex=i,window.applyCredential(t)},e.appendChild(d)}));const d=wifiCredentials.length>0;["delete-cred","clear-creds","cred-actions-inline"].forEach((e=>{const t=$(e);t&&(d?t.classList.remove("hide"):t.classList.add("hide"))}))},window.addEventListener("resize",(()=>{wifiCredentials&&wifiCredentials.length&&"function"==typeof renderCredentialTabs&&renderCredentialTabs()})),window.deleteSelectedCredential=()=>{if(selectedCredentialIndex<0||selectedCredentialIndex>=wifiCredentials.length)return;const e=wifiCredentials[selectedCredentialIndex];openModal("Delete WiFi",`Delete <b>${e.ssid}</b>?`,(async()=>{try{await fetch(`${esp}wifi/credentials?index=${selectedCredentialIndex}`,{method:"DELETE"}),await loadCredentials(),closeModal(!1)}catch(e){openModal("Error","Failed to delete")}}))},window.clearAllCredentials=()=>{wifiCredentials.length&&openModal("Clear All","Delete all WiFi credentials?",(async()=>{try{await fetch(`${esp}wifi/credentials`,{method:"DELETE"}),await loadCredentials(),closeModal(!1)}catch(e){openModal("Error","Failed to clear")}}))};