// dashboard/app.jsx — Main app shell with sticky side nav and section assembly.

const { useState, useEffect, useRef } = React;

const SECTIONS = [
{ id: 'overview', short: 'Overview', eyebrow: '01', title: 'Overview', subtitle: 'Σκοπός, μοντέλα, στρατηγική αξιολόγησης' },
{ id: 'models', short: 'Μοντέλα', eyebrow: '02', title: 'Models — DeepLabV3 + PointRend', subtitle: 'Backbone, bands, training configuration' },
{ id: 'data', short: 'Data', eyebrow: '03', title: 'Data — Ground-truth raster', subtitle: 'Class distribution και inherent imbalance' },
{ id: 'methods', short: 'Methods M1–M4', eyebrow: '04', title: 'Evaluation methods', subtitle: 'Τέσσερις ανεξάρτητες μεθοδολογίες, κάθε μία εφαρμοσμένη και στα δύο μοντέλα' },
{ id: 'metrics-def', short: 'Metrics explained', eyebrow: '05', title: 'Metrics — επεξήγηση και θεωρία', subtitle: 'Η ιντουϊτιώδης σημασία των OA, Kappa, P/R/F1, IoU' },
{ id: 'results', short: 'Global results', eyebrow: '06', title: 'Global results — methods × metrics', subtitle: 'M1–M4 × {OA, Kappa, Macro-F1, mIoU} × {7-Band, RGB} σε ένα συμπαγές view' },
{ id: 'method-bars', short: 'OA per method', eyebrow: '07', title: 'OA per method — visual comparison', subtitle: 'Πόσο σταθερό είναι το advantage μεταξύ μεθόδων' },
{ id: 'perclass', short: 'Per-class F1', eyebrow: '08', title: 'Per-class F1 — mean of M1–M4', subtitle: 'Ποιες κλάσεις ωφελούνται περισσότερο από τα extra bands' },
{ id: 'delta', short: 'Per-class Δ', eyebrow: '09', title: 'Per-class advantage — Δ F1', subtitle: '7-Band − RGB ανά κλάση' },
{ id: 'parity', short: 'Parity plot · ⚡', eyebrow: '10', title: 'Per-class parity plot — διαδραστικό', subtitle: '7-Band F1 vs RGB F1 — hover/click σε κάθε κλάση για πλήρη breakdown' },
{ id: 'cm', short: 'Confusion matrix', eyebrow: '11', title: 'Confusion matrices', subtitle: 'Row-normalized (recall). Πάτησε model/method για εναλλαγή' },
{ id: 'sig-mcnemar', short: 'McNemar', eyebrow: '12', title: 'Stage 8 — McNemar exact test', subtitle: 'Paired design, n = 2,100 stratified random points' },
{ id: 'sig-null', short: 'Null distributions · ⚡', eyebrow: '13', title: 'Per-class null distributions — διαδραστικό', subtitle: 'Η παρατηρούμενη τιμή b έναντι της Binomial(n, 0.5) PMF' },
{ id: 'sig-boot', short: 'Bootstrap', eyebrow: '14', title: 'Paired bootstrap — effect size', subtitle: '95% CIs για ΔOA, ΔKappa, ΔMacro-F1 από B = 10,000 resamples' },
{ id: 'sig-pc', short: 'Per-class table', eyebrow: '15', title: 'Per-class significance + Holm correction', subtitle: 'Σε ποιες κλάσεις είναι το advantage πραγματικά σημαντικό' },
{ id: 'sig-conv', short: 'Convergent validity', eyebrow: '16', title: 'Convergent validity', subtitle: 'Πέντε ανεξάρτητα tests, ίδια απόφαση' },
{ id: 'findings', short: 'Findings', eyebrow: '17', title: 'Key findings', subtitle: 'Τι μας λέει η ανάλυση' },
{ id: 'project', short: 'Project info', eyebrow: '18', title: 'Project information', subtitle: 'Reproducibility metadata' }];


