import type { ReactNode } from 'react';
import { Car, ImageOff } from 'lucide-react';
import { cn } from '../utils/cn';
export interface ThumbnailItem {
/** Backend image URL — null/undefined renders placeholder */
url?: string | null;
/** Alt text for accessibility */
alt?: string;
/** Optional badge content rendered top-right (e.g. damage count) */
badge?: ReactNode;
/** Optional label rendered bottom (e.g. "Ön sol") */
label?: string;
}
interface Props {
items: ThumbnailItem[];
className?: string;
/** Click handler — called with item index */
onItemClick?: (index: number) => void;
/** Aspect ratio class — defaults to 4:3 for vehicle photos */
aspectRatioClass?: string;
}
/**
* Responsive thumbnail grid for multi-photo inspections.
* - 3 columns on mobile, 4 on sm, 6 on lg
* - Fixed aspect ratio reserves space (prevents CLS)
* - Renders car-icon placeholder when image url is missing
*/
export function MultiImageThumbnailGrid({
items,
className,
onItemClick,
aspectRatioClass = 'aspect-[4/3]',
}: Props) {
if (!items || items.length === 0) return null;
return (
{items.map((item, i) => {
const interactive = !!onItemClick;
const hasUrl = !!item.url;
const alt = item.alt ?? `Fotoğraf ${i + 1}`;
const content = (
<>
{hasUrl ? (
// packages/ui is framework-agnostic — plain
with
// explicit width/height reserves space (parent aspect ratio
// prevents CLS). Consumer apps can wrap with next/image if
// they need optimised srcSet.
) : (
)}
{item.badge && (
{item.badge}
)}
{item.label && (
{item.label}
)}
>
);
return (
{interactive ? (
onItemClick?.(i)}
aria-label={item.label ? `${item.label} — ${alt}` : alt}
className="group block w-full rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500 focus-visible:ring-offset-2"
>
{content}
) : (
{content}
)}
);
})}
);
}
function ThumbnailPlaceholder({ index }: { index: number }) {
return (
#{index + 1}
);
}
/**
* Compact placeholder for history rows when no thumbnail is available.
* Use as standalone (square) icon block.
*/
export function ThumbnailFallback({
className,
size = 'md',
}: {
className?: string;
size?: 'sm' | 'md' | 'lg';
}) {
const dimensions =
size === 'sm' ? 'h-10 w-10' : size === 'lg' ? 'h-20 w-20' : 'h-14 w-14';
const iconSize =
size === 'sm' ? 'h-5 w-5' : size === 'lg' ? 'h-9 w-9' : 'h-7 w-7';
return (
);
}