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

const{OpenFileDialog:OpenFileDialog,DialogCreator:DialogCreator,Theme:Theme}=w96.ui,{RadioBox:RadioBox}=w96.ui.components,{WizardBaseApplication:WizardBaseApplication}=w96.app.templates;class BackupManagerApp extends WizardBaseApplication{constructor(){super()}async main(e){await super.main(e);const t=e.includes("--no-restore"),o=this.findPage("intro");o.titleText="Welcome to the Backup Wizard",o.graphic="/system/resource/app/backup/graphic.png",o.body="This wizard will help you create or restore a Windows 96 backup.<br><br>Please note that all applications must be closed for the best results.<br><br>The OS may freeze during the backup (do not panic, it is normal).",o.buttons[1].onclick=()=>this.openPage(t?"backup":"backup-select",[]);let a="backup";this.pages.push({id:"backup-select",type:"page",body:'Select an action:\n                <div class="w96-radiobox">\n                    <div class="option">\n                        <input type="radio" name="bopt" value="opt1">\n                        <label for="opt1" class="text">Create system backup.</label>\n                    </div>\n                    <div class="option">\n                        <input type="radio" name="bopt" value="opt2">\n                        <label for="opt2" class="text">Restore from backup ZIP.</label>\n                    </div>\n                </div>',graphic:"/system/resource/app/backup/graphic-top.png",titleText:"What would you like to do?",description:"You can backup your system or restore from one.",buttons:[{class:"back",onclick:()=>this.openPage("intro",[]),enabled:!0,text:"Back"},{class:"next",onclick:()=>{"backup"==a?this.openPage("backup",[]):this.openPage("restore",[])},enabled:!0,text:"Next"},{class:"cancel",onclick:()=>this.quit(),enabled:!0,text:"Cancel"}],onopen:(e,t)=>{const o=new RadioBox([{label:"Create system backup.",id:"backup",onselect:()=>{a="backup"},selected:!0},{label:"Restore from ZIP archive.",id:"restore",onselect:()=>{a="restore"},selected:!1}]);e.querySelector(".w96-radiobox").replaceWith(o.getElement())}}),this.pages.push({id:"backup",type:"page",body:"\n                <div>\n                    To begin the backup, press the next button. When the backup is complete, you will receive a locally generated download button with your data as a ZIP file.<br><br>\n                    Please note that your OS may lag/freeze/slow down because of heavy file system activity.<br><br>\n                    It is recommended to close all applications to avoid data corruption.<br><br>Please save your work, you will not be able to close the backup process once its running!\n                </div>\n            ",graphic:"/system/resource/app/backup/graphic-top.png",titleText:"Begin the backup",description:"Read the information below carefully.",buttons:[{class:"back",onclick:()=>this.openPage("backup-select",[]),enabled:!0,text:"Back"},{class:"next",onclick:()=>{localStorage.setItem("backup_mode_reboot","true"),document.location.reload()},enabled:!0,text:"Next"},{class:"cancel",onclick:()=>this.quit(),enabled:!0,text:"Cancel"}],onopen:(e,t)=>{}}),this.pages.push({id:"restore",type:"page",body:'\n                <div>\n                    To restore your system, please select a ZIP file below.<br><br>\n                    When this is done, click Next to restore your system.<br><br>\n                    Do not interrupt the restore process, you may likely make your installation unusable or corrupt.<br><br>\n                </div>\n                <div class="path-box">\n                    <input class="w96-textbox path">\n                    <button class="w96-button browse">Browse...</button>\n                </div>\n            ',graphic:"/system/resource/aPP/backup/graphic-top.png",titleText:"Restore from a backup",description:"Upload your ZIP file to begin the restore process",buttons:[{class:"back",onclick:()=>this.openPage("backup-select",[]),enabled:!0,text:"Back"},{class:"next",onclick:async()=>{const e=this.mainwnd.getBodyContainer().querySelector("input").value;await FS.exists(e)?(localStorage.setItem("restore_image",e),document.location.reload()):DialogCreator.alert("The specified ZIP file does not exist.")},enabled:!0,text:"Next"},{class:"cancel",onclick:()=>this.quit(),enabled:!0,text:"Cancel"}],onopen:(e,t)=>{e.querySelector("input").setAttribute("style","width: 100%; box-sizing: border-box; margin-bottom: 10px;"),e.querySelector("button.browse").addEventListener("click",(()=>{new OpenFileDialog("c:/",[".zip",".ZIP"],(t=>{null!=t&&""!=t.trim()&&(e.querySelector("input").value=t)})).show()}))}}),this.openPage("intro",[]),this.mainwnd.setTitle("Backup Wizard"),this.mainwnd.setWindowIcon(await Theme.getIconUrl("apps/backupmgr","16x16"))}}

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