'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-7a477838.js');
const randomIdGenerator_util = require('./randomIdGenerator.util-e7f4b6de.js');
const typographyVariation_enum = require('./typography-variation.enum-8fd8bed4.js');
const logger_util = require('./logger.util-fdafc086.js');
require('./badge-notification-shape.enum-ff802554.js');
require('./badge-status-variation.enum-0a5adc21.js');
require('./code-example-variation.enum-1611825e.js');
require('./form-input-search-variation.enum-e0e025b1.js');
require('./button-variation.enum-bc521499.js');
require('./calendar-week-view-heading-level.enum-fd0c841b.js');
require('./code-variation.enum-c4a4e6fd.js');
require('./expandable-accordion-header-level.enum-45483252.js');
require('./expandable-faq-item-variation.enum-89427195.js');
require('./expandable-faq-variation.enum-af923f49.js');
require('./footer-card-variation.enum-99555edc.js');
require('./form-checkbox-variation.enum-d2ca879e.js');
require('./form-file-upload-variation.enum-634cfae8.js');
require('./form-input-type.enum-9c8ee12a.js');
require('./form-input-variation.enum-c750520c.js');
require('./form-select-variation.enum-528c1bf0.js');
require('./form-textarea-variation.enum-9c90d40f.js');
require('./form-validation-message-variation.enum-855ae0be.js');
require('./info-card-multi-type.enum-14746572.js');
require('./info-card-variation.enum-64cef637.js');
require('./layout-block-variation.enum-f6102119.js');
require('./layout-columns-variation.enum-65675649.js');
require('./link-button-variation.enum-137785e3.js');
require('./list-type.enum-aea4d012.js');
require('./loader-skeleton-variation.enum-d52ba55e.js');
require('./loader-spinner-size.enum-db2973f0.js');
require('./logo-variation.enum-607fadb4.js');
require('./media-figure-alignment.enum-3885aba5.js');
require('./navigation-sidebar-variation.enum-1c0c3064.js');
require('./progress-indicator-variation.enum-7cf8e0e4.js');
require('./progress-list-item-variation.enum-90e4c874.js');
require('./progress-list-variation.enum-06d5ce27.js');
require('./progressbar-variation.enum-aff9fa80.js');
require('./quote-image-inner-position.enum-e64e7a6d.js');
require('./table-variation.enum-25df2ad7.js');
require('./tag-media-icon.enum-372563c5.js');
require('./tag-size.enum-387c516c.js');
require('./tools-feedback-banner-type.enum-de373ba0.js');
require('./tools-feedback-rating-variation.enum-2f71e84d.js');
require('./tools-theme-provider.brand.enum-bc855272.js');
require('./typography-heading-jumbo-variation.enum-8677e099.js');
require('./typography-meta-variation.enum-13ac3538.js');
require('./typography-time-variation.enum-bce1d87e.js');
require('./util-breakpoint-observer-breakpoints.enum-e96d3a84.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) {
        index.registerInstance(this, hostRef);
        this.afOnClickLink = index.createEvent(this, "afOnClickLink", 7);
        this.afOnReady = index.createEvent(this, "afOnReady", 3);
        this.linkItems = [];
        this.afHeading = undefined;
        this.afHeadingLevel = typographyVariation_enum.FormErrorListHeadingLevel.H2;
        this.afDescription = undefined;
        this.afId = randomIdGenerator_util.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_util.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 (index.h("div", { key: '868c07e57dbbc9f46ccc5f9214341301c0e7b1b7', class: "digi-form-error-list", id: this.afId }, index.h("digi-notification-alert", { key: '437a183cac9324be7d1a8907e21586fd172a41dd', ref: (el) => (this._notificationAlert = el), "af-heading": this.afHeading, "af-heading-level": this.afHeadingLevel, "af-variation": typographyVariation_enum.NotificationAlertVariation.DANGER }, this.afDescription && (index.h("digi-typography", { key: '1db9783857417e3f0619bca6af9f6e5d38351dcd', "af-variation": typographyVariation_enum.TypographyVariation.SMALL }, index.h("p", { key: '3889e42373badbcf3f4b39bdb6c29736d4a11ae8', class: "digi-form-error-list__description" }, this.afDescription))), index.h("ul", { key: '1f23512859a993e96b005bbe958db6a59761e67c', class: "digi-form-error-list__list" }, this.linkItems.map((item) => {
            return (index.h("li", { class: "digi-form-error-list__item" }, index.h("digi-link-internal", { class: "digi-form-error-list__link", afHref: item.href }, item.text)));
        }))), index.h("div", { key: '255cc10b49e79829d75c7260f9018c58650200d3', hidden: true, class: "digi-form-error-list__slot" }, index.h("digi-util-mutation-observer", { key: '0b69e728b52eb717824c9422dcfd1eb39a50960b', afOptions: {
                attributes: false,
                childList: true,
                subtree: true,
                characterData: true
            }, ref: (el) => (this._observer = el), onAfOnChange: () => this.getLinks() }, index.h("slot", { key: '290ad5d315d3a1c6e4986c2e76374b0b16e72d18' })))));
    }
    get hostElement() { return index.getElement(this); }
};
FormErrorList.style = DigiFormErrorListStyle0;

exports.digi_form_error_list = FormErrorList;
