//!wrt $BSPEC:{"icn":"apps/syslog","cpr":"Copyright (C) Windows 96 Team 2022.","dsc":"System Event Log","frn":"System Log","ver":1,"ssy":"gui"}

const{MenuBar:MenuBar,Theme:Theme,DialogCreator:DialogCreator,SaveFileDialog:SaveFileDialog}=w96.ui,{ListView:ListView}=w96.ui.components,{log:log}=w96.sys;class SysLogApplication extends WApplication{constructor(){super(),this.state={_sfdInitialDir:"C:/user"}}async main(e){await super.main(e);const t={error:await Theme.getIconUrl("status/error","16x16"),warning:await Theme.getIconUrl("status/warning","16x16"),info:await Theme.getIconUrl("status/info","16x16"),none:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="},n=this.createWindow({title:"System Log",icon:await Theme.getIconUrl("apps/syslog","16x16"),initialHeight:380,initialWidth:550,bodyClass:"systemlog-app",body:'\n                <div class="appbar"></div>\n                <div class="content">\n                    <div class="table"></div>\n                    <div class="description w96-textbox" readonly></div>\n                </div>\n                <footer class="w96-footer">\n                    <div class="cell">\n                        0 items.\n                    </div>\n                </footer>\n            ',taskbar:!0},!0);this.mainwnd=n;const a=n.getBodyContainer(),i=new MenuBar;i.addRoot("File",[{type:"normal",label:"Dump To File...",onclick:()=>new SaveFileDialog(this.state._sfdInitialDir,[".json",".slg"],(e=>{e&&(this.state._sfdInitialDir=FSUtil.getParentPath(e),FS.writestr(e,JSON.stringify(log.events)))})).show()},{type:"separator"},{type:"normal",label:"Exit",onclick:()=>this.terminate()}]),i.addRoot("Help",[{type:"normal",label:"About",onclick:async()=>DialogCreator.alert('<span class="bold-noaa">System Event Log</span><br>Version 1.0',{title:"About",icon:await Theme.getIconUrl("apps/syslog")})}]),a.querySelector(".appbar").replaceWith(i.getMenuDiv());const o=new ListView;o.addColumnHeader("Level",80),o.addColumnHeader("Source",100),o.addColumnHeader("Date/Time");for(let e=log.events.length-1;e>=0;e--){const n=log.events[e];let a;switch(n.severity){case"info":a="Information";break;case"warning":a="Warning";break;case"error":a="Error";break;case"none":a="Other"}o.pushData([a,n.source,n.date],t[n.severity]||null).addEventListener("click",(()=>{this.displayDescription(n)}))}a.querySelector(".table").replaceWith(o.getElement()),log.events.length>0&&(o.select(0),this.displayDescription(log.events[log.events.length-1])),a.querySelector(".cell").textContent=1==log.events.length?"1 item":`${log.events.length} items`,n.onshown=()=>{log.silenced&&DialogCreator.alert("The system event log has been silenced, nothing to see here.",{title:"System Event Log",icon:"error"})},n.show()}displayDescription(e){this.mainwnd.getBodyContainer().querySelector(".description").textContent=`Source: ${e.source}\n\nDate: ${new Date(e.date).toString()}\n\nMessage: ${e.message}`}async ontermination(){await super.ontermination(),this.mainwnd=null}}

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