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