import { KeyboardEvent, useState } from "react"; import { ActionIcon } from "@mantine/core"; import { IconChevronRight, IconFileDescription } from "@tabler/icons-react"; import { useTranslation } from "react-i18next"; import { IPage } from "@/features/page/types/page.types"; import { getPageTitle } from "@/features/page/page.utils"; import { PageChildren } from "./page-children"; import classes from "./destination-picker.module.css"; type PageRowProps = { page: Partial; depth: number; limit: number; selectedId: string | null; excludePageId?: string; onSelect: (page: Partial) => void; }; export function PageRow({ page, depth, limit, selectedId, excludePageId, onSelect, }: PageRowProps) { const { t } = useTranslation(); const [expanded, setExpanded] = useState(false); const isExcluded = page.id === excludePageId; const isSelected = page.id === selectedId; const rowClasses = [ classes.pageRow, isSelected && classes.selected, isExcluded && classes.disabled, ] .filter(Boolean) .join(" "); const handleSelect = () => { if (!isExcluded) onSelect(page); }; const handleRowKeyDown = (e: KeyboardEvent) => { if (e.target !== e.currentTarget) return; if (e.key === "Enter" || e.key === " ") { e.preventDefault(); handleSelect(); } }; return ( <>
{page.hasChildren ? ( { e.stopPropagation(); setExpanded(!expanded); }} > ) : (
)}
{page.icon ? ( page.icon ) : ( )}
{getPageTitle(page.title, page.isBase, t)}
{expanded && page.hasChildren && ( )} ); }