import React, { useState } from 'react'; type HighlightMode = 'none' | 'bus' | 'club' | 'cond_club_bus' | 'cond_bus_club' | 'or_bus_club'; const ProbabilityTableWidget: React.FC = () => { const [highlight, setHighlight] = useState('none'); const data = { bus_club: 36, bus_noClub: 24, noBus_club: 30, noBus_noClub: 30 }; const totals = { bus: data.bus_club + data.bus_noClub, // 60 noBus: data.noBus_club + data.noBus_noClub, // 60 club: data.bus_club + data.noBus_club, // 66 noClub: data.bus_noClub + data.noBus_noClub, // 54 total: 120 }; const getCellClass = (cell: string) => { const base = "p-4 text-center border font-mono font-bold transition-colors duration-300 "; // Logic for highlighting based on mode let isNum = false; let isDenom = false; if (highlight === 'bus') { if (cell === 'bus_total') isNum = true; if (cell === 'grand_total') isDenom = true; } else if (highlight === 'club') { if (cell === 'club_total') isNum = true; if (cell === 'grand_total') isDenom = true; } else if (highlight === 'cond_club_bus') { if (cell === 'bus_club') isNum = true; if (cell === 'bus_total') isDenom = true; } else if (highlight === 'cond_bus_club') { if (cell === 'bus_club') isNum = true; if (cell === 'club_total') isDenom = true; } else if (highlight === 'or_bus_club') { if (['bus_club', 'bus_noClub', 'noBus_club'].includes(cell)) isNum = true; if (cell === 'grand_total') isDenom = true; } if (isNum) return base + "bg-emerald-100 text-emerald-800 border-emerald-300"; if (isDenom) return base + "bg-indigo-100 text-indigo-800 border-indigo-300"; return base + "bg-white border-slate-200 text-slate-600"; }; const explanation = () => { switch(highlight) { case 'bus': return { title: "P(Bus)", math: `${totals.bus} / ${totals.total} = 0.50` }; case 'club': return { title: "P(Club)", math: `${totals.club} / ${totals.total} = 0.55` }; case 'cond_club_bus': return { title: "P(Club | Bus)", math: `${data.bus_club} / ${totals.bus} = 0.60`, sub: "Given Bus, restrict to Bus row." }; case 'cond_bus_club': return { title: "P(Bus | Club)", math: `${data.bus_club} / ${totals.club} ≈ 0.55`, sub: "Given Club, restrict to Club column." }; case 'or_bus_club': return { title: "P(Bus OR Club)", math: `(${totals.bus} + ${totals.club} - ${data.bus_club}) / ${totals.total} = ${totals.bus+totals.club-data.bus_club}/${totals.total} = 0.75`, sub: "Add totals, subtract overlap." }; default: return { title: "Select a Probability", math: "---" }; } }; const exp = explanation(); return (
Club
No Club
Total
Bus
{data.bus_club}
{data.bus_noClub}
{totals.bus}
No Bus
{data.noBus_club}
{data.noBus_noClub}
{totals.noBus}
Total
{totals.club}
{totals.noClub}
{totals.total}

{exp.title}

{exp.math}
{exp.sub &&

{exp.sub}

}
); }; export default ProbabilityTableWidget;