var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellCashCounting/PisellCashCounting.tsx
var PisellCashCounting_exports = {};
__export(PisellCashCounting_exports, {
  default: () => PisellCashCounting_default
});
module.exports = __toCommonJS(PisellCashCounting_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_pisellPriceKeyboardModal = __toESM(require("../../pro/pisellPriceKeyboardModal"));
var import_locales = __toESM(require("./locales"));
var import_materials = require("@pisell/materials");
var import_CashCountingModal = __toESM(require("./components/CashCountingModal/index"));
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_hooks = require("./hooks");
var import_PisellCashCounting = require("./PisellCashCounting.less");
var PREFIX = "pisell-private-cash-counting";
var PisellCashCounting = (props) => {
  var _a, _b;
  const context = (0, import_useEngineContext.default)();
  import_utils.locales.init(import_locales.default, ((_b = (_a = context == null ? void 0 : context.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "en");
  const {
    disabled = false,
    countDisabled = false,
    placeholder,
    layout = "vertical",
    countCashButtonText,
    showCurrencySymbol = true,
    useThousandsSeparator = false,
    inputNumberProps,
    buttonProps,
    className,
    style,
    modalWidth
  } = props;
  const {
    modalRef,
    triggerRef,
    keyboardOpen,
    setKeyboardOpen,
    currencyDenominations,
    decimalPlaces,
    symbol,
    currencyCode,
    currentValue,
    handleAmountChange,
    handleKeyboardClose,
    openCountModal,
    handleCountCancel,
    handleCountConfirm,
    manualCountMismatchOpen,
    confirmUseCountedTotal,
    confirmKeepManualAmount
  } = (0, import_hooks.usePisellCashCounting)(props);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)(PREFIX, className), style }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(`${PREFIX}__field`, {
        [`${PREFIX}__field--horizontal`]: layout === "horizontal"
      }),
      ref: triggerRef
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.InputNumber,
      {
        ...inputNumberProps,
        controls: false,
        disabled,
        precision: decimalPlaces,
        value: currentValue,
        placeholder: placeholder ?? import_utils.locales.getText("pisell-cash-counting.placeholder"),
        className: (0, import_classnames.default)(`${PREFIX}__input`, inputNumberProps == null ? void 0 : inputNumberProps.className),
        readOnly: true,
        addonBefore: symbol,
        size: "large",
        style: { width: "100%" },
        onClick: () => {
          if (!disabled) {
            setKeyboardOpen(true);
          }
        },
        onChange: handleAmountChange
      }
    ),
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        ...buttonProps,
        type: "primary",
        disabled: disabled || countDisabled || (buttonProps == null ? void 0 : buttonProps.disabled),
        className: (0, import_classnames.default)(`${PREFIX}__button`, buttonProps == null ? void 0 : buttonProps.className),
        onClick: (event) => {
          var _a2;
          (_a2 = buttonProps == null ? void 0 : buttonProps.onClick) == null ? void 0 : _a2.call(buttonProps, event);
          openCountModal();
        }
      },
      countCashButtonText ?? import_utils.locales.getText("pisell-cash-counting.countCash")
    )
  ), /* @__PURE__ */ import_react.default.createElement(
    import_pisellPriceKeyboardModal.default,
    {
      symbol,
      visible: keyboardOpen,
      value: currentValue,
      triggerRef,
      showCurrencySymbol,
      useThousandsSeparator,
      onChange: handleAmountChange,
      onClose: handleKeyboardClose
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal.Information,
    {
      open: manualCountMismatchOpen,
      closable: false,
      maskClosable: false,
      title: import_utils.locales.getText("pisell-cash-counting.manual-vs-count-message-title"),
      describe: import_utils.locales.getText("pisell-cash-counting.manual-vs-count-message"),
      okText: import_utils.locales.getText("pisell-cash-counting.keep-manual-amount"),
      cancelText: import_utils.locales.getText("pisell-cash-counting.use-count-total"),
      onOk: confirmKeepManualAmount,
      onCancel: confirmUseCountedTotal
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_CashCountingModal.default,
    {
      ref: modalRef,
      modalWidth,
      currencyCode,
      currencyDenominations,
      decimalPlaces,
      symbol,
      onCancel: handleCountCancel,
      onConfirm: handleCountConfirm
    }
  ));
};
var PisellCashCounting_default = PisellCashCounting;
