var _extends=Object.assign||function(a){for(var b,c=1;c; super(a),this.state={tree:null,main:null,export:!1,counter:0,vision:localStorage.getItem('AdminVision')},this.tree={},API.setUrl('/'),Core.onUpdate(()=>{this.onUpdate()}),this._elist=window.addEventListener('keydown',a=>!((window.navigator.platform.match('Mac')?a.metaKey:a.ctrlKey)&&83==a.which)||(this._save(Core.export()),window.M?window.M.toast({html:'Project saved! -------',displayLength:5e3}):window.Materialize&&window.Materialize.toast('Project saved! --------------',5e3),a.preventDefault(),!1))}onUpdate(){this.mounted&&(console.log('UPDATE OK'),this.forceUpdate())}componentDidMount(){this.mounted=!0,this._load()}componentWillUnmount(){window.removeEventListener('keydown',this._elist),this.mounted=!1}addService(a){a.id=parseInt(1234567890*Math.random())%7654321,Core.loadService(a),Core.refresh()}toggleMode(){'admin'===localStorage.getItem('AdminMode')?localStorage.setItem('AdminMode',''):localStorage.setItem('AdminMode','admin'),Core.refresh(!0),this.forceUpdate()}toggle(){'admin'===localStorage.getItem('AdminVision')?(localStorage.setItem('AdminVision',''),this.setState({vision:!1})):(localStorage.setItem('AdminVision','admin'),this.setState({vision:!0}))}addRoot(a){let b=prompt('Add Name');if(b){a.id=b;let c=prompt('Add Route');this.setState({main:[a]}),Core.loadModule(a,!0),Core.RoutingSystem.addRoute(c,a.id),Core.go(c),this._save(Core.export())}}_save(a){console.log(a),localStorage.setItem('Site',JSON.stringify(a))}_load(){if(localStorage.getItem('Site'))try{let a=JSON.parse(localStorage.getItem('Site'));this.setState({main:a,counter:0}),Core.import(a),console.log('Loaded',a,this)}catch(a){Logger.error('Memory Loader : Failed to parse localStorage Site.',a)}}exportToFile(){(function download(a,b){var c=document.createElement('a');c.setAttribute('href','data:text/plain;charset=utf-8,'+encodeURIComponent(b)),c.setAttribute('download',a),c.style.display='none',document.body.appendChild(c),c.click(),document.body.removeChild(c)})('Modularity'+new Date().toISOString()+'.txt',JSON.stringify(Core.export()))}importFromFile(a){this;var b=a.target,c=new FileReader;c.onload=function(){var a=c.result;let b=window.confirm('Import : '+a);if(b)try{Core.import(JSON.parse(a)),Core.refresh(!0)}catch(a){alert('No good file!')}},c.readAsText(b.files[0])}render(){let a=Core.renderModules(),b=Core.renderServices();return a||console.log('Core Modules rendered: '+a),b||console.log('Core services rendered: '+b),React.createElement('div',null,this.state.vision?React.createElement('div',null,React.createElement(Card,{className:'MemoryLoaderUI',key:'UI'},React.createElement('div',{className:'row'},React.createElement(Button,{type:'button',className:'btn btn-primary col s6',onClick:()=>this.toggle()},React.createElement(FontAwesomeIcon,{icon:'eye'})),React.createElement(Button,{className:'btn btn-primary darken-1 col s6',onClick:()=>this.toggleMode()},'Admin'),React.createElement(Button,{className:'btn btn-primary col s6',onClick:()=>this._save(Core.export())},React.createElement(Icon,null,'save')),React.createElement(Button,{className:'btn btn-primary col s6',onClick:()=>this.exportToFile()},React.createElement(Icon,null,'file_download')),React.createElement(Input,{type:'file',label:React.createElement(Icon,null,'file_upload'),s:12,onChange:a=>this.importFromFile(a)}),React.createElement('div',{className:'col s12'},React.createElement('div',null,React.createElement(InputMarker,{name:'root',onDrop:a=>this.addRoot(a)})),React.createElement('div',null,React.createElement(InputMarker,{name:'services',onDrop:a=>this.addService(a)})),React.createElement('div',null,React.createElement(Extendable,{header:'Add input'},React.createElement(InputGeneratorUI,null))),React.createElement('div',null,React.createElement(Extendable,{header:'Add output'},React.createElement(OutputGeneratorUI,null))),React.createElement('div',null,React.createElement(Extendable,{header:'Core I/O'},React.createElement(IO,null)))))),b?b:'',React.createElement(ModuleLoader,null)):React.createElement(Card,{className:'MemoryLoaderUI mini',key:'UI'},React.createElement('div',{className:'row'},React.createElement('button',{type:'button',className:'btn btn-primary col s12',onClick:()=>this.toggle()},React.createElement(FontAwesomeIcon,{icon:'eye-slash'})))),a?a:'No render')}}class SolidLoader extends React.Component{constructor(a){super(a),this.state={script:a.script||{}},API.setUrl('/'),Core.onUpdate(()=>this.onUpdate())}onUpdate(){this.forceUpdate()}componentDidMount(){this._load()}_load(){if(this.state.script)try{let a=this.props.script;this.setState({main:a,counter:0}),Core.import(a),console.log('Loaded',a,this)}catch(a){Logger.error('Solid Loader : Failed to parse SiteScript.',a)}}render(){let a=Core.renderModules(),b=Core.renderServices();return React.createElement('div',null,a?a:'No render')}}class IO extends React.Component{constructor(a){super(a),this.state={}}render(){console.log(Core.inputs);let a=Core.inputs||{},b=Core.outputs||{},c=Object.keys(a).map((b,c)=>(Core.getInput(b).onUpdate(()=>this.forceUpdate()),React.createElement('div',{key:c+Math.random()},RendererInput(Core.getInput(b),(c,d)=>Core.updateInput(_extends({},a[b],{value:d}))),React.createElement('span',{onClick:()=>Core.removeInput(b)},React.createElement(Icon,null,'delete'))))),d=Object.keys(b).map((a,c)=>React.createElement('div',{key:c},RendererOutput(Core.getOutput(a),(c,d)=>Core.updateOutput(_extends({},b[a],{value:d}))),React.createElement('span',{onClick:()=>Core.removeOutput(a)},React.createElement(Icon,null,'delete'))));return React.createElement('div',null,React.createElement('div',null,c),React.createElement('div',null,d))}}class InputGeneratorUI extends React.Component{constructor(a){super(a),this.state={type:Types.Text,arrType:Types.Text,name:'',defaultValue:''}}submit(){Core.addInput(_extends({},this.state))}render(){return React.createElement('div',{className:'InputGenerator',style:{background:'white'}},React.createElement('div',{className:'row'},React.createElement(Select,{s:12,type:'select',label:'Type',defaultValue:Types.Text,onChange:a=>this.setState({type:parseInt(a.target.value)})},Object.keys(Types).map((a,b)=>React.createElement('option',{key:b,value:Types[a]},a)))),React.createElement('div',{className:'row'},this.state.type===Types.Array?React.createElement(Select,{s:12,type:'select',label:'Array Type',defaultValue:Types.Text,onChange:a=>this.setState({arrType:parseInt(a.target.value)})},Object.keys(Types).map((a,b)=>React.createElement('option',{key:b,value:Types[a],disabled:'Array'==a},a))):''),React.createElement('div',{className:'row'},React.createElement('input',{className:'col s12',type:'text',onChange:a=>this.setState({name:a.target.value}),placeholder:'Name'})),React.createElement('div',{className:'row'},React.createElement('input',{className:'col s12',type:'text',onChange:a=>this.setState({defaultValue:a.target.value}),placeholder:'Default'})),React.createElement('div',{className:'row'},React.createElement(Button,{className:'btn btn-primary col s12',type:'text',onClick:()=>this.submit()},'Add')))}}class OutputGeneratorUI extends React.Component{constructor(a){super(a),this.state={type:0,arrType:0,name:''}}submit(){Core.addOutput(_extends({},this.state))}render(){return React.createElement('div',{className:'OutputGenerator',style:{background:'white'}},React.createElement('div',{className:'row'},React.createElement(Select,{s:12,type:'select',label:'Type',defaultValue:'2',onChange:a=>this.setState({type:parseInt(a.target.value)})},Object.keys(Types).map((a,b)=>React.createElement('option',{key:b,value:Types[a]},a)))),React.createElement('div',{className:'row'},this.state.type===Types.Array?React.createElement(Select,{s:12,type:'select',label:'Array Type',defaultValue:'2',onChange:a=>this.setState({arrType:parseInt(a.target.value)})},Object.keys(Types).map((a,b)=>React.createElement('option',{key:b,value:Types[a],disabled:'Array'==a},a))):''),React.createElement('div',{className:'row'},React.createElement('input',{className:'col s12',type:'text',onChange:a=>this.setState({name:a.target.value}),placeholder:'Name'})),React.createElement('div',{className:'row'},React.createElement(Button,{className:'btn btn-primary col s12',type:'text',onClick:()=>this.submit()},'Add')))}}ModuleLoader.MemoryLoader=MemoryLoader,ModuleLoader.SolidLoader=SolidLoader;export default ModuleLoader;