<template>
    <v-menu
        v-model="menu.visible"
        :position-x="menu.x"
        :position-y="menu.y"
        absolute
        offset-y
        right
        :close-on-content-click="false"
        :close-on-click="false"
    >
        <v-card width="300">
            <v-card-title class="red white--text">
                {{ __('Ștergere rânduri selectate') }}
            </v-card-title>

            <v-divider></v-divider>

            <v-card-text class="my-2">
                <v-alert type="error" outlined>
                    {{ __('Sunteți sigur că doriți ștergerea rândurilor selectate?') }}
                </v-alert>
            </v-card-text>

            <v-divider></v-divider>

            <v-card-actions>
                <cs-btn 
                    caption="Șterge"
                    icon="mdi-delete"
                    color="red"
                    outlined
                    tooltip="Confirmă ștergerea"
                    :loading="app.requests.Deleterows.processing"
                    :disabled="app.requests.Deleterows.processing"
                    @click="OnClickSave"
                />

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

<script>
    export default {
        props: {
            app: {required: true},
            menu: {required: true},
        },

        methods: {
            OnClickSave() {
                this.app.requests.Deleterows.ResetData().SetData(
                    {
                        row_id: this.menu.row_id,
                        status: this.status,
                    }
                ).Request([
                    response => {

                        let registru = {...this.app.classes.Customerregistru.activeRegistru};

                        this.app.dataSession.Registrelemele.GetByCustomerIdAndRegistruId(this.app.payload.customer_id, this.app.payload.registru_id);

                        let i = setInterval( () => {

                            if(! this.app.dataSession.Registrelemele.processing )
                            {
                                clearInterval(i);

                                let item = _.find(this.app.dataSession.Registrelemele.items, item => item.id == registru.id);
                                this.app.classes.Customerregistru.activeRegistru = item;

                                this.app.classes.Customerregistru.selectedrows = [];

                                this.OnClickCancel();
                            }
                        }, 350);
                        
                    }
                ])
            },

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

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

        name: 'DeleteRows',
    }
</script>