Spaces:
Sleeping
Sleeping
File size: 8,235 Bytes
e067c2d 47bba68 e067c2d 47bba68 e067c2d 47bba68 e067c2d 47bba68 e067c2d 47bba68 e067c2d 47bba68 e067c2d 47bba68 e067c2d 47bba68 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 |
import React from 'react';
import { useGridStore } from '../../store/gridStore';
import { Card, CardContent, CardHeader, CardTitle } from '../ui/card';
import { Button } from '../ui/button';
import {
X,
Truck,
Package,
Route,
Clock,
Activity,
HardDrive,
ArrowRight,
CheckCircle,
Eye,
EyeOff,
} from 'lucide-react';
// Colors matching the store
const PATH_COLORS = [
'#f97316', // orange
'#06b6d4', // cyan
'#ec4899', // pink
'#84cc16', // lime
'#a855f7', // purple
'#14b8a6', // teal
'#f43f5e', // rose
'#eab308', // yellow
'#6366f1', // indigo
'#22c55e', // green
];
interface PlanResultsModalProps {
isOpen: boolean;
onClose: () => void;
}
export const PlanResultsModal: React.FC<PlanResultsModalProps> = ({ isOpen, onClose }) => {
const { planResult, selectedAlgorithm, showPlanPaths, setShowPlanPaths } = useGridStore();
if (!isOpen || !planResult) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center">
{/* Backdrop */}
<div
className="absolute inset-0 bg-black/70 backdrop-blur-sm"
onClick={onClose}
/>
{/* Modal */}
<div className="relative bg-zinc-900 border border-zinc-800 rounded-xl shadow-2xl w-full max-w-3xl max-h-[85vh] overflow-hidden m-4">
{/* Header */}
<div className="flex items-center justify-between px-6 py-4 border-b border-zinc-800 bg-zinc-800/30">
<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>
<h2 className="text-sm font-semibold text-zinc-200">Delivery Plan Results</h2>
<p className="text-xs text-zinc-500">Algorithm: {selectedAlgorithm}</p>
</div>
</div>
<Button variant="ghost" size="icon" onClick={onClose}>
<X className="w-4 h-4" />
</Button>
</div>
{/* Content */}
<div className="overflow-y-auto max-h-[calc(85vh-140px)] p-6 space-y-4">
{/* Summary Stats */}
<div className="grid grid-cols-4 gap-3">
<Card>
<CardContent className="p-3">
<div className="flex items-center gap-2 text-zinc-500 text-xs mb-1">
<Route className="w-3.5 h-3.5" />
Total Cost
</div>
<p className="text-lg font-semibold text-zinc-200 font-mono">
{planResult.totalCost}
</p>
</CardContent>
</Card>
<Card>
<CardContent className="p-3">
<div className="flex items-center gap-2 text-zinc-500 text-xs mb-1">
<Activity className="w-3.5 h-3.5" />
Nodes Expanded
</div>
<p className="text-lg font-semibold text-zinc-200 font-mono">
{planResult.totalNodesExpanded.toLocaleString()}
</p>
</CardContent>
</Card>
<Card>
<CardContent className="p-3">
<div className="flex items-center gap-2 text-zinc-500 text-xs mb-1">
<Clock className="w-3.5 h-3.5" />
Runtime
</div>
<p className="text-lg font-semibold text-zinc-200 font-mono">
{planResult.runtimeMs.toFixed(2)}ms
</p>
</CardContent>
</Card>
<Card>
<CardContent className="p-3">
<div className="flex items-center gap-2 text-zinc-500 text-xs mb-1">
<HardDrive className="w-3.5 h-3.5" />
Memory
</div>
<p className="text-lg font-semibold text-zinc-200 font-mono">
{planResult.memoryKb.toFixed(2)}KB
</p>
</CardContent>
</Card>
</div>
{/* Plan Output */}
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-xs text-zinc-400 font-medium">Plan Output</CardTitle>
</CardHeader>
<CardContent>
<div className="bg-zinc-950 rounded-lg p-3 font-mono text-xs text-zinc-300 whitespace-pre-wrap overflow-x-auto">
{planResult.output || 'No output'}
</div>
</CardContent>
</Card>
{/* Assignments */}
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-xs text-zinc-400 font-medium flex items-center gap-2">
<Package className="w-3.5 h-3.5" />
Delivery Assignments ({planResult.assignments.length})
</CardTitle>
</CardHeader>
<CardContent className="space-y-2">
{planResult.assignments.length === 0 ? (
<p className="text-zinc-500 text-sm">No assignments made</p>
) : (
planResult.assignments.map((assignment, index) => {
const pathColor = PATH_COLORS[index % PATH_COLORS.length];
return (
<div
key={index}
className="bg-zinc-800/50 rounded-lg p-3 border border-zinc-800"
style={{ borderLeftWidth: 4, borderLeftColor: pathColor }}
>
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-3">
{/* Color indicator */}
<div
className="w-3 h-3 rounded-full"
style={{ backgroundColor: pathColor }}
/>
<div className="flex items-center gap-2">
<div className="w-6 h-6 rounded bg-blue-500/20 border border-blue-500/30 flex items-center justify-center">
<span className="text-xs font-mono text-blue-400">S{assignment.store_id}</span>
</div>
<ArrowRight className="w-4 h-4 text-zinc-600" />
<div className="w-6 h-6 rounded-full bg-emerald-500/20 border border-emerald-500/30 flex items-center justify-center">
<span className="text-xs font-mono text-emerald-400">D{assignment.destination_id}</span>
</div>
</div>
<CheckCircle className="w-4 h-4 text-emerald-500" />
</div>
<div className="flex items-center gap-4 text-xs text-zinc-500">
<span>Cost: <span className="text-zinc-300 font-mono">{assignment.path.cost}</span></span>
<span>Nodes: <span className="text-zinc-300 font-mono">{assignment.path.nodes_expanded}</span></span>
</div>
</div>
<div className="text-xs text-zinc-500">
<span className="text-zinc-600">Path: </span>
<span className="font-mono text-zinc-400">{assignment.path.plan || 'Direct'}</span>
</div>
</div>
);
})
)}
</CardContent>
</Card>
</div>
{/* Footer */}
<div className="px-6 py-3 border-t border-zinc-800 bg-zinc-800/20 flex justify-between">
<Button
variant={showPlanPaths ? 'primary' : 'outline'}
size="sm"
onClick={() => setShowPlanPaths(!showPlanPaths)}
className="gap-2"
>
{showPlanPaths ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}
{showPlanPaths ? 'Hide Paths on Grid' : 'Show Paths on Grid'}
</Button>
<Button variant="secondary" size="sm" onClick={onClose}>
Close
</Button>
</div>
</div>
</div>
);
};
export default PlanResultsModal;
|