"use client"; import Link from "next/link"; import { ArrowRight, BellRing, CheckCircle2, Coins, Crown, ExternalLink, Loader2, Lock, MessageSquare, Radar, Send, Sparkles, TrendingUp, Wallet, X, Zap, } from "lucide-react"; import s from "./UnlockProOverlay.module.css"; const DEFAULT_FAQ_HREF = "/subscription-help"; const DEFAULT_TELEGRAM_GROUP_URL = ""; export type UnlockProBilling = { pointsEnabled: boolean; isEligible: boolean; pointsUsed: number; discountAmount: number; finalPrice: number; maxDiscountUsd: number; pointsPerUsd: number; }; type UnlockProOverlayProps = { points: number; planPriceUsd: number; planLabel?: string; periodLabel?: string; usePoints: boolean; billing: UnlockProBilling; onToggleUsePoints: () => void; onPay: () => void; onManualPay?: () => void; onClose?: () => void; payBusy?: boolean; payLabel?: string; manualPayLabel?: string; locale?: "zh-CN" | "en-US"; errorText?: string; infoText?: string; faqHref?: string; telegramGroupUrl?: string; txHash?: string; chainId?: number; paymentTokenLabel?: string; }; function formatUsdcAmount(value: number) { if (!Number.isFinite(value)) return "0"; return value.toFixed(2).replace(/\.?0+$/, ""); } const FEATURES = { "zh-CN": [ "Terminal:市场温度与城市机会扫描", "机场 / 跑道实测:METAR + 结算源优先", "DEB 路径与高温时段复核", "Telegram 提醒与账户权益同步", ], "en-US": [ "Terminal: market temperature and city signal scanning", "Airport / runway observations: METAR + settlement-source-first", "DEB paths and peak-temperature window review", "Telegram alerts and entitlement sync", ], }; export function UnlockProOverlay({ points, planPriceUsd, planLabel, periodLabel, usePoints, billing, onToggleUsePoints, onPay, onManualPay, onClose, payBusy = false, payLabel, manualPayLabel, locale = "zh-CN", errorText, infoText, faqHref = DEFAULT_FAQ_HREF, telegramGroupUrl = DEFAULT_TELEGRAM_GROUP_URL, txHash, chainId = 137, paymentTokenLabel, }: UnlockProOverlayProps) { const isEn = locale === "en-US"; const canUsePoints = billing.pointsEnabled && billing.isEligible; const featureList = FEATURES[locale] ?? FEATURES["zh-CN"]; const currencyLabel = "USDC"; const formattedPlanPrice = formatUsdcAmount(planPriceUsd); const formattedFinalPrice = formatUsdcAmount(billing.finalPrice); const formattedDiscount = formatUsdcAmount(billing.discountAmount); const formattedMaxDiscount = formatUsdcAmount(billing.maxDiscountUsd); const resolvedPlanLabel = planLabel || "Standard Pro"; const resolvedPeriodLabel = periodLabel || (isEn ? "/ 30 days" : "/ 30 天"); const finalPayLabel = payLabel || (isEn ? "Subscribe & Activate" : "立即订阅并激活服务"); const maxDiscountUsdInt = Math.max(1, Math.floor(billing.maxDiscountUsd || 0)); const maxPointsForFullDiscount = Math.max( billing.pointsPerUsd, billing.pointsPerUsd * maxDiscountUsdInt, ); const redeemableUsdNow = billing.pointsEnabled ? Math.min(maxDiscountUsdInt, Math.floor(points / Math.max(1, billing.pointsPerUsd))) : 0; const formattedRedeemableNow = formatUsdcAmount(redeemableUsdNow); const formattedMaxDiscountInt = formatUsdcAmount(maxDiscountUsdInt); const progressPct = billing.pointsEnabled ? Math.min(100, Math.round((points / maxPointsForFullDiscount) * 100)) : 0; const resolvedTelegramGroupUrl = String(telegramGroupUrl || "").trim(); const txHref = txHash && txHash.startsWith("0x") ? `${chainId === 137 ? "https://polygonscan.com" : "https://etherscan.io"}/tx/${txHash}` : ""; return (
{isEn ? "Confirm your subscription for the settlement-source-first terminal: observations, DEB paths, city charts, and alerts." : "确认订阅结算源优先的天气决策终端:实测观测、DEB 路径、城市图表和提醒。"}
{usePoints ? isEn ? `Using ${billing.pointsUsed} pts · saves ${formattedDiscount} ${currencyLabel}` : `已消耗 ${billing.pointsUsed} 积分 · 省 ${formattedDiscount} ${currencyLabel}` : isEn ? `Toggle to save up to ${formattedMaxDiscount} ${currencyLabel}` : `开启可最多抵扣 ${formattedMaxDiscount} ${currencyLabel}`}
{isEn ? `Now redeemable: ${formattedRedeemableNow} / ${formattedMaxDiscountInt} ${currencyLabel}` : `当前可抵:${formattedRedeemableNow} / ${formattedMaxDiscountInt} ${currencyLabel}`}
{!billing.pointsEnabled ? isEn ? "Points redemption is unavailable for this plan." : "当前套餐暂不支持积分抵扣。" : isEn ? `Starts at ${billing.pointsPerUsd} pts, ${billing.pointsPerUsd} pts per 1 ${currencyLabel}, up to ${formattedMaxDiscountInt} ${currencyLabel}. You have: ${points}` : `满 ${billing.pointsPerUsd} 分起兑,每 ${billing.pointsPerUsd} 分抵 1 ${currencyLabel},最多抵 ${formattedMaxDiscountInt} ${currencyLabel}。当前 ${points} 分`}
{billing.pointsEnabled && ({isEn ? "Total Due Today" : "今日应付"}
{paymentTokenLabel && ({isEn ? "Token" : "支付币种"}: {paymentTokenLabel}
)} {billing.discountAmount > 0 && usePoints && ({formattedPlanPrice} {currencyLabel}
)}{isEn ? "Choose one payment method only. Do not pay again after the order is completed." : "请只选择一种支付方式;订单完成后请勿重复付款。"}
) : null}