import { useState, useRef, useEffect } from "react";
// ═══ MOCK DATA ═══
const mockTransactions = [
{ id: "1", date: "2026-02-23T10:30:00Z", sender: "Jean Dupont", amount: 250.00, branch: "ICC Montréal", status: "deposited" },
{ id: "2", date: "2026-02-22T14:15:00Z", sender: "Marie Tremblay", amount: 150.00, branch: "ICC Québec", status: "deposited" },
{ id: "3", date: "2026-02-22T09:00:00Z", sender: "Pierre Gagnon", amount: 500.00, branch: "ICC Gatineau", status: "pending" },
{ id: "4", date: "2026-02-21T16:45:00Z", sender: "Sophie Lavoie", amount: 75.00, branch: "ICC Sherbrooke", status: "deposited" },
{ id: "5", date: "2026-02-21T11:20:00Z", sender: "Marc Bélanger", amount: 320.00, branch: "ICC Ottawa", status: "deposited" },
{ id: "6", date: "2026-02-20T08:00:00Z", sender: "Anne Roy", amount: 180.00, branch: "ICC Toronto", status: "expired" },
{ id: "7", date: "2026-02-19T13:30:00Z", sender: "Luc Martin", amount: 425.00, branch: "ICC Montréal", status: "deposited" },
];
const mockStats = {
totalTransactions: 847,
totalAmount: 156234.50,
byBranch: [
{ branch: "ICC Montréal", count: 234, total: 45230.00 },
{ branch: "ICC Québec", count: 156, total: 32100.00 },
{ branch: "ICC Gatineau", count: 98, total: 21450.00 },
{ branch: "ICC Ottawa", count: 87, total: 18900.00 },
{ branch: "ICC Toronto", count: 72, total: 15340.00 },
],
};
// ═══ SIMULATED AI RESPONSES ═══
function simulateResponse(text) {
const lower = text.toLowerCase();
if (lower.includes("scann") || lower.includes("scan")) {
return {
type: "scan_started",
message: "🔍 Scan lancé pour la période du 25 janvier 2024 au 23 février 2026. Les résultats apparaîtront en temps réel dans le tableau.",
data: { preset: "custom" },
};
}
if (lower.includes("transaction") || lower.includes("virement") || lower.includes("montre")) {
return {
type: "transactions",
message: "📊 847 transactions au total. Voici les 7 plus récentes:",
data: { transactions: mockTransactions },
};
}
if (lower.includes("stat") || lower.includes("combien") || lower.includes("total")) {
return {
type: "stats",
message: "📈 **Résumé des virements**\n\n💰 **Total:** 847 virements — 156 234,50 $ CAD\n\n🏢 **Top succursales:** Montréal en tête avec 234 virements.",
data: mockStats,
};
}
if (lower.includes("cherch") || lower.includes("search") || lower.includes("trouve")) {
const filtered = mockTransactions.filter((t) =>
t.sender.toLowerCase().includes("dupont") || t.sender.toLowerCase().includes("martin")
);
return {
type: "search_results",
message: `🔍 ${filtered.length} résultat(s) trouvé(s):`,
data: { transactions: filtered.length > 0 ? filtered : mockTransactions.slice(0, 3) },
};
}
return {
type: "message",
message: "Je peux t'aider avec:\n• **Scanner** des courriels Interac\n• **Afficher** les transactions\n• **Statistiques** des virements\n• **Chercher** par nom ou succursale",
};
}
// ═══ STATUS BADGE ═══
function StatusBadge({ status }) {
const colors = {
deposited: "bg-emerald-100 text-emerald-700",
pending: "bg-amber-100 text-amber-700",
expired: "bg-slate-100 text-slate-500",
cancelled: "bg-red-100 text-red-600",
};
return (
{status || "—"}
);
}
// ═══ TRANSACTION TABLE ═══
function TransactionTable({ transactions }) {
if (!transactions?.length) return null;
return (
| Date |
Expéditeur |
Montant |
Succursale |
Statut |
{transactions.map((tx, i) => (
|
{new Date(tx.date).toLocaleDateString("fr-CA", { day: "2-digit", month: "short" })}
|
{tx.sender} |
{Number(tx.amount).toFixed(2)} $
|
{tx.branch} |
|
))}
);
}
// ═══ STATS CARD ═══
function StatsCard({ stats }) {
if (!stats) return null;
return (
{stats.totalTransactions}
Virements
{Number(stats.totalAmount).toLocaleString("fr-CA", { minimumFractionDigits: 2 })} $
Total
{stats.byBranch?.length > 0 && (
Top succursales
{stats.byBranch.slice(0, 5).map((b, i) => {
const pct = (b.total / stats.totalAmount) * 100;
return (
{b.branch}
{b.count} · {Number(b.total).toLocaleString("fr-CA")} $
);
})}
)}
);
}
// ═══ FORMATTED TEXT ═══
function FormattedText({ text }) {
return (
<>
{text.split("\n").map((line, i) => {
const formatted = line.replace(/\*\*(.*?)\*\*/g, '$1');
return (
{i > 0 &&
}
);
})}
>
);
}
// ═══ MESSAGE BUBBLE ═══
function MessageBubble({ message }) {
const isUser = message.role === "user";
return (
{!isUser && (
)}
{message.data && (message.type === "transactions" || message.type === "search_results") && (
)}
{message.data && message.type === "stats" &&
}
{message.timestamp.toLocaleTimeString("fr-CA", { hour: "2-digit", minute: "2-digit" })}
);
}
// ═══ MAIN APP ═══
export default function ICCChatDemo() {
const [isOpen, setIsOpen] = useState(true);
const [input, setInput] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [messages, setMessages] = useState([
{
id: "welcome",
role: "assistant",
content:
"Bonjour! 👋 Je suis ton assistant ICC. Tu peux me demander:\n\n• **Scanner** — \"Scanne les courriels du 25 janvier 2024 à aujourd'hui\"\n• **Voir les transactions** — \"Montre-moi les virements\"\n• **Statistiques** — \"Combien de virements au total?\"\n• **Chercher** — \"Cherche les virements de Jean Dupont\"",
type: "message",
timestamp: new Date(),
},
]);
const endRef = useRef(null);
useEffect(() => {
endRef.current?.scrollIntoView({ behavior: "smooth" });
}, [messages]);
const send = async () => {
if (!input.trim() || isLoading) return;
const text = input.trim();
setInput("");
setMessages((prev) => [
...prev,
{ id: `u-${Date.now()}`, role: "user", content: text, timestamp: new Date() },
]);
setIsLoading(true);
// Simulate AI processing delay
await new Promise((r) => setTimeout(r, 800 + Math.random() * 700));
const response = simulateResponse(text);
setMessages((prev) => [
...prev,
{ id: `a-${Date.now()}`, role: "assistant", ...response, timestamp: new Date() },
]);
setIsLoading(false);
};
const quickActions = [
{ label: "Scanner aujourd'hui", cmd: "Scanne les courriels d'aujourd'hui" },
{ label: "Transactions", cmd: "Montre les transactions récentes" },
{ label: "Statistiques", cmd: "Statistiques" },
{ label: "Chercher", cmd: "Cherche Jean Dupont" },
];
return (
{/* Background pattern */}
{/* Demo label */}
💬 ICC Chat Assistant — Démo interactive
{/* Chat Panel */}
{/* Header */}
Assistant ICC
Gestion intelligente des virements Interac
{/* Messages */}
{messages.map((msg) => (
))}
{isLoading && (
)}
{/* Quick Actions */}
{quickActions.map((a) => (
))}
{/* Input */}
);
}