var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/wallet/components/UsageRules/index.tsx
var UsageRules_exports = {};
__export(UsageRules_exports, {
  default: () => UsageRules_default
});
module.exports = __toCommonJS(UsageRules_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_index = require("./index.less");
var { Text } = import_materials.Typography;
function UsageRules({
  className = "",
  style,
  rules,
  personalLimit = {
    total: 5,
    remaining: 3,
    note: "用完后此券将自动失效"
  },
  locales
}) {
  const interpolateText = (text, variables) => {
    return text.replace(/\{(\w+)\}/g, (match, key) => {
      return variables[key] !== void 0 ? variables[key] : match;
    });
  };
  const getText = (key, fallback) => {
    return (locales == null ? void 0 : locales.getText(key)) || fallback || key;
  };
  const getRuleDescription = (type, limit) => {
    if (limit === 0 && type === "monthly") {
      return getText("page.wallet.monthlyLimitUnlimited", "无限制");
    }
    const templateKey = `page.wallet.${type}LimitDesc`;
    const template = getText(templateKey, "");
    return interpolateText(template, { limit });
  };
  const getRuleResetTime = (type) => {
    const resetKey = `page.wallet.${type}Reset`;
    return getText(resetKey, "");
  };
  const 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")
    }
  ];
  const processedRules = rules ? rules.map((rule) => ({
    ...rule,
    description: getRuleDescription(rule.type, rule.limit),
    resetTime: getRuleResetTime(rule.type)
  })) : defaultRules;
  const finalRules = processedRules;
  const 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__ */ import_react.default.createElement("div", { className: `usage-rules ${className}`, style }, /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-title" }, getText("page.wallet.usageRules", "使用规则")), /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-subtitle" }, getText("page.wallet.usageRulesSubtitle", "请仔细阅读以下使用条件")), /* @__PURE__ */ import_react.default.createElement("div", { className: "usage-rules-section" }, /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-section-title" }, getText("page.wallet.timeUsageLimits", "时间使用限制")), /* @__PURE__ */ import_react.default.createElement("div", { className: "usage-rules-list" }, finalRules.length > 0 ? finalRules.map((rule, index) => /* @__PURE__ */ import_react.default.createElement("div", { key: index, className: "usage-rules-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "usage-rules-item-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "usage-rules-item-main-line" }, /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-item-label" }, getRuleLabel(rule.type)), /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-item-description" }, rule.description)), rule.resetTime && /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-item-reset" }, rule.resetTime)))) : /* @__PURE__ */ import_react.default.createElement("div", { className: "usage-rules-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "usage-rules-item-content" }, /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-item-description" }, getText("page.wallet.monthlyLimitUnlimited", "无限制")))))), /* @__PURE__ */ import_react.default.createElement("div", { className: "usage-rules-section" }, /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-section-title" }, getText("page.wallet.totalQuantityControl", "总量控制")), /* @__PURE__ */ import_react.default.createElement("div", { className: "usage-rules-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "usage-rules-item-content" }, personalLimit.total > 0 ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-item-label" }, getText("page.wallet.personalLimit", "个人限额:")), /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-item-description" }, interpolateText(
    getText("page.wallet.personalLimitDesc", "您最多可使用此券{total}次(剩余{remaining}次)"),
    { total: personalLimit.total, remaining: personalLimit.remaining }
  )), /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-item-note" }, getText("page.wallet.voucherExpireNote", "用完后此券将自动失效"))) : /* @__PURE__ */ import_react.default.createElement(Text, { className: "usage-rules-item-description" }, getText("page.wallet.monthlyLimitUnlimited", "无限制"))))));
}
var UsageRules_default = UsageRules;
