import { defineComponent as K, computed as k, provide as q, openBlock as m, createBlock as d, mergeProps as w, unref as o, toHandlers as B, withKeys as N, withCtx as $, createElementVNode as A, normalizeClass as E, renderSlot as O, createCommentVNode as P } from "vue";
import { useTheme as j } from "../../composables/useTheme.js";
import { useInteractive as z } from "../../composables/useInteractive.js";
import { useInputtable as a } from "../../composables/useInputtable.js";
import { injectFormGroupKey as H } from "../../composables/keys.js";
import S from "../label/Label.vue.js";
import T from "../inputFooter/InputFooter.vue.js";
const X = {
  ...z.props(),
  ...a.props(),
  vertical: {
    type: Boolean,
    default: !1
  }
}, D = {
  name: "XFormGroup"
}, Y = /* @__PURE__ */ K({
  ...D,
  props: X,
  emits: a.emits(),
  setup(f, { expose: c, emit: V }) {
    const r = f, t = [], y = k(() => typeof r.modelValue == "string" || typeof r.modelValue == "number" || Array.isArray(r.modelValue) ? r.modelValue : "");
    q(H, {
      registerInputGroup: (e, s) => {
        t.push({ name: e, focus: s });
      },
      unregisterInputGroup: (e) => {
        const s = t.findIndex((C) => C.name === e);
        t.splice(s, 1);
      },
      setValue: (e) => {
        n("update:modelValue", e);
      },
      isInsideFormGroup: !0,
      value: y
    });
    function i() {
      var e;
      (e = t[0]) == null || e.focus();
    }
    const n = V, {
      errorInternal: u,
      isInsideForm: v,
      isFirstValidation: p,
      reset: h,
      validate: l,
      setError: I
    } = a(r, { focus: i, emit: n }), b = {
      change: (e) => {
        r.validateOnInput && !p.value && l(r.modelValue);
      }
    };
    function F() {
      r.validateOnInput && !p.value && l(r.modelValue);
    }
    const { styles: G, classes: g, className: _ } = j("FormGroup", {}, r, { errorInternal: u });
    return c({ focus: i, blur, reset: h, validate: l, setError: I }), (e, s) => (m(), d(S, w({
      tag: "fieldset",
      style: o(G),
      disabled: e.disabled,
      required: e.required,
      "is-inside-form": o(v),
      label: e.label,
      class: [
        o(_)
      ],
      tooltip: e.tooltip
    }, B(b), {
      onKeyup: N(F, ["space"])
    }), {
      default: $(() => [
        A("div", {
          class: E(o(g).wrapper)
        }, [
          O(e.$slots, "default")
        ], 2),
        e.hideFooter ? P("", !0) : (m(), d(T, {
          key: 0,
          error: o(u),
          helper: e.helper
        }, null, 8, ["error", "helper"]))
      ]),
      _: 3
    }, 16, ["style", "disabled", "required", "is-inside-form", "label", "class", "tooltip", "onKeyup"]));
  }
});
export {
  Y as default
};
