import { useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { X, Hash, Percent, Leaf, TrendingUp } from "lucide-react"; interface ZoneSpecies { name: string; percentage: number; } interface ZoneData { zone: number; infestation: number; weedCount: number; dominantWeed: string; species: ZoneSpecies[]; heatmapCells: number[]; } const mockZones: ZoneData[] = [ { zone: 1, infestation: 12, weedCount: 34, dominantWeed: "Amaranthus", species: [{ name: "Amaranthus retroflexus", percentage: 52 }, { name: "Digitaria sanguinalis", percentage: 30 }, { name: "Portulaca oleracea", percentage: 18 }], heatmapCells: [5, 15, 8, 20, 10, 5, 12, 18, 6] }, { zone: 2, infestation: 28, weedCount: 89, dominantWeed: "Cyperus", species: [{ name: "Cyperus rotundus", percentage: 45 }, { name: "Echinochloa crus-galli", percentage: 35 }, { name: "Amaranthus retroflexus", percentage: 20 }], heatmapCells: [25, 30, 20, 35, 40, 28, 15, 22, 30] }, { zone: 3, infestation: 8, weedCount: 22, dominantWeed: "Digitaria", species: [{ name: "Digitaria sanguinalis", percentage: 60 }, { name: "Portulaca oleracea", percentage: 40 }], heatmapCells: [3, 8, 5, 10, 12, 6, 4, 9, 7] }, { zone: 4, infestation: 35, weedCount: 112, dominantWeed: "Amaranthus", species: [{ name: "Amaranthus retroflexus", percentage: 48 }, { name: "Cyperus rotundus", percentage: 30 }, { name: "Echinochloa crus-galli", percentage: 22 }], heatmapCells: [30, 40, 35, 45, 50, 38, 25, 30, 28] }, { zone: 5, infestation: 22, weedCount: 67, dominantWeed: "Echinochloa", species: [{ name: "Echinochloa crus-galli", percentage: 42 }, { name: "Amaranthus retroflexus", percentage: 33 }, { name: "Cyperus rotundus", percentage: 25 }], heatmapCells: [18, 22, 25, 20, 30, 22, 15, 18, 20] }, { zone: 6, infestation: 18, weedCount: 51, dominantWeed: "Cyperus", species: [{ name: "Cyperus rotundus", percentage: 50 }, { name: "Digitaria sanguinalis", percentage: 30 }, { name: "Portulaca oleracea", percentage: 20 }], heatmapCells: [12, 18, 20, 15, 25, 18, 10, 15, 22] }, { zone: 7, infestation: 42, weedCount: 138, dominantWeed: "Amaranthus", species: [{ name: "Amaranthus retroflexus", percentage: 55 }, { name: "Echinochloa crus-galli", percentage: 25 }, { name: "Cyperus rotundus", percentage: 20 }], heatmapCells: [40, 50, 45, 55, 60, 48, 35, 42, 38] }, { zone: 8, infestation: 15, weedCount: 43, dominantWeed: "Digitaria", species: [{ name: "Digitaria sanguinalis", percentage: 45 }, { name: "Portulaca oleracea", percentage: 35 }, { name: "Amaranthus retroflexus", percentage: 20 }], heatmapCells: [10, 15, 12, 18, 20, 15, 8, 12, 14] }, { zone: 9, infestation: 9, weedCount: 25, dominantWeed: "Echinochloa", species: [{ name: "Echinochloa crus-galli", percentage: 55 }, { name: "Digitaria sanguinalis", percentage: 45 }], heatmapCells: [4, 8, 6, 10, 14, 8, 5, 9, 7] }, ]; const ZONE_LABELS = [ "Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right", ]; const getColor = (rate: number) => { if (rate > 35) return "border-destructive"; if (rate > 20) return "border-warning"; return "border-success"; }; const getOverlayBg = (rate: number) => { if (rate > 35) return "rgba(220, 38, 38, 0.25)"; if (rate > 20) return "rgba(234, 179, 8, 0.22)"; return "rgba(34, 197, 94, 0.2)"; }; const getSeverityColor = (rate: number) => { if (rate > 35) return "text-destructive"; if (rate > 20) return "text-warning"; return "text-success"; }; const getHeatColor = (intensity: number) => { if (intensity > 40) return "bg-destructive/70"; if (intensity > 25) return "bg-warning/60"; if (intensity > 10) return "bg-accent/40"; return "bg-success/30"; }; const FieldOverlay = () => { const mostInfested = mockZones.reduce((max, z) => z.infestation > max.infestation ? z : max, mockZones[0]); const [selectedZone, setSelectedZone] = useState(mostInfested); return (

Field Reconstruction — Weed Distribution Map

Botanical Garden, Astana · 51.0906°N, 71.4185°E · Click any zone to drill down

{/* Satellite map with zone overlay */}
{/* 3x3 satellite tile background */}
{[ "0-0.png", "1-0.png", "2-0.png", "0-1.png", "1-1.png", "2-1.png", "0-2.png", "1-2.png", "2-2.png", ].map((tile, i) => ( ))}
{/* Zone overlay grid */}
{mockZones.map((z, i) => { return ( setSelectedZone(selectedZone?.zone === z.zone ? null : z)} className={`relative flex flex-col items-center justify-center border cursor-pointer transition-all overflow-hidden ${getColor(z.infestation)} ${ selectedZone?.zone === z.zone ? "ring-2 ring-primary ring-inset z-10" : "hover:brightness-110" }`} style={{ backgroundColor: getOverlayBg(z.infestation) }} > {/* Mini heatmap background */}
{z.heatmapCells.map((cell, ci) => (
))}
Z{z.zone} {z.infestation}% {z.weedCount} weeds ); })}
{/* Detail panel */} {selectedZone ? (

Zone {selectedZone.zone}

{ZONE_LABELS[selectedZone.zone - 1]}

{selectedZone.weedCount}

total weeds

{selectedZone.infestation}%

infested

Density Distribution

{selectedZone.heatmapCells.map((cell, i) => (
{cell}%
))}

Species Breakdown

{selectedZone.species.map((s) => (
{s.name} {s.percentage}%
))}
) : (

Click a zone on the map to view its detailed analysis

)}
{/* Legend */}
Low (<20%)
Medium (20-35%)
High (>35%)
); }; export default FieldOverlay;