import { useState } from 'react' import { PieChart, Pie, Cell, Legend, Tooltip, BarChart, Bar, XAxis, YAxis, ResponsiveContainer, LineChart, Line } from 'recharts' import { motion } from 'framer-motion' import { useUsageLimiter } from '../hooks/useUsageLimiter' import AccessModal from '../components/AccessModal' // ── PSR Maths (all pure frontend — no API call) ──────────────────────────────── function calcPSR(feeMm: number, contractYrs: number, weeklyWageK: number, agentFeeMm: number) { const annualAmort = feeMm / contractYrs const annualWage = (weeklyWageK * 52) / 1000 const annualAgent = agentFeeMm / contractYrs const totalAnnual = annualAmort + annualWage + annualAgent const totalContract = feeMm + annualWage * contractYrs + agentFeeMm return { annualAmort, annualWage, annualAgent, totalAnnual, totalContract } } const DONUT_COLORS = ['#505070', '#4f8ef7', '#00e87a'] export default function FFPAdvisor() { const { isLocked } = useUsageLimiter() const [feeMm, setFeeMm] = useState(50) const [contractYrs, setContractYrs] = useState(5) const [weeklyWageK, setWeeklyWageK] = useState(120) const [agentFeeMm, setAgentFeeMm] = useState(5) const [psrLossMm, setPsrLossMm] = useState(50) const [psrMaxMm, setPsrMaxMm] = useState(105) const { annualAmort, annualWage, annualAgent, totalAnnual, totalContract } = calcPSR(feeMm, contractYrs, weeklyWageK, agentFeeMm) const newPsrLoss = psrLossMm + totalAnnual const psrRemaining = Math.max(psrMaxMm - newPsrLoss, 0) const isBreach = newPsrLoss > psrMaxMm const overageM = isBreach ? newPsrLoss - psrMaxMm : 0 const donutData = [ { name: 'Existing PSR Loss', value: psrLossMm }, { name: 'This Transfer (Yr1)', value: totalAnnual }, { name: 'Remaining Allowance', value: psrRemaining }, ] const years = Array.from({ length: contractYrs }, (_, i) => `Yr ${i + 1}`) const barData = years.map(y => ({ name: y, Amortisation: +annualAmort.toFixed(2), Wages: +annualWage.toFixed(2), 'Agent Fees': +annualAgent.toFixed(2), })) const bookValueData = years.map((y, i) => ({ name: y, 'Remaining Asset Value': +(feeMm - annualAmort * (i + 1)).toFixed(2) })) return (
Model the precise P&L impact of any transfer on your 3-year Profitability & Sustainability Rules allowance.
PSR calculations are illustrative. The 3-year rolling assessment includes prior years. Always verify with your club's finance team. PL limit = £105m over 3 seasons (2025 rules).