import { Checkbox } from "@/components/ui/checkbox"
import { ColumnDef } from "@tanstack/react-table"
import { VendorPoolItem } from "./vendor-pool-table"

// Vendor Pool 테이블 컬럼
export const vendorPoolColumns: ColumnDef<VendorPoolItem>[] = [
    {
        id: "select",
        header: ({ table }) => (
            <Checkbox
                checked={
                    table.getIsAllPageRowsSelected() ||
                    (table.getIsSomePageRowsSelected() && "indeterminate")
                }
                onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
                aria-label="Select all"
            />
        ),
        cell: ({ row, table }) => {
            // Vendor Pool 테이블의 단일 선택 핸들러
            const handleRowSelection = (checked: boolean) => {
                if (checked) {
                    // 다른 모든 행의 선택 해제
                    table.getRowModel().rows.forEach(r => {
                        if (r !== row && r.getIsSelected()) {
                            r.toggleSelected(false)
                        }
                    })
                }
                // 현재 행 선택/해제
                row.toggleSelected(checked)
            }

            return (
                <Checkbox
                    checked={row.getIsSelected()}
                    onCheckedChange={handleRowSelection}
                    aria-label="Select row"
                />
            )
        },
        enableSorting: false,
        enableHiding: false,
        size: 50,
    },
    {
        accessorKey: "no",
        header: "No.",
        size: 60,
    },
    {
        accessorKey: "designCategory",
        header: "설계공종",
        size: 120,
    },
    {
        accessorKey: "avlVendorName",
        header: "AVL 등재업체명",
        size: 140,
    },
    {
        accessorKey: "materialGroupCode",
        header: "자재그룹코드",
        size: 130,
    },
    {
        accessorKey: "materialGroupName",
        header: "자재그룹명",
        size: 130,
    },
    {
        accessorKey: "vendorName",
        header: "협력업체 정보",
        size: 130,
    },
    {
        accessorKey: "tier",
        header: "업체분류",
        size: 100,
    },
    {
        accessorKey: "faStatus",
        header: "FA현황",
        size: 100,
    },
    {
        accessorKey: "recentQuoteNumber",
        header: "최근견적번호",
        size: 130,
    },
    {
        accessorKey: "recentOrderNumber",
        header: "최근발주번호",
        size: 130,
    },
]