<template>
    <v-card tile flat>
        <index-page 
            :app="app"
            :controller="controller"
            :disabled="controller.assignusermenu.visible"
        >
            <template #append-breadcrumbs>
                <customer-entities-popup 
                    :menu="app.menus.Entitiespopup"
                />
            </template>

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

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

        <assign-user-menu 
            v-if="controller.assignusermenu.visible"
            :app="app"
            :menu="controller.assignusermenu"
        />

    </v-card>
</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.controller.FormRegisterFormProvider('Departamente');
                this.controller.FormRegisterFormProvider('Users');
                this.app.forms.Accountstatus.SetFormProvider(this.app.formproviders.Accountstatus);
                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.Accountstatus);
                columns['role-column'].editable.AttachForm(this.app.forms.Accountsrole);
                columns['avatar-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['departament-column'].editable.AttachForm(this.app.forms.Accounts);
                
            },

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

            LoadData() {
                this.app.dataSession.Customers.GetById(this.controller.customer_id);
                this.app.dataSession.Roles.GetByType('b2b');
            }
        },

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

        name: 'Index',
    }
</script>