var _initData, _closeNotify;
import { __classPrivateFieldGet } from "tslib";
import { Component, Inject } from '@angular/core';
import { MatSnackBar, MAT_SNACK_BAR_DATA } from '@angular/material/snack-bar';
import { ZuiFR } from '@material-zui/core';
import { ZUIToastDataService } from '../service/data.service';
export class ZUINotifyComponent {
    constructor(snackbar, data, zuiToastDataService) {
        this.snackbar = snackbar;
        this.data = data;
        this.zuiToastDataService = zuiToastDataService;
        _initData.set(this, () => {
            this.items.forEach(item => {
                var _a;
                if (!(item === null || item === void 0 ? void 0 : item.id))
                    item.id = ZuiFR.datatype.uuid();
                if (!(item === null || item === void 0 ? void 0 : item.duration))
                    item.duration = (_a = this.config) === null || _a === void 0 ? void 0 : _a.duration;
                if (item === null || item === void 0 ? void 0 : item.type) {
                    const { icon, color } = this.getStyle(item);
                    if (!(item === null || item === void 0 ? void 0 : item.icon))
                        item.icon = icon;
                    if (!(item === null || item === void 0 ? void 0 : item.iconColor))
                        item.iconColor = color;
                }
            });
        });
        _closeNotify.set(this, () => {
            const first = this.data.items[this.items.length - 1];
            this.closeNotify = setTimeout(() => {
                this.close(first.id);
            }, first.duration);
        });
        this.close = (id) => {
            this.data.items = this.items.filter(item => id !== item.id);
            this.zuiToastDataService.setNotifyItems(this.data.items);
            if (this.items.length > 0) {
                __classPrivateFieldGet(this, _closeNotify).call(this);
            }
            else {
                this.snackbar.dismiss();
            }
        };
        this.getStyle = (item) => {
            switch (item.type) {
                case 'primary':
                    return {
                        'background-color': '#007bff',
                        color: '#fff',
                        icon: 'priority_high',
                    };
                case 'success':
                    return {
                        'background-color': '#28a745',
                        color: '#fff',
                        icon: 'check_circle_outline',
                    };
                case 'error':
                    return {
                        'background-color': '#dc3545',
                        color: '#fff',
                        icon: 'error',
                    };
                case 'warning':
                    return {
                        'background-color': '#ffc107',
                        color: '#212529',
                        icon: 'warning',
                    };
                case 'info':
                    return {
                        'background-color': '#17a2b8',
                        color: '#fff',
                        icon: 'info',
                    };
                case 'normal':
                    return {
                        'background-color': '#fafafa',
                        color: '#000',
                        icon: 'notifications',
                    };
            }
        };
    }
    ngOnInit() {
        __classPrivateFieldGet(this, _initData).call(this);
        __classPrivateFieldGet(this, _closeNotify).call(this);
    }
    ngOnDestroy() {
        clearTimeout(this.closeNotify);
    }
    get items() {
        var _a;
        return (_a = this.data.items) !== null && _a !== void 0 ? _a : [];
    }
    get config() {
        return this.data.config;
    }
}
_initData = new WeakMap(), _closeNotify = new WeakMap();
ZUINotifyComponent.decorators = [
    { type: Component, args: [{
                selector: 'zui-notify',
                template: "<ng-container *ngFor=\"let item of items; let i = index\">\n  <div class=\"zui-toast-item\" [ngStyle]=\"getStyle(item)\">\n    <div class=\"d-flex\">\n      <div *ngIf=\"item?.icon\" class=\"d-flex align-items-center\">\n        <mat-icon *ngIf=\"item.icon\" class=\"mr-5\" [ngStyle]=\"{color: item.iconColor}\">{{ item.icon }}</mat-icon>\n      </div>\n      <div class=\"d-flex-1\">\n        <div *ngIf=\"item?.title\" class=\"font-weight-bold\">{{ item.title }}</div>\n        <div class=\"font-italic fs-15\">{{ item.message }}</div>\n      </div>\n      <mat-icon class=\"zui-pointer zui-toast-item-close fs-18 lh-24\" (click)=\"close(item.id)\">close</mat-icon>\n    </div>\n  </div>\n</ng-container>\n",
                styles: [".zui-toast-item{margin-bottom:10px;border-radius:4px;padding:10px;box-shadow:0 3px 5px -1px rgba(0,0,0,.2),0 6px 10px rgba(0,0,0,.1411764706),0 1px 18px rgba(0,0,0,.1215686275)}.zui-toast-item-close{color:#000;opacity:.5}.zui-toast-item-close:hover{opacity:1}.zui-toast-item-color{color:#000}::ng-deep .zui-toast.mat-snack-bar-container{background:transparent!important;box-shadow:none!important}"]
            },] }
];
ZUINotifyComponent.ctorParameters = () => [
    { type: MatSnackBar },
    { type: undefined, decorators: [{ type: Inject, args: [MAT_SNACK_BAR_DATA,] }] },
    { type: ZUIToastDataService }
];
//# sourceMappingURL=index.component.js.map