"use client" import { useState } from 'react' import { SiteHeader } from '@/components/site-header' import { useFamily } from '@/context/family-context' import { useRelationship } from '@/hooks/use-relationship' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' export default function RelationshipTestPage() { const { treeData } = useFamily() const { calculateRelationship, getDirectRelatives, getSiblings } = useRelationship() const [fromId, setFromId] = useState('') const [toId, setToId] = useState('') const [result, setResult] = useState(null) const members = Object.values(treeData.members) const handleCalculate = () => { if (!fromId || !toId) return const relationship = calculateRelationship(fromId, toId) const fromMember = treeData.members[fromId] const toMember = treeData.members[toId] setResult({ from: fromMember, to: toMember, relationship }) } return (
{/* 标题 */}

家族关系计算器

选择两个家族成员,自动计算他们之间的亲属关系

{/* 选择成员 */} 选择成员 请选择要计算关系的两个成员
{/* 计算结果 */} {result && ( 计算结果
{result.from.fullName}
第{result.from.generation}世
{result.relationship.term} {result.relationship.path && ( 路径: {result.relationship.path} )}
{result.to.fullName}
第{result.to.generation}世
{result.relationship.description && (
关系说明:
{result.from.fullName}{result.to.fullName}{result.relationship.term}
)} {result.relationship.success === false && (
⚠️ {result.relationship.error || '无法计算关系'}
)}
)} {/* 快速查询示例 */} {fromId && ( {treeData.members[fromId]?.fullName} 的直系亲属 {(() => { const relatives = getDirectRelatives(fromId) if (!relatives) return null return (
{relatives.father && (
父亲
{relatives.father.fullName}
)} {relatives.mother && (
母亲
{relatives.mother.fullName}
)} {relatives.spouses.length > 0 && (
配偶
{relatives.spouses.map((spouse: any) => (
{spouse.fullName}
))}
)} {relatives.children.length > 0 && (
子女 ({relatives.children.length}人)
{relatives.children.slice(0, 3).map((child: any) => (
{child.fullName}
))} {relatives.children.length > 3 && (
还有 {relatives.children.length - 3} 人...
)}
)}
) })()} {(() => { const siblings = getSiblings(fromId) if (siblings.length === 0) return null return (
兄弟姐妹 ({siblings.length}人)
{siblings.map((sibling: any) => ( {sibling.fullName} ))}
) })()}
)}
) }