Spaces:
Running
Running
File size: 12,240 Bytes
b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 b72652e 7dff677 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | 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 (
<div className="page" style={{ position: 'relative' }}>
{isLocked && <AccessModal />}
<motion.div
className="container"
initial={{ opacity: 0, y: 15 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5 }}
>
{/* Header */}
<div style={{ marginBottom:36 }}>
<span className="badge badge-blue" style={{ marginBottom:10, display:'inline-flex' }}>Regulatory Compliance Tool</span>
<h1 style={{ marginBottom:8 }}>💼 PSR / Financial Fair Play Advisor</h1>
<p>Model the precise P&L impact of any transfer on your 3-year Profitability & Sustainability Rules allowance.</p>
</div>
<div style={{ display:'grid', gridTemplateColumns:'320px 1fr', gap:24, alignItems:'start' }}>
{/* ── Left: Inputs ─────────────────────────────────────────────── */}
<div style={{ display:'flex', flexDirection:'column', gap:16 }}>
<div className="glass-flat" style={{ padding:24 }}>
<h3 style={{ marginBottom:20 }}>Transfer Financials</h3>
<div style={{ display:'flex', flexDirection:'column', gap:16 }}>
<div className="input-group">
<label className="field-label">
Transfer Fee (£m)
<span className="range-val" style={{ float:'right' }}>£{feeMm}m</span>
</label>
<input type="range" min={1} max={300} step={1} value={feeMm} onChange={e => setFeeMm(+e.target.value)}/>
<div className="range-row"><span>£1m</span><span>£300m</span></div>
</div>
<div className="input-group">
<label className="field-label">
Contract Length (Years)
<span className="range-val" style={{ float:'right' }}>{contractYrs}yr</span>
</label>
<input type="range" min={1} max={7} step={1} value={contractYrs} onChange={e => setContractYrs(+e.target.value)}/>
<div className="range-row"><span>1yr</span><span>7yr</span></div>
</div>
<div className="input-group">
<label className="field-label">Weekly Wage (£k)</label>
<input type="number" className="input" min={5} max={1000} step={5}
value={weeklyWageK} onChange={e => setWeeklyWageK(+e.target.value)}/>
</div>
<div className="input-group">
<label className="field-label">Agent / Sign-on Fees (£m)</label>
<input type="number" className="input" min={0} max={50} step={0.5}
value={agentFeeMm} onChange={e => setAgentFeeMm(+e.target.value)}/>
</div>
</div>
</div>
<div className="glass-flat" style={{ padding:24 }}>
<h3 style={{ marginBottom:20 }}>Club Economics</h3>
<div style={{ display:'flex', flexDirection:'column', gap:16 }}>
<div className="input-group">
<label className="field-label">Current 3-Yr PSR Loss (£m)</label>
<input type="number" className="input" min={0} max={200} step={5}
value={psrLossMm} onChange={e => setPsrLossMm(+e.target.value)}/>
</div>
<div className="input-group">
<label className="field-label">Max Allowed Loss (£m)</label>
<input type="number" className="input" min={0} max={200} step={5}
value={psrMaxMm} onChange={e => setPsrMaxMm(+e.target.value)}/>
</div>
</div>
</div>
</div>
{/* ── Right: Results ────────────────────────────────────────────── */}
<div style={{ display:'flex', flexDirection:'column', gap:18 }}>
{/* Verdict */}
<div className={`alert ${isBreach ? 'alert-danger' : 'alert-success'}`} style={{ fontSize:'0.95rem', fontWeight:600 }}>
{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.`}
</div>
{/* Summary metrics */}
<div className="glass" style={{ padding:24 }}>
<h3 style={{ marginBottom:20 }}>Financial Impact Summary</h3>
<div className="grid-4" style={{ marginBottom:20 }}>
<div className="metric">
<div className="metric-label">Amortisation / yr</div>
<div className="metric-value">£{annualAmort.toFixed(1)}m</div>
</div>
<div className="metric">
<div className="metric-label">Wages / yr</div>
<div className="metric-value">£{annualWage.toFixed(1)}m</div>
</div>
<div className="metric">
<div className="metric-label">Agent Accrual / yr</div>
<div className="metric-value">£{annualAgent.toFixed(1)}m</div>
</div>
<div className="metric">
<div className="metric-label">Total Annual P&L Hit</div>
<div className="metric-value" style={{ color:'var(--red)' }}>£{totalAnnual.toFixed(1)}m</div>
</div>
</div>
<div style={{ padding:'12px 16px', background:'rgba(79,142,247,0.08)', borderRadius:8, border:'1px solid rgba(79,142,247,0.18)' }}>
<span style={{ color:'var(--blue)', fontWeight:700 }}>
Total Package Cost over {contractYrs} Years: £{totalContract.toFixed(1)}m
</span>
</div>
</div>
{/* Charts row */}
<div style={{ display:'flex', flexDirection:'column', gap:18 }}>
<div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap:18 }}>
<div className="glass" style={{ padding:24 }}>
<h3 style={{ marginBottom:12 }}>PSR Budget Overview</h3>
<PieChart width={280} height={230}>
<Pie data={donutData} cx="50%" cy="50%" innerRadius={55} outerRadius={80} dataKey="value" paddingAngle={2}>
{donutData.map((_, i) => <Cell key={i} fill={DONUT_COLORS[i]}/>)}
</Pie>
<Tooltip
contentStyle={{ background:'var(--bg-elevated)', border:'1px solid var(--glass-border)', borderRadius:8, fontSize:12 }}
formatter={(v: number) => [`£${v.toFixed(1)}m`]}/>
<Legend wrapperStyle={{ fontSize:'0.75rem', color:'var(--text-2)' }}/>
</PieChart>
</div>
<div className="glass" style={{ padding:24 }}>
<h3 style={{ marginBottom:12 }}>Annual P&L Schedule</h3>
<ResponsiveContainer width="100%" height={200}>
<BarChart data={barData} margin={{ top:4, right:8, left:-16, bottom:4 }}>
<XAxis dataKey="name" tick={{ fill:'var(--text-2)', fontSize:10 }} axisLine={false} tickLine={false}/>
<YAxis tick={{ fill:'var(--text-2)', fontSize:10 }} axisLine={false} tickLine={false}/>
<Tooltip
contentStyle={{ background:'var(--bg-elevated)', border:'1px solid var(--glass-border)', borderRadius:8, fontSize:11 }}
formatter={(v: number) => [`£${v.toFixed(1)}m`]}/>
<Bar dataKey="Amortisation" stackId="a" fill="#4f8ef7" radius={[0,0,2,2]}/>
<Bar dataKey="Wages" stackId="a" fill="#00e87a"/>
<Bar dataKey="Agent Fees" stackId="a" fill="#f5a623" radius={[2,2,0,0]}/>
</BarChart>
</ResponsiveContainer>
</div>
</div>
{/* New Declining Book Value Chart */}
<div className="glass" style={{ padding:24 }}>
<h3 style={{ marginBottom:12 }}>Remaining Balance Sheet Book Value (Post-Amortisation)</h3>
<ResponsiveContainer width="100%" height={160}>
<LineChart data={bookValueData} margin={{ top:4, right:8, left:-16, bottom:4 }}>
<XAxis dataKey="name" tick={{ fill:'var(--text-2)', fontSize:10 }} axisLine={false} tickLine={false}/>
<YAxis tick={{ fill:'var(--text-2)', fontSize:10 }} axisLine={false} tickLine={false}/>
<Tooltip
contentStyle={{ background:'var(--bg-elevated)', border:'1px solid var(--glass-border)', borderRadius:8, fontSize:11 }}
formatter={(v: number) => [`£${v.toFixed(1)}m`]}/>
<Line type="monotone" dataKey="Remaining Asset Value" stroke="#4f8ef7" strokeWidth={3} dot={{ fill: '#00e87a', strokeWidth: 2, r: 4 }} activeDot={{ r: 6 }}/>
</LineChart>
</ResponsiveContainer>
</div>
</div>
{/* Disclaimer */}
<p style={{ fontSize:'0.72rem', color:'var(--text-3)', textAlign:'center', lineHeight:1.5 }}>
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).
</p>
</div>
</div>
</motion.div>
</div>
)
}
|