File size: 2,384 Bytes
425a907
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useState } from 'react';
import { AppProvider, useAppState } from './context/AppContext.jsx';
import Toast from './components/Toast.jsx';
import Step1Setup from './pages/Step1Setup.jsx';
import Step2Variables from './pages/Step2Variables.jsx';
import Step3Contributions from './pages/Step3Contributions.jsx';
import Step4Mapping from './pages/Step4Mapping.jsx';
import Step5FixedVars from './pages/Step5FixedVars.jsx';
import Step6Params from './pages/Step6Params.jsx';
import Step7Config from './pages/Step7Config.jsx';
import { showWarnToast } from './components/Toast.jsx';

function AppInner() {
  const [step, setStep] = useState(1);
  const state = useAppState();

  function canLeave(from) {
    if (from === 1) {
      if (!state.files.d || !state.files.p) { showWarnToast('Upload both CSV files first.'); return false; }
      if (!state.selectedPanels.size) { showWarnToast('Select at least 1 panel.'); return false; }
    }
    if (from === 2) {
      const selCount = state.allRows.filter(r => r._sel).length;
      if (!selCount) { showWarnToast('Select at least 1 variable.'); return false; }
    }
    if (from === 3) {
      const hasActs = state.allRows.some(r => r._sel);
      if (!hasActs) { showWarnToast('No variables selected — go back to Page 2.'); return false; }
    }
    if (from === 4) {
      const anyMapped = Object.values(state.panelMap).some(row => Object.values(row).some(v => v === true));
      if (!anyMapped) { showWarnToast('Map at least 1 variable before proceeding.'); return false; }
    }
    return true;
  }

  function goTo(n) {
    if (n > step && !canLeave(step)) return;
    setStep(n);
  }

  function next() { goTo(step + 1); }
  function back() { setStep(s => Math.max(1, s - 1)); }

  const pageProps = { onNext: next, onBack: back, onNav: n => { if (n < step) setStep(n); } };

  return (
    <>
      {step === 1 && <Step1Setup {...pageProps} />}
      {step === 2 && <Step2Variables {...pageProps} />}
      {step === 3 && <Step3Contributions {...pageProps} />}
      {step === 4 && <Step4Mapping {...pageProps} />}
      {step === 5 && <Step5FixedVars {...pageProps} />}
      {step === 6 && <Step6Params {...pageProps} />}
      {step === 7 && <Step7Config {...pageProps} />}
      <Toast />
    </>
  );
}

export default function App() {
  return (
    <AppProvider>
      <AppInner />
    </AppProvider>
  );
}