import { defineComponent as D, ref as M, computed as P, unref as s, openBlock as o, createElementBlock as n, normalizeStyle as T, normalizeClass as r, withKeys as H, withModifiers as L, createElementVNode as a, withDirectives as O, mergeProps as U, toHandlers as X, vModelRadio as _, createBlock as h, toDisplayString as j, createCommentVNode as p, renderSlot as A } from "vue";
import { useCommon as g } from "../../composables/useCommon.js";
import { useTheme as J } from "../../composables/useTheme.js";
import { useColors as Q } from "../../composables/useColors.js";
import { useInteractive as w } from "../../composables/useInteractive.js";
import { useInputtable as c } from "../../composables/useInputtable.js";
import W from "../spinner/Spinner.vue.js";
import Y from "../inputFooter/InputFooter.vue.js";
const Z = ["aria-selected", "aria-disabled", "onKeypress"], x = ["id", "name", "required", "disabled"], ee = /* @__PURE__ */ a("circle", {
  cx: "10",
  cy: "10",
  r: "10"
}, null, -1), le = [
  ee
], se = ["textContent"], oe = {
  ...g.props(),
  ...Q.props("primary"),
  ...w.props(),
  ...c.props(),
  value: [String, Number],
  glow: Boolean
}, re = {
  name: "XRadio",
  validators: {
    ...g.validators()
  }
}, ce = /* @__PURE__ */ D({
  ...re,
  props: oe,
  emits: c.emits(!1),
  setup(V, { expose: k, emit: I }) {
    const l = V, d = I, f = M(null), { focus: v, blur: C } = w(f), {
      errorInternal: $,
      hideFooterInternal: z,
      isInsideForm: B,
      isInsideFormGroup: u,
      isFirstValidation: R,
      formGroup: m,
      reset: F,
      validate: b,
      setError: N
    } = c(l, { focus: v, emit: d, withListeners: !1 }), i = P({
      get() {
        const e = s(m.value);
        return u ? e === l.value : l.value === l.modelValue;
      },
      set() {
        d("update:modelValue", l.value), m.setValue(l.value);
      }
    });
    function S() {
      d("update:modelValue", l.value), m.setValue(l.value);
    }
    const q = {
      input: () => {
        u || setTimeout(() => {
          l.validateOnInput && !R.value && b(l.modelValue);
        }, 0);
      }
    }, { styles: E, classes: t, className: G } = J("Radio", {}, l, { selected: i, isInsideForm: B, isInsideFormGroup: u });
    return k({ focus: v, blur: C, reset: F, validate: b, setError: N }), (e, y) => (o(), n("label", {
      ref_key: "elRef",
      ref: f,
      tabindex: "0",
      "aria-selected": i.value ? "true" : "false",
      "aria-disabled": e.disabled || e.loading ? "true" : void 0,
      style: T(s(E)),
      class: r([
        s(G),
        s(t).wrapper
      ]),
      onKeypress: H(L(S, ["prevent", "stop"]), ["space"])
    }, [
      a("div", {
        class: r(["flex items-center", { "cursor-not-allowed": e.disabled }])
      }, [
        O(a("input", U({
          id: e.id,
          "onUpdate:modelValue": y[0] || (y[0] = (K) => i.value = K),
          name: e.name,
          required: e.required,
          disabled: e.disabled || e.loading,
          type: "radio",
          class: "invisible absolute"
        }, X(q, !0)), null, 16, x), [
          [_, i.value]
        ]),
        a("div", {
          class: r([
            e.$style.radio,
            s(t).circle,
            [e.glow && !e.disabled && !e.loading ? e.$style["radio--glow"] : ""]
          ])
        }, [
          e.loading ? (o(), h(W, {
            key: 0,
            size: e.size,
            class: "absolute"
          }, null, 8, ["size"])) : (o(), n("svg", {
            key: 1,
            viewBox: "0 0 20 20",
            class: r(["fill-current w-full", [
              s(t).circleIcon,
              e.$style.radio_circle
            ]])
          }, le, 2))
        ], 2),
        a("div", null, [
          e.label ? (o(), n("div", {
            key: 0,
            class: r(s(t).label),
            textContent: j(e.label)
          }, null, 10, se)) : p("", !0),
          e.$slots.default ? (o(), n("div", {
            key: 1,
            class: r(s(t).content)
          }, [
            A(e.$slots, "default")
          ], 2)) : p("", !0)
        ])
      ], 2),
      s(z) ? p("", !0) : (o(), h(Y, {
        key: 0,
        error: s($),
        helper: e.helper
      }, null, 8, ["error", "helper"]))
    ], 46, Z));
  }
});
export {
  ce as default
};
