import { type ColumnDef } from "@tanstack/react-table"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { FileText, Building2, Monitor } from "lucide-react"; import { UploadDialog } from "@/components/upload-dialog"; import { VersionTable } from "@/components/version-table"; import { RequestUpdateMenu } from "@/components/request-update-menu"; import type { AxiosProgressEvent } from "axios"; import { useState } from "react"; import { SelectDialog } from "@/components/select-dialog"; // <-- dùng dialog chung interface AppManagerTemplateProps { title: string; description: string; data: TData[]; isLoading: boolean; columns: ColumnDef[]; onUpload: ( fd: FormData, config?: { onUploadProgress?: (e: AxiosProgressEvent) => void } ) => Promise; onUpdate?: (targetNames: string[]) => Promise | void; updateLoading?: boolean; onTableInit?: (table: any) => void; rooms?: string[]; devices?: string[]; } export function AppManagerTemplate({ title, description, data, isLoading, columns, onUpload, onUpdate, updateLoading, onTableInit, rooms = [], devices = [], }: AppManagerTemplateProps) { const [dialogOpen, setDialogOpen] = useState(false); const [dialogType, setDialogType] = useState<"room" | "device" | null>(null); const openRoomDialog = () => { if (rooms.length > 0 && onUpdate) { setDialogType("room"); setDialogOpen(true); } }; const openDeviceDialog = () => { if (devices.length > 0 && onUpdate) { setDialogType("device"); setDialogOpen(true); } }; const handleUpdateAll = async () => { if (!onUpdate) return; const allTargets = [...rooms, ...devices]; await onUpdate(allTargets); }; 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 */} Lịch sử phiên bản Tất cả các phiên bản đã tải lên {onUpdate && ( )} {/* 🧩 SelectDialog tái sử dụng */} {dialogProps && ( setDialogOpen(false)} title={dialogProps.title} description={dialogProps.description} icon={dialogProps.icon} items={dialogProps.items} onConfirm={async (selectedItems) => { if (!onUpdate) return; await onUpdate(selectedItems); setDialogOpen(false); }} /> )}
); }