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 from 'react';
import { Rate } from 'antd';
import { getDisplayState } from '@pisell/utils';
import "./PisellRating.less";

/**
 * PisellRating 评分组件
 * 
 * 基于 Ant Design Rate 组件开发，提供直观的星级评分交互。
 * 支持只读、编辑、禁用三种状态。
 * 
 * @param props 组件 Props
 * 
 * @example
 * // 基础使用
 * const [rating, setRating] = useState(0);
 * <PisellRating value={rating} onChange={setRating} />
 * 
 * @example
 * // 只读态
 * <PisellRating mode="read" value={4.5} allowHalf />
 * 
 * @example
 * // 带评分描述
 * <PisellRating
 *   value={rating}
 *   onChange={setRating}
 *   tooltips={['很差', '差', '一般', '好', '很好']}
 * />
 */
export var PisellRating = function PisellRating(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,
    value = props.value,
    defaultValue = props.defaultValue,
    onChange = props.onChange,
    count = props.count,
    _props$max = props.max,
    max = _props$max === void 0 ? count !== null && count !== void 0 ? count : 5 : _props$max,
    _props$allowHalf = props.allowHalf,
    allowHalf = _props$allowHalf === void 0 ? false : _props$allowHalf,
    _props$allowClear = props.allowClear,
    allowClear = _props$allowClear === void 0 ? true : _props$allowClear,
    character = props.character,
    tooltips = props.tooltips,
    _props$showValue = props.showValue,
    showValue = _props$showValue === void 0 ? false : _props$showValue,
    _props$showCount = props.showCount,
    showCount = _props$showCount === void 0 ? false : _props$showCount,
    reviewCount = props.reviewCount,
    _props$size = props.size,
    size = _props$size === void 0 ? 20 : _props$size,
    _props$color = props.color,
    color = _props$color === void 0 ? '#fadb14' : _props$color,
    _props$unselectedColo = props.unselectedColor,
    unselectedColor = _props$unselectedColo === void 0 ? '#d9d9d9' : _props$unselectedColo,
    onHoverChange = props.onHoverChange,
    onFocus = props.onFocus,
    onBlur = props.onBlur,
    className = props.className,
    style = props.style,
    ariaLabel = props['aria-label'],
    id = props.id;

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

  // 只读态 = disabled
  var isReadOnly = displayState === 'read';
  var isDisabled = displayState === 'disabled';

  // 组合样式
  var rateStyle = _objectSpread({
    fontSize: size,
    color: color
  }, style);
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-rating pisell-rating-".concat(displayState, " ").concat(className || ''),
    id: id
  }, /*#__PURE__*/React.createElement(Rate, {
    value: value,
    defaultValue: defaultValue,
    onChange: onChange,
    onHoverChange: onHoverChange,
    onFocus: onFocus,
    onBlur: onBlur,
    count: max,
    allowHalf: allowHalf,
    allowClear: allowClear,
    character: character,
    tooltips: tooltips,
    disabled: isReadOnly || isDisabled,
    style: rateStyle,
    "aria-label": ariaLabel
  }), showValue && value !== undefined && /*#__PURE__*/React.createElement("span", {
    className: "pisell-rating-value",
    style: {
      marginLeft: 8
    }
  }, value.toFixed(allowHalf ? 1 : 0)), showCount && reviewCount !== undefined && /*#__PURE__*/React.createElement("span", {
    className: "pisell-rating-count",
    style: {
      marginLeft: 8,
      color: '#999'
    }
  }, "(", reviewCount, " \u4EBA\u8BC4\u4EF7)"));
};

// 性能优化
export default /*#__PURE__*/React.memo(PisellRating, function (prevProps, nextProps) {
  return prevProps.value === nextProps.value && prevProps.mode === nextProps.mode && prevProps.disabled === nextProps.disabled;
});