import { useMemo } from 'react' import { type ColumnDef } from '@tanstack/react-table' import { useTranslation } from 'react-i18next' import { DataTableColumnHeader } from '@/components/data-table' import { GroupBadge } from '@/components/group-badge' import { StatusBadge } from '@/components/status-badge' import { formatDuration, formatResetPeriod } from '../lib' import type { PlanRecord } from '../types' import { DataTableRowActions } from './data-table-row-actions' export function useSubscriptionsColumns(): ColumnDef[] { const { t } = useTranslation() return useMemo( (): ColumnDef[] => [ { accessorFn: (row) => row.plan.id, id: 'id', meta: { label: 'ID', mobileHidden: true }, header: ({ column }) => ( ), cell: ({ row }) => ( #{row.original.plan.id} ), size: 60, }, { accessorFn: (row) => row.plan.title, id: 'title', meta: { label: t('Plan'), mobileTitle: true }, header: ({ column }) => ( ), cell: ({ row }) => { const plan = row.original.plan return (
{plan.title}
{plan.subtitle && (
{plan.subtitle}
)}
) }, size: 200, }, { accessorFn: (row) => row.plan.price_amount, id: 'price', meta: { label: t('Price') }, header: ({ column }) => ( ), cell: ({ row }) => ( ${Number(row.original.plan.price_amount || 0).toFixed(2)} ), size: 100, }, { id: 'duration', meta: { label: t('Validity') }, header: ({ column }) => ( ), cell: ({ row }) => ( {formatDuration(row.original.plan, t)} ), size: 100, }, { id: 'reset', meta: { label: t('Quota Reset'), mobileHidden: true }, header: ({ column }) => ( ), cell: ({ row }) => ( {formatResetPeriod(row.original.plan, t)} ), size: 80, }, { accessorFn: (row) => row.plan.sort_order, id: 'sort_order', meta: { label: t('Priority'), mobileHidden: true }, header: ({ column }) => ( ), cell: ({ row }) => ( {row.original.plan.sort_order} ), size: 80, }, { accessorFn: (row) => row.plan.enabled, id: 'enabled', meta: { label: t('Status'), mobileBadge: true }, header: ({ column }) => ( ), cell: ({ row }) => row.original.plan.enabled ? ( ) : ( ), size: 80, }, { id: 'payment', meta: { label: t('Payment Channel'), mobileHidden: true }, header: ({ column }) => ( ), cell: ({ row }) => { const plan = row.original.plan return (
{plan.stripe_price_id && ( )} {plan.creem_product_id && ( )}
) }, size: 140, }, { id: 'total_amount', meta: { label: t('Total Quota'), mobileHidden: true }, header: ({ column }) => ( ), cell: ({ row }) => { const total = Number(row.original.plan.total_amount || 0) return ( {total > 0 ? total : t('Unlimited')} ) }, size: 100, }, { id: 'upgrade_group', meta: { label: t('Upgrade Group'), mobileHidden: true }, header: ({ column }) => ( ), cell: ({ row }) => { const group = row.original.plan.upgrade_group if (!group) { return {t('No Upgrade')} } return }, size: 100, }, { id: 'actions', cell: ({ row }) => , size: 80, }, ], [t] ) }