import { defineComponent as T, ref as C, reactive as I, computed as S, onMounted as y, nextTick as d, openBlock as R, createElementBlock as w, mergeProps as F, renderSlot as U } from "vue";
import { C as i } from "../Shared/base-PQGakkrl.js";
import { C as h, a as k } from "../Shared/index-BnerInzC.js";
import "js-cookie";
import "decimal.js";
class b {
  startTime;
  startPos;
  endPos;
  duration;
  runEasing;
  runIngFun;
  lastPos;
  lastInterval;
  timeAnimate;
  constructor(n) {
    this.startTime = 0, this.startPos = 0, this.endPos = 0, this.duration = 0, this.runEasing = null, this.runIngFun = n.runIngCallback, this.lastPos = 0, this.lastInterval = 0;
  }
  _easing = {
    /**
     * t:动画已经消耗的时间
     * b:初始位置
     * c:目标位置
     * d:动画持续的总时间
    */
    linear: (n, e, r, l) => r * n / l + e,
    easeInCubic: (n, e, r, l) => r * (n /= l) * n * n + e,
    // eslint-disable-line
    easeOutCubic: (n, e, r, l) => r * ((n = n / l - 1) * n * n + 1) + e
    // eslint-disable-line
  };
  start(n, e, r, l = "linear") {
    const a = this;
    return new Promise((m) => {
      this.startTime = +/* @__PURE__ */ new Date(), this.startPos = n, this.endPos = e, this.duration = r, this.runEasing = a._easing[l], a.timeAnimate = i.requestAnimationFrame(function f() {
        a.step() === !1 ? (a.stop(), m(a.lastInterval)) : a.timeAnimate = i.requestAnimationFrame(f);
      });
    });
  }
  step() {
    const n = +/* @__PURE__ */ new Date();
    if (n >= this.startTime + this.duration)
      return this.runIngFun(this.endPos), !1;
    const e = this.runEasing(n - this.startTime, this.startPos, this.endPos - this.startPos, this.duration);
    return this.lastInterval = Math.abs(e - this.lastPos), this.lastPos = e, this.runIngFun(e), !0;
  }
  stop() {
    this.timeAnimate && i.cancelAnimationFrame(this.timeAnimate);
  }
}
const L = /* @__PURE__ */ T({
  name: "ClForm",
  __name: "Index",
  props: {
    theme: {},
    className: {},
    isAwaitRun: { type: Boolean },
    preScroll: {},
    pElError: {},
    isScrollToErr: { type: Boolean }
  },
  setup(E, { expose: n }) {
    const e = E, r = C(null), l = I({ isRun: !e.isAwaitRun }), a = {
      _scrollUpAnimate: null,
      parentScroll: null,
      isScrollWindow: !0
    }, m = S(() => {
      const t = {
        "data-cl-validate": ""
      };
      return l.isRun && (t["data-run"] = ""), i.isEmpty(e.theme) || (t["data-theme"] = e.theme), t;
    }), f = S(() => {
      const t = {
        "panel-form": !0,
        "form-validate": !0
      };
      return e.className && !i.isEmpty(e.className) && e.className.split(" ").forEach((s) => {
        i.isEmpty(s) || (t[s] = !0);
      }), t;
    }), p = (t) => {
      let s = !0;
      return l.isRun && !i.isUndefined(t) && r.value?.contains(t) && t.runValidate && (s = t.runValidate()), s;
    }, A = () => {
      const t = r.value?.querySelectorAll("[data-validate-error]");
      if (!i.isUndefined(t) && t.length && t.length > 0) {
        let s = t[0];
        const { preScroll: o, pElError: c } = e, u = !i.isEmpty(s.pElError), g = !i.isEmpty(c);
        if (u || g) {
          const P = h.getParent(s, u ? s.pElError : c, r.value);
          i.isUndefined(P) || (s = P);
        }
        let v = h.getOffset(s, a.isScrollWindow ? null : a.parentScroll).top - 10;
        o && !i.isUndefined(o) && (v -= o), a._scrollUpAnimate.start(a.parentScroll.scrollTop, v, 200);
      }
    }, _ = () => {
      const t = h.getParentScrollList(r.value, null, !1);
      a.isScrollWindow = t.length === 0, a.parentScroll = a.isScrollWindow ? document.documentElement : t[0].children[0], a._scrollUpAnimate = new b({
        runIngCallback: (s) => {
          a.parentScroll.scrollTop = s;
        }
      });
    };
    return y(() => {
      d(() => {
        _();
      });
    }), n({
      validate: (t) => k.promiseFun((s) => {
        let o = !0;
        i.isUndefined(t) ? (l.isRun = !0, d(() => {
          const c = r.value?.querySelectorAll("[data-validate-el]");
          !i.isUndefined(c) && c.length && c.length > 0 && c.forEach((u) => {
            p(u) || (o = !1);
          }), o || e.isScrollToErr && d(() => {
            A();
          }), s(o);
        })) : (o = p(t), s(o));
      }),
      reset: () => {
        l.isRun = !1, r.value?.removeAttribute("data-run");
        const t = r.value?.querySelectorAll("[data-validate-el]");
        !i.isUndefined(t) && t.length && t.length > 0 && t.forEach((s) => {
          s.runReset && s.runReset();
        });
      }
    }), (t, s) => (R(), w("form", F({
      ref_key: "refElTop",
      ref: r,
      autocomplete: "off",
      class: f.value
    }, m.value), [
      U(t.$slots, "default")
    ], 16));
  }
});
export {
  L as default
};
//# sourceMappingURL=ClForm.js.map
