/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { __decorate } from "tslib";
import { attachShadowTemplate, coerceBoolean, customElement, coreProperty } from '@tylertech/forge-core';
import { tylIconClose } from '@tylertech/tyler-icons/standard';
import { ButtonComponent } from '../button';
import { setDefaultAria } from '../constants';
import { BaseComponent } from '../core/base/base-component';
import { WithDefaultAria } from '../core/mixins/internals/with-default-aria';
import { WithElementInternals } from '../core/mixins/internals/with-element-internals';
import { DialogComponent, dialogStack } from '../dialog';
import { IconComponent, IconRegistry } from '../icon';
import { IconButtonComponent } from '../icon-button';
import { OverlayComponent } from '../overlay';
import { ToastAdapter } from './toast-adapter';
import { TOAST_CONSTANTS } from './toast-constants';
import { ToastCore } from './toast-core';
const template = '<template><forge-overlay exportparts=\"root:overlay\" no-anchor persistent><div class=\"surface\" part=\"surface\"><slot name=\"icon\"></slot><div class=\"message\" part=\"message\"><slot></slot></div><forge-button hidden part=\"action-button\" class=\"action-button\"></forge-button><forge-icon-button part=\"close-button\" class=\"close-button\" aria-label=\"Dismiss\" density=\"medium\"><forge-icon name=\"close\"></forge-icon></forge-icon-button></div></forge-overlay></template>';
const styles = '@-webkit-keyframes slidein{from{-webkit-transform:translateY(var(--_toast-slide-origin));transform:translateY(var(--_toast-slide-origin))}to{-webkit-transform:translateY(0);transform:translateY(0)}}@keyframes slidein{from{-webkit-transform:translateY(var(--_toast-slide-origin));transform:translateY(var(--_toast-slide-origin))}to{-webkit-transform:translateY(0);transform:translateY(0)}}@-webkit-keyframes slideout{from{-webkit-transform:translateY(0);transform:translateY(0)}to{-webkit-transform:translateY(var(--_toast-slide-origin));transform:translateY(var(--_toast-slide-origin))}}@keyframes slideout{from{-webkit-transform:translateY(0);transform:translateY(0)}to{-webkit-transform:translateY(var(--_toast-slide-origin));transform:translateY(var(--_toast-slide-origin))}}@-webkit-keyframes fadein{from{opacity:0}to{opacity:1}}@keyframes fadein{from{opacity:0}to{opacity:1}}@-webkit-keyframes fadeout{from{opacity:1}to{opacity:0}}@keyframes fadeout{from{opacity:1}to{opacity:0}}@layer base,open,theme,placement,media; @layer base{:host{display:contents}:host([hidden]){display:none}.surface{--_toast-background:var(--forge-toast-background, var(--forge-theme-surface-inverse, #333333));--_toast-color:var(--forge-toast-color, var(--forge-theme-on-surface-inverse, #ffffff));--_toast-offset:var(--forge-toast-offset, var(--forge-spacing-medium, 16px));--_toast-shape:var(--forge-toast-shape, var(--forge-shape-medium, 4px));--_toast-elevation:var(--forge-toast-elevation, 0px 3px 5px -1px rgba(0, 0, 0, 0.2), 0px 6px 10px 0px rgba(0, 0, 0, 0.14), 0px 1px 18px 0px rgba(0, 0, 0, 0.12));--_toast-action-color:var(--forge-toast-action-color, var(--forge-theme-secondary, #ffc107));--_toast-min-width:var(--forge-toast-min-width, 344px);--_toast-max-width:var(--forge-toast-max-width, 672px);--_toast-min-height:var(--forge-toast-min-height, 48px);--_toast-inline-padding:var(--forge-toast-inline-padding, var(--forge-spacing-medium, 16px));--_toast-spacing:var(--forge-toast-spacing, var(--forge-spacing-xsmall, 8px));--_toast-message-padding:var(--forge-toast-message-padding, var(--forge-spacing-xsmall, 8px));--_toast-enter-duration:var(--forge-toast-enter-duration, var(--forge-animation-duration-medium1, 250ms));--_toast-enter-timing:var(--forge-toast-enter-timing, var(--forge-animation-easing-decelerate, cubic-bezier(0, 0, 0, 1)));--_toast-exit-duration:var(--forge-toast-exit-duration, var(--forge-animation-duration-short4, 200ms));--_toast-exit-timing:var(--forge-toast-exit-timing, var(--forge-animation-easing-emphasized-accelerate, cubic-bezier(0.3, 0, 0.8, 0.15)));--_toast-slide-origin:var(--forge-toast-slide-origin, 100%)}.surface{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-family:var(--forge-typography-body2-font-family, var(--forge-typography-font-family, \"Roboto\", sans-serif));font-size:var(--forge-typography-body2-font-size, calc(var(--forge-typography-font-size, 1rem) * var(--forge-typography-body-font-size-scale, 1)));font-weight:var(--forge-typography-body2-font-weight,400);line-height:var(--forge-typography-body2-line-height, calc(var(--forge-typography-font-size, 1rem) * var(--forge-typography-body-line-height-scale, 1.375)));letter-spacing:var(--forge-typography-body2-letter-spacing, .015625em);text-transform:var(--forge-typography-body2-text-transform,inherit);-webkit-text-decoration:var(--forge-typography-body2-text-decoration,inherit);text-decoration:var(--forge-typography-body2-text-decoration,inherit);position:fixed;display:-webkit-box;display:flex;-webkit-box-align:center;align-items:center;-webkit-column-gap:var(--_toast-spacing);-moz-column-gap:var(--_toast-spacing);column-gap:var(--_toast-spacing);border-radius:var(--_toast-shape);padding-inline:var(--_toast-inline-padding);margin:var(--_toast-offset);min-width:var(--_toast-min-width);max-width:var(--_toast-max-width);min-height:var(--_toast-min-height);-webkit-box-sizing:border-box;box-sizing:border-box;background:var(--_toast-background);color:var(--_toast-color);-webkit-box-shadow:var(--_toast-elevation);box-shadow:var(--_toast-elevation)}.message{-webkit-box-flex:1;flex-grow:1;padding-block:var(--_toast-message-padding);text-overflow:ellipsis;overflow:hidden}forge-button.action-button{--forge-button-primary-color:var(--_toast-action-color)}forge-icon-button.close-button{--forge-icon-button-focus-indicator-color:var(--_toast-color)}:host(:not([dismissible])) .close-button{display:none}.action-button:not([hidden]){-webkit-margin-end:-8px;margin-inline-end:-8px}:host([dismissible]) .close-button{-webkit-margin-end:-8px;margin-inline-end:-8px}}@layer theme{:host([theme=primary]) .surface{--_toast-background:var(--forge-toast-background, var(--forge-theme-primary, #3f51b5));--_toast-color:var(--forge-toast-color, var(--forge-theme-on-primary, #ffffff));--_toast-action-color:var(--_toast-color)}:host([theme=secondary]) .surface{--_toast-background:var(--forge-toast-background, var(--forge-theme-secondary, #ffc107));--_toast-color:var(--forge-toast-color, var(--forge-theme-on-secondary, #000000));--_toast-action-color:var(--_toast-color)}:host([theme=tertiary]) .surface{--_toast-background:var(--forge-toast-background, var(--forge-theme-tertiary, #3d5afe));--_toast-color:var(--forge-toast-color, var(--forge-theme-on-tertiary, #ffffff));--_toast-action-color:var(--_toast-color)}:host([theme=success]) .surface{--_toast-background:var(--forge-toast-background, var(--forge-theme-success, #2e7d32));--_toast-color:var(--forge-toast-color, var(--forge-theme-on-success, #ffffff));--_toast-action-color:var(--_toast-color)}:host([theme=warning]) .surface{--_toast-background:var(--forge-toast-background, var(--forge-theme-warning, #d14900));--_toast-color:var(--forge-toast-color, var(--forge-theme-on-warning, #ffffff));--_toast-action-color:var(--_toast-color)}:host([theme=error]) .surface{--_toast-background:var(--forge-toast-background, var(--forge-theme-error, #b00020));--_toast-color:var(--forge-toast-color, var(--forge-theme-on-error, #ffffff));--_toast-action-color:var(--_toast-color)}:host([theme=info]) .surface{--_toast-background:var(--forge-toast-background, var(--forge-theme-info, #1565c0));--_toast-color:var(--forge-toast-color, var(--forge-theme-on-info, #ffffff));--_toast-action-color:var(--_toast-color)}}@layer open{forge-overlay[open] .surface{-webkit-animation-name:slidein;animation-name:slidein;-webkit-animation-duration:var(--_toast-enter-duration);animation-duration:var(--_toast-enter-duration);-webkit-animation-timing-function:var(--_toast-enter-timing);animation-timing-function:var(--_toast-enter-timing)}forge-overlay[open] .surface.exiting{-webkit-animation-name:slideout;animation-name:slideout;-webkit-animation-duration:var(--_toast-exit-duration);animation-duration:var(--_toast-exit-duration);-webkit-animation-timing-function:var(--_toast-exit-timing);animation-timing-function:var(--_toast-exit-timing)}}@layer placement{:host([placement=bottom-start]) .surface{bottom:0;left:0}:host(:is(:not([placement]),[placement=bottom])) .surface{bottom:0;left:50%;translate:-50%}:host([placement=bottom-end]) .surface{bottom:0;right:0}:host([placement=top-start]) .surface{--_toast-slide-origin:var(--forge-toast-slide-origin, -100%);top:0;left:0}:host([placement=top]) .surface{--_toast-slide-origin:var(--forge-toast-slide-origin, -100%);top:0;left:50%;translate:-50%}:host([placement=top-end]) .surface{--_toast-slide-origin:var(--forge-toast-slide-origin, -100%);top:0;right:0}}@layer media{@media (prefers-reduced-motion:reduce){forge-overlay[open] .surface{-webkit-animation-name:fadein;animation-name:fadein}forge-overlay[open] .surface.exiting{-webkit-animation-name:fadeout;animation-name:fadeout}}@media (max-width:599px){:host([placement^=top]) .surface{bottom:auto;top:0}.surface{bottom:0;left:0;right:0;margin:0;translate:none;max-width:none;min-width:auto;border-radius:0}}}';
/**
 * @tag forge-toast
 *
 * @summary Toasts are non-modal notifications that appear in response to user interactions.
 *
 * @dependency forge-overlay
 * @dependency forge-button
 * @dependency forge-icon-button
 * @dependency forge-icon
 *
 * @property {boolean} [open=false] - The open state.
 * @property {number} [duration=2750] - The duration in milliseconds that the toast is displayed.
 * @property {ToastPlacement} [placement="bottom"] - The placement of the toast.
 * @property {string} actionText - The text for the action button. This controls the visibility of the action button.
 * @property {boolean} [dismissible=false] - Whether the toast is dismissible (displays a close button).
 * @property {string} dismissLabel - The accessible label for the dismiss button.
 * @property {ToastTheme} [theme="default"] - The theme of the toast.
 *
 * @globalconfig duration
 * @globalconfig placement
 * @globalconfig dismissible
 *
 * @attribute {boolean} [open=false] - The open state.
 * @attribute {number} [duration=2750] - The duration in milliseconds that the toast is displayed.
 * @attribute {ToastPlacement} placement - The placement of the toast.
 * @attribute {string} action-text - The text for the action button. This controls the visibility of the action button.
 * @attribute {boolean} [dismissible=false] - Whether the toast is dismissible (displays a close button).
 * @attribute {string} dismiss-label - The accessible label for the dismiss button.
 * @attribute {ToastTheme} [theme="default"] - The theme of the toast.
 *
 * @event {CustomEvent<void>} forge-toast-action - Dispatched when the action button is clicked.
 * @event {CustomEvent<void>} forge-toast-close - Dispatched when the toast is closed.
 *
 * @cssproperty --forge-toast-background - The background color of the toast.
 * @cssproperty --forge-toast-color - The text color of the toast.
 * @cssproperty --forge-toast-offset - The offset of the toast from the edge of the viewport.
 * @cssproperty --forge-toast-shape - The shape of the toast.
 * @cssproperty --forge-toast-elevation - The elevation of the toast.
 * @cssproperty --forge-toast-action-color - The text color of the action button.
 * @cssproperty --forge-toast-min-width - The minimum width of the toast.
 * @cssproperty --forge-toast-max-width - The maximum width of the toast.
 * @cssproperty --forge-toast-min-height - The minimum height of the toast.
 * @cssproperty --forge-toast-inline-padding - The padding of the toast when inline.
 * @cssproperty --forge-toast-spacing - The spacing between toasts.
 * @cssproperty --forge-toast-message-padding - The padding of the toast message.
 * @cssproperty --forge-toast-enter-duration - The duration of the enter animation.
 * @cssproperty --forge-toast-enter-timing - The timing function of the enter animation.
 * @cssproperty --forge-toast-exit-duration - The duration of the exit animation.
 * @cssproperty --forge-toast-exit-timing - The timing function of the exit animation.
 * @cssproperty --forge-toast-slide-origin - The origin of the slide animation.
 *
 * @csspart surface - The surface container.
 * @csspart message - The message container.
 * @csspart action-button - The action button.
 * @csspart close-button - The close button.
 * @csspart overlay - The `<forge-overlay>` element.
 */
