function getPeriodKey(resetPeriod) {
  const now = /* @__PURE__ */ new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, "0");
  const day = String(now.getDate()).padStart(2, "0");
  switch (resetPeriod) {
    case "never":
      return "all_time";
    case "daily":
      return `${year}-${month}-${day}`;
    case "monthly":
      return `${year}-${month}`;
    case "yearly":
      return `${year}`;
    default:
      return "all_time";
  }
}
function getNextResetDate(resetPeriod) {
  const now = /* @__PURE__ */ new Date();
  switch (resetPeriod) {
    case "never":
      return null;
    case "daily": {
      const tomorrow = new Date(now);
      tomorrow.setDate(tomorrow.getDate() + 1);
      tomorrow.setHours(0, 0, 0, 0);
      return tomorrow;
    }
    case "monthly": {
      const nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, 1);
      return nextMonth;
    }
    case "yearly": {
      const nextYear = new Date(now.getFullYear() + 1, 0, 1);
      return nextYear;
    }
    default:
      return null;
  }
}
function calculatePercentUsed(current, max) {
  if (max === -1) return 0;
  if (max === 0) return 100;
  return Math.min(100, Math.round(current / max * 100));
}
function calculateRemaining(current, max) {
  if (max === -1) return Infinity;
  return Math.max(0, max - current);
}
function isSubscriptionActive(status) {
  return ["active", "trialing", "past_due"].includes(status);
}
function isInTrial(trialEndsAt) {
  if (!trialEndsAt) return false;
  return /* @__PURE__ */ new Date() < trialEndsAt;
}
function getTrialDaysRemaining(trialEndsAt) {
  if (!trialEndsAt) return 0;
  const now = /* @__PURE__ */ new Date();
  const diff = trialEndsAt.getTime() - now.getTime();
  return Math.max(0, Math.ceil(diff / (1e3 * 60 * 60 * 24)));
}
function hasFeature(planFeatures, featureSlug) {
  if (planFeatures.includes("*")) return true;
  return planFeatures.includes(featureSlug);
}
function formatPrice(cents, currency = "usd", locale = "en-US") {
  const amount = cents / 100;
  return new Intl.NumberFormat(locale, {
    style: "currency",
    currency: currency.toUpperCase()
  }).format(amount);
}
function calculateYearlySavings(priceMonthly, priceYearly) {
  const yearlyEquivalent = priceMonthly * 12;
  const savings = yearlyEquivalent - priceYearly;
  return Math.round(savings / yearlyEquivalent * 100);
}
export {
  calculatePercentUsed,
  calculateRemaining,
  calculateYearlySavings,
  formatPrice,
  getNextResetDate,
  getPeriodKey,
  getTrialDaysRemaining,
  hasFeature,
  isInTrial,
  isSubscriptionActive
};
