import { p as proxyCustomElement, H, c as createEvent, h } from './p-a53686b3.js';
import { r as randomIdGenerator } from './p-ffe5c0e8.js';
import { g as FormErrorListHeadingLevel, q as NotificationAlertVariation, u as TypographyVariation } from './p-5a256d98.js';
import { l as logger } from './p-e3d2e899.js';
import './p-717306ef.js';
import './p-a4a001e1.js';
import './p-f518a4cf.js';
import './p-7e32c40b.js';
import './p-dcdffb3c.js';
import './p-5d21a361.js';
import './p-ad16c7a1.js';
import './p-f40f4b2a.js';
import './p-1f68d501.js';
import './p-ee88e3f1.js';
import './p-8142cc73.js';
import './p-905ccb30.js';
import './p-bc3d2778.js';
import './p-c8429245.js';
import './p-06625463.js';
import './p-f447b984.js';
import './p-9c5a93d8.js';
import './p-7933b555.js';
import './p-0f6c0360.js';
import './p-814ca2ad.js';
import './p-d8a98b3b.js';
import './p-07303cb5.js';
import './p-5f8dc01a.js';
import './p-2a023831.js';
import './p-5ba6737a.js';
import './p-e4a9f8f0.js';
import './p-f2a6768b.js';
import './p-40657c82.js';
import './p-f600576a.js';
import './p-3b20ec86.js';
import './p-9dd5d6c8.js';
import './p-77a93845.js';
import './p-06f939ab.js';
import './p-8cd2d6dd.js';
import './p-484a1d6d.js';
import './p-0f3fbb1e.js';
import './p-820e795b.js';
import './p-46cbbcb5.js';
import './p-d74742b8.js';
import './p-6e383896.js';
import './p-4bad4fb0.js';
import './p-d1886fff.js';
import './p-a6ca40fc.js';
import './p-b0e88537.js';
import './p-cdcaf0eb.js';
import { d as defineCustomElement$d } from './p-e8fc33ed.js';
import { d as defineCustomElement$c } from './p-dafe1c96.js';
import { d as defineCustomElement$b } from './p-e25ae6dc.js';
import { d as defineCustomElement$a } from './p-31096d78.js';
import { d as defineCustomElement$9 } from './p-c102c5fe.js';
import { d as defineCustomElement$8 } from './p-915b1874.js';
import { d as defineCustomElement$7 } from './p-70ca6868.js';
import { d as defineCustomElement$6 } from './p-da621047.js';
import { d as defineCustomElement$5 } from './p-3e02ce82.js';
import { d as defineCustomElement$4 } from './p-f478b763.js';
import { d as defineCustomElement$3 } from './p-5c53d1d4.js';
import { d as defineCustomElement$2 } from './p-2f619b66.js';

const formErrorListCss = ".sc-digi-form-error-list-h{--digi--form-error-list--list--padding:var(--digi--gutter--smaller) 0 0 0;--digi--form-error-list--list--margin:0;--digi--form-error-list--item--padding:var(--digi--padding--smaller) 0 0 0;--digi--form-error-list--item--margin:0}.sc-digi-form-error-list-h .digi-form-error-list__list.sc-digi-form-error-list{list-style:none;padding:var(--digi--form-error-list--list--padding);margin:var(--digi--form-error-list--list--margin)}.sc-digi-form-error-list-h .digi-form-error-list__item.sc-digi-form-error-list{list-style:none;padding:var(--digi--form-error-list--item--padding);margin:var(--digi--form-error-list--item--margin)}";
const DigiFormErrorListStyle0 = formErrorListCss;

