'use client';

import WithdrawAction from '@/components/withdraw/withdraw-action';
import { formatToCurrency } from '@/lib/utils';
import { Withdraw } from '@/types';
import { ColumnDef } from '@tanstack/react-table';

// This type is used to define the shape of our data.
// You can use a Zod schema here if you want.

export const withdrawsColumns: ColumnDef<Withdraw>[] = [
    {
        accessorKey: 'user.name',
        header: 'User Name',
    },
    {
        accessorKey: 'wallet_address',
        header: 'Address',
    },
    {
        accessorKey: 'amount',
        header: 'Amount (USDT)',
        cell: ({ row }) => <span>{formatToCurrency(Number(row.original.amount))}</span>,
    },
    {
        accessorKey: 'payment_method',
        header: 'Network Chain',
    },

    {
        accessorKey: 'status',
        header: 'Status',
        cell: ({ row }) => (
            <span
                className={`rounded-full px-2 py-1 text-xs font-medium capitalize ${
                    row.getValue('status') === 'completed'
                        ? 'bg-green-100 text-green-800'
                        : row.getValue('status') === 'pending'
                          ? 'bg-yellow-100 text-yellow-800'
                          : 'bg-red-100 text-red-800'
                }`}
            >
                {row.getValue('status')}
            </span>
        ),
    },
    {
        id: 'created_at',
        header: 'Created At',
        cell: ({ row }) => {
            const createdAt = row.original.created_at;
            console.log(createdAt);
            return <span>{new Date(createdAt as string).toLocaleDateString()}</span>;
        },
    },
    {
        id: 'actions',
        enableHiding: false,
        header: 'Actions',
        cell: ({ row }) => <WithdrawAction withdraw={row.original} />,
    },
];
