import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import React, { useMemo } from "react";
import { useNumberInputState } from "@pisell/utils";
import { InputNumber } from "antd";
//#region src/components/pisellCurrency/components/EditView.tsx
/**
* PisellCurrency 编辑态视图组件
* 
* 负责渲染编辑态的输入框，基于 Ant Design InputNumber 组件
* 
* 功能：
* - 货币数值输入
* - 货币符号显示（prefix 或 addonAfter）
* - 负数校验
* - 实时或失焦校验
* - 错误提示展示
* 
* @param props 组件 Props
*/
const EditView = (props) => {
	const { currencySymbol = "¥", symbolPosition = "before", showSymbol = true, allowNegative = true, precision = 2, useGrouping = true, min, max, step, placeholder = "请输入金额", disabled, autoFocus, size, keyboard, controls, className, style, "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, id, name, onPressEnter } = props;
	const enhancedValidator = useMemo(() => {
		return (value) => {
			if (!allowNegative && value !== null && value < 0) return "金额不能为负数";
			if (props.validator) return props.validator(value);
			return true;
		};
	}, [allowNegative, props.validator]);
	const computedMin = useMemo(() => {
		if (min !== void 0) return min;
		if (!allowNegative) return 0;
	}, [min, allowNegative]);
	const { value, isValid, errors, handleChange, handleBlur, handleFocus } = useNumberInputState(_objectSpread2(_objectSpread2({}, props), {}, {
		validator: enhancedValidator,
		min: computedMin,
		max,
		precision
	}));
	const prefixNode = showSymbol && symbolPosition === "before" ? currencySymbol : void 0;
	const addonAfterNode = showSymbol && symbolPosition === "after" ? currencySymbol : void 0;
	return /* @__PURE__ */ React.createElement("div", { className: `pisell-currency pisell-currency-edit ${className || ""}` }, /* @__PURE__ */ React.createElement(InputNumber, {
		value: value !== null && value !== void 0 ? value : void 0,
		onChange: handleChange,
		onBlur: handleBlur,
		onFocus: handleFocus,
		onPressEnter: () => onPressEnter === null || onPressEnter === void 0 ? void 0 : onPressEnter(value !== null && value !== void 0 ? value : null),
		min: computedMin,
		max,
		step,
		precision,
		prefix: prefixNode,
		addonAfter: addonAfterNode,
		placeholder,
		disabled,
		autoFocus,
		size,
		keyboard,
		controls,
		status: isValid ? void 0 : "error",
		style,
		"aria-label": ariaLabel,
		"aria-describedby": ariaDescribedBy,
		id,
		name
	}), !isValid && errors.length > 0 && /* @__PURE__ */ React.createElement("div", { className: "pisell-currency-error" }, errors[0]));
};
//#endregion
export { EditView as default };
