import { ColumnDef } from "@tanstack/react-table";
import { RecordTag } from "@/user-management/dto/recordTags/recordTags.type";
import { format } from "date-fns";
import { t } from "i18next";
import RecordTagActionsCell from "./RecordTagActionsCell";

import { useLocalizedName } from "@/shared/common/localizedName";

export const RecordTagColumnDefn = (unitId: string): ColumnDef<RecordTag>[] => {
  return [
    {
      accessorKey: "name",
      header: () => t("recordTag.name"),
      cell: ({ row }) => {
        const localizedName = useLocalizedName();
        const name = row.original?.name;
        return <span>{localizedName(name)}</span>;
      },
    },
    {
      accessorKey: "key",
      header: () => t("recordTag.key"),
      cell: ({ row }) => {
        const key = row.original?.key;
        return <span>{key || "--"}</span>;
      },
    },
    {
      accessorKey: "createdAt",
      header: () => t("recordTag.CreatedAt"),
      cell: ({ row }) => {
        const date = row.original?.createdAt;
        return (
          <span>
            {date ? format(new Date(date), "MMM d, yyyy HH:mm") : "--"}
          </span>
        );
      },
    },
    {
      id: "actions",
      header: () => t("recordTag.Actions"),
      cell: ({ row }) => (
        <RecordTagActionsCell row={row.original} unitId={unitId} />
      ),
    },
  ];
};
