import { defineComponent as _, useSlots as h, shallowRef as p, getCurrentInstance as B, computed as v, onMounted as x, openBlock as i, createBlock as w, unref as u, mergeProps as y, withCtx as g, createElementBlock as S, renderSlot as m, createTextVNode as $, createCommentVNode as E, createElementVNode as b, toDisplayString as M } from "vue";
import { ElButton as V, ElSpace as P } from "element-plus";
import { wetCountDownButtonProps as R } from "./types.mjs";
const W = { key: 0 }, j = { key: 0 }, F = /* @__PURE__ */ _({
  name: "WetCountDownButton",
  __name: "index",
  props: R,
  emits: ["click"],
  setup(k, { emit: C }) {
    const I = C, o = k, T = h(), s = p(!1), l = p(o.initCount), r = B(), n = v(() => o.uid || (r == null ? void 0 : r.uid) || (/* @__PURE__ */ new Date()).getTime()), D = v(() => o.disabled || s.value);
    let d;
    const c = (e = !0) => {
      e && I("click"), s.value = !0;
      const t = sessionStorage.getItem(`wet-deadlinetime-${n.value}`);
      let a = t ? Number(t) : 0;
      const f = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
      a || (a = f + o.initCount, sessionStorage.setItem(`wet-deadlinetime-${n.value}`, `${a}`)), l.value = Number(a) - f, d = setInterval(() => {
        const N = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
        l.value = Number(a) - Number(N), l.value <= 0 && (clearInterval(d), s.value = !1, sessionStorage.setItem(`wet-deadlinetime-${n.value}`, ""));
      }, 1e3);
    };
    return x(() => {
      const e = sessionStorage.getItem(`wet-deadlinetime-${n.value}`), t = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
      Number(e) - t > 0 ? c(!1) : (s.value = !1, sessionStorage.setItem(`wet-deadlinetime-${n.value}`, ""));
    }), (e, t) => (i(), w(u(V), y(o, {
      onClick: t[0] || (t[0] = () => c()),
      disabled: D.value
    }), {
      default: g(() => [
        s.value ? (i(), w(u(P), { key: 1 }, {
          default: g(() => [
            u(T).prefix ? (i(), S("span", j, [
              m(e.$slots, "prefix")
            ])) : E("", !0),
            b("span", null, M(l.value) + "s", 1),
            b("span", null, [
              m(e.$slots, "suffix", {}, () => [
                $("后获取")
              ])
            ])
          ]),
          _: 3
        })) : (i(), S("span", W, [
          m(e.$slots, "default", {}, () => [
            $("验证码")
          ])
        ]))
      ]),
      _: 3
    }, 16, ["disabled"]));
  }
});
export {
  F as default
};
