<template>
    <el-dialog
        :custom-class="`modal-wizard ${isInTransition ? 'is-in-transition' : 'isnt-in-transition'}`"
        :visible.sync="visible"
        :width="width"
        :close-on-press-escape="close_on_esc"
        :close-on-click-modal="close_on_click"
        :before-close="handleClose"
        :top="margin_top"
        v-if="visible"
    >
        <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">
                    <slot
                        :name="`step-${i-1}`"
                        :data_object="data_object_model"
                        :nextStep="nextStep"
                        :previousStep="previousStep"
                        :getDataObject="getDataObject"
                        :open="open"
                        :close="close"
                    />
                </div>
            </transition>
        </template>
    </el-dialog>
</template>
<script>
    export default {
        name: 'DialogWizard',
        props: {
            close_on_esc: {
                type: Boolean,
                default: false,
            },
            close_on_click: {
                type: Boolean,
                default: false,
            },
            margin_top: {
                type: String,
                default: '40px',
            },
            width: {
                type: String,
                default: '70%',
            },
            qty_steps: {
                type: Number,
                default: 0,
            },
            data_object: {
                type: Object,
                default: () => ({}),
            },
        },
        data() {
            return {
                slide_type: 'rl',
                visible: false,
                data_object_model: Object.assign({}, this.data_object),
                step: 0,
                isInTransition : true,
            };
        },
        methods: {
            handleClose(done) {
                this.$emit('onClose');
                done();
            },
            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--;
            },
            open() {
                this.visible = true;
            },
            close() {
                this.visible = false;
                this.step = 0;
                this.data_object_model = Object.assign({}, this.data_object);
            },
            getDataObject() {
                return this.data_object_model;
            },
        },
    };
</script>

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