import { jsxs as i, jsx as e, Fragment as _ } 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 p 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";
const K = ({ thead: n, isLastTh: a }) => {
  const [o, t] = N((l) => l.currentFilterColumn), [r, s] = b(null), [c, x] = b(null);
  v(
    () => {
      t((l) => {
        l.currentFilterColumn = void 0;
      });
    },
    null,
    [c, r]
  );
  const m = B(() => o == n.cellParam, [o]);
  return /* @__PURE__ */ i("div", { className: "_relative _z-60", children: [
    /* @__PURE__ */ e("div", { ref: s, "data-ignore-outside-clicks": !0, onClick: () => {
      t(m ? (l) => {
        l.currentFilterColumn = void 0;
      } : (l) => {
        l.currentFilterColumn = n.cellParam;
      });
    }, children: /* @__PURE__ */ e(p.SearchIcon, { className: "_ml-2 _w-4 _h-4 _cursor-pointer" }) }),
    /* @__PURE__ */ e(j, { children: /* @__PURE__ */ e(y, { condition: m, children: /* @__PURE__ */ i(
      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: n }),
          /* @__PURE__ */ e(V, { thead: n }),
          /* @__PURE__ */ e(k, { thead: n }),
          /* @__PURE__ */ e(T, { thead: n })
        ]
      }
    ) }) })
  ] });
}, S = ({ thead: n }) => {
  var l;
  const [a, o] = N((d) => d.metaDataPagination), { getCurrentFiltValue: t, simpleSetFilter: r } = I(), s = (d) => {
    r(n.cellParam, "contains", "text", d), d && o((h) => {
      h.metaDataPagination = {
        ...h.metaDataPagination,
        currentPage: 1
      };
    });
  }, { handleInput: c, loading: x, searchValue: m, removeSearchInput: g } = w(
    s,
    `${t(n.cellParam)}`
  );
  return ((l = n.filter) == null ? void 0 : l.type) !== "text" ? /* @__PURE__ */ e(_, {}) : /* @__PURE__ */ i("div", { className: "_px-1", children: [
    /* @__PURE__ */ e("label", { className: "_font-main _px-[5px] _text-[#4B4B4B] _text-sm", children: "Buscar" }),
    /* @__PURE__ */ i("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(p.LoadingIcon, { className: "_static" }) : /* @__PURE__ */ e("div", { className: "_h-4 _w-4" }),
      /* @__PURE__ */ e(y, { condition: !!m && !x, children: /* @__PURE__ */ e(p.XIcon, { className: "_text-red-500 _cursor-pointer", onClick: g }) })
    ] })
  ] });
}, V = ({ thead: n }) => {
  const { sortByParam: a, currentSortByParam: o } = D(), t = o(n.cellParam), r = t !== void 0, s = r ? !(t != null && t.desc) : !1, c = r ? t == null ? void 0 : t.desc : !1;
  return n.canSort ? /* @__PURE__ */ i(_, { children: [
    /* @__PURE__ */ e("p", { className: "_font-main _px-[5px] _text-[#4B4B4B] _text-sm", children: "Ordenar información" }),
    /* @__PURE__ */ i(
      "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(n.cellParam, !1);
        },
        children: [
          /* @__PURE__ */ e(p.AscIcon, {}),
          " Orden Ascendente"
        ]
      }
    ),
    /* @__PURE__ */ i(
      "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(n.cellParam, !0);
        },
        children: [
          /* @__PURE__ */ e(p.DescIcon, {}),
          " Orden Descendente"
        ]
      }
    )
  ] }) : /* @__PURE__ */ e(_, {});
}, k = ({ thead: n }) => {
  var r;
  const { changeFiltValue: a, sendValue: o, state: t } = F({ thead: n });
  return ((r = n.filter) == null ? void 0 : r.type) !== "ranged-number" ? /* @__PURE__ */ e(_, {}) : /* @__PURE__ */ i("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: n }) => {
  var s;
  const { changeFiltValue: a, sendValue: o, state: t } = F({ thead: n }), r = B(() => P().format("YYYY-MM-DD"), []);
  return ((s = n.filter) == null ? void 0 : s.type) !== "ranged-date" ? /* @__PURE__ */ e(_, {}) : /* @__PURE__ */ i("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 === "" ? r : 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: r
        }
      }
    ),
    /* @__PURE__ */ e(C.Button, { className: "_w-min _mx-auto", type: "submit", children: "Enviar" })
  ] });
};
export {
  K as FiltersBox
};
