import { useState } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { useGrowthTrends } from '@/hooks/useGrowthTrends'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; import { ChartContainer, ChartTooltip, ChartTooltipContent } from '@/components/ui/chart'; import type { GranularityType } from '@/types/database-analytics'; import { format } from 'date-fns'; const chartConfig = { parks_added: { label: "Parks", color: "hsl(var(--chart-1))", }, rides_added: { label: "Rides", color: "hsl(var(--chart-2))", }, companies_added: { label: "Companies", color: "hsl(var(--chart-3))", }, ride_models_added: { label: "Models", color: "hsl(var(--chart-4))", }, photos_added: { label: "Photos", color: "hsl(var(--chart-5))", }, } as const; export function GrowthTrendsChart() { const [timeRange, setTimeRange] = useState(90); const [granularity, setGranularity] = useState('daily'); const [activeLines, setActiveLines] = useState({ parks_added: true, rides_added: true, companies_added: true, ride_models_added: true, photos_added: true, }); const { data, isLoading } = useGrowthTrends(timeRange, granularity); const toggleLine = (key: keyof typeof activeLines) => { setActiveLines(prev => ({ ...prev, [key]: !prev[key] })); }; if (isLoading) { return ( Growth Trends Loading growth data...
); } const formattedData = data?.map(point => ({ ...point, date: format(new Date(point.period), granularity === 'daily' ? 'MMM dd' : granularity === 'weekly' ? 'MMM dd' : 'MMM yyyy'), })) || []; return (
Growth Trends Entity additions over time
{/* Time Range Controls */}
{[ { label: '7D', days: 7 }, { label: '30D', days: 30 }, { label: '90D', days: 90 }, { label: '1Y', days: 365 }, ].map(({ label, days }) => ( ))}
{/* Granularity Controls */}
{(['daily', 'weekly', 'monthly'] as GranularityType[]).map((g) => ( ))}
{/* Entity Type Toggles */}
{Object.entries(chartConfig).map(([key, config]) => ( ))}
{/* Chart */} } /> {activeLines.parks_added && ( )} {activeLines.rides_added && ( )} {activeLines.companies_added && ( )} {activeLines.ride_models_added && ( )} {activeLines.photos_added && ( )}
); }