import type { MouseEvent as ReactMouseEvent } from 'react' import { useI18n } from '../../../i18n' import type { StudioFileAttachment, StudioWorkResult } from '../../protocol/studio-agent-types' import type { PlotPreviewVariant } from '../types' interface PlotPreviewSurfaceProps { attachment: StudioFileAttachment | null | undefined previewSrc?: string result: StudioWorkResult | null canNavigate: boolean currentIndex: number total: number variant: PlotPreviewVariant onOpen: () => void onContextMenu: (event: ReactMouseEvent) => void onPrev: () => void onNext: () => void } export function PlotPreviewSurface({ attachment, previewSrc, result, canNavigate, currentIndex, total, variant, onOpen, onContextMenu, onPrev, onNext, }: PlotPreviewSurfaceProps) { const { t } = useI18n() const isMinimal = variant === 'pure-minimal-top' if (attachment?.mimeType?.startsWith('image/') || isImagePath(attachment?.path)) { return (
{canNavigate && ( <>
{String(currentIndex + 1).padStart(2, '0')} / {String(total).padStart(2, '0')}
)}
) => { if (event.button !== 0) { return } onOpen() }} onKeyDown={(event) => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault() onOpen() } }} onContextMenu={onContextMenu} className={`flex h-full w-full cursor-zoom-in items-center justify-center animate-fade-in-soft ${ isMinimal ? 'px-4 py-3 sm:px-8 sm:py-6' : '' }`} title={t('image.openTitle')} >
{attachment?.name
) } if (result?.kind === 'failure-report') { return (
{t('studio.renderFailed')}
) } return (
[ Canvas Area ]
) } function isImagePath(path?: string) { return Boolean(path && /\.(png|jpg|jpeg|gif|webp|svg)$/i.test(path)) }