import { Fragment, useMemo } from "react";
import { Link } from "@tanstack/react-router";
import { ChevronRight, Lock } from "lucide-react";
import type { Page, PageAncestor } from "@/shared/types";
import { DEFAULT_PAGE_TITLE } from "@/shared/constants";
import { EmojiIcon } from "@/client/components/ui/emoji-icon";
interface LabelProps {
currentTitle: string;
currentIcon: string | null;
}
interface WorkspaceFramedProps extends LabelProps {
workspaceSlug: string;
workspaceName?: string | null;
}
type PageBreadcrumbsProps =
| (WorkspaceFramedProps & {
mode: "workspace";
pages: Page[];
currentParentId: string | null;
})
| (WorkspaceFramedProps & {
mode: "shared-in-workspace";
ancestors: PageAncestor[];
})
| (LabelProps & {
mode: "shared";
ancestors: PageAncestor[];
onNavigate: (pageId: string) => void;
});
const RESTRICTED_TITLE = "You don't have access to this page";
function Sep() {
return ;
}
function CurrentLabel({ title, icon }: { title: string; icon: string | null }) {
return (
{icon && }
{title || DEFAULT_PAGE_TITLE}
);
}
function RestrictedLabel() {
return (
Restricted
);
}
function EllipsisDot() {
return (
…
);
}
function WorkspaceBreadcrumbs({
currentTitle,
currentIcon,
workspaceSlug,
workspaceName,
pages,
currentParentId,
}: WorkspaceFramedProps & { pages: Page[]; currentParentId: string | null }) {
const ancestors = useMemo(() => {
const chain: Page[] = [];
const byId = new Map(pages.map((p) => [p.id, p]));
let cur = currentParentId ? byId.get(currentParentId) : undefined;
while (cur && chain.length < 10) {
chain.push(cur);
cur = cur.parent_id ? byId.get(cur.parent_id) : undefined;
}
return chain.reverse();
}, [pages, currentParentId]);
const workspaceLabel = workspaceName ?? workspaceSlug;
const immediateAncestor = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
const hasHiddenPrefix = ancestors.length > 0;
return (
);
}
function SharedInWorkspaceBreadcrumbs({
currentTitle,
currentIcon,
workspaceSlug,
workspaceName,
ancestors,
}: WorkspaceFramedProps & { ancestors: PageAncestor[] }) {
const workspaceLabel = workspaceName ?? workspaceSlug;
const immediateAncestor = ancestors.length > 0 ? ancestors[ancestors.length - 1] : null;
const hasHiddenPrefix = ancestors.length > 0;
return (
);
}
function SharedBreadcrumbs({
currentTitle,
currentIcon,
ancestors,
onNavigate,
}: LabelProps & {
ancestors: PageAncestor[];
onNavigate: (pageId: string) => void;
}) {
if (ancestors.length === 0) return null;
const immediateAncestor = ancestors[ancestors.length - 1];
const hasHiddenPrefix = ancestors.length > 1;
return (
);
}
export function PageBreadcrumbs(props: PageBreadcrumbsProps) {
if (props.mode === "workspace") {
return (
);
}
if (props.mode === "shared-in-workspace") {
return (
);
}
return (
);
}