'use strict';

var index = require('./index-DuCXzb-X.js');

const getIcon = variant => {
  const icons = {
    default: 'fa-lightbulb',
    success: 'fa-check',
    info: 'fa-info-circle',
    warning: 'fa-exclamation-triangle',
    alert: 'fa-exclamation-triangle',
  };

  return icons[variant] || icons['default'];
};

const getElementClass = (variant, size = 'default') => {
  return {
    'spw-message': true,
    [`spw-message--${variant}`]: true,
    [`spw-message--${size}`]: true,
  };
};

const spwMessageCss = () => `@charset "UTF-8";html{line-height:1.3;-webkit-text-size-adjust:100%;}h1,h2,h3,h4,h5,h6,p,ul,li{padding:0;margin:0}ul{list-style:none}:host{box-sizing:border-box;line-height:1.3;-webkit-text-size-adjust:100%;font-size:100%}:host *,:host *::before,:host *::after{box-sizing:inherit;font-family:var(--spw-ds-font-main)}body{margin:0}hr{box-sizing:content-box;height:0;overflow:visible;}pre{font-family:monospace, monospace;font-size:1em;}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted;}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em;}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0;}button,input{overflow:visible}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}button::-moz-focus-inner,[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal;}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0;}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px;}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit;}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}:root{--spw-ds-container-xl:1232px;--spw-ds-container-lg:1024px;--spw-ds-container-md:768px;--spw-ds-container-sm:640px}.spw-ds-container{width:100%;padding-left:16px;padding-right:16px;margin-left:auto;margin-right:auto}@media (min-width: 460px){.spw-ds-container{max-width:var(--spw-ds-container-sm)}}@media (min-width: 768px){.spw-ds-container{max-width:var(--spw-ds-container-md)}}@media (min-width: 1024px){.spw-ds-container{max-width:var(--spw-ds-container-lg)}}@media (min-width: 1350px){.spw-ds-container{max-width:var(--spw-ds-container-xl)}}:host{display:block;--spw-message-margin-top-content:12px;--spw-message-title-color:var(--spw-colors-support-grey-grey-900);--spw-message-body-color:var(--spw-colors-support-grey-grey-900);--spw-message-font-size:16px;--spw-message-default-background-color:var(--spw-colors-support-grey-grey-100);--spw-message-default-icon-color:var(--spw-colors-support-grey-grey-900);--spw-message-default-border-color:var(--spw-colors-support-grey-grey-300);--spw-message-success-background-color:var(--spw-colors-multi-branding-green-green-50);--spw-message-success-icon-color:var(--spw-colors-multi-branding-green-green-600);--spw-message-success-border-color:var(--spw-colors-multi-branding-green-green-300);--spw-message-alert-background-color:var(--spw-colors-multi-branding-red-red-50);--spw-message-alert-icon-color:var(--spw-colors-multi-branding-red-red-accent-3);--spw-message-alert-border-color:var(--spw-colors-multi-branding-red-red-300);--spw-message-info-background-color:var(--spw-colors-multi-branding-blue-blue-50);--spw-message-info-icon-color:var(--spw-colors-multi-branding-blue-blue-accent-3);--spw-message-info-border-color:var(--spw-colors-multi-branding-blue-blue-300);--spw-message-warning-background-color:#ffeee0;--spw-message-warning-icon-color:#d84300;--spw-message-warning-border-color:#f4b095}.spw-message{padding:24px;border-radius:16px;border:2px solid transparent;color:var(--spw-message-title-color);font-size:var(--spw-message-font-size)}.spw-message__title-container{display:flex;gap:24px;flex-wrap:nowrap;justify-content:space-between;flex-direction:column}@media (min-width: 1024px){.spw-message__title-container{flex-direction:row}}.spw-message__close{order:-1}@media (min-width: 1024px){.spw-message__close{order:initial}}.spw-message__title{font-size:18px;flex:1;display:block}.spw-message__title spw-icon,.spw-message__title .spw-icon{position:relative;margin-right:6px;top:1px}.spw-message__text{margin-top:var(--spw-message-margin-top-content);color:var(--spw-message-body-color)}.spw-message__separator{font-weight:normal}.spw-message__inline-content{font-weight:normal}.spw-message--compact{padding:16px}.spw-message--compact .spw-message__title{font-size:16px;display:inline}.spw-message--compact .spw-message__title spw-icon{margin-right:4px}.spw-message--default{background:var(--spw-message-default-background-color);border-color:var(--spw-message-default-border-color)}.spw-message--default .spw-icon{color:var(--spw-message-default-icon-color)}.spw-message--success{background:var(--spw-message-success-background-color);border-color:var(--spw-message-success-border-color)}.spw-message--success spw-icon,.spw-message--success .spw-icon{color:var(--spw-message-success-icon-color)}.spw-message--alert{background:var(--spw-message-alert-background-color);border-color:var(--spw-message-alert-border-color)}.spw-message--alert spw-icon,.spw-message--alert .spw-icon{color:var(--spw-message-alert-icon-color)}.spw-message--info{background:var(--spw-message-info-background-color);border-color:var(--spw-message-info-border-color)}.spw-message--info spw-icon,.spw-message--info .spw-icon{color:var(--spw-message-info-icon-color)}.spw-message--warning{background:var(--spw-message-warning-background-color);border-color:var(--spw-message-warning-border-color)}.spw-message--warning spw-icon,.spw-message--warning .spw-icon{color:var(--spw-message-warning-icon-color)}.spw-message spw-link{--spw-link-color:var(--spw-colors-support-grey-grey-900);--spw-link-hover-color:var(--spw-colors-support-grey-grey-900);--spw-link-active-color:var(--spw-colors-support-grey-grey-800);--spw-link-padding:12px}.spw-message spw-link:focus-visible{outline:3px solid white;outline-offset:0;box-shadow:0 0 0 6px black}`;

