"use strict";
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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = NumberIncrement;
const react_1 = __importDefault(require("react"));
const Icon_1 = __importStar(require("./Icon/Icon"));
const Text_1 = __importStar(require("./Text"));
const Tooltip_1 = __importDefault(require("./Tooltip/Tooltip"));
function NumberIncrement(props) {
    const { textSize = Text_1.TextType.Body, hideTooltips } = props;
    const currentNumber = props.number ? props.number : 0;
    const setNumber = (newNumber) => {
        if (props.onChange) {
            props.onChange(newNumber);
        }
    };
    const updateCurrentNumber = (increment) => {
        let newNumber = currentNumber + (increment ? 1 : -1);
        if (increment) {
            if (typeof props.max === 'number' && newNumber >= props.max) {
                newNumber = props.max;
            }
        }
        else {
            if (typeof props.min === 'number' && newNumber <= props.min) {
                newNumber = props.min;
            }
        }
        setNumber(newNumber);
    };
    const decrementCurrentNumber = () => {
        updateCurrentNumber(false);
    };
    const incrementCurrentNumber = () => {
        updateCurrentNumber(true);
    };
    const decreaseButton = (react_1.default.createElement("div", { className: 'number-increment--button' + (currentNumber <= (props.min || 0) ? ' disabled' : ''), onClick: decrementCurrentNumber },
        react_1.default.createElement(Icon_1.default, { icon: Icon_1.IconType.Remove, size: "24px" })));
    const increaseButton = (react_1.default.createElement("div", { className: 'number-increment--button' + (currentNumber >= (props.max || 0) ? ' disabled' : ''), onClick: incrementCurrentNumber },
        react_1.default.createElement(Icon_1.default, { icon: Icon_1.IconType.Add, size: "24px" })));
    return (react_1.default.createElement("div", { className: "number-increment" },
        hideTooltips ? decreaseButton : react_1.default.createElement(Tooltip_1.default, { title: currentNumber <= (props.min || 0) ? 'Minimum reached' : 'Remove' }, decreaseButton),
        react_1.default.createElement("div", { className: "number-increment--value" },
            react_1.default.createElement(Text_1.default, { type: textSize }, currentNumber)),
        hideTooltips ? increaseButton : react_1.default.createElement(Tooltip_1.default, { title: currentNumber >= (props.max || 0) ? 'Maximum reached' : 'Add' }, increaseButton)));
}
//# sourceMappingURL=NumberIncrement.js.map