import { useState } from "react"; import { Tooltip } from "@mantine/core"; import { IconChevronRight, IconLock } from "@tabler/icons-react"; import { useTranslation } from "react-i18next"; import { ISpace } from "@/features/space/types/space.types"; import { IPage } from "@/features/page/types/page.types"; import { SpaceRole } from "@/lib/types"; import { CustomAvatar } from "@/components/ui/custom-avatar"; import { AvatarIconType } from "@/features/attachments/types/attachment.types"; import { PageChildren } from "./page-children"; import classes from "./destination-picker.module.css"; type SpaceRowProps = { space: ISpace; limit: number; selectedId: string | null; excludePageId?: string; onSelectSpace: (space: ISpace) => void; onSelectPage: (page: Partial, space: ISpace) => void; }; export function SpaceRow({ space, limit, selectedId, excludePageId, onSelectSpace, onSelectPage, }: SpaceRowProps) { const { t } = useTranslation(); const [expanded, setExpanded] = useState(false); const writable = !!space.membership?.role && space.membership.role !== SpaceRole.READER; const isSelected = space.id === selectedId; const rowClasses = [ classes.spaceRow, isSelected && classes.selected, !writable && classes.disabled, ] .filter(Boolean) .join(" "); const rowContent = (
writable && onSelectSpace(space)} > {writable ? (
{ e.stopPropagation(); setExpanded(!expanded); }} >
) : (
)}
{space.name}
{!writable && ( )}
); return ( <> {writable ? ( rowContent ) : (
{rowContent}
)} {expanded && writable && ( onSelectPage(page, space)} /> )} ); }