import { Calendar, Tag, ArrowRight, MapPin, Building2, Clock } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { Separator } from '@/components/ui/separator'; import { FlexibleDateDisplay } from '@/components/ui/flexible-date-display'; import type { TimelineSubmissionData } from '@/types/timeline'; import { useEffect, useState } from 'react'; import { supabase } from '@/lib/supabaseClient'; interface RichTimelineEventDisplayProps { data: TimelineSubmissionData; actionType: 'create' | 'edit' | 'delete'; } export function RichTimelineEventDisplay({ data, actionType }: RichTimelineEventDisplayProps) { const [entityName, setEntityName] = useState(null); const [parkContext, setParkContext] = useState(null); const [fromEntity, setFromEntity] = useState(null); const [toEntity, setToEntity] = useState(null); const [fromLocation, setFromLocation] = useState(null); const [toLocation, setToLocation] = useState(null); useEffect(() => { if (!data) return; const fetchRelatedData = async () => { // Fetch the main entity this timeline event is for if (data.entity_id && data.entity_type) { if (data.entity_type === 'park') { const { data: park } = await supabase .from('parks') .select('name') .eq('id', data.entity_id) .single(); setEntityName(park?.name || null); } else if (data.entity_type === 'ride') { const { data: ride } = await supabase .from('rides') .select('name, park:parks(name)') .eq('id', data.entity_id) .single(); setEntityName(ride?.name || null); setParkContext((ride?.park as any)?.name || null); } } // Fetch from/to entities for relational changes if (data.from_entity_id) { const { data: entity } = await supabase .from('companies') .select('name') .eq('id', data.from_entity_id) .single(); setFromEntity(entity?.name || null); } if (data.to_entity_id) { const { data: entity } = await supabase .from('companies') .select('name') .eq('id', data.to_entity_id) .single(); setToEntity(entity?.name || null); } // Fetch from/to locations for location changes if (data.from_location_id) { const { data: loc } = await supabase .from('locations') .select('*') .eq('id', data.from_location_id) .single(); setFromLocation(loc); } if (data.to_location_id) { const { data: loc } = await supabase .from('locations') .select('*') .eq('id', data.to_location_id) .single(); setToLocation(loc); } }; fetchRelatedData(); }, [data.entity_id, data.entity_type, data.from_entity_id, data.to_entity_id, data.from_location_id, data.to_location_id]); const formatEventType = (type: string) => { return type.replace(/_/g, ' ').replace(/\b\w/g, (l) => l.toUpperCase()); }; const getEventTypeColor = (type: string) => { switch (type) { case 'opening': return 'bg-green-600'; case 'closure': return 'bg-red-600'; case 'reopening': return 'bg-blue-600'; case 'renovation': return 'bg-purple-600'; case 'expansion': return 'bg-indigo-600'; case 'acquisition': return 'bg-amber-600'; case 'name_change': return 'bg-cyan-600'; case 'operator_change': case 'owner_change': return 'bg-orange-600'; case 'location_change': return 'bg-pink-600'; case 'status_change': return 'bg-yellow-600'; case 'milestone': return 'bg-emerald-600'; default: return 'bg-gray-600'; } }; const getPrecisionIcon = (precision: string) => { switch (precision) { case 'day': return '📅'; case 'month': return '📆'; case 'year': return '🗓️'; default: return '📅'; } }; const formatLocation = (loc: any) => { if (!loc) return null; const parts = [loc.city, loc.state_province, loc.country].filter(Boolean); return parts.join(', '); }; return (
{/* Header Section */}

{data.title}

{formatEventType(data.event_type)} {actionType === 'create' && ( New Event )} {actionType === 'edit' && ( Edit Event )} {actionType === 'delete' && ( Delete Event )}
{/* Entity Context Section */}
Event For: {entityName || 'Loading...'} {data.entity_type}
{parkContext && (
Park: {parkContext}
)}
{/* Event Date Section */}
Event Date:
{getPrecisionIcon(data.event_date_precision)}
Precision: {data.event_date_precision}
{/* Change Details Section */} {(data.from_value || data.to_value || fromEntity || toEntity) && ( <>
Change Details:
From
{fromEntity || data.from_value || '—'}
To
{toEntity || data.to_value || '—'}
)} {/* Location Change Section */} {(fromLocation || toLocation) && ( <>
Location Change:
From
{formatLocation(fromLocation) || '—'}
To
{formatLocation(toLocation) || '—'}
)} {/* Description Section */} {data.description && ( <>
Description:

{data.description}

)}
); }