import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { o as onComponentRequiredPropUndefined, y as getInputHelperTextID } from './helpers.js';
import { d as defineCustomElement$1 } from './ic-typography2.js';

const icInputLabelCss = "ic-input-label{margin-bottom:var(--ic-space-xs);--ic-typography-color:var(\n    --ic-input-label-text-color,\n    var(--ic-color-text-primary)\n  )}ic-input-label.with-helper{margin-bottom:0}ic-input-label.ic-input-label-readonly{--ic-typography-color:var(--ic-input-label-readonly-typography-color)}ic-input-label .helpertext,ic-input-label .helpertext ::slotted(*){margin-top:var(--ic-space-xxxs);padding-bottom:var(--ic-input-label-helpertext-padding, 0);--ic-typography-color:var(\n    --ic-input-label-helper-text-color,\n    var(--ic-color-text-secondary)\n  )}ic-input-label .helpertext-normal{--ic-typography-color:var(\n    --ic-input-label-helper-text-color,\n    var(--ic-color-text-secondary)\n  )}ic-input-label .helpertext-readonly{--ic-typography-color:var(--ic-input-label-readonly-helpertext-color)}ic-input-label .readonly-label{--ic-typography-color:var(--ic-input-label-readonly-label-color)}ic-input-label .error-label{--ic-typography-color:var(--ic-input-label-error-label-color)}";
const IcInputLabelStyle0 = icInputLabelCss;

const InputLabel = /*@__PURE__*/ proxyCustomElement(class InputLabel extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        /**
         * If `true`, the disabled state will be set.
         */
        this.disabled = false;
        /**
         * The helper text that will be displayed.
         */
        this.helperText = "";
        /**
         * The label will be visually hidden.
         */
        this.hideLabel = false;
        /**
         * If `true`, the readonly state will be set.
         */
        this.readonly = false;
        /**
         * If `true`, the input label will require a value.
         */
        this.required = false;
        /**
         * The status of the label - e.g. 'error'.
         */
        this.status = "";
        /**
         * @internal If `true`, wraps label text in label tag
         */
        this.useLabelTag = true;
        this.isSlotUsed = (slot) => {
            const assignedEls = slot === null || slot === void 0 ? void 0 : slot.assignedElements();
            if (assignedEls && assignedEls.length) {
                for (const el of assignedEls) {
                    if (el.tagName === "SLOT") {
                        // Recursion needed for when slot is forwarded multiple times - through child components
                        // (e.g. in date picker)
                        if (this.isSlotUsed(el)) {
                            return true;
                        }
                    }
                    else {
                        // Found an assigned element which is not a nested <slot>
                        return true;
                    }
                }
            }
            return false;
        };
    }
    componentDidLoad() {
        onComponentRequiredPropUndefined([{ prop: this.label, propName: "label" }], "Input Label");
    }
    render() {
        const { disabled, readonly, label, required, helperText, status, hideLabel, useLabelTag, } = this;
        const labelText = required ? label + " *" : label;
        const helperTextId = this.for && getInputHelperTextID(this.for);
        const helperTextClass = {
            helpertext: true,
            "helpertext-normal": !disabled && !readonly,
            "helpertext-readonly": readonly,
        };
        const helperTextSlot = this.el.querySelector("slot[name='helper-text']");
        const labelSlot = this.el.querySelector('[slot="label"]');
        const LabelContent = () => this.isSlotUsed(labelSlot) ? (h("slot", { name: "label" })) : readonly || !useLabelTag ? (h("ic-typography", { variant: "label", class: {
                "readonly-label": readonly,
                "error-label": status === "error" && !(readonly || disabled),
            } }, labelText)) : (h("ic-typography", { variant: "label", class: {
                "readonly-label": readonly,
                "error-label": status === "error" && !(readonly || disabled),
            } }, h("label", { htmlFor: this.for }, labelText)));
        return (h(Host, { key: 'f22dfddc6e1c5dc956e3a2288a168b41ad18b35b', class: {
                "ic-input-label-disabled": !!disabled,
                "ic-input-label-readonly": readonly,
                "with-helper": this.isSlotUsed(helperTextSlot) || helperText !== "",
            } }, !hideLabel && h(LabelContent, { key: 'db3607fc40a7752954f3cd7e40bcf969a6941bdb' }), this.isSlotUsed(helperTextSlot) ? (h("span", { id: helperTextId, class: helperTextClass }, h("slot", { name: "helper-text" }))) : (helperText !== "" && (h("ic-typography", { variant: "caption", class: helperTextClass }, h("span", { id: helperTextId }, helperText))))));
    }
    get el() { return this; }
    static get style() { return IcInputLabelStyle0; }
}, [4, "ic-input-label", {
        "disabled": [4],
        "for": [1],
        "helperText": [1, "helper-text"],
        "hideLabel": [4, "hide-label"],
        "label": [1],
        "readonly": [4],
        "required": [4],
        "status": [1],
        "useLabelTag": [4, "use-label-tag"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["ic-input-label", "ic-typography"];
    components.forEach(tagName => { switch (tagName) {
        case "ic-input-label":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, InputLabel);
            }
            break;
        case "ic-typography":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { InputLabel as I, defineCustomElement as d };

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