/* global React, DATA, Panel, KPI, fmtN, fmtEUR */
const Overrides = () => {
  const ov = DATA.overrides;
  const accepted = ov.filter(o => o.status === 'Accepted').length;
  const agentProposed = ov.filter(o => o.source === 'Agent-proposed').length;
  const totalImpact = ov.reduce((s, o) => s + (o.revenue_impact_eur || 0), 0);
  const statusPill = s => s === 'Accepted' ? 'pill-pos' : s === 'Rejected' ? 'pill-neg' : 'pill-warn';

  return React.createElement('div', { className: 'page' },
    React.createElement('div', { className: 'page-head' },
      React.createElement('div', { className: 'eyebrow', style: { marginBottom: 8 } }, 'Override Activity'),
      React.createElement('h1', { className: 'headline', style: { fontSize: 46 } }, 'Every decision, ', React.createElement('em', null, 'on the record.')),
      React.createElement('div', { className: 'subhead' }, 'The audit trail of agent-proposed and analyst-initiated overrides — the human-in-the-loop record behind every inventory and pricing move.')),

    React.createElement('div', { className: 'grid grid-4 gap-2', style: { marginBottom: 22 } },
      React.createElement(KPI, { label: 'Overrides logged', value: fmtN(ov.length), sub: 'recent window' }),
      React.createElement(KPI, { label: 'Agent-proposed', value: fmtN(agentProposed), sub: `${Math.round(agentProposed / ov.length * 100)}% of activity` }),
      React.createElement(KPI, { label: 'Accepted', value: fmtN(accepted), sub: `${Math.round(accepted / ov.length * 100)}% acceptance` }),
      React.createElement(KPI, { label: 'Net revenue impact', value: fmtEUR(totalImpact), sub: 'estimated' })),

    React.createElement(Panel, { title: 'Override register', sub: 'Most recent first', flush: true },
      React.createElement('div', { style: { maxHeight: 560, overflowY: 'auto' } },
        React.createElement('table', { className: 'tbl tbl-zebra' },
          React.createElement('thead', null, React.createElement('tr', null,
            ['When', 'Analyst', 'O&D', 'Action', 'Detail', 'Source', 'Status', 'Rev impact'].map((h, i) =>
              React.createElement('th', { key: i, className: i === 7 ? 'num' : '' }, h)))),
          React.createElement('tbody', null,
            ov.map((o, i) => React.createElement('tr', { key: i },
              React.createElement('td', { className: 'mono text-muted', style: { fontSize: 10.5, whiteSpace: 'nowrap' } }, (o.ts || '').slice(5, 16).replace('T', ' ')),
              React.createElement('td', null, o.analyst),
              React.createElement('td', { style: { fontWeight: 600 } }, o.od),
              React.createElement('td', null, React.createElement('span', { className: 'pill pill-info' }, o.action)),
              React.createElement('td', { className: 'text-dim', style: { fontSize: 11 } }, o.description),
              React.createElement('td', { className: 'text-muted', style: { fontSize: 10.5 } }, o.source),
              React.createElement('td', null, React.createElement('span', { className: 'pill ' + statusPill(o.status) }, o.status)),
              React.createElement('td', { className: 'num mono ' + ((o.revenue_impact_eur || 0) >= 0 ? 'text-pos' : 'text-neg') }, fmtEUR(o.revenue_impact_eur))))))) ));
};
window.Overrides = Overrides;
