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

        <template #prepend>
            <customer-form-menu 
                v-if="controller.form.visible"
                :app="app"
                :form="controller.form"
            />

            <customers-filter-menu 
                :app="app"
                :filterform="controller.filterform"
            />

            <customer-status-form-menu 
                :form="app.forms.Customersstatus"
                :statuses="app.dataSession.Customerstatuses.items"
            />
        </template>
    </index-page>
</template>

<script>


    export default {
        props: {
            app: {require: true},
        },

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

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

                let formprovider = {
                    ...this.app.formproviders[this.controller.model],
                }

                this.app.forms.Customersstatus.SetFormProvider(formprovider);

                this.controller.MakeEditableColumn(this.controller.model, 'logo-column');
                this.controller.MakeEditableColumn(this.controller.model, 'name-column');
                this.controller.MakeEditableColumn(this.controller.model, 'email-column');
                this.controller.MakeEditableColumn(this.controller.model, 'phone-column');


                let columns =  this.app.datatables.Customers._columns;
                columns['status-column'].AttachForm(this.app.forms.Customersstatus)

            },

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

            LoadData() {
                this.app.dataSession.Customers.Refresh();
                this.app.dataSession.Customerstatuses.Get();
            }
        },

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

        name: 'Index',
    }
</script>