/** * Plant Analytics Page * Detailed analytics for plant registrations and lineage */ import { useState, useEffect } from 'react'; import Link from 'next/link'; import { KPICard, DateRangePicker, LineChart, BarChart, PieChart, DataTable, TrendIndicator, } from '../../components/analytics'; import { TimeRange, PlantAnalytics } from '../../lib/analytics/types'; export default function PlantAnalyticsPage() { const [timeRange, setTimeRange] = useState('30d'); const [loading, setLoading] = useState(true); const [data, setData] = useState(null); useEffect(() => { fetchData(); }, [timeRange]); const fetchData = async () => { setLoading(true); try { const response = await fetch(`/api/analytics/plants?timeRange=${timeRange}`); const result = await response.json(); setData(result.data); } catch (error) { console.error('Failed to fetch plant analytics:', error); } finally { setLoading(false); } }; const speciesColumns = [ { key: 'species', header: 'Species' }, { key: 'count', header: 'Count', align: 'right' as const }, { key: 'percentage', header: '% Share', align: 'right' as const, render: (v: number) => `${v.toFixed(1)}%` }, { key: 'trend', header: 'Trend', render: (v: string) => }, ]; const growerColumns = [ { key: 'name', header: 'Grower' }, { key: 'totalPlants', header: 'Plants', align: 'right' as const }, { key: 'totalSpecies', header: 'Species', align: 'right' as const }, { key: 'averageGeneration', header: 'Avg Gen', align: 'right' as const, render: (v: number) => v.toFixed(1) }, ]; return (
{/* Header */}

Plant Analytics

Detailed insights into plant registrations and lineage

{/* Time Range Selector */}
{/* Navigation Tabs */} {/* KPI Cards */}
{/* Charts */}
{data?.registrationsTrend && ( )} {data?.plantsBySpecies && ( )}
{/* Generation Distribution */} {data?.plantsByGeneration && (
)} {/* Tables */}
{data?.plantsBySpecies && ( )} {data?.topGrowers && ( )}
); }