"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebSiteEvent = void 0;
const lodash_1 = require("lodash");
class WebSiteEvent {
    constructor(menuTree) {
        this.prefixMenuTitle = [];
        this.hasIcon = false;
        this.eventTitle = menuTree.treeNode.eventTitle
            ? menuTree.treeNode.eventTitle
            : menuTree.treeNode.menuTitle
                ? menuTree.treeNode.menuTitle
                : menuTree.treeNode.pageTitle
                    ? menuTree.treeNode.pageTitle
                    : menuTree.treeNode.paragraphTitle
                        ? menuTree.treeNode.paragraphTitle
                        : '';
        this.icon = 'fas fa-splotch';
        this.menuTitle = this.eventTitle ? this.eventTitle : menuTree.treeNode.name;
        this.originalMenuTitle = menuTree.menuTitle;
        this.pageTreeId = menuTree.pageTreeId;
        this.pageTreeUri = menuTree.pageTreeUri;
        this.prefixMenuTitle = [];
        this.treeNode = menuTree.treeNode;
        menuTree.eventTitle = this.eventTitle;
    }
    static async get(entriesTree, menuTree, eventType, eventContributors, ctx) {
        const event = new eventType(menuTree);
        for (const contributor of eventContributors) {
            if (!(await contributor(event, entriesTree, menuTree, ctx))) {
                break;
            }
        }
        if ('' === event.eventTitle ||
            undefined === event.eventTitle ||
            null === event.eventTitle) {
            menuTree.eventTitle = menuTree.menuTitle;
            event.eventTitle = menuTree.eventTitle;
        }
        else {
            const prefixes = event.prefixMenuTitle.filter((prefix) => prefix !== null &&
                prefix !== undefined &&
                prefix !== '' &&
                prefix !== menuTree.evenTitle);
            if (0 < prefixes.length) {
                menuTree.menuTitle = prefixes.join(', ') + ', ' + menuTree.eventTitle;
            }
            else {
                menuTree.menuTitle = menuTree.eventTitle;
            }
            event.menuTitle = menuTree.menuTitle;
        }
        event.hasIcon = event.icon !== 'fas fa-splotch';
        return event;
    }
    addEventMenuTitle(titlePrefix, eventType) {
        if (this.eventType === eventType) {
            if (titlePrefix) {
                this.menuTitle = titlePrefix;
                if (-1 < lodash_1.indexOf(this.prefixMenuTitle, titlePrefix)) {
                    this.prefixMenuTitle.splice(lodash_1.indexOf(this.prefixMenuTitle, titlePrefix), 1);
                }
                this.prefixMenuTitle.unshift(titlePrefix);
            }
        }
        else if (titlePrefix &&
            -1 === lodash_1.indexOf(this.prefixMenuTitle, titlePrefix)) {
            this.prefixMenuTitle.push(titlePrefix);
        }
    }
    addSpecificFields(fields) {
        Object.assign(this, fields);
    }
}
exports.WebSiteEvent = WebSiteEvent;
//# sourceMappingURL=web-site.interface.js.map