import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { RouterModule } from '@angular/router';
import { BabylonDynamicHeadingComponent } from '../../shared';
import * as i0 from "@angular/core";
import * as i1 from "@angular/router";
export class BabylonWebmapComponent {
    constructor() {
        this._groupByCategory = false;
        this.groupedLinks = [];
    }
    set links(value) {
        this._links = value;
        this.refreshGroupedLinks();
    }
    get links() {
        return this._links;
    }
    set groupByCategory(value) {
        this._groupByCategory = this.hasTokenValue(value);
        this.refreshGroupedLinks();
    }
    get shouldGroupLinks() {
        return this._groupByCategory;
    }
    linkClick(e) {
        e.preventDefault();
    }
    refreshGroupedLinks() {
        this.groupedLinks = this._groupByCategory
            ? this.groupLinksByUrl(this._links)
            : [];
    }
    groupLinksByUrl(links) {
        if (!links?.length)
            return [];
        const groups = [];
        const groupedByFirstSegment = new Map();
        links.forEach((link, index) => {
            const segments = this.getUrlSegments(link.url);
            if (segments.length === 0) {
                groups.push(this.createGroup(link, `home-${index}`, '', true));
                return;
            }
            const [firstSegment] = segments;
            const group = groupedByFirstSegment.get(firstSegment) ??
                this.createGroup(undefined, firstSegment, this.getLabelFromSlug(firstSegment));
            if (!groupedByFirstSegment.has(firstSegment)) {
                groupedByFirstSegment.set(firstSegment, group);
                groups.push(group);
            }
            if (segments.length === 1) {
                group.link = link;
                group.label = link.label || group.label;
                group.trackKey = link.url || firstSegment;
                return;
            }
            group.children.push(link);
        });
        return this.moveHomeGroupFirst(groups);
    }
    createGroup(link, trackKey, fallbackLabel = '', isHome = false) {
        return {
            label: link?.label || fallbackLabel,
            link,
            children: [],
            trackKey: link?.url || trackKey,
            isHome,
        };
    }
    getUrlSegments(url) {
        if (!url)
            return [];
        const path = this.getUrlPath(url);
        const segments = path.split('/').filter(Boolean);
        if (segments[0] && this.isLanguageSegment(segments[0])) {
            return segments.slice(1);
        }
        return segments;
    }
    getUrlPath(url) {
        const cleanUrl = url.split('#')[0]?.split('?')[0] ?? '';
        if (/^[a-z][a-z\d+\-.]*:\/\//i.test(cleanUrl)) {
            try {
                return new URL(cleanUrl).pathname;
            }
            catch {
                return cleanUrl;
            }
        }
        return cleanUrl;
    }
    isLanguageSegment(segment) {
        return /^[a-z]{2}(-[a-z]{2})?$/i.test(segment);
    }
    hasTokenValue(value) {
        if (typeof value === 'boolean')
            return value;
        if (typeof value === 'string')
            return value.trim().length > 0;
        return false;
    }
    getLabelFromSlug(slug) {
        return slug
            .split('-')
            .filter(Boolean)
            .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
            .join(' ');
    }
    moveHomeGroupFirst(groups) {
        const homeIndex = groups.findIndex((group) => group.isHome);
        if (homeIndex <= 0)
            return groups;
        const sortedGroups = [...groups];
        const [homeGroup] = sortedGroups.splice(homeIndex, 1);
        return [homeGroup, ...sortedGroups];
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: BabylonWebmapComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "17.3.12", type: BabylonWebmapComponent, isStandalone: true, selector: "lib-babylon-webmap", inputs: { pretitle: "pretitle", title: "title", image: "image", tags: "tags", textColors: "textColors", links: "links", groupByCategory: "groupByCategory" }, ngImport: i0, template: "<section class=\"babylon__webmap margin-main\">\n    <div class=\"container\">\n        <div class=\"row cs_gap_y_30\">\n            <div class=\"col-lg-6 cs_pr_110\">\n                <div class=\"intro_info no-align\">\n                    @if (pretitle) {\n                        <lib-babylon-dynamic-heading\n                            [tag]=\"tags?.pretitle || 'h3'\"\n                            cssClass=\"pretitle mb--10\"\n                            [color]=\"textColors?.pretitle\"\n                            [content]=\"pretitle\"\n                        ></lib-babylon-dynamic-heading>\n                    }\n                    @if (title) {\n                        <lib-babylon-dynamic-heading\n                            [tag]=\"tags?.title || 'h2'\"\n                            cssClass=\"title\"\n                            [color]=\"textColors?.title\"\n                            [content]=\"title\"\n                        ></lib-babylon-dynamic-heading>\n                    }\n                    @if (shouldGroupLinks && groupedLinks.length) {\n                        <ul\n                            class=\"cs_list cs_style_1 cs_mp_0 babylon__webmap-list--grouped\"\n                        >\n                            @for (group of groupedLinks; track group.trackKey) {\n                                <li\n                                    [class.babylon__webmap-group--has-children]=\"\n                                        group.children.length\n                                    \"\n                                >\n                                    <div class=\"babylon__webmap-group-title\">\n                                        @if (group.link?.url) {\n                                            <a\n                                                [attr.aria-label]=\"\n                                                    group.link?.label\n                                                \"\n                                                [href]=\"group.link?.url\"\n                                                [routerLink]=\"group.link?.url\"\n                                                (click)=\"linkClick($event)\"\n                                            >\n                                                <p class=\"text--small\">\n                                                    {{ group.label }}\n                                                </p>\n                                            </a>\n                                        } @else {\n                                            <p class=\"text--small\">\n                                                {{ group.label }}\n                                            </p>\n                                        }\n                                    </div>\n                                    @if (group.children.length) {\n                                        <ul class=\"babylon__webmap-sublist\">\n                                            @for (\n                                                child of group.children;\n                                                track child.url ||\n                                                    child.label ||\n                                                    $index\n                                            ) {\n                                                <li>\n                                                    <a\n                                                        [attr.aria-label]=\"\n                                                            child.label\n                                                        \"\n                                                        [href]=\"child.url\"\n                                                        [routerLink]=\"child.url\"\n                                                        (click)=\"\n                                                            linkClick($event)\n                                                        \"\n                                                    >\n                                                        <p class=\"text--small\">\n                                                            {{ child.label }}\n                                                        </p>\n                                                    </a>\n                                                </li>\n                                            }\n                                        </ul>\n                                    }\n                                </li>\n                            }\n                        </ul>\n                    } @else if (links?.length) {\n                        <ul class=\"cs_list cs_style_1 cs_mp_0\">\n                            @for (link of links; track $index) {\n                                @if (link) {\n                                    <li>\n                                        <a\n                                            [attr.aria-label]=\"link.label\"\n                                            [href]=\"link.url\"\n                                            [routerLink]=\"link.url\"\n                                            (click)=\"linkClick($event)\"\n                                        >\n                                            <p class=\"text--small\">\n                                                {{ link.label }}\n                                            </p>\n                                        </a>\n                                    </li>\n                                }\n                            }\n                        </ul>\n                    }\n                </div>\n            </div>\n            @if (image) {\n                <div class=\"col-lg-6\">\n                    <div\n                        class=\"cs_pr_1101 cs_image_layer cs_style_3 position-relative\"\n                    >\n                        <img\n                            [src]=\"\n                                image?.src ||\n                                'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'\n                            \"\n                            [alt]=\"image?.alt ?? image?.title ?? 'title'\"\n                            class=\"cs--radius\"\n                            loading=\"lazy\"\n                        />\n                    </div>\n                </div>\n            }\n        </div>\n    </div>\n</section>\n", styles: ["@charset \"UTF-8\";.cs_list.cs_style_1 li{position:relative;display:flex;align-items:flex-start;gap:10px;border-bottom:1px solid var(--cl_border-light);padding-bottom:10px}.cs_list.cs_style_1 li:not(:last-child){margin-bottom:15px}.cs_list.cs_style_1.babylon__webmap-list--grouped li{flex-direction:column;gap:8px}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-group-title{display:flex;align-items:flex-start;gap:10px}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-group-title:before{content:\"\\2022\";flex:none;line-height:1.7}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-group--has-children>.babylon__webmap-group-title .text--small{font-weight:700}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-sublist{display:flex;flex-direction:column;gap:8px;width:100%;padding-left:28px}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-sublist li{display:flex;flex-direction:row;gap:10px;border-bottom:0;padding-bottom:0}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-sublist li:not(:last-child){margin-bottom:0}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-sublist li:before{content:\"\\2022\";flex:none;line-height:1.7}.cs_image_layer.cs_style_3.cs_type_1,.cs_image_layer.cs_style_4.cs_type_1{border-radius:250px 0}.cs_image_layer.cs_style_3.cs_type_1 img,.cs_image_layer.cs_style_4.cs_type_1 img{border-radius:inherit}.cs_image_layer.cs_style_3.cs_type_1:before,.cs_image_layer.cs_style_4.cs_type_1:before{border-radius:225px 0}.cs_list{width:100%}\n"], dependencies: [{ kind: "ngmodule", type: RouterModule }, { kind: "directive", type: i1.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "component", type: BabylonDynamicHeadingComponent, selector: "lib-babylon-dynamic-heading", inputs: ["useInnerHtml", "tag", "wrapper", "cssClass", "content", "color"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: BabylonWebmapComponent, decorators: [{
            type: Component,
            args: [{ selector: 'lib-babylon-webmap', standalone: true, imports: [RouterModule, BabylonDynamicHeadingComponent], changeDetection: ChangeDetectionStrategy.OnPush, template: "<section class=\"babylon__webmap margin-main\">\n    <div class=\"container\">\n        <div class=\"row cs_gap_y_30\">\n            <div class=\"col-lg-6 cs_pr_110\">\n                <div class=\"intro_info no-align\">\n                    @if (pretitle) {\n                        <lib-babylon-dynamic-heading\n                            [tag]=\"tags?.pretitle || 'h3'\"\n                            cssClass=\"pretitle mb--10\"\n                            [color]=\"textColors?.pretitle\"\n                            [content]=\"pretitle\"\n                        ></lib-babylon-dynamic-heading>\n                    }\n                    @if (title) {\n                        <lib-babylon-dynamic-heading\n                            [tag]=\"tags?.title || 'h2'\"\n                            cssClass=\"title\"\n                            [color]=\"textColors?.title\"\n                            [content]=\"title\"\n                        ></lib-babylon-dynamic-heading>\n                    }\n                    @if (shouldGroupLinks && groupedLinks.length) {\n                        <ul\n                            class=\"cs_list cs_style_1 cs_mp_0 babylon__webmap-list--grouped\"\n                        >\n                            @for (group of groupedLinks; track group.trackKey) {\n                                <li\n                                    [class.babylon__webmap-group--has-children]=\"\n                                        group.children.length\n                                    \"\n                                >\n                                    <div class=\"babylon__webmap-group-title\">\n                                        @if (group.link?.url) {\n                                            <a\n                                                [attr.aria-label]=\"\n                                                    group.link?.label\n                                                \"\n                                                [href]=\"group.link?.url\"\n                                                [routerLink]=\"group.link?.url\"\n                                                (click)=\"linkClick($event)\"\n                                            >\n                                                <p class=\"text--small\">\n                                                    {{ group.label }}\n                                                </p>\n                                            </a>\n                                        } @else {\n                                            <p class=\"text--small\">\n                                                {{ group.label }}\n                                            </p>\n                                        }\n                                    </div>\n                                    @if (group.children.length) {\n                                        <ul class=\"babylon__webmap-sublist\">\n                                            @for (\n                                                child of group.children;\n                                                track child.url ||\n                                                    child.label ||\n                                                    $index\n                                            ) {\n                                                <li>\n                                                    <a\n                                                        [attr.aria-label]=\"\n                                                            child.label\n                                                        \"\n                                                        [href]=\"child.url\"\n                                                        [routerLink]=\"child.url\"\n                                                        (click)=\"\n                                                            linkClick($event)\n                                                        \"\n                                                    >\n                                                        <p class=\"text--small\">\n                                                            {{ child.label }}\n                                                        </p>\n                                                    </a>\n                                                </li>\n                                            }\n                                        </ul>\n                                    }\n                                </li>\n                            }\n                        </ul>\n                    } @else if (links?.length) {\n                        <ul class=\"cs_list cs_style_1 cs_mp_0\">\n                            @for (link of links; track $index) {\n                                @if (link) {\n                                    <li>\n                                        <a\n                                            [attr.aria-label]=\"link.label\"\n                                            [href]=\"link.url\"\n                                            [routerLink]=\"link.url\"\n                                            (click)=\"linkClick($event)\"\n                                        >\n                                            <p class=\"text--small\">\n                                                {{ link.label }}\n                                            </p>\n                                        </a>\n                                    </li>\n                                }\n                            }\n                        </ul>\n                    }\n                </div>\n            </div>\n            @if (image) {\n                <div class=\"col-lg-6\">\n                    <div\n                        class=\"cs_pr_1101 cs_image_layer cs_style_3 position-relative\"\n                    >\n                        <img\n                            [src]=\"\n                                image?.src ||\n                                'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'\n                            \"\n                            [alt]=\"image?.alt ?? image?.title ?? 'title'\"\n                            class=\"cs--radius\"\n                            loading=\"lazy\"\n                        />\n                    </div>\n                </div>\n            }\n        </div>\n    </div>\n</section>\n", styles: ["@charset \"UTF-8\";.cs_list.cs_style_1 li{position:relative;display:flex;align-items:flex-start;gap:10px;border-bottom:1px solid var(--cl_border-light);padding-bottom:10px}.cs_list.cs_style_1 li:not(:last-child){margin-bottom:15px}.cs_list.cs_style_1.babylon__webmap-list--grouped li{flex-direction:column;gap:8px}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-group-title{display:flex;align-items:flex-start;gap:10px}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-group-title:before{content:\"\\2022\";flex:none;line-height:1.7}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-group--has-children>.babylon__webmap-group-title .text--small{font-weight:700}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-sublist{display:flex;flex-direction:column;gap:8px;width:100%;padding-left:28px}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-sublist li{display:flex;flex-direction:row;gap:10px;border-bottom:0;padding-bottom:0}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-sublist li:not(:last-child){margin-bottom:0}.cs_list.cs_style_1.babylon__webmap-list--grouped .babylon__webmap-sublist li:before{content:\"\\2022\";flex:none;line-height:1.7}.cs_image_layer.cs_style_3.cs_type_1,.cs_image_layer.cs_style_4.cs_type_1{border-radius:250px 0}.cs_image_layer.cs_style_3.cs_type_1 img,.cs_image_layer.cs_style_4.cs_type_1 img{border-radius:inherit}.cs_image_layer.cs_style_3.cs_type_1:before,.cs_image_layer.cs_style_4.cs_type_1:before{border-radius:225px 0}.cs_list{width:100%}\n"] }]
        }], propDecorators: { pretitle: [{
                type: Input
            }], title: [{
                type: Input
            }], image: [{
                type: Input
            }], tags: [{
                type: Input
            }], textColors: [{
                type: Input
            }], links: [{
                type: Input
            }], groupByCategory: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 