"use client"; import { useState } from "react"; import Link from "next/link"; import { LockKeyhole, CreditCard, LogIn } from "lucide-react"; import { UnlockProOverlay } from "@/components/subscription/UnlockProOverlay"; import { useTerminalPay } from "@/components/subscription/useTerminalPay"; const ACCESS_TERM = { signInToContinue: { en: "Sign in to continue", zh: "请先登录" }, proAccessRequired: { en: "Pro Access Required", zh: "需要付费订阅" }, month: { en: "/ month", zh: "/ 月" }, subscribeNow: { en: "Subscribe Now — $10/mo", zh: "立即订阅 — $10/月" }, backToProduct: { en: "Back to product overview", zh: "返回产品介绍页" }, } as const; function t(key: keyof typeof ACCESS_TERM, isEn: boolean) { return isEn ? ACCESS_TERM[key].en : ACCESS_TERM[key].zh; } // ─── Layer 2: Authenticated but no active subscription ─────────────────────── function SubscriptionGate({ isEn, points, onPaid, }: { isEn: boolean; points: number; onPaid: () => void; }) { const [showOverlay, setShowOverlay] = useState(false); const { billing, usePoints, setUsePoints, payBusy, errorText, infoText, txHash, chainId, tokenSymbol, walletAddress, handlePay, } = useTerminalPay({ points, planPriceUsd: 10, onPaid: () => { setShowOverlay(false); onPaid(); }, isEn, }); const handleSubscribeClick = () => { setShowOverlay(true); }; const features = isEn ? [ "Real-time METAR observations across 500+ stations", "DEB forecast blends with 0–240h horizon", "AI decision cards with Poly-score ranking", "Historical backtesting & weather market signals", ] : [ "500+ 气象站实时 METAR 实况", "DEB 智能融合预测(0–240 小时)", "AI 决策卡片 + Poly-score 排名", "历史回测与天气市场交易信号", ]; return (
{/* Header badge */}
{t("proAccessRequired", isEn)}
{/* Main card */}
{/* Card top band */}

{isEn ? "Unlock the Weather Terminal" : "解锁天气交易决策台"}

{isEn ? "Your account is verified. One step away from full access." : "账号已验证,只差一步即可获得完整访问权限。"}

{/* Price */}
$10 {t("month", isEn)}
{/* Feature list */}
    {features.map((f) => (
  • {f}
  • ))}
{/* CTA */}

{isEn ? "Cancel anytime · No hidden fees · Instant access after payment" : "随时取消 · 无隐藏费用 · 付款后立即解锁"}

{/* Back link */}
← {t("backToProduct", isEn)}
{/* Payment overlay */} {showOverlay && (
setUsePoints((prev) => !prev)} onPay={() => void handlePay()} onClose={() => setShowOverlay(false)} payBusy={payBusy} payLabel={ walletAddress ? isEn ? "Subscribe & Activate" : "立即订阅并激活服务" : isEn ? "Connect Wallet & Subscribe" : "连接钱包并订阅" } errorText={errorText || undefined} infoText={infoText || undefined} txHash={txHash || undefined} chainId={chainId} paymentTokenLabel={tokenSymbol} locale={isEn ? "en-US" : "zh-CN"} faqHref="/subscription-help" />
)}
); } // ─── Layer 1 fallback: Should not normally appear (middleware handles it) ───── function UnauthenticatedGate({ isEn, userLocalTime, }: { isEn: boolean; userLocalTime: string; }) { return (
); } /** Unified access gate — routes to the correct layer based on auth state */ export function ProductAccessRequired({ isAuthenticated, isEn, points, onPaid, userLocalTime, }: { isAuthenticated: boolean; isEn: boolean; points: number; onPaid: () => void; userLocalTime: string; }) { if (!isAuthenticated) { return ; } return (
); }