import React, { useState, useEffect } from 'react'; import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'; const API_BASE = import.meta.env.VITE_API_URL || 'http://localhost:8000'; const STORES = [ { id: 'store_001', name: 'Patia Dark Store' }, { id: 'store_002', name: 'Infocity Hub' }, { id: 'store_003', name: 'Saheed Nagar Node' }, ]; export default function DarkStoreIntel() { const [forecast, setForecast] = useState(null); const [storeHealth, setStoreHealth] = useState(null); const [selectedStore, setSelectedStore] = useState('store_001'); const [loading, setLoading] = useState(true); const fetchData = async (storeId) => { setLoading(true); try { const [fcRes, healthRes] = await Promise.all([ fetch(`${API_BASE}/api/ml/demand-forecast?store_id=${storeId}`), fetch(`${API_BASE}/api/ml/store-health`), ]); setForecast(await fcRes.json()); setStoreHealth(await healthRes.json()); } catch { // Backend not running — show placeholder } setLoading(false); }; useEffect(() => { fetchData(selectedStore); }, [selectedStore]); const currentStore = storeHealth?.stores?.find(s => s.id === selectedStore); const chartData = forecast?.forecast?.map(f => ({ name: f.label, demand: f.predicted_units, lower: f.lower_ci, upper: f.upper_ci, isPeak: f.is_peak, })) || []; return (