"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LibraryTemplateScopeService = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
const static_injector_1 = require("static-injector");
const const_1 = require("./const");
const i0 = __importStar(require("static-injector"));
class LibraryTemplateScopeService {
    // 追加模板
    constructor() {
        this.scopeExtraUseComponentsMap = new Map();
        this.scopeLibraryUseComponentsMap = new Map();
        this.setScopeExtraUseComponents = (libraryScope, extraData) => {
            const data = this.scopeExtraUseComponentsMap.get(libraryScope) || { useComponents: {}, templateList: [] };
            this.scopeExtraUseComponentsMap.set(libraryScope, {
                useComponents: Object.assign(Object.assign({}, data.useComponents), extraData.useComponents),
                templateList: [...data.templateList, ...extraData.templateList],
            });
        };
        this.setScopeLibraryUseComponents = (libraryScope, libraryUseComponents) => {
            this.scopeLibraryUseComponentsMap.set(libraryScope, libraryUseComponents);
        };
    }
    register(compilation) {
        compilation[const_1.TemplateScopeSymbol] = {
            setScopeExtraUseComponents: this.setScopeExtraUseComponents,
            setScopeLibraryUseComponents: this.setScopeLibraryUseComponents,
        };
    }
    exportLibraryComponentConfig() {
        const list = [];
        this.scopeLibraryUseComponentsMap.forEach((obj, libraryScope) => {
            const extraData = this.scopeExtraUseComponentsMap.get(libraryScope) || {
                useComponents: {},
            };
            // if (!extraData) {
            //   throw new Error(`没有找到${libraryScope}对应的配置`);
            // }
            for (const item of obj) {
                const configPath = item.configPath;
                const usingComponents = Object.assign(Object.assign({}, item.useComponents), extraData.useComponents);
                list.push({
                    filePath: configPath,
                    content: { component: true, usingComponents: usingComponents },
                });
            }
        });
        return list;
    }
    exportLibraryTemplate() {
        const fileGroup = {};
        this.scopeLibraryUseComponentsMap.forEach((obj, libraryScope) => {
            const extraData = this.scopeExtraUseComponentsMap.get(libraryScope) || {
                templateList: [],
            };
            // if (!extraData) {
            //   throw new Error(`没有找到${libraryScope}对应的配置`);
            // }
            for (const item of obj) {
                if (fileGroup[item.templatePath]) {
                    continue;
                }
                fileGroup[item.templatePath] = extraData.templateList.join('');
            }
        });
        return fileGroup;
    }
}
exports.LibraryTemplateScopeService = LibraryTemplateScopeService;
LibraryTemplateScopeService.ɵfac = function LibraryTemplateScopeService_Factory(t) { return new (t || LibraryTemplateScopeService)(); };
LibraryTemplateScopeService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: LibraryTemplateScopeService, factory: LibraryTemplateScopeService.ɵfac });
