import { p as proxyCustomElement, H, c as createEvent, h } from './p-a53686b3.js';
import { P as ProgressListHeadingLevel, c as ProgressListVariation, b as ProgressListType, a as ProgressListStatus } from './p-06f939ab.js';
import { l as logger } from './p-e3d2e899.js';
import { d as defineCustomElement$2 } from './p-5c53d1d4.js';

const progressListCss = ".sc-digi-progress-list-h{--digi--progress-list--content--padding-top:var(--digi--padding--medium);--digi--progress-list--heading--font-size:var(--digi--typography--heading-1--font-size--desktop);--digi--progress-list--heading--font-weight:var(--digi--typography--heading-1--font-weight--desktop);--digi--progress-list--heading--margin-bottom:var(--digi--margin--largest)}.sc-digi-progress-list-h .digi-progress-list__header.sc-digi-progress-list{font-size:var(--digi--progress-list--heading--font-size);font-weight:var(--digi--progress-list--heading--font-weight);margin-bottom:var(--digi--progress-list--heading--margin-bottom)}.sc-digi-progress-list-h .digi-progress-list__content.sc-digi-progress-list{margin-top:0;padding-left:0;padding-bottom:0;padding-top:var(--digi--progress-list--content--padding-top)}.sc-digi-progress-list-h .digi-progress-list.sc-digi-progress-list ol.sc-digi-progress-list{max-width:100%}";
const DigiProgressListStyle0 = progressListCss;

const ProgressList = /*@__PURE__*/ proxyCustomElement(class ProgressList extends H {
    constructor() {
        super();
        this.__registerHost();
        this.afOnReady = createEvent(this, "afOnReady", 3);
        this.afHeading = undefined;
        this.afAriaLabel = undefined;
        this.afHeadingLevel = ProgressListHeadingLevel.H2;
        this.afVariation = ProgressListVariation.PRIMARY;
        this.afType = ProgressListType.CIRCLE;
        this.afExpandable = false;
        this.afExpandText = '';
        this.afCollapseText = '';
        this.afCurrentStep = 1;
        this.steps = [];
    }
    async afMNext() {
        this.afCurrentStep += 1;
    }
    async afMPrevious() {
        this.afCurrentStep -= 1;
    }
    componentWillLoad() {
        this.getSteps();
        this.setStepAndTypeProps();
    }
    componentWillUpdate() {
        this.getSteps();
        this.setStepAndTypeProps();
    }
    componentDidLoad() {
        this.afOnReady.emit();
    }
    getSteps() {
        const steps = this.hostElement.querySelectorAll('digi-progress-list-item');
        if (!steps || steps.length <= 0) {
            logger.warn(`The slot contains no children elements.`, this.hostElement);
            return;
        }
        this.steps = [...Array.from(steps)].map((step) => {
            return {
                outerHTML: step.outerHTML,
                ref: step
            };
        });
    }
    setStepAndTypeProps() {
        if (this.steps && this.afCurrentStep < 1) {
            logger.warn(`Current step is set to ${this.afCurrentStep} which is not allowed.`, this.hostElement);
            this.afCurrentStep = 1;
            return;
        }
        if (this.steps && this.afCurrentStep > this.steps.length + 1) {
            logger.warn(`Current step is set to ${this.afCurrentStep} which is more than the amount of available steps (${this.steps.length}).`, this.hostElement);
            this.afCurrentStep = this.steps.length + 1;
            return;
        }
        this.steps &&
            this.steps.forEach((step, index) => {
                step.ref.afVariation = this.afVariation;
                try {
                    const topLevelN = Number.parseInt(this.afHeadingLevel.split('h')[1]) + 1;
                    const topLevel = Math.max(Math.min(topLevelN, 6), 1);
                    const afHeadingLevel = 'h' + topLevel;
                    const isLast = index == this.steps.length - 1;
                    step.ref.afIsLast = isLast;
                    let status;
                    if (index < this.afCurrentStep - 1) {
                        status = ProgressListStatus.DONE;
                    }
                    else if (index == this.afCurrentStep - 1) {
                        status = ProgressListStatus.CURRENT;
                    }
                    else {
                        status = ProgressListStatus.UPCOMING;
                    }
                    step.ref.afStepStatus = status;
                    step.ref.afType = this.afType;
                    step.ref.afHeadingLevel = afHeadingLevel;
                    // If expandable, check if expanded
                    step.ref.afExpandable = this.afExpandable;
                    step.ref.afExpanded = status === ProgressListStatus.CURRENT;
                    step.ref.afExpandText = this.afExpandText;
                    step.ref.afCollapseText = this.afCollapseText;
                }
                catch (e) {
                    logger.warn(`Error in setStepAndTypeProps, `, e);
                }
            });
    }
    renderHeading() {
        var _a;
        if (((_a = this.afHeading) === null || _a === void 0 ? void 0 : _a.trim().length) > 1) {
            return (h("div", null, h(this.afHeadingLevel, { class: "digi-progress-list__header", "aria-label": this.afAriaLabel }, this.afHeading)));
        }
        return null;
    }
    render() {
        return (h("div", { key: '49e79226a302b6f1600eb8a8071fc52ed9d1af17', class: "digi-progress-list" }, h("digi-typography", { key: '5393e83a0748300d42a1e4044af64c592805cc6b' }, this.renderHeading(), h("ol", { key: '80d221f36d6e8539c81a8a55ef31457d88a55f09', class: "digi-progress-list__content" }, h("slot", { key: 'a67b614383b6fbc3e1dace65a8641860d163e51a' })))));
    }
    get hostElement() { return this; }
    static get style() { return DigiProgressListStyle0; }
}, [6, "digi-progress-list", {
        "afHeading": [1, "af-heading"],
        "afAriaLabel": [1, "af-aria-label"],
        "afHeadingLevel": [1, "af-heading-level"],
        "afVariation": [1, "af-variation"],
        "afType": [1, "af-type"],
        "afExpandable": [4, "af-expandable"],
        "afExpandText": [1, "af-expand-text"],
        "afCollapseText": [1, "af-collapse-text"],
        "afCurrentStep": [2, "af-current-step"],
        "steps": [32],
        "afMNext": [64],
        "afMPrevious": [64]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["digi-progress-list", "digi-typography"];
    components.forEach(tagName => { switch (tagName) {
        case "digi-progress-list":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, ProgressList);
            }
            break;
        case "digi-typography":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const DigiProgressList = ProgressList;
const defineCustomElement = defineCustomElement$1;

export { DigiProgressList, defineCustomElement };
