import { p as proxyCustomElement, H, h } from './p-a53686b3.js';
import { r as randomIdGenerator } from './p-ffe5c0e8.js';
import { l as logger } from './p-e3d2e899.js';
import { _ as _t } from './p-08cf2c0e.js';

const formLabelCss = ".sc-digi-form-label-h .digi-form-label.sc-digi-form-label{font-family:var(--digi--global--typography--font-family--default);font-size:var(--digi--typography--label--font-size--desktop);color:var(--digi--color--text--primary);display:flex;flex-direction:column}.sc-digi-form-label-h .digi-form-label__label--label.sc-digi-form-label{font-weight:var(--digi--typography--label--font-weight--desktop)}.sc-digi-form-label-h .digi-form-label__label--label.sc-digi-form-label,.sc-digi-form-label-h .digi-form-label__label--description.sc-digi-form-label{line-height:var(--digi--typography--label--line-height--desktop);cursor:pointer;display:block}.sc-digi-form-label-h .digi-form-label__label-group.sc-digi-form-label{display:inline-flex;align-items:center;gap:var(--digi--gutter--icon)}.sc-digi-form-label-h .digi-form-label__description.sc-digi-form-label{max-width:var(--digi--paragraph-width--medium);line-height:var(--digi--typography--label-description--line-height--desktop);font-size:var(--digi--typography--label-description--font-size--desktop)}";
const DigiFormLabelStyle0 = formLabelCss;

const FormLabel = /*@__PURE__*/ proxyCustomElement(class FormLabel extends H {
    constructor() {
        super();
        this.__registerHost();
        this.labelText = undefined;
        this.hasActionSlot = undefined;
        this.afLabel = undefined;
        this.afId = randomIdGenerator('digi-form-label');
        this.afFor = undefined;
        this.afDescription = undefined;
        this.afRequired = undefined;
        this.afAnnounceIfOptional = false;
        this.afRequiredText = _t.required.toLowerCase();
        this.afAnnounceIfOptionalText = _t.optional.toLowerCase();
    }
    componentWillLoad() {
        this.setLabelText();
        this.validateFor();
        this.handleSlotVisibility();
    }
    validateFor() {
        if (this.afFor == null) {
            logger.warn(`digi-form-label must have a for attribute. Please add a for attribute using af-for`, this.hostElement);
        }
    }
    setLabelText() {
        this.labelText = `${this.afLabel} ${this.requiredText}`;
        if (!this.afLabel) {
            logger.warn(`digi-form-label must have a label. Please add a label using af-label`, this.hostElement);
        }
    }
    handleSlotVisibility() {
        this.hasActionSlot = !!this.hostElement.querySelector('[slot="actions"]');
    }
    get requiredText() {
        if (this.afRequired && !this.afAnnounceIfOptional) {
            return this.afRequiredText ? ` (${this.afRequiredText})` : '';
        }
        else if (!this.afRequired && this.afAnnounceIfOptional) {
            return this.afAnnounceIfOptionalText
                ? ` (${this.afAnnounceIfOptionalText})`
                : '';
        }
        else {
            return '';
        }
    }
    render() {
        return (h("div", { key: '0714a446215f218b8cc5449a318090a7e15de36e', class: "digi-form-label" }, h("div", { key: '290f19411233736a2741ccff9f95a328f0181513', class: "digi-form-label__label-group" }, this.afFor && this.afLabel && (h("label", { key: '9c990f78e47ee4bc1de6cc750cea54f8eb763033', class: "digi-form-label__label", htmlFor: this.afFor, id: this.afId }, h("span", { key: '22a428a427bb72921dd9b2487f2fb97844db541f', class: "digi-form-label__label--label" }, this.labelText), this.afDescription && (h("span", { key: 'd13261b4e0525e5fd680032cd625c579d8037302', class: "digi-form-label__label--description" }, this.afDescription)))), this.hasActionSlot && (h("div", { key: '198faa5a754472ca76e2e84edf38f6ea1280b067', class: "digi-form-label__actions" }, h("slot", { key: '0066fc1f5cab5b72c2971e50cb8f0b1736d24ec7', name: "actions" }))))));
    }
    get hostElement() { return this; }
    static get watchers() { return {
        "afFor": ["validateFor"],
        "afLabel": ["setLabelText"],
        "afRequired": ["setLabelText"],
        "afAnnounceIfOptional": ["setLabelText"]
    }; }
    static get style() { return DigiFormLabelStyle0; }
}, [6, "digi-form-label", {
        "afLabel": [1, "af-label"],
        "afId": [1, "af-id"],
        "afFor": [1, "af-for"],
        "afDescription": [1, "af-description"],
        "afRequired": [4, "af-required"],
        "afAnnounceIfOptional": [4, "af-announce-if-optional"],
        "afRequiredText": [1, "af-required-text"],
        "afAnnounceIfOptionalText": [1, "af-announce-if-optional-text"],
        "labelText": [32],
        "hasActionSlot": [32]
    }, undefined, {
        "afFor": ["validateFor"],
        "afLabel": ["setLabelText"],
        "afRequired": ["setLabelText"],
        "afAnnounceIfOptional": ["setLabelText"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["digi-form-label"];
    components.forEach(tagName => { switch (tagName) {
        case "digi-form-label":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, FormLabel);
            }
            break;
    } });
}

export { FormLabel as F, defineCustomElement as d };
