import { ChangeEvent, useEffect, useState } from 'react' import { retrieveRendition } from '../../../utils' import { ContentObjectItem } from '@vertesia/common' import { Button, Card, CardContent, Separator, VTooltip } from "@vertesia/ui/core" import { useUserSession } from "@vertesia/ui/session" import { DocumentSelection } from '../DocumentSelectionProvider' import { CheckIcon, Eye } from 'lucide-react' interface DocumentIconProps { document: ContentObjectItem onSelectionChange: ((object: ContentObjectItem, ev: ChangeEvent) => void); selection: DocumentSelection; onRowClick?: (object: ContentObjectItem) => void; highlightRow?: (item: ContentObjectItem) => boolean; previewObject?: (objectId: string) => void; selectedObject?: ContentObjectItem | null; } export function DocumentIconSkeleton({ isLoading = false, counts = 6 }: { isLoading?: boolean, counts?: number }) { if (!isLoading) { return null } return (
{Array(counts).fill(0).map((_, index) =>
 
)}
) } export function DocumentIcon({ selection, document, onSelectionChange, onRowClick, highlightRow, previewObject, selectedObject }: Readonly) { const { client } = useUserSession() const [renditionUrl, setRenditionUrl] = useState(undefined) const [renditionAlt, setRenditionAlt] = useState(undefined) const [renditionStatus, setRenditionStatus] = useState(undefined) const handleSelect = (ev: React.ChangeEvent) => { ev.stopPropagation() onSelectionChange(document, ev) } useEffect(() => { if (!document?.content) { return } retrieveRendition(client, document, setRenditionUrl, setRenditionAlt, setRenditionStatus) }, [document]) const isHighlighted = highlightRow?.(document); return ( (onRowClick && onRowClick(document))}> {isHighlighted && (
)} { selection && (
e.stopPropagation()} />
) }
{ (renditionUrl && renditionStatus == 'ready') ? ( {renditionAlt} ) : (
{renditionStatus}
) }

{document.properties?.title ?? document.name}

{ document?.type?.name ? (

{document?.type?.name}

) :

{"\u2002"}

}
{document.score && (
Score: {(document.score).toFixed(4) ?? "-"}
)}
) }