import Image from "next/image";
import Link from "next/link";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { buttonVariants } from "@/components/ui/button";
import { ScrollArea } from "@/components/ui/scroll-area";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { useTranslation } from "@/lib/i18n/client";
import {
AlertTriangle,
Archive,
BookOpen,
Camera,
ExpandIcon,
Video,
} from "lucide-react";
import { useSession } from "next-auth/react";
import { useQueryState } from "nuqs";
import { ErrorBoundary } from "react-error-boundary";
import {
BookmarkTypes,
ZBookmark,
ZBookmarkedLink,
} from "@karakeep/shared/types/bookmarks";
import { contentRendererRegistry } from "./content-renderers";
import ReaderView from "./ReaderView";
function CustomRendererErrorFallback({ error }: { error: Error }) {
return (
Renderer Error
Failed to load custom content renderer.{" "}
Technical details
{error.message}
);
}
function FullPageArchiveSection({ link }: { link: ZBookmarkedLink }) {
const archiveAssetId =
link.fullPageArchiveAssetId ?? link.precrawledArchiveAssetId;
return (
);
}
function ScreenshotSection({ link }: { link: ZBookmarkedLink }) {
return (
);
}
function VideoSection({ link }: { link: ZBookmarkedLink }) {
return (
{/* eslint-disable-next-line jsx-a11y/media-has-caption -- captions not (yet) available */}
);
}
export default function LinkContentSection({
bookmark,
}: {
bookmark: ZBookmark;
}) {
const { t } = useTranslation();
const availableRenderers = contentRendererRegistry.getRenderers(bookmark);
const defaultSection =
availableRenderers.length > 0 ? availableRenderers[0].id : "cached";
const [section, setSection] = useQueryState("section", {
defaultValue: defaultSection,
});
const { data: session } = useSession();
const isOwner = session?.user?.id === bookmark.userId;
if (bookmark.content.type != BookmarkTypes.LINK) {
throw new Error("Invalid content type");
}
let content;
// Check if current section is a custom renderer
const customRenderer = availableRenderers.find((r) => r.id === section);
if (customRenderer) {
const RendererComponent = customRenderer.component;
content = (
);
} else if (section === "cached") {
content = (
);
} else if (section === "archive") {
content = ;
} else if (section === "video") {
content = ;
} else {
content = ;
}
return (
{section === "cached" && (
FullScreen
)}
{content}
);
}