<template>
    <v-card
        tile
        flat
        :height="height"
        :class="{
            'overflow-y-auto': !! height
        }"
    >
        <v-card-text class="px-0">

            <customers-autocomplete 
                :items="customersOptions"
                v-model="customer_id"
            />

            {{ customer_id }}
            <hr/>

            {{ foldersOrderCode }}
            {{ user.my_settings }}
        </v-card-text>
    </v-card>
</template>

<script>
    export default {
        props: {
            height: {default: null},
            app: {required: true},
            user: {required: true},
        },

        data: () => ({
            customer_id: null,
            folders: [],
        }),

        computed: {

            foldersOrderCode() {
                return this.customer_id ? 'b2b-' + this.customer_id + '-customer-folders-order' : null;
            },

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

            accountsdataprovider() {
                return this.app.dataSession.Accounts;
            },

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

            items() {
                return this.dataprovider.items;
            },

            customersOptions() {
                return this.accountsdataprovider.customersOptions;
            },
        },

        watch: {
            customer_id: function(customer_id) {
                if( ! customer_id )
                {
                    this.folders = [];
                }
                else
                {
                    this.GetFolders(customer_id)
                }
            },
        },

        methods: {
            GetFolders(customer_id) {
                this.foldersdataprovider.GetByCustomerId(customer_id);

                let i = setInterval( () => {
                    if(! this.foldersdataprovider.processing )
                    {
                        clearInterval(i);

                        if(_.has(this.user.my_settings, this.foldersOrderCode))
                        {   
                        }

                    }
                }, 300);
            }
        },

        name: 'UserFoldersPermissions',
    }
</script>