import { useCallback, useState } from 'react'; import type { EventProperties } from '@/api/types'; import { metaKey } from '@/lib/platform'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { KeyHint } from '@/components/key-hint'; import { toDatetimeLocalValue } from '@/features/particles/event-particle-view'; interface EventComposeStepProps { onCancel: () => void; onSubmit: (properties: EventProperties) => void; } function nextFullHour(): Date { const date = new Date(); date.setMinutes(0, 0, 0); date.setHours(date.getHours() + 1); return date; } const dateInputClass = 'w-full rounded-md border border-white/10 bg-white/5 px-3 py-1.5 text-sm text-white outline-none [color-scheme:dark] focus:border-white/30'; export function EventComposeStep({ onCancel, onSubmit, }: EventComposeStepProps) { const [title, setTitle] = useState(''); const [startAt, setStartAt] = useState(() => toDatetimeLocalValue(nextFullHour()), ); const [endAt, setEndAt] = useState(''); const [notes, setNotes] = useState(''); const handleSubmit = useCallback(() => { const trimmed = title.trim(); if (!trimmed || !startAt) return; onSubmit({ title: trimmed, start_at: new Date(startAt), ...(endAt && { end_at: new Date(endAt) }), ...(notes.trim() && { notes: notes.trim() }), }); }, [title, startAt, endAt, notes, onSubmit]); const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault(); onCancel(); } else if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) { e.preventDefault(); handleSubmit(); } }, [onCancel, handleSubmit], ); return (