<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>
                {{ __('Ștergere fișier') }}
            </v-card-title>

            <v-divider></v-divider>

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

            <v-divider></v-divider>

            <v-card-actions>

                <cs-btn 
                    caption="Șterge"
                    icon="mdi-minus"
                    color="red"
                    outlined
                    tooltip="Confirmă ștergerea fișerului"
                    :loading="app.requests.Stergerefisier.processing"
                    @click="OnClickDelete"
                />

                <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: {
            OnClickDelete(e) {
                this.app.requests.Stergerefisier.ResetData().SetData({
                    id: this.menu.customerfile.id,
                    customer_id: this.app.payload.customer_id,
                }).Request([
                    response => {
                        if( !! this.app.classes.Accescurs )
                        {
                            this.app.dataSession.Customercursurifiles.GetByCustomerCursId(this.app.payload.customer_curs_id);
                        }
                        else
                        {
                            if(!!this.app.dataSession.Cursuriatasate)
                            {
                                this.app.dataSession.Cursuriatasate.GetByCustomerId(this.app.classes.Cursuri.customer_id);
                            }

                            if(!! this.app.dataSession.Customercursurifiles)
                            {
                                // console.log('Bam bam....', this.cursatasat.id); 
                                this.app.dataSession.Customercursurifiles.GetByCustomerCursId(this.app.payload.customer_curs_id);
                            }
                        }
                        this.OnClickCancel();
                    }
                ]);
            },

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

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

        name: 'DeleteFileMenu'
    }
</script>