import { isYoutubeLink } from "@lib/string.ts";
import { IconBrandYoutube } from "@components/icons.tsx";

export function Card(
  { link, title, image, backgroundSize = 100 }: {
    backgroundSize?: number;
    link?: string;
    title?: string;
    image?: string;
  },
) {
  const backgroundStyle = {
    backgroundImage: `url(${image})`,
    backgroundSize: "cover",
  };

  if (backgroundSize !== 100) {
    backgroundStyle["backgroundSize"] = `${backgroundSize}%`;
    backgroundStyle["backgroundRepeat"] = "no-repeat";
    backgroundStyle["backgroundPosition"] = "center";
  }

  return (
    <a
      href={link}
      style={backgroundStyle}
      class="text-white rounded-3xl shadow-md p-4 relative overflow-hidden 
  lg:w-56 lg:h-56 
  sm:w-48 sm:h-48
  w-[37vw] h-[37vw]"
    >
      <div class="h-full flex flex-col justify-between relative z-10">
        <div>
          {/* Recipe Card content */}
        </div>
        <div class="mt-2 flex items-center gap-2">
          {isYoutubeLink(link || "") && <IconBrandYoutube />}
          {title}
        </div>
      </div>
      <div
        class="absolute inset-x-0 bottom-0 h-3/4"
        style={{ background: "linear-gradient(transparent, #000e)" }}
      />
    </a>
  );
}
