"use client"

import * as React from "react"
import { type ColumnDef } from "@tanstack/react-table"

import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header"

// MaterialGroup 타입 정의 (서비스에서 반환되는 타입과 일치)
type MaterialGroup = {
  materialGroupCode: string | null;
  materialName: string | null;
  displayText: string | null;
}

/**
 * MaterialGroup 테이블 컬럼 정의
 */
export function getColumns(): ColumnDef<MaterialGroup>[] {
  // ----------------------------------------------------------------
  // 데이터 컬럼들
  // ----------------------------------------------------------------
  const dataColumns: ColumnDef<MaterialGroup>[] = [
    {
      accessorKey: "materialGroupCode",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="자재그룹코드" />
      ),
      cell: ({ row }) => {
        const value = row.getValue("materialGroupCode") as string | null
        return (
          <div className="font-medium">
            {value || "-"}
          </div>
        )
      },
      enableSorting: true,
      enableHiding: false,
    },
    {
      accessorKey: "materialName",
      header: ({ column }) => (
        <DataTableColumnHeaderSimple column={column} title="자재그룹명" />
      ),
      cell: ({ row }) => {
        const value = row.getValue("materialName") as string | null
        return (
          <div className="max-w-[300px] truncate">
            {value || "-"}
          </div>
        )
      },
      enableSorting: true,
      enableHiding: false,
    },
  ]

  // ----------------------------------------------------------------
  // 최종 컬럼 배열
  // ----------------------------------------------------------------
  return dataColumns
}
