import { jsx as e, jsxs as p } from "@emotion/react/jsx-runtime";
import { useModuleDictionary as T } from "@m4l/core";
import { useState as E, useCallback as s } from "react";
import { getPropDataTestId as I } from "../../../../test/getNameDataTestId.js";
import { DYNAMIC_SORT_KEY_COMPONENT as R } from "../../constants.js";
import { getDynamicSortDictionary as m, DICCTIONARY as c } from "../../dictionary.js";
import { DynamicSortSlots as _ } from "../../slots/SlotsEnum.js";
import M from "../DynamicSortBase/useDynamicSortBase.js";
import { useDynamicSortStore as k } from "../../store/useDynamicSortStore.js";
import N from "./useAppliedSorts.js";
import { AppliedSortsStyled as f, AppliedSortInnerContainerStyled as P, ChipSortWrapperStyled as x, EmptyStateLabelStyled as Y, OverflowMoreChipStyled as j } from "../../slots/DynamicSortSlots.js";
import L from "../AppliedSortChip/AppliedSortChip.js";
import { Typography as $ } from "../../../extended/mui/Typography/Typography.js";
import z from "../SortActions/SortActions.js";
import B from "../OverflowSortPopover/OverflowSortPopover.js";
function re() {
  const {
    visibleSorts: i,
    overflowSorts: t,
    isSkeleton: d,
    parentRef: S,
    containerRef: h,
    setChipRef: y,
    setMoreChipRef: u,
    setActionsRef: C
  } = N(), { dataTestId: v, ownerState: w, size: n } = M(), { getLabel: l } = T(), { openPopoverMenuFields: A } = k((o) => o.actions), [r, a] = E(null), b = s((o) => {
    a(o.currentTarget);
  }, []), g = s(() => {
    a(null);
  }, []);
  if (d)
    return /* @__PURE__ */ e(f, {});
  const D = i.length === 0 && t.length === 0;
  return /* @__PURE__ */ p(
    f,
    {
      ref: S,
      ...I(R, _.appliedSorts, v),
      ownerState: { ...w },
      children: [
        /* @__PURE__ */ p(P, { ref: h, children: [
          i.map((o) => /* @__PURE__ */ e(
            x,
            {
              ref: (O) => y(o.id, O),
              children: /* @__PURE__ */ e(L, { ...o })
            },
            o.id
          )),
          D && /* @__PURE__ */ e(
            Y,
            {
              "data-testid": "empty-state-label",
              component: "span",
              variant: "body",
              size: n,
              color: "inherit",
              onClick: A,
              children: l(m(c.label_no_sorts_applied))
            }
          )
        ] }),
        t.length > 0 && /* @__PURE__ */ e(
          j,
          {
            ref: u,
            size: n,
            variant: "contained",
            color: r ? "info" : "default",
            opacity: !0,
            dataTestId: "overflow-more-chip",
            ownerState: { selected: !!r },
            label: /* @__PURE__ */ e($, { component: "span", variant: "bodyDens", size: n, color: "inherit", children: `${l(m(c.label_more))} (${t.length})` }),
            onClick: b
          }
        ),
        /* @__PURE__ */ e(z, { ref: C }),
        r && t.length > 0 && /* @__PURE__ */ e(
          B,
          {
            anchorEl: r,
            sorts: t,
            onClose: g
          }
        )
      ]
    }
  );
}
export {
  re as default
};
