File size: 4,682 Bytes
0ce9643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { useEffect } from 'react';
import { useLocaleStore } from '../store/useLocaleStore';
import type { TranslationKey } from '../i18n/translations';

const SECTIONS: { key: string; color: string }[] = [
  { key: 'overview', color: 'var(--accent-active)' },
  { key: 'T1', color: '#e0e0e0' },
  { key: 'T2', color: '#aaccee' },
  { key: 'fMRI', color: '#ff6644' },
  { key: 'DTI', color: '#44ddaa' },
  { key: 'FLAIR', color: '#ff4466' },
  { key: 'perturbation', color: 'var(--accent-active)' },
  { key: 'shortcuts', color: 'var(--text-primary)' },
];

export function GuideModal() {
  const { isGuideOpen, closeGuide, toggleLocale, locale, t } = useLocaleStore();

  // ESC and H key handlers
  useEffect(() => {
    const handleKey = (e: KeyboardEvent) => {
      if (e.key === 'Escape' && isGuideOpen) {
        closeGuide();
      }
      if (e.key === 'h' || e.key === 'H') {
        // Don't toggle when typing in an input
        const tag = (e.target as HTMLElement).tagName;
        if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return;
        if (isGuideOpen) closeGuide();
        else useLocaleStore.getState().openGuide();
      }
    };
    window.addEventListener('keydown', handleKey);
    return () => window.removeEventListener('keydown', handleKey);
  }, [isGuideOpen, closeGuide]);

  // Prevent body scroll when open
  useEffect(() => {
    if (isGuideOpen) {
      document.body.style.overflow = 'hidden';
      return () => { document.body.style.overflow = ''; };
    }
  }, [isGuideOpen]);

  if (!isGuideOpen) return null;

  return (
    <div
      style={{
        position: 'fixed',
        inset: 0,
        zIndex: 100,
        background: 'rgba(0,0,0,0.75)',
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        animation: 'nmri-fade-in 200ms ease-out',
      }}
      onClick={(e) => {
        if (e.target === e.currentTarget) closeGuide();
      }}
    >
      <div
        style={{
          background: 'var(--bg-primary)',
          border: '1px solid var(--border)',
          borderRadius: 6,
          width: '90vw',
          maxWidth: 700,
          maxHeight: '80vh',
          display: 'flex',
          flexDirection: 'column',
          boxShadow: '0 8px 32px rgba(0,0,0,0.6)',
        }}
      >
        {/* Header */}
        <div
          className="flex items-center gap-3 px-5 py-3 shrink-0"
          style={{ borderBottom: '1px solid var(--border)' }}
        >
          <button
            onClick={closeGuide}
            style={{
              background: 'none',
              border: 'none',
              color: 'var(--text-secondary)',
              fontSize: 'var(--font-size-lg)',
              cursor: 'pointer',
              fontFamily: 'var(--font-primary)',
              padding: '0 4px',
            }}
          >
            X
          </button>
          <span
            className="tracking-widest font-bold"
            style={{ color: 'var(--text-primary)', fontSize: 'var(--font-size-lg)' }}
          >
            {t('guide.title')}
          </span>
          <button
            onClick={toggleLocale}
            className="ml-auto rounded"
            style={{
              background: 'rgba(0,255,170,0.08)',
              border: '1px solid rgba(0,255,170,0.2)',
              color: 'var(--accent-active)',
              padding: '2px 8px',
              fontSize: 'var(--font-size-xs)',
              fontFamily: 'var(--font-primary)',
              cursor: 'pointer',
              letterSpacing: '1px',
            }}
          >
            {locale === 'en' ? 'KO' : 'EN'}
          </button>
        </div>

        {/* Content */}
        <div
          className="overflow-y-auto px-5 py-4"
          style={{ flex: 1 }}
        >
          {SECTIONS.map(({ key, color }) => (
            <div key={key} className="mb-6">
              <div
                className="tracking-wide font-bold mb-2"
                style={{
                  color,
                  fontSize: 'var(--font-size-md)',
                  borderBottom: `1px solid ${color}33`,
                  paddingBottom: 4,
                }}
              >
                {t(`guide.${key}.title` as TranslationKey)}
              </div>
              <div
                style={{
                  color: 'var(--text-data)',
                  fontSize: 'var(--font-size-sm)',
                  lineHeight: 1.7,
                  whiteSpace: 'pre-line',
                }}
              >
                {t(`guide.${key}.body` as TranslationKey)}
              </div>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}