import { Captions, Clock, ClockArrowDown, Copy, FileCheck, Mountain, } from "lucide-react"; import SpoiledWrapper from "@/components/spoiled-wrapper"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; import React from "react"; import { type TelegramFile } from "@/lib/types"; import { type RowHeight } from "@/components/table-row-height-switch"; import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard"; import { formatDistanceToNow } from "date-fns"; import { cn } from "@/lib/utils"; import useIsMobile from "@/hooks/use-is-mobile"; interface FileExtraProps { file: TelegramFile; rowHeight: RowHeight; } function FileName({ file }: { file: TelegramFile }) { if (!file.fileName) { return null; } return (

{file.fileName}

); } function FileCaption({ file, rowHeight }: FileExtraProps) { if (!file.caption) { return null; } return (

{file.caption}

"), }} >

); } function FilePath({ file }: { file: TelegramFile }) { const [, copyToClipboard] = useCopyToClipboard(); const isMobile = useIsMobile(); if (!file.localPath) { return null; } return (

!isMobile && copyToClipboard(file.localPath)} > {file.localPath.split("/").pop()}

{file.localPath}
); } function FileTime({ file }: { file: TelegramFile }) { return (

{formatDistanceToNow(new Date(file.date * 1000), { addSuffix: true, })}

{`Message received at ${new Date(file.date * 1000).toLocaleString()}`}
{file.completionDate && (

{formatDistanceToNow(new Date(file.completionDate), { addSuffix: true, })}

{`File downloaded at ${new Date(file.completionDate).toLocaleString()}`}
)}
); } function hasValue(value: string | null | undefined): boolean { return value !== null && value !== undefined && value.trim() !== ""; } export default function FileExtra({ file, rowHeight }: FileExtraProps) { if (rowHeight === "s") { const renderOrder = [ { key: "fileName", Component: FileName }, { key: "caption", Component: FileCaption }, { key: "localPath", Component: FilePath }, { key: "default", Component: FileTime }, ]; for (const item of renderOrder) { if ( item.key === "default" || hasValue(file[item.key as keyof typeof file] as string) ) { return ( ); } } } return (
); }