function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useMemo } from 'react';
import { InputNumber } from 'antd';
import { useNumberInputState } from '@pisell/utils';
/**
 * PisellCurrency 编辑态视图组件
 * 
 * 负责渲染编辑态的输入框，基于 Ant Design InputNumber 组件
 * 
 * 功能：
 * - 货币数值输入
 * - 货币符号显示（prefix 或 addonAfter）
 * - 负数校验
 * - 实时或失焦校验
 * - 错误提示展示
 * 
 * @param props 组件 Props
 */
var EditView = function EditView(props) {
  var _props$currencySymbol = props.currencySymbol,
    currencySymbol = _props$currencySymbol === void 0 ? '¥' : _props$currencySymbol,
    _props$symbolPosition = props.symbolPosition,
    symbolPosition = _props$symbolPosition === void 0 ? 'before' : _props$symbolPosition,
    _props$showSymbol = props.showSymbol,
    showSymbol = _props$showSymbol === void 0 ? true : _props$showSymbol,
    _props$allowNegative = props.allowNegative,
    allowNegative = _props$allowNegative === void 0 ? true : _props$allowNegative,
    _props$precision = props.precision,
    precision = _props$precision === void 0 ? 2 : _props$precision,
    _props$useGrouping = props.useGrouping,
    useGrouping = _props$useGrouping === void 0 ? true : _props$useGrouping,
    min = props.min,
    max = props.max,
    step = props.step,
    _props$placeholder = props.placeholder,
    placeholder = _props$placeholder === void 0 ? '请输入金额' : _props$placeholder,
    disabled = props.disabled,
    autoFocus = props.autoFocus,
    size = props.size,
    keyboard = props.keyboard,
    controls = props.controls,
    className = props.className,
    style = props.style,
    ariaLabel = props['aria-label'],
    ariaDescribedBy = props['aria-describedby'],
    id = props.id,
    name = props.name,
    _onPressEnter = props.onPressEnter;

  // 扩展校验逻辑：负数校验
  var enhancedValidator = useMemo(function () {
    return function (value) {
      // 负数校验
      if (!allowNegative && value !== null && value < 0) {
        return '金额不能为负数';
      }

      // 调用原始校验函数
      if (props.validator) {
        return props.validator(value);
      }
      return true;
    };
  }, [allowNegative, props.validator]);

  // 计算 min（考虑 allowNegative）
  var computedMin = useMemo(function () {
    if (min !== undefined) return min;
    if (!allowNegative) return 0;
    return undefined;
  }, [min, allowNegative]);

  // 使用状态管理 hook
  var _useNumberInputState = useNumberInputState(_objectSpread(_objectSpread({}, props), {}, {
      validator: enhancedValidator,
      min: computedMin,
      max: max,
      precision: precision
    })),
    value = _useNumberInputState.value,
    isValid = _useNumberInputState.isValid,
    errors = _useNumberInputState.errors,
    handleChange = _useNumberInputState.handleChange,
    handleBlur = _useNumberInputState.handleBlur,
    handleFocus = _useNumberInputState.handleFocus;

  // 货币符号显示在 prefix（前置）或 addonAfter（后置）
  var prefixNode = showSymbol && symbolPosition === 'before' ? currencySymbol : undefined;
  var addonAfterNode = showSymbol && symbolPosition === 'after' ? currencySymbol : undefined;
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-currency pisell-currency-edit ".concat(className || '')
  }, /*#__PURE__*/React.createElement(InputNumber, {
    value: value !== null && value !== void 0 ? value : undefined,
    onChange: handleChange,
    onBlur: handleBlur,
    onFocus: handleFocus,
    onPressEnter: function onPressEnter() {
      return _onPressEnter === null || _onPressEnter === void 0 ? void 0 : _onPressEnter(value !== null && value !== void 0 ? value : null);
    },
    min: computedMin,
    max: max,
    step: step,
    precision: precision,
    prefix: prefixNode,
    addonAfter: addonAfterNode,
    placeholder: placeholder,
    disabled: disabled,
    autoFocus: autoFocus,
    size: size,
    keyboard: keyboard,
    controls: controls,
    status: isValid ? undefined : 'error',
    style: style,
    "aria-label": ariaLabel,
    "aria-describedby": ariaDescribedBy,
    id: id,
    name: name
  }), !isValid && errors.length > 0 && /*#__PURE__*/React.createElement("div", {
    className: "pisell-currency-error"
  }, errors[0]));
};
export default EditView;