var Helper;
(function (Helper) {
    /**
     * FormatHelper to add 1000 Delimiter
     */
    class FormatHelper {
        oldVal;
        /**
         * Constructor adds all events to the functions
         */
        constructor() {
            $(".number-separated").keyup((e) => this.add1000Separator(e));
            $(".number-separated").focus((e) => this.onFocusSaveOriginalVal(e));
            $(".number-separated").focusout((e) => this.onFocusLooseCheckOriginalVal(e));
            //$(".number-separated").val((index: number, value: string) => FormatHelper.Remove1000Separator(index, value));
            //$.fn.val = ((value: object) => this.removeSeparator(value));
            /*jQuery.fn.extend({
                val: function (value) {
                    const $this = $(this);
                    
                    if ($(this).hasClass("number-separated")) {
                        var originalValue: string = $this.attr("value");
                        originalValue += "";
                        originalValue = originalValue.replace(/[^0-9\.]/g, "");
                        originalValue = originalValue.replace(/'/g, "");

                        return originalValue;
                    }

                    return value;
                }
            });*/
        }
        /**
         * Adds the 1000 separator to the inputs
         * @param {Event} e
         */
        add1000Separator(e) {
            var originalValue = $(e.currentTarget).val();
            originalValue += "";
            let minusSign = "";
            if (originalValue.length > 0 && originalValue[0] == "-") {
                minusSign = "-";
            }
            originalValue = originalValue.replace(/[^0-9\.]/g, "");
            var x = originalValue.split(".");
            var x1 = x[0];
            var x2 = x.length > 1 ? "." + x[1] : "";
            var x1 = x1.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1'");
            $(e.currentTarget).val(minusSign + x1 + x2);
            //$(e.currentTarget).val(x1 + x2);
        }
        /**
         * Sets the data attribute with original value, to check on loose focus if something changed and trigger the change event
         * @param {Event} e
         */
        onFocusSaveOriginalVal(e) {
            $(e.currentTarget).data("original-value", $(e.currentTarget).val());
        }
        /**
         * Event checks when the focus is lost, if the val has changed
         * @param {Event} e
         */
        onFocusLooseCheckOriginalVal(e) {
            var originalVal = $(e.currentTarget).data("original-value");
            var newValue = $(e.currentTarget)[0].value;
            newValue = newValue.replace(/'/g, "");
            if (newValue != originalVal) {
                $(e.currentTarget).change();
            }
        }
    }
    Helper.FormatHelper = FormatHelper;
})(Helper || (Helper = {}));
//# sourceMappingURL=FormatHelper.js.map