<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="width"
            :height="height"
        >
            <v-card-title>
                {{ __('Ștergere fișiere selectate') }}
                <v-spacer></v-spacer>

                <cs-btn 
                    icon="mdi-close"
                    :click="() => menu.visible = false"
                />
            </v-card-title>

            <v-card-text>
                <cs-info-alert 
                    icon="mdi-help-circle-outline"
                    color="red"
                    :message="__('Sunteți sigur că vreți să ștergeți cele :x fișier(e) selectate?', {
                        x: selectedFiles.length,
                    })"
                />
            </v-card-text>

            <v-divider></v-divider>

            <v-card-actions>
                <cs-btn 
                    color="red"
                    caption="Șterge"
                    outlined
                    :click="OnClickDelete"
                />

                <v-spacer></v-spacer>
                
                <cs-btn-cancel 
                    :click="() => menu.visible = false"
                />
            </v-card-actions>
        </v-card>
    </v-menu>
</template>

<script>

    

    export default {
        
        props: {
            menu: {required: true},
            app: {required: true},
            width: {default: 420},
            height: {default: 186},
        },

        computed: {
            request() {
                return this.app.requests.Deletefiles;
            },

            dataprovider() {
                return this.app.dataSession.Customerfolders;
            },

            uploader() {
                return this.app.classes.Customeruploader;
            },

            customer() {
                return this.uploader.customer;
            },
            
            selectedFiles() {
                return this.uploader.selectedFilesManager.selectedFiles;
            },

        },

        methods: {
            OnClickDelete() {
                let data = {
                    files: this.selectedFiles,
                }
                this.request
                    .ResetData()
                    .SetData(data)
                    .Post([
                        response => {
                            this.uploader.selectedFilesManager.selectedFiles = [];
                            this.uploader.activeFileManager.activeFile = null;
                            this.menu.visible = false;
                            this.app.formproviders.Files.RefreshFolder(this.app.classes.Customeruploader.activeFolderManager.selectedFolder.id)
                        }
                    ]);
            }
        },

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

        name: 'FilesDeleteMenu',
    }
</script>