import type { ReactNode } from "react";
import { BlockTableBody } from "../components/tableBody";
import { BlockTableCaption } from "../components/tableCaption";
import { BlockTableFoot } from "../components/tableFoot";
import { BlockTableHead } from "../components/tableHead";
import type { IBlockTableItem } from "../config/types";

/**
 * Возвращает компонент таблицы
 * @returns
 */
export const getTableItem = ({
  type = "tbody", key, html = "", rows = [], extraClasses = {}, extraAttrs = {},
}: IBlockTableItem): ReactNode => {
  const computedProps = {
    html, rows, extraClasses, extraAttrs,
  };
  switch (type) {
    case "caption":
      return <BlockTableCaption key={key} {...computedProps} />;
    case "thead":
      return <BlockTableHead key={key} {...computedProps} />;
    case "tfoot":
      return <BlockTableFoot key={key} {...computedProps} />;
    default:
      return <BlockTableBody key={key} {...computedProps} />;
  }
};
