"use client"; import React, { useState, useMemo } from "react"; import { Check, ChevronsUpDown } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; import type { TableInfo } from "../pop-dashboard/utils/dataFetcher"; interface TableComboboxProps { tables: TableInfo[]; value: string; onSelect: (tableName: string) => void; placeholder?: string; } export function TableCombobox({ tables, value, onSelect, placeholder = "테이블을 선택하세요", }: TableComboboxProps) { const [open, setOpen] = useState(false); const [search, setSearch] = useState(""); const selectedLabel = useMemo(() => { const found = tables.find((t) => t.tableName === value); return found ? (found.displayName || found.tableName) : ""; }, [tables, value]); const filtered = useMemo(() => { if (!search) return tables; const q = search.toLowerCase(); return tables.filter( (t) => t.tableName.toLowerCase().includes(q) || (t.displayName && t.displayName.toLowerCase().includes(q)) ); }, [tables, search]); return ( 검색 결과가 없습니다. {filtered.map((table) => ( { onSelect(table.tableName); setOpen(false); setSearch(""); }} className="text-xs" >
{table.displayName || table.tableName} {table.displayName && ( {table.tableName} )}
))}
); }