'use client'; import { useCallback, useEffect, useState } from 'react'; import { Image as ImageIcon } from 'lucide-react'; import { useForm } from 'react-hook-form'; import { Button } from '../shadcn/button'; import { ImageUploadInput } from './image-upload-input'; import { Trans } from './trans'; export function ImageUploader( props: React.PropsWithChildren<{ value: string | null | undefined; onValueChange: (value: File | null) => unknown; }>, ) { const [image, setImage] = useState(props.value); const { setValue, register } = useForm<{ value: string | null | FileList; }>({ defaultValues: { value: props.value, }, mode: 'onChange', reValidateMode: 'onChange', }); const control = register('value'); const onClear = useCallback(() => { props.onValueChange(null); setValue('value', null); setImage(''); }, [props, setValue]); const onValueChange = useCallback( ({ image, file }: { image: string; file: File }) => { props.onValueChange(file); setImage(image); }, [props], ); const Input = () => ( ); useEffect(() => { setImage(props.value); }, [props.value]); if (!image) { return ( ); } return (
); } function FallbackImage( props: React.PropsWithChildren<{ descriptionSection?: React.ReactNode; }>, ) { return (
{props.descriptionSection}
); }