"use client" import type { FamilyMember } from "@/types/family" import { FamilyNode } from "./family-node" import { useFamily } from "@/context/family-context" interface TreeLayoutProps { rootId: string onSelectMember?: (member: FamilyMember) => void } export function TreeLayout({ rootId, onSelectMember }: TreeLayoutProps) { const { getMember } = useFamily() const root = getMember(rootId) if (!root) return null // Recursive component to render the tree const TreeNode = ({ memberId }: { memberId: string }) => { const member = getMember(memberId) if (!member) return null const hasChildren = member.childrenIds && member.childrenIds.length > 0 return (
{/* Connector to children */} {hasChildren &&
}
{hasChildren && (
{/* Horizontal connecting line */} {member.childrenIds.length > 1 && (
// Rough approx for connector width )}
{/* Top connecting lines for children */} {member.childrenIds.length > 1 && (
{/* This needs precise calculation or just use CSS pseudo elements on children */}
)} {member.childrenIds.map((childId, index) => (
{/* Vertical line from parent's horizontal line to child */}
{/* Horizontal connector fix for first/last child */} {member.childrenIds.length > 1 && ( <> {index === 0 &&
} {index === member.childrenIds.length - 1 && (
)} {index > 0 && index < member.childrenIds.length - 1 && (
)} )}
))}
)}
) } return (
) }