'use client'; import { useMemo } from 'react'; import type { ColumnDef } from '@tanstack/react-table'; import { Badge } from '@/components/ui/badge'; import type { Plan } from '@/types'; function formatDate(value?: string | null) { if (!value) return '-'; return new Intl.DateTimeFormat('en-IN', { day: '2-digit', month: 'short', year: 'numeric', }).format(new Date(value)); } function formatPrice(value: string, cycle: string) { const amount = Number(value); const price = Number.isFinite(amount) ? amount.toFixed(2) : value; return `${price} / ${cycle}`; } export function usePlanColumns(): ColumnDef[] { return useMemo(() => { return [ { accessorKey: 'name', header: 'Plan', cell: ({ row }) => (

{row.original.name}

{row.original.slug}

), }, { accessorKey: 'price', header: 'Price', cell: ({ row }) => formatPrice(row.original.price, row.original.billing_cycle), }, { accessorKey: 'trial_days', header: 'Trial', cell: ({ row }) => `${row.original.trial_days} days`, }, { id: 'limits', header: 'Limits', enableSorting: false, cell: ({ row }) => (

{row.original.max_projects} projects

{row.original.max_users} users

), }, { accessorKey: 'created_at', header: 'Created', cell: ({ row }) => formatDate(row.original.created_at), }, { accessorKey: 'is_active', header: 'Status', cell: ({ row }) => (
{row.original.is_active ? 'Active' : 'Inactive'} {row.original.is_custom ? ( Custom ) : null}
), }, ]; }, []); }