//!wrt $BSPEC:{"icn":"apps/resetwiz","cpr":"Copyright (C) Windows 96 Team 2021.","dsc":"System Reset Wizard","frn":"Reset Wizard","ver":1,"ssy":"gui"}

const{MsgBoxSimple:MsgBoxSimple,Theme:Theme}=w96.ui,{RadioBox:RadioBox}=w96.ui.components,{WizardBaseApplication:WizardBaseApplication}=w96.app.templates;class ResetWizardApp extends WizardBaseApplication{constructor(){super()}async main(e){await super.main(e);const t=this.findPage("intro");t.titleText="Welcome to the Reset Wizard",t.graphic="/system/resource/app/resetwiz/graphic.png",t.body='This wizard will help you to completely reset your current installation.<br>\n        <br>\n        Please ensure you have a backup of any important data before starting, should anything happen at all.\n        <br>\n        <br>\n        <span class="bold-noaa">WARNING: If you choose to delete everything, the data will NOT be recoverable!</span>',t.buttons[1].onclick=()=>this.openPage("reset-select",[]);let a="clear-user";this.pages.push({id:"reset-select",type:"page",body:'Select an action:\n                <div class="w96-radiobox"></div>',graphic:"/system/resource/app/resetwiz/graphic-top.png",titleText:"What would you like to reset?",description:"Choose carefully what you would like to reset.",buttons:[{class:"back",onclick:()=>this.openPage("intro",[]),enabled:!0,text:"Back"},{class:"next",onclick:()=>{"clear-user"==a?this.openPage("reset-user",[]):this.openPage("reset-all",[])},enabled:!0,text:"Next"},{class:"cancel",onclick:()=>this.quit(),enabled:!0,text:"Cancel"}],onopen:(e,t)=>{const s=new RadioBox([{label:"Reset everything but keep user files (c:/user)",id:"clear-user",onselect:()=>{a="clear-user"},selected:!0},{label:"Completely reset the current installation",id:"clear-all",onselect:()=>{a="clear-all"},selected:!1}]);e.querySelector(".w96-radiobox").replaceWith(s.getElement())}}),this.pages.push({id:"reset-user",type:"page",body:'\n                <div>\n                    To begin resetting everything but keeping user files, you may press Next.<br>\n                    <br>Ensure that any unsaved files are saved, and that any programs which might be using the disk are closed.<br><br>\n                    <span class="bold-noaa">All installed programs, program data, and custom system configurations will be removed.</span>\n                </div>\n            ',graphic:"/system/resource/app/resetwiz/graphic-top.png",titleText:"Begin the reset",description:"Read the information below carefully.",buttons:[{class:"back",onclick:()=>this.openPage("reset-select",[]),enabled:!0,text:"Back"},{class:"next",onclick:async()=>{MsgBoxSimple.idleProgress("Reset Wizard","Working - please wait..."),this.mainwnd.wndObject.style.display="none";for(let e of await FS.readdir("c:/"))if("c:/user"!=e.toLowerCase())try{await FS.isFile(e)?await FS.rm(e):await FS.rmdir(e)}catch(e){}localStorage.clear(),this.mainwnd.close(),document.location.reload()},enabled:!0,text:"Next"},{class:"cancel",onclick:()=>this.quit(),enabled:!0,text:"Cancel"}],onopen:(e,t)=>{}}),this.pages.push({id:"reset-all",type:"page",body:'\n                <div>\n                    To begin resetting everything, you may press Next.<br>\n                    <br>\n                    <span class="bold-noaa">Everything will be lost, and nothing can be recovered. Back up any data you care about.</span>\n                </div>\n            ',graphic:"/system/resource/app/resetwiz/graphic-top.png",titleText:"Begin a full reset",description:"Read the information below carefully.",buttons:[{class:"back",onclick:()=>this.openPage("reset-select",[]),enabled:!0,text:"Back"},{class:"next",onclick:()=>{let e=localStorage.getItem("storeid");if(localStorage.clear(),indexedDB){const t=indexedDB.deleteDatabase(e);t.onsuccess=()=>{console.log("DB clear successful!"),localStorage.setItem("storeid",e),document.location.reload()},t.onerror=()=>{console.error("DB clear failed!"),localStorage.setItem("storeid",e),document.location.reload()},t.onblocked=()=>{console.error("Operation blocked - cannot clear DB."),localStorage.setItem("storeid",e),document.location.reload()}}else document.location.reload()},enabled:!0,text:"Next"},{class:"cancel",onclick:()=>this.quit(),enabled:!0,text:"Cancel"}],onopen:(e,t)=>{}}),this.openPage("intro",[]),this.mainwnd.setTitle("Reset Wizard"),this.mainwnd.setWindowIcon(await Theme.getIconUrl("apps/resetwiz","16x16")),this.mainwnd.center()}}

return await WApplication.execAsync(new ResetWizardApp(), this.boxedEnv.args, this);