"use client"
import { useState } from "react"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { Input } from "@/components/ui/input"
import { Edit, ExternalLink, MoreHorizontal, Search, RefreshCw } from "lucide-react"
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
interface DataSource {
id: string
name: string
type: "api" | "file" | "database" | "third-party"
status: "active" | "inactive" | "error" | "pending"
lastSync: Date | null
recordCount: number
createdAt: Date
}
export function DataSourceList() {
const [searchQuery, setSearchQuery] = useState("")
// 模拟数据
const dataSources: DataSource[] = [
{
id: "1",
name: "CRM系统用户数据",
type: "api",
status: "active",
lastSync: new Date(2023, 6, 15, 14, 30),
recordCount: 45892,
createdAt: new Date(2023, 3, 10),
},
{
id: "2",
name: "电商平台订单数据",
type: "api",
status: "active",
lastSync: new Date(2023, 6, 15, 10, 15),
recordCount: 128456,
createdAt: new Date(2023, 2, 5),
},
{
id: "3",
name: "营销活动参与用户",
type: "file",
status: "active",
lastSync: new Date(2023, 6, 14, 9, 45),
recordCount: 8754,
createdAt: new Date(2023, 5, 20),
},
{
id: "4",
name: "APP用户行为数据",
type: "api",
status: "error",
lastSync: new Date(2023, 6, 10, 16, 20),
recordCount: 65432,
createdAt: new Date(2023, 1, 15),
},
{
id: "5",
name: "社交媒体用户数据",
type: "third-party",
status: "active",
lastSync: new Date(2023, 6, 15, 8, 0),
recordCount: 32145,
createdAt: new Date(2023, 4, 25),
},
]
// 过滤数据源
const filteredDataSources = dataSources.filter(
(source) =>
source.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
source.type.toLowerCase().includes(searchQuery.toLowerCase()),
)
const formatDate = (date: Date | null) => {
if (!date) return "从未同步"
return date.toLocaleString("zh-CN", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
})
}
const getStatusBadge = (status: DataSource["status"]) => {
switch (status) {
case "active":
return