const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_PisellPriceKeyboardModal = require("../../pro/pisellPriceKeyboardModal/PisellPriceKeyboardModal.js");
const require_locales = require("./locales.js");
const require_index = require("./components/CashCountingModal/index.js");
const require_hooks = require("./hooks.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./PisellCashCounting.less");
//#region src/components/pisellCashCounting/PisellCashCounting.tsx
const PREFIX = "pisell-private-cash-counting";
const PisellCashCounting = (props) => {
	var _context$engine;
	const context = require_useEngineContext.default();
	_pisell_utils.locales.init(require_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 } = require_hooks.usePisellCashCounting(props);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)(PREFIX, className),
		style
	}, /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)(`${PREFIX}__field`, { [`${PREFIX}__field--horizontal`]: layout === "horizontal" }),
		ref: triggerRef
	}, /* @__PURE__ */ react.default.createElement(antd.InputNumber, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, inputNumberProps), {}, {
		controls: false,
		disabled,
		precision: decimalPlaces,
		value: currentValue,
		placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : _pisell_utils.locales.getText("pisell-cash-counting.placeholder"),
		className: (0, classnames.default)(`${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.default.createElement(antd.Button, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, buttonProps), {}, {
		type: "primary",
		disabled: disabled || countDisabled || (buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.disabled),
		className: (0, classnames.default)(`${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 : _pisell_utils.locales.getText("pisell-cash-counting.countCash"))), /* @__PURE__ */ react.default.createElement(require_PisellPriceKeyboardModal.default, {
		symbol,
		visible: keyboardOpen,
		value: currentValue,
		triggerRef,
		showCurrencySymbol,
		useThousandsSeparator,
		onChange: handleAmountChange,
		onClose: handleKeyboardClose
	}), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellModal.Information, {
		open: manualCountMismatchOpen,
		closable: false,
		maskClosable: false,
		title: _pisell_utils.locales.getText("pisell-cash-counting.manual-vs-count-message-title"),
		describe: _pisell_utils.locales.getText("pisell-cash-counting.manual-vs-count-message"),
		okText: _pisell_utils.locales.getText("pisell-cash-counting.keep-manual-amount"),
		cancelText: _pisell_utils.locales.getText("pisell-cash-counting.use-count-total"),
		onOk: confirmKeepManualAmount,
		onCancel: confirmUseCountedTotal
	}), /* @__PURE__ */ react.default.createElement(require_index.default, {
		ref: modalRef,
		modalWidth,
		currencyCode,
		currencyDenominations,
		decimalPlaces,
		symbol,
		onCancel: handleCountCancel,
		onConfirm: handleCountConfirm
	}));
};
//#endregion
exports.default = PisellCashCounting;
