<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"
            :disabled="formIsDisabed"
        > 
            <account-input 
                :controls="controls"
                :activeRecord="activeRecord"
                :errorsManager="errorsManager"
                :action="action"
                :currentAction="currentAction"

                :departmentForm="app.forms.Departamente"
                :usersForm="app.forms.Users"
                :userType="userType"

                :app="app"
            />
        </cs-form-card>
    </v-menu>
</template>

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

        computed: {
            formIsDisabed() {
                if( _.has(this.app.forms, 'Departamente') && this.app.forms.Departamente.visible )
                {
                    return true;
                }

                if( _.has(this.app.forms, 'Users') && this.app.forms.Users.visible )
                {
                    return true;
                }

                return false;
            }
        },

        watch: {
            'form.menu.visible': function(visible, oldvisible) {
                if(this.action == 'insert')
                {
                    this.activeRecord.user.last_name = null;
                    this.activeRecord.user.first_name = null;
                    this.activeRecord.user.email = null;
                    this.activeRecord.user.phone = null;
                }
            }
        },

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

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

        name: 'AccountFormMenu',
    }
</script>