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 (
{isLocked && } {/* Header */}
Regulatory Compliance Tool

💼 PSR / Financial Fair Play Advisor

Model the precise P&L impact of any transfer on your 3-year Profitability & Sustainability Rules allowance.

{/* ── Left: Inputs ─────────────────────────────────────────────── */}

Transfer Financials

setFeeMm(+e.target.value)}/>
£1m£300m
setContractYrs(+e.target.value)}/>
1yr7yr
setWeeklyWageK(+e.target.value)}/>
setAgentFeeMm(+e.target.value)}/>

Club Economics

setPsrLossMm(+e.target.value)}/>
setPsrMaxMm(+e.target.value)}/>
{/* ── Right: Results ────────────────────────────────────────────── */}
{/* Verdict */}
{isBreach ? `⚠️ BREACH RISK — This transfer pushes the club £${overageM.toFixed(1)}m over the £${psrMaxMm}m PSR limit in Year 1.` : `✅ COMPLIANT — The club remains £${psrRemaining.toFixed(1)}m under the £${psrMaxMm}m PSR limit.`}
{/* Summary metrics */}

Financial Impact Summary

Amortisation / yr
£{annualAmort.toFixed(1)}m
Wages / yr
£{annualWage.toFixed(1)}m
Agent Accrual / yr
£{annualAgent.toFixed(1)}m
Total Annual P&L Hit
£{totalAnnual.toFixed(1)}m
Total Package Cost over {contractYrs} Years: £{totalContract.toFixed(1)}m
{/* Charts row */}

PSR Budget Overview

{donutData.map((_, i) => )} [`£${v.toFixed(1)}m`]}/>

Annual P&L Schedule

[`£${v.toFixed(1)}m`]}/>
{/* New Declining Book Value Chart */}

Remaining Balance Sheet Book Value (Post-Amortisation)

[`£${v.toFixed(1)}m`]}/>
{/* Disclaimer */}

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).

) }