"use client";

import { ColumnDef } from "@tanstack/react-table";
import { DwgReceiptItem } from "../actions";

export const drawingListColumns: ColumnDef<DwgReceiptItem>[] = [
  {
    accessorKey: "DrawingNo",
    header: "도면번호",
    minSize: 200,
    cell: ({ row }) => {
      return <div className="font-medium">{row.getValue("DrawingNo")}</div>;
    },
  },
  {
    accessorKey: "DrawingName",
    header: "도면명",
    minSize: 400,
    cell: ({ row }) => {
      return <div>{row.getValue("DrawingName")}</div>;
    },
  },
  {
    accessorKey: "Discipline",
    header: "설계공종",
    minSize: 80,
  },
  {
    accessorKey: "Manager",
    header: "담당자명",
    minSize: 200,
    cell: ({ row }) => {
      const managerENM = row.original.ManagerENM;
      const manager = row.getValue("Manager");
      return <div>{managerENM || manager}</div>;
    },
  },
  {
    accessorKey: "AppDwg_PlanDate",
    header: "승인도면 예정일",
    minSize: 140,
    cell: ({ row }) => {
      const date = row.getValue("AppDwg_PlanDate") as string;
      if (!date || date.length !== 8) return null;
      return `${date.substring(0, 4)}-${date.substring(4, 6)}-${date.substring(6, 8)}`;
    },
  },
  {
    accessorKey: "AppDwg_ResultDate",
    header: "승인도면 결과일",
    minSize: 140,
    cell: ({ row }) => {
      const date = row.getValue("AppDwg_ResultDate") as string;
      if (!date || date.length !== 8) return null;
      return `${date.substring(0, 4)}-${date.substring(4, 6)}-${date.substring(6, 8)}`;
    },
  },
  {
    accessorKey: "WorDwg_PlanDate",
    header: "작업도면 예정일",
    minSize: 140,
    cell: ({ row }) => {
      const date = row.getValue("WorDwg_PlanDate") as string;
      if (!date || date.length !== 8) return null;
      return `${date.substring(0, 4)}-${date.substring(4, 6)}-${date.substring(6, 8)}`;
    },
  },
  {
    accessorKey: "WorDwg_ResultDate",
    header: "작업도면 결과일",
    minSize: 140,
    cell: ({ row }) => {
      const date = row.getValue("WorDwg_ResultDate") as string;
      if (!date || date.length !== 8) return null;
      return `${date.substring(0, 4)}-${date.substring(4, 6)}-${date.substring(6, 8)}`;
    },
  },
  {
    accessorKey: "CreateDt",
    header: "생성일시",
    minSize: 200,
    cell: ({ row }) => {
      return <div className="text-sm text-muted-foreground">{row.getValue("CreateDt")}</div>;
    },
  },
];

