import React, { useCallback } from "react";
import { Pagination } from "@ttk/component";
import { useData, useActions, useCommit } from "@ttk/app-loader";

export default function (props) {
  const actions = useActions(props);
  const commit = useCommit();
  const { pageIndex, pageSize, recordCount } = useData([
    props,
    "searchParam",
    "pager",
  ]).toJS();
  async function onShowSizeChange(current, pageSize) {
    commit([props, "searchParam"], {
      type: "update_search_page",
      data: { pageSize },
    });
    await actions.tableData();
  }
  async function onChange(page, pageSize) {
    commit([props, "searchParam"], {
      type: "update_search_page",
      data: { pageIndex: page },
    });
    actions.tableData();
  }
  return (
    <div>
      <Pagination
        pageSize={pageSize}
        total={recordCount}
        current={pageIndex}
        pageSizeOptions={["20", "50", "100", "200", "300", "400"]}
        onChange={onChange}
        showSizeChanger
        onShowSizeChange={onShowSizeChange}
      />
    </div>
  );
}
