"use client"; import { Icon } from "@/components/icons"; import { FileField } from "@/components/qr-forms/file-field"; import type { QrFormProps } from "@/components/qr-forms/types"; import { Field, TextArea, TextInput } from "@/components/ui"; import { MAX_IMAGES, type ImageEntry } from "@/lib/qr/types/image"; import { formatBytes } from "@/lib/uploads.shared"; function readImages(value: unknown): ImageEntry[] { if (!Array.isArray(value)) return []; return value.flatMap((entry) => { const record = (entry ?? {}) as Record; if (typeof record.fileId !== "string" || record.fileId.length === 0) { return []; } return [ { fileId: record.fileId, filename: typeof record.filename === "string" ? record.filename : "bild", size: typeof record.size === "number" ? record.size : 0, caption: typeof record.caption === "string" ? record.caption : "", }, ]; }); } export function ImageForm({ value, onChange, error, disabled }: QrFormProps) { const title = typeof value.title === "string" ? value.title : ""; const description = typeof value.description === "string" ? value.description : ""; const images = readImages(value.images); const setImages = (next: ImageEntry[]) => onChange({ ...value, images: next }); const move = (index: number, direction: -1 | 1) => { const target = index + direction; if (target < 0 || target >= images.length) return; const next = [...images]; [next[index], next[target]] = [next[target], next[index]]; setImages(next); }; return (
Bilder {images.length} von {MAX_IMAGES}
{images.length > 0 ? (
    {images.map((image, index) => (
  • {/* eslint-disable-next-line @next/next/no-img-element -- eigene Auslieferung, unbekannte Maße */}

    {image.filename} {image.size > 0 ? ` · ${formatBytes(image.size)}` : ""}

    setImages( images.map((entry, i) => i === index ? { ...entry, caption: event.target.value } : entry, ), ) } />
  • ))}
) : null} {images.length < MAX_IMAGES ? ( setImages([ ...images, { fileId: file.fileId, filename: file.filename, size: file.size, caption: "", }, ]) } /> ) : null} {error ? (

{error}

) : (

PNG, JPEG, WebP, GIF oder AVIF. Mehrere Bilder erscheinen untereinander als Galerie.

)}
onChange({ ...value, title: event.target.value })} />