import React, { useState } from 'react'; const FanInterestCalc = () => { const [marketSize, setMarketSize] = useState(10); const [currentFanInterest, setCurrentFanInterest] = useState(50); const [fanLoyalty, setFanLoyalty] = useState(5); const [winPercentages, setWinPercentages] = useState(['.500', '.500', '.500', '.500', '.500']); const [playoffAppearances, setPlayoffAppearances] = useState(0); const [divisionTitles, setDivisionTitles] = useState(0); const [pennants, setPennants] = useState(0); const [championships, setChampionships] = useState(0); const [expansionBoost, setExpansionBoost] = useState(false); const [newFanInterest, setNewFanInterest] = useState(currentFanInterest); const [newFanLoyalty, setNewFanLoyalty] = useState(fanLoyalty); const calculateFanInterest = () => { let interest = parseInt(currentFanInterest); let loyalty = parseInt(fanLoyalty); // Convert win % to actual decimals for calculation let winRates = winPercentages.map(wp => parseFloat(wp)); let avgWinRate = winRates.reduce((a, b) => a + b, 0) / winRates.length; let recentTrend = winRates[4] - winRates[0]; // Change from 5 years ago // **Base Win % Impact** if (avgWinRate >= .600) interest += 5; else if (avgWinRate >= .500) interest += 2; else if (avgWinRate < .400) interest -= 5; else if (avgWinRate < .300) interest -= 10; // **Trend Impact** if (recentTrend > .050) interest += 3; else if (recentTrend < -.050) interest -= 3; // **Postseason Performance Impact** interest += playoffAppearances * 2; interest += divisionTitles * 4; interest += pennants * 6; interest += championships * 10; // **Expansion/Relocation Boost** if (expansionBoost) interest += 15; // **Market Size Modifier** (Larger markets are more stable) let marketFactor = (marketSize - 10) * 0.5; // Scale around 10 interest += marketFactor; // **Randomization Factor** (Slight variability) let variance = Math.floor(Math.random() * 5) - 2; // -2 to +2 interest += variance; // **Clamp Fan Interest between 1-100** interest = Math.max(1, Math.min(100, interest)); // **Fan Loyalty Calculation** (More winning = higher loyalty, sustained losing drops it) if (avgWinRate >= .550) loyalty += 1; if (avgWinRate < .450) loyalty -= 1; if (championships > 0) loyalty += 2; if (expansionBoost) loyalty += 1; loyalty = Math.max(0, Math.min(10, loyalty)); setNewFanInterest(interest); setNewFanLoyalty(loyalty); }; return (