import { defineComponent as P, ref as w, watch as m, unref as a, openBlock as i, createElementBlock as p, normalizeStyle as R, normalizeClass as u, createElementVNode as d, withKeys as T, withModifiers as H, withDirectives as O, mergeProps as U, toHandlers as X, vModelCheckbox as j, createBlock as V, renderSlot as C, toDisplayString as J, createCommentVNode as Q } from "vue";
import { useTheme as W } from "../../composables/useTheme.js";
import { useCommon as I } from "../../composables/useCommon.js";
import { useColors as Y } from "../../composables/useColors.js";
import { useInteractive as z } from "../../composables/useInteractive.js";
import { useInputtable as f } from "../../composables/useInputtable.js";
import Z from "../spinner/Spinner.vue.js";
import x from "../inputFooter/InputFooter.vue.js";
const ee = ["onKeypress"], se = ["id", "name", "aria-checked", "aria-disabled", "disabled", "required"], le = {
  key: 1,
  name: "check-icon",
  class: "w-2/3 h-[2px] bg-white dark:bg-secondary-900"
}, oe = /* @__PURE__ */ d("path", { d: "M0 11l2-2 5 5L18 3l2 2L7 18z" }, null, -1), ae = [
  oe
], re = ["textContent"], ie = {
  ...I.props(),
  ...Y.props("primary"),
  ...z.props(),
  ...f.props(),
  value: [String, Number],
  indeterminate: Boolean,
  glow: Boolean
}, te = {
  name: "XCheckbox",
  validators: {
    ...I.validators()
  }
}, he = /* @__PURE__ */ P({
  ...te,
  props: ie,
  emits: f.emits(!1),
  setup(A, { expose: B, emit: $ }) {
    const s = A, v = $, h = w(null), l = w(!1);
    function b() {
      l.value = !l.value;
    }
    const { focus: y, blur: F } = z(h), {
      errorInternal: G,
      hideFooterInternal: N,
      isInsideForm: S,
      isInsideFormGroup: c,
      isFirstValidation: _,
      formGroup: r,
      reset: q,
      validate: k,
      setError: E
    } = f(s, { focus: y, emit: v, withListeners: !1 });
    c ? (m(() => r.value, () => {
      const e = a(r.value);
      e && Array.isArray(e) && e.includes(s.value) ? l.value = !0 : l.value = !1;
    }, { immediate: !0, deep: !0 }), m(() => l.value, (e) => {
      if (!s.value)
        return;
      const o = a(r.value);
      if (e)
        if (o && Array.isArray(o)) {
          if (!o.includes(s.value)) {
            const n = [...o, s.value];
            r.setValue(n);
          }
        } else
          r.setValue([s.value]);
      else if (o && Array.isArray(o) && o.includes(s.value)) {
        const n = o.findIndex((D) => D === s.value), g = [...o];
        g.splice(n, 1), r.setValue(g);
      }
    })) : (m(() => s.modelValue, (e) => {
      l.value = !!e;
    }, { immediate: !0 }), m(() => l.value, (e) => {
      v("update:modelValue", e);
    }));
    const K = {
      input: () => {
        c || setTimeout(() => {
          s.validateOnInput && !_.value && k(s.modelValue);
        }, 0);
      }
    }, { styles: L, classes: t, className: M } = W("Checkbox", {}, s, { checked: l, isInsideForm: S, isInsideFormGroup: c });
    return B({ focus: y, blur: F, toggle: b, reset: q, validate: k, setError: E }), (e, o) => (i(), p("label", {
      style: R(a(L)),
      class: u([
        a(M),
        a(t).wrapper
      ])
    }, [
      d("div", {
        ref_key: "elRef",
        ref: h,
        class: u(a(t).content),
        tabindex: "0",
        onKeypress: T(H(b, ["prevent", "stop"]), ["space"])
      }, [
        O(d("input", U({
          id: e.id,
          "onUpdate:modelValue": o[0] || (o[0] = (n) => l.value = n),
          name: e.name,
          "aria-checked": e.indeterminate ? "mixed" : l.value ? "true" : "false",
          "aria-disabled": e.disabled ? "true" : void 0,
          type: "checkbox",
          class: "invisible absolute",
          disabled: e.disabled || e.loading,
          required: e.required
        }, X(K, !0)), null, 16, se), [
          [j, l.value]
        ]),
        d("div", {
          class: u([
            a(t).box,
            [e.glow && !e.disabled && !e.loading ? e.$style["checkbox--glow"] : ""]
          ])
        }, [
          e.loading ? (i(), V(Z, {
            key: 0,
            size: e.size,
            class: "absolute"
          }, null, 8, ["size"])) : e.indeterminate ? (i(), p("span", le)) : C(e.$slots, "icon", { key: 2 }, () => [
            (i(), p("svg", {
              viewBox: "0 0 20 20",
              class: u([a(t).icon, { "opacity-0": !l.value }])
            }, ae, 2))
          ])
        ], 2),
        d("div", {
          class: u(a(t).label)
        }, [
          e.label ? (i(), p("span", {
            key: 0,
            textContent: J(e.label)
          }, null, 8, re)) : C(e.$slots, "default", { key: 1 })
        ], 2)
      ], 42, ee),
      a(N) ? Q("", !0) : (i(), V(x, {
        key: 0,
        error: a(G),
        helper: e.helper
      }, null, 8, ["error", "helper"]))
    ], 6));
  }
});
export {
  he as default
};
