import { r as registerInstance, c as createEvent, h, g as getElement } from './index-148a7577.js';
import { P as ProgressListHeadingLevel, c as ProgressListVariation, b as ProgressListType, a as ProgressListStatus } from './progress-list-variation.enum-300bd89d.js';
import { l as logger } from './logger.util-ede3c48a.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 = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        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: '64bf972e1029f4e802207f6b263d73c5912a8852', class: "digi-progress-list" }, h("digi-typography", { key: '68eae21de61ec1758cdf803f9df543f713036a73' }, this.renderHeading(), h("ol", { key: '3900f3181170af233600a57b8e94dd8c08727556', class: "digi-progress-list__content" }, h("slot", { key: 'd34a28c365b74000cbfc8d0a152b7eb13c7a7e6a' })))));
    }
    get hostElement() { return getElement(this); }
};
ProgressList.style = DigiProgressListStyle0;

export { ProgressList as digi_progress_list };
