var modal_helper = angular.module('picard.modal', []);

modal_helper.factory('numPadHelper', [, function () {
    return {
        addDigitInt: function ($scope, digit) {
            $scope.amount = $scope.amount * 10 + digit;
        },
        addDigitFloat: function ($scope, digit) {
            var decimals = $scope.amount.toString().split('.');
            if (decimals.length !== 2) {
                $scope.amount = $scope.amount * 10 + digit;
            } else {
                $scope.amount = parseFloat($scope.amount.toString() + digit);
            }
        },
        delDigit: function ($scope) {
            if ($scope.amount !== 0) {
                var amt = $scope.amount.toString();
                $scope.amount = Number(amt.substr(0, amt.length - 1));
            }
        },
        addDecimal: function ($scope) {
            if ($scope.amount % 1 === 0) {

            }
            if ($scope.amount.indexOf('.') !== -1) {
                return;
            }
            if ($scope.amount.length === 0) {
                $scope.amount = '0';
            }
            $scope.amount += '.';
        }
    }
}]);
