<template>
    <div class="slider-foundation">
        <template v-for="i in qty_steps">
            <transition :name="`slide-${slide_type}`" :key="i" appear @before-enter="beforeEnter" @after-enter="afterEnter" >
                <div v-if="step == i-1" :class="`step-${i-1}`">
                    <slot
                        :name="`step-${i-1}`"
                        :nextStep="nextStep"
                        :previousStep="previousStep"
                        :qtySteps="qty_steps"
                        :currentStep="step"
                        :open="open"
                        :close="close"
                    />
                </div>
            </transition>
        </template>
    </div>
</template>
<script>
    export default {
        name: 'SliderSteps',
        props: {
            initial_step : {
                type: Number,
                default: 0
            },
            close : {
                type: Function,
                default: () => {},
            },
            open : {
                type: Function,
                default: () => {},
            },
        },
        data() {
            return {
                slide_type: 'rl',
                step: this.initial_step,
                isInTransition : true,
            };
        },
        watch : {
            step(val) {
                this.$emit("on-step-changed",val)
            }
        },
        computed : {
            qty_steps() {
                return Object.keys(this.$scopedSlots).length
            },
        },
        methods: {
            beforeEnter() {
                this.isInTransition = true
            },
            afterEnter() {
                this.isInTransition = false;
            },
            nextStep() {
                this.slide_type = 'right-to-left';
                this.step++;
            },
            previousStep() {
                this.slide_type = 'left-to-right';
                this.step--;
            },
        },
    };
</script>

<style lang="scss">
    @import './styles.scss';
</style>
