import { useEffect as f } from "react";
import { a as m, u as g } from "../useQuery-n4ls1rLk.js";
import { a as S, c as C, y as p } from "../index.esm-Jcyi89ZF.js";
import { useGeneralForm as d } from "../context/generalContext/index.js";
import { formClient as y } from "../config/index.js";
import "../_commonjsHelpers-2ufMB8rV.js";
import "../context/index.js";
import "react/jsx-runtime";
import "../axios-f2q_J-wz.js";
S(C, "validateDv", function({ message: e }) {
  return this.test("validateDv", "Digito no corresponde al documento", function(r, o) {
    return new Promise((n, a) => {
      r >= 1 && a(this.createError({ message: e, path: o.path })), n(!0);
    });
  });
});
var _ = /* @__PURE__ */ ((e) => (e.Caracter = "CARACTER", e.Empty = "", e.Numerico = "NUMERICO", e))(_ || {});
function h(e) {
  const r = e;
  return typeof r.validationScheme == "function" && typeof r.formulaScheme == "object" && typeof r.functionScheme == "object";
}
const D = () => {
  const [e, r] = d((i) => i.mainConfig), { configFrm: o, isPending: n } = q(), {
    isPending: a,
    data: t,
    error: u
  } = m({
    queryKey: ["module", o],
    queryFn: async () => o != null && o.functions ? await import(e.endpoint ? e.endpoint : `https://nodejs.softwaretributario.com:8001/form/${o.functions}.js`).then((c) => c == null ? void 0 : c.default) : void 0,
    select: (i) => {
      if (i && h(i))
        return { ...i, validationScheme: i.validationScheme(p) };
    },
    enabled: !!(o != null && o.functions) && !n
  }), { data: s, isPending: v } = m({
    queryKey: ["params", e],
    queryFn: async () => {
      if (!e)
        return null;
      switch (e.type) {
        case "govco":
          if (!e.formulario_id && !e.impuesto_id)
            return null;
          const i = { impuesto_id: e.impuesto_id, formulario_id: e.formulario_id };
          return (await y.post("external/parms", i)).data;
        default:
          return null;
      }
    },
    select(i) {
      return i == null ? void 0 : i.getParmByForm.reduce(
        (c, l) => (c[l.description] = l.value, c),
        {}
      );
    }
  });
  return f(() => {
    t && r((i) => {
      i.functions = t.functionScheme, i.formules_schema = t.formulaScheme;
    });
  }, [r, t]), f(() => {
    s && r((i) => {
      i.params = s;
    });
  }, [r, s]), { isPending: a || n || v, validationScheme: t == null ? void 0 : t.validationScheme, error: u, jsx: (t == null ? void 0 : t.jsx) || "" };
}, q = () => {
  const [e] = d((a) => a.mainConfig), {
    // isPending,
    isFetching: r,
    data: o,
    error: n
  } = m({
    queryKey: ["frmtype", e.guid_form],
    queryFn: async () => e.guid_form ? (await y.get(`frmtype${e.guid_form}`)).data : null
  });
  return { configFrm: o, isPending: r, error: n };
}, K = () => {
  const [e, r] = d((t) => t.mainConfig), {
    isPending: o,
    data: n,
    error: a
  } = m({
    queryKey: ["module", e.endpoint],
    queryFn: async () => {
      if (e.endpoint) {
        const t = e.endpoint;
        return console.log("aa", t), await import(t).then((u) => u == null ? void 0 : u.default);
      }
    },
    select: (t) => {
      if (t && h(t))
        return { ...t, validationScheme: t.validationScheme(p) };
    }
  });
  return f(() => {
    n && r((t) => {
      t.functions = n.functionScheme, t.formules_schema = n.formulaScheme;
    });
  }, [r, n]), { isPending: o, validationScheme: n == null ? void 0 : n.validationScheme, error: a, jsx: (n == null ? void 0 : n.jsx) || "" };
}, M = (e) => {
  var a, t;
  const o = (t = (a = g().getQueryCache().find({ exact: !1, queryKey: ["params"] })) == null ? void 0 : a.state.data) == null ? void 0 : t.getParmByForm;
  return o ? { values: o.reduce(
    (u, s) => ((!e || e.includes(s.code)) && (u[s.description] = s.value), u),
    {}
  ) } : { values: {} };
};
export {
  _ as ParamType,
  M as useGetParamsByQuery,
  D as useLoadFiles,
  q as useLoadFrmType,
  K as useLoadJsxFiles
};
