import type { ColumnDef } from '@tanstack/vue-table';
import type { Member } from './schema';
import DataTableColumnHeader from '@/components/custom/table/components/DataTableColumnHeader.vue';
import DataTableRowActions from '../components/DataTableRowActions.vue';
import { Checkbox } from '@/components/ui/checkbox';
import { formatBoolean, formatDate, renderImage } from '@/utils/formatters';
import { h } from 'vue';
import { Button } from '@/components/ui/button';
import { ChevronRight, ChevronDown } from 'lucide-vue-next';
export const columns: ColumnDef<Member>[] = [
{
id: 'select',
header: ({ table }) => h(Checkbox, {
'modelValue': table.getIsAllPageRowsSelected() || (table.getIsSomePageRowsSelected() && 'indeterminate'),
'onUpdate:modelValue': (value: boolean) => table.toggleAllPageRowsSelected(!!value),
'aria-label': 'Select all',
'class': 'translate-y-0.5'
}),
cell: ({ row }) => h(Checkbox, {
'modelValue': row.getIsSelected(),
'onUpdate:modelValue': (value: boolean) => row.toggleSelected(!!value),
'aria-label': 'Select row',
'class': 'translate-y-0.5'
}),
size: 50,
maxSize: 70,
headerStyle: 'width: 50px;max-width: 50px;',
enableSorting: false,
enableHiding: false
},
{
id: 'actions',
header: () => h('div', { class: 'text-center pr-2' }, 'Actions'),
cell: ({ row, table }) => h(DataTableRowActions, {
row,
onAddChild: () => table.options.meta?.onAddChild(row.original)
}),
enableSorting: false,
enableHiding: false,
size: 150,
maxSize: 150,
headerStyle: 'width: 125px;max-width: 125px;',
},
{
accessorKey: 'avatar',
header: () => '',
cell: ({ row }) => renderImage(row.getValue('avatar'), {}),
enableSorting: false,
enableColumnFilter: false,
},
{
accessorKey: 'name',
header: () => 'Name',
cell: ({ row }) => {
const canExpand = row.getCanExpand();
const isExpanded = row.getIsExpanded();
return h('div', {
class: 'flex items-center',
style: { paddingLeft: `${row.depth * 1.5}rem` } // Indentation
}, [
canExpand
? h(Button, {
variant: 'ghost',
size: 'sm',
class: 'p-1 h-7 w-7 mr-2',
onClick: row.getToggleExpandedHandler()
}, () => h(isExpanded ? ChevronDown : ChevronRight, { class: 'h-4 w-4' }))
: h('span', { class: 'w-7 mr-2' }), // Placeholder for alignment
h('span', { class: 'text-200 text-left' }, String(row.getValue('name') ?? '-')),
]);
},
enableSorting: false,
enableColumnFilter: false,
},
{
accessorKey: 'email',
header: () => 'Email',
cell: ({ row }) => h('span', { class: 'text-250 text-left' }, String(row.getValue('email') ?? '-')),
enableSorting: false,
enableColumnFilter: false,
},
// ... all other columns are the same
{
accessorKey: 'mobile',
header: () => 'Mobile',
cell: ({ row }) => h('span', { class: 'text-200 text-left' }, String(row.getValue('mobile') ?? '-')),
enableSorting: false,
enableColumnFilter: false,
},
{
accessorKey: 'updated_at',
header: ({ column }) => h(DataTableColumnHeader, { column, title: 'Updated' }),
cell: ({ row }) => formatDate(row.getValue('updated_at'), {}),
enableColumnFilter: false,
}
];