import { jsxs as o, jsx as t } from "react/jsx-runtime";
import { useEffect as I } from "react";
import { b as x, a as C } from "../../index.esm-BQxOvVZs.js";
import u from "../../components/Buttons/index.js";
import n from "../../components/Card/index.js";
import b from "../../components/Icons.js";
import d from "../../components/Layouts.js";
import { F as s } from "../../index-ec7CVlTE.js";
import { useGeneralForm as g } from "../../context/generalContext/index.js";
import { RenderEach as A } from "../../utils/components/RenderEach.js";
import { RenderIf as N } from "../../utils/components/RenderIf.js";
import "../../utils/functions.js";
import "../../components/Buttons/variants.js";
import "../../index-xVF7D3FM.js";
import "../../clsx-7d8NmkQq.js";
import "../../context/index.js";
import "../../style.module-m7wnmRz9.js";
import "../../components/Card/variants.js";
import "../../hooks/useHasNextSiblingByAttribute.js";
import "../../index-OHO5PlsB.js";
import "../../components/Inputs/variants.js";
import "../../motion-dVICNqWI.js";
import "../../SVGVisualElement-aqO4D4Z5.js";
import "../../LayoutGroupContext-3euHzeKi.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/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 "../../useQuery-n4ls1rLk.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";
import "../../config/index.js";
const y = () => {
  var c;
  const i = C({ name: "activities" }) ?? [], m = i.length > 0, e = !((c = i.at(-1)) != null && c.activityCode);
  return { hasFields: m, validateLastField: e };
}, St = () => {
  const [i, m] = g((r) => r.functions), { fields: e, append: c, remove: v } = x({
    name: "activities"
  }), { hasFields: f, validateLastField: _ } = y();
  I(() => {
    if (e.length == 0)
      return () => {
        p();
      };
  }, []);
  const p = () => {
    const r = e.length;
    c({
      activityCode: "",
      tarifa: "",
      activityDescription: "",
      taxableIncome: "",
      taxValue: ""
    }), m((a) => {
      a.formules_schema && (a.formules_schema[`activities.${r}.taxValue`] = {
        req: ["activities", `activities.${r}.taxableIncome`, `activities.${r}.tarifa`],
        fx: (l) => +l[`activities.${r}.tarifa`] / 1e3 * +l[`activities.${r}.taxableIncome`]
      });
    });
  }, h = (r) => {
    e.length != 1 && (v(r), m((a) => {
      a.formules_schema && delete a.formules_schema[`activities.${r}.taxValue`];
    }));
  };
  return /* @__PURE__ */ o("div", { className: "_flex _flex-col _w-full", children: [
    /* @__PURE__ */ t("p", { className: "_ml-5 _mt-5 _text-maximun _font-semibold", children: "Actividades gravadas" }),
    f ? /* @__PURE__ */ t(A, { of: e, render: (r, a) => /* @__PURE__ */ t(F, { index: a, onDelete: () => h(a) }, r.id) }) : /* @__PURE__ */ t("p", { children: "Agrega una actividad principal" }),
    /* @__PURE__ */ t(u.Button, { className: "_w-fit _mb-4 _ml-6", onClick: p, disabled: _, type: "button", children: "Agregar Actividad" })
  ] });
}, F = ({ index: i, onDelete: m }) => {
  const e = i == 0;
  return /* @__PURE__ */ o(
    n.Wrapper,
    {
      canCloseContent: !0,
      titleToShow: /* @__PURE__ */ o("p", { children: [
        "ACTIVIDAD ",
        i + 1,
        " ",
        e ? "(PRINCIPAL)" : ""
      ] }),
      className: "_mx-4 _my-4",
      variant: { shadow: "withShadow" },
      children: [
        /* @__PURE__ */ o("div", { className: "_px-4 _py-4", children: [
          /* @__PURE__ */ o(d.InputsWrapper, { children: [
            /* @__PURE__ */ o("div", { className: "_flex _flex-[2]", children: [
              /* @__PURE__ */ t(s.InputFormCntx, { currentId: `activities.${i}.activityCode`, label: "Código Actividad (MUN)*" }),
              /* @__PURE__ */ t(u.Activities, { className: "_ml-1", index: i, targetId: `activities.${i}.activityCode` })
            ] }),
            /* @__PURE__ */ t(s.InputFormCntx, { currentId: `activities.${i}.tarifa`, label: "Tarifa (Por mil)*", inputProps: { disabled: !0 } })
          ] }),
          /* @__PURE__ */ o(d.InputsWrapper, { children: [
            /* @__PURE__ */ t(
              s.InputFormCntx,
              {
                inputProps: { disabled: !0 },
                className: "_flex-[2]",
                currentId: `activities.${i}.activityDescription`,
                label: "Descripción de la Actividad"
              }
            ),
            /* @__PURE__ */ t(s.CalcInput, { className: "_flex-1", currentId: `activities.${i}.taxableIncome`, label: "Ingresos gravados*" })
          ] })
        ] }),
        /* @__PURE__ */ o(n.Footer, { className: "_flex _flex-row", variant: { variant: "govco" }, children: [
          /* @__PURE__ */ t(N, { condition: !e, children: /* @__PURE__ */ o("div", { onClick: m, className: "_group hover:_text-black _flex _gap-2 _items-center _cursor-pointer", children: [
            /* @__PURE__ */ t(b.XWithCircleIcon, { className: "group-hover:_text-red-700 _text-red-600" }),
            /* @__PURE__ */ t("p", { className: "group-hover:_underline _text-red-600", children: "Descartar Actividad" })
          ] }) }),
          /* @__PURE__ */ t(s.CalcInput, { disabled: !0, className: "_ml-auto _w-fit", currentId: `activities.${i}.taxValue`, label: "VALOR IMPUESTO" })
        ] })
      ]
    }
  );
};
export {
  St as ActivitiesCards,
  F as CardActivity
};
