// -----------------------------------------------------------------------------
// Lou-Ka — Agrégateur de logements à louer (province de Québec)
// Auteur : Simon-Pierre Boucher — contact@spboucher.ai
// components/ListingCard.tsx : carte d'annonce (grille de résultats)
// -----------------------------------------------------------------------------
import { Link } from "react-router-dom";
import { Listing, fmtPrice, sourceName } from "../api";

export default function ListingCard({ l }: { l: Listing }) {
  const img = l.images && l.images.length > 0 ? l.images[0] : null;
  return (
    <Link to={`/logement/${encodeURIComponent(l.uid)}`} className="card">
      <div className="card-img">
        {img ? (
          <img src={img} alt={l.title} loading="lazy" />
        ) : (
          <div className="noimg">🏠</div>
        )}
        {l.unit_type && <span className="badge type">{l.unit_type}</span>}
        {l.images.length > 1 && (
          <span className="badge right">📷 {l.images.length}</span>
        )}
      </div>
      <div className="card-body">
        <div className="card-price">
          {fmtPrice(l.price, l.price_label)} {l.price != null && <small>/ mois</small>}
        </div>
        <div className="card-title">{l.title || l.address}</div>
        <div className="card-meta">
          {l.sector && <span>{l.sector}</span>}
          {l.sector && l.city && <span className="sep" />}
          {l.city && <span>{l.city}</span>}
        </div>
        <div className="card-foot">
          <span className="source-tag">{sourceName(l.source)}</span>
          {l.availability && <span className="avail">{l.availability}</span>}
        </div>
      </div>
    </Link>
  );
}
