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