import { useEffect, useState } from "react";
import { Collapsible, CollapsibleContent } from "@/components/ui/collapsible";
import { FullPageSpinner } from "@/components/ui/full-page-spinner";
import {
augmentBookmarkListsWithInitialData,
useBookmarkLists,
} from "@hoarder/shared-react/hooks/lists";
import { ZBookmarkList } from "@hoarder/shared/types/lists";
import { ZBookmarkListTreeNode } from "@hoarder/shared/utils/listUtils";
type RenderFunc = (params: {
item: ZBookmarkListTreeNode;
level: number;
open: boolean;
}) => React.ReactNode;
type IsOpenFunc = (list: ZBookmarkListTreeNode) => boolean;
function ListItem({
node,
render,
level,
className,
isOpenFunc,
}: {
node: ZBookmarkListTreeNode;
render: RenderFunc;
isOpenFunc: IsOpenFunc;
level: number;
className?: string;
}) {
// Not the most efficient way to do this, but it works for now
const isAnyChildOpen = (
node: ZBookmarkListTreeNode,
isOpenFunc: IsOpenFunc,
): boolean => {
if (isOpenFunc(node)) {
return true;
}
return node.children.some((l) => isAnyChildOpen(l, isOpenFunc));
};
const [open, setOpen] = useState(false);
useEffect(() => {
setOpen((curr) => curr || isAnyChildOpen(node, isOpenFunc));
}, [node, isOpenFunc]);
return (