var _iconLookup;
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import React from 'react';
import capitalize from 'lodash/capitalize';
import { IconAdd, IconRemove } from '@defencedigital/icon-library';
import { Decimal } from 'decimal.js';
import { InlineButton } from '../InlineButtons/InlineButton';
import { NUMBER_INPUT_BUTTON_TYPE } from './constants';
import { StyledDivider } from './partials/StyledDivider';
import { StyledInlineButtons } from '../InlineButtons/partials/StyledInlineButtons';
var iconLookup = (_iconLookup = {}, _defineProperty(_iconLookup, NUMBER_INPUT_BUTTON_TYPE.DECREASE, /*#__PURE__*/React.createElement(IconRemove, {
  size: 18
})), _defineProperty(_iconLookup, NUMBER_INPUT_BUTTON_TYPE.INCREASE, /*#__PURE__*/React.createElement(IconAdd, {
  size: 18
})), _iconLookup);
export var Buttons = function Buttons(_ref) {
  var isDisabled = _ref.isDisabled,
    onClick = _ref.onClick,
    size = _ref.size,
    step = _ref.step,
    value = _ref.value;
  function handleClick(event, isDecrease) {
    // Do nothing if the value is e.g. only `-`
    if (value && !Number.isFinite(parseFloat(value))) {
      return;
    }
    var decimal = new Decimal(value || 0);
    var newValue = (isDecrease ? decimal.minus(step) : decimal.plus(step)).toString();
    onClick(event, newValue);
  }
  return /*#__PURE__*/React.createElement(StyledInlineButtons, null, /*#__PURE__*/React.createElement(InlineButton, {
    "aria-label": "".concat(capitalize(NUMBER_INPUT_BUTTON_TYPE.DECREASE), " the input value"),
    isDisabled: isDisabled,
    onClick: function onClick(event) {
      return handleClick(event, true);
    },
    size: size
  }, iconLookup[NUMBER_INPUT_BUTTON_TYPE.DECREASE]), /*#__PURE__*/React.createElement(StyledDivider, {
    $size: size
  }), /*#__PURE__*/React.createElement(InlineButton, {
    "aria-label": "".concat(capitalize(NUMBER_INPUT_BUTTON_TYPE.INCREASE), " the input value"),
    isDisabled: isDisabled,
    onClick: function onClick(event) {
      return handleClick(event, false);
    },
    size: size
  }, iconLookup[NUMBER_INPUT_BUTTON_TYPE.INCREASE]));
};
Buttons.displayName = 'Buttons';