/*
 * Copyright 2015-2024 Ritense BV, the Netherlands.
 *
 * Licensed under EUPL, Version 1.2 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { Component, HostBinding, ViewChild, ViewContainerRef, } from '@angular/core';
import { map, of, switchMap } from 'rxjs';
import User20 from '@carbon/icons/es/user/20';
import { CurrentCarbonTheme } from '../../models';
import * as i0 from "@angular/core";
import * as i1 from "keycloak-angular";
import * as i2 from "@valtimo/config";
import * as i3 from "carbon-components-angular";
import * as i4 from "../../services/shell.service";
import * as i5 from "@angular/platform-browser";
import * as i6 from "../../services";
import * as i7 from "@angular/common";
import * as i8 from "@angular/router";
import * as i9 from "../paragraph/paragraph.component";
export class TopbarComponent {
    constructor(keyCloakService, configService, iconService, shellService, sanitizer, pageHeaderService, cdsThemeService) {
        this.keyCloakService = keyCloakService;
        this.configService = configService;
        this.iconService = iconService;
        this.shellService = shellService;
        this.sanitizer = sanitizer;
        this.pageHeaderService = pageHeaderService;
        this.cdsThemeService = cdsThemeService;
        this.headerClass = true;
        this.logoBase64$ = this.cdsThemeService.currentTheme$.pipe(map(currentTheme => {
            const base64logo = this.getBase64Logo(this.configService.config, currentTheme);
            return this.sanitizer.bypassSecurityTrustResourceUrl(`${base64logo.isSvg ? 'data:image/svg+xml;base64' : 'data:image/png;base64'}, ${base64logo.base64string}`);
        }));
        this.userFullName$ = of(this.keyCloakService.isLoggedIn()).pipe(switchMap(() => this.keyCloakService.loadUserProfile()), map(profile => `${profile.firstName} ${profile.lastName}`));
        this.applicationTitle = this.configService.config.applicationTitle;
        this.largeLogoMargin = this.configService.config.featureToggles?.largeLogoMargin;
        this.sideBarExpanded$ = this.shellService.sideBarExpanded$;
        this.largeScreen$ = this.shellService.largeScreen$;
        this.panelExpanded$ = this.shellService.panelExpanded$;
        this.collapsibleWidescreenMenu$ = this.shellService.collapsibleWidescreenMenu$;
        this.showUserNameInTopBar$ = this.pageHeaderService.showUserNameInTopBar$;
    }
    ngOnInit() {
        this.iconService.registerAll([User20]);
    }
    ngAfterViewInit() {
        this.pageHeaderService.setHeaderViewContainerRef(this._headerVcr);
    }
    toggleSideBar() {
        this.shellService.toggleSideBar();
    }
    setPanelExpanded(expanded) {
        this.shellService.setPanelExpanded(expanded);
    }
    mouseEnter() {
        this.shellService.setMouseOnTopBar(true);
    }
    mouseLeave() {
        this.shellService.setMouseOnTopBar(false);
    }
    getBase64Logo(config, currentTheme) {
        const { logoSvgBase64, logoPngBase64, darkModeLogoSvgBase64, darkModeLogoPngBase64 } = this.configService.config;
        let base64string;
        let isSvg = true;
        switch (currentTheme) {
            case CurrentCarbonTheme.G10:
                if (logoSvgBase64) {
                    base64string = logoSvgBase64;
                }
                else if (logoPngBase64) {
                    base64string = logoPngBase64;
                    isSvg = false;
                }
                else if (darkModeLogoSvgBase64) {
                    base64string = darkModeLogoSvgBase64;
                }
                else {
                    base64string = darkModeLogoPngBase64;
                    isSvg = false;
                }
                break;
            case CurrentCarbonTheme.G90:
                if (darkModeLogoSvgBase64) {
                    base64string = darkModeLogoSvgBase64;
                }
                else if (darkModeLogoPngBase64) {
                    base64string = darkModeLogoPngBase64;
                    isSvg = false;
                }
                else if (logoSvgBase64) {
                    base64string = logoSvgBase64;
                }
                else {
                    base64string = logoPngBase64;
                    isSvg = false;
                }
                break;
        }
        return {
            isSvg,
            base64string,
        };
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TopbarComponent, deps: [{ token: i1.KeycloakService }, { token: i2.ConfigService }, { token: i3.IconService }, { token: i4.ShellService }, { token: i5.DomSanitizer }, { token: i6.PageHeaderService }, { token: i6.CdsThemeService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: TopbarComponent, selector: "valtimo-topbar", host: { properties: { "class.cds--header": "this.headerClass" } }, viewQueries: [{ propertyName: "_headerVcr", first: true, predicate: ["headerVcr"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<cds-header [useRouter]=\"false\" (mouseenter)=\"mouseEnter()\" (mouseleave)=\"mouseLeave()\">\n  <a\n    *ngIf=\"logoBase64$ | async as logoBase64\"\n    class=\"logo-link\"\n    [ngClass]=\"{'logo-link--large-margin': largeLogoMargin}\"\n    [routerLink]=\"['/']\"\n    [title]=\"applicationTitle\"\n  >\n    <img [src]=\"logoBase64\" class=\"logo-image\" />\n  </a>\n  <cds-hamburger\n    *ngIf=\"(largeScreen$ | async) === false || (collapsibleWidescreenMenu$ | async)\"\n    [active]=\"sideBarExpanded$ | async\"\n    (selected)=\"toggleSideBar()\"\n  ></cds-hamburger>\n  <cds-header-global>\n    <ng-container #headerVcr></ng-container>\n\n    <ng-container *ngTemplateOutlet=\"userFullName\"></ng-container>\n\n    <cds-header-action\n      title=\"action\"\n      [active]=\"panelExpanded$ | async\"\n      (activeChange)=\"setPanelExpanded($event)\"\n    >\n      <svg cdsIcon=\"user\" size=\"20\"></svg>\n    </cds-header-action>\n  </cds-header-global>\n</cds-header>\n\n<ng-template #userFullName>\n  <div\n    class=\"user-full-name\"\n    *ngIf=\"(showUserNameInTopBar$ | async) && {userFullName: userFullName$ | async} as obs\"\n  >\n    <v-paragraph [loading]=\"!obs.userFullName\">{{ obs.userFullName }}</v-paragraph>\n  </div>\n</ng-template>\n", styles: [".user-icon{font-size:30px}.be-toggle-right-sidebar{display:flex}.user-full-name{display:flex;height:100%;align-items:center;justify-content:center;margin-inline-end:var(--v-top-bar-user-name-spacing);flex-shrink:0}::ng-deep .cds--header__name{display:none!important}.logo-link{height:100%;padding-left:16px;padding-top:8px;padding-bottom:8px}.logo-link--large-margin{padding-top:16px;padding-bottom:16px}.logo-image{height:100%;object-fit:contain}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"], dependencies: [{ kind: "directive", type: i7.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i7.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i7.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i8.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "component", type: i9.ParagraphComponent, selector: "v-paragraph", inputs: ["center", "fullWidth", "margin", "italic", "loading", "dataTestId"] }, { kind: "component", type: i3.Header, selector: "cds-header, ibm-header", inputs: ["skipTo", "name", "brand", "href", "route", "routeExtras", "useRouter"], outputs: ["navigation"] }, { kind: "component", type: i3.HeaderGlobal, selector: "cds-header-global, ibm-header-global" }, { kind: "component", type: i3.HeaderAction, selector: "cds-header-action, ibm-header-action", inputs: ["description", "ariaLabel", "active"], outputs: ["activeChange", "selected"] }, { kind: "component", type: i3.Hamburger, selector: "cds-hamburger, ibm-hamburger", inputs: ["active", "activeTitle", "inactiveTitle"], outputs: ["selected"] }, { kind: "directive", type: i3.IconDirective, selector: "[cdsIcon], [ibmIcon]", inputs: ["ibmIcon", "cdsIcon", "size", "title", "ariaLabel", "ariaLabelledBy", "ariaHidden", "isFocusable"] }, { kind: "pipe", type: i7.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: TopbarComponent, decorators: [{
            type: Component,
            args: [{ selector: 'valtimo-topbar', template: "<!--\n  ~ Copyright 2015-2024 Ritense BV, the Netherlands.\n  ~\n  ~ Licensed under EUPL, Version 1.2 (the \"License\");\n  ~ you may not use this file except in compliance with the License.\n  ~ You may obtain a copy of the License at\n  ~\n  ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n  ~\n  ~ Unless required by applicable law or agreed to in writing, software\n  ~ distributed under the License is distributed on an \"AS IS\" basis,\n  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  ~ See the License for the specific language governing permissions and\n  ~ limitations under the License.\n  -->\n\n<cds-header [useRouter]=\"false\" (mouseenter)=\"mouseEnter()\" (mouseleave)=\"mouseLeave()\">\n  <a\n    *ngIf=\"logoBase64$ | async as logoBase64\"\n    class=\"logo-link\"\n    [ngClass]=\"{'logo-link--large-margin': largeLogoMargin}\"\n    [routerLink]=\"['/']\"\n    [title]=\"applicationTitle\"\n  >\n    <img [src]=\"logoBase64\" class=\"logo-image\" />\n  </a>\n  <cds-hamburger\n    *ngIf=\"(largeScreen$ | async) === false || (collapsibleWidescreenMenu$ | async)\"\n    [active]=\"sideBarExpanded$ | async\"\n    (selected)=\"toggleSideBar()\"\n  ></cds-hamburger>\n  <cds-header-global>\n    <ng-container #headerVcr></ng-container>\n\n    <ng-container *ngTemplateOutlet=\"userFullName\"></ng-container>\n\n    <cds-header-action\n      title=\"action\"\n      [active]=\"panelExpanded$ | async\"\n      (activeChange)=\"setPanelExpanded($event)\"\n    >\n      <svg cdsIcon=\"user\" size=\"20\"></svg>\n    </cds-header-action>\n  </cds-header-global>\n</cds-header>\n\n<ng-template #userFullName>\n  <div\n    class=\"user-full-name\"\n    *ngIf=\"(showUserNameInTopBar$ | async) && {userFullName: userFullName$ | async} as obs\"\n  >\n    <v-paragraph [loading]=\"!obs.userFullName\">{{ obs.userFullName }}</v-paragraph>\n  </div>\n</ng-template>\n", styles: [".user-icon{font-size:30px}.be-toggle-right-sidebar{display:flex}.user-full-name{display:flex;height:100%;align-items:center;justify-content:center;margin-inline-end:var(--v-top-bar-user-name-spacing);flex-shrink:0}::ng-deep .cds--header__name{display:none!important}.logo-link{height:100%;padding-left:16px;padding-top:8px;padding-bottom:8px}.logo-link--large-margin{padding-top:16px;padding-bottom:16px}.logo-image{height:100%;object-fit:contain}\n/*!\n * Copyright 2015-2024 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n"] }]
        }], ctorParameters: () => [{ type: i1.KeycloakService }, { type: i2.ConfigService }, { type: i3.IconService }, { type: i4.ShellService }, { type: i5.DomSanitizer }, { type: i6.PageHeaderService }, { type: i6.CdsThemeService }], propDecorators: { headerClass: [{
                type: HostBinding,
                args: ['class.cds--header']
            }], _headerVcr: [{
                type: ViewChild,
                args: ['headerVcr', { static: true, read: ViewContainerRef }]
            }] } });
//# sourceMappingURL=data:application/json;base64, 