let ToastComponent = class ToastComponent extends WithElementInternals(WithDefaultAria(BaseComponent)) {
    static get observedAttributes() {
        return Object.values(TOAST_CONSTANTS.observedAttributes);
    }
    constructor() {
        super();
        IconRegistry.define(tylIconClose);
        attachShadowTemplate(this, template, styles);
        this._core = new ToastCore(new ToastAdapter(this));
    }
    connectedCallback() {
        const hasRole = this.hasAttribute('role') || this.getAttribute('aria-hidden') === 'true';
        if (!hasRole) {
            this[setDefaultAria]({
                role: 'alert',
                ariaLive: 'assertive',
                ariaAtomic: 'true'
            });
        }
        this._core.initialize();
    }
    attributeChangedCallback(name, oldValue, newValue) {
        switch (name) {
            case TOAST_CONSTANTS.attributes.OPEN:
                this.open = coerceBoolean(newValue);
                break;
            case TOAST_CONSTANTS.attributes.DURATION:
                const value = Number(newValue);
                this.duration = value && value > 0 ? value : TOAST_CONSTANTS.defaults.DURATION;
                break;
            case TOAST_CONSTANTS.attributes.PLACEMENT:
                this.placement = newValue || TOAST_CONSTANTS.defaults.PLACEMENT;
                break;
            case TOAST_CONSTANTS.attributes.ACTION_TEXT:
                this.actionText = newValue;
                break;
            case TOAST_CONSTANTS.attributes.DISMISSIBLE:
                this.dismissible = coerceBoolean(newValue);
                break;
            case TOAST_CONSTANTS.attributes.DISMISS_LABEL:
                this.dismissLabel = newValue;
                break;
            case TOAST_CONSTANTS.attributes.THEME:
                this.theme = newValue;
                break;
        }
    }
    /**
     * Shows the toast.
     */
    show() {
        this._core.show();
    }
    /**
     * Hides the toast.
     * @returns A promise that resolves when the toast animation completes.
     */
    hide() {
        return this._core.hide();
    }
    /**
     * Presents a toast notification.
     * @param config The configuration for the toast.
     * @returns A promise that resolves when the toast is closed.
     * @ignore CEM
     */
    static present({ message, element, icon, className, topLayer, ...config }) {
        const toast = document.createElement(TOAST_CONSTANTS.elementName);
        if (element) {
            toast.appendChild(element);
        }
        else if (message) {
            toast.append(message);
        }
        if (icon) {
            const iconEl = document.createElement('forge-icon');
            Object.assign(iconEl, icon);
            iconEl.slot = 'icon';
            toast.appendChild(iconEl);
        }
        if (className) {
            const classes = Array.isArray(className) ? className : [className];
            toast.classList.add(...classes);
        }
        if (config) {
            Object.assign(toast, config);
        }
        const hostEl = (topLayer && Array.from(DialogComponent[dialogStack]).at(-1)) || document.body;
        hostEl.appendChild(toast);
        toast.open = true;
        toast.addEventListener(TOAST_CONSTANTS.events.CLOSE, () => toast.remove());
        return toast;
    }
};
__decorate([
    coreProperty()
], ToastComponent.prototype, "open", void 0);
__decorate([
    coreProperty()
], ToastComponent.prototype, "duration", void 0);
__decorate([
    coreProperty()
], ToastComponent.prototype, "placement", void 0);
__decorate([
    coreProperty()
], ToastComponent.prototype, "actionText", void 0);
__decorate([
    coreProperty()
], ToastComponent.prototype, "dismissible", void 0);
__decorate([
    coreProperty()
], ToastComponent.prototype, "dismissLabel", void 0);
__decorate([
    coreProperty()
], ToastComponent.prototype, "theme", void 0);
ToastComponent = __decorate([
    customElement({
        name: TOAST_CONSTANTS.elementName,
        dependencies: [OverlayComponent, ButtonComponent, IconButtonComponent, IconComponent]
    })
], ToastComponent);
export { ToastComponent };
