"use client"; import { useTranslation } from "react-i18next"; import { fadeInUp } from "../Animation/OwnerPageAnimation"; import { handleImageUpload } from "@/app/HelperFunction/UploadImage"; import { motion } from "framer-motion"; import Image from "next/image"; import { Camera, X } from "lucide-react"; import { useRef } from "react"; export default function UploadImage({ idImagePreviews, type, errors, setIdImagePreviews, setIdImages }) { const { t } = useTranslation(); const fileInputRef = useRef(null); const currentPreview = idImagePreviews?.[type]; const handleRemoveImage = (e) => { e.stopPropagation(); setIdImages((prev) => ({ ...prev, [type]: null })); setIdImagePreviews((prev) => ({ ...prev, [type]: "" })); if (fileInputRef.current) { fileInputRef.current.value = ""; } }; const getLabel = () => { switch (type) { case "front": return t("register.owner.frontIdLabel"); case "back": return t("register.owner.backIdLabel"); case "license": return t("register.owner.licenseImageLabel"); default: return ""; } }; const getClickText = () => { return type === "license" ? t("register.owner.clickUploadLicense") : t("register.owner.clickUploadImage"); }; const getAltText = () => { switch (type) { case "front": return t("register.uploadFrontAlt"); case "back": return t("register.uploadBackAlt"); case "license": return t("register.uploadLicenseAlt"); default: return "Preview Image"; } }; return ( {type === "license" &&
{t("register.owner.licenseHint")}
}
fileInputRef.current?.click()} className={`relative border-2 border-dashed rounded-xl p-6 text-center cursor-pointer transition-all ${ currentPreview ? "border-green-500 bg-green-500/10" : errors ? "border-red-500 bg-red-500/10" : "border-gray-700 hover:border-amber-500 hover:bg-white/5" }`} > handleImageUpload(type, e.target.files?.[0], t, setIdImagePreviews, setIdImages)} className="hidden" /> {currentPreview ? (
{getAltText()}
) : ( <>

{getClickText()}

JPEG, PNG, JPG • {t("register.upTo5MB")}

)}
{errors &&

{errors}

}
); }