import { RequestUpdateMenu } from "@/components/request-update-menu"; import { SelectDialog } from "@/components/select-dialog"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { UploadDialog } from "@/components/upload-dialog"; import { VersionTable } from "@/components/version-table"; import type { ColumnDef } from "@tanstack/react-table"; import type { AxiosProgressEvent } from "axios"; import { FileText, Building2, Monitor } from "lucide-react"; import { useState } from "react"; interface BlackListManagerTemplateProps { title: string; description: string; data: TData[]; isLoading: boolean; columns: ColumnDef[]; onUpload: ( fd: FormData, config?: { onUploadProgress?: (e: AxiosProgressEvent) => void } ) => Promise; onUpdate?: (roomName: string) => void; updateLoading?: boolean; onTableInit?: (table: any) => void; rooms: string[]; devices?: string[]; } export function BlackListManagerTemplate({ title, description, data, isLoading, columns, onUpload, onUpdate, updateLoading, onTableInit, rooms = [], devices = [], }: BlackListManagerTemplateProps) { const [dialogOpen, setDialogOpen] = useState(false); const [dialogType, setDialogType] = useState<"room" | "device" | null>(null); const handleUpdateAll = () => { if (onUpdate) onUpdate("All"); }; const openRoomDialog = () => { if (rooms.length > 0 && onUpdate) { setDialogType("room"); setDialogOpen(true); } }; const openDeviceDialog = () => { if (devices.length > 0 && onUpdate) { setDialogType("device"); setDialogOpen(true); } }; const getDialogProps = () => { if (dialogType === "room") { return { title: "Chọn phòng", description: "Chọn các phòng cần cập nhật", icon: , items: rooms, }; } if (dialogType === "device") { return { title: "Chọn thiết bị", description: "Chọn các thiết bị cần cập nhật", icon: , items: devices, }; } return null; }; const dialogProps = getDialogProps(); return (
{/* Header */}

{title}

{description}

{/* Table */} Danh sách phần mềm bị chặn Các phần mềm không được cho phép trong hệ thống {/* Footer */} {onUpdate && ( )} {dialogProps && ( setDialogOpen(false)} title={dialogProps.title} description={dialogProps.description} icon={dialogProps.icon} items={dialogProps.items} onConfirm={async (selectedItems) => { if (!onUpdate) return; for (const item of selectedItems) { onUpdate(item); } setDialogOpen(false); }} /> )}
); }