<template>
    <v-chip 
        small 
        outlined
        @click="ShowCustomersWorkForm"
    >
        <v-icon>mdi-account-settings</v-icon>
    </v-chip>
</template>

<script>
    export default {

        props: {
            user: {required: true},
            app: {required: true},
            form: {required: true},
        },

        methods: {
            ShowCustomersWorkForm(e) {
                
                if(this.form)
                {          
                    this.form.visible = false;
                    this.form.left = 0;
                    this.form.top = 0;
                    this.form.user = {...this.user};

                    this.$nextTick(() => {
                    
                        this.form.formprovider.SetFormCaption('update', this.user.full_name + '. Editare permisiuni');

                        this.form.visible = true;

                        let permissions = ! this.user.permissions ? {} : {...this.user.permissions};
                        if(this.user.role)
                        {
                            permissions = {
                                ...this.user.role.permissions,
                                ...permissions,
                            };
                        }

                        this.form.formprovider.Reset().SetAction('update').SetActiveRecord({
                            ...this.form.formprovider.blankRecord,
                            user_id: this.user.id,
                            permissions,
                        });

                        this.form.formprovider.oldRecord = null;
                    })
                }
            }
        },
        
        name: 'UserPermissions',
    }
</script>