TTMT.ManageWebGUI/src/components/grids/device-grid.tsx

65 lines
2.3 KiB
TypeScript
Raw Normal View History

2025-10-20 16:46:17 +07:00
import { Monitor, DoorOpen } from "lucide-react";
2025-11-19 14:55:14 +07:00
import { ComputerCard } from "../cards/computer-card";
import { useMachineNumber } from "../../hooks/useMachineNumber";
2025-10-20 16:46:17 +07:00
export function DeviceGrid({ devices }: { devices: any[] }) {
const getMachineNumber = useMachineNumber();
const deviceMap = new Map<number, any>();
devices.forEach((device) => {
const number = getMachineNumber(device.id || "");
if (number > 0 && number <= 40) deviceMap.set(number, device);
});
const totalRows = 5;
const renderRow = (rowIndex: number) => {
2025-11-19 14:55:14 +07:00
// Đảo ngược: 21-40 sang trái, 1-20 sang phải
const leftStart = 21 + (totalRows - 1 - rowIndex) * 4;
const rightStart = (totalRows - 1 - rowIndex) * 4 + 1;
2025-10-31 16:52:56 +07:00
2025-10-20 16:46:17 +07:00
return (
<div key={rowIndex} className="flex items-center justify-center gap-3">
2025-11-19 14:55:14 +07:00
{/* Bên trái (2140) */}
2025-10-20 16:46:17 +07:00
{Array.from({ length: 4 }).map((_, i) => {
2025-11-19 14:55:14 +07:00
const pos = leftStart + (3 - i);
2025-10-31 16:52:56 +07:00
return (
<ComputerCard key={pos} device={deviceMap.get(pos)} position={pos} />
);
2025-10-20 16:46:17 +07:00
})}
2025-10-31 16:52:56 +07:00
{/* Đường chia giữa */}
2025-10-20 16:46:17 +07:00
<div className="w-32 flex items-center justify-center">
<div className="h-px w-full bg-border border-t-2 border-dashed" />
</div>
2025-10-31 16:52:56 +07:00
2025-11-19 14:55:14 +07:00
{/* Bên phải (120) */}
2025-10-20 16:46:17 +07:00
{Array.from({ length: 4 }).map((_, i) => {
2025-11-19 14:55:14 +07:00
const pos = rightStart + (3 - i);
2025-10-31 16:52:56 +07:00
return (
<ComputerCard key={pos} device={deviceMap.get(pos)} position={pos} />
);
2025-10-20 16:46:17 +07:00
})}
</div>
);
};
return (
<div className="px-0.5 py-8 space-y-6">
<div className="flex items-center justify-between px-4 pb-6 border-b-2 border-dashed">
<div className="flex items-center gap-3 px-6 py-4 bg-muted rounded-lg border-2 border-border">
<DoorOpen className="h-6 w-6 text-muted-foreground" />
<span className="font-semibold text-lg">Cửa Ra Vào</span>
</div>
2025-11-19 14:55:14 +07:00
<div className="flex items-center gap-3 px-6 py-4 bg-primary/10 rounded-lg border-2 border-primary/20">
<Monitor className="h-6 w-6 text-primary" />
<span className="font-semibold text-lg">Bàn Giảng Viên</span>
</div>
2025-10-20 16:46:17 +07:00
</div>
<div className="space-y-4">
{Array.from({ length: totalRows }).map((_, i) => renderRow(i))}
</div>
</div>
);
}