import { __extends, __assign } from '../../../../node_modules/tslib/tslib.es6.js';
import { replaceParameters } from '../../../../utilities/replacePathParameters.js';
import { BaseConfig } from '../../BaseConfig.js';
import { UserTypeExternal } from '../types.js';
import { HeaderNavigationLink } from './headerNavigationLink.js';

var menuHeightConfig = '60px';
var HeaderNavigationConfig = /** @class */ (function (_super) {
    __extends(HeaderNavigationConfig, _super);
    function HeaderNavigationConfig(_a) {
        var brand = _a.brand, environment = _a.environment, useAbsoluteUrls = _a.useAbsoluteUrls, project = _a.project, config = _a.config, user = _a.user, urlPathParams = _a.urlPathParams;
        var _this = this;
        var entitlements = Object.keys((user === null || user === void 0 ? void 0 : user.entitlements) || {});
        _this = _super.call(this, { brand: brand, environment: environment, useAbsoluteUrls: useAbsoluteUrls, project: project, entitlements: entitlements }) || this;
        _this.replacePathParams = function (link) {
            if (link && _this.urlPathParams) {
                return Object.entries(link).reduce(function (acc, _a) {
                    var _b;
                    var key = _a[0], value = _a[1];
                    return __assign(__assign({}, acc), (_b = {}, _b[key] = replaceParameters({
                        path: value,
                        params: _this.urlPathParams,
                    }), _b));
                }, {});
            }
            return link;
        };
        _this.getHeaderLinks = function () {
            return _this.config.headerItems
                .map(function (link) { return _this.mapLink(link); })
                .filter(function (item) { return item.isVisible; });
        };
        _this.getIconItems = function () {
            return Object.keys(_this.config.iconItems).reduce(function (previousValue, currentValue) {
                var linkToMap = _this.config.iconItems[currentValue];
                previousValue[currentValue] = linkToMap
                    ? _this.mapLink(linkToMap)
                    : null;
                return previousValue;
            }, {});
        };
        _this.getDrawerNodeItems = function () {
            var itemsEntires = Object.entries(_this.config.drawerItems);
            var mappedEntries = _this.mapDrawerItemsEntries(itemsEntires);
            return Object.fromEntries(mappedEntries);
        };
        _this.mapDrawerItemsEntries = function (itemsEntires) {
            return itemsEntires.map(function (_a) {
                var nodeKey = _a[0], nodes = _a[1];
                var mappedNodes = _this.mapDrawerNodes(nodes);
                return [nodeKey, mappedNodes];
            });
        };
        _this.mapDrawerNodes = function (nodeEntry) {
            return nodeEntry.map(function (node) {
                var mappedItems = _this.mapDrawerNodeItems(node.items);
                return __assign(__assign({}, node), { items: mappedItems });
            });
        };
        _this.mapDrawerNodeItems = function (items) {
            return items
                .map(function (item) { return _this.mapLink(item); })
                .filter(function (item) { return item.isVisible; });
        };
        _this.config = config;
        _this.homeUrl = '/';
        _this.menuHeight = menuHeightConfig;
        _this.user = user;
        _this.userType = user ? user.userType : UserTypeExternal.Guest;
        _this.urlPathParams = urlPathParams;
        return _this;
    }
    HeaderNavigationConfig.prototype.getMappedConfig = function () {
        if (this.mappedConfig)
            return this.mappedConfig;
        var mappedConfig = {
            homeUrl: this.homeUrl,
            menuHeight: this.menuHeight,
            user: this.user,
            headerItems: this.getHeaderLinks(),
            drawerItems: this.getDrawerNodeItems(),
            iconItems: this.getIconItems(),
        };
        this.mappedConfig = mappedConfig;
        return this.mappedConfig;
    };
    HeaderNavigationConfig.prototype.mapEntitlementConfig = function (entitlementConfig) {
        return __assign(__assign({}, entitlementConfig), { missingEntitlementFallbackLink: this.replacePathParams(entitlementConfig.missingEntitlementFallbackLink) });
    };
    HeaderNavigationConfig.prototype.mapLink = function (link) {
        var entitlementConfig = link.entitlementConfig;
        return new HeaderNavigationLink({
            config: {
                title: link.title,
                translationKey: link.translationKey,
                translationParameters: link.translationParameters,
                link: this.replacePathParams(link.link),
                onClick: link.onClick,
                target: undefined,
                visibilitySettings: link.visibilitySettings,
                entitlementConfig: entitlementConfig && this.mapEntitlementConfig(entitlementConfig),
                projectIdentifier: link.projectIdentifier,
            },
            forceMotoscoutLink: link.forceMotoscoutLink,
            forceAutoscoutLink: link.forceAutoscoutLink,
            brand: this.brand,
            userType: this.userType,
            environment: this.environment,
            useAbsoluteUrls: this.useAbsoluteUrls,
            project: this.project,
            linkProtocol: this.linkProtocol,
            domains: this.domains,
            isNew: link.isNew,
            rightIcon: link.rightIcon,
            showUnderMoreLinkBelow: link.showUnderMoreLinkBelow,
            fontWeight: link.fontWeight,
            variant: link.variant,
            color: link.color,
            userAvatar: link.userAvatar,
            userEntitlements: this.entitlements,
        });
    };
    return HeaderNavigationConfig;
}(BaseConfig));

export { HeaderNavigationConfig, menuHeightConfig };
//# sourceMappingURL=HeaderNavigationConfig.js.map
