// -----------------------------------------------------------------------------
// Auto-Ka — Agrégateur de voitures usagées à vendre (province de Québec)
// Auteur : Simon-Pierre Boucher — contact@spboucher.ai
// fiche/Closing.tsx : « En bref », CTA sticky mobile, aside desktop et
// « Demander à Ka » (widget KA Agent partagé) de la fiche véhicule.
// -----------------------------------------------------------------------------
import { useEffect, useState } from "react";
import { VehicleDetail, fmtPrice } from "../api";
import { Ico, IcoHeart } from "../components/Icons";
import BottomSheet from "./BottomSheet";
import { ScoreRing, kaLabel } from "./ScoreCard";
import { ComparaisonPrix, Constat } from "./synthese";
import { PriceCapsule } from "./VehicleHero";
import { SectionCard, SkeletonLines, relTime } from "./ui";
export function BriefList({ items, compact = false }: { items: Constat[]; compact?: boolean }) {
const glyph = (t: Constat["tone"]) => (t === "good" ? "✓" : t === "bad" ? "✕" : t === "warn" ? "!" : "○");
return (
{items.map((c) => (
-
{glyph(c.tone)}
{c.titre}
{!compact && c.detail &&
{c.detail}
}
))}
);
}
export function Summary({ items, loading }: { items: Constat[]; loading: boolean }) {
return (
{items.length > 0 ? : loading ? : Pas encore de synthèse pour ce véhicule.
}
);
}
export function usePastElement(watch: React.RefObject): boolean {
const [past, setPast] = useState(false);
useEffect(() => {
const check = () => { const el = watch.current; if (el) setPast(el.getBoundingClientRect().bottom < 0); };
check();
window.addEventListener("scroll", check, { passive: true });
window.addEventListener("resize", check);
return () => { window.removeEventListener("scroll", check); window.removeEventListener("resize", check); };
}, [watch]);
return past;
}
export function StickyCTA({ v, cmp, show }: { v: VehicleDetail; cmp: ComparaisonPrix | null; show: boolean }) {
return (
);
}
export function DesktopAside({ v, cmp, brief, fav, onFav, onShare }: {
v: VehicleDetail; cmp: ComparaisonPrix | null; brief: Constat[]; fav: boolean; onFav: () => void; onShare: () => void;
}) {
const maj = relTime(v.updated_at);
const s = v.ka_score;
return (
);
}
const SUGGESTIONS = ["Est-ce un bon prix ?", "Compare-le aux véhicules similaires", "Quels sont les points de vigilance ?", "Quel budget mensuel prévoir ?", "Y a-t-il des rappels connus ?"];
function envoyerAKa(question: string): boolean {
const btn = document.querySelector(".kaa-btn");
const ta = document.querySelector(".kaa-panel textarea");
const send = document.querySelector(".kaa-in button");
if (!btn || !ta || !send) return false;
btn.click(); ta.value = question; setTimeout(() => send.click(), 60);
return true;
}
export function KaAssistant({ v, hidden }: { v: VehicleDetail; hidden?: boolean }) {
const [open, setOpen] = useState(false);
const [q, setQ] = useState("");
const [err, setErr] = useState(false);
useEffect(() => { const on = () => setOpen(true); window.addEventListener("ak:askka", on); return () => window.removeEventListener("ak:askka", on); }, []);
const contexte = () => `(Véhicule consulté sur Auto-Ka : ${v.title}${v.mileage_km != null ? ` — ${Math.round(v.mileage_km).toLocaleString("fr-CA")} km` : ""}${v.price != null ? ` — ${fmtPrice(v.price)}` : ""} — ${v.dealer_name || v.source}${v.city ? `, ${v.city}` : ""} — https://www.auto-ka.com/vehicule/${encodeURIComponent(v.uid)})`;
const poser = (question: string) => { const ok = envoyerAKa(`${question}\n\n${contexte()}`); if (ok) { setOpen(false); setQ(""); setErr(false); } else setErr(true); };
return (
<>
setOpen(false)} title="Demander à Ka" sub="Assistant Groupe KA · connaît cette fiche"
footer={}>
Je peux situer ce prix dans le marché, expliquer le KA Score, résumer les rappels et chercher des alternatives chez d'autres concessionnaires.
{v.images?.[0] &&

}
{v.title}{[v.dealer_name || v.source, v.price != null ? fmtPrice(v.price) : null, v.mileage_km != null ? `${Math.round(v.mileage_km).toLocaleString("fr-CA")} km` : null].filter(Boolean).join(" · ")}
{SUGGESTIONS.map((s) => )}
{err && L'assistant n'est pas encore chargé — réessayez dans un instant.
}
>
);
}