"use client"; import { useCallback, useEffect, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { api } from "@/lib/api"; import { useAuth } from "@/lib/auth"; import { useToast } from "@/lib/toast"; import { useI18n } from "@/lib/i18n"; import type { MatchIntent, MatchProfile, MatchQuota } from "@/lib/types"; import RingNext from "@/components/RingNext"; import { useRingSteps } from "@/lib/rings"; const INTENTS: { key: MatchIntent; label: string; emoji: string }[] = [ { key: "friends", label: "交朋友", emoji: "🤝" }, { key: "dating", label: "约会", emoji: "💕" }, { key: "partner", label: "伴侣", emoji: "💑" }, { key: "roommate", label: "合租", emoji: "🏠" }, { key: "cofounder", label: "联创", emoji: "🚀" }, { key: "explore", label: "探索", emoji: "🌍" }, ]; const PRIMARY_INTENTS = INTENTS.slice(0, 3); export default function DatingClient() { const { user, token } = useAuth(); const router = useRouter(); const { toast } = useToast(); const { t } = useI18n(); const rings = useRingSteps(); const [intent, setIntent] = useState("friends"); const [moreIntents, setMoreIntents] = useState(false); const [deck, setDeck] = useState([]); const [quota, setQuota] = useState(null); const [loading, setLoading] = useState(true); const [joined, setJoined] = useState(false); const [matchModal, setMatchModal] = useState<{ conversationId?: string; name: string } | null>(null); const load = useCallback(async () => { if (!token) return; setLoading(true); try { const [candidates, q] = await Promise.all([ api.getMatchCandidates(token, { intent }), api.getMatchQuota(token), ]); setDeck(candidates); setQuota(q); setJoined(true); } catch { setJoined(false); setDeck([]); } finally { setLoading(false); } }, [token, intent]); useEffect(() => { void load(); }, [load]); const quickJoin = async () => { if (!token) { router.push("/login?next=/dating"); return; } try { await api.socialJoin(token, { city: "全球", lookingFor: [intent, "explore"], bio: "nomadro 游民", }); toast("资料已完善,开始匹配", "success"); await load(); } catch { toast("加入失败", "error"); } }; const swipe = async (action: "like" | "dislike" | "superlike") => { if (!token || !deck[0]) return; const current = deck[0]; try { const res = await api.swipe(token, current.id, action, intent); if (res.matched && res.match?.conversationId) { setMatchModal({ conversationId: res.match.conversationId, name: current.name }); } setDeck((d) => d.slice(1)); const q = await api.getMatchQuota(token); setQuota(q); } catch { toast("滑动失败,请检查登录或配额", "error"); } }; const top = deck[0]; if (!user) { return (

{t.dating.loginTitle}

{t.dating.loginDesc}

{t.nav.login}
); } return (
{t.dating.tag}

{t.dating.title}

{t.dating.subtitle}

{(moreIntents ? INTENTS : PRIMARY_INTENTS).map((i) => ( ))} {!moreIntents && ( )}
{quota && (

{quota.vip ? "✨ VIP 无限滑" : `今日剩余 ${quota.remaining}/${quota.limit} 次`} {!quota.vip && quota.remaining <= 0 && ( <> {" · "} 开通 VIP 无限匹配 )}

)} {!joined && !loading && (

{t.dating.joinFirst}

)} {loading && joined &&

加载候选人…

} {top && (
{top.photo || "🧑‍💻"}

{top.name}

{top.location} · {top.gender} {top.single ? `· ${top.single}` : ""}

{top.bio}

{(top.tags || []).map((tag) => {tag})}
{token && ( )}
)} {!loading && joined && !top && (

{t.dating.empty}

去活动认识人 查看对话 {quota && !quota.vip && 开通 VIP}
)}
{matchModal && (

🎉 {t.dating.matched} {matchModal.name}!

{matchModal.conversationId && ( {t.dating.chatNow} )}
)}
); }