import { useState } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from './ui/card'; import { Button } from './ui/button'; import { Badge } from './ui/badge'; import { Tabs, TabsContent, TabsList, TabsTrigger } from './ui/tabs'; import { Slider } from './ui/slider'; import { TrendingUp, Brain, Target, Zap, DollarSign, Fish, Activity } from 'lucide-react'; import { LineChart, Line, BarChart, Bar, AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from 'recharts'; import { User, Farm } from '../types'; interface AnalyticsProps { user: User; selectedFarm: Farm | null; } export default function Analytics({ user, selectedFarm }: AnalyticsProps) { const [predictionDays, setPredictionDays] = useState([30]); const [feedRate, setFeedRate] = useState([3.5]); const [temperature, setTemperature] = useState([26]); // Growth Prediction Data const growthPrediction = [ { week: 'Week 1', actual: 120, predicted: 122 }, { week: 'Week 2', actual: 145, predicted: 147 }, { week: 'Week 3', actual: 175, predicted: 173 }, { week: 'Week 4', actual: 210, predicted: 208 }, { week: 'Week 5', actual: 245, predicted: 248 }, { week: 'Week 6', actual: 285, predicted: 287 }, { week: 'Week 7', predicted: 328 }, { week: 'Week 8', predicted: 372 }, ]; // Profitability Analysis const profitabilityData = [ { month: 'May', revenue: 38000, costs: 28500, profit: 9500 }, { month: 'Jun', revenue: 42000, costs: 30200, profit: 11800 }, { month: 'Jul', revenue: 45000, costs: 31800, profit: 13200 }, { month: 'Aug', revenue: 48000, costs: 33500, profit: 14500 }, { month: 'Sep', revenue: 51000, costs: 35100, profit: 15900 }, { month: 'Oct', revenue: 54000, costs: 36800, profit: 17200 }, ]; // FCR Trends const fcrTrends = [ { date: 'Sep 15', fcr: 1.42, target: 1.40 }, { date: 'Sep 22', fcr: 1.38, target: 1.40 }, { date: 'Sep 29', fcr: 1.35, target: 1.40 }, { date: 'Oct 06', fcr: 1.37, target: 1.40 }, { date: 'Oct 13', fcr: 1.35, target: 1.40 }, { date: 'Oct 20', fcr: 1.33, target: 1.40 }, ]; // KPIs const kpis = [ { label: 'Predicted Weight (30 days)', value: '420g', change: '+47%', trend: 'up' }, { label: 'Forecasted FCR', value: '1.32', change: '-5%', trend: 'down' }, { label: 'Survival Rate Prediction', value: '96.8%', change: '+1.2%', trend: 'up' }, { label: 'Expected ROI', value: '42%', change: '+8%', trend: 'up' }, ]; // Scenario simulation results const scenarioResults = { currentFeed: { finalWeight: 420, fcr: 1.32, cost: 3250, profit: 14800 }, optimized: { finalWeight: 445, fcr: 1.28, cost: 3180, profit: 16200 } }; return (

AI Analytics & Predictions

Data-driven insights for optimal performance

AI-Powered
{/* Key Performance Indicators */}
{kpis.map((kpi, index) => ( {kpi.label}
{kpi.value}

{kpi.change} vs target

))}
Growth Prediction Profitability Scenario Simulation Performance Metrics {/* Growth Prediction */} AI Growth Forecast Model

Predictions based on historical data, water quality, and feeding patterns

Model Insights

Optimal Growth Trajectory

Current growth rate is 3% above predicted baseline. Fish are responding well to current feeding regime.

Harvest Window

Recommended harvest at 112 days (Week 16) when fish reach optimal market size of 650-700g.

Growth Acceleration Opportunity

Increasing feed protein content by 2% could improve SGR by 0.3% with minimal cost increase.

Prediction Confidence
Model Accuracy 94.2%
Data Quality 91%
Historical Match 88.5%

Predictions are updated every 6 hours based on real-time sensor data and growth sampling.

{/* Profitability Dashboard */}
Revenue vs Cost Trends Profit Margin Analysis
Projected Annual Revenue
$648,000

+18% vs last year

Average Profit Margin
31.8%

Above industry average (28%)

Break-even Point
Day 98

14 days ahead of schedule

{/* Scenario Simulation */} What-If Scenario Planning

Simulate different conditions to optimize your operations

Current Settings

Predicted Final Weight {scenarioResults.currentFeed.finalWeight}g
Expected FCR {scenarioResults.currentFeed.fcr}
Total Feed Cost ${scenarioResults.currentFeed.cost}
Projected Profit ${scenarioResults.currentFeed.profit}

Optimized Scenario

Predicted Final Weight {scenarioResults.optimized.finalWeight}g (+{scenarioResults.optimized.finalWeight - scenarioResults.currentFeed.finalWeight}g)
Expected FCR {scenarioResults.optimized.fcr} (-0.04)
Total Feed Cost ${scenarioResults.optimized.cost} (-$70)
Projected Profit ${scenarioResults.optimized.profit} (+${scenarioResults.optimized.profit - scenarioResults.currentFeed.profit})
{/* Performance Metrics */} Feed Conversion Ratio Trends
Performance Score
8.7/10
{[...Array(9)].map((_, i) => (
))}

Excellent performance

Efficiency Rating
92%

Top 10% of farms

Sustainability Index
A+

Low environmental impact

); }