import { jsx as o, Fragment as h, jsxs as f } from "react/jsx-runtime";
import { useEffect as L } from "react";
import { a as S } from "../../useQuery-n4ls1rLk.js";
import { b as D, u as I } from "../../index.esm-BQxOvVZs.js";
import O from "../../components/Card/index.js";
import { S as b } from "../../index-OHO5PlsB.js";
import R from "../../components/Layouts.js";
import { F as c } from "../../index-ec7CVlTE.js";
import { RenderEach as y } from "../../utils/components/RenderEach.js";
import { RenderIf as C } from "../../utils/components/RenderIf.js";
import "../../utils/functions.js";
import { formClient as F } from "../../config/index.js";
import "../../style.module-m7wnmRz9.js";
import "../../components/Icons.js";
import "../../clsx-7d8NmkQq.js";
import "../../components/Card/variants.js";
import "../../index-xVF7D3FM.js";
import "../../components/Inputs/variants.js";
import "../../motion-dVICNqWI.js";
import "../../SVGVisualElement-aqO4D4Z5.js";
import "../../LayoutGroupContext-3euHzeKi.js";
import "../../hooks/useHasNextSiblingByAttribute.js";
import "../../index.esm--ZdnNCdl.js";
import "../../_commonjsHelpers-2ufMB8rV.js";
import "../../components/AlertDialog/index.js";
import "react-dom";
import "../../components/AlertDialog/variants.js";
import "../../components/Buttons/index.js";
import "../../context/generalContext/index.js";
import "../../context/index.js";
import "../../components/Buttons/variants.js";
import "../../components/FormProvider.js";
import "../Modal.js";
import "../../hooks/useAnimatePresence.js";
import "../../use-unmount-effect-Wy5iLAex.js";
import "../../index-T7wQHOux.js";
import "../../feature/govco/FormModal.js";
import "../../feature/RenderFeatureComponents.js";
import "../../components/Maps/index.js";
import "../../hooks/useDeepCompareEffect.js";
import "../../components/Inputs/InputFileSimple.js";
import "../../hooks/useUploadFiles.js";
import "../../axios-f2q_J-wz.js";
import "../../components/Inputs/CircleProgressLoading.js";
import "../../PdfViewer-tzZO2boW.js";
import "../../index-XF2mSoW7.js";
import "../../index-JtU1DT1I.js";
import "../../index-5sPke2Og.js";
import "../../components/Table/components/Basic.js";
import "../../components/Table/context/index.js";
import "../../components/Table/utils/useTableInfoRest.js";
import "../../components/Table/components/Elements.js";
import "../../dayjs.min-KYonM6tp.js";
import "../../components/Table/components/TdComponents/WrapperTableTdComponents.js";
import "../../components/Table/components/variants.js";
import "../../components/Table/components/Filters.js";
import "../../hooks/useClickOutside.js";
import "../../components/Table/context/useCases.js";
import "../../components/Table/hooks/usePaginationSelector.js";
import "../../components/Table/hooks/useHandleInputWithTimer.js";
import "../../components/Table/components/TableStatesComponents.js";
import "../../components/Table/components/HeaderComponents/QuickSearch.js";
import "../FunctionalComponents.js";
import "../../hooks/useDebounce.js";
import "../../hooks/useLoadFiles.js";
const Ur = ({ payload: d, url: r, config: T }) => {
  const { fields: g, replace: A } = D({
    name: "signatories"
  }), { data: t, isPending: u, isError: E } = S({
    queryKey: ["signatories"],
    queryFn: async () => (await F.post(r, d, T)).data.findFirmantesByContribuyente.items,
    select: (s) => s.reduce(
      (e, p) => (p.firmante_cargo === "REPRESENTANTE LEGAL" ? (e["REPRESENTANTE LEGAL"] || (e["REPRESENTANTE LEGAL"] = []), e["REPRESENTANTE LEGAL"].push(p)) : p.firmante_cargo === "CONTADOR" && (e.CONTADOR || (e.CONTADOR = []), e.CONTADOR.push(p)), e),
      {
        "REPRESENTANTE LEGAL": [],
        CONTADOR: []
      }
    ),
    staleTime: 0,
    gcTime: 0
  }), m = t ?? {
    "REPRESENTANTE LEGAL": [],
    CONTADOR: []
  }, n = [...m["REPRESENTANTE LEGAL"], ...m.CONTADOR];
  return L(() => {
    const s = n == null ? void 0 : n.map((i) => ({
      firmName: i.firmante_nombre,
      firmDoc: i.firmante_tipo_documento,
      firmNumDoc: i.firmante_documento,
      fisNumTarjetaProf: i.firmante_cargo == "REPRESENTANTE LEGAL" ? void 0 : i.firmante_tarjeta_profesional,
      firmTipo: i.firmante_tipo,
      firmante_cargo: i.firmante_cargo
    }));
    (!t || ((t == null ? void 0 : t.length) ?? 0) == 0) && A(s.slice(0, 2));
  }, [t]), !t && !u ? /* @__PURE__ */ o(h, { children: "No hay data..." }) : u ? /* @__PURE__ */ o(h, { children: "Loading..." }) : E ? /* @__PURE__ */ o(h, { children: "Oops hubo un error" }) : /* @__PURE__ */ o(
    y,
    {
      of: g,
      render: (s, i) => /* @__PURE__ */ o(
        v,
        {
          data: n[i],
          index: i,
          dataArray: n,
          dataWithoutPrincipal: t.CONTADOR,
          dataWithPrincipal: t["REPRESENTANTE LEGAL"]
        },
        s.id
      )
    }
  );
}, v = ({ data: d, index: r, dataArray: T, dataWithoutPrincipal: g, dataWithPrincipal: A }) => {
  const {
    setValue: t,
    watch: u,
    formState: { errors: E }
  } = I(), m = (d == null ? void 0 : d.firmante_tipo) == "PRINCIPAL", n = m ? "FIRMA DEL RESPONSABLE FISCAL" : "FIRMA DEL DECLARANTE", s = (N) => {
    N.preventDefault();
    const l = N.target.value, a = T.find((_) => _.firmante_nombre == l);
    t(`signatories.${r}.firmName`, l, {
      shouldValidate: !0
    }), a && (t(`signatories.${r}.firmDoc`, a.firmante_tipo_documento, {
      shouldValidate: !0
    }), t(`signatories.${r}.firmNumDoc`, a.firmante_documento, {
      shouldValidate: !0
    }), t(`signatories.${r}.firmTipo`, a.firmante_tipo, {
      shouldValidate: !0
    }), t(`signatories.${r}.firmante_cargo`, a.firmante_cargo, {
      shouldValidate: !0
    }), m || t(`signatories.${r}.fisNumTarjetaProf`, a.firmante_tarjeta_profesional, {
      shouldValidate: !0
    }));
  }, [i, e, p] = u([`signatories.${r}.firmName`, `signatories.${r}.firmDoc`, `signatories.${r}.firmNumDoc`]), P = (N) => {
    const l = E == null ? void 0 : E.signatories;
    if (Array.isArray(l)) {
      const a = l ? l[r] : void 0, _ = a ? a[N] : void 0;
      return _ ? _.message : void 0;
    }
  };
  return /* @__PURE__ */ o(O.Wrapper, { titleToShow: n, className: "_mx-4 _my-4", variant: { shadow: "withShadow" }, children: /* @__PURE__ */ f("div", { className: "_px-4 _py-2 _flex _flex-col _gap-[8px]", children: [
    /* @__PURE__ */ o(C, { condition: !m, children: /* @__PURE__ */ f(R.InputsWrapper, { children: [
      /* @__PURE__ */ o("div", { className: "_flex _flex-col _flex-1", children: /* @__PURE__ */ f(R.InputsWrapper, { className: "xl:_mt-2", children: [
        /* @__PURE__ */ o(
          c.RadioFormCntx,
          {
            inputProps: { value: "CONTADOR", disabled: e },
            currentId: `signatories.${r}.firmante_cargo`,
            label: "Contador"
          }
        ),
        /* @__PURE__ */ o(
          c.RadioFormCntx,
          {
            inputProps: { value: "REVISOR_FISCAL", disabled: e },
            currentId: `signatories.${r}.firmante_cargo`,
            label: "Revisor Fiscal"
          }
        )
      ] }) }),
      /* @__PURE__ */ o("div", { className: "flex-1" })
    ] }) }),
    /* @__PURE__ */ o(
      b,
      {
        inputProps: { onChange: s, value: u(`signatories.${r}.firmName`) },
        label: "Nombres y Apellidos",
        selectOptions: m ? A : g,
        placeholder: "Seleccionar un declarante",
        optionsEntries: ["firmante_nombre", "firmante_nombre"]
      }
    ),
    /* @__PURE__ */ f(R.InputsWrapper, { children: [
      /* @__PURE__ */ f("div", { className: "_flex _flex-col _flex-1", children: [
        /* @__PURE__ */ o("p", { className: "_text-input", children: "Tipo de identificación*" }),
        /* @__PURE__ */ f(R.InputsWrapper, { className: "xl:_mt-2", children: [
          /* @__PURE__ */ o(
            c.RadioFormCntx,
            {
              inputProps: { value: "CC", disabled: e },
              currentId: `signatories.${r}.firmDoc`,
              label: "Cédula de Ciudadanía"
            }
          ),
          /* @__PURE__ */ o(
            c.RadioFormCntx,
            {
              inputProps: { value: "CE", disabled: e },
              currentId: `signatories.${r}.firmDoc`,
              label: "Cédula de Extranjería"
            }
          )
        ] })
      ] }),
      /* @__PURE__ */ o(c.InputFormCntx, { currentId: `signatories.${r}.firmNumDoc`, label: "No. de documento*", inputProps: { disabled: p } })
    ] }),
    /* @__PURE__ */ o(C, { condition: !m, children: /* @__PURE__ */ o(
      c.InputFormCntx,
      {
        fieldError: P("fisNumTarjetaProf"),
        currentId: `signatories.${r}.fisNumTarjetaProf`,
        label: "No. Tarjeta Profesional",
        inputProps: { disabled: i }
      }
    ) })
  ] }) });
};
export {
  Ur as CardsSignatories
};
