"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));
require("./index.scss");
var _right = _interopRequireDefault(require("../../assets/icon/mine/right.png"));
var _excluded = ["userName", "gradeImg", "isMaxLevel", "maxTotal", "currentNum", "isFastExpireCoupon", "discount", "handleClick", "handleCouponClick"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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 = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _otherProps = otherProps || {};

  // 计算进度百分比 使用 useMemo 来模拟计算属性
  var progressPercentage = (0, _react.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["default"].createElement("div", (0, _extends2["default"])({
    className: "member-card"
  }, _otherProps, {
    onClick: handleClick
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "header"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "left"
  }, /*#__PURE__*/_react["default"].createElement("span", null, userName), gradeImg && /*#__PURE__*/_react["default"].createElement("img", {
    className: "grade",
    src: gradeImg
  })), discount && /*#__PURE__*/_react["default"].createElement("div", {
    className: "btn-tag"
  }, "\u5C0A\u4EAB", discount !== null && discount !== void 0 ? discount : 0, "\u6298")), /*#__PURE__*/_react["default"].createElement("div", {
    className: "footer"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "progress-bar-container",
    style: {
      width: containerWidth
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "progress-bar-background"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "progress-bar-foreground",
    style: {
      width: progressPercentage + "%"
    }
  }))), isFastExpireCoupon && /*#__PURE__*/_react["default"].createElement("div", {
    className: "right",
    onClick: handleCouponClick
  }, "\u60A8\u6709\u4F18\u60E0\u5238\u5373\u5C06\u5230\u671F", /*#__PURE__*/_react["default"].createElement("img", {
    className: "img",
    src: _right["default"]
  }))));
};
MemberCard.displayName = 'MemberCard';
var _default = exports["default"] = MemberCard;