<template>
    <v-menu
        v-model="form.menu.visible"
        :position-x="form.menu.x"
        :position-y="form.menu.y"
        absolute
        offset-y
        right
        :close-on-content-click="false"
        :close-on-click="false"
    >
        <cs-form-card 
            :form="form"
            :messageBox="null"
            @insert="$emit('insert', $event)"
        > 
            <v-alert type="warning" class="text-body-2" outlined rounde="lg" v-if="registru && (! registru.columns || registru.columns.length == 0)">
                {{ __('Registrul :name nu are definită structura pe coloane.', {name: registru.name}) }}
            </v-alert>

            <customer-register-input 
                :app="app"
                :controls="controls"
                :activeRecord="activeRecord"
                :errorsManager="errorsManager"
                :action="action"
                :currentAction="currentAction"
                :departmentForm="app.forms.Departamente"
            />

        </cs-form-card>
    </v-menu>
</template>

<script>
    export default {
        props: {
            app: {required: true},
            form: {required: true},
        },

        computed: {

            controller() {
                return this.app.classes.Customerregistru;
            },

            registru() {
                return this.controller.registru;
            }
        },

        watch: {
            'form.menu.visible': function(visible) {

                if(visible)
                {
                    this.GetNextNumber();
                }
            }
        },

        methods: {
            GetNextNumber() {
                if(this.action == 'insert') 
                {
                    this.app.requests.Getnextnumber.ResetData().SetData({
                        customer_id: this.app.payload.customer_id,
                        register_id: this.app.payload.registru_id,
                    }).Request([
                        response => {
                           this.activeRecord.number = response.payload;
                        }
                    ]);
                }
            }
        },

        created() {
            this.GetNextNumber();
        },
        
        components: {
            CsFormCard: require('@CsVueComp/cards/CsFormCard').default,
        },

        mixins: [
            require('@CsVueMix/Forminput/Forminput')
        ],

        name: 'CustomerRegisterFormMenu',
    }
</script>