import ngModule from '../module';

class Controller {
    constructor($scope, $stateParams) {
        this.$scope = $scope;
        this.$stateParams = $stateParams;
        this.filter = {
            include: [{
                relation: 'item'
            },
            {
                relation: 'isChecked',
                scope: {
                    fields: ['isChecked']
                }
            }]
        };
    }

    showDescriptor(event, itemFk) {
        this.quicklinks = {
            btnThree: {
                icon: 'icon-transaction',
                state: `item.card.diary({
                    id: ${itemFk}, 
                    warehouseFk: ${this.ticket.warehouseFk},
                    ticketFk: ${this.ticket.id}
                })`,
                tooltip: 'Item diary'
            }
        };
        this.$scope.descriptor.itemFk = itemFk;
        this.$scope.descriptor.parent = event.target;
        this.$scope.descriptor.show();
    }

    onDescriptorLoad() {
        this.$scope.popover.relocate();
    }
}

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

ngModule.component('vnTicketSaleChecked', {
    template: require('./index.html'),
    controller: Controller,
    bindings: {
        ticket: '<'
    }
});