import { jsxs as a, jsx as e } from "react/jsx-runtime";
import { useMemo as h } from "react";
import { a as x } from "../../../../useQuery-n4ls1rLk.js";
import { a as y } from "../../../../axios-f2q_J-wz.js";
import C from "../../../Icons.js";
import { C as F } from "../../../../index-OHO5PlsB.js";
import { useTableContext as T } from "../../context/index.js";
import { useManagementFilter as g } from "../../context/useCases.js";
import { cn as m, createUrlWithQueryParams as w } from "../../../../utils/functions.js";
import { RenderEach as A } from "../../../../utils/components/RenderEach.js";
import { RenderIf as v } from "../../../../utils/components/RenderIf.js";
import { A as N } from "../../../../index-T7wQHOux.js";
import { m as E } from "../../../../motion-dVICNqWI.js";
import "../../../../clsx-7d8NmkQq.js";
import "../../../Inputs/variants.js";
import "../../../../index-xVF7D3FM.js";
import "../../../../context/index.js";
import "../../hooks/usePaginationSelector.js";
import "../../../../LayoutGroupContext-3euHzeKi.js";
import "../../../../SVGVisualElement-aqO4D4Z5.js";
import "../../../../use-unmount-effect-Wy5iLAex.js";
const Z = ({ requestType: i, thLabel: t, className: o, cellParam: n, isLastTh: s, ...c }) => /* @__PURE__ */ a("div", { className: m("_flex _justify-between _items-center _py-3.5 _px-5", o), children: [
  t,
  /* @__PURE__ */ e(S, { cellParam: n, isLastTh: s, ...c })
] }), S = ({ cellParam: i, isLastTh: t, ...o }) => {
  const [n, s] = T((l) => l.currentFilterColumn), c = h(() => n == i, [n]), r = () => {
    s(c ? (l) => {
      l.currentFilterColumn = void 0;
    } : (l) => {
      l.currentFilterColumn = i;
    });
  };
  return /* @__PURE__ */ a("div", { className: "_relative", children: [
    /* @__PURE__ */ e(C.SearchIcon, { onClick: r, className: "_w-4 _h-4 _cursor-pointer" }),
    /* @__PURE__ */ e(N, { children: /* @__PURE__ */ e(v, { condition: c, children: /* @__PURE__ */ e(
      E.div,
      {
        className: m(
          "_absolute _p-1 _rounded-md _shadow-lg _top-5 !_left-1/2 !-_translate-x-1/2 _bg-white _z-10 _w-max _py-2 _flex _flex-col _gap-2",
          { "!-_left-24": t }
        ),
        initial: { opacity: 0, y: -10 },
        animate: { opacity: 1, y: 0 },
        exit: { opacity: 0, y: -10 },
        children: /* @__PURE__ */ e(G, { cellParam: i, ...o })
      }
    ) }) })
  ] });
}, G = ({
  url: i,
  customHeaders: t,
  payload: o,
  targetId: n,
  targetItemId: s,
  cellParam: c
}) => {
  const { data: r, isLoading: l, isError: p, isFetching: u } = x({
    queryKey: ["Group-rest", i],
    queryFn: async () => {
      const d = w(i, o), _ = y.create({
        headers: {
          "Content-Type": "application/json",
          "Access-Control-Allow-Origin": "*",
          "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
          "Access-Control-Allow-Credentials": !0,
          "Access-Control-Allow-Headers": "*",
          ...t
        }
      }), { data: f } = await _.get(d.href);
      return f[n];
    }
  });
  return l || u ? /* @__PURE__ */ e("div", { children: "Loading..." }) : p ? /* @__PURE__ */ e("div", { children: "Error" }) : r ? /* @__PURE__ */ e(O, { data: r, cellParam: c, targetItemId: s }) : /* @__PURE__ */ e("div", { children: "No data" });
}, O = ({ data: i, cellParam: t, targetItemId: o }) => {
  const { simpleSetFilter: n, getCurrentFiltValue: s } = g(), c = (r) => {
    s(t) == r ? n(t, "=", "text", "") : n(t, "=", "text", r);
  };
  return /* @__PURE__ */ e("div", { className: "_flex _flex-col _gap-2", children: /* @__PURE__ */ e(
    A,
    {
      of: i,
      render: (r) => /* @__PURE__ */ a("div", { className: "_flex _gap-0.5 _items-center", children: [
        /* @__PURE__ */ e(
          F,
          {
            inputProps: {
              onChange: () => {
                c(r[o]);
              },
              checked: s(t) == r[o]
            },
            className: "_h-4 _w-4"
          }
        ),
        /* @__PURE__ */ e("label", { className: "_text-sm _font-main _font-medium", children: r[o] })
      ] }, r[o])
    }
  ) });
};
export {
  Z as default
};
