/* global React, DATA, Panel, KPI, BarChart, ComposedChart, fmtEUR, fmtN, fmtPct, fmtSignPct */
const Overview = () => {
  const k = DATA.kpi, m = DATA.meta;
  const rev = DATA.revenue_by_month;
  const revSpark = rev.map(x => x.revenue);
  const lfSpark = rev.map(x => x.lf);
  const mixMax = Math.max(...DATA.market_mix.map(x => x.revenue));

  return React.createElement('div', { className: 'page' },
    // headline
    React.createElement('div', { className: 'page-head' },
      React.createElement('div', { className: 'eyebrow', style: { marginBottom: 8 } }, 'Cyprus Airways Revenue Desk · Network edition'),
      React.createElement('h1', { className: 'headline' }, 'The network is ', React.createElement('em', null, 'pacing ahead'), ' into summer.'),
      React.createElement('div', { className: 'subhead' },
        `Trailing-twelve-month revenue of ${fmtEUR(k.revenue)} on ${fmtN(k.pax)} passengers, up ${fmtSignPct(k.revenue_yoy)} year on year. `
        + `${m.fleet_count} aircraft, ${m.routes} directional O&Ds, ${m.destinations} destinations across ${m.countries} countries from Larnaca.`)),

    // Summer-peak banner
    React.createElement('div', { className: 'banner', style: { marginBottom: 22 } },
      React.createElement('div', { className: 'banner-glyph' }, '☼'),
      React.createElement('div', { style: { flex: 1 } },
        React.createElement('div', { className: 'banner-title' }, 'Summer leisure peak building — Jun 15 through Aug 31'),
        React.createElement('div', { className: 'banner-body' }, 'Greek-island & Mediterranean demand firming into the peak; the Tel Aviv and Athens trunks are pacing ahead of last year. Protect high-yield inventory, hold deep-discount classes closed and review overbooking on the tightest O&Ds.')),
      React.createElement('span', { className: 'pill pill-peak' }, 'PEAK SEASON')),

    // KPI row
    React.createElement('div', { className: 'grid grid-5 gap-2', style: { marginBottom: 22 } },
      React.createElement(KPI, { label: 'Revenue · TTM', value: fmtEUR(k.revenue), delta: k.revenue_yoy, sub: 'YoY', sparkline: revSpark }),
      React.createElement(KPI, { label: 'Passengers · TTM', value: fmtK(k.pax), delta: k.pax_yoy, sub: 'YoY' }),
      React.createElement(KPI, { label: 'Load Factor', value: fmtPct(k.lf), delta: k.lf_delta, sub: 'pts YoY', sparkline: lfSpark, sparklineColor: 'var(--ink)' }),
      React.createElement(KPI, { label: 'RASK', value: '€' + k.rask.toFixed(3), delta: k.rask_yoy, sub: 'YoY' }),
      React.createElement(KPI, { label: 'Yield · per RPK', value: '€' + k.yield_.toFixed(3), sub: 'passenger yield' })),

    // revenue trend + market mix
    React.createElement('div', { className: 'grid gap-3', style: { gridTemplateColumns: '1.55fr 1fr', marginBottom: 22 } },
      React.createElement(Panel, { title: 'Monthly revenue & load factor', sub: 'Flown actuals · €bars, load-factor line' },
        React.createElement(ComposedChart, { data: rev, barKey: 'revenue', lineKey: 'lf', labelKey: 'label',
          barFormat: fmtEUR, lineFormat: v => v.toFixed(0) + '%', barLabel: 'Revenue', lineLabel: 'Load factor', height: 290 })),
      React.createElement(Panel, { title: 'Revenue by market', sub: 'Share of trailing-12-month revenue' },
        React.createElement('div', { style: { padding: '4px 2px' } },
          DATA.market_mix.map((x, i) => React.createElement('div', { key: i, style: { marginBottom: 11 } },
            React.createElement('div', { className: 'row between', style: { marginBottom: 3 } },
              React.createElement('span', { style: { fontWeight: 600, fontSize: 12 } }, x.market),
              React.createElement('span', { className: 'mono', style: { fontSize: 11 } }, fmtEUR(x.revenue), ' · ', fmtPct(x.share))),
            React.createElement('div', { style: { height: 7, background: 'var(--paper-edge)', borderRadius: 3, overflow: 'hidden' } },
              React.createElement('div', { style: { width: (x.revenue / mixMax * 100) + '%', height: '100%', background: i === 0 ? 'var(--accent)' : 'var(--ink)' } })),
            React.createElement('div', { className: 'text-muted', style: { fontSize: 10, marginTop: 2 } }, `LF ${fmtPct(x.lf)} · yield €${x.yield_.toFixed(3)}`))))) ),

    // top routes table
    React.createElement(Panel, { title: 'Top revenue O&Ds', sub: 'Trailing twelve months · directional', flush: true },
      React.createElement('div', { style: { maxHeight: 420, overflowY: 'auto' } },
        React.createElement('table', { className: 'tbl tbl-zebra' },
          React.createElement('thead', null, React.createElement('tr', null,
            ['', 'O&D', 'Market', 'Revenue', 'Pax', 'Load', 'Yield', 'YoY', 'Sectors'].map((h, i) =>
              React.createElement('th', { key: i, className: i > 2 ? 'num' : '' }, h)))),
          React.createElement('tbody', null,
            DATA.top_routes.map((r, i) => React.createElement('tr', { key: i },
              React.createElement('td', { className: 'mono text-faint' }, String(i + 1).padStart(2, '0')),
              React.createElement('td', null, React.createElement('span', { style: { fontWeight: 600 } }, r.od)),
              React.createElement('td', { className: 'text-muted' }, r.market),
              React.createElement('td', { className: 'num mono' }, fmtEUR(r.revenue)),
              React.createElement('td', { className: 'num mono' }, fmtN(r.pax)),
              React.createElement('td', { className: 'num mono' }, fmtPct(r.lf)),
              React.createElement('td', { className: 'num mono' }, '€' + r.yield_.toFixed(3)),
              React.createElement('td', { className: 'num mono ' + (r.yoy >= 0 ? 'text-pos' : 'text-neg') }, r.yoy == null ? '—' : fmtSignPct(r.yoy)),
              React.createElement('td', { className: 'num mono text-muted' }, fmtN(r.flights)))))))));
};
window.Overview = Overview;
