import { useFileBlobUrl } from '../../hooks/useFileBuffer';
import { FilePreviewFallback } from './FilePreviewFallback';

interface PdfPreviewProps {
  fileId: string;
  fileName: string;
}

export function PdfPreview({ fileId, fileName }: PdfPreviewProps) {
  const { blobUrl, loading, error } = useFileBlobUrl(fileId, 'application/pdf');

  if (error || (!loading && !blobUrl)) {
    return <FilePreviewFallback fileId={fileId} fileName={fileName} error={error} />;
  }

  if (loading || !blobUrl) {
    return <FilePreviewFallback fileId={fileId} fileName={fileName} loading />;
  }

  return (
    <iframe
      src={blobUrl}
      title={fileName}
      className="h-full w-full border-0 bg-white"
    />
  );
}
