File size: 5,520 Bytes
14356bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState } from 'react'
import { useData } from '../DataContext.jsx'
import UploadModal from './UploadModal.jsx'

const LS_KEY = 'genesis_active_file'

export default function Header({ user, onLogout }) {
  const { stats, reload } = useData()
  const s = stats || {}
  const [uploadOpen, setUploadOpen] = useState(false)
  const [activeFile, setActiveFile] = useState(
    () => localStorage.getItem(LS_KEY) || ''
  )

  function handleSuccess(filename) {
    if (filename) {
      setActiveFile(filename)
      localStorage.setItem(LS_KEY, filename)
    }
    reload()
  }

  return (
    <>
      <header className="hdr">
        <div className="hdr-left">
          <img src="/dabur_logo.jpg" alt="Dabur" className="logo-d" />
          <div className="hdr-brand-txt">
            <div className="brand">{s.brand || 'Genesis AI'}</div>
            <div className="sub">Price Elasticity Intelligence · Genesis AI</div>
          </div>
          <img src="/genesis_logo.jpg" alt="Genesis AI" className="logo-g" />
        </div>
        <div className="hdr-right">

          {/* Active file display */}
          <div style={{
            display: 'flex', alignItems: 'center', gap: 7,
            background: activeFile ? 'rgba(26,107,47,.07)' : 'var(--sf)',
            border: `1px solid ${activeFile ? 'rgba(26,107,47,.25)' : 'var(--bd)'}`,
            borderRadius: 8, padding: '5px 11px',
            minWidth: 160, maxWidth: 280,
          }}>
            <span style={{ fontSize: 14, flexShrink: 0 }}>
              {activeFile ? '📄' : '📭'}
            </span>
            <div style={{ minWidth: 0 }}>
              <div style={{
                fontSize: 9, fontWeight: 600, letterSpacing: .5,
                color: activeFile ? 'var(--gn)' : 'var(--mt)',
                textTransform: 'uppercase', lineHeight: 1,
              }}>
                {activeFile ? 'Simulating' : 'No file loaded'}
              </div>
              {activeFile ? (
                <div style={{
                  fontSize: 10, color: 'var(--tx)', fontFamily: 'var(--mono)',
                  whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis',
                  maxWidth: 200, marginTop: 2, lineHeight: 1.2,
                }}>
                  {activeFile}
                </div>
              ) : (
                <div style={{ fontSize: 10, color: 'var(--mt)', marginTop: 2, lineHeight: 1.2 }}>
                  Upload an Excel file to begin
                </div>
              )}
            </div>
          </div>

          {/* Upload button — always visible */}
          <button
            onClick={() => setUploadOpen(true)}
            title={activeFile ? 'Replace current file' : 'Upload Excel file'}
            style={{
              display: 'flex', alignItems: 'center', gap: 5,
              background: activeFile ? 'var(--sf)' : 'var(--gn)',
              color: activeFile ? 'var(--gn)' : '#fff',
              border: activeFile ? '1px solid rgba(26,107,47,.4)' : 'none',
              borderRadius: 8,
              padding: '6px 13px', cursor: 'pointer',
              fontSize: 11, fontWeight: 600,
              boxShadow: activeFile ? 'none' : '0 1px 4px rgba(26,107,47,.25)',
              flexShrink: 0,
            }}>
            {activeFile ? '↑ Replace' : '↑ Upload'}
          </button>

          <div className="bdg">30 grains</div>
          {s.dab_cr_25 && (
            <div className="hdr-stat">
              <span className="val">₹{s.dab_cr_25?.toFixed(1)}Cr</span>
              <span className="lbl">2025 Value</span>
            </div>
          )}
          {s.vol_growth != null && (
            <div className="hdr-stat">
              <span className="val" style={{ color: s.vol_growth >= 0 ? 'var(--gn)' : 'var(--rd)' }}>
                {s.vol_growth >= 0 ? '+' : ''}{s.vol_growth?.toFixed(1)}%
              </span>
              <span className="lbl">Vol Growth</span>
            </div>
          )}
          {s.avg_own_e != null && (
            <div className="hdr-stat">
              <span className="val" style={{ color: 'var(--saf)' }}>{s.avg_own_e?.toFixed(2)}</span>
              <span className="lbl">Avg Own ε</span>
            </div>
          )}

          {/* Logged-in user + logout */}
          {user && (
            <div style={{
              display: 'flex', alignItems: 'center', gap: 8,
              borderLeft: '1px solid var(--bd)', paddingLeft: 12, marginLeft: 4,
            }}>
              <div style={{ textAlign: 'right' }}>
                <div style={{ fontSize: 11, fontWeight: 600, color: 'var(--tx)', lineHeight: 1.2 }}>
                  {user.name}
                </div>
                <div style={{ fontSize: 9, color: 'var(--mt)', lineHeight: 1.2 }}>
                  {user.email}
                </div>
              </div>
              <button
                onClick={onLogout}
                title="Sign out"
                style={{
                  background: 'var(--sf)', border: '1px solid var(--bd)',
                  borderRadius: 7, padding: '5px 10px',
                  fontSize: 11, fontWeight: 600, color: 'var(--mt)',
                  cursor: 'pointer', flexShrink: 0,
                }}>
                Sign out
              </button>
            </div>
          )}
        </div>
      </header>

      <UploadModal
        open={uploadOpen}
        onClose={() => setUploadOpen(false)}
        onSuccess={handleSuccess}
      />
    </>
  )
}