import React from 'react'; import { useSleepSession } from '../../hooks/useSleepSession'; interface SleepButtonProps { time: string; } const SleepButton: React.FC = ({ time }) => { const { activeSession, createSession, endSession, isCreating, isEnding } = useSleepSession(); const isSleeping = !!activeSession; const handleClick = async () => { if (!time) { alert('Please select a valid time.'); return; } try { if (isSleeping && activeSession?.id) { await endSession({ sessionId: activeSession.id, endTime: time }); } else { await createSession({ start_time: time }); } } catch (error: unknown) { console.error('Failed to update sleep session:', error instanceof Error ? error.message : error); } }; return ( ); }; export default SleepButton;