<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"
        >
            <v-card-title>
                {{ __('Import participanți din fișier excel') }}
            </v-card-title>

            <v-divider></v-divider>

            <v-card-text>
                <v-file-input
                    dense
                    :label="__('Selectați un fișier excel')"
                    v-model="file"
                >
                </v-file-input>
            </v-card-text>

            <v-divider></v-divider>

            <v-card-actions>
                <cs-btn 
                    caption="Importă"
                    icon="mdi-content-save"
                    color="primary"
                    :loading="app.requests.Importparticipants.processing"
                    :disabled="! file || app.requests.Importparticipants.processing"
                    @click="OnClickSave"
                />

                <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: 300},
        },

        data: () => ({
            file: null,
        }),

        methods: {
            OnClickSave() {
                this.app.requests.Importparticipants.ResetData().SetData({
                    file: this.file,
                    customer_curs_id: this.app.payload.customer_curs_id,
                    customer_id: this.app.payload.customer_id,
                }).Request([
                    response => {
                        this.file = null;
                        this.menu.visible = false;
                        this.app.dataSession.Customercursuriparticipants.GetByCustomerCursId(this.app.payload.customer_curs_id);

                        if(!!this.app.dataSession.Cursuriatasate)
                        {
                            this.app.dataSession.Cursuriatasate.GetByCustomerId(this.app.classes.Cursuri.customer_id);
                        }
                    }
                ])
            },

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

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

        name: 'ImportParticipantsMenu'
    }
</script>