import React from 'react'; import {Plant, Task, MaintenanceRecord, HarvestRecord, PlantTitles, Maintenances} from '../types'; import { Calendar, AlertTriangle, CheckCircle, Sprout, Scissors, Droplets } from 'lucide-react'; interface DashboardProps { plants: Plant[]; tasks: Task[]; maintenanceRecords: MaintenanceRecord[]; harvestRecords: HarvestRecord[]; onNavigate: (tab: string) => void; } const Dashboard: React.FC = ({ plants, tasks, maintenanceRecords, harvestRecords, onNavigate }) => { const upcomingTasks = tasks .filter(task => !task.completed && new Date(task.deadline) >= new Date()) .sort((a, b) => new Date(a.deadline).getTime() - new Date(b.deadline).getTime()) .slice(0, 5); const plantsNeedingAttention = plants.filter(plant => plant.healthStatus === 'needs-attention'); const recentMaintenanceRecords = maintenanceRecords .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) .slice(0, 5); const stats = [ { label: 'Всего растений', value: plants.length, icon: Sprout, color: 'text-green-600', bgColor: 'bg-green-100' }, { label: 'Отложенные работы', value: tasks.filter(task => !task.completed).length, icon: Calendar, color: 'text-blue-600', bgColor: 'bg-blue-100' }, { label: 'Требует внимания', value: plantsNeedingAttention.length, icon: AlertTriangle, color: 'text-yellow-600', bgColor: 'bg-yellow-100' }, { label: ' Урожай этого года', value: harvestRecords.filter(record => new Date(record.date).getFullYear() === new Date().getFullYear() ).length, icon: CheckCircle, color: 'text-purple-600', bgColor: 'bg-purple-100' } ]; const getMaintenanceIcon = (type: string) => { switch (type) { case 'pruning': return Scissors; case 'watering': return Droplets; default: return Calendar; } }; return (

Сводка по саду

Добро пожаловать в мой центр управления садом

{/* Stats Grid */}
{stats.map((stat, index) => { const Icon = stat.icon; return (

{stat.label}

{stat.value}

); })}
{/* Upcoming Tasks */}

Предстоящие работы

{upcomingTasks.length > 0 ? (
{upcomingTasks.map((task) => { const plant = plants.find(p => p.id === task.plantId); const isOverdue = new Date(task.deadline) < new Date(); return (

{task.title}

{plant && (

{plant.variety}

)}

Срок: {new Date(task.deadline).toLocaleDateString()}

); })}
) : (

Предстоящих работ нет

)}
{/* Plants Needing Attention */}

Растения, требующие внимания

{plantsNeedingAttention.length > 0 ? (
{plantsNeedingAttention.map((plant) => (

{plant.variety}

{PlantTitles[plant.type]}

{plant.notes && (

{plant.notes}

)}
))}
) : (

All plants are healthy!

)}
{/* Recent Maintenance */}

Недавние работы

{recentMaintenanceRecords.length > 0 ? (
{recentMaintenanceRecords.map((record) => { const plant = plants.find(p => p.id === record.plantId); const Icon = getMaintenanceIcon(record.type); return (

{Maintenances[record.type]}

{plant?.variety}

{record.description}

{new Date(record.date).toLocaleDateString()}

); })}
) : (

Записей о выполненных работах пока нет

)}
); }; export default Dashboard;