import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import usePisellConfig from "../../pisell-config-provider/hooks/usePisellConfig.js";
import BaseNumberKeyboard from "../BaseNumberKeyboard/index.js";
import PisellText from "../../pisellText/index.js";
import { amountThemeConfig } from "./themeConfig.js";
import React, { useEffect, useMemo } from "react";
import { setTheme } from "@pisell/utils";
import classNames from "classnames";
import { useControllableValue } from "ahooks";
import "./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;
	_objectWithoutProperties(props, _excluded);
	usePisellConfig();
	const [value, setValue] = useControllableValue(props, { defaultValue: defaultValue || "" });
	useEffect(() => {
		document.body.id = "body";
	}, []);
	/**
	* 配置颜色
	* 根据 props 和 selectType 生成最终的配置颜色
	*/
	const configColor = useMemo(() => {
		const currentConfig = amountThemeConfig[selectType];
		const validProps = Object.entries(props).reduce((acc, [key, value]) => {
			if (value !== void 0 && key in currentConfig) acc[key] = value;
			return acc;
		}, {});
		return _objectSpread2(_objectSpread2({}, currentConfig), validProps);
	}, [selectType, props]);
	useEffect(() => {
		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.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(PisellText.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.createElement("div", { className: classNames("pisell-amount-keyboard-wrap", {
		"pisell-amount-keyboard-dark": selectType === "dark",
		"pisell-amount-keyboard-light": selectType === "light"
	}) }, /* @__PURE__ */ React.createElement(BaseNumberKeyboard, {
		defaultSelect,
		max,
		min,
		value,
		onChange: setValue,
		placeholder,
		defaultValue,
		format,
		doneText,
		resetText,
		onEnter,
		presets,
		rightItemsStyle: _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
export { Amount as default };
