"use client"; import { PublicRestaurant } from "@/app/types/Types"; import { glassSurfaceCard } from "@/lib/styles/glassSurface"; import { ArrowLeft2, Location } from "iconsax-react"; import Image from "next/image"; import Link from "next/link"; import { useState } from "react"; const FALLBACK_LOGO = "/assets/images/avatar.svg"; function isValidLogoUrl(url: string | null | undefined): url is string { if (!url?.trim()) return false; const lower = url.toLowerCase(); if (lower.endsWith(".pdf")) return false; return lower.startsWith("http") || lower.startsWith("/"); } function getInitials(name: string): string { const trimmed = name.trim(); if (!trimmed) return "?"; return trimmed.charAt(0); } type Props = { restaurant: PublicRestaurant; }; export default function RestaurantCard({ restaurant }: Props) { const validLogo = isValidLogoUrl(restaurant.logo); const [logoSrc, setLogoSrc] = useState(validLogo && restaurant.logo ? restaurant.logo : FALLBACK_LOGO); const showInitials = !validLogo || logoSrc === FALLBACK_LOGO; return (
{showInitials ? (
{getInitials(restaurant.name)}
) : ( {restaurant.name} setLogoSrc(FALLBACK_LOGO)} /> )}

{restaurant.name}

{restaurant.address && (

{restaurant.address?.trim()}

)} {restaurant.establishedYear != null && (

سال تاسیس {restaurant.establishedYear}

)}
); }