import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { z as getInputValidationTextID, i as isSlotUsed, A as IcInformationStatus } from './helpers.js';
import { w as warningIcon, m as errorIcon, s as successIcon } from './constants.js';
import { d as defineCustomElement$1 } from './ic-typography2.js';

const icInputValidationCss = "ic-input-validation{max-width:var(--input-width, 20rem);display:flex}ic-input-validation.ic-input-validation-with-status{margin-top:var(--ic-space-xs)}ic-input-validation.ic-input-validation-full-width{width:100%;max-width:none}ic-input-validation span.status-icon{padding-right:var(--ic-space-xxs)}ic-input-validation span.status-icon>svg{height:1.25rem;width:1.25rem}ic-input-validation span.icon-success>svg{fill:var(--ic-input-validation-success-icon-color)}ic-input-validation span.icon-error>svg{fill:var(--ic-input-validation-error, var(--ic-atoms-status-icon-error))}ic-input-validation span.icon-warning>svg{fill:var(--ic-input-validation-warning-icon-color)}ic-input-validation .statustext{flex-grow:1;color:var(\n    --ic-input-validation-status-text-color,\n    var(--ic-color-text-primary)\n  );--ic-typography-color:var(\n    --ic-input-validation-status-text-color,\n    var(--ic-color-text-primary)\n  )}ic-input-validation .sr-only{position:absolute;left:-9999px}";
const IcInputValidationStyle0 = icInputValidationCss;

const ICON = {
    [IcInformationStatus.Warning]: warningIcon,
    [IcInformationStatus.Error]: errorIcon,
    [IcInformationStatus.Success]: successIcon,
};
const INVISIBLE_CHAR = "\u200B";
const InputValidation = /*@__PURE__*/ proxyCustomElement(class InputValidation extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        /**
         *  The ARIA live mode to apply to the message.
         */
        this.ariaLiveMode = "polite";
        /**
         *  If `true`, the input validation will fill the width of the container.
         */
        this.fullWidth = false;
        /**
         * The status of the validation - e.g. 'error' | 'warning' | 'success'.
         */
        this.status = "";
    }
    watchMessageHandler(newValue) {
        // Force detectable DOM changes
        // Invisible character used as screen readers can ignore whitespace changes e.g. "" and " "
        this.messageEl.textContent = INVISIBLE_CHAR;
        setTimeout(() => {
            this.messageEl.textContent = newValue;
        }, 200); // Delay to help ensure screen readers detect change
    }
    componentDidLoad() {
        this.messageEl.textContent = INVISIBLE_CHAR;
    }
    render() {
        const { ariaLiveMode, fullWidth, status, message } = this;
        const displayIcon = status !== "" ? ICON[status] : "";
        return (h(Host, { key: '3b6f6b3e7ad37b899ee8fb71dbf7868a0eb4bd3f', class: {
                [`ic-input-validation-${status}`]: status !== "",
                "ic-input-validation-full-width": !!fullWidth,
                "ic-input-validation-with-status": status !== "",
            } }, displayIcon !== "" && (h("span", { key: 'f5d6eab684ec1ce116a2bb09e2a91a2d88d1620f', class: {
                "status-icon": true,
                [`icon-${status}`]: true,
            }, innerHTML: displayIcon })), h("ic-typography", { key: '841d8bfbf9dab21d611325dd3d7148c83ea09f40', variant: "caption", class: "statustext" }, h("span", { key: 'b35e925cc1dfd87cf8b4b2e3a8276492d5f4abda', id: this.for && getInputValidationTextID(this.for) }, isSlotUsed(this.el, "validation-message") ? (h("slot", { name: "validation-message" })) : (message)), h("span", { key: '2945b04c5e9dd1376793efc206a3c61fd96d84f2', ref: (el) => (this.messageEl = el), class: "sr-only", "aria-live": ariaLiveMode })), h("slot", { key: 'fd6c89ce76c2abf86813c2d20aadd2e652e649ca', name: "validation-message-adornment" })));
    }
    get el() { return this; }
    static get watchers() { return {
        "message": ["watchMessageHandler"]
    }; }
    static get style() { return IcInputValidationStyle0; }
}, [4, "ic-input-validation", {
        "ariaLiveMode": [1, "aria-live-mode"],
        "for": [1],
        "fullWidth": [4, "full-width"],
        "message": [1],
        "status": [1]
    }, undefined, {
        "message": ["watchMessageHandler"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["ic-input-validation", "ic-typography"];
    components.forEach(tagName => { switch (tagName) {
        case "ic-input-validation":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, InputValidation);
            }
            break;
        case "ic-typography":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { InputValidation as I, defineCustomElement as d };

//# sourceMappingURL=ic-input-validation2.js.map