import ngModule from '../module';

class Controller {
    constructor($http, $stateParams) {
        Object.assign(this, {
            $http,
            $stateParams,
        });
    }

    $onInit() {
        this.reload();
    }

    reload() {
        let query = `api/Workers/${this.$stateParams.id}`;
        let filter = {
            include: [
                {
                    relation: 'user',
                    scope: {fields: ['name', 'email']}
                }, {
                    relation: 'client',
                    scope: {fields: ['fi']}
                }, {
                    relation: 'department',
                    scope: {fields: ['department']}
                }, {
                    relation: 'sip',
                    scope: {fields: ['extension']}
                }
            ]
        };

        this.$http.get(query, {params: {filter}}).then(res => {
            this.worker = res.data;
        });
    }
}

Controller.$inject = ['$http', '$stateParams'];

ngModule.component('vnWorkerCard', {
    template: require('./index.html'),
    controller: Controller
});