<template>
    <index-page :app="app" :controller="controller">
        <template #append-breadcrumbs>
        </template>

        <template #prepend>
            <account-form-menu :app="app" :form="controller.form" />

            <accounts-filter-menu :app="app" :filterform="controller.filterform" />
        </template>
    </index-page>
    
</template>

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

        computed: {
            controller() {
                return this.app.classes.Accounts;
            }
        },

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

            InitDatatable() {
                this.controller.DatatableRegisterDataProvider(this.controller.model);
            },

            InitForms() {
                this.controller.FormRegisterFormProvider(this.controller.model);

                this.app.forms.Users.SetFormProvider(this.app.formproviders.Users);
                // this.app.forms.Usersstatus.SetFormProvider(this.app.formproviders.Usersstatus);
                this.app.forms.Usersstatus.SetFormProvider(this.app.formproviders.Accountsrole);
                this.app.forms.Accountsrole.SetFormProvider(this.app.formproviders.Accountsrole);

                let columns = this.app.datatables.Accounts._columns;
                
                columns['last_name-column'].editable.AttachForm(this.app.forms.Users);

                // columns['active-column'].editable.AttachForm(this.app.forms.Usersstatus);
                columns['active-column'].editable.AttachForm(this.app.forms.Accountsrole);

                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['role-column'].editable.AttachForm(this.app.forms.Accountsrole);
            },

            InitFiltering() {
                this.controller.FilterformRegisterDataProvider(this.controller.model);

                let columns = this.app.datatables.Accounts._columns;
                let controls = this.app.filterForms.Accounts.controls;

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

            LoadData() {
                this.app.dataSession.Roles.GetByType('b2b');
                this.app.dataSession.Customers.Get();
                this.app.dataSession.Accounts.Get();
            }
        },

        mixins: [
            require('VUEMIX/Index/IndexPage'),
        ],

        name: 'Index',
    }
</script>