File size: 3,444 Bytes
3ce30ae
712f4ea
 
 
 
 
3ce30ae
 
 
 
712f4ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0cd5796
712f4ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80df99b
 
 
 
712f4ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ce30ae
 
 
 
 
712f4ea
 
 
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
import { useState, lazy, Suspense } from 'react';
import { Plus, BarChart3 } from 'lucide-react';
import { PairList } from '../pairs/PairList';
import { Button } from '../ui/Button';
import type { Pair, Signal } from '../../types';

const AddPairModal = lazy(() =>
  import('../pairs/AddPairModal').then((m) => ({ default: m.AddPairModal }))
);

interface SidebarProps {
  pairs: Pair[];
  signals: Signal[];
  isLoading: boolean;
  selectedSymbol: string | null;
  onSelect: (symbol: string) => void;
}

export function Sidebar({ pairs, signals, isLoading, selectedSymbol, onSelect }: SidebarProps) {
  const [isAddModalOpen, setIsAddModalOpen] = useState(false);

  const activePairCount = pairs.filter((p) => p.is_active).length;

  return (
    <>
      <aside className="w-64 lg:w-72 xl:w-80 shrink-0 flex flex-col border-r border-border bg-bg-card overflow-hidden">
        {/* Sidebar header */}
        <div className="px-4 py-3 border-b border-border">
          <div className="flex items-center justify-between mb-3">
            <div className="flex items-center gap-2">
              <BarChart3 size={14} className="text-accent-blue" />
              <span className="text-xs font-semibold text-text-secondary uppercase tracking-wider">
                Pairs
              </span>
            </div>
            {activePairCount > 0 && (
              <span className="text-[10px] font-mono bg-accent-blue/10 text-accent-blue border border-accent-blue/20 px-1.5 py-0.5 rounded">
                {activePairCount} active
              </span>
            )}
          </div>

          <Button
            variant="primary"
            size="sm"
            onClick={() => setIsAddModalOpen(true)}
            icon={<Plus size={13} />}
            className="w-full justify-center"
          >
            Add Pair
          </Button>
        </div>

        {/* Pair list */}
        <div className="flex-1 overflow-y-auto py-2">
          <PairList
            pairs={pairs}
            signals={signals}
            isLoading={isLoading}
            selectedSymbol={selectedSymbol}
            onSelect={onSelect}
          />
        </div>

        {/* Footer stats */}
        <div className="px-4 py-3 border-t border-border">
          <div className="grid grid-cols-3 gap-2 text-center">
            {(['LONG', 'SHORT', 'NEUTRAL'] as const).map((dir) => {
              const activeSymbolSet = new Set(pairs.filter((p) => p.is_active).map((p) => p.symbol));
              const count = signals.filter(
                (s) => activeSymbolSet.has(s.symbol) && s.direction === dir
              ).length;
              return (
                <div key={dir}>
                  <p
                    className={`text-sm font-bold font-mono ${
                      dir === 'LONG'
                        ? 'text-signal-long'
                        : dir === 'SHORT'
                        ? 'text-signal-short'
                        : 'text-text-muted'
                    }`}
                  >
                    {count}
                  </p>
                  <p className="text-[10px] text-text-muted">{dir}</p>
                </div>
              );
            })}
          </div>
        </div>
      </aside>

      {isAddModalOpen && (
        <Suspense fallback={null}>
          <AddPairModal isOpen={isAddModalOpen} onClose={() => setIsAddModalOpen(false)} />
        </Suspense>
      )}
    </>
  );
}