import { useMemo, useState } from "react"; import Image from "next/image"; import Link from "next/link"; import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { useTranslation } from "@/lib/i18n/client"; import { BookmarkTypes, ZBookmark } from "@karakeep/shared/types/bookmarks"; import { getAssetUrl } from "@karakeep/shared/utils/assetUtils"; // 20 MB const BIG_FILE_SIZE = 20 * 1024 * 1024; function PDFContentSection({ bookmark }: { bookmark: ZBookmark }) { if (bookmark.content.type != BookmarkTypes.ASSET) { throw new Error("Invalid content type"); } const { t } = useTranslation(); const initialSection = useMemo(() => { if (bookmark.content.type != BookmarkTypes.ASSET) { throw new Error("Invalid content type"); } const screenshot = bookmark.assets.find( (item) => item.assetType === "assetScreenshot", ); const bigSize = bookmark.content.size && bookmark.content.size > BIG_FILE_SIZE; if (bigSize && screenshot) { return "screenshot"; } return "pdf"; }, [bookmark]); const [section, setSection] = useState(initialSection); const screenshot = bookmark.assets.find( (r) => r.assetType === "assetScreenshot", )?.id; const content = section === "screenshot" && screenshot ? (