var _showNotify, _addConfig;
import { __classPrivateFieldGet } from "tslib";
import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ZUINotifyComponent } from '../notify';
import { ZUIToastDataService } from './data.service';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/snack-bar";
import * as i2 from "./data.service";
export class ZUIToastService {
    constructor(snackBar, zuiToastDataService) {
        this.snackBar = snackBar;
        this.zuiToastDataService = zuiToastDataService;
        _showNotify.set(this, (notifyItems, config = {}) => {
            var _a;
            this.zuiToastDataService.setNotifyItems([...notifyItems, ...this.notifyItems]);
            const onlyConfig = Object.assign(Object.assign({}, this.config), config);
            const duration = (_a = config.duration) !== null && _a !== void 0 ? _a : this.config.duration;
            const data = { config: Object.assign(Object.assign({}, onlyConfig), { duration }), items: this.notifyItems };
            config = Object.assign(Object.assign({}, onlyConfig), { duration: 0, data });
            return this.snackBar.openFromComponent(ZUINotifyComponent, config);
        });
        _addConfig.set(this, (notifyItems, type) => {
            const items = Array.isArray(notifyItems) ? notifyItems : [notifyItems];
            return items.map(item => {
                if (!item.type)
                    item.type = type !== null && type !== void 0 ? type : 'normal';
                return item;
            });
        });
        this.open = (message, action = 'Close', config = {}) => {
            const { panelClass } = config;
            config = Object.assign(Object.assign(Object.assign({}, this.config), config), { panelClass });
            return this.snackBar.open(message, action, config);
        };
        this.notify = (notifyItems, config = {}) => {
            const items = __classPrivateFieldGet(this, _addConfig).call(this, notifyItems, 'normal');
            return __classPrivateFieldGet(this, _showNotify).call(this, items, config);
        };
        this.notifySuccess = (notifyItems, config = {}) => {
            const items = __classPrivateFieldGet(this, _addConfig).call(this, notifyItems, 'success');
            return __classPrivateFieldGet(this, _showNotify).call(this, items, config);
        };
        this.notifyError = (notifyItems, config = {}) => {
            const items = __classPrivateFieldGet(this, _addConfig).call(this, notifyItems, 'error');
            return __classPrivateFieldGet(this, _showNotify).call(this, items, config);
        };
        this.notifyWarning = (notifyItems, config = {}) => {
            const items = __classPrivateFieldGet(this, _addConfig).call(this, notifyItems, 'warning');
            return __classPrivateFieldGet(this, _showNotify).call(this, items, config);
        };
        this.notifyInfo = (notifyItems, config = {}) => {
            const items = __classPrivateFieldGet(this, _addConfig).call(this, notifyItems, 'info');
            return __classPrivateFieldGet(this, _showNotify).call(this, items, config);
        };
        this.notifyPrimary = (notifyItems, config = {}) => {
            const items = __classPrivateFieldGet(this, _addConfig).call(this, notifyItems, 'primary');
            return __classPrivateFieldGet(this, _showNotify).call(this, items, config);
        };
    }
    get config() {
        return this.zuiToastDataService.config;
    }
    get notifyItems() {
        return this.zuiToastDataService.notifyItems;
    }
}
_showNotify = new WeakMap(), _addConfig = new WeakMap();
ZUIToastService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ZUIToastService_Factory() { return new ZUIToastService(i0.ɵɵinject(i1.MatSnackBar), i0.ɵɵinject(i2.ZUIToastDataService)); }, token: ZUIToastService, providedIn: "root" });
ZUIToastService.decorators = [
    { type: Injectable, args: [{ providedIn: 'root' },] }
];
ZUIToastService.ctorParameters = () => [
    { type: MatSnackBar },
    { type: ZUIToastDataService }
];
//# sourceMappingURL=index.service.js.map