var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard");var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _RoutingSystem=_interopRequireDefault(require("./RoutingSystem.js"));var _ViewSystem=_interopRequireWildcard(require("./ViewSystem.js"));var _ModuleSystem=_interopRequireDefault(require("./ModuleSystem.js"));var _modules=_interopRequireDefault(require("../../modules"));var _EventSystem=_interopRequireDefault(require("./EventSystem"));var _ActionSystem=_interopRequireDefault(require("./ActionSystem"));var _RulingSystem=_interopRequireDefault(require("./RulingSystem"));var _InjectionSystem=_interopRequireDefault(require("./InjectionSystem"));var Font=_interopRequireWildcard(require("expo-font"));var _Universal=_interopRequireDefault(require("!!raw-loader!../../rules/Universal.css"));var CoreSystem=function(){function CoreSystem(){var _this=this;var dev=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;(0,_classCallCheck2.default)(this,CoreSystem);_InjectionSystem.default.depend("Core",this);this.Routing=new _RoutingSystem.default();_InjectionSystem.default.depend("Routing",this.Routing);this.ModuleSystem=new _ModuleSystem.default();_InjectionSystem.default.depend("Modules",this.ModuleSystem);this.ActionSystem=new _ActionSystem.default(this);_InjectionSystem.default.depend("Actions",this.ActionSystem);this.ActionSystem.onUpdate(function(){return _this.forceUpdate();});this.RulingSystem=new _RulingSystem.default();_InjectionSystem.default.depend("Ruling",this.RulingSystem);this.RulingSystem.addRuleFile(_Universal.default);this.RulingSystem.onUpdate(function(){return _this.forceUpdate();});this.ViewSystem=new _ViewSystem.default(this);_InjectionSystem.default.depend("Views",this.ViewSystem);this.loadFonts();this.__loadModules(_modules.default);this._devMode=dev;}(0,_createClass2.default)(CoreSystem,[{key:"onUpdate",value:function onUpdate(fn){this._onUpdate=fn;}},{key:"forceUpdate",value:function forceUpdate(){this._onUpdate&&this._onUpdate();}},{key:"fresh",value:function fresh(){var _this2=this;this.ActionSystem=new _ActionSystem.default(this);this.ActionSystem.onUpdate(function(){return _this2.forceUpdate();});this.Routing=new _RoutingSystem.default();this.ModuleSystem=new _ModuleSystem.default();this.ViewSystem=new _ViewSystem.default(this);var HomeView=new _ViewSystem.View();this.addPage('Home',HomeView,'VSHome').setHome('Home');this.__loadModules(_modules.default);}},{key:"loadFonts",value:function loadFonts(){Font.loadAsync({'black':require("../assets/fonts/SFCompactDisplay-Black_0.otf"),'bold':require("../assets/fonts/SFCompactDisplay-Bold_0.otf"),'heavy':require("../assets/fonts/SFCompactDisplay-Heavy_0.otf"),'light':require("../assets/fonts/SFCompactDisplay-Light_0.otf"),'medium':require("../assets/fonts/SFCompactDisplay-Medium_0.otf"),'regular':require("../assets/fonts/SFCompactDisplay-Regular_0.otf"),'semibold':require("../assets/fonts/SFCompactDisplay-Semibold_0.otf"),'thin':require("../assets/fonts/SFCompactDisplay-Thin_0.otf"),'ultralight':require("../assets/fonts/SFCompactDisplay-Ultralight_0.otf"),'roboto-black':require("../assets/fonts/Roboto-Black.ttf"),'roboto-black-italic':require("../assets/fonts/Roboto-BlackItalic.ttf"),'roboto-bold':require("../assets/fonts/Roboto-Bold.ttf"),'roboto-bold-italic':require("../assets/fonts/Roboto-BoldItalic.ttf"),'roboto-light':require("../assets/fonts/Roboto-Light.ttf"),'roboto-light-italic':require("../assets/fonts/Roboto-LightItalic.ttf"),'roboto-medium':require("../assets/fonts/Roboto-Medium.ttf"),'roboto-medium-italic':require("../assets/fonts/Roboto-MediumItalic.ttf"),'roboto-regular':require("../assets/fonts/Roboto-Regular.ttf"),'roboto-regular-italic':require("../assets/fonts/Roboto-RegularItalic.ttf"),'roboto-thin':require("../assets/fonts/Roboto-Thin.ttf"),'roboto-thin-italic':require("../assets/fonts/Roboto-ThinItalic.ttf")});}},{key:"getCurrentView",value:function getCurrentView(){return this.ViewSystem.getView(this.Routing.getCurrentView());}},{key:"setHome",value:function setHome(route,View){this.Routing.setHome(route);return this;}},{key:"goto",value:function goto(route){var res=this.Routing.goTo(route);this.forceUpdate();return res;}},{key:"addPage",value:function addPage(route,View){var ViewID=arguments.length>2&&arguments[2]!==undefined?arguments[2]:Math.random();this.Routing.addRoute(route,route);this.Routing.setView(route,ViewID);this.ViewSystem.addView(ViewID,View);return this;}},{key:"removePage",value:function removePage(route){this.Routing.removeRoute(route);return this;}},{key:"goBack",value:function goBack(){}},{key:"__loadModules",value:function __loadModules(){this.ModuleSystem.load(_modules.default);}},{key:"addModule",value:function addModule(mod,namespace){this.ModuleSystem.loadModule(mod.name,mod,namespace);return this;}},{key:"render",value:function render(){var ViewID=this.Routing.getCurrentView();return this.ViewSystem.render(ViewID);}},{key:"import",value:function _import(data){var Routing=data.Routing,Views=data.Views;try{this.Routing.import(Routing);this.ViewSystem.import(Views);}catch(e){throw new Error("CoreSystem cannot import data : ",e);}console.log("Successful import");}},{key:"export",value:function _export(){var RS=this.Routing.export();var VS=this.ViewSystem.export();return{Routing:RS,Views:VS};}},{key:"ray",value:function ray(data){var event=data.event;var targets=event.path.map(function(item){return findReactElement(item);});var resViewNode=null;for(var i in targets){if(targets[i]&&targets[i].ID){resViewNode=targets[i].ID;break;}}var ViewID=this.Routing.getCurrentView();return this.ViewSystem.getNode(ViewID,resViewNode);}}]);return CoreSystem;}();exports.default=CoreSystem;var findReactElement=function findReactElement(node){for(var key in node){if(key.startsWith("__reactInternalInstance$")){return node[key]._debugOwner&&node[key]._debugOwner.stateNode.props||node[key].return.memoizedProps;}}return null;};