var l=require("electron/renderer"),m=require("../../common/modules/client"),s=require("../../common/global"),d=require("dompurify");const f=(0,m.getBuildInfo)().type;function g(){const e=this.name.split("."),r=this.type==="checkbox"?this.checked:parseInt(this.value);let n={};n={[e[e.length-1]??0]:r};for(let t=e.length-2;t>=0;t--)n={[e[t]??0]:n};l.ipcRenderer.send("settings-config-modified",{settings:n})}function h(e){if(e==="currentInstance")return s.knownInstancesList.map(r=>[r[0],r[2]]);throw new Error("Currently unsupported!")}function b(e){switch(e){case"win32":case"darwin":return process.platform===e;case"unix":return process.platform!=="win32";case"menuBar":return process.platform!=="darwin";default:return!0}}function u(e){const r=document.createElement("fieldset"),n=document.createElement("input"),t=document.createElement("label");switch(n.type=e.type,n.name=e.id,n.checked=e.isChecked,e.type){case"checkbox":n.id=e.id;break;case"radio":n.id=e.id+e.value,n.value=e.value;break}return t.setAttribute("for",n.id),e.description!==void 0&&(n.title=e.description,t.title=e.description),(e.enabled??!0)||(t.classList.add("disabled"),n.disabled=!0),n.addEventListener("change",g),t.innerHTML=(0,d.sanitize)(e.label+(n.title!==""?" \u{1F6C8}":""),s.sanitizeConfig),r.append(n,t),r}function y(e){document.body.replaceChildren();for(const[r,n]of e){document.body.appendChild(document.createElement("h1")).innerHTML=(0,d.sanitize)(n.name,s.sanitizeConfig);for(const t of Object.keys(n))if(t!=="name"&&t!==f&&b(t)){const i=n[t];if(i){if(i.name===void 0||i.description===void 0)try{console.warn("Invalid configuration option: "+JSON.stringify(i))}catch{console.warn("'setting' is not a valid object!")}finally{return}const c=document.createElement("p"),a=document.createElement("form");if(c.innerHTML=(0,d.sanitize)(i.description),c.classList.add("description"),a.classList.add("settingsContainer"),"radio"in i)for(const[o,p]of Object.entries(h(t)))a.appendChild(u({type:"radio",id:r+"."+t+".radio",isChecked:Number(o)===i.radio,label:p[0],value:o,enabled:p[1]}));else if(!("dropdown"in i||"input"in i||"keybind"in i))a.append(...Object.keys(i).sort().filter(o=>o!=="name"&&o!=="description"&&o!=="labels"&&o!=="info"&&i[o]!==void 0).map(o=>u({type:"checkbox",id:r+"."+t+"."+o,isChecked:i[o]===!0,label:i.labels[o]??"N/A",description:i.info?.[o]??void 0})));else throw new Error("Still unimplemented / unsupported configuration type!");document.body.appendChild(document.createElement("h2")).innerHTML=(0,d.sanitize)(i.name),document.body.append(c,a)}}}}window.addEventListener("load",()=>{(async()=>{y(await l.ipcRenderer.invoke("settings-generate-html","ready-to-render")),(0,s.wLog)("Settings preloaded!")})()});
