import { jsx as n, Fragment as E, jsxs as P } from "react/jsx-runtime";
import { useMemo as T, useEffect as F } from "react";
import { a as B } from "../useQuery-n4ls1rLk.js";
import { u, C as w, a as N } from "../index.esm-BQxOvVZs.js";
import { I as v, T as D, S as q, a as k, R as A, C as R, b as j } from "../index-20bzTFSx.js";
import { useGeneralForm as y } from "../context/generalContext/index.js";
import { cn as f } from "../utils/functions.js";
import "../utils/components/RenderEach.js";
import "../utils/components/RenderIf.js";
import "../components/Icons.js";
import "../components/Inputs/variants.js";
import "../index-xVF7D3FM.js";
import "../clsx-7d8NmkQq.js";
import "../motion-dVICNqWI.js";
import "../SVGVisualElement-aqO4D4Z5.js";
import "../LayoutGroupContext-3euHzeKi.js";
import "../context/index.js";
const M = ({ currentId: e, inputProps: s, className: t, fieldError: o, dependentId: r, ...m }) => {
  var c;
  const {
    register: l,
    formState: { errors: a }
  } = u();
  return /* @__PURE__ */ n(
    v,
    {
      ...m,
      className: f("_flex-1", t),
      inputProps: { ...s, ...l(e) },
      fieldError: o || ((c = a[e]) == null ? void 0 : c.message)
    }
  );
}, O = ({ currentId: e, inputProps: s, className: t, fieldError: o, ...r }) => {
  var a;
  const {
    register: m,
    formState: { errors: l }
  } = u();
  return /* @__PURE__ */ n(
    D,
    {
      ...r,
      className: f("_flex-1", t),
      inputProps: { ...s, ...m(e) },
      fieldError: o || ((a = l[e]) == null ? void 0 : a.message)
    }
  );
}, V = ({ currentId: e, inputProps: s, disabled: t = !1, className: o, ...r }) => {
  var a;
  const {
    register: m,
    formState: { errors: l }
  } = u();
  return /* @__PURE__ */ n(
    q,
    {
      disabled: t,
      className: f("_flex-1", o),
      ...r,
      inputProps: { ...s, ...m(e) },
      fieldError: (a = l[e]) == null ? void 0 : a.message
    }
  );
}, G = ({ currentId: e, className: s, label: t, labelClass: o }) => {
  const {
    formState: { errors: r },
    control: m
  } = u();
  return /* @__PURE__ */ n(
    w,
    {
      control: m,
      name: e,
      render: ({ field: { value: l, onChange: a } }) => {
        var c;
        return /* @__PURE__ */ n(
          k,
          {
            className: f("_flex-1", s),
            labelClass: o,
            label: t,
            value: l,
            onChange: () => a(!l),
            fieldError: (c = r[e]) == null ? void 0 : c.message
          }
        );
      }
    }
  );
}, K = ({ currentId: e, inputProps: s, label: t }) => {
  const { register: o } = u();
  return /* @__PURE__ */ n(A, { inputProps: { ...s, ...o(e) }, label: t });
}, L = ({ currentId: e, inputProps: s, ...t }) => {
  const { register: o } = u();
  return /* @__PURE__ */ n(R, { inputProps: { ...s, ...o(e) }, ...t });
}, Q = ({ currentId: e, inputClass: s, exact: t = !0, ...o }) => {
  const [r] = y((i) => (i.formules_schema ?? {})[e]), [m] = y((i) => i.functions), {
    setValue: l,
    formState: { dirtyFields: a, errors: c, isSubmitting: h, isSubmitted: p },
    control: x
  } = u(), _ = N({ name: (r == null ? void 0 : r.req) ?? "", exact: t }), [g, S] = T(() => {
    if (!_)
      return [void 0, void 0];
    let i = [], C = {};
    for (const [b, d] of r.req.entries())
      C[d] = _[b] || 0, i.push(!c[d] && a[d]);
    return [C, i];
  }, [r, c, a, _]);
  return F(() => {
    if (!(!g || !r || h || p) && S.some((i) => i))
      try {
        const i = r.fx(g, m);
        l(e, i, { shouldValidate: !0, shouldDirty: !0, shouldTouch: !0 });
      } catch (i) {
        console.error("Oops hubo un error en el calculo del campo: " + e), console.error(i == null ? void 0 : i.message);
      }
  }, [e, g, S, r, m, h, p, l]), /* @__PURE__ */ n(
    w,
    {
      control: x,
      name: e,
      render: ({ field: { onChange: i, ref: C, ...b } }) => /* @__PURE__ */ n(
        j,
        {
          ...o,
          ...b,
          disabled: o.disabled,
          onValueChange: ({ value: d }) => i(d),
          decimalSeparator: ",",
          thousandSeparator: ".",
          prefix: "$",
          inputClass: s
        }
      )
    }
  );
}, W = ({ currentId: e, targetValue: s, fetchOptions: t, ...o }) => {
  const r = N({ name: s }), {
    data: m,
    isLoading: l,
    error: a
  } = B({
    queryKey: ["Select", e, r],
    queryFn: async () => r ? await t(r) : [],
    enabled: !!r
  });
  return a ? /* @__PURE__ */ n("div", { className: "_h-[43px] _mt-[23px] _w-full _flex-1 _text-red-700", children: a.message }) : l ? /* @__PURE__ */ n("div", { className: "_h-[43px] _mt-[23px] _w-full _flex-1 _bg-gray-200 _animate-pulse" }) : /* @__PURE__ */ n(V, { selectOptions: m || [], currentId: e, ...o });
}, $ = ({ currentId: e, inputProps: s, className: t, fieldError: o, dependentId: r, ...m }) => {
  var x;
  const {
    watch: l,
    register: a,
    setValue: c,
    formState: { errors: h }
  } = u(), p = r != null && l(r) == !1;
  return F(() => {
    p && c(e, void 0);
  }, [p]), /* @__PURE__ */ n(E, { children: /* @__PURE__ */ n(
    v,
    {
      ...m,
      className: f("_flex-1", t),
      inputProps: { ...s, ...a(e), disabled: p },
      fieldError: o || ((x = h[e]) == null ? void 0 : x.message)
    }
  ) });
}, z = ({ headers: e, data: s }) => /* @__PURE__ */ P("table", { className: "_w-full _table-auto _border-collapse _overflow-hidden _rounded-xl _shadow-md", children: [
  /* @__PURE__ */ n("thead", { className: "_h-16 _bg-terceary _text-left _text-secondary", children: e.map((t) => /* @__PURE__ */ n("th", { children: t })) }),
  /* @__PURE__ */ n("tbody", { children: s.map((t) => /* @__PURE__ */ n("tr", { className: "_h-16 _border-1 _border-t-gray-600", children: t.map((o) => /* @__PURE__ */ n("td", { children: o })) })) })
] }), ce = {
  InputFormCntx: M,
  SelectFormCntx: V,
  TextAreaFormCntx: O,
  CalcInput: Q,
  SelectByAnotherField: W,
  SwitchFormCntx: G,
  RadioFormCntx: K,
  CheckBoxFormCntx: L,
  InputFormCntxDependentCheckbox: $,
  FormTableConceptosCntx: z
};
export {
  ce as default
};
