import { Host, h } from "@stencil/core";
import { getIcon, getElementClass } from "./utils.js";
export class SpwMessage {
    constructor() {
        /** 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 ? (h(Host, null, h("div", { class: getElementClass(this.variant, this.size), role: "alert", "aria-live": "polite", "aria-label": this.messageTitle }, h("div", { class: "spw-message__title-container" }, h("strong", { class: "spw-message__title" }, h("spw-icon", { icon: iconToDisplay }), " ", this.messageTitle, isCompact && this.hasSlotContent && h("span", { class: "spw-message__separator" }, "\u00A0:\u00A0"), isCompact && (h("span", { class: "spw-message__inline-content" }, h("slot", { ref: el => (this.slotElement = el), onSlotchange: this.handleSlotChange })))), this.isDismissable && (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 && (h("div", { class: "spw-message__text" }, h("slot", { ref: el => (this.slotElement = el), onSlotchange: this.handleSlotChange })))))) : null;
    }
    static get is() { return "spw-message"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["spw-message.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["spw-message.css"]
        };
    }
    static get properties() {
        return {
            "variant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "'default' | 'success' | 'info' | 'alert' | 'warning'",
                    "resolved": "\"alert\" | \"default\" | \"info\" | \"success\" | \"warning\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Le type de variante"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "variant",
                "defaultValue": "'default'"
            },
            "messageId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Identifiant unique pour le message"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "message-id"
            },
            "isDismissable": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Si la notification est masquable"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "is-dismissable",
                "defaultValue": "true"
            },
            "dismissableText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Texte du bouton pour masquer la notification"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "dismissable-text",
                "defaultValue": "'Masquer'"
            },
            "messageTitle": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Titre de la notification"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "message-title",
                "defaultValue": "'Notification'"
            },
            "icon": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Ic\u00F4ne personnalis\u00E9e (si non d\u00E9finie, utilise l'ic\u00F4ne par d\u00E9faut de la variante)"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "icon"
            },
            "size": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "'default' | 'compact'",
                    "resolved": "\"compact\" | \"default\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Taille du message"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "size",
                "defaultValue": "'default'"
            }
        };
    }
    static get states() {
        return {
            "isVisible": {},
            "hasSlotContent": {}
        };
    }
    static get events() {
        return [{
                "method": "spwDismiss",
                "name": "spwDismiss",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "\u00C9v\u00E9nement \u00E9mis lors du clic sur le bouton de fermeture"
                },
                "complexType": {
                    "original": "{ messageId: string }",
                    "resolved": "{ messageId: string; }",
                    "references": {}
                }
            }];
    }
    static get methods() {
        return {
            "showMessage": {
                "complexType": {
                    "signature": "() => Promise<void>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Affiche le message",
                    "tags": []
                }
            },
            "hideMessage": {
                "complexType": {
                    "signature": "() => Promise<void>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "Masque le message",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
}
