<template>
    <customer-notificari-page 
        v-if="isCustomersBooted && activeCustomer"
        :app="app"
        :customer="activeCustomer"
    />
    <cs-centered-alert
        v-else
        :height="app.height"
        :width="app.width"
        message="Se încarcă..."
    >
        <v-progress-circular
            indeterminate
            color="orange darken-1"
        >
        </v-progress-circular>
    </cs-centered-alert>
</template>

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

        methods: {
            
            /**
             * Incarca resursele necesare: clase, providere, etc
             */
            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.AddRequestsByContext(require.context('./../../Requests', true, /\.request.js$/i));
            },

            /**
             * Se ataseaza formprovider-ele la formulare
             */
            InitForms() {
                // this.app.forms.Customers.SetFormProvider(this.app.formproviders.Customers);
                
                // this.app.forms.Files.SetFormProvider( this.app.formproviders.Files );
                // this.app.forms.Folders.SetFormProvider( this.app.formproviders.Folders );

                // this.app.forms.Departments.SetFormProvider( this.app.formproviders.Departments );

                // this.app.forms.Contracte.SetFormProvider( this.app.formproviders.Contracte );
                // this.app.forms.Orders.SetFormProvider( this.app.formproviders.Orders );
                // this.app.forms.Services.SetFormProvider( this.app.formproviders.Services );

                // this.app.forms.Accounts.SetFormProvider( this.app.formproviders.Accounts );

                // this.app.forms.Users.SetFormProvider( this.app.formproviders.Users );
            },

            /**
             * Ca fac coloane editabile
             */
            InitEditableColumns() {
               
            },

            /**
             * atasez dataproviderul la datatable
             */
            InitDatatable() {
                // this.app.datatables.Customers.RegisterDataProvider(this.app.dataSession.Customers);

                // let columns =  this.app.datatables.Customers._columns;

                // columns['name-column'].editable.AttachForm(this.app.forms.Customers)
                // columns['email-column'].editable.AttachForm(this.app.forms.Customers)
                // columns['phone-column'].editable.AttachForm(this.app.forms.Customers)
                // columns['logo-column'].editable.AttachForm(this.app.forms.Customers)
                // columns['status-column'].AttachForm(this.app.forms.Customers)
                
                // this.app.datatables.Departments.RegisterDataProvider(this.app.dataSession.Departments);
                // this.app.datatables.Contracte.RegisterDataProvider(this.app.dataSession.Contracte);
                // this.app.datatables.Orders.RegisterDataProvider(this.app.dataSession.Orders);
                // this.app.datatables.Services.RegisterDataProvider(this.app.dataSession.Services);
                // this.app.datatables.Accounts.RegisterDataProvider(this.app.dataSession.Accounts);
            },

            /**
             * Filtering
             */
            InitFiltering() {
                /**
                 * formularul de filtrare își inregistreaza dataprovider-ul
                 */
                // this.app.filterForms.Customers.RegisterDataProvider(this.app.dataSession.Customers);

                // /**
                //  * La coloana name atasez filter controlul name din formularul de filtrare, etc
                //  */
                // let columns =  this.app.datatables.Customers._columns;

                // columns['name-column']._header.filterable.AttachFilterControl(
                //     this.app.filterForms.Customers.controls.name
                // );
                // columns['status-column']._header.filterable.AttachFilterControl(
                //     this.app.filterForms.Customers.controls.status
                // );
            },

            LoadData() {
                /** Incarc clientul */
                this.app.dataSession.Customers.Post();
                // /**  Incarc starile clientilor (customers-statuses) */
                // this.app.dataSession.Customersstatuses.Post();
                // /** ashboard items */
                // this.app.dataSession.Dashboarditems.Post();
            }
        },

        created() {
            this.LoadResources();
            this.InitForms();
            // this.InitEditableColumns();
            this.InitDatatable();
            this.InitFiltering();
            
            this.LoadData();

            /***
             * De sters. Simulez ajungerea pe dashboard
             */
            // if(this.app.config.env == 'local')
            // {
                // let i = setInterval(() => {


                   

                //     if(this.app.dataSession.Customers.items.length > 0 && this.app.dataSession.Dashboarditems.items.length)
                //     {
                        // clearInterval(i);

                        // this.app.menus.Customerstoolbar.options.Insert.Click();


                        // this.app.classes.Controller.currentComponent = 'customer-insert-page';

            //         this.app.datatables.Customers.OnClickRow({
            //             item: this.app.dataSession.Customers.items[1],
            //         });

            //         /**
            //          * Statistica
            //          * Sa vedem cum se refresheaza
            //          */
            //         this.app.classes.Controller.GetSummaryes();

            //         setTimeout(() => {

            //             // const item = this.app.dataSession.Dashboarditems.items[0];
                        
            //             // this.app.classes.Controller.activeDashboardItem = item;
            //             // this.app.classes.Controller.currentComponent = 'customer-dashboard-active-page';

            //             this.app.classes.Controller.currentComponent = 'customer-dashboard-page';

            //             // this.app.classes.Controller.currentComponent = 'customer-departments-page';

            //             // this.app.classes.Controller.currentComponent = 'customer-accounts-page';

            //             // this.app.classes.Controller.currentComponent = 'customer-contracte-page';

            //         }, 50)
                    
                    // }
                // }, 100)
            // }
        },

        components: {
            CsCenteredAlert: require('@CsVueComp/sheets/CsCenteredAlert').default,
            // CustomersPage: require('./../components/CustomersPage').default,

            // CustomerDashboardPage: require('@MyDpoComp/Entities/Customer/Dashboard/CustomerDashboardPage').default,
            
            // //CustomerDepartmentsPage: require('@MyDpoComp/Entities/CustomerDepartments/CustomerDepartmentsPage').default,
            // // CustomerAccountsPage: require('@MyDpoComp/Entities/CustomerAccounts/CustomerAccountsPage').default,
        },

        name: 'Index',
    }
</script>