Spaces:
Runtime error

File size: 6,900 Bytes
8f05b63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import React from 'react'
import { Upload, Download, Trash2, MousePointer, Minus, ArrowUpDown, Square, TrendingUp, Sun, Moon, Type, Settings } from 'lucide-react'
import { Button } from './ui/button'
import { Separator } from './ui/separator'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './ui/tooltip'

const Sidebar = ({
  onFileUpload,
  onReset,
  activeTool,
  setActiveTool,
  theme,
  setTheme,
  chartType,
  setChartType,
  currentSymbol,
  symbolData,
  onDownloadSample,
  onNavigateToDate
}) => {
  const [dateInput, setDateInput] = React.useState('')
  const fileInputRef = React.useRef(null)

  const tools = [
    { id: 'cursor', icon: MousePointer, label: 'Курсор' },
    { id: 'horizontal', icon: Minus, label: 'Горизонтальна лінія' },
    { id: 'vertical', icon: ArrowUpDown, label: 'Вертикальна лінія' },
    { id: 'rectangle', icon: Square, label: 'Прямокутник' },
    { id: 'fibonacci', icon: TrendingUp, label: 'Фібоначчі' },
  ]

  const chartTypes = [
    { id: 'candlestick', label: 'Свічки' },
    { id: 'line', label: 'Лінія' },
    { id: 'area', label: 'З областю' },
  ]

  const handleFileChange = (e) => {
    const file = e.target.files?.[0]
    if (file) onFileUpload(file)
    e.target.value = ''
  }

  const handleNavigate = () => {
    if (dateInput) {
      onNavigateToDate(dateInput)
      setDateInput('')
    }
  }

  return (
    <div className="w-full h-full flex flex-col bg-card border-r overflow-hidden">
      <div className="p-4 flex-1 overflow-y-auto space-y-6">
        <div className="space-y-2">
          <h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Дані</h3>
          <div className="space-y-2">
            <Button
              variant="outline"
              className="w-full justify-start gap-2"
              onClick={() => fileInputRef.current?.click()}
            >
              <Upload className="h-4 w-4" />
              Завантажити CSV
            </Button>
            <input
              ref={fileInputRef}
              type="file"
              accept=".csv"
              className="hidden"
              onChange={handleFileChange}
            />
            <Button
              variant="outline"
              className="w-full justify-start gap-2"
              onClick={onDownloadSample}
            >
              <Download className="h-4 w-4" />
              Зразок CSV
            </Button>
            <Button
              variant="outline"
              className="w-full justify-start gap-2 text-destructive hover:text-destructive"
              onClick={onReset}
            >
              <Trash2 className="h-4 w-4" />
              Очистити
            </Button>
          </div>
        </div>

        <Separator />

        <div className="space-y-2">
          <h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Тип графіка</h3>
          <div className="flex flex-col gap-1">
            {chartTypes.map((type) => (
              <Button
                key={type.id}
                variant={chartType === type.id ? 'secondary' : 'ghost'}
                size="sm"
                className="w-full justify-start"
                onClick={() => setChartType(type.id)}
              >
                {type.label}
              </Button>
            ))}
          </div>
        </div>

        <Separator />

        <div className="space-y-2">
          <h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Інструменти малювання</h3>
          <div className="grid grid-cols-2 gap-1">
            <TooltipProvider>
              {tools.map((tool) => (
                <Tooltip key={tool.id}>
                  <TooltipTrigger asChild>
                    <Button
                      variant={activeTool === tool.id ? 'secondary' : 'ghost'}
                      size="icon"
                      className="w-full h-9"
                      onClick={() => setActiveTool(activeTool === tool.id ? 'cursor' : tool.id)}
                    >
                      <tool.icon className="h-4 w-4" />
                    </Button>
                  </TooltipTrigger>
                  <TooltipContent>
                    <p>{tool.label}</p>
                  </TooltipContent>
                </Tooltip>
              ))}
            </TooltipProvider>
          </div>
        </div>

        <Separator />

        <div className="space-y-2">
          <h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Навігація</h3>
          <div className="space-y-2">
            <div className="flex gap-2">
              <input
                type="datetime-local"
                value={dateInput}
                onChange={(e) => setDateInput(e.target.value)}
                className="flex-1 h-9 rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
              />
              <Button size="sm" onClick={handleNavigate}>
                Перейти
              </Button>
            </div>
          </div>
        </div>

        <Separator />

        <div className="space-y-2">
          <h3 className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">Налаштування</h3>
          <Button
            variant="outline"
            size="sm"
            className="w-full justify-start gap-2"
            onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
          >
            {theme === 'dark' ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}
            {theme === 'dark' ? 'Світла тема' : 'Темна тема'}
          </Button>
        </div>
      </div>

      <div className="p-4 border-t bg-muted/50">
        <div className="flex items-center gap-2 text-xs text-muted-foreground">
          <Type className="h-3 w-3" />
          {currentSymbol ? (
            <span className="font-medium">{currentSymbol}</span>
          ) : (
            <span>Немає даних</span>
          )}
        </div>
        {symbolData && (
          <div className="mt-2 grid grid-cols-2 gap-x-2 gap-y-1 text-xs text-muted-foreground">
            <span>O: {symbolData.open?.toFixed(2)}</span>
            <span>H: {symbolData.high?.toFixed(2)}</span>
            <span>L: {symbolData.low?.toFixed(2)}</span>
            <span>C: {symbolData.close?.toFixed(2)}</span>
          </div>
        )}
      </div>
    </div>
  )
}

export default Sidebar