import { defineComponent as x, ref as B, reactive as N, computed as m, onMounted as b, nextTick as K, resolveComponent as M, openBlock as l, createElementBlock as u, normalizeClass as f, createVNode as T, createElementVNode as V, Fragment as D, toDisplayString as F, withModifiers as C } from "vue";
import { C as i } from "../Shared/base-PQGakkrl.js";
import { _ as O } from "../Shared/Index.vue_vue_type_script_setup_true_lang-DWw1B8Z2.js";
const $ = {
  key: 0,
  class: "inputCaptcha-count"
}, j = /* @__PURE__ */ x({
  name: "ClInputCaptcha",
  components: {
    ClInput: O
  },
  __name: "Index",
  props: {
    value: {},
    className: {},
    theme: {},
    placeholder: {},
    countdownMax: {},
    onSendBefore: { type: Function }
  },
  emits: ["update:value", "onChange", "onKeyupEnter", "onSend"],
  setup(p, { expose: h, emit: v }) {
    const o = p, c = v, w = B(null), e = N({
      value: "",
      isSend: !1,
      isCountdown: !1,
      countdown: o.countdownMax || 120
    }), r = {
      intervalCountdownId: null
    }, _ = m(() => {
      const n = {
        "panel-input-captcha": !0,
        "box-width": !0
      };
      return o.className && !i.isEmpty(o.className) && o.className.split(" ").forEach((t) => {
        i.isEmpty(t) || (n[t] = !0);
      }), n[`inputCaptcha-theme-${o.theme || "default"}`] = !0, n;
    }), y = m(() => ({
      "inputCaptcha-send": !0,
      "inputCaptcha-send-ing": e.isCountdown
    })), S = (n) => {
      c("update:value", n), c("onChange", n);
    }, E = () => {
      c("onKeyupEnter", e.value);
    }, g = () => {
      c("onSend");
    };
    b(() => {
      K(() => {
      });
    });
    const k = (n) => {
      S(n);
    }, I = () => {
      E();
    }, d = () => {
      const { countdownMax: n = 120 } = o;
      let t = e.countdown;
      if (t === n) {
        let a = !1;
        o.onSendBefore && (a = o.onSendBefore(), a = i.isBoolean(a) ? a : !1), e.isSend = a, a && (g(), t = n, e.isCountdown = !0, e.countdown = t, r.intervalCountdownId = setInterval(() => {
          t -= 1;
          let s = !1;
          t <= 0 ? (clearInterval(r.intervalCountdownId), t = n, s = !1) : s = !0, e.countdown = t, e.isCountdown = s;
        }, 1e3));
      }
    };
    return h({
      getValue: () => i.trim(e.value)
    }), (n, t) => {
      const a = M("cl-input");
      return l(), u("div", {
        class: f(_.value)
      }, [
        T(a, {
          ref_key: "refElInput",
          ref: w,
          theme: "bottomLine",
          isNumber: !0,
          decimal: 0,
          isThousand: !1,
          value: e.value,
          "onUpdate:value": t[0] || (t[0] = (s) => e.value = s),
          placeholder: p.placeholder,
          isClean: !0,
          onOnKeyupEnter: I,
          onOnChange: k
        }, null, 8, ["value", "placeholder"]),
        V("div", {
          class: f(y.value)
        }, [
          e.isSend ? (l(), u(D, { key: 0 }, [
            e.isCountdown ? (l(), u("span", $, F(e.countdown) + "秒后重发", 1)) : (l(), u("span", {
              key: 1,
              class: "inputCaptcha-btn",
              onClick: C(d, ["stop"])
            }, "重新发送"))
          ], 64)) : (l(), u("span", {
            key: 1,
            class: "inputCaptcha-btn",
            onClick: C(d, ["stop"])
          }, "发送验证码"))
        ], 2)
      ], 2);
    };
  }
});
export {
  j as default
};
//# sourceMappingURL=ClInputCaptcha.js.map
