File size: 10,071 Bytes
e067c2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47bba68
e067c2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import { useState, useEffect } from 'react';
import { useGridStore } from './store/gridStore';
import { Grid } from './components/Grid/Grid';
import { GridGenerator } from './components/Controls/GridGenerator';
import { AlgorithmSelector } from './components/Controls/AlgorithmSelector';
import { PlaybackControls } from './components/Controls/PlaybackControls';
import { MetricsPanel } from './components/Stats/MetricsPanel';
import { ComparisonDashboard } from './components/Stats/ComparisonDashboard';
import { GroupInfo } from './components/Info/GroupInfo';
import { PlanResultsModal } from './components/Stats/PlanResultsModal';
import { Button } from './components/ui/button';
import {
  ChevronLeft,
  ChevronRight,
  Play,
  FileText,
  Eye,
  BarChart3,
  Truck,
  AlertCircle,
  Users,
  Circle,
  Square,
  X,
} from 'lucide-react';

type Tab = 'visualize' | 'compare' | 'info';

function App() {
  const [activeTab, setActiveTab] = useState<Tab>('visualize');
  const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
  const [showPlanModal, setShowPlanModal] = useState(false);
  const {
    grid,
    planResult,
    runPlan,
    runSearch,
    isLoading,
    error,
  } = useGridStore();

  // Open modal when planResult is updated
  useEffect(() => {
    if (planResult) {
      setShowPlanModal(true);
    }
  }, [planResult]);

  const handleRunSearch = () => {
    if (!grid || grid.stores.length === 0 || grid.destinations.length === 0) return;
    const start = grid.stores[0].position;
    const goal = grid.destinations[0].position;
    runSearch(start, goal);
  };

  const handleRunPlan = async () => {
    await runPlan();
  };

  return (
    <div className="h-screen w-screen bg-zinc-950 text-zinc-100 flex flex-col overflow-hidden">
      {/* Header */}
      <header className="bg-zinc-900/80 backdrop-blur-sm border-b border-zinc-800 px-6 py-3 flex items-center justify-between shrink-0">
        <div className="flex items-center gap-4">
          <div className="flex items-center gap-3">
            <div className="p-2 bg-zinc-800 rounded-lg">
              <Truck className="w-5 h-5 text-zinc-300" />
            </div>
            <div>
              <h1 className="text-lg font-semibold text-zinc-100">Pathfinding Visualizer</h1>
              <p className="text-xs text-zinc-500">Search Algorithm Analysis</p>
            </div>
          </div>
        </div>

        {/* Tab navigation */}
        <div className="flex gap-1 p-1 bg-zinc-800/50 rounded-lg">
          <Button
            onClick={() => setActiveTab('visualize')}
            variant={activeTab === 'visualize' ? 'secondary' : 'ghost'}
            size="sm"
            className="gap-2"
          >
            <Eye className="w-4 h-4" />
            Visualize
          </Button>
          <Button
            onClick={() => setActiveTab('compare')}
            variant={activeTab === 'compare' ? 'secondary' : 'ghost'}
            size="sm"
            className="gap-2"
          >
            <BarChart3 className="w-4 h-4" />
            Compare
          </Button>
          <Button
            onClick={() => setActiveTab('info')}
            variant={activeTab === 'info' ? 'secondary' : 'ghost'}
            size="sm"
            className="gap-2"
          >
            <Users className="w-4 h-4" />
            Group Info
          </Button>
        </div>

        <div className="flex items-center gap-2">
          {grid && (
            <>
              <Button
                onClick={handleRunSearch}
                disabled={isLoading}
                variant="primary"
                size="sm"
                className="gap-2"
              >
                <Play className="w-4 h-4" />
                {isLoading ? 'Running...' : 'Run Search for S1'}
              </Button>
              <Button
                onClick={handleRunPlan}
                disabled={isLoading}
                variant="outline"
                size="sm"
                className="gap-2"
              >
                <FileText className="w-4 h-4" />
                Full Plan
              </Button>
            </>
          )}
        </div>
      </header>

      {/* Main content */}
      <div className="flex-1 flex overflow-hidden">
        {/* Sidebar */}
        <aside className={`bg-zinc-900/50 border-r border-zinc-800 flex flex-col transition-all duration-300 ${sidebarCollapsed ? 'w-12' : 'w-80'}`}>
          <button
            onClick={() => setSidebarCollapsed(!sidebarCollapsed)}
            className="p-3 text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800/50 border-b border-zinc-800 transition-colors"
          >
            {sidebarCollapsed ? <ChevronRight className="w-4 h-4" /> : <ChevronLeft className="w-4 h-4" />}
          </button>

          {!sidebarCollapsed && (
            <div className="flex-1 overflow-y-auto p-4 space-y-4">
              <GridGenerator />
              <AlgorithmSelector />
              <PlaybackControls />
              <MetricsPanel />
            </div>
          )}
        </aside>

        {/* Main area */}
        <main className="flex-1 flex flex-col overflow-hidden" style={{ backgroundColor: '#0a0a0b' }}>
          {/* Error display */}
          {error && (
            <div className="m-4 mb-0 p-3 bg-red-500/10 border border-red-500/20 rounded-lg text-red-400 flex items-center gap-3 text-sm">
              <AlertCircle className="w-4 h-4 shrink-0" />
              <span>{error}</span>
            </div>
          )}

          {/* Content */}
          <div className="flex-1 overflow-hidden relative">
            {activeTab === 'visualize' ? (
              <>
                <Grid />
                {/* Legend overlay */}
                <div className="absolute bottom-4 left-4 bg-zinc-900/95 backdrop-blur-sm border border-zinc-800 rounded-lg p-3 shadow-xl">
                  <p className="text-[10px] uppercase tracking-wider text-zinc-500 font-medium mb-2">Legend</p>
                  <div className="flex gap-4 text-xs">
                    <div className="flex flex-col gap-1.5">
                      <div className="flex items-center gap-2">
                        <Circle className="w-2.5 h-2.5 fill-amber-500 text-amber-500" />
                        <span className="text-zinc-400">Current</span>
                      </div>
                      <div className="flex items-center gap-2">
                        <Circle className="w-2.5 h-2.5 fill-emerald-500 text-emerald-500" />
                        <span className="text-zinc-400">Path</span>
                      </div>
                      <div className="flex items-center gap-2">
                        <Circle className="w-2.5 h-2.5 fill-sky-500 text-sky-500" />
                        <span className="text-zinc-400">Frontier</span>
                      </div>
                      <div className="flex items-center gap-2">
                        <Circle className="w-2.5 h-2.5 fill-zinc-500 text-zinc-500" />
                        <span className="text-zinc-400">Explored</span>
                      </div>
                    </div>
                    <div className="border-l border-zinc-800 pl-4 flex flex-col gap-1.5">
                      <div className="flex items-center gap-2">
                        <Square className="w-2.5 h-2.5 fill-blue-500 text-blue-500 rounded-sm" />
                        <span className="text-zinc-400">Store</span>
                      </div>
                      <div className="flex items-center gap-2">
                        <Circle className="w-2.5 h-2.5 fill-emerald-500 text-emerald-500" />
                        <span className="text-zinc-400">Destination</span>
                      </div>
                      <div className="flex items-center gap-2">
                        <Circle className="w-2.5 h-2.5 fill-purple-500 text-purple-500" />
                        <span className="text-zinc-400">Tunnel</span>
                      </div>
                      <div className="flex items-center gap-2">
                        <X className="w-2.5 h-2.5 text-red-500" />
                        <span className="text-zinc-400">Blocked</span>
                      </div>
                    </div>
                    <div className="border-l border-zinc-800 pl-4">
                      <p className="text-zinc-600 text-[10px] mb-1">Edge Costs</p>
                      <div className="flex gap-2 text-xs font-mono">
                        <span className="text-zinc-300">1</span>
                        <span className="text-zinc-400">2</span>
                        <span className="text-zinc-500">3</span>
                        <span className="text-zinc-600">4</span>
                      </div>
                    </div>
                  </div>
                </div>
              </>
            ) : activeTab === 'compare' ? (
              <div className="h-full p-4">
                <ComparisonDashboard />
              </div>
            ) : (
              <GroupInfo />
            )}
          </div>
        </main>
      </div>

      {/* Status bar */}
      <footer className="bg-zinc-900/50 border-t border-zinc-800 px-6 py-2 flex items-center justify-between text-xs text-zinc-600 shrink-0">
        <div className="flex items-center gap-4 font-mono">
          {grid && (
            <>
              <span>Grid {grid.width}x{grid.height}</span>
              <span className="text-zinc-700">|</span>
              <span>S:{grid.stores.length}</span>
              <span>D:{grid.destinations.length}</span>
              <span>T:{grid.tunnels.length}</span>
            </>
          )}
        </div>
        <div className="flex items-center gap-2">
          <span className="w-1.5 h-1.5 rounded-full bg-emerald-500"></span>
          <span>Connected</span>
        </div>
      </footer>

      {/* Plan Results Modal */}
      <PlanResultsModal
        isOpen={showPlanModal}
        onClose={() => setShowPlanModal(false)}
      />
    </div>
  );
}

export default App;