"use client" import * as React from "react" import { useReactTable, getCoreRowModel, getPaginationRowModel, getSortedRowModel, getFilteredRowModel, type ColumnDef } from "@tanstack/react-table" import { DataTable } from "@/components/data-table/data-table" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { getStandardAvlVendorInfo } from "../service" import { GetStandardAvlSchema } from "../validations" import { AvlDetailItem } from "../types" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { Search } from "lucide-react" import { toast } from "sonner" // 검색 옵션들 const constructionSectorOptions = [ { value: "all", label: "전체" }, { value: "조선", label: "조선" }, { value: "해양", label: "해양" }, ] const shipTypeOptions = [ { value: "all", label: "전체" }, { value: "컨테이너선", label: "컨테이너선" }, { value: "유조선", label: "유조선" }, { value: "LNG선", label: "LNG선" }, { value: "LPG선", label: "LPG선" }, { value: "벌크선", label: "벌크선" }, { value: "여객선", label: "여객선" }, ] const avlKindOptions = [ { value: "all", label: "전체" }, { value: "표준", label: "표준" }, { value: "특별", label: "특별" }, { value: "임시", label: "임시" }, ] const htDivisionOptions = [ { value: "all", label: "전체" }, { value: "H", label: "Hull (H)" }, { value: "T", label: "Topside (T)" }, ] // 선종별 표준 AVL 테이블에서는 AvlDetailItem을 사용 export type StandardAvlItem = AvlDetailItem interface StandardAvlTableProps { onSelectionChange?: (count: number) => void resetCounter?: number constructionSector?: string // 공사부문 필터 shipType?: string // 선종 필터 avlKind?: string // AVL 종류 필터 htDivision?: string // H/T 구분 필터 } // 선종별 표준 AVL 테이블 컬럼 const standardAvlColumns: ColumnDef[] = [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" /> ), cell: ({ row, table }) => { // 선종별 표준 AVL 테이블의 단일 선택 핸들러 const handleRowSelection = (checked: boolean) => { if (checked) { // 다른 모든 행의 선택 해제 table.getRowModel().rows.forEach(r => { if (r !== row && r.getIsSelected()) { r.toggleSelected(false) } }) } // 현재 행 선택/해제 row.toggleSelected(checked) } return ( ) }, enableSorting: false, enableHiding: false, size: 50, }, { accessorKey: "no", header: "No.", size: 60, }, { accessorKey: "disciplineName", header: "설계공종", size: 120, }, { accessorKey: "avlVendorName", header: "AVL 등재업체명", size: 140, }, { accessorKey: "materialGroupCode", header: "자재그룹 코드", size: 120, }, { accessorKey: "materialGroupName", header: "자재그룹 명", size: 130, }, { accessorKey: "vendorCode", header: "협력업체 코드", size: 120, }, { accessorKey: "vendorName", header: "협력업체 명", size: 130, }, { accessorKey: "headquarterLocation", header: "본사 위치 (국가)", size: 140, }, { accessorKey: "tier", header: "등급 (Tier)", size: 120, }, ] export function StandardAvlTable({ onSelectionChange, resetCounter, constructionSector: initialConstructionSector, shipType: initialShipType, avlKind: initialAvlKind, htDivision: initialHtDivision }: StandardAvlTableProps) { const [data, setData] = React.useState([]) const [loading, setLoading] = React.useState(false) const [pageCount, setPageCount] = React.useState(0) // 검색 상태 const [searchConstructionSector, setSearchConstructionSector] = React.useState(initialConstructionSector || "all") const [searchShipType, setSearchShipType] = React.useState(initialShipType || "all") const [searchAvlKind, setSearchAvlKind] = React.useState(initialAvlKind || "all") const [searchHtDivision, setSearchHtDivision] = React.useState(initialHtDivision || "all") // 데이터 로드 함수 const loadData = React.useCallback(async (searchParams: Partial) => { try { setLoading(true) const params: GetStandardAvlSchema = { page: searchParams.page ?? 1, perPage: searchParams.perPage ?? 10, sort: searchParams.sort ?? [{ id: "no", desc: false }], constructionSector: searchConstructionSector === "all" ? "" : searchConstructionSector || "", shipType: searchShipType === "all" ? "" : searchShipType || "", avlKind: searchAvlKind === "all" ? "" : searchAvlKind || "", htDivision: searchHtDivision === "all" ? "" : searchHtDivision || "", search: "", ...searchParams, } const result = await getStandardAvlVendorInfo(params) setData(result.data) setPageCount(result.pageCount) } catch (error) { console.error("선종별 표준 AVL 데이터 로드 실패:", error) setData([]) setPageCount(0) } finally { setLoading(false) } }, [searchConstructionSector, searchShipType, searchAvlKind, searchHtDivision]) // 검색 핸들러 const handleSearch = React.useCallback(() => { loadData({}) }, [loadData]) // 검색 초기화 핸들러 const handleResetSearch = React.useCallback(() => { setSearchConstructionSector("all") setSearchShipType("all") setSearchAvlKind("all") setSearchHtDivision("all") loadData({}) }, [loadData]) // 초기 데이터 로드 React.useEffect(() => { loadData({}) }, [loadData]) const table = useReactTable({ data, columns: standardAvlColumns, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), manualPagination: true, pageCount, initialState: { pagination: { pageSize: 10, }, }, onPaginationChange: (updater) => { const newState = typeof updater === 'function' ? updater(table.getState().pagination) : updater loadData({ page: newState.pageIndex + 1, perPage: newState.pageSize, }) }, }) // 선택 상태 변경 시 콜백 호출 React.useEffect(() => { onSelectionChange?.(table.getFilteredSelectedRowModel().rows.length) }, [table.getFilteredSelectedRowModel().rows.length, onSelectionChange]) // 선택 해제 요청이 오면 모든 선택 해제 React.useEffect(() => { if (resetCounter && resetCounter > 0) { table.toggleAllPageRowsSelected(false) } }, [resetCounter, table]) return (

선종별 표준 AVL

{/* 검색 UI */}
{/* 공사부문 */}
{/* 선종 */}
{/* AVL종류 */}
{/* H/T */}
{/* 검색 버튼들 */}
) }