var _option, _bSubjectData, _bSubjectToast, _getContent, _open;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { Injectable } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
import { BehaviorSubject } from 'rxjs';
import * as i0 from "@angular/core";
import * as i1 from "../index";
import * as i2 from "ngx-toastr";
export class ZUIToastV2Service {
    constructor(toastr) {
        this.toastr = toastr;
        _option.set(this, { closeButton: true, progressBar: true, enableHtml: true, timeOut: 3000 });
        _bSubjectData.set(this, void 0);
        _bSubjectToast.set(this, void 0);
        _getContent.set(this, (messages) => (Array.isArray(messages) ? messages.map(message => `<div>${message}</div>`).join('') : messages));
        _open.set(this, (message, title = '', option, type) => {
            const ops = Object.assign(Object.assign({}, __classPrivateFieldGet(this, _option)), option);
            const content = __classPrivateFieldGet(this, _getContent).call(this, message);
            const { toastComponent, data, timeOut } = ops;
            let activeToast;
            if (toastComponent && data) {
                __classPrivateFieldSet(this, _bSubjectData, new BehaviorSubject(data));
                __classPrivateFieldSet(this, _bSubjectToast, new BehaviorSubject(activeToast));
            }
            switch (type) {
                case 'success':
                    activeToast = this.toastr.success(content, title, ops);
                    break;
                case 'info':
                    activeToast = this.toastr.info(content, title, ops);
                    break;
                case 'warning':
                    activeToast = this.toastr.warning(content, title, ops);
                    break;
                case 'error':
                    activeToast = this.toastr.error(content, title, ops);
                    break;
                default:
                    activeToast = this.toastr.show(content, title, ops);
            }
            if (toastComponent)
                __classPrivateFieldGet(this, _bSubjectToast).next(activeToast);
            if (toastComponent && timeOut)
                setTimeout(() => this.remove(activeToast.toastId), timeOut);
            return activeToast;
        });
        this.getData = () => __classPrivateFieldGet(this, _bSubjectData);
        this.getToast = () => __classPrivateFieldGet(this, _bSubjectToast);
        this.setOption = (option) => {
            __classPrivateFieldSet(this, _option, option);
        };
        this.show = (message, title = '', option) => __classPrivateFieldGet(this, _open).call(this, message, title, option, 'show');
        this.success = (message, title = '', option) => __classPrivateFieldGet(this, _open).call(this, message, title, option, 'success');
        this.info = (message, title = '', option) => __classPrivateFieldGet(this, _open).call(this, message, title, option, 'info');
        this.warning = (message, title = '', option) => __classPrivateFieldGet(this, _open).call(this, message, title, option, 'warning');
        this.error = (message, title = '', option) => __classPrivateFieldGet(this, _open).call(this, message, title, option, 'error');
        this.clear = (toastId) => this.toastr.clear(toastId);
        this.remove = (toastId) => this.toastr.remove(toastId);
    }
}
_option = new WeakMap(), _bSubjectData = new WeakMap(), _bSubjectToast = new WeakMap(), _getContent = new WeakMap(), _open = new WeakMap();
ZUIToastV2Service.ɵprov = i0.ɵɵdefineInjectable({ factory: function ZUIToastV2Service_Factory() { return new i1.ZUIToastV2Service(i0.ɵɵinject(i2.ToastrService)); }, token: i1.ZUIToastV2Service, providedIn: "root" });
ZUIToastV2Service.decorators = [
    { type: Injectable, args: [{ providedIn: 'root' },] }
];
ZUIToastV2Service.ctorParameters = () => [
    { type: ToastrService }
];
//# sourceMappingURL=index.service.js.map