import { jsx as o, jsxs as s } from "@emotion/react/jsx-runtime";
import { useModuleDictionary as g } from "@m4l/core";
import { useState as A, useCallback as a } from "react";
import { DICCTIONARY as c } from "../../dictionary.js";
import O from "../DynamicFilterBase/useDynamicFilterBase.js";
import R from "./useAppliedFilters.js";
import { useDynamicFilterStore as D } from "../../store/useDynamicFilterStore.js";
import { AppliedFiltersStyled as d, AppliedFilterInnerContainerStyled as E, ChipWrapperStyled as M, EmptyStateLabelStyled as k, OverflowMoreChipStyled as I } from "../../slots/dynamicFilterSlots.js";
import T from "../AppliedFilterChip/AppliedFilterChip.js";
import { Typography as _ } from "../../../extended/mui/Typography/Typography.js";
import x from "../FilterActions/FilterActions.js";
import P from "../OverflowPopover/OverflowPopover.js";
function K() {
  const { visibleFilters: l, overflowFilters: r, isSkeleton: f, parentRef: m, containerRef: h, setChipRef: u, setMoreChipRef: y, setActionsRef: v } = R(), { size: i } = O(), { getLabel: n } = g(), C = D((e) => e.actions.openPopoverMenuFields), [t, p] = A(null), F = a((e) => {
    p(e.currentTarget);
  }, []), S = a(() => {
    p(null);
  }, []);
  if (f)
    return /* @__PURE__ */ o(d, {});
  const w = l.length === 0 && r.length === 0;
  return /* @__PURE__ */ s(d, { ref: m, children: [
    /* @__PURE__ */ s(E, { ref: h, children: [
      l.map((e) => /* @__PURE__ */ o(
        M,
        {
          ref: (b) => u(e.id, b),
          ownerState: { isWarning: e.isSet && e.field.color === "warning" },
          children: /* @__PURE__ */ o(T, { ...e })
        },
        e.id
      )),
      w && /* @__PURE__ */ o(k, { "data-testid": "empty-state-label", component: "span", variant: "body", size: i, color: "inherit", onClick: C, children: n(c.label_no_filters_applied) })
    ] }),
    r.length > 0 && /* @__PURE__ */ o(
      I,
      {
        ref: y,
        size: i,
        variant: "contained",
        color: t ? "info" : "default",
        opacity: !0,
        dataTestId: "overflow-more-chip",
        ownerState: { selected: !!t },
        label: /* @__PURE__ */ o(_, { component: "span", variant: "bodyDens", size: i, color: "inherit", children: `${n(c.label_more)} (${r.length})` }),
        onClick: F
      }
    ),
    /* @__PURE__ */ o(x, { ref: v }),
    t && r.length > 0 && /* @__PURE__ */ o(
      P,
      {
        anchorEl: t,
        filters: r,
        onClose: S
      }
    )
  ] });
}
export {
  K as default
};
