function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React from 'react';
import { Button, InputNumber } from 'antd';
import classNames from 'classnames';
import { locales } from '@pisell/utils';
import NumberKeyboard from "../../pro/keyboards/numberKeyboard";
import localeTexts from "./locales";
import { PisellModal } from '@pisell/materials';
import CashCountingModal from "./components/CashCountingModal/index";
import useEngineContext from "../../hooks/useEngineContext";
import { usePisellCashCounting } from "./hooks";
import "./PisellCashCounting.less";
var PREFIX = 'pisell-private-cash-counting';
var PisellCashCounting = function PisellCashCounting(props) {
  var _context$engine;
  var context = useEngineContext();
  locales.init(localeTexts, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || 'en');
  var _props$disabled = props.disabled,
    disabled = _props$disabled === void 0 ? false : _props$disabled,
    _props$countDisabled = props.countDisabled,
    countDisabled = _props$countDisabled === void 0 ? false : _props$countDisabled,
    placeholder = props.placeholder,
    _props$layout = props.layout,
    layout = _props$layout === void 0 ? 'vertical' : _props$layout,
    countCashButtonText = props.countCashButtonText,
    _props$showCurrencySy = props.showCurrencySymbol,
    showCurrencySymbol = _props$showCurrencySy === void 0 ? true : _props$showCurrencySy,
    _props$useThousandsSe = props.useThousandsSeparator,
    useThousandsSeparator = _props$useThousandsSe === void 0 ? false : _props$useThousandsSe,
    inputNumberProps = props.inputNumberProps,
    buttonProps = props.buttonProps,
    className = props.className,
    style = props.style,
    modalWidth = props.modalWidth;
  var _usePisellCashCountin = usePisellCashCounting(props),
    modalRef = _usePisellCashCountin.modalRef,
    triggerRef = _usePisellCashCountin.triggerRef,
    keyboardOpen = _usePisellCashCountin.keyboardOpen,
    setKeyboardOpen = _usePisellCashCountin.setKeyboardOpen,
    currencyDenominations = _usePisellCashCountin.currencyDenominations,
    decimalPlaces = _usePisellCashCountin.decimalPlaces,
    symbol = _usePisellCashCountin.symbol,
    currencyCode = _usePisellCashCountin.currencyCode,
    currentValue = _usePisellCashCountin.currentValue,
    handleAmountChange = _usePisellCashCountin.handleAmountChange,
    handleKeyboardClose = _usePisellCashCountin.handleKeyboardClose,
    openCountModal = _usePisellCashCountin.openCountModal,
    handleCountCancel = _usePisellCashCountin.handleCountCancel,
    handleCountConfirm = _usePisellCashCountin.handleCountConfirm,
    manualCountMismatchOpen = _usePisellCashCountin.manualCountMismatchOpen,
    confirmUseCountedTotal = _usePisellCashCountin.confirmUseCountedTotal,
    confirmKeepManualAmount = _usePisellCashCountin.confirmKeepManualAmount;
  return /*#__PURE__*/React.createElement("div", {
    className: classNames(PREFIX, className),
    style: style
  }, /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(PREFIX, "__field"), _defineProperty({}, "".concat(PREFIX, "__field--horizontal"), layout === 'horizontal')),
    ref: triggerRef
  }, /*#__PURE__*/React.createElement(InputNumber, _extends({}, inputNumberProps, {
    controls: false,
    disabled: disabled,
    precision: decimalPlaces,
    value: currentValue,
    placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : locales.getText('pisell-cash-counting.placeholder'),
    className: classNames("".concat(PREFIX, "__input"), inputNumberProps === null || inputNumberProps === void 0 ? void 0 : inputNumberProps.className),
    readOnly: true,
    addonBefore: symbol,
    size: "large",
    style: {
      width: '100%'
    },
    onClick: function onClick() {
      if (!disabled) {
        setKeyboardOpen(true);
      }
    },
    onChange: handleAmountChange
  })), /*#__PURE__*/React.createElement(Button, _extends({}, buttonProps, {
    type: "primary",
    disabled: disabled || countDisabled || (buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.disabled),
    className: classNames("".concat(PREFIX, "__button"), buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.className),
    onClick: function onClick(event) {
      var _buttonProps$onClick;
      buttonProps === null || buttonProps === void 0 || (_buttonProps$onClick = buttonProps.onClick) === null || _buttonProps$onClick === void 0 || _buttonProps$onClick.call(buttonProps, event);
      openCountModal();
    }
  }), countCashButtonText !== null && countCashButtonText !== void 0 ? countCashButtonText : locales.getText('pisell-cash-counting.countCash'))), /*#__PURE__*/React.createElement(NumberKeyboard, {
    mode: "decimal",
    containerProps: {
      renderType: 'modal',
      open: keyboardOpen,
      onCancel: handleKeyboardClose
    },
    value: currentValue,
    originalValue: currentValue,
    maxLength: 10,
    precision: 2,
    onChange: handleAmountChange,
    onEnter: handleKeyboardClose
  }), /*#__PURE__*/React.createElement(PisellModal.Information, {
    open: manualCountMismatchOpen,
    closable: false,
    maskClosable: false,
    title: locales.getText('pisell-cash-counting.manual-vs-count-message-title'),
    describe: locales.getText('pisell-cash-counting.manual-vs-count-message'),
    okText: locales.getText('pisell-cash-counting.keep-manual-amount'),
    cancelText: locales.getText('pisell-cash-counting.use-count-total'),
    onOk: confirmKeepManualAmount,
    onCancel: confirmUseCountedTotal
  }), /*#__PURE__*/React.createElement(CashCountingModal, {
    ref: modalRef,
    modalWidth: modalWidth,
    currencyCode: currencyCode,
    currencyDenominations: currencyDenominations,
    decimalPlaces: decimalPlaces,
    symbol: symbol,
    onCancel: handleCountCancel,
    onConfirm: handleCountConfirm
  }));
};
export default PisellCashCounting;