import { X } from 'lucide-react'; import type { ButtonHTMLAttributes, ReactNode } from 'react'; import { ResolvedAssetImage } from '../ResolvedAssetImage'; import { PlatformIconButton } from './PlatformIconButton'; import { PlatformSubpanel } from './PlatformSubpanel'; type PlatformUploadPreviewCardProps = { imageSrc: string; imageAlt: string; imageRefreshKey?: string | number | null; removeLabel: string; layout?: 'square' | 'inline'; surface?: 'platform' | 'editorDark'; caption?: ReactNode; previewLabel?: string; onPreview?: () => void; onRemove?: () => void; disabled?: boolean; resolveAsset?: boolean; className?: string; imageClassName?: string; imageShellClassName?: string; captionClassName?: string; removeIcon?: ReactNode; previewButtonProps?: Omit< ButtonHTMLAttributes, 'aria-label' | 'children' | 'disabled' | 'onClick' | 'type' >; removeButtonProps?: Omit< ButtonHTMLAttributes, 'aria-label' | 'children' | 'disabled' | 'onClick' | 'type' >; }; /** * 平台上传预览卡片。 * 统一承载上传后缩略图、预览壳和右上角移除按钮。 */ export function PlatformUploadPreviewCard({ imageSrc, imageAlt, imageRefreshKey = null, removeLabel, layout = 'square', surface = 'platform', caption, previewLabel, onPreview, onRemove, disabled = false, resolveAsset = false, className, imageClassName, imageShellClassName, captionClassName, removeIcon = , previewButtonProps, removeButtonProps, }: PlatformUploadPreviewCardProps) { const { className: previewButtonClassName, ...restPreviewButtonProps } = previewButtonProps ?? {}; const { className: removeButtonClassName, ...restRemoveButtonProps } = removeButtonProps ?? {}; const inline = layout === 'inline'; const editorDark = surface === 'editorDark'; const imageClassNames = ['h-full w-full object-cover', imageClassName] .filter(Boolean) .join(' '); const imageShellClassNames = [ inline ? [ 'h-12 w-12 shrink-0 overflow-hidden rounded-[0.8rem]', editorDark ? 'border border-white/10 bg-black/30' : 'bg-[var(--platform-track-fill)]', ].join(' ') : caption ? 'aspect-square overflow-hidden' : 'h-full w-full', imageShellClassName, ] .filter(Boolean) .join(' '); const captionClassNames = [ 'truncate px-2 py-2 pr-8 text-[11px] font-semibold', editorDark ? 'text-zinc-300' : 'text-[var(--platform-text-base)]', captionClassName, ] .filter(Boolean) .join(' '); const previewActionLabel = previewLabel ?? imageAlt; const imageElement = resolveAsset ? ( ) : ( {imageAlt} ); const imageContent = caption || imageShellClassName || inline ? (
{imageElement}
) : ( imageElement ); const squareRootClassName = surface === 'editorDark' ? 'relative h-[5.75rem] w-[5.75rem] overflow-hidden rounded-xl border border-white/10 bg-black/25' : 'relative h-[5.75rem] w-[5.75rem] overflow-hidden rounded-xl border border-[var(--platform-subpanel-border)] bg-[var(--platform-input-fill)]'; const cardContent = ( <> {onPreview ? ( ) : ( imageContent )} {caption ? (
{caption}
) : null} {onRemove ? ( ) : null} ); if (inline) { return ( {cardContent} ); } return (
{cardContent}
); }