"use client"; import { useEffect, useState } from "react"; import { useParams, useRouter } from "next/navigation"; import { useAuth } from "@/components/AuthProvider"; import { c2api } from "@/lib/c2api"; import type { TripRecord, TripEvent } from "@/lib/types"; // --------------------------------------------------------------------------- // Formatting helpers // --------------------------------------------------------------------------- function fmtDate(iso: string) { return new Date(`${iso}T12:00:00`).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", }); } function fmtDayLabel(iso: string) { return new Date(`${iso}T12:00:00`).toLocaleDateString("en-US", { weekday: "long", month: "short", day: "numeric", }); } function fmtTime(t: string | null) { if (!t) return null; const [h, m] = t.split(":").map(Number); const d = new Date(); d.setHours(h, m, 0, 0); return d.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" }); } function dateRange(start: string, end: string): string[] { const dates: string[] = []; const cur = new Date(`${start}T12:00:00`); const endDate = new Date(`${end}T12:00:00`); while (cur <= endDate) { dates.push(cur.toISOString().slice(0, 10)); cur.setDate(cur.getDate() + 1); } return dates; } // --------------------------------------------------------------------------- // Add Event modal // --------------------------------------------------------------------------- function AddEventModal({ trip, onClose, onAdd }: { trip: TripRecord; onClose: () => void; onAdd: (body: object) => Promise; }) { const [title, setTitle] = useState(""); const [date, setDate] = useState(trip.start_date); const [time, setTime] = useState(""); const [location, setLocation] = useState(""); const [mapsLink, setMapsLink] = useState(""); const [notes, setNotes] = useState(""); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setSaving(true); setError(null); try { await onAdd({ title, date, time: time || null, location: location || null, maps_link: mapsLink || null, notes: notes || null, }); onClose(); } catch { setError("Failed to add event. Make sure the date is within the trip range."); } finally { setSaving(false); } } return (

Add Event

setTitle(e.target.value)} placeholder="Dinner on Broadway" className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500" />
setDate(e.target.value)} className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500" />
setTime(e.target.value)} className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500" />
setLocation(e.target.value)} placeholder={trip.location} className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500" />
setMapsLink(e.target.value)} placeholder="https://maps.google.com/…" className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500" />