import { ImageVariant } from "@/generated/prisma";
import { formatFileSize } from "@/utils/formatFileSize";
import NextImage from "next/image";

export default function ImageVariants({ variants }: { variants: ImageVariant[] }) {
  return (
    <>
      <h2 className="font-semibold text-lg mb-2">Variants</h2>
      <div>
        {variants.map((variant) => (
          <div key={variant.id}>
            <div className="text-sm mb-1">{variant.type} | {variant.width}x{variant.height}px | {variant.sizeBytes ? formatFileSize(variant.sizeBytes) : "-"}</div>
            {variant.s3Key && (
              <NextImage src={`/api/image/${variant.s3Key}`} alt={variant.s3Key} width={variant.width} height={variant.height} className="rounded shadow max-w-md" />
            )}
          </div>
        ))}
      </div>
    </>
  );
}