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 { Typography } from '@pisell/materials';
import "./index.less";
var Text = Typography.Text;
function UsageRules(_ref) {
  var _ref$className = _ref.className,
    className = _ref$className === void 0 ? '' : _ref$className,
    style = _ref.style,
    rules = _ref.rules,
    _ref$personalLimit = _ref.personalLimit,
    personalLimit = _ref$personalLimit === void 0 ? {
      total: 5,
      remaining: 3,
      note: '用完后此券将自动失效'
    } : _ref$personalLimit,
    locales = _ref.locales;
  // Helper function to interpolate text with variables
  var interpolateText = function interpolateText(text, variables) {
    return text.replace(/\{(\w+)\}/g, function (match, key) {
      return variables[key] !== undefined ? variables[key] : match;
    });
  };

  // Get localized text with fallback
  var getText = function getText(key, fallback) {
    return (locales === null || locales === void 0 ? void 0 : locales.getText(key)) || fallback || key;
  };

  // Generate rule description with limit value
  var getRuleDescription = function getRuleDescription(type, limit) {
    // Handle unlimited case (limit = 0 means unlimited)
    if (limit === 0 && type === 'monthly') {
      return getText('page.wallet.monthlyLimitUnlimited', '无限制');
    }
    var templateKey = "page.wallet.".concat(type, "LimitDesc");
    var template = getText(templateKey, '');
    return interpolateText(template, {
      limit: limit
    });
  };

  // Generate rule reset time text
  var getRuleResetTime = function getRuleResetTime(type) {
    var resetKey = "page.wallet.".concat(type, "Reset");
    return getText(resetKey, '');
  };

  // Default rules with localized text
  var defaultRules = [{
    type: 'daily',
    limit: 3,
    description: getRuleDescription('daily', 3),
    resetTime: getRuleResetTime('daily')
  }, {
    type: 'weekly',
    limit: 15,
    description: getRuleDescription('weekly', 15),
    resetTime: getRuleResetTime('weekly')
  }, {
    type: 'monthly',
    limit: 60,
    description: getRuleDescription('monthly', 60),
    resetTime: getRuleResetTime('monthly')
  }];

  // Process rules to add localized descriptions
  var processedRules = rules ? rules.map(function (rule) {
    return _objectSpread(_objectSpread({}, rule), {}, {
      description: getRuleDescription(rule.type, rule.limit),
      resetTime: getRuleResetTime(rule.type)
    });
  }) : defaultRules;
  var finalRules = processedRules;
  var getRuleLabel = function getRuleLabel(type) {
    switch (type) {
      case 'daily':
        return getText('page.wallet.dailyLimit', '每日限制:');
      case 'weekly':
        return getText('page.wallet.weeklyLimit', '每周限制:');
      case 'monthly':
        return getText('page.wallet.monthlyLimit', '每月限制:');
      default:
        return getText('page.wallet.dailyLimit', '限制:');
    }
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "usage-rules ".concat(className),
    style: style
  }, /*#__PURE__*/React.createElement(Text, {
    className: "usage-rules-title"
  }, getText('page.wallet.usageRules', '使用规则')), /*#__PURE__*/React.createElement(Text, {
    className: "usage-rules-subtitle"
  }, getText('page.wallet.usageRulesSubtitle', '请仔细阅读以下使用条件')), /*#__PURE__*/React.createElement("div", {
    className: "usage-rules-section"
  }, /*#__PURE__*/React.createElement(Text, {
    className: "usage-rules-section-title"
  }, getText('page.wallet.timeUsageLimits', '时间使用限制')), /*#__PURE__*/React.createElement("div", {
    className: "usage-rules-list"
  }, finalRules.length > 0 ? finalRules.map(function (rule, index) {
    return /*#__PURE__*/React.createElement("div", {
      key: index,
      className: "usage-rules-item"
    }, /*#__PURE__*/React.createElement("div", {
      className: "usage-rules-item-content"
    }, /*#__PURE__*/React.createElement("div", {
      className: "usage-rules-item-main-line"
    }, /*#__PURE__*/React.createElement(Text, {
      className: "usage-rules-item-label"
    }, getRuleLabel(rule.type)), /*#__PURE__*/React.createElement(Text, {
      className: "usage-rules-item-description"
    }, rule.description)), rule.resetTime && /*#__PURE__*/React.createElement(Text, {
      className: "usage-rules-item-reset"
    }, rule.resetTime)));
  }) : /*#__PURE__*/React.createElement("div", {
    className: "usage-rules-item"
  }, /*#__PURE__*/React.createElement("div", {
    className: "usage-rules-item-content"
  }, /*#__PURE__*/React.createElement(Text, {
    className: "usage-rules-item-description"
  }, getText('page.wallet.monthlyLimitUnlimited', '无限制')))))), /*#__PURE__*/React.createElement("div", {
    className: "usage-rules-section"
  }, /*#__PURE__*/React.createElement(Text, {
    className: "usage-rules-section-title"
  }, getText('page.wallet.totalQuantityControl', '总量控制')), /*#__PURE__*/React.createElement("div", {
    className: "usage-rules-item"
  }, /*#__PURE__*/React.createElement("div", {
    className: "usage-rules-item-content"
  }, personalLimit.total > 0 ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
    className: "usage-rules-item-label"
  }, getText('page.wallet.personalLimit', '个人限额:')), /*#__PURE__*/React.createElement(Text, {
    className: "usage-rules-item-description"
  }, interpolateText(getText('page.wallet.personalLimitDesc', '您最多可使用此券{total}次(剩余{remaining}次)'), {
    total: personalLimit.total,
    remaining: personalLimit.remaining
  })), /*#__PURE__*/React.createElement(Text, {
    className: "usage-rules-item-note"
  }, getText('page.wallet.voucherExpireNote', '用完后此券将自动失效'))) : /*#__PURE__*/React.createElement(Text, {
    className: "usage-rules-item-description"
  }, getText('page.wallet.monthlyLimitUnlimited', '无限制'))))));
}
export default UsageRules;