'use strict';

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

const index = require('./index-7a477838.js');
const progressListVariation_enum = require('./progress-list-variation.enum-06d5ce27.js');
const logger_util = require('./logger.util-fdafc086.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) {
        index.registerInstance(this, hostRef);
        this.afOnReady = index.createEvent(this, "afOnReady", 3);
        this.afHeading = undefined;
        this.afAriaLabel = undefined;
        this.afHeadingLevel = progressListVariation_enum.ProgressListHeadingLevel.H2;
        this.afVariation = progressListVariation_enum.ProgressListVariation.PRIMARY;
        this.afType = progressListVariation_enum.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_util.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_util.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_util.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 = progressListVariation_enum.ProgressListStatus.DONE;
                    }
                    else if (index == this.afCurrentStep - 1) {
                        status = progressListVariation_enum.ProgressListStatus.CURRENT;
                    }
                    else {
                        status = progressListVariation_enum.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 === progressListVariation_enum.ProgressListStatus.CURRENT;
                    step.ref.afExpandText = this.afExpandText;
                    step.ref.afCollapseText = this.afCollapseText;
                }
                catch (e) {
                    logger_util.logger.warn(`Error in setStepAndTypeProps, `, e);
                }
            });
    }
    renderHeading() {
        var _a;
        if (((_a = this.afHeading) === null || _a === void 0 ? void 0 : _a.trim().length) > 1) {
            return (index.h("div", null, index.h(this.afHeadingLevel, { class: "digi-progress-list__header", "aria-label": this.afAriaLabel }, this.afHeading)));
        }
        return null;
    }
    render() {
        return (index.h("div", { key: '49e79226a302b6f1600eb8a8071fc52ed9d1af17', class: "digi-progress-list" }, index.h("digi-typography", { key: '5393e83a0748300d42a1e4044af64c592805cc6b' }, this.renderHeading(), index.h("ol", { key: '80d221f36d6e8539c81a8a55ef31457d88a55f09', class: "digi-progress-list__content" }, index.h("slot", { key: 'a67b614383b6fbc3e1dace65a8641860d163e51a' })))));
    }
    get hostElement() { return index.getElement(this); }
};
ProgressList.style = DigiProgressListStyle0;

exports.digi_progress_list = ProgressList;