const FormErrorList = /*@__PURE__*/ proxyCustomElement(class FormErrorList extends H {
    constructor() {
        super();
        this.__registerHost();
        this.afOnClickLink = createEvent(this, "afOnClickLink", 7);
        this.afOnReady = createEvent(this, "afOnReady", 3);
        this.linkItems = [];
        this.afHeading = undefined;
        this.afHeadingLevel = FormErrorListHeadingLevel.H2;
        this.afDescription = undefined;
        this.afId = randomIdGenerator('digi-form-error-list');
        this.afOverrideLink = false;
        this.afEnableHeadingFocus = true;
    }
    /**
     * Sätter fokus på rubriken.
     * @en Sets focus on the heading.
     */
    async afMSetHeadingFocus() {
        this.setHeadingFocus();
    }
    componentWillLoad() {
        this.getLinks();
    }
    componentWillUpdate() {
        this.getLinks(true);
    }
    componentDidLoad() {
        this.setHeadingFocus();
        this.afOnReady.emit();
    }
    getLinks(update) {
        const elements = this.hostElement.children;
        if (!elements || elements.length <= 0) {
            logger.warn(`The slot contains no link elements`, this.hostElement);
            return;
        }
        let items;
        if (update) {
            items = this._observer.children;
        }
        else {
            items = elements;
        }
        this.linkItems = [...items]
            .filter((element) => element.tagName.toLowerCase() === 'a')
            .map((element) => {
            return {
                text: element.textContent,
                href: element.getAttribute('href') || ''
            };
        });
    }
    setHeadingFocus() {
        if (this.afEnableHeadingFocus) {
            setTimeout(async () => {
                const el = await this._notificationAlert.afMGetHeadingElement();
                !!el && el.focus();
            }, 0);
        }
    }
    clickResponse(e) {
        if (this.afOverrideLink) {
            e.detail.preventDefault();
        }
        this.afOnClickLink.emit(e);
    }
    render() {
        return (h("div", { key: 'b1538bef3aa4d16c21c04cc6ec3a16e1da48cf9c', class: "digi-form-error-list", id: this.afId }, h("digi-notification-alert", { key: '2b6989a273a1182560cf313e22c5c6d2fd01fd33', ref: (el) => (this._notificationAlert = el), "af-heading": this.afHeading, "af-heading-level": this.afHeadingLevel, "af-variation": NotificationAlertVariation.DANGER }, this.afDescription && (h("digi-typography", { key: '9142a6f39761391edd40aa8102cff60547be34b2', "af-variation": TypographyVariation.SMALL }, h("p", { key: '0244fd85c399f6823dca2437e5b25e329fcfa9b2', class: "digi-form-error-list__description" }, this.afDescription))), h("ul", { key: '47caec67e8e33bdaa13abb8b04f5ce9756a93e8b', class: "digi-form-error-list__list" }, this.linkItems.map((item) => {
            return (h("li", { class: "digi-form-error-list__item" }, h("digi-link-internal", { class: "digi-form-error-list__link", afHref: item.href }, item.text)));
        }))), h("div", { key: '9e48117d3a59c50c10684f05a40f350c5b936867', hidden: true, class: "digi-form-error-list__slot" }, h("digi-util-mutation-observer", { key: '02d6c18bd0c16be3fb3266abebd4bd8156e4a432', afOptions: {
                attributes: false,
                childList: true,
                subtree: true,
                characterData: true
            }, ref: (el) => (this._observer = el), onAfOnChange: () => this.getLinks() }, h("slot", { key: 'd1d766b6f1f094c135a0ae8c9624a0e871ccdfad' })))));
    }
    get hostElement() { return this; }
    static get style() { return DigiFormErrorListStyle0; }
}, [6, "digi-form-error-list", {
        "afHeading": [1, "af-heading"],
        "afHeadingLevel": [1, "af-heading-level"],
        "afDescription": [1, "af-description"],
        "afId": [1, "af-id"],
        "afOverrideLink": [4, "af-override-link"],
        "afEnableHeadingFocus": [4, "af-enable-heading-focus"],
        "linkItems": [32],
        "afMSetHeadingFocus": [64]
    }, [[0, "afOnClick", "clickResponse"]]]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["digi-form-error-list", "digi-button", "digi-icon-chevron-right", "digi-icon-notification-error", "digi-icon-notification-info", "digi-icon-notification-succes", "digi-icon-notification-warning", "digi-icon-x", "digi-link", "digi-link-internal", "digi-notification-alert", "digi-typography", "digi-util-mutation-observer"];
    components.forEach(tagName => { switch (tagName) {
        case "digi-form-error-list":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, FormErrorList);
            }
            break;
        case "digi-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$d();
            }
            break;
        case "digi-icon-chevron-right":
            if (!customElements.get(tagName)) {
                defineCustomElement$c();
            }
            break;
        case "digi-icon-notification-error":
            if (!customElements.get(tagName)) {
                defineCustomElement$b();
            }
            break;
        case "digi-icon-notification-info":
            if (!customElements.get(tagName)) {
                defineCustomElement$a();
            }
            break;
        case "digi-icon-notification-succes":
            if (!customElements.get(tagName)) {
                defineCustomElement$9();
            }
            break;
        case "digi-icon-notification-warning":
            if (!customElements.get(tagName)) {
                defineCustomElement$8();
            }
            break;
        case "digi-icon-x":
            if (!customElements.get(tagName)) {
                defineCustomElement$7();
            }
            break;
        case "digi-link":
            if (!customElements.get(tagName)) {
                defineCustomElement$6();
            }
            break;
        case "digi-link-internal":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "digi-notification-alert":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "digi-typography":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "digi-util-mutation-observer":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const DigiFormErrorList = FormErrorList;
const defineCustomElement = defineCustomElement$1;

export { DigiFormErrorList, defineCustomElement };
