"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { Lock } from "lucide-react"; import { apiUnlockPost } from "@/lib/api"; import { toast } from "@/lib/toast"; export default function ContentLockGate({ postId, hint, access, points, loggedIn, }: { postId: number; hint?: string; access?: string; points?: number; loggedIn: boolean; }) { const router = useRouter(); const [busy, setBusy] = useState(false); const unlock = async () => { setBusy(true); try { const res = await apiUnlockPost(String(postId)); if (res.post) { toast("已解锁全文", "ok"); router.refresh(); } else { toast(res.error || "解锁失败", "error"); } } catch { toast("解锁失败", "error"); } finally { setBusy(false); } }; return (

{hint || "正文暂不可见"}

{access === "points" ? `支付 ${points || 0} 积分后可阅读全文` : access === "reply" ? "发表一条回复后即可阅读全文" : access === "login" ? "登录后即可阅读全文" : null}

{access === "login" && !loggedIn && ( 去登录 )} {access === "points" && loggedIn && ( )} {access === "points" && !loggedIn && ( 登录后解锁 )} {access === "reply" && ( 去回复 )}
); }