import ngModule from '../module';
import Summary from 'salix/components/summary';
class Controller extends Summary {
    get worker() {
        return this._worker;
    }

    set worker(value) {
        this._worker = value;
        this.$.worker = null;
        if (!value) return;

        const query = `Workers/${value.id}`;
        const filter = {
            include: [
                {
                    relation: 'user',
                    scope: {
                        fields: ['name', 'roleFk'],
                        include: [{
                            relation: 'role',
                            scope: {
                                fields: ['name']
                            }
                        },
                        {
                            relation: 'emailUser',
                            scope: {
                                fields: ['email']
                            }
                        }]
                    }
                },
                {
                    relation: 'client',
                    scope: {fields: ['fi', 'phone']}
                },
                {
                    relation: 'boss',
                    scope: {fields: ['id', 'name']}
                },
                {
                    relation: 'sip',
                    scope: {fields: ['extension']}
                },
                {
                    relation: 'department',
                    scope: {
                        include: {
                            relation: 'department',
                            scope: {fields: ['id', 'code', 'name']}
                        }
                    }
                }
            ]
        };

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

    get isHr() {
        return this.aclService.hasAny(['hr']);
    }
}

ngModule.vnComponent('vnWorkerSummary', {
    template: require('./index.html'),
    controller: Controller,
    bindings: {
        worker: '<'
    }
});