"use client";

import { ColumnDef } from "@tanstack/react-table";
import { DwgReceiptItem } from "../actions";
import { formatDolceDateYYYYMMDD, formatDolceDateTime } from "../utils/date-formatter";

export function drawingListColumns(lng: string, t: any): ColumnDef<DwgReceiptItem>[] {
  return [
    {
      accessorKey: "DrawingNo",
      header: t("drawingList.columns.drawingNo"),
      minSize: 200,
      cell: ({ row }) => {
        return <div className="font-medium">{row.getValue("DrawingNo")}</div>;
      },
    },
    {
      accessorKey: "RegisterGroupId",
      header: "RegisterGroupId",
      minSize: 150,
    },
    {
      accessorKey: "DrawingName",
      header: t("drawingList.columns.drawingName"),
      minSize: 600,
      cell: ({ row }) => {
        return <div>{row.getValue("DrawingName")}</div>;
      },
    },
    {
      accessorKey: "Discipline",
      header: t("drawingList.columns.discipline"),
      minSize: 120,
    },
    {
      accessorKey: "Manager",
      header: t("drawingList.columns.manager"),
      minSize: 200,
      cell: ({ row }) => {
        const managerENM = row.original.ManagerENM;
        const manager = row.getValue("Manager");
        return <div>{managerENM || manager}</div>;
      },
    },
    {
      accessorKey: "AppDwg_PlanDate",
      header: t("drawingList.columns.appDwgPlanDate"),
      minSize: 140,
      cell: ({ row }) => {
        const date = row.getValue("AppDwg_PlanDate") as string;
        return formatDolceDateYYYYMMDD(date);
      },
    },
    {
      accessorKey: "AppDwg_ResultDate",
      header: t("drawingList.columns.appDwgResultDate"),
      minSize: 140,
      cell: ({ row }) => {
        const date = row.getValue("AppDwg_ResultDate") as string;
        return formatDolceDateYYYYMMDD(date);
      },
    },
    {
      accessorKey: "WorDwg_PlanDate",
      header: t("drawingList.columns.worDwgPlanDate"),
      minSize: 140,
      cell: ({ row }) => {
        const date = row.getValue("WorDwg_PlanDate") as string;
        return formatDolceDateYYYYMMDD(date);
      },
    },
    {
      accessorKey: "WorDwg_ResultDate",
      header: t("drawingList.columns.worDwgResultDate"),
      minSize: 140,
      cell: ({ row }) => {
        const date = row.getValue("WorDwg_ResultDate") as string;
        return formatDolceDateYYYYMMDD(date);
      },
    },
    {
      accessorKey: "CreateDt",
      header: t("drawingList.columns.createDt"),
      minSize: 260,
      cell: ({ row }) => {
        const date = row.getValue("CreateDt") as string;
        return <div className="text-sm text-muted-foreground">{formatDolceDateTime(date)}</div>;
      },
    },
  ];
}

