import { jsxs as l, jsx as e, Fragment as p } from "react/jsx-runtime";
import { useState as b, useMemo as B } from "react";
import { useClickOutside as v } from "../../../hooks/useClickOutside.js";
import { d as P } from "../../../dayjs.min-KYonM6tp.js";
import C from "../../Buttons/index.js";
import _ from "../../Icons.js";
import { I as u } from "../../../index-20bzTFSx.js";
import { cn as f } from "../../../utils/functions.js";
import { RenderIf as y } from "../../../utils/components/RenderIf.js";
import { useTableContext as N } from "../context/index.js";
import { useManagementFilter as I, useSortTable as D, useHandleIntervalFilter as F } from "../context/useCases.js";
import { useHandleTextInputWithTimer as w } from "../hooks/useHandleInputWithTimer.js";
import { A as j } from "../../../index-T7wQHOux.js";
import { m as M } from "../../../motion-dVICNqWI.js";
import "../../../_commonjsHelpers-2ufMB8rV.js";
import "../../../index.esm-BQxOvVZs.js";
import "../../../context/generalContext/index.js";
import "../../../context/index.js";
import "../../Buttons/variants.js";
import "../../../index-xVF7D3FM.js";
import "../../../clsx-7d8NmkQq.js";
import "../../../utils/components/RenderEach.js";
import "../../Inputs/variants.js";
import "../hooks/usePaginationSelector.js";
import "../../../LayoutGroupContext-3euHzeKi.js";
import "../../../SVGVisualElement-aqO4D4Z5.js";
import "../../../use-unmount-effect-Wy5iLAex.js";
const me = ({ thead: r, isLastTh: a }) => {
  const [o, t] = N((i) => i.currentFilterColumn), [n, s] = b(null), [c, x] = b(null);
  v(
    () => {
      t((i) => {
        i.currentFilterColumn = void 0;
      });
    },
    null,
    [c, n]
  );
  const m = B(() => o == r.cellParam, [o]);
  return /* @__PURE__ */ l("div", { className: "_relative _z-60", children: [
    /* @__PURE__ */ e("div", { ref: s, "data-ignore-outside-clicks": !0, onClick: () => {
      t(m ? (i) => {
        i.currentFilterColumn = void 0;
      } : (i) => {
        i.currentFilterColumn = r.cellParam;
      });
    }, children: /* @__PURE__ */ e(_.SearchIcon, { className: "_ml-2 _w-4 _h-4 _cursor-pointer" }) }),
    /* @__PURE__ */ e(j, { children: /* @__PURE__ */ e(y, { condition: m, children: /* @__PURE__ */ l(
      M.div,
      {
        ref: x,
        className: f(
          "_absolute _rounded-md _shadow-lg _top-5 _left-[-50%] !_translate-x-[-50%] _bg-white _z-20 _w-max _py-2 _flex _flex-col _gap-2",
          { "_opacity-100": m },
          { "!_left-[-400%]": a }
        ),
        initial: { opacity: 0, y: -10 },
        animate: { opacity: 1, y: 0 },
        exit: { opacity: 0, y: -10 },
        children: [
          /* @__PURE__ */ e(S, { thead: r }),
          /* @__PURE__ */ e(V, { thead: r }),
          /* @__PURE__ */ e(k, { thead: r }),
          /* @__PURE__ */ e(T, { thead: r })
        ]
      }
    ) }) })
  ] });
}, S = ({ thead: r }) => {
  var i;
  const [a, o] = N((d) => d.metaDataPagination), { getCurrentFiltValue: t, simpleSetFilter: n } = I(), s = (d) => {
    n(r.cellParam, "contains", "text", d), d && o((h) => {
      h.metaDataPagination = {
        ...h.metaDataPagination,
        currentPage: 1
      };
    });
  }, { handleInput: c, loading: x, searchValue: m, removeSearchInput: g } = w(
    s,
    `${t(r.cellParam)}`
  );
  return ((i = r.filter) == null ? void 0 : i.type) !== "text" ? /* @__PURE__ */ e(p, {}) : /* @__PURE__ */ l("div", { className: "_px-1", children: [
    /* @__PURE__ */ e("label", { className: "_font-main _px-[5px] _text-[#4B4B4B] _text-sm", children: "Buscar" }),
    /* @__PURE__ */ l("div", { className: "_flex _justify-between _items-center _border _border-zinc-400", children: [
      /* @__PURE__ */ e(
        u,
        {
          labelClass: "_text-xs",
          inputProps: { className: "_h-[24px] _border-none _text-medium _text-zinc-700", onChange: c, value: m }
        }
      ),
      x ? /* @__PURE__ */ e(_.LoadingIcon, { className: "_static" }) : /* @__PURE__ */ e("div", { className: "_h-4 _w-4" }),
      /* @__PURE__ */ e(y, { condition: !!m && !x, children: /* @__PURE__ */ e(_.XIcon, { className: "_text-red-500 _cursor-pointer", onClick: g }) })
    ] })
  ] });
}, V = ({ thead: r }) => {
  const { sortByParam: a, currentSortByParam: o } = D(), t = o(r.cellParam), n = t !== void 0, s = n ? !(t != null && t.desc) : !1, c = n ? t == null ? void 0 : t.desc : !1;
  return r.canSort ? /* @__PURE__ */ l(p, { children: [
    /* @__PURE__ */ e("p", { className: "_font-main _px-[5px] _text-[#4B4B4B] _text-sm", children: "Ordenar información" }),
    /* @__PURE__ */ l(
      "p",
      {
        className: f("_flex _gap-2 _items-center _font-main _px-[5px] _text-[#4B4B4B] _text-sm _cursor-pointer", {
          "_bg-primary _text-white": s
        }),
        onClick: () => {
          a(r.cellParam, !1);
        },
        children: [
          /* @__PURE__ */ e(_.AscIcon, {}),
          " Orden Ascendente"
        ]
      }
    ),
    /* @__PURE__ */ l(
      "p",
      {
        className: f("_flex _gap-2 _items-center _font-main _px-[5px] _text-[#4B4B4B] _text-sm _cursor-pointer", {
          "_bg-primary _text-white": c
        }),
        onClick: () => {
          a(r.cellParam, !0);
        },
        children: [
          /* @__PURE__ */ e(_.DescIcon, {}),
          " Orden Descendente"
        ]
      }
    )
  ] }) : /* @__PURE__ */ e(p, {});
}, k = ({ thead: r }) => {
  var n;
  const { changeFiltValue: a, sendValue: o, state: t } = F({ thead: r });
  return ((n = r.filter) == null ? void 0 : n.type) !== "ranged-number" ? /* @__PURE__ */ e(p, {}) : /* @__PURE__ */ l("form", { className: "_flex _flex-col _gap-1.5 _px-2.5 _pb-[5px]", onSubmit: o, children: [
    /* @__PURE__ */ e("p", { className: "_font-main _px-[5px] _text-[#4B4B4B] _text-sm", children: "Filtrar por un valor" }),
    /* @__PURE__ */ e(
      u,
      {
        label: "Mayor a:",
        labelClass: "_text-xs",
        inputProps: { className: "_h-[24px] !_appearence-none", type: "number", id: "major", onChange: a, value: t.major }
      }
    ),
    /* @__PURE__ */ e(
      u,
      {
        label: "Menor a:",
        labelClass: "_text-xs",
        inputProps: { className: "_h-[24px] !_appearence-none", type: "number", id: "minor", onChange: a, value: t.minor }
      }
    ),
    /* @__PURE__ */ e(C.Button, { className: "_w-min _mx-auto", type: "submit", children: "Enviar" })
  ] });
}, T = ({ thead: r }) => {
  var s;
  const { changeFiltValue: a, sendValue: o, state: t } = F({ thead: r }), n = B(() => P().format("YYYY-MM-DD"), []);
  return ((s = r.filter) == null ? void 0 : s.type) !== "ranged-date" ? /* @__PURE__ */ e(p, {}) : /* @__PURE__ */ l("form", { className: "_flex _flex-col _gap-1.5 _px-2.5 _pb-[5px]", onSubmit: o, children: [
    /* @__PURE__ */ e("p", { className: "_font-main _px-[5px] _text-[#4B4B4B] _text-sm", children: "Filtrar por un valor" }),
    /* @__PURE__ */ e(
      u,
      {
        label: "Mayor a:",
        labelClass: "_text-xs",
        inputProps: {
          className: "_h-[24px] _border-none !_appearence-none",
          type: "date",
          id: "major",
          onChange: a,
          value: t.major,
          max: t.minor === "" ? n : t.minor
        }
      }
    ),
    /* @__PURE__ */ e(
      u,
      {
        label: "Menor a:",
        labelClass: "_text-xs",
        inputProps: {
          className: "_h-[24px] _border-none !_appearence-none",
          type: "date",
          id: "minor",
          onChange: a,
          value: t.minor,
          min: t.major,
          max: n
        }
      }
    ),
    /* @__PURE__ */ e(C.Button, { className: "_w-min _mx-auto", type: "submit", children: "Enviar" })
  ] });
};
export {
  me as FiltersBox
};
