import { useState, useEffect } from 'react'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { ParkCard } from '@/components/parks/ParkCard'; import { RideCard } from '@/components/rides/RideCard'; import { RecentChangeCard } from './RecentChangeCard'; import { Badge } from '@/components/ui/badge'; import { Park, Ride, ActivityEntry } from '@/types/database'; import { supabase } from '@/integrations/supabase/client'; export function ContentTabs() { const [trendingParks, setTrendingParks] = useState([]); const [trendingRides, setTrendingRides] = useState([]); const [recentParks, setRecentParks] = useState([]); const [recentRides, setRecentRides] = useState([]); const [recentChanges, setRecentChanges] = useState([]); const [recentlyOpened, setRecentlyOpened] = useState>([]); const [loading, setLoading] = useState(true); useEffect(() => { fetchContent(); }, []); const fetchContent = async () => { try { // Trending Parks (by 30-day view count) const { data: trending } = await supabase .from('parks') .select(`*, location:locations(*), operator:companies!parks_operator_id_fkey(*)`) .order('view_count_30d', { ascending: false }) .limit(12); // Recently Added Parks const { data: recent } = await supabase .from('parks') .select(`*, location:locations(*), operator:companies!parks_operator_id_fkey(*)`) .order('created_at', { ascending: false }) .limit(12); // Trending Rides (by 30-day view count) const { data: trendingRidesData } = await supabase .from('rides') .select(`*, park:parks!inner(name, slug, location:locations(*))`) .order('view_count_30d', { ascending: false }) .limit(12); // Recently Added Rides const { data: recentRidesData } = await supabase .from('rides') .select(`*, park:parks!inner(name, slug, location:locations(*))`) .order('created_at', { ascending: false }) .limit(12); // Recent changes will be populated from other sources since entity_versions requires auth const changesData: ActivityEntry[] = []; // Process changes to extract entity info from version_data const processedChanges: ActivityEntry[] = []; // Fetch recently opened parks and rides const oneYearAgo = new Date(); oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1); const dateThreshold = oneYearAgo.toISOString().split('T')[0]; const { data: openedParks } = await supabase .from('parks') .select(`*, location:locations(*), operator:companies!parks_operator_id_fkey(*)`) .not('opening_date', 'is', null) .gte('opening_date', dateThreshold) .order('opening_date', { ascending: false }) .limit(20); const { data: openedRides } = await supabase .from('rides') .select(`*, park:parks!inner(name, slug, location:locations(*))`) .not('opening_date', 'is', null) .gte('opening_date', dateThreshold) .order('opening_date', { ascending: false }) .limit(20); // Combine and sort by opening date const combinedOpened = [ ...(openedParks || []).map(p => ({ ...p, entityType: 'park' as const })), ...(openedRides || []).map(r => ({ ...r, entityType: 'ride' as const })) ] .sort((a, b) => new Date(b.opening_date).getTime() - new Date(a.opening_date).getTime()) .slice(0, 24); setTrendingParks(trending || []); setRecentParks(recent || []); setTrendingRides(trendingRidesData || []); setRecentRides(recentRidesData || []); setRecentChanges(processedChanges); setRecentlyOpened(combinedOpened); } catch (error) { console.error('Error fetching content:', error); } finally { setLoading(false); } }; if (loading) { return (
{[...Array(6)].map((_, i) => (
))}
); } return (
Trending Parks Trending Rides New Parks New Rides Recent Changes Recently Opened

Trending Parks

Most viewed parks in the last 30 days

{trendingParks.map((park) => ( ))}

Trending Rides

Most viewed rides in the last 30 days

{trendingRides.map((ride) => ( ))}

Recently Added Parks

Latest parks added to our database

{recentParks.map((park) => ( ))}

Recently Added Rides

Latest attractions added to our database

{recentRides.map((ride) => ( ))}

Recent Changes

Latest updates across all entities

No recent changes to display

Recently Opened

Parks and rides that opened in the last year

{recentlyOpened.map((entity: any) => ( entity.entityType === 'park' ? (
{new Date(entity.opening_date).getFullYear()}
) : (
{new Date(entity.opening_date).getFullYear()}
) ))}
); }