import { PrimaryTable } from "tdesign-react";

import type { HistoryResponse } from "../../shared/api";

import { HISTORY_COLUMNS } from "../constants/history-table-columns";

interface HistoryTabProps {
  historyData: HistoryResponse;
  historyLoading: boolean;
  onPageChange: (page: number) => void;
}

export function HistoryTab({ historyData, historyLoading, onPageChange }: HistoryTabProps) {
  return (
    <PrimaryTable
      columns={HISTORY_COLUMNS}
      data={historyData.items}
      disableDataPage
      loading={historyLoading}
      onPageChange={({ current }) => {
        if (current) onPageChange(current);
      }}
      pagination={{
        current: historyData.page,
        pageSize: historyData.pageSize,
        total: historyData.total,
      }}
      rowKey="timestamp"
    />
  );
}
