import React from 'react';
import { getDisplayState } from '@pisell/utils';
import ReadOnlyView from "./components/ReadOnlyView";
import EditView from "./components/EditView";
import DisabledView from "./components/DisabledView";
import "./PisellCurrency.less";

/**
 * PisellCurrency 货币组件
 * 
 * 基于 PisellNumber 派生，专门处理货币数据。
 * 默认启用千分位和2位小数，符合财务规范。
 * 
 * @param props 组件 Props
 * 
 * @example
 * // 受控模式
 * const [price, setPrice] = useState(0);
 * <PisellCurrency 
 *   value={price}
 *   onChange={setPrice}
 *   currencySymbol="¥"
 * />
 * 
 * @example
 * // 非受控模式
 * <PisellCurrency 
 *   defaultValue={100}
 *   currencySymbol="$"
 * />
 * 
 * @example
 * // 只读态
 * <PisellCurrency 
 *   mode="read"
 *   value={1234.56}
 *   currencySymbol="¥"
 * />
 * // 显示: ¥1,234.56
 */
export var PisellCurrency = function PisellCurrency(props) {
  var _props$mode = props.mode,
    mode = _props$mode === void 0 ? 'edit' : _props$mode,
    _props$disabled = props.disabled,
    disabled = _props$disabled === void 0 ? false : _props$disabled;

  // 计算显示状态
  var displayState = getDisplayState(mode, disabled);

  // 根据状态渲染对应子组件
  switch (displayState) {
    case 'read':
      return /*#__PURE__*/React.createElement(ReadOnlyView, props);
    case 'edit':
      return /*#__PURE__*/React.createElement(EditView, props);
    case 'disabled':
      return /*#__PURE__*/React.createElement(DisabledView, props);
    default:
      return null;
  }
};

// 性能优化：使用 memo 避免不必要的重渲染
var MemoizedPisellCurrency = /*#__PURE__*/React.memo(PisellCurrency, function (prevProps, nextProps) {
  return prevProps.value === nextProps.value && prevProps.mode === nextProps.mode && prevProps.disabled === nextProps.disabled && prevProps.currencySymbol === nextProps.currencySymbol && prevProps.symbolPosition === nextProps.symbolPosition;
});
export default MemoizedPisellCurrency;