import React from 'react';
import { formatDate, formatNumber } from '@theorchard/suite-i18n';
import { set } from '@theorchard/suite-utils';
import type { ColumnTemplates } from './types';

export const TableColumnTemplates: ColumnTemplates = {
    number: {
        align: 'right',
        maxWidth: 'max-content',
        minWidth: 'min-content',
        sortNullsLast: true,
        defaultSortDirection: 'desc',
        Cell: ({ value }) => <>{formatNumber(value)}</>,
        className: 'util-tabular-nums',
    },
    date: {
        maxWidth: 'max-content',
        minWidth: 'min-content',
        Cell: ({ value }) => <>{formatDate(value)}</>,
    },
};

export function defineColumnTemplate<Name extends keyof ColumnTemplates>(
    name: Name,
    template: ColumnTemplates[Name]
) {
    set(TableColumnTemplates, name, template);
}
