import { createColumnHelper } from "@tanstack/react-table";

type ColumnConfig = {
  accessor: any;
  header: string;
  enableSorting?: boolean;
  cellRenderer?: (info: any) => JSX.Element;
};


export const createColumns = <T,>(columnConfigs: ColumnConfig[]) => {
  const columnHelper = createColumnHelper<T>();
  return columnConfigs.map(config =>
    columnHelper.accessor(config.accessor, {
      header: () => config.header,
      cell: (info) => config.cellRenderer ? config.cellRenderer(info) : info.getValue(),
      enableSorting: config.enableSorting ?? true,
    })
  );
};
