<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>
                {{ __('Mutarea fișierelor selectate') }}
                <v-spacer></v-spacer>

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

            <v-card-text>
                <folder-selector-input 
                    :folders="folders"
                    v-model="destinationFolder"
                />
            </v-card-text>
   
            <v-divider></v-divider>

            <v-card-actions>
                <cs-btn 
                    color="bg-dark-blue"
                    caption="Mută"
                    outlined
                    :click="OnClickMove"
                    :disabled="! destinationFolder"
                />

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

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

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

        computed: {

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


            folders() {
                return this.app.dataSession.Folders.items;
            },

            request() {
                return this.app.requests.Movefiles;
            },

        },

        methods: {
            OnClickMove() {
                let data = {
                    files: this.uploader.selectedFilesManager.selectedFiles,
                    folder_id: this.destinationFolder,
                }

                this.request
                    .ResetData()
                    .SetData(data)
                    .Post([
                        response => {
                            this.menu.visible = false;
                            this.uploader.selectedFilesManager.selectedFiles = [];
                            this.uploader.Refreshfolders();
                            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,
        },

        name: 'FilesMoveMenu',
    }
</script>