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