<template>
    <v-menu
        v-model="menu.visible"
        :position-x="menu.x"
        :position-y="menu.y"
        absolute
        offset-y
        :close-on-content-click="false"
        :close-on-click="false"
    >
        <v-card
            tile
            flat
            :width="width"
            :disabled="disabled"
        >
            <v-card-title>
                {{ __('Desasociere utilizator') }}
            </v-card-title>

            <v-divider></v-divider>

            <v-sheet
                :height="height"
                class="overflow-y-auto"
                v-if="menu.customercurs"
            >
                <v-card-text class="pa-1">
                    <v-alert
                        type="error"
                    >
                        {{ __('Ești sigur că vrei să desasociezi utilizatorul :full_name de la cursul :curs?', {
                            full_name: menu.customercurs.user.full_name,
                            curs: curs.name,
                        }) }}
                    </v-alert>
                </v-card-text>
            </v-sheet>

            <v-divider></v-divider>

            <v-card-actions>

                <cs-btn 
                    caption="Desasociază"
                    icon="mdi-minus"
                    color="red"
                    outlined
                    tooltip="Confirmă desasocierea"
                    :loading="app.requests.Desasocierecursuri.processing"
                    @click="OnClickDesaociere"
                />

                <v-spacer></v-spacer>

                <cs-btn 
                    caption="Renunță"
                    icon="mdi-close"
                    @click="OnClickCancel"
                />
            </v-card-actions>
        </v-card>
    </v-menu>
</template>

<script>
    export default {
        props: {
            app: {required: true},
            menu: {required: true},
            width: {default: 400},
            height: {default: null},
            disabled: {default: false},
        },

        computed: {
            cursatasat() {
                return this.app.dataSession.Cursuriatasate.cursatasat;
            },

            curs() {
                return this.cursatasat.curs;
            },
        },

        methods: {
            OnClickDesaociere(e) {
                this.app.requests.Desasocierecursuri.ResetData().SetData({
                    ids: [this.menu.customercurs.id],
                    customer_id: this.app.payload.customer_id,
                }).Request([
                    response => {
                        if(!!this.app.payload.customer_curs_id)
                        {
                            this.app.dataSession.Customercursuriuser.GetByCustomerCursId(this.app.payload.customer_curs_id);
                        }
                        else
                        {
                            this.app.dataSession.Customercursuriuser.GetByCustomerCursId(this.menu.customercurs.customer_curs_id);
                        }
                        this.OnClickCancel();
                    }
                ]);
            },

            OnClickCancel() {
                this.menu.visible = false;
            }
        },

        components: {
            CsBtn: require('@CsVueComp/buttons/CsBtn').default,
        },

        name: 'DeleteUserMenu'
    }
</script>