import { r as registerInstance, h, g as getElement } from './chunk-8105bee0.js';

class Stepper {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.activeStep = 0;
        this.inactiveSteps = [];
    }
    componentDidLoad() {
        Array.from(this.host.querySelectorAll('materials-step')).forEach(step => {
            if (!step.showButtons) {
                step.showButtons = this.showButtons;
            }
        });
        this.calcIndexes();
    }
    async calcIndexes() {
        const activeSteps = Array.from(this.host.querySelectorAll('materials-step')).filter((_val, index) => this.inactiveSteps.indexOf(index) < 0);
        activeSteps.forEach((step, index) => {
            step.style.display = 'flex';
            step.index = index;
            step.active = (index === 0);
            if (step.index === (activeSteps.length - 1)) {
                step.isLast = true;
            }
        });
        const inactiveSteps = Array.from(this.host.querySelectorAll('materials-step')).filter((_val, index) => this.inactiveSteps.indexOf(index) > -1);
        inactiveSteps.forEach(step => step.style.display = 'none');
        this.adjustHeight();
    }
    async handleActiveStepUpdate() {
        const steps = Array.from(this.host.querySelectorAll('materials-step')).filter((_val, index) => this.inactiveSteps.indexOf(index) < 0);
        steps.forEach((step) => {
            if (step.index === this.activeStep) {
                this.currentStep = step;
            }
            step.active = (step.index === this.activeStep);
        });
    }
    switchStep(ev) {
        // On peut se rendre sur un step si tous les steps précédent sont valides ou optionels
        const steps = Array.from(this.host.querySelectorAll('materials-step')).filter((_val, index) => this.inactiveSteps.indexOf(index) < 0);
        const invalidPrevious = steps.find(e => !(e.status === 'valid' || e.optional) && e.index < ev.detail);
        if (!invalidPrevious) {
            this.activeStep = ev.detail;
        }
    }
    async openStep(index) {
        this.activeStep = index;
    }
    async nextStep() {
        const steps = Array.from(this.host.querySelectorAll('materials-step')).filter((_val, index) => this.inactiveSteps.indexOf(index) < 0);
        if (this.activeStep < (steps.length - 1)) {
            this.activeStep++;
        }
    }
    async previousStep() {
        if (this.activeStep > 0) {
            this.activeStep--;
        }
    }
    async adjustHeight() {
        const steps = Array.from(this.host.querySelectorAll('materials-step'));
        if (steps) {
            steps.forEach((step) => {
                step.adjustHeight();
            });
        }
    }
    render() {
        return (h("slot", null));
    }
    get host() { return getElement(this); }
    static get watchers() { return {
        "inactiveSteps": ["calcIndexes"],
        "activeStep": ["handleActiveStepUpdate"]
    }; }
    static get style() { return ":host{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-pack:start;justify-content:flex-start;overflow:hidden}"; }
}

export { Stepper as materials_stepper };
