"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputCounter = void 0;
var react_1 = __importStar(require("react"));
var Utils_1 = require("@devesharp/react-utils/lib/Utils");
var faMinusCircle_1 = require("@fortawesome/free-solid-svg-icons/faMinusCircle");
var faPlusCircle_1 = require("@fortawesome/free-solid-svg-icons/faPlusCircle");
var react_fontawesome_1 = require("@fortawesome/react-fontawesome");
var Input_1 = require("../Input");
var InputCounter_style_1 = __importDefault(require("./InputCounter.style"));
exports.InputCounter = react_1.default.forwardRef(function InputCounter(_a, ref) {
    var name = _a.name, title = _a.title, _b = _a.withoutDotNumber, withoutDotNumber = _b === void 0 ? true : _b, onEnter = _a.onEnter, value = _a.value, onInput = _a.onInput, rest = __rest(_a, ["name", "title", "withoutDotNumber", "onEnter", "value", "onInput"]);
    var input = (0, react_1.useRef)(null);
    function addNumber() {
        if (value == undefined) {
            var getValue = Number((0, Utils_1.OnlyNumbers)(input.current.value));
            input.current.value = (getValue + 1);
            if (onInput)
                onInput(input.current.value);
        }
        else if (onInput) {
            onInput(value + 1);
        }
    }
    function subNumber() {
        if (value == undefined) {
            var getValue = Number((0, Utils_1.OnlyNumbers)(input.current.value));
            input.current.value = (getValue <= 0 ? 0 : getValue - 1);
            if (onInput)
                onInput(input.current.value);
        }
        else if (onInput) {
            onInput((value <= 0 ? 0 : value - 1));
        }
    }
    return (react_1.default.createElement(InputCounter_style_1.default, null,
        react_1.default.createElement(Input_1.Input, __assign({ ref: input }, rest, { name: name, title: title, onEnter: onEnter, mask: "number", decimals: 0, withoutDotNumber: withoutDotNumber, textCenter: true, value: value, onInput: onInput, prefix: react_1.default.createElement("div", { className: "button-action", onClick: subNumber, "data-testid": "sub-number" },
                react_1.default.createElement(react_fontawesome_1.FontAwesomeIcon, { icon: faMinusCircle_1.faMinusCircle })), suffix: react_1.default.createElement("div", { className: "button-action", onClick: addNumber, "data-testid": "add-number" },
                react_1.default.createElement(react_fontawesome_1.FontAwesomeIcon, { icon: faPlusCircle_1.faPlusCircle })) }))));
});
//# sourceMappingURL=InputCounter.js.map