"use client";

import { ColumnDef } from "@tanstack/react-table";
import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header";
import { VendorPossibleMaterial } from "../vendor-possible-material-service";
import { formatDate } from "@/lib/utils";

// 확정정보 테이블 컬럼
export const confirmedMaterialsColumns: ColumnDef<VendorPossibleMaterial>[] = [
  {
    accessorKey: "vendorTypeNameEn",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="업체유형" />
    ),
    cell: ({ row }) => {
      const vendorTypeNameEn = row.getValue("vendorTypeNameEn") as string;
      return <span>{vendorTypeNameEn || "-"}</span>;
    },
  },
  {
    accessorKey: "itemCode",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="자재그룹" />
    ),
    cell: ({ row }) => {
      const itemCode = row.getValue("itemCode") as string;
      return <span className="font-mono">{itemCode || "-"}</span>;
    },
  },
  {
    accessorKey: "itemName",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="자재그룹명" />
    ),
    cell: ({ row }) => {
      const itemName = row.getValue("itemName") as string;
      return <span>{itemName || "-"}</span>;
    },
  },
  {
    accessorKey: "recentPoNo",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="최근 Po No." />
    ),
    cell: ({ row }) => {
      const recentPoNo = row.getValue("recentPoNo") as string;
      return <span className="font-mono">{recentPoNo || "-"}</span>;
    },
  },
  {
    accessorKey: "recentPoDate",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="최근 Po일" />
    ),
    cell: ({ row }) => {
      const date = row.getValue("recentPoDate") as Date;
      return <span>{date ? formatDate(date) : "-"}</span>;
    },
  },
  {
    accessorKey: "recentDeliveryDate",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="최근 납품일" />
    ),
    cell: ({ row }) => {
      const date = row.getValue("recentDeliveryDate") as Date;
      return <span>{date ? formatDate(date) : "-"}</span>;
    },
  },
  {
    accessorKey: "createdAt",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="등록일" />
    ),
    cell: ({ row }) => {
      const date = row.getValue("createdAt") as Date;
      return <span>{formatDate(date)}</span>;
    },
  },
  {
    accessorKey: "registerUserName",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="등록자명" />
    ),
    cell: ({ row }) => {
      const userName = row.getValue("registerUserName") as string;
      return <span>{userName || "-"}</span>;
    },
  },
  {
    accessorKey: "recentOrderDate",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="최근발주일" />
    ),
    cell: ({ row }) => {
      const date = row.getValue("recentOrderDate") as Date;
      return <span>{date ? formatDate(date) : "-"}</span>;
    },
  },
];

// 업체입력정보 테이블 컬럼
export const vendorInputMaterialsColumns: ColumnDef<VendorPossibleMaterial>[] = [
  {
    accessorKey: "vendorTypeNameEn",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="업체유형" />
    ),
    cell: ({ row }) => {
      const vendorTypeNameEn = row.getValue("vendorTypeNameEn") as string;
      return <span>{vendorTypeNameEn || "-"}</span>;
    },
  },
  {
    accessorKey: "itemCode",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="자재그룹" />
    ),
    cell: ({ row }) => {
      const itemCode = row.getValue("itemCode") as string;
      return <span className="font-mono">{itemCode || "-"}</span>;
    },
  },
  {
    accessorKey: "itemName",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="자재그룹명" />
    ),
    cell: ({ row }) => {
      const itemName = row.getValue("itemName") as string;
      return <span>{itemName || "-"}</span>;
    },
  },
  {
    accessorKey: "createdAt",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="등록일" />
    ),
    cell: ({ row }) => {
      const date = row.getValue("createdAt") as Date;
      return <span>{formatDate(date)}</span>;
    },
  },
  {
    accessorKey: "registerUserName",
    header: ({ column }) => (
      <DataTableColumnHeaderSimple column={column} title="등록자명" />
    ),
    cell: ({ row }) => {
      const userName = row.getValue("registerUserName") as string;
      return <span>{userName || "-"}</span>;
    },
  },
];
