import { jsxs as r, 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 d from "../../components/Card/index.js";
import b from "../../components/Icons.js";
import p from "../../components/Layouts.js";
import c from "../FormInputs.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 "../../components/Card/variants.js";
import "../../hooks/useHasNextSiblingByAttribute.js";
import "../../index-20bzTFSx.js";
import "../../components/Inputs/variants.js";
import "../../motion-dVICNqWI.js";
import "../../SVGVisualElement-aqO4D4Z5.js";
import "../../LayoutGroupContext-3euHzeKi.js";
import "../../useQuery-n4ls1rLk.js";
const y = () => {
  var l;
  const e = C({ name: "activities" }) ?? [], o = e.length > 0, a = !((l = e.at(-1)) != null && l.activityCode);
  return { hasFields: o, validateLastField: a };
}, Q = () => {
  const [e, o] = g((i) => i.functions), { fields: a, append: l, remove: v } = x({
    name: "activities"
  }), { hasFields: f, validateLastField: _ } = y();
  I(() => {
    if (a.length == 0)
      return () => {
        n();
      };
  }, []);
  const n = () => {
    const i = a.length;
    l({
      activityCode: "",
      tarifa: "",
      activityDescription: "",
      taxableIncome: "",
      taxValue: ""
    }), o((s) => {
      s.formules_schema && (s.formules_schema[`activities.${i}.taxValue`] = {
        req: ["activities", `activities.${i}.taxableIncome`, `activities.${i}.tarifa`],
        fx: (m) => +m[`activities.${i}.tarifa`] / 1e3 * +m[`activities.${i}.taxableIncome`]
      });
    });
  }, h = (i) => {
    a.length != 1 && (v(i), o((s) => {
      s.formules_schema && delete s.formules_schema[`activities.${i}.taxValue`];
    }));
  };
  return /* @__PURE__ */ r("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: a, render: (i, s) => /* @__PURE__ */ t(F, { index: s, onDelete: () => h(s) }, i.id) }) : /* @__PURE__ */ t("p", { children: "Agrega una actividad principal" }),
    /* @__PURE__ */ t(u.Button, { className: "_w-fit _mb-4 _ml-6", onClick: n, disabled: _, type: "button", children: "Agregar Actividad" })
  ] });
}, F = ({ index: e, onDelete: o }) => {
  const a = e == 0;
  return /* @__PURE__ */ r(
    d.Wrapper,
    {
      canCloseContent: !0,
      titleToShow: /* @__PURE__ */ r("p", { children: [
        "ACTIVIDAD ",
        e + 1,
        " ",
        a ? "(PRINCIPAL)" : ""
      ] }),
      className: "_mx-4 _my-4",
      variant: { shadow: "withShadow" },
      children: [
        /* @__PURE__ */ r("div", { className: "_px-4 _py-4", children: [
          /* @__PURE__ */ r(p.InputsWrapper, { children: [
            /* @__PURE__ */ r("div", { className: "_flex _flex-[2]", children: [
              /* @__PURE__ */ t(c.InputFormCntx, { currentId: `activities.${e}.activityCode`, label: "Código Actividad (MUN)*" }),
              /* @__PURE__ */ t(u.Activities, { className: "_ml-1", index: e, targetId: `activities.${e}.activityCode` })
            ] }),
            /* @__PURE__ */ t(c.InputFormCntx, { currentId: `activities.${e}.tarifa`, label: "Tarifa (Por mil)*", inputProps: { disabled: !0 } })
          ] }),
          /* @__PURE__ */ r(p.InputsWrapper, { children: [
            /* @__PURE__ */ t(
              c.InputFormCntx,
              {
                inputProps: { disabled: !0 },
                className: "_flex-[2]",
                currentId: `activities.${e}.activityDescription`,
                label: "Descripción de la Actividad"
              }
            ),
            /* @__PURE__ */ t(c.CalcInput, { className: "_flex-1", currentId: `activities.${e}.taxableIncome`, label: "Ingresos gravados*" })
          ] })
        ] }),
        /* @__PURE__ */ r(d.Footer, { className: "_flex _flex-row", variant: { variant: "govco" }, children: [
          /* @__PURE__ */ t(N, { condition: !a, children: /* @__PURE__ */ r("div", { onClick: o, 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(c.CalcInput, { disabled: !0, className: "_ml-auto _w-fit", currentId: `activities.${e}.taxValue`, label: "VALOR IMPUESTO" })
        ] })
      ]
    }
  );
};
export {
  Q as ActivitiesCards,
  F as CardActivity
};
