import { ArrowRight, Heart, MapPin, Moon, Route, Star, Sun } from "lucide-react";
import { AiImage } from "@/components/AiImage";
import { cruiseSlug } from "@/data/cruise-detail";
import { cruiseImage } from "@/data/home";
import { getMediaUrl } from "@/lib/admin-api";
import type { CatalogTour } from "@/lib/tours-api";

type Props = {
  cruise: CatalogTour;
};

export function CruiseListCard({ cruise }: Props) {
  const isDay = cruise.duration === "Day tour";
  const href = `/cruise-tours/${cruise.slug || cruiseSlug(cruise.name)}`;
  const imageSrc = cruise.cover_image
    ? getMediaUrl(cruise.cover_image)
    : cruiseImage(cruise, "wide");

  return (
    <article className="group flex flex-col overflow-hidden rounded-2xl border border-[var(--line)] bg-white transition hover:shadow-[0_14px_36px_rgba(13,58,77,0.1)] sm:flex-row">
      <div className="relative aspect-[16/11] shrink-0 overflow-hidden sm:aspect-auto sm:w-[280px] lg:w-[320px]">
        <AiImage
          src={imageSrc}
          alt={cruise.name}
          className="h-full min-h-[200px] w-full transition duration-700 group-hover:scale-105 sm:absolute sm:inset-0"
        />
        <span className="absolute top-3 left-3 inline-flex items-center gap-1.5 rounded-full bg-black/55 px-3 py-1 text-[11px] font-semibold text-white backdrop-blur">
          {isDay ? (
            <Sun className="h-3.5 w-3.5" strokeWidth={2} />
          ) : (
            <Moon className="h-3.5 w-3.5" fill="currentColor" strokeWidth={0} />
          )}
          {cruise.duration}
        </span>
        <button
          type="button"
          className="absolute top-3 right-3 grid h-8 w-8 place-items-center rounded-full bg-white/90 text-brand transition hover:bg-white"
          aria-label="Add to wishlist"
        >
          <Heart className="h-4 w-4" strokeWidth={2} />
        </button>
      </div>

      <div className="flex flex-1 flex-col justify-between gap-4 p-4 sm:p-5">
        <div className="space-y-2.5">
          <div className="flex items-start justify-between gap-3">
            <h3 className="text-lg leading-snug font-semibold text-brand-deep capitalize">
              {cruise.name}
            </h3>
            <div
              className="flex shrink-0 items-center gap-0.5 text-amber-400"
              aria-label={`${cruise.rating} star rating`}
            >
              {Array.from({ length: 5 }).map((_, i) => (
                <Star
                  key={i}
                  className={`h-3.5 w-3.5 ${i < cruise.rating ? "text-amber-400" : "text-[#d7e2e7]"}`}
                  fill="currentColor"
                  strokeWidth={0}
                />
              ))}
            </div>
          </div>

          <p className="flex items-center gap-1.5 text-sm text-muted">
            <MapPin className="h-4 w-4 text-accent" fill="currentColor" strokeWidth={0} />
            {cruise.bay}
          </p>

          <div className="flex flex-wrap gap-1.5">
            {cruise.amenities.slice(0, 4).map((item) => (
              <span
                key={item}
                className="rounded-full border border-[var(--line)] px-2.5 py-0.5 text-[11px] font-medium text-brand-deep"
              >
                {item}
              </span>
            ))}
          </div>

          <p className="flex items-start gap-1.5 text-xs text-muted sm:text-sm">
            <Route className="mt-0.5 h-4 w-4 shrink-0 text-[#e8845a]" strokeWidth={2} />
            <span>
              <span className="font-semibold tracking-wide text-brand-deep uppercase">
                Sea route:{" "}
              </span>
              {cruise.seaRoute}
            </span>
          </p>

          <p className="inline-flex rounded-full bg-accent/10 px-2.5 py-1 text-[11px] font-semibold text-brand">
            Pick up: {cruise.pickup}
          </p>
        </div>

        <div className="flex items-end justify-between gap-3 border-t border-[var(--line)] pt-3">
          <p className="text-sm">
            {cruise.price == null ? (
              <span className="font-bold text-accent">Price updating!</span>
            ) : (
              <>
                <span className="text-muted">From </span>
                <span className="text-xl font-bold text-[#e8845a]">${cruise.price}</span>{" "}
                <span className="text-xs font-medium text-muted">USD per person</span>
              </>
            )}
          </p>
          <a
            href={href}
            className="inline-flex items-center gap-2 rounded-full border border-accent px-4 py-2 text-sm font-semibold text-accent transition hover:bg-accent hover:text-white"
          >
            View cruise
            <ArrowRight className="h-4 w-4" strokeWidth={2.2} />
          </a>
        </div>
      </div>
    </article>
  );
}
