import { isUndefined as s } from "lodash-unified";
import { ref as g, watch as d, computed as l, unref as a } from "vue";
import "../../utils/index.mjs";
import { isDef as f } from "../../utils/is.mjs";
const C = (e) => {
  const i = g(
    e.pagination && e.pagination.defaultCurrent || 1
  ), o = g(
    e.pagination && e.pagination.defaultPageSize || 10
  );
  function u(t, n) {
    i.value = t, o.value = n;
  }
  d(
    () => e.dataSource,
    (t) => {
      if (!t?.length)
        return;
      const n = Math.max(
        Math.ceil(t.length / o.value),
        1
      );
      console.log(n, i.value), n < i.value && u(n, o.value);
    },
    { deep: 1 }
  );
  const h = l(() => e.dataSource ? e.pagination === !1 ? [...e.dataSource] : e.dataSource.slice(
    (a(i) - 1) * a(o),
    a(i) * a(o)
  ) : []);
  return {
    pagination: l(() => {
      const { showLessItems: t, showSizeChanger: n, showQuickJumper: r, pageSizeOptions: c } = e.pagination || {};
      return {
        current: a(i),
        pageSize: a(o),
        total: e.dataSource?.length || 0,
        showSizeChanger: f(n) ? n : !t,
        showQuickJumper: f(r) ? r : !t,
        showLessItems: t,
        size: "default",
        pageSizeOptions: s(c) ? ["10", "20", "50", "100"] : c
      };
    }),
    dataSource: h,
    onChange: u
  };
};
export {
  C as useOfflineList
};
