// Vrai-Prix — groupes de types d'annonces Immo-Ka (module PUR : importable côté client). export type TypeGroupKey = | "maison" | "condo" | "plex" | "terrain" | "chalet" | "fermette" | "mobile" | "commercial" | "autre"; export const TYPE_GROUPS: { key: TypeGroupKey; fr: string; en: string }[] = [ { key: "maison", fr: "Maison", en: "House" }, { key: "condo", fr: "Condo", en: "Condo" }, { key: "plex", fr: "Plex", en: "Plex" }, { key: "terrain", fr: "Terrain", en: "Land" }, { key: "chalet", fr: "Chalet", en: "Cottage" }, { key: "fermette", fr: "Fermette / agricole", en: "Hobby farm" }, { key: "mobile", fr: "Maison mobile", en: "Mobile home" }, { key: "commercial", fr: "Commercial", en: "Commercial" }, { key: "autre", fr: "Autre", en: "Other" }, ]; const fold = (s: string | null | undefined) => (s ?? "") .normalize("NFD") .replace(/[\u0300-\u036f]/g, "") .toLowerCase() .trim(); /** Type Immo-Ka (libre, sale) → groupe stable. Même logique que typeBucket du pipeline. */ export function typeGroup(pt: string | null): TypeGroupKey { const t = fold(pt); if (!t) return "autre"; if (t.includes("condo")) return "condo"; if (/(du|tri|quadru|multi)plex/.test(t) || t.includes("plex")) return "plex"; if (t.includes("terrain") || t === "lot") return "terrain"; if (t.includes("commerc") || t.includes("industri") || t.includes("bureau") || t.includes("service")) return "commercial"; if (t.includes("chalet") || t.includes("recreativ")) return "chalet"; if (t.includes("ferme") || t.includes("agric")) return "fermette"; if (t.includes("mobile") || t.includes("roulotte")) return "mobile"; if ( t.includes("maison") || t.includes("jumel") || t.includes("detach") || t.includes("residen") || t === "propriete" || t.includes("bungalow") || t.includes("cottage") ) return "maison"; return "autre"; } /** groupe → type_prop du rôle (moteur) pour un sujet sans unité jumelée. */ export function groupToTypeProp(g: TypeGroupKey): string { switch (g) { case "condo": return "condo_ou_multi"; case "plex": return "plex"; case "terrain": return "terrain"; case "chalet": return "chalet"; case "mobile": return "maison_mobile"; case "commercial": return "autre"; default: return "unifamilial"; } } export function groupLabel(key: string, fr: boolean): string { const g = TYPE_GROUPS.find((x) => x.key === key); return g ? (fr ? g.fr : g.en) : key; }