import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import useEngineContext from "../../hooks/useEngineContext.js";
import PisellPriceKeyboardModal from "../../pro/pisellPriceKeyboardModal/PisellPriceKeyboardModal.js";
import locales_default from "./locales.js";
import CashCountingModal from "./components/CashCountingModal/index.js";
import { usePisellCashCounting } from "./hooks.js";
import React from "react";
import { Button, InputNumber } from "antd";
import { locales } from "@pisell/utils";
import { PisellModal } from "@pisell/materials";
import classNames from "classnames";
import "./PisellCashCounting.less";
//#region src/components/pisellCashCounting/PisellCashCounting.tsx
const PREFIX = "pisell-private-cash-counting";
const PisellCashCounting = (props) => {
	var _context$engine;
	const context = useEngineContext();
	locales.init(locales_default, (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");
	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 } = usePisellCashCounting(props);
	return /* @__PURE__ */ React.createElement("div", {
		className: classNames(PREFIX, className),
		style
	}, /* @__PURE__ */ React.createElement("div", {
		className: classNames(`${PREFIX}__field`, { [`${PREFIX}__field--horizontal`]: layout === "horizontal" }),
		ref: triggerRef
	}, /* @__PURE__ */ React.createElement(InputNumber, _objectSpread2(_objectSpread2({}, inputNumberProps), {}, {
		controls: false,
		disabled,
		precision: decimalPlaces,
		value: currentValue,
		placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : locales.getText("pisell-cash-counting.placeholder"),
		className: classNames(`${PREFIX}__input`, inputNumberProps === null || inputNumberProps === void 0 ? void 0 : inputNumberProps.className),
		readOnly: true,
		addonBefore: symbol,
		size: "large",
		style: { width: "100%" },
		onClick: () => {
			if (!disabled) setKeyboardOpen(true);
		},
		onChange: handleAmountChange
	})), /* @__PURE__ */ React.createElement(Button, _objectSpread2(_objectSpread2({}, buttonProps), {}, {
		type: "primary",
		disabled: disabled || countDisabled || (buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.disabled),
		className: classNames(`${PREFIX}__button`, buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.className),
		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(PisellPriceKeyboardModal, {
		symbol,
		visible: keyboardOpen,
		value: currentValue,
		triggerRef,
		showCurrencySymbol,
		useThousandsSeparator,
		onChange: handleAmountChange,
		onClose: 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,
		currencyCode,
		currencyDenominations,
		decimalPlaces,
		symbol,
		onCancel: handleCountCancel,
		onConfirm: handleCountConfirm
	}));
};
//#endregion
export { PisellCashCounting as default };
