(function () {
    global.dashModule
        .controller('removeBidCtrl', ['$scope', '$http', '$', '$translate', 'utilsService', removeBidCtrl]);

    function removeBidCtrl($scope, $http, $, $translate, utilsService) {
        $scope.removeBid = removeBid;

        function removeBid(params){
            $http({
                method: 'POST',
                url: 'bids/api/removeBid',
                data: $.param({
                    idBid: params.bid.idBid
                })
            }).then((response)=>{displayMessage(response, params.getBids);} , utilsService.onHttpError);
        }

        function displayMessage(response, callback){
            if (typeof response.data.messages !== 'undefined') {
                response.data.messages.forEach((messageObj) => {
                    const translatedMessage = $translate.instant('bids.messages.' + messageObj.message);
                    utilsService.displayMessage(messageObj.code, translatedMessage);
                    if(messageObj.code === 'success'){
                        callback();
                    }
                });
            }
        }
    }
})();
