// -----------------------------------------------------------------------------
// Immo-Ka — Agrégateur de propriétés à vendre (province de Québec)
// Auteur : Simon-Pierre Boucher — contact@spboucher.ai
// components/Icons.tsx : iconographie MAISON — traits 1,7 px sur grille 24,
//   dessinée pour Immo-Ka (zéro emoji, zéro pack générique). Chaque icône est
//   un tracé « stroke » net qui hérite de la couleur du texte (currentColor).
// -----------------------------------------------------------------------------
import { ReactNode } from "react";

const P: Record<string, ReactNode> = {
  // --- navigation -----------------------------------------------------------
  home: (<>
    <path d="M3.5 10.6 12 3.4l8.5 7.2" />
    <path d="M5.6 9.4V20h12.8V9.4" />
    <path d="M10 20v-5.6h4V20" />
  </>),
  map: (<>
    <path d="M3.2 6.4 9 4.2l6 2.2 5.8-2.2v13.4L15 19.8l-6-2.2-5.8 2.2z" />
    <path d="M9 4.2v13.4M15 6.4v13.4" />
  </>),
  chart: (<>
    <path d="M4 20h16" />
    <path d="M7.2 20v-5.6M12 20V8.8M16.8 20V12" />
  </>),
  building: (<>
    <path d="M5 20V5.6A1.6 1.6 0 0 1 6.6 4h6.2a1.6 1.6 0 0 1 1.6 1.6V20" />
    <path d="M14.4 9.4h3.4A1.6 1.6 0 0 1 19.4 11v9" />
    <path d="M3.2 20h17.6" />
    <path d="M8 8h2.4M8 11.6h2.4M8 15.2h2.4M16.4 13h.9M16.4 16.2h.9" />
  </>),

  // --- specs propriété --------------------------------------------------------
  bed: (<>
    <path d="M3.4 6.8V18.6" />
    <path d="M3.4 15.4h17.2v3.2" />
    <path d="M3.4 12.2h6.2v3.2" />
    <circle cx="6.5" cy="9.9" r="1.35" />
    <path d="M11.4 12.2h5.8a3.4 3.4 0 0 1 3.4 3.2" />
  </>),
  bath: (<>
    <path d="M3.6 12.4h16.8v1.4a5.2 5.2 0 0 1-5.2 5.2H8.8a5.2 5.2 0 0 1-5.2-5.2z" />
    <path d="M5.8 12.4V5.9a2.1 2.1 0 0 1 4-1" />
    <path d="m7 19.4-1 2.1M17 19.4l1 2.1" />
  </>),
  drop: (<>
    <path d="M12 3.6s6 6.4 6 10.6a6 6 0 1 1-12 0C6 10 12 3.6 12 3.6z" />
    <path d="M9.4 14.2a2.7 2.7 0 0 0 2 2.6" />
  </>),
  area: (<>
    <path d="M4.4 19.6 19.6 4.4" />
    <path d="M4.4 14v5.6H10" />
    <path d="M19.6 10V4.4H14" />
  </>),
  land: (<>
    <path d="M4.4 9.6v9.8M9.5 9.6v9.8M14.5 9.6v9.8M19.6 9.6v9.8" />
    <path d="M3 12.6h18M3 16.4h18" />
    <path d="M4.4 9.6 12 5.2l7.6 4.4" />
  </>),
  calendar: (<>
    <rect x="4" y="5.6" width="16" height="14.8" rx="2" />
    <path d="M4 10.2h16M8.2 3.4v4M15.8 3.4v4" />
  </>),
  tag: (<>
    <path d="m12.9 3.6 7.5 7.5a1.8 1.8 0 0 1 0 2.5l-6.8 6.8a1.8 1.8 0 0 1-2.5 0L3.6 12.9V3.6z" />
    <circle cx="8" cy="8" r="1.5" />
  </>),
  camera: (<>
    <rect x="3.4" y="7" width="17.2" height="13" rx="2" />
    <path d="M8.6 7 10 4.4h4L15.4 7" />
    <circle cx="12" cy="13.2" r="3.4" />
  </>),

  // --- actions / états ----------------------------------------------------------
  search: (<>
    <circle cx="10.6" cy="10.6" r="6.2" />
    <path d="m15.3 15.3 5.3 5.3" />
  </>),
  arrow: (<>
    <path d="M4 12h15.2" />
    <path d="m13.8 6.4 5.4 5.6-5.4 5.6" />
  </>),
  check: (<path d="m5 12.8 4.3 4.4L19 7.4" />),
  alert: (<>
    <path d="M12 4.2 2.9 19.4h18.2z" />
    <path d="M12 10.2v4.4" />
    <path d="M12 17.4v.05" />
  </>),
  phone: (<path d="M5.2 4h3.6L10.4 8.4 8.3 10.1a12.5 12.5 0 0 0 5.6 5.6l1.7-2.1 4.4 1.6v3.6a1.8 1.8 0 0 1-1.9 1.8A16.4 16.4 0 0 1 3.4 5.9 1.8 1.8 0 0 1 5.2 4z" />),
  trendup: (<>
    <path d="m3.6 17.4 6-6.4 4 3.6 6.8-7.8" />
    <path d="M15.6 6.8h4.8v4.8" />
  </>),
  trenddown: (<>
    <path d="m3.6 6.8 6 6.4 4-3.6 6.8 7.8" />
    <path d="M15.6 17.4h4.8v-4.8" />
  </>),
  external: (<>
    <path d="M14.4 4h5.6v5.6" />
    <path d="M20 4 11.4 12.6" />
    <path d="M18.6 13.6V18a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7.4a2 2 0 0 1 2-2h4.4" />
  </>),
  pin: (<>
    <path d="M12 21.2S5.4 15.7 5.4 10.8a6.6 6.6 0 0 1 13.2 0c0 4.9-6.6 10.4-6.6 10.4z" />
    <circle cx="12" cy="10.6" r="2.3" />
  </>),

  // --- quartier ---------------------------------------------------------------------
  leaf: (<>
    <path d="M5 19.2C5 9.6 12 5 20 4.2c0 9-4.2 15-13.2 15z" />
    <path d="M5 19.2C7 14 11 10 15 8" />
  </>),
  thermo: (<>
    <path d="M10.4 4.2a1.9 1.9 0 0 1 3.8 0v8.8a4.2 4.2 0 1 1-3.8 0z" />
    <path d="M12.3 8.4v7" />
  </>),
  sun: (<>
    <circle cx="12" cy="12" r="4.2" />
    <path d="M12 3.2v2M12 18.8v2M3.2 12h2M18.8 12h2M5.8 5.8l1.4 1.4M16.8 16.8l1.4 1.4M18.2 5.8l-1.4 1.4M7.2 16.8l-1.4 1.4" />
  </>),
  shield: (<>
    <path d="M12 3.4 5.2 5.9v5.9c0 4.6 3 7.6 6.8 8.8 3.8-1.2 6.8-4.2 6.8-8.8V5.9z" />
    <path d="m9.2 12 2 2 3.8-4" />
  </>),
  cart: (<>
    <circle cx="9.6" cy="19.6" r="1.35" />
    <circle cx="17" cy="19.6" r="1.35" />
    <path d="M3.4 4.4h2.2l2.5 10.8h9.6l2.7-7.8H7" />
  </>),
  bus: (<>
    <rect x="4.6" y="3.8" width="14.8" height="13.4" rx="2.4" />
    <path d="M4.6 10.4h14.8" />
    <path d="M7.6 20.2v-3M16.4 20.2v-3" />
    <path d="M8.3 14h.05M15.7 14h.05" />
  </>),
  tree: (<>
    <path d="M12 3.4 6.8 11.4h2.8L5.4 17.8h13.2l-4.2-6.4h2.8z" />
    <path d="M12 17.8v3.4" />
  </>),
  school: (<>
    <path d="m12 4.2 9.8 4.4L12 13 2.2 8.6z" />
    <path d="M6.6 10.8v5c0 1.6 2.4 3 5.4 3s5.4-1.4 5.4-3v-5" />
    <path d="M21.8 8.6v5.4" />
  </>),
  health: (<>
    <circle cx="12" cy="12" r="8.4" />
    <path d="M12 8.4v7.2M8.4 12h7.2" />
  </>),
  pill: (<>
    <rect x="3.2" y="8.6" width="17.6" height="6.8" rx="3.4" transform="rotate(-33 12 12)" />
    <path d="M12 8.6v6.8" transform="rotate(-33 12 12)" />
  </>),
  people: (<>
    <circle cx="9" cy="8" r="3.2" />
    <path d="M3.6 20a5.4 5.4 0 0 1 10.8 0" />
    <path d="M15.4 5.4a3.2 3.2 0 0 1 0 5.9M17 14.8a5.4 5.4 0 0 1 3.4 5.2" />
  </>),
};

export type IconName = keyof typeof P;

export function Ico({ name, size = 18, className = "", stroke = 1.7 }:
  { name: IconName | string; size?: number; className?: string; stroke?: number }) {
  const paths = P[name as IconName];
  if (!paths) return null;
  return (
    <svg
      className={`ico ${className}`}
      width={size} height={size} viewBox="0 0 24 24"
      fill="none" stroke="currentColor" strokeWidth={stroke}
      strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"
    >
      {paths}
    </svg>
  );
}

/** Version « chaîne HTML » pour les popups MapLibre (hors React). */
export function icoHTML(name: IconName, size = 30): string {
  const d: Record<string, string> = {
    home: '<path d="M3.5 10.6 12 3.4l8.5 7.2"/><path d="M5.6 9.4V20h12.8V9.4"/><path d="M10 20v-5.6h4V20"/>',
  };
  return `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">${d[name] ?? d.home}</svg>`;
}
