import { ThemeService } from '@alauda/ui';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, HostListener, } from '@angular/core';
import { map } from 'rxjs';
import { publishRef } from '../../../../core/public-api';
import { NotifyService } from '../notify.service';
import { NOTIFY_PUSH_TYPE } from '../utils';
import * as i0 from "@angular/core";
import * as i1 from "../notify.service";
import * as i2 from "@alauda/ui";
function HeaderNotifyComponent_div_3_Template(rf, ctx) { if (rf & 1) {
    const _r3 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 5)(1, "span", 6);
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "translate");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "div", 7)(5, "span", 8);
    i0.ɵɵtext(6);
    i0.ɵɵpipe(7, "translate");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(8, "aui-switch", 9);
    i0.ɵɵlistener("ngModelChange", function HeaderNotifyComponent_div_3_Template_aui_switch_ngModelChange_8_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r2 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r2.switchPush($event)); })("ngModelChange", function HeaderNotifyComponent_div_3_Template_aui_switch_ngModelChange_8_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.push = $event); });
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(3, 3, "message"), "");
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(7, 5, "notify_push"), "");
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngModel", ctx_r0.push);
} }
function HeaderNotifyComponent_ng_container_4_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelement(1, "acl-notification-list", 12);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r5 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("list", ctx_r5.list);
} }
function HeaderNotifyComponent_ng_container_4_ng_template_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 13);
    i0.ɵɵelement(1, "img", 14);
    i0.ɵɵpipe(2, "async");
    i0.ɵɵelementStart(3, "span", 15);
    i0.ɵɵtext(4);
    i0.ɵɵpipe(5, "translate");
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r7 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("src", i0.ɵɵpipeBind1(2, 2, ctx_r7.noDataSrc$), i0.ɵɵsanitizeUrl);
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(5, 4, "no_message"), " ");
} }
function HeaderNotifyComponent_ng_container_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, HeaderNotifyComponent_ng_container_4_ng_container_1_Template, 2, 1, "ng-container", 10);
    i0.ɵɵtemplate(2, HeaderNotifyComponent_ng_container_4_ng_template_2_Template, 6, 6, "ng-template", null, 11, i0.ɵɵtemplateRefExtractor);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const _r6 = i0.ɵɵreference(3);
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r1.list == null ? null : ctx_r1.list.length)("ngIfElse", _r6);
} }
export class HeaderNotifyComponent {
    constructor(notifyService, theme, cdr) {
        this.notifyService = notifyService;
        this.theme = theme;
        this.cdr = cdr;
        this.active = false;
        this.visible = false;
        this.noDataSrc$ = this.theme.currentTheme$.pipe(map(theme => `images/${theme}/no-message.svg`), publishRef());
    }
    beforeUnloadHandle() {
        this.notifyService.destroy();
    }
    ngOnInit() {
        this.notifyService.watchNotify();
        this.notifyService.userName$.subscribe(() => {
            this.watchMessageConfigMap();
        });
        this.getNotifyList();
    }
    watchMessageConfigMap() {
        this.pushEnabled = true;
        this.push =
            '' + this.notifyService.getCacheLocalValue(NOTIFY_PUSH_TYPE) === 'true';
        this.cdr.markForCheck();
    }
    getNotifyList() {
        this.notifyService.getNotifyList().subscribe((res) => {
            this.list = res;
            this.cdr.markForCheck();
        });
    }
    openNotify() {
        this.active = true;
    }
    closeNotify() {
        this.active = false;
    }
    switchPush(enabled) {
        this.notifyService.addCacheLocalValue(NOTIFY_PUSH_TYPE, enabled);
    }
    ngOnDestroy() {
        this.notifyService.destroy();
    }
}
HeaderNotifyComponent.ɵfac = function HeaderNotifyComponent_Factory(t) { return new (t || HeaderNotifyComponent)(i0.ɵɵdirectiveInject(i1.NotifyService), i0.ɵɵdirectiveInject(i2.ThemeService), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); };
HeaderNotifyComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: HeaderNotifyComponent, selectors: [["acl-header-notify"]], hostBindings: function HeaderNotifyComponent_HostBindings(rf, ctx) { if (rf & 1) {
        i0.ɵɵlistener("beforeunload", function HeaderNotifyComponent_beforeunload_HostBindingHandler() { return ctx.beforeUnloadHandle(); }, false, i0.ɵɵresolveWindow);
    } }, decls: 5, vars: 5, consts: [[1, "notify", 3, "click"], ["icon", "basic:global_message", 1, "notify__icon"], ["drawerClass", "header-notify", "offsetY", "64px", 3, "visible", "width", "hideOnClickOutside", "close"], ["class", "header", 4, "auiDrawerHeader"], [4, "auiDrawerContent"], [1, "header"], [1, "text"], [1, "header_push"], [1, "label"], ["name", "push", 3, "ngModel", "ngModelChange"], [4, "ngIf", "ngIfElse"], ["elseTemplate", ""], [3, "list"], [1, "noData"], [3, "src"], [1, "noData_text"]], template: function HeaderNotifyComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵelementStart(0, "div", 0);
        i0.ɵɵlistener("click", function HeaderNotifyComponent_Template_div_click_0_listener() { return ctx.active ? ctx.closeNotify() : ctx.openNotify(); });
        i0.ɵɵelement(1, "aui-icon", 1);
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(2, "aui-drawer", 2);
        i0.ɵɵlistener("close", function HeaderNotifyComponent_Template_aui_drawer_close_2_listener() { return ctx.closeNotify(); });
        i0.ɵɵtemplate(3, HeaderNotifyComponent_div_3_Template, 9, 7, "div", 3);
        i0.ɵɵtemplate(4, HeaderNotifyComponent_ng_container_4_Template, 4, 2, "ng-container", 4);
        i0.ɵɵelementEnd();
    } if (rf & 2) {
        i0.ɵɵclassProp("active", ctx.active);
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("visible", ctx.active)("width", 400)("hideOnClickOutside", true);
    } }, styles: [".notify[_ngcontent-%COMP%]{display:flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:2px;color:var(--acl-page-header-text-color);cursor:pointer}.notify[_ngcontent-%COMP%]:hover, .active[_ngcontent-%COMP%]{color:#fff;background-color:rgb(var(--aui-color-primary))}.header[_ngcontent-%COMP%]{display:flex;justify-content:space-between}.header[_ngcontent-%COMP%]   .text[_ngcontent-%COMP%]{color:rgb(var(--aui-color-n-2));font-weight:500;font-size:var(--aui-font-size-l)}.header_push[_ngcontent-%COMP%]{display:flex;font-size:var(--aui-font-size-s);font-weight:400;color:rgb(var(--aui-color-n-1));align-items:center}.header_push[_ngcontent-%COMP%]   .label[_ngcontent-%COMP%]{margin-right:8px}  .aui-drawer.header-notify .noData{display:flex;flex-direction:column;justify-content:center;align-items:center;width:100%;height:100%}  .aui-drawer.header-notify .noData img{width:160px}  .aui-drawer.header-notify .noData_text{color:rgb(var(--aui-color-n-1));font-weight:400;margin-top:16px;font-size:var(--aui-font-size-xl)}  aui-notification .platform-class{border-left:4px solid #1cb6cc}  aui-notification .platform-class .aui-notification__icon{color:#1cb6cc}"], changeDetection: 0 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(HeaderNotifyComponent, [{
        type: Component,
        args: [{ selector: 'acl-header-notify', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div\n  class=\"notify\"\n  [class.active]=\"active\"\n  (click)=\"active ? closeNotify() : openNotify()\"\n>\n  <aui-icon\n    icon=\"basic:global_message\"\n    class=\"notify__icon\"\n  ></aui-icon>\n</div>\n\n<aui-drawer\n  drawerClass=\"header-notify\"\n  offsetY=\"64px\"\n  [visible]=\"active\"\n  (close)=\"closeNotify()\"\n  [width]=\"400\"\n  [hideOnClickOutside]=\"true\"\n>\n  <div\n    *auiDrawerHeader\n    class=\"header\"\n  >\n    <span class=\"text\"> {{ 'message' | translate }}</span>\n    <!-- TODO: \u8FD9\u4E2A\u7248\u672C\u6CA1\u6709\u81EA\u52A8\u53D1\u9001\u7684\u6D88\u606F\uFF0C\u7528\u6237\u624B\u518C\u6CA1\u6709\u529E\u6CD5\u63CF\u8FF0\u8FD9\u90E8\u5206\u529F\u80FD, \u4E0D\u5224\u65AD config map \u503C -->\n    <!-- <div class=\"header_push\" *ngIf=\"pushEnabled\"> -->\n    <div class=\"header_push\">\n      <span class=\"label\"> {{ 'notify_push' | translate }}</span>\n      <aui-switch\n        name=\"push\"\n        (ngModelChange)=\"switchPush($event)\"\n        [(ngModel)]=\"push\"\n      >\n      </aui-switch>\n    </div>\n  </div>\n  <ng-container *auiDrawerContent>\n    <ng-container *ngIf=\"list?.length; else elseTemplate\">\n      <acl-notification-list [list]=\"list\"></acl-notification-list>\n    </ng-container>\n    <ng-template #elseTemplate>\n      <div class=\"noData\">\n        <img [src]=\"noDataSrc$ | async\" />\n        <span class=\"noData_text\">\n          {{ 'no_message' | translate }}\n        </span>\n      </div>\n    </ng-template>\n  </ng-container>\n</aui-drawer>\n", styles: [".notify{display:flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:2px;color:var(--acl-page-header-text-color);cursor:pointer}.notify:hover,.active{color:#fff;background-color:rgb(var(--aui-color-primary))}.header{display:flex;justify-content:space-between}.header .text{color:rgb(var(--aui-color-n-2));font-weight:500;font-size:var(--aui-font-size-l)}.header_push{display:flex;font-size:var(--aui-font-size-s);font-weight:400;color:rgb(var(--aui-color-n-1));align-items:center}.header_push .label{margin-right:8px}::ng-deep .aui-drawer.header-notify .noData{display:flex;flex-direction:column;justify-content:center;align-items:center;width:100%;height:100%}::ng-deep .aui-drawer.header-notify .noData img{width:160px}::ng-deep .aui-drawer.header-notify .noData_text{color:rgb(var(--aui-color-n-1));font-weight:400;margin-top:16px;font-size:var(--aui-font-size-xl)}::ng-deep aui-notification .platform-class{border-left:4px solid #1cb6cc}::ng-deep aui-notification .platform-class .aui-notification__icon{color:#1cb6cc}\n"] }]
    }], function () { return [{ type: i1.NotifyService }, { type: i2.ThemeService }, { type: i0.ChangeDetectorRef }]; }, { beforeUnloadHandle: [{
            type: HostListener,
            args: ['window:beforeunload']
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 