<template>
    <permissions-page
        v-if="isBooted"
        :app="app"
    />

    <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},
        },

        computed: {

            isBooted() {
                return this.app.classes.Controller.isBooted;
            }
        },

        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.Permissions.SetFormProvider(this.app.formproviders.Permissions);
                this.app.forms.Children.SetFormProvider(this.app.formproviders.Children);
            },

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

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

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

                // columns['last_name-column'].editable.AttachForm(this.app.forms.Users)
                // columns['email-column'].editable.AttachForm(this.app.forms.Users)
                // columns['phone-column'].editable.AttachForm(this.app.forms.Users)
                // columns['avatar-column'].editable.AttachForm(this.app.forms.Users)
                // columns['active-column'].AttachForm(this.app.forms.Users)

            },

            /**
             * Filtering
             */
            InitFiltering() {
                // this.app.filterForms.Users.RegisterDataProvider(this.app.dataSession.Users);

                // let columns =  this.app.datatables.Users._columns;
                // let controls = this.app.filterForms.Users.controls

                // columns['email-column']._header.filterable.AttachFilterControl(controls.email);
                // columns['active-column']._header.filterable.AttachFilterControl(controls.status);
                // columns['last_name-column']._header.filterable.AttachFilterControl(controls.last_name);
                // columns['first_name-column']._header.filterable.AttachFilterControl(controls.first_name);
            },

            LoadData() {
                // this.app.dataSession.Roles.Post();
                this.app.dataSession.Permissions.GetRootPermissions();
            }
        },

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

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

        name: 'Index',
    }
</script>