"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CntrlSdkContext = void 0;
class CntrlSdkContext {
    constructor(customItems, customSections) {
        this.customItems = customItems;
        this.customSections = customSections;
        this._layouts = [];
        this.sectionHeightMap = new Map();
    }
    resolveSectionData(sections) {
        return __awaiter(this, void 0, void 0, function* () {
            const resolvers = sections.map(section => {
                const resolver = section.name ? this.customSections.getResolver(section.name) : undefined;
                if (!resolver)
                    return;
                return {
                    name: section.name,
                    resolver
                };
            }).filter(isDefined);
            return Object.fromEntries(yield Promise.all(resolvers.map(({ name, resolver }) => __awaiter(this, void 0, void 0, function* () { return [name, yield resolver()]; }))));
        });
    }
    init({ project, article }) {
        this.setLayouts(project.layouts);
        this.setSectionsHeight(article.sections);
    }
    setLayouts(layouts) {
        this._layouts = layouts;
    }
    setSectionsHeight(sections) {
        for (const section of sections) {
            this.sectionHeightMap.set(section.id, section.height);
        }
    }
    getSectionHeightData(sectionId) {
        const sectionHeightData = this.sectionHeightMap.get(sectionId);
        return sectionHeightData;
    }
    get layouts() {
        return this._layouts;
    }
}
exports.CntrlSdkContext = CntrlSdkContext;
function isDefined(value) {
    return value !== undefined;
}
