import { useState } from "react";
import { ImageOff } from "lucide-react";
interface ResilientImageProps {
src: string;
alt: string;
className?: string;
fallbackTitle?: string;
}
export function ResilientImage({
src,
alt,
className = "",
fallbackTitle,
}: ResilientImageProps) {
const [hasError, setHasError] = useState(false);
if (hasError) {
return (
<div
className={`flex flex-col items-center justify-center bg-[#EFECE5] text-[#475569] p-6 text-center ${className}`}
role="img"
aria-label={alt}
>
<ImageOff className="w-6 h-6 mb-2 text-[#9A630A]" aria-hidden="true" />
<p className="text-sm font-medium text-[#1C2430]">{fallbackTitle || alt}</p>
</div>
);
}
return (
<img
src={src}
alt={alt}
referrerPolicy="no-referrer"
onError={() => setHasError(true)}
className={className}
/>
);
}