import Image from "next/image";
import Link from "next/link";
import { Bath, BedDouble, MapPin, Ruler, Trees } from "lucide-react";
import { localizedPath, type Locale, type PropertyCardDto } from "@alterra/shared";
import PriceTag from "./PriceTag";
import ExclusiveSeal from "../brand/ExclusiveSeal";
import type { PropertyCopy } from "@/lib/propertyCopy";

export default function PropertyCard({
  property,
  lang,
  copy,
  sizes = "(min-width: 1024px) 33vw, (min-width: 768px) 50vw, 100vw",
  priority = false,
}: {
  property: PropertyCardDto;
  lang: Locale;
  copy: Pick<PropertyCopy, "card" | "types" | "badges">;
  sizes?: string;
  priority?: boolean;
}) {
  const fmt = (n: number) => n.toLocaleString(lang === "es" ? "es-CO" : "en-US");
  const c = copy.card;

  return (
    <article className="group">
      <Link href={localizedPath(lang, `/properties/${property.slug}`)} className="block">
        <div className="relative aspect-[4/5] overflow-hidden bg-moss">
          {property.image && (
            <Image
              src={property.image.url}
              alt={property.image.alt}
              fill
              sizes={sizes}
              priority={priority}
              className="object-cover transition-transform duration-[1.6s] ease-out group-hover:scale-[1.06]"
            />
          )}
          <div className="absolute inset-x-4 top-4 flex items-start gap-2">
            <div className="flex flex-1 flex-wrap gap-2">
              <span className="eyebrow bg-ink/80 px-3 py-1.5 text-[0.6rem] text-cream backdrop-blur">{copy.types[property.type]}</span>
              {property.badges.map((badge) =>
                badge === "exclusive" ? (
                  <span key={badge} className="eyebrow flex items-center gap-1.5 bg-ink/85 py-1 pl-1.5 pr-3 text-[0.6rem] text-gold-light backdrop-blur">
                    <ExclusiveSeal size={18} />
                    {copy.badges[badge]}
                  </span>
                ) : (
                  <span key={badge} className="eyebrow bg-gold-light px-3 py-1.5 text-[0.6rem] text-ink">
                    {copy.badges[badge]}
                  </span>
                ),
              )}
            </div>
            {property.isSample && (
              <span className="eyebrow shrink-0 border border-cream/50 px-2.5 py-1.5 text-[0.55rem] text-cream backdrop-blur">{c.sample}</span>
            )}
          </div>
        </div>
        <div className="border-b border-sand py-6">
          <p className="flex items-center gap-1.5 text-xs tracking-wide text-stone uppercase">
            <MapPin size={13} strokeWidth={1.5} /> {property.location.name}
          </p>
          <h3 className="mt-2 font-serif text-[1.6rem] leading-tight transition-colors duration-500 group-hover:text-forest">{property.title}</h3>
          <div className="mt-4 flex flex-wrap items-center gap-x-5 gap-y-2 text-sm text-ink/80">
            {property.bedrooms ? (
              <span className="flex items-center gap-1.5">
                <BedDouble size={15} strokeWidth={1.4} /> {property.bedrooms} {c.beds}
              </span>
            ) : null}
            {property.bathrooms ? (
              <span className="flex items-center gap-1.5">
                <Bath size={15} strokeWidth={1.4} /> {property.bathrooms} {c.baths}
              </span>
            ) : null}
            {property.builtAreaM2 ? (
              <span className="flex items-center gap-1.5">
                <Ruler size={15} strokeWidth={1.4} /> {fmt(property.builtAreaM2)} m² {c.built}
              </span>
            ) : null}
            {property.lotAreaM2 ? (
              <span className="flex items-center gap-1.5">
                <Trees size={15} strokeWidth={1.4} /> {fmt(property.lotAreaM2)} m² {c.lot}
              </span>
            ) : null}
          </div>
          <div className="mt-5">
            <PriceTag
              price={property.price}
              lang={lang}
              priceOnRequest={c.priceOnRequest}
              perMonth={c.perMonth}
              usdNote={c.usdNote}
              rent={property.operation === "rent"}
            />
          </div>
        </div>
      </Link>
    </article>
  );
}
