"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const api_1 = require("./api");
const registries_1 = require("./registries");
const Context_1 = require("./Context");
const intl_1 = require("./intl");
const react_1 = tslib_1.__importDefault(require("react"));
const themes_1 = require("./themes");
const getComponent_1 = require("./getComponent");
const filters_1 = tslib_1.__importDefault(require("./filters"));
const BlueBaseContent = getComponent_1.getComponent('BlueBaseContent');
class BlueBase {
    constructor() {
        // APIs
        this.Analytics = new api_1.Analytics(this);
        this.Logger = new api_1.Logger(this);
        // Registries
        this.Assets = new registries_1.AssetRegistry(this);
        this.Components = new registries_1.ComponentRegistry(this);
        this.Configs = new registries_1.ConfigRegistry(this);
        this.Filters = new registries_1.FilterRegistry(this);
        this.Fonts = new registries_1.FontRegistry(this);
        this.Plugins = new registries_1.PluginRegistry(this);
        this.Themes = new registries_1.ThemeRegistry(this);
        // Flags
        this.booted = false;
        this.bootOptions = {
            assets: {},
            components: {},
            configs: {},
            filters: {},
            fonts: {},
            plugins: [],
            themes: [],
        };
    }
    async boot(options) {
        // Update boot options
        this.bootOptions = Object.assign({}, this.bootOptions, options);
        // Register basic filters here, so they can be used in boot
        await this.Filters.registerNestedCollection(filters_1.default);
        await this.Filters.registerNestedCollection(this.bootOptions.filters);
        // 🚀 Boot!
        await this.Filters.run('bluebase.boot', this.bootOptions);
        // Navigation
        const navigatorConfigs = await this.Filters.run('bluebase.navigator.root', {});
        // TODO: Move this to BlueBaseApp component
        const BlueBaseRoot = () => (react_1.default.createElement(Context_1.BlueBaseProvider, { value: this },
            react_1.default.createElement(themes_1.ThemeProvider, null,
                react_1.default.createElement(intl_1.IntlProvider, null,
                    react_1.default.createElement(BlueBaseContent, { BB: this, children: this.bootOptions.children, navigator: navigatorConfigs })))));
        this.booted = true;
        return BlueBaseRoot;
    }
}
exports.BlueBase = BlueBase;