const SpwMessage = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.spwDismiss = index.createEvent(this, "spwDismiss", 7);
        /** Le type de variante */
        this.variant = 'default';
        /** Si la notification est masquable */
        this.isDismissable = true;
        /** Texte du bouton pour masquer la notification */
        this.dismissableText = 'Masquer';
        /** Titre de la notification */
        this.messageTitle = 'Notification';
        /** Taille du message */
        this.size = 'default';
        this.isVisible = true;
        this.hasSlotContent = false;
        this.handleKeyDown = (ev) => {
            if (ev.key === 'Enter') {
                ev.preventDefault();
                this.handleDismiss();
            }
        };
        this.handleDismiss = () => {
            this.spwDismiss.emit({ messageId: this.messageId });
            this.isVisible = false;
        };
        this.handleSlotChange = () => {
            if (this.slotElement) {
                const assignedNodes = this.slotElement.assignedNodes({ flatten: true });
                this.hasSlotContent = assignedNodes.some(node => { var _a; return node.nodeType === Node.ELEMENT_NODE || (node.nodeType === Node.TEXT_NODE && ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== ''); });
            }
        };
    }
    /**
     * Affiche le message
     */
    async showMessage() {
        this.isVisible = true;
    }
    /**
     * Masque le message
     */
    async hideMessage() {
        this.isVisible = false;
    }
    render() {
        const iconToDisplay = this.icon || getIcon(this.variant);
        const isCompact = this.size === 'compact';
        return this.isVisible ? (index.h(index.Host, null, index.h("div", { class: getElementClass(this.variant, this.size), role: "alert", "aria-live": "polite", "aria-label": this.messageTitle }, index.h("div", { class: "spw-message__title-container" }, index.h("strong", { class: "spw-message__title" }, index.h("spw-icon", { icon: iconToDisplay }), " ", this.messageTitle, isCompact && this.hasSlotContent && index.h("span", { class: "spw-message__separator" }, "\u00A0:\u00A0"), isCompact && (index.h("span", { class: "spw-message__inline-content" }, index.h("slot", { ref: el => (this.slotElement = el), onSlotchange: this.handleSlotChange })))), this.isDismissable && (index.h("spw-link", { tabindex: "0", icon: "fa-close", class: "spw-message__close", "aria-label": this.dismissableText, onClick: this.handleDismiss, onKeyDown: this.handleKeyDown }, this.dismissableText))), !isCompact && (index.h("div", { class: "spw-message__text" }, index.h("slot", { ref: el => (this.slotElement = el), onSlotchange: this.handleSlotChange })))))) : null;
    }
    get el() { return index.getElement(this); }
};
SpwMessage.style = spwMessageCss();

exports.spw_message = SpwMessage;
