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