import { ColumnDef } from "@tanstack/react-table";
import { format } from "date-fns";

// This type is used to define the shape of our data.
// You can use a Zod schema here if you want.
export type Adjustmnets = {
    siloAdjust_id: string;
    currentStockLevel: string;
    newLevel: number;
    dateAdjusted: string;
    lastDateAdjusted: string;
    comment: string;
    commentAddedBy: string;
    commentDate: string;
    add_user: string;
};

export const columns: ColumnDef<Adjustmnets>[] = [
    {
        accessorKey: "currentStockLevel",
        header: () => <div className="text-right">Stock At Post</div>,
    },
    {
        accessorKey: "newLevel",
        header: "Level Entered",
    },
    {
        accessorKey: "dateAdjusted",
        header: "Adjustmnet",
        cell: ({ row }) => {
            if (row.getValue("dateAdjusted")) {
                const correctDate = format(
                    row.original.dateAdjusted?.replace("Z", ""),
                    "M/d/yyyy hh:mm"
                );
                return (
                    <div className="text-right font-medium">{correctDate}</div>
                );
            }
        },
    },
    {
        accessorKey: "lastDateAdjusted",
        header: "Last Adjusted",
        cell: ({ row }) => {
            if (row.getValue("lastDateAdjusted")) {
                const correctDate = format(
                    row.original.lastDateAdjusted?.replace("Z", ""),
                    "M/d/yyyy hh:mm"
                );
                return (
                    <div className="text-right font-medium">{correctDate}</div>
                );
            }
        },
    },
    {
        accessorKey: "comment",
        header: "Comment",
    },
    {
        accessorKey: "commentAddedBy",
        header: "Commenter ",
    },
    {
        accessorKey: "commentDate",
        header: "Comment Date ",
        cell: ({ row }) => {
            if (row.getValue("commentDate")) {
                const correctDate = format(
                    row.original.commentDate?.replace("Z", ""),
                    "M/d/yyyy hh:mm"
                );
                return (
                    <div className="text-right font-medium">{correctDate}</div>
                );
            }
        },
    },
    {
        accessorKey: "add_user",
        header: "Creator",
    },
];
