import { r as registerInstance, c as createEvent, h, g as getElement } from './index-148a7577.js';
import { r as randomIdGenerator } from './randomIdGenerator.util-56406f2e.js';
import { e as FormErrorListHeadingLevel, u as NotificationAlertVariation, y as TypographyVariation } from './typography-variation.enum-531cdf64.js';
import { l as logger } from './logger.util-ede3c48a.js';
import './badge-notification-shape.enum-e15a6245.js';
import './badge-status-variation.enum-8d6370ff.js';
import './code-example-variation.enum-e656d235.js';
import './form-input-search-variation.enum-6d8dc10a.js';
import './button-variation.enum-94fffdd6.js';
import './calendar-week-view-heading-level.enum-6774297c.js';
import './code-variation.enum-1eee7c7a.js';
import './expandable-accordion-header-level.enum-85681e2f.js';
import './expandable-faq-item-variation.enum-a8cb225b.js';
import './expandable-faq-variation.enum-6934c367.js';
import './footer-card-variation.enum-cc732148.js';
import './form-checkbox-variation.enum-83e906fc.js';
import './form-file-upload-variation.enum-9c49ec5e.js';
import './form-input-type.enum-3da3db27.js';
import './form-input-variation.enum-64d9450f.js';
import './form-select-variation.enum-f2f6098d.js';
import './form-textarea-variation.enum-05017e8e.js';
import './form-validation-message-variation.enum-bcef8a9d.js';
import './info-card-multi-type.enum-07ee124f.js';
import './info-card-variation.enum-2ccc52c1.js';
import './layout-block-variation.enum-b7a20db4.js';
import './layout-columns-variation.enum-34f7754e.js';
import './link-button-variation.enum-84d4976f.js';
import './list-type.enum-fbb331ad.js';
import './loader-skeleton-variation.enum-f9f867b4.js';
import './loader-spinner-size.enum-0b246fa0.js';
import './logo-variation.enum-5b68b79f.js';
import './media-figure-alignment.enum-a1d36567.js';
import './navigation-sidebar-variation.enum-8fead764.js';
import './progress-indicator-variation.enum-b12ba50a.js';
import './progress-list-item-variation.enum-384b9a3a.js';
import './progress-list-variation.enum-300bd89d.js';
import './progressbar-variation.enum-40adaab4.js';
import './quote-image-inner-position.enum-8e9b1e65.js';
import './table-variation.enum-dd9366b6.js';
import './tag-media-icon.enum-fefa191c.js';
import './tag-size.enum-403e0cd8.js';
import './tools-feedback-banner-type.enum-74b4e580.js';
import './tools-feedback-rating-variation.enum-29058ff2.js';
import './tools-theme-provider.brand.enum-8c5a98c9.js';
import './typography-heading-jumbo-variation.enum-eb737f1b.js';
import './typography-meta-variation.enum-1f7c2878.js';
import './typography-time-variation.enum-34c830ef.js';
import './util-breakpoint-observer-breakpoints.enum-6d004731.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 = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        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: '868c07e57dbbc9f46ccc5f9214341301c0e7b1b7', class: "digi-form-error-list", id: this.afId }, h("digi-notification-alert", { key: '437a183cac9324be7d1a8907e21586fd172a41dd', ref: (el) => (this._notificationAlert = el), "af-heading": this.afHeading, "af-heading-level": this.afHeadingLevel, "af-variation": NotificationAlertVariation.DANGER }, this.afDescription && (h("digi-typography", { key: '1db9783857417e3f0619bca6af9f6e5d38351dcd', "af-variation": TypographyVariation.SMALL }, h("p", { key: '3889e42373badbcf3f4b39bdb6c29736d4a11ae8', class: "digi-form-error-list__description" }, this.afDescription))), h("ul", { key: '1f23512859a993e96b005bbe958db6a59761e67c', 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: '255cc10b49e79829d75c7260f9018c58650200d3', hidden: true, class: "digi-form-error-list__slot" }, h("digi-util-mutation-observer", { key: '0b69e728b52eb717824c9422dcfd1eb39a50960b', afOptions: {
                attributes: false,
                childList: true,
                subtree: true,
                characterData: true
            }, ref: (el) => (this._observer = el), onAfOnChange: () => this.getLinks() }, h("slot", { key: '290ad5d315d3a1c6e4986c2e76374b0b16e72d18' })))));
    }
    get hostElement() { return getElement(this); }
};
FormErrorList.style = DigiFormErrorListStyle0;

export { FormErrorList as digi_form_error_list };
