/**
 * @packageDocumentation
 * @module account-menu
 */
import { setTheme as setChartTheme } from '@alauda/chart';
import { AlaudaMonacoProviderService } from '@alauda/code-editor';
import { ThemeService } from '@alauda/ui';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Router } from '@angular/router';
import { combineLatest, finalize, map, timeout } from 'rxjs';
import { AuthorizationStateService } from '../../../../authorization/public-api';
import { TranslateService } from '../../../../translate/public-api';
import * as i0 from "@angular/core";
import * as i1 from "../../../../authorization/public-api";
import * as i2 from "../../../../translate/public-api";
import * as i3 from "@angular/router";
import * as i4 from "@alauda/ui";
import * as i5 from "@alauda/code-editor";
function AccountMenuComponent_aui_submenu_13_aui_icon_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "aui-icon", 19);
} }
function AccountMenuComponent_aui_submenu_13_aui_icon_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "aui-icon", 20);
} }
function AccountMenuComponent_aui_submenu_13_aui_icon_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "aui-icon", 21);
} }
function AccountMenuComponent_aui_submenu_13_Template(rf, ctx) { if (rf & 1) {
    const _r6 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "aui-submenu")(1, "div");
    i0.ɵɵtemplate(2, AccountMenuComponent_aui_submenu_13_aui_icon_2_Template, 1, 0, "aui-icon", 11);
    i0.ɵɵtemplate(3, AccountMenuComponent_aui_submenu_13_aui_icon_3_Template, 1, 0, "aui-icon", 12);
    i0.ɵɵtemplate(4, AccountMenuComponent_aui_submenu_13_aui_icon_4_Template, 1, 0, "aui-icon", 13);
    i0.ɵɵelementStart(5, "span");
    i0.ɵɵtext(6);
    i0.ɵɵpipe(7, "translate");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(8, "aui-menu-item", 14);
    i0.ɵɵlistener("click", function AccountMenuComponent_aui_submenu_13_Template_aui_menu_item_click_8_listener() { i0.ɵɵrestoreView(_r6); const ctx_r5 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r5.setThemeMode("system")); });
    i0.ɵɵelementStart(9, "aui-radio-group", 15)(10, "aui-radio", 16);
    i0.ɵɵtext(11);
    i0.ɵɵpipe(12, "translate");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(13, "aui-menu-item", 14);
    i0.ɵɵlistener("click", function AccountMenuComponent_aui_submenu_13_Template_aui_menu_item_click_13_listener() { i0.ɵɵrestoreView(_r6); const ctx_r7 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r7.setThemeMode("light")); });
    i0.ɵɵelementStart(14, "aui-radio-group", 15)(15, "aui-radio", 17);
    i0.ɵɵtext(16);
    i0.ɵɵpipe(17, "translate");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementStart(18, "aui-menu-item", 14);
    i0.ɵɵlistener("click", function AccountMenuComponent_aui_submenu_13_Template_aui_menu_item_click_18_listener() { i0.ɵɵrestoreView(_r6); const ctx_r8 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r8.setThemeMode("dark")); });
    i0.ɵɵelementStart(19, "aui-radio-group", 15)(20, "aui-radio", 18);
    i0.ɵɵtext(21);
    i0.ɵɵpipe(22, "translate");
    i0.ɵɵelementEnd()()()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", ctx_r1.themeMode === "system");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r1.themeMode === "light");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r1.themeMode === "dark");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(7, 10, "appearance"));
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("value", ctx_r1.themeMode);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(12, 12, "follow_the_system"), " ");
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("value", ctx_r1.themeMode);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(17, 14, "light_theme"), " ");
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("value", ctx_r1.themeMode);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(22, 16, "dark_theme"), " ");
} }
const LOCAL_THEME_KEY = 'theme-mode';
export class AccountMenuComponent {
    constructor(auth, translate, router, theme, monacoService) {
        this.auth = auth;
        this.translate = translate;
        this.router = router;
        this.theme = theme;
        this.monacoService = monacoService;
        this.platformPath = '/console-platform';
        this.displayName$ = this.auth
            .getTokenPayload()
            .pipe(map(account => account.email || account.name));
        this.initThemeMode();
        this.theme.currentTheme$.subscribe(theme => {
            setChartTheme(theme);
        });
        combineLatest([
            this.theme.currentTheme$,
            this.monacoService.themeMode$,
            // wait monaco to be loaded first
            this.monacoService.initMonaco(),
        ]).subscribe(([theme, mode]) => {
            this.monacoService.changeThemeMode(mode, theme);
        });
    }
    get icon() {
        return `basic:${this.translate.locale === 'zh' ? 'switch_to_english' : 'switch_to_chinese'}`;
    }
    logout() {
        // 审计记录登出
        this.auth
            .logoutAudit()
            .pipe(timeout(1000), finalize(() => {
            this.auth.logout();
        }))
            .subscribe();
    }
    changeLanguage() {
        this.translate.toggleLocale();
    }
    navigateToLink(href) {
        if (this.platformPath) {
            window.open(`${this.platformPath}${href}`, '_parent');
        }
        else {
            this.router.navigate([href]);
        }
    }
    setThemeMode(v) {
        localStorage.setItem(LOCAL_THEME_KEY, v);
        this.themeMode = v;
        this.theme.setThemeMode(v);
    }
    initThemeMode() {
        let localTheme = localStorage.getItem(LOCAL_THEME_KEY);
        if (!localTheme) {
            localTheme = 'system';
            localStorage.setItem(LOCAL_THEME_KEY, localTheme);
        }
        this.themeMode = localTheme;
        if (['system', 'light', 'dark'].includes(localTheme)) {
            this.theme.setThemeMode(localTheme);
        }
    }
}
AccountMenuComponent.ɵfac = function AccountMenuComponent_Factory(t) { return new (t || AccountMenuComponent)(i0.ɵɵdirectiveInject(i1.AuthorizationStateService), i0.ɵɵdirectiveInject(i2.TranslateService), i0.ɵɵdirectiveInject(i3.Router), i0.ɵɵdirectiveInject(i4.ThemeService), i0.ɵɵdirectiveInject(i5.AlaudaMonacoProviderService)); };
AccountMenuComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: AccountMenuComponent, selectors: [["acl-account-menu"]], inputs: { platformPath: "platformPath" }, decls: 24, vars: 17, consts: [[1, "account-menu", 3, "auiDropdown", "auiDropdownClass"], ["src", "header/portrait.svg", "alt", "portrait", 1, "account-menu__icon"], [1, "account-menu__display"], ["icon", "angle_down", 1, "account-menu__pointer"], ["menu", ""], [3, "click"], ["icon", "basic:user_s"], [4, "ngIf"], [3, "icon"], [3, "divide", "click"], ["icon", "basic:sign_out_s"], ["icon", "computer", 4, "ngIf"], ["icon", "sun", 4, "ngIf"], ["icon", "moon", 4, "ngIf"], [1, "menu-item--with-radio", 3, "click"], [3, "value"], ["value", "system"], ["value", "light"], ["value", "dark"], ["icon", "computer"], ["icon", "sun"], ["icon", "moon"]], template: function AccountMenuComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵelementStart(0, "div", 0);
        i0.ɵɵelement(1, "img", 1);
        i0.ɵɵelementStart(2, "div", 2);
        i0.ɵɵtext(3);
        i0.ɵɵpipe(4, "async");
        i0.ɵɵelementEnd();
        i0.ɵɵelement(5, "aui-icon", 3);
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(6, "aui-menu", null, 4)(8, "aui-menu-item", 5);
        i0.ɵɵlistener("click", function AccountMenuComponent_Template_aui_menu_item_click_8_listener() { return ctx.navigateToLink("/personal-info"); });
        i0.ɵɵelement(9, "aui-icon", 6);
        i0.ɵɵelementStart(10, "span");
        i0.ɵɵtext(11);
        i0.ɵɵpipe(12, "translate");
        i0.ɵɵelementEnd()();
        i0.ɵɵtemplate(13, AccountMenuComponent_aui_submenu_13_Template, 23, 18, "aui-submenu", 7);
        i0.ɵɵelementStart(14, "aui-menu-item", 5);
        i0.ɵɵlistener("click", function AccountMenuComponent_Template_aui_menu_item_click_14_listener() { return ctx.changeLanguage(); });
        i0.ɵɵelement(15, "aui-icon", 8);
        i0.ɵɵelementStart(16, "span");
        i0.ɵɵtext(17);
        i0.ɵɵpipe(18, "translate");
        i0.ɵɵelementEnd()();
        i0.ɵɵelementStart(19, "aui-menu-item", 9);
        i0.ɵɵlistener("click", function AccountMenuComponent_Template_aui_menu_item_click_19_listener() { return ctx.logout(); });
        i0.ɵɵelement(20, "aui-icon", 10);
        i0.ɵɵelementStart(21, "span");
        i0.ɵɵtext(22);
        i0.ɵɵpipe(23, "translate");
        i0.ɵɵelementEnd()()();
    } if (rf & 2) {
        const _r0 = i0.ɵɵreference(7);
        i0.ɵɵproperty("auiDropdown", _r0)("auiDropdownClass", "acl-page-header__tooltip");
        i0.ɵɵadvance(3);
        i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(4, 9, ctx.displayName$));
        i0.ɵɵadvance(8);
        i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(12, 11, "my_profile"));
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("ngIf", ctx.themeMode !== "custom");
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("icon", ctx.icon);
        i0.ɵɵadvance(2);
        i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(18, 13, "next_locale"));
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("divide", true);
        i0.ɵɵadvance(3);
        i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(23, 15, "logout"));
    } }, styles: ["[_nghost-%COMP%]{display:block}.account-menu[_ngcontent-%COMP%]{display:flex;align-items:center;padding:0 8px 0 24px;height:32px;border-radius:2px;color:var(--acl-page-header-text-color);cursor:pointer;position:relative}.account-menu__icon[_ngcontent-%COMP%]{position:absolute;left:-16px;top:0;height:32px;width:32px;border-radius:50%;margin-right:8px}.account-menu[_ngcontent-%COMP%]:hover, .account-menu.isActive[_ngcontent-%COMP%]{color:#fff;background-color:rgb(var(--aui-color-primary))}.account-menu[_ngcontent-%COMP%]:hover   .account-menu__icon[_ngcontent-%COMP%], .account-menu.isActive[_ngcontent-%COMP%]   .account-menu__icon[_ngcontent-%COMP%]{border:2px solid rgb(var(--aui-color-primary));height:36px;width:36px;top:-2px;left:-18px}.account-menu__pointer[_ngcontent-%COMP%]{font-size:12px;margin-left:2px}.account-menu__display[_ngcontent-%COMP%]{max-width:175px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}  .acl-page-header__tooltip{min-width:155px}  .acl-page-header__tooltip .aui-menu-item:hover,   .acl-page-header__tooltip .aui-submenu:hover{color:rgb(var(--aui-color-primary))}  .menu-item--with-radio .aui-radio{line-height:var(--aui-inline-height-s)}  .menu-item--with-radio:hover .aui-radio__content{color:rgb(var(--aui-color-primary))}"], changeDetection: 0 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(AccountMenuComponent, [{
        type: Component,
        args: [{ selector: 'acl-account-menu', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div\n  class=\"account-menu\"\n  [auiDropdown]=\"menu\"\n  [auiDropdownClass]=\"'acl-page-header__tooltip'\"\n>\n  <img\n    src=\"header/portrait.svg\"\n    class=\"account-menu__icon\"\n    alt=\"portrait\"\n  />\n  <div class=\"account-menu__display\">{{ displayName$ | async }}</div>\n  <aui-icon\n    class=\"account-menu__pointer\"\n    icon=\"angle_down\"\n  ></aui-icon>\n</div>\n\n<aui-menu #menu>\n  <aui-menu-item (click)=\"navigateToLink('/personal-info')\">\n    <aui-icon icon=\"basic:user_s\"></aui-icon>\n    <span>{{ 'my_profile' | translate }}</span>\n  </aui-menu-item>\n\n  <aui-submenu *ngIf=\"themeMode !== 'custom'\">\n    <div>\n      <aui-icon\n        *ngIf=\"themeMode === 'system'\"\n        icon=\"computer\"\n      ></aui-icon>\n      <aui-icon\n        *ngIf=\"themeMode === 'light'\"\n        icon=\"sun\"\n      ></aui-icon>\n      <aui-icon\n        *ngIf=\"themeMode === 'dark'\"\n        icon=\"moon\"\n      ></aui-icon>\n      <span>{{ 'appearance' | translate }}</span>\n    </div>\n    <aui-menu-item\n      class=\"menu-item--with-radio\"\n      (click)=\"setThemeMode('system')\"\n    >\n      <aui-radio-group [value]=\"themeMode\">\n        <aui-radio value=\"system\">\n          {{ 'follow_the_system' | translate }}\n        </aui-radio>\n      </aui-radio-group>\n    </aui-menu-item>\n    <aui-menu-item\n      class=\"menu-item--with-radio\"\n      (click)=\"setThemeMode('light')\"\n    >\n      <aui-radio-group [value]=\"themeMode\">\n        <aui-radio value=\"light\">\n          {{ 'light_theme' | translate }}\n        </aui-radio>\n      </aui-radio-group>\n    </aui-menu-item>\n    <aui-menu-item\n      class=\"menu-item--with-radio\"\n      (click)=\"setThemeMode('dark')\"\n    >\n      <aui-radio-group [value]=\"themeMode\">\n        <aui-radio value=\"dark\">\n          {{ 'dark_theme' | translate }}\n        </aui-radio>\n      </aui-radio-group>\n    </aui-menu-item>\n  </aui-submenu>\n\n  <aui-menu-item (click)=\"changeLanguage()\">\n    <aui-icon [icon]=\"icon\"></aui-icon>\n    <span>{{ 'next_locale' | translate }}</span>\n  </aui-menu-item>\n\n  <aui-menu-item\n    [divide]=\"true\"\n    (click)=\"logout()\"\n  >\n    <aui-icon icon=\"basic:sign_out_s\"></aui-icon>\n    <span>{{ 'logout' | translate }}</span>\n  </aui-menu-item>\n</aui-menu>\n", styles: [":host{display:block}.account-menu{display:flex;align-items:center;padding:0 8px 0 24px;height:32px;border-radius:2px;color:var(--acl-page-header-text-color);cursor:pointer;position:relative}.account-menu__icon{position:absolute;left:-16px;top:0;height:32px;width:32px;border-radius:50%;margin-right:8px}.account-menu:hover,.account-menu.isActive{color:#fff;background-color:rgb(var(--aui-color-primary))}.account-menu:hover .account-menu__icon,.account-menu.isActive .account-menu__icon{border:2px solid rgb(var(--aui-color-primary));height:36px;width:36px;top:-2px;left:-18px}.account-menu__pointer{font-size:12px;margin-left:2px}.account-menu__display{max-width:175px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}::ng-deep .acl-page-header__tooltip{min-width:155px}::ng-deep .acl-page-header__tooltip .aui-menu-item:hover,::ng-deep .acl-page-header__tooltip .aui-submenu:hover{color:rgb(var(--aui-color-primary))}::ng-deep .menu-item--with-radio .aui-radio{line-height:var(--aui-inline-height-s)}::ng-deep .menu-item--with-radio:hover .aui-radio__content{color:rgb(var(--aui-color-primary))}\n"] }]
    }], function () { return [{ type: i1.AuthorizationStateService }, { type: i2.TranslateService }, { type: i3.Router }, { type: i4.ThemeService }, { type: i5.AlaudaMonacoProviderService }]; }, { platformPath: [{
            type: Input
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 