import { Card } from "@components/Card.tsx";
import { Recipe } from "@lib/resource/recipes.ts";
import { isLocalImage } from "@lib/string.ts";

export function RecipeCard({ recipe }: { recipe: Recipe }) {
  const { meta: { image = "/placeholder.svg" } = {} } = recipe;

  const imageUrl = isLocalImage(image)
    ? `/api/images?image=${image}&width=200&height=200`
    : image;

  return (
    <Card
      title={recipe.name}
      image={imageUrl}
      thumbnail={recipe?.meta?.thumbnail}
      link={`/recipes/${recipe.id}`}
    />
  );
}
