"use client"; import type { ReactNode } from "react"; import { Lock } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { apiUnlockPost } from "@/lib/api"; import { toast } from "@/lib/toast"; import { hideKindLabel, type HideKind } from "@/lib/hideBlocks"; type MdHideBlockProps = { kind: HideKind; points?: number; locked?: boolean; postId?: number; loggedIn?: boolean; children?: ReactNode; }; /** 正文内嵌隐藏块:已解锁显示徽章容器;locked 显示就地门禁 */ export default function MdHideBlock({ kind, points = 0, locked = false, postId, loggedIn = false, children, }: MdHideBlockProps) { const router = useRouter(); const [busy, setBusy] = useState(false); const label = hideKindLabel(kind); if (locked) { const unlock = async () => { if (!postId) return; 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 ( ); } return (
{label} {kind === "points" && points > 0 && ( {points} 积分 )}
{children}
); }