import type { ColumnDef } from '@tanstack/vue-table';
import { h } from 'vue';
import { DataTableColumnHeader } from '@/components/data-table';
import MediaThumbnailCell from '@/components/media/MediaThumbnailCell.vue';
import type { ExpenseListItem } from '@/types/expense';
import DataTableActions from './data-table-actions.vue';

export function createColumns(onEdit: (expense: ExpenseListItem) => void): ColumnDef<ExpenseListItem>[] {
    return [
        {
            accessorKey: 'created_at_formatted',
            enableSorting: true,
            header: () => h(DataTableColumnHeader, { title: 'Tanggal', column: 'created_at' }),
        },
        {
            accessorKey: 'amount_formatted',
            enableSorting: true,
            header: () => h(DataTableColumnHeader, { title: 'Jumlah', column: 'amount' }),
        },
        {
            accessorKey: 'description',
            enableSorting: true,
            header: () => h(DataTableColumnHeader, { title: 'Keterangan', column: 'description' }),
        },
        {
            id: 'photos',
            enableSorting: false,
            header: () => 'Foto',
            cell: ({ row }) => h(MediaThumbnailCell, { items: row.original.photos ?? [] }),
        },
        {
            accessorKey: 'created_by_name',
            enableSorting: false,
            header: () => 'Oleh',
        },
        {
            id: 'actions',
            enableSorting: false,
            enableHiding: false,
            cell: ({ row }) => h(DataTableActions, {
                expense: row.original,
                onEdit: () => onEdit(row.original),
            }),
        },
    ];
}