function useScrollSpy(ids, offset = 120) {
  const [active, setActive] = useState(ids[0]);
  useEffect(() => {
    const onScroll = () => {
      let current = ids[0];
      for (const id of ids) {
        const el = document.getElementById(id);
        if (!el) continue;
        const top = el.getBoundingClientRect().top;
        if (top - offset <= 0) current = id;
      }
      setActive(current);
    };
    window.addEventListener('scroll', onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener('scroll', onScroll);
  }, [ids.join('|'), offset]);
  return active;
}

function App() {
  const active = useScrollSpy(SECTIONS.map((s) => s.id));

  return (
    <div className="dash-shell">
      {/* Sticky side nav */}
      <aside className="dash-nav" aria-label="Section navigation">
        <div className="dash-brand">
          <div className="dash-brand-mark">
            <svg viewBox="0 0 24 24" width="22" height="22">
              <rect x="3" y="3" width="8" height="8" rx="1.5" fill="oklch(55% 0.13 250)" />
              <rect x="13" y="3" width="8" height="8" rx="1.5" fill="oklch(70% 0.13 60)" />
              <rect x="3" y="13" width="8" height="8" rx="1.5" fill="oklch(52% 0.17 145)" />
              <rect x="13" y="13" width="8" height="8" rx="1.5" fill="oklch(40% 0.04 250)" />
            </svg>
          </div>
          <div className="dash-brand-text">
            <div className="dash-brand-name">Thesis Dashboard</div>
            <div className="dash-brand-sub">7-Band vs RGB · DeepLabV3</div>
          </div>
        </div>
        <nav className="dash-nav-list">
          {SECTIONS.map((s) =>
          <a key={s.id} href={'#' + s.id}
          className={'nav-item' + (active === s.id ? ' active' : '')}>
              <span className="nav-num mono">{s.eyebrow}</span>
              <span className="nav-label">{s.short}</span>
            </a>
          )}
        </nav>
        <div className="dash-nav-foot">
          <a href="7-Band Loss Curves.html" className="nav-extra">↗ 7-Band loss curves</a>
          <a href="RGB Loss Curves.html" className="nav-extra">↗ RGB loss curves</a>
        </div>
      </aside>

      {/* Main content */}
      <main className="dash-main">
        <window.DHero />

        <window.DSection {...SECTIONS[0]} label="01 Overview">
          <window.DKPIs />
        </window.DSection>

        <window.DSection {...SECTIONS[1]} label="02 Models">
          <window.DModelCards />
        </window.DSection>

        <window.DSection {...SECTIONS[2]} label="03 Data">
          <window.DClassDistribution />
        </window.DSection>

        <window.DSection {...SECTIONS[3]} label="04 Methods">
          <window.DMethodCards />
        </window.DSection>

        <window.DSection {...SECTIONS[4]} label="05 Metrics explained">
          <window.DMetricsExplained />
        </window.DSection>

        <window.DSection {...SECTIONS[5]} label="06 Global results">
          <window.DGlobalResults />
          <window.DResultsViz />
        </window.DSection>

        <window.DSection {...SECTIONS[6]} label="07 OA per method">
          <window.DMethodBars />
        </window.DSection>

        <window.DSection {...SECTIONS[7]} label="08 Per-class F1">
          <window.DPerClassF1 />
        </window.DSection>

        <window.DSection {...SECTIONS[8]} label="09 Per-class delta">
          <window.DDeltaChart />
        </window.DSection>

        <window.DSection {...SECTIONS[9]} label="10 Parity plot">
          <window.DParityScatter />
        </window.DSection>

        <window.DSection {...SECTIONS[10]} label="11 Confusion matrices">
          <window.DConfusionMatrixSection />
        </window.DSection>

        <window.DSection {...SECTIONS[11]} label="12 McNemar">
          <window.DMcNemarContingency />
        </window.DSection>

        <window.DSection {...SECTIONS[12]} label="13 Null distributions">
          <window.DNullDistribution />
        </window.DSection>

        <window.DSection {...SECTIONS[13]} label="14 Bootstrap">
          <window.DBootstrapCard />
        </window.DSection>

        <window.DSection {...SECTIONS[14]} label="15 Per-class significance">
          <window.DPerClassMcNemar />
        </window.DSection>

        <window.DSection {...SECTIONS[15]} label="16 Convergent validity">
          <window.DConvergentValidity />
        </window.DSection>

        <window.DSection {...SECTIONS[16]} label="17 Findings">
          <window.DFindingsCards />
        </window.DSection>

        <window.DSection {...SECTIONS[17]} label="18 Project info">
          <window.DProjectInfo />
        </window.DSection>

        <footer className="dash-footer">
          <span>© {window.DASH.meta.author} · {window.DASH.meta.institution}</span>
        </footer>
      </main>
    </div>);

}

ReactDOM.createRoot(document.getElementById('root')).render(<App />);