// Copyright (c) Laserfiche.
// Licensed under the MIT License. See LICENSE in the project root for license information.
import { Component, Input } from '@angular/core';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
/** @internal */
export var LfMessageToastTypes;
(function (LfMessageToastTypes) {
    LfMessageToastTypes["Error"] = "Error";
    LfMessageToastTypes["Warning"] = "Warning";
    LfMessageToastTypes["Validation"] = "Validation";
    LfMessageToastTypes["Informational"] = "Informational";
})(LfMessageToastTypes || (LfMessageToastTypes = {}));
/** @internal */
export class LfToastMessageComponent {
    set messages(messages) {
        if (typeof messages === 'undefined') {
            return;
        }
        for (const message of messages) {
            let messageId = message.id;
            if (!messageId) {
                messageId = message.id = Math.random().toString();
            }
            this.allMessages.push(message);
            // Errors and Warnings will not auto dismiss
            if ((message.type === LfMessageToastTypes.Validation || message.type === LfMessageToastTypes.Informational) &&
                message.timeToShow &&
                message.timeToShow > 0) {
                window.setTimeout(this._removeToast.bind(this, messageId), message.timeToShow);
            }
        }
    }
    constructor() {
        this.allMessages = [];
    }
    _computeTypeIcon(type) {
        switch (type) {
            case LfMessageToastTypes.Validation:
                return 'check_circle_outline';
            case LfMessageToastTypes.Warning:
                return 'warning_amber';
            case LfMessageToastTypes.Informational:
                return 'info';
            default:
                return 'error_outline';
        }
    }
    _closeToast(messageId) {
        this._removeToast(messageId);
    }
    _removeToast(messageId) {
        const idx = this.allMessages.findIndex((message) => message.id === messageId);
        if (idx !== -1) {
            this.allMessages.splice(idx, 1);
        }
    }
    clearToasts(toastFilter) {
        this.allMessages = toastFilter ? this.allMessages.filter((message) => message.type !== toastFilter) : [];
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LfToastMessageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: LfToastMessageComponent, selector: "lf-toast-message", inputs: { messages: "messages" }, ngImport: i0, template: "<!--Copyright (c) Laserfiche.\r\nLicensed under the MIT License. See LICENSE in the project root for license information.-->\r\n\r\n<div\r\n  *ngFor=\"let message of allMessages; index as idx\"\r\n  class=\"toast-message message-holder lf-flexbox-col\"\r\n  [ngClass]=\"{\r\n    error: message.type === 'Error',\r\n    warning: message.type === 'Warning',\r\n    validation: message.type === 'Validation',\r\n    informational: message.type === 'Informational'\r\n  }\"\r\n>\r\n  <div class=\"lf-flexbox-row lf-flexbox-center both-axis\">\r\n    <span\r\n      class=\"material-icons-outlined\"\r\n      style=\"flex: 0 0 auto\"\r\n      [ngClass]=\"{\r\n        warningIcon: message.type === 'Warning',\r\n        'hide-icon': message.noIcon\r\n      }\"\r\n      [attr.aria-label]=\"message.type\"\r\n    >\r\n      {{ _computeTypeIcon(message.type) }}\r\n    </span>\r\n    <div\r\n      class=\"message-text lf-flex-item lf-flexbox-row\"\r\n      [ngClass]=\"{\r\n        error: message.type === 'Error',\r\n        warning: message.type === 'Warning',\r\n        validation: message.type === 'Validation',\r\n        informational: message.type === 'Informational',\r\n        'no-left-padding': message.noIcon\r\n      }\"\r\n    >\r\n      <div class=\"message-wrapper\">\r\n        {{ message.message }}\r\n      </div>\r\n    </div>\r\n    <button\r\n      id=\"close-btn\"\r\n      (click)=\"_closeToast(message.id)\"\r\n      style=\"flex: 0 0 auto\"\r\n      [ngClass]=\"{\r\n        warningIcon: message.type === 'Warning'\r\n      }\"\r\n    >\r\n      <span class=\"material-icons-outlined\" aria-label=\"close\"> close </span>\r\n    </button>\r\n  </div>\r\n</div>\r\n", styles: [":host{pointer-events:none}:host:not(.relative){display:flex;flex-direction:column;place-content:center;align-items:center;position:absolute;width:100%;z-index:9999}:host(.relative){display:block;left:calc(var(--lf-toast-message-offset, 48px) / 2);width:100%;z-index:9999}:host:not(.bottom-align){top:10px}:host(.bottom-align){bottom:10px}.lf-flexbox-row{display:flex;flex-direction:row}.lf-flexbox-col{display:flex;flex-direction:column}.lf-flexbox-center.both-axis{align-items:center;place-content:center}.lf-flex-item{flex:1 1 auto}.hide-icon{display:none}.message-holder{margin:1px 0;padding:8px 8px 8px 20px;border-radius:5px;min-width:300px;max-width:560px;cursor:pointer;-ms-text-overflow:ellipsis;-o-text-overflow:ellipsis;text-overflow:ellipsis;font-weight:600;font-size:14px;pointer-events:auto}.no-left-padding{padding-left:0}.message-holder.error{color:#ab2227;background-color:#f7e8e9;border:#ab2227 1px solid}.message-holder.warning{background-color:#fff9eb;border:#facb5e 1px solid}.warning,.warningIcon{color:#333}.message-holder.validation{color:#216352;background-color:#e8efed;border:#216352 1px solid}.message-holder.informational{color:#0058ad;background-color:#c1d6eb;border:#0058ad 1px solid}.message-text{font-size:13px;font-weight:600;padding:0 10px;white-space:pre-line;max-height:85px;overflow-y:auto}.message-wrapper{margin:auto 0}#close-btn{width:24px;height:24px;color:inherit;border:none;background:inherit;cursor:pointer;padding:0;pointer-events:all}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LfToastMessageComponent, decorators: [{
            type: Component,
            args: [{ selector: 'lf-toast-message', template: "<!--Copyright (c) Laserfiche.\r\nLicensed under the MIT License. See LICENSE in the project root for license information.-->\r\n\r\n<div\r\n  *ngFor=\"let message of allMessages; index as idx\"\r\n  class=\"toast-message message-holder lf-flexbox-col\"\r\n  [ngClass]=\"{\r\n    error: message.type === 'Error',\r\n    warning: message.type === 'Warning',\r\n    validation: message.type === 'Validation',\r\n    informational: message.type === 'Informational'\r\n  }\"\r\n>\r\n  <div class=\"lf-flexbox-row lf-flexbox-center both-axis\">\r\n    <span\r\n      class=\"material-icons-outlined\"\r\n      style=\"flex: 0 0 auto\"\r\n      [ngClass]=\"{\r\n        warningIcon: message.type === 'Warning',\r\n        'hide-icon': message.noIcon\r\n      }\"\r\n      [attr.aria-label]=\"message.type\"\r\n    >\r\n      {{ _computeTypeIcon(message.type) }}\r\n    </span>\r\n    <div\r\n      class=\"message-text lf-flex-item lf-flexbox-row\"\r\n      [ngClass]=\"{\r\n        error: message.type === 'Error',\r\n        warning: message.type === 'Warning',\r\n        validation: message.type === 'Validation',\r\n        informational: message.type === 'Informational',\r\n        'no-left-padding': message.noIcon\r\n      }\"\r\n    >\r\n      <div class=\"message-wrapper\">\r\n        {{ message.message }}\r\n      </div>\r\n    </div>\r\n    <button\r\n      id=\"close-btn\"\r\n      (click)=\"_closeToast(message.id)\"\r\n      style=\"flex: 0 0 auto\"\r\n      [ngClass]=\"{\r\n        warningIcon: message.type === 'Warning'\r\n      }\"\r\n    >\r\n      <span class=\"material-icons-outlined\" aria-label=\"close\"> close </span>\r\n    </button>\r\n  </div>\r\n</div>\r\n", styles: [":host{pointer-events:none}:host:not(.relative){display:flex;flex-direction:column;place-content:center;align-items:center;position:absolute;width:100%;z-index:9999}:host(.relative){display:block;left:calc(var(--lf-toast-message-offset, 48px) / 2);width:100%;z-index:9999}:host:not(.bottom-align){top:10px}:host(.bottom-align){bottom:10px}.lf-flexbox-row{display:flex;flex-direction:row}.lf-flexbox-col{display:flex;flex-direction:column}.lf-flexbox-center.both-axis{align-items:center;place-content:center}.lf-flex-item{flex:1 1 auto}.hide-icon{display:none}.message-holder{margin:1px 0;padding:8px 8px 8px 20px;border-radius:5px;min-width:300px;max-width:560px;cursor:pointer;-ms-text-overflow:ellipsis;-o-text-overflow:ellipsis;text-overflow:ellipsis;font-weight:600;font-size:14px;pointer-events:auto}.no-left-padding{padding-left:0}.message-holder.error{color:#ab2227;background-color:#f7e8e9;border:#ab2227 1px solid}.message-holder.warning{background-color:#fff9eb;border:#facb5e 1px solid}.warning,.warningIcon{color:#333}.message-holder.validation{color:#216352;background-color:#e8efed;border:#216352 1px solid}.message-holder.informational{color:#0058ad;background-color:#c1d6eb;border:#0058ad 1px solid}.message-text{font-size:13px;font-weight:600;padding:0 10px;white-space:pre-line;max-height:85px;overflow-y:auto}.message-wrapper{margin:auto 0}#close-btn{width:24px;height:24px;color:inherit;border:none;background:inherit;cursor:pointer;padding:0;pointer-events:all}\n"] }]
        }], ctorParameters: () => [], propDecorators: { messages: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 