import TablePro from "@cqsjjb/jjb-react-admin-component/Table";
import { getIndexColumn } from "../../utils/index";
import "./index.less";

function Table(props) {
  const {
    columns = [],
    showIndexColumn = true,
    useAlignCenter = true,
    indexColumnFixed = "left",
    rowKey = "id",
    ...restProps
  } = props;
  function calcColumns() {
    showIndexColumn && columns.unshift({...getIndexColumn(props.pagination), fixed: indexColumnFixed});

    const setAlign = (column) => ({
      align: useAlignCenter ? "center" : "left",
      ...column,
      ...(column.children ? { children: column.children.map(setAlign) } : {})
    });

    return columns.map(setAlign);
  }
  return <TablePro rowKey={rowKey} columns={calcColumns()} bordered {...restProps} />;
}

export default Table;
