import type { PropsWithChildren } from 'react';
import React from 'react';
import AccountingRunActionSection from 'src/components/accounting-run-list/accounting-run-action-section';
import SummaryLink from 'src/components/accounting-run-list/summary-link';
import type { GridTableColumnDefinition } from '@theorchard/suite-components';
import type { CellProps } from '@theorchard/suite-components/dist/esm/src/components/table/base/types';

export const AccountingRunsTableColumns = (areRunsComplete: boolean) => {
    const ACCOUNTING_RUN_LIST_COLUMNS: GridTableColumnDefinition<unknown>[] = [
        {
            name: 'contractCount',
            title: '# of Contracts',
            Cell: ({
                data: { id, contractCount },
            }: PropsWithChildren<CellProps<any>>) => (
                <>
                    {
                        <SummaryLink
                            accountingRunId={id}
                            contractCount={contractCount}
                        />
                    }
                </>
            ),
        },
        {
            name: 'name',
            title: 'Run Controller',
            Cell: ({ data: { name } }: PropsWithChildren<CellProps<any>>) => (
                <>{name}</>
            ),
        },
        {
            name: 'date',
            title: 'Date',
            Cell: ({ data: { date } }: PropsWithChildren<CellProps<any>>) => (
                <>{date}</>
            ),
        },
        {
            name: 'status',
            title: 'Status',
            Cell: ({ data: { status } }: PropsWithChildren<CellProps<any>>) => (
                <>{status}</>
            ),
        },
        {
            name: 'action',
            title: 'Actions',
            Cell: ({
                data: { id, status },
            }: PropsWithChildren<CellProps<any>>) => (
                <>
                    {areRunsComplete ? (
                        '-'
                    ) : (
                        <AccountingRunActionSection id={id} status={status} />
                    )}
                </>
            ),
        },
    ];
    return ACCOUNTING_RUN_LIST_COLUMNS;
};
