import { defineComponent as j, reactive as H, computed as x, ref as D, watch as z, openBlock as f, createElementBlock as v, normalizeClass as S, createElementVNode as m, toDisplayString as y, Fragment as K, renderList as R, createVNode as B, createCommentVNode as P, unref as $ } from "vue";
import { C as r } from "../Shared/base-PQGakkrl.js";
import { _ as U } from "../Shared/Index.vue_vue_type_script_setup_true_lang-DWw1B8Z2.js";
import { _ as q } from "../Shared/Index.vue_vue_type_script_setup_true_lang-_Zu2nb2q.js";
import { u as G } from "../Shared/language-DxTlvFs2.js";
const Q = { class: "paginate-statistic" }, W = { class: "paginate-list" }, X = { class: "pagination" }, Y = ["onClick"], Z = ["innerHTML"], ee = {
  key: 0,
  class: "paginate-limit"
}, te = {
  key: 1,
  class: "paginate-jump"
}, pe = /* @__PURE__ */ j({
  name: "ClPaginate",
  __name: "Index",
  props: {
    isShowLimit: {
      type: Boolean,
      default: !0
    },
    limitValue: {
      type: Number,
      default: 10
    },
    limitData: Array,
    isShowJump: {
      type: Boolean,
      default: !0
    },
    totalCount: {
      type: Number,
      default: 0
    },
    currentPage: {
      type: Number,
      default: 1
    },
    isDisabled: {
      type: Boolean,
      default: !1
    }
  },
  emits: ["onChange"],
  setup(c, { emit: E }) {
    const s = c, k = E, { optPageLanguage: u, getPageLanguage: N } = G();
    N("paginate");
    const w = H({
      keyIndex: `paginate-${r.getRandom(8)}`
    }), F = () => {
      let e = s.limitValue.toString();
      if (s.isShowLimit && _.value.length > 0) {
        let i = !1, t = "";
        _.value.forEach((l, a) => {
          const b = l.id.toString();
          a === 0 && (t = b), e === b && (i = !0);
        }), i || (e = t);
      }
      return e;
    }, _ = x(() => {
      const e = s.limitData;
      return e && !r.isEmpty(e) ? r.getListClone(e) : [
        { id: 10, name: `10${u.value.pageStrip}` },
        { id: 20, name: `20${u.value.pageStrip}` },
        { id: 30, name: `30${u.value.pageStrip}` },
        { id: 50, name: `50${u.value.pageStrip}` },
        { id: 100, name: `100${u.value.pageStrip}` }
      ];
    }), O = F(), p = D(O), h = D(""), V = x(() => {
      const e = parseInt(p.value), i = s.currentPage, t = s.totalCount;
      let l = (i - 1) * e, a = i * e;
      return t > 0 ? (l = l + 1, a = a > t ? t : a) : (l = 0, a = 0), r.convertStringFormat(u.value.statistic, { s: l, e: a, _total: t });
    }), A = x(() => {
      let e = !1, i = !1, t = !1, l = !1, a = 0;
      const b = parseInt(p.value), o = s.currentPage, I = s.totalCount;
      I > 0 && (a = Math.ceil(I / b), e = o === 1, i = e, t = o === a, l = t);
      const g = [];
      if (g.push({
        title: "<i class='clIconFont clIcon-angle-double-left paginate-first-icon'></i>",
        active: !1,
        disabled: e,
        page: 1
      }), g.push({
        title: "<i class='clIconFont clIcon-angle-left paginate-prev-icon'></i>",
        active: !1,
        disabled: i,
        page: e ? 1 : o - 1
      }), a > 0) {
        let n = [];
        if (a > 7) {
          const L = a - 5 + 1 + 1;
          o <= 4 ? (n = r.getArrByMinMax(1, 5), n.push("…"), n.push(a)) : o >= L ? (n = r.getArrByMinMax(L - 1, a), n.unshift("…"), n.unshift(1)) : (n = r.getArrByMinMax(o - 1, o + 1), n.unshift("…"), n.unshift(1), n.push("…"), n.push(a));
        } else
          n = r.getArrByMinMax(1, a);
        n.forEach((d) => {
          g.push({ title: d, active: d === o, isOmit: d === "…", page: d });
        });
      }
      return g.push({
        title: "<i class='clIconFont clIcon-angle-right paginate-next-icon'></i>",
        active: !1,
        disabled: l,
        page: t ? a : o + 1
      }), g.push({
        title: "<i class='clIconFont clIcon-angle-double-right paginate-last-icon'></i>",
        active: !1,
        disabled: t,
        page: a
      }), g;
    });
    z(
      () => s.limitValue,
      (e) => {
        p.value = e.toString();
      }
    );
    const C = (e, i) => {
      k("onChange", parseInt(e), parseInt(i));
    }, J = (e) => {
      s.isDisabled || !e.active && !e.disabled && !e.isOmit && (h.value = "", C(e.page, p.value));
    }, T = (e) => {
      s.isDisabled || (h.value = "", C(1, e));
    }, M = (e) => {
      !s.isDisabled && !r.isEmpty(e) && C(e, p.value);
    };
    return (e, i) => (f(), v("div", {
      class: S({ "panel-paginate": !0, "paginate-disabled": c.isDisabled })
    }, [
      m("div", Q, y(V.value), 1),
      m("div", W, [
        m("ul", X, [
          (f(!0), v(K, null, R(A.value, (t, l) => (f(), v("li", {
            key: `${w.keyIndex}_${l}`,
            class: S({ "paginate-disabled": t.disabled || c.isDisabled, "paginate-active": t.active, "paginate-omit": t.isOmit }),
            onClick: (a) => J(t)
          }, [
            m("span", {
              innerHTML: t.title
            }, null, 8, Z)
          ], 10, Y))), 128))
        ])
      ]),
      c.isShowLimit ? (f(), v("div", ee, [
        B(q, {
          list: _.value,
          value: p.value,
          disabled: c.isDisabled,
          onOnChange: T
        }, null, 8, ["list", "value", "disabled"])
      ])) : P("", !0),
      c.isShowJump ? (f(), v("div", te, [
        m("span", null, y($(u).jumpTo), 1),
        B(U, {
          value: h.value,
          "onUpdate:value": i[0] || (i[0] = (t) => h.value = t),
          disabled: c.isDisabled,
          onOnKeyupEnter: M,
          onOnChangeBlur: M,
          onOnClear: M
        }, null, 8, ["value", "disabled"]),
        m("span", null, y($(u).page), 1)
      ])) : P("", !0)
    ], 2));
  }
});
export {
  pe as default
};
//# sourceMappingURL=ClPaginate.js.map
