<template>
    <cs-centered-alert
        v-if="! controller.isBooted"
        :height="controller.height"
        :width="controller.width"
        message="Se încarcă..."
    >
        <v-progress-circular
            indeterminate
            color="orange darken-1"
        >
        </v-progress-circular>
    </cs-centered-alert>

    <v-card
        v-else
        tile
        flat
    >
        <v-card
            tile
            flat
            :height="app.height"
            :width="app.width"
            :disabled="
                controller.cursusersmenu.visible || 
                controller.cursfilesmenu.visible || 
                controller.cursparticipantsmenu.visible ||
                controller.sendcursurimenu.visible ||
                controller.desasocierecursurimenu.visible ||
                controller.deleteparticipantmenu.visible ||
                controller.deletefilemenu.visible
            "
        >
            <v-card-title 
                class="pa-0 primary--text text--darken-3"
            >
                {{ controller.title  }}
            </v-card-title>

            <v-card-title class="pa-0">
                <v-breadcrumbs 
                    v-if="controller.hasBreadcrumbs"
                    :items="controller.breadcrumbs" 
                    class="pa-0"
                >
                    <template v-slot:divider>
                        <v-icon>mdi-dots-vertical</v-icon>
                    </template>
                </v-breadcrumbs>
            </v-card-title>

            <cs-toolbar 
                v-if="controller.hasToolbar" 
                :toolbar="controller.toolbar"
            >
            </cs-toolbar>

            <v-card
                tile
                flat
                :height="app.height - 112"
                :width="app.width"
            >
                <data-table 
                    :app="app"
                    :dataprovider="app.dataSession.Cursuriatasate"
                    :datatable="app.datatables.Cursuriatasate"
                    :height="app.height - 112"
                    :width="app.width"
                    :dtWidth="app.datatables.Cursuriatasate.dtWidth"
                />
            </v-card>

        </v-card>

        <curs-users-menu 
            :app="app"
            :menu="controller.cursusersmenu"
        />

        <curs-files-menu 
            :app="app"
            :menu="controller.cursfilesmenu"
            :disabled="controller.uploadfilemenu.visible || controller.previewcursmenu.visible"
        />

        <curs-participants-menu 
            :app="app"
            :menu="controller.cursparticipantsmenu"
            :disabled="controller.importparticipantsmenu.visible"
        />

        <import-participants-menu 
            :app="app"
            :menu="controller.importparticipantsmenu"
        />

        <upload-file-menu 
            :app="app"
            :menu="controller.uploadfilemenu"
        />

        <send-cursuri-menu 
            :app="app"
            :menu="controller.sendcursurimenu"
        />

        <desasociere-cursuri-menu 
            :app="app"
            :menu="controller.desasocierecursurimenu"
        />

        <trimitere-form-menu 
            :app="app"
            :form="app.forms.Share"
            target="customer-cursuri"
        />

        <preview-curs-menu 
            :app="app"
            :menu="controller.previewcursmenu"
        />

        <delete-user-menu 
            :app="app"
            :menu="controller.deleteusermenu"
        />

        <delete-participant-menu 
            :app="app"
            :menu="controller.deleteparticipantmenu"
        />

        <delete-file-menu 
            :app="app"
            :menu="controller.deletefilemenu"
        />

    </v-card>

</template>

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

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

        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.app.datatables.Cursuriatasate.RegisterDataProvider(this.app.dataSession.Cursuriatasate);
                this.app.datatables.Cursuriusers.RegisterDataProvider(this.app.dataSession.Customercursuriuser);
                this.app.datatables.Cursurifiles.RegisterDataProvider(this.app.dataSession.Customercursurifiles);
                this.app.datatables.Cursuriparticipants.RegisterDataProvider(this.app.dataSession.Customercursuriparticipants);

                this.app.forms.Share.SetFormProvider(this.app.formproviders.Share);
            },

            LoadData() {
                this.app.dataSession.Customers.GetById(this.controller.customer_id);
                this.app.dataSession.Cursuriatasate.GetByCustomerId(this.controller.customer_id);
                this.app.dataSession.Customercursuriuser.request_count = 1;
            }
        },

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

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

        name: 'Index',
    }
</script>