import { useState, type FC } from 'react'; import { Box, Button, Card, CardContent, CircularProgress, Alert, Stack, Typography, Chip, } from '@mui/material'; import WarningAmberIcon from '@mui/icons-material/WarningAmber'; import CheckCircleIcon from '@mui/icons-material/CheckCircle'; import { useInteractionStore, useMedicationStore } from '../../store/useStore'; import { SeverityChip } from '../common/SeverityChip'; export const InteractionsChecker: FC = () => { const { medications } = useMedicationStore(); const { interactions, isChecking, error, checkInteractions, clearError } = useInteractionStore(); const [selected, setSelected] = useState([]); const toggle = (name: string) => { setSelected((prev) => prev.includes(name) ? prev.filter((n) => n !== name) : [...prev, name], ); }; const runCheck = async () => { if (selected.length < 2) return; await checkInteractions(selected); }; const hasChecked = interactions.length > 0 || !isChecking; return ( Drug interactions Select two or more of your medications to check for known interactions. {error && ( {error} )} {medications.length === 0 ? ( Add medications first (Medications tab), then check them for interactions. ) : ( <> {medications.map((m) => { const on = selected.includes(m.name); return ( toggle(m.name)} /> ); })} {/* Results */} {hasChecked && !isChecking && selected.length >= 2 && ( <> {interactions.length === 0 ? ( } severity="success"> No known interactions found between the selected medications. ) : ( } severity="warning"> {interactions.length} interaction{interactions.length > 1 ? 's' : ''} found. {interactions.map((ix, i) => ( {ix.medications.join(' + ')} {ix.description} {ix.disclaimer && ( {ix.disclaimer} )} ))} )} )} )} ); }; export default InteractionsChecker;