import { ref, watch, reactive } from "vue";
import { IMeta } from "#/api";

/**
 * 判断是否加载下一页的hooks
 * TODO 还需要根据具体情况做调整
 */
const usePagination = () => {
  let meta = ref<Partial<IMeta>>({
    current_page: 0,
    per_page: 10,
    total: 0,
  });

  let loading = ref(false);
  let tablePageOptions = reactive({
    current: meta.value.current_page,
    pageSize: meta.value.per_page,
    total: meta.value.total,
  });

  watch(
    () => meta.value,
    () => {
      console.log("change page");
      tablePageOptions.current = meta.value.current_page;
      tablePageOptions.pageSize = meta.value.per_page;
      tablePageOptions.total = meta.value.total;
      loading.value = false;
      console.log(tablePageOptions)
    }
  );

  return { loading, meta, tablePageOptions };
};

export default usePagination;
