<template>
    <v-card tile flat :width="app.width">
        
        <v-card-title class="pt-0">
            {{  __('Utilizatori platformă') }} 
        </v-card-title>

        <v-sheet class="d-flex justify-center py-3" v-if="loading">
            <v-progress-circular
                indeterminate
                color="orange darken-3"
            >
            </v-progress-circular>
        </v-sheet>

        <v-card v-else tile flat class="d-flex" :width="app.width" :disabled="Utilizatori.Menus.visible || Utilizatori.Forms.visible">

            <users-sidebar :app="app" :width="Utilizatori.Layout.sidebar.width"/>

            <user-desktop :app="app" :width="'calc(100% - ' + Utilizatori.Layout.sidebar.width + 'px)'"/>

        </v-card>

        <div v-for="(menu, index) in Utilizatori.Menus.menus" :key="'menu-' + index">
            <component 
                v-if="menu.visible"
                :is="menu.component" 
                :menu="menu" 
                :app="app"
            >
            </component>
        </div>

        <div v-for="(item, index) in Utilizatori.Forms.items" :key="'form-' + index">
            <component 
                v-if="app.forms[item.name].menu.visible"
                :is="item.component" 
                :form="app.forms[item.name]" 
                :app="app"
            >
            </component>
        </div>

        <right-menu 
            v-for="(menukey, index) in Utilizatori.Rightmenus.items" :key="'rightmenu-' + index"
            :menu="app.menus[menukey]"
        />
    </v-card>
    
</template>

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

        computed: {

            loading() {

                let dataSessions = ['Users', 'Customers', 'Permissions'];

                let r = false;
                
                _.each(dataSessions, item => {

                    if(this.app.dataSession[item].request_count < 1)
                    {
                        r = true;
                    }

                    if(this.app.dataSession[item].progressing)
                    {
                        r = true;
                    }

                })

                return r;
               
            }
        },

        methods: {

            LoadResources() {
                this.app.AddClassesByContext(require.context('./../../Classes', true, /\.class.js$/i));
                this.app.AddDataProvidersByContext(require.context('./../../DataSessions', true, /\.dataprovider.js$/i));
                this.app.AddDatatablesByContext(require.context('./../../Datatables', true, /\.datatable.js$/i));
                this.app.AddFormProvidersByContext(require.context('./../../FormProviders', true, /\.formprovider.js$/i));                
                this.app.AddFormsByContext(require.context('./../../Forms', true, /\.form.js$/i));
                this.app.AddFilterFormsByContext(require.context('./../../Filterforms', true, /\.filterform.js$/i));
                this.app.AddMenusByContext(require.context('./../../Toolbars', true, /\.toolbar.js$/i));
                this.app.AddMenusByContext(require.context('./../../Menus', true, /\.menu.js$/i));
                this.app.AddMenusByContext(require.context('./../../Breadcrumbs', true, /\.breadcrumbs.js$/i));
                this.app.AddRequestsByContext(require.context('./../../Requests', true, /\.request.js$/i));
            },
        },

        
        created() {
            this.LoadResources();

            this.Utilizatori.Forms.Init();

            this.app.dataSession.Customers.Post();
            this.app.dataSession.Users.Post();
            this.app.dataSession.Permissions.GetRootPermissions();
        },

        components: {
            RightMenu: require('@CsVueComp/menus/rightmenu/RightMenu').default,
        },

        name: 'Index',
    }
</script>