const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_usePisellConfig = require("../../pisell-config-provider/hooks/usePisellConfig.js");
const require_index = require("../BaseNumberKeyboard/index.js");
const require_index$1 = require("../../pisellText/index.js");
const require_themeConfig = require("./themeConfig.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/virtual-keyboard/Amount/index.tsx
const _excluded = [
	"min",
	"max",
	"amountProps",
	"doneText",
	"resetText",
	"defaultValue",
	"placeholder",
	"onEnter",
	"presets",
	"defaultSelect",
	"inputFormat",
	"rightItemsStyle",
	"selectType"
];
const Amount = (props) => {
	var _rightItemsStyle$isDo;
	const { min, max, amountProps, doneText, resetText, defaultValue, placeholder, onEnter, presets, defaultSelect, inputFormat, rightItemsStyle, selectType = "light" } = props;
	require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	require_usePisellConfig.default();
	const [value, setValue] = (0, ahooks.useControllableValue)(props, { defaultValue: defaultValue || "" });
	(0, react.useEffect)(() => {
		document.body.id = "body";
	}, []);
	/**
	* 配置颜色
	* 根据 props 和 selectType 生成最终的配置颜色
	*/
	const configColor = (0, react.useMemo)(() => {
		const currentConfig = require_themeConfig.amountThemeConfig[selectType];
		const validProps = Object.entries(props).reduce((acc, [key, value]) => {
			if (value !== void 0 && key in currentConfig) acc[key] = value;
			return acc;
		}, {});
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, currentConfig), validProps);
	}, [selectType, props]);
	(0, react.useEffect)(() => {
		(0, _pisell_utils.setTheme)({
			"--pisell-amount-background-color": configColor.backgroundColor,
			"--pisell-amount-container-background-color": configColor.containerBackgroundColor,
			"--pisell-amount-text-color": configColor.textColor,
			"--pisell-amount-keyboard-background-color": configColor.keyboardBackgroundColor,
			"--pisell-amount-keyboard-button-background-color": configColor.keyboardButtonBackgroundColor,
			"--pisell-amount-keyboard-button-text-color": configColor.keyboardButtonTextColor,
			"--pisell-amount-keyboard-button-hover-color": configColor.keyboardButtonHoverColor,
			"--pisell-amount-reset-button-background-color": configColor.resetButtonBackgroundColor,
			"--pisell-amount-reset-button-text-color": configColor.resetButtonTextColor,
			"--pisell-amount-done-button-background-color": configColor.doneButtonBackgroundColor,
			"--pisell-amount-done-button-text-color": configColor.doneButtonTextColor
		});
	}, [configColor]);
	const format = (_v) => {
		const v = `${_v}`;
		if (inputFormat === null || inputFormat === void 0 ? void 0 : inputFormat(v)) return inputFormat === null || inputFormat === void 0 ? void 0 : inputFormat(v);
		const precision = v.includes(".") ? v.split(".")[1].length : 0;
		const endWith = v.endsWith(".");
		const value = endWith ? v.slice(0, -1) : v;
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_index$1.default.Amount, {
			value,
			precision,
			hideDecimalForWholeNumbers: false,
			showCurrencySymbol: amountProps === null || amountProps === void 0 ? void 0 : amountProps.showCurrencySymbol,
			useThousandsSeparator: amountProps === null || amountProps === void 0 ? void 0 : amountProps.useThousandsSeparator,
			symbol: amountProps === null || amountProps === void 0 ? void 0 : amountProps.symbol,
			style: { color: (rightItemsStyle === null || rightItemsStyle === void 0 ? void 0 : rightItemsStyle.textColor) || configColor.textColor }
		}), endWith && ".");
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("pisell-amount-keyboard-wrap", {
		"pisell-amount-keyboard-dark": selectType === "dark",
		"pisell-amount-keyboard-light": selectType === "light"
	}) }, /* @__PURE__ */ react.default.createElement(require_index.default, {
		defaultSelect,
		max,
		min,
		value,
		onChange: setValue,
		placeholder,
		defaultValue,
		format,
		doneText,
		resetText,
		onEnter,
		presets,
		rightItemsStyle: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, rightItemsStyle), {}, {
			buttonBackgroundColor: (rightItemsStyle === null || rightItemsStyle === void 0 ? void 0 : rightItemsStyle.buttonBackgroundColor) || configColor.buttonBackgroundColor,
			textColor: (rightItemsStyle === null || rightItemsStyle === void 0 ? void 0 : rightItemsStyle.textColor) || configColor.textColor,
			resetButtonBackgroundColor: (rightItemsStyle === null || rightItemsStyle === void 0 ? void 0 : rightItemsStyle.resetButtonBackgroundColor) || configColor.resetButtonBackgroundColor,
			resetButtonTextColor: (rightItemsStyle === null || rightItemsStyle === void 0 ? void 0 : rightItemsStyle.resetButtonTextColor) || configColor.resetButtonTextColor,
			isDoneButtonFollowTheme: (_rightItemsStyle$isDo = rightItemsStyle === null || rightItemsStyle === void 0 ? void 0 : rightItemsStyle.isDoneButtonFollowTheme) !== null && _rightItemsStyle$isDo !== void 0 ? _rightItemsStyle$isDo : configColor.isDoneButtonFollowTheme,
			doneButtonBackgroundColor: (rightItemsStyle === null || rightItemsStyle === void 0 ? void 0 : rightItemsStyle.doneButtonBackgroundColor) || configColor.doneButtonBackgroundColor,
			doneButtonTextColor: (rightItemsStyle === null || rightItemsStyle === void 0 ? void 0 : rightItemsStyle.doneButtonTextColor) || configColor.doneButtonTextColor
		})
	}));
};
//#endregion
exports.default = Amount;
