"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Modules = void 0;
const ModuleManager_1 = __importDefault(require("../../core/libs/common/ModuleManager"));
const core_1 = require("../../core");
const findDep_1 = __importDefault(require("../../core/libs/utils/findDep"));
const Storage_1 = __importDefault(require("./Storage"));
const Preview_1 = __importDefault(require("./Preview"));
const Upload_1 = __importDefault(require("./Upload"));
const UI_1 = __importDefault(require("./UI"));
const EventTracker_1 = __importDefault(require("./EventTracker"));
const Service_1 = __importDefault(require("./Service"));
const Feedback_1 = __importDefault(require("./Feedback"));
const Account_1 = __importDefault(require("./Account"));
const Static_1 = __importDefault(require("./Static"));
const moduleMap = {
    [core_1.ModuleName.account]: Account_1.default,
    [core_1.ModuleName.ui]: UI_1.default,
    [core_1.ModuleName.storage]: Storage_1.default,
    [core_1.ModuleName.preview]: Preview_1.default,
    [core_1.ModuleName.upload]: Upload_1.default,
    [core_1.ModuleName.compile]: core_1.CompileModule,
    [core_1.ModuleName.service]: Service_1.default,
    [core_1.ModuleName.jssdk]: core_1.JSSDKModule,
    [core_1.ModuleName.feedback]: Feedback_1.default,
    [core_1.ModuleName.eventTracker]: EventTracker_1.default,
    [core_1.ModuleName.sniffer]: core_1.SnifferModule,
    [core_1.ModuleName.creator]: core_1.CreatorModule,
    [core_1.ModuleName.static]: Static_1.default,
};
class Modules {
    constructor(name) {
        this.modules = [];
        this.modulesMap = {};
        const manager = new ModuleManager_1.default();
        let modules = [];
        if (name) {
            modules = Array.isArray(name)
                ? name.reduce((prev, cur) => {
                    prev = Array.from(new Set([...prev, ...(0, findDep_1.default)(cur)]));
                    return prev;
                }, [])
                : (0, findDep_1.default)(name);
        }
        else {
            modules = Object.keys(moduleMap);
        }
        this.modules = modules.map((m) => {
            const Module = moduleMap[m];
            const module = new Module();
            this.modulesMap[m] = module;
            return module;
        });
        this.manager = manager;
        this.init();
    }
    init() {
        return this.manager.init(this.modules);
    }
}
exports.Modules = Modules;
