import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["userName", "gradeImg", "isMaxLevel", "maxTotal", "currentNum", "isFastExpireCoupon", "discount", "handleClick", "handleCouponClick"];
import React, { useMemo } from 'react';
import "./index.scss";
import arrowImg from "../../assets/icon/mine/right.png";
var MemberCard = function MemberCard(_ref) {
  var userName = _ref.userName,
    gradeImg = _ref.gradeImg,
    isMaxLevel = _ref.isMaxLevel,
    maxTotal = _ref.maxTotal,
    currentNum = _ref.currentNum,
    isFastExpireCoupon = _ref.isFastExpireCoupon,
    discount = _ref.discount,
    _ref$handleClick = _ref.handleClick,
    handleClick = _ref$handleClick === void 0 ? function () {} : _ref$handleClick,
    _ref$handleCouponClic = _ref.handleCouponClick,
    handleCouponClick = _ref$handleCouponClic === void 0 ? function () {} : _ref$handleCouponClic,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _otherProps = otherProps || {};

  // 计算进度百分比 使用 useMemo 来模拟计算属性
  var progressPercentage = useMemo(function () {
    if (isMaxLevel) return 100;
    if (maxTotal === 0) return 0; // 防止除以零错误
    if (!maxTotal || !currentNum) return 0;
    return (currentNum / maxTotal * 100).toFixed(2); // 保留两位小数
  }, [isMaxLevel, maxTotal, currentNum]);

  // 外层容器的宽度
  var containerWidth = isFastExpireCoupon ? '60%' : '100%';
  return /*#__PURE__*/React.createElement("div", _extends({
    className: "member-card"
  }, _otherProps, {
    onClick: handleClick
  }), /*#__PURE__*/React.createElement("div", {
    className: "header"
  }, /*#__PURE__*/React.createElement("div", {
    className: "left"
  }, /*#__PURE__*/React.createElement("span", null, userName), gradeImg && /*#__PURE__*/React.createElement("img", {
    className: "grade",
    src: gradeImg
  })), discount && /*#__PURE__*/React.createElement("div", {
    className: "btn-tag"
  }, "\u5C0A\u4EAB", discount !== null && discount !== void 0 ? discount : 0, "\u6298")), /*#__PURE__*/React.createElement("div", {
    className: "footer"
  }, /*#__PURE__*/React.createElement("div", {
    className: "progress-bar-container",
    style: {
      width: containerWidth
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "progress-bar-background"
  }, /*#__PURE__*/React.createElement("div", {
    className: "progress-bar-foreground",
    style: {
      width: progressPercentage + "%"
    }
  }))), isFastExpireCoupon && /*#__PURE__*/React.createElement("div", {
    className: "right",
    onClick: handleCouponClick
  }, "\u60A8\u6709\u4F18\u60E0\u5238\u5373\u5C06\u5230\u671F", /*#__PURE__*/React.createElement("img", {
    className: "img",
    src: arrowImg
  }))));
};
MemberCard.displayName = 'MemberCard';
export default MemberCard;