import { jsxs as n, jsx as t } from "react/jsx-runtime";
import { useMemo as o, Fragment as $ } from "react";
import { c as x, d as A } from "../../../../CommandPrimitive-DexRxw-2.js";
import j from "../../../checkbox/components/checkbox-group/CheckboxGroup.js";
import h from "../../../box/Box.js";
import g from "../../../text/Text.js";
import u from "../command-item/CommandItem.js";
import _ from "../command-empty/CommandEmpty.js";
const D = ({
  value: i,
  groups: s,
  inputValue: l,
  selectedGroupRef: y,
  onCheckboxGroupChange: C,
  onItemSelect: d,
  onGroupClear: S,
  onGroupSelectAll: k,
  onClearAll: w,
  noResultsLabel: N,
  renderItem: p
}) => {
  const b = l !== "", m = "cursor-pointer bg-transparent border-none p-0 text-[length:var(--typography-base-sizes-extra-small-font-size)] leading-[var(--typography-base-sizes-extra-small-line-height)] text-[var(--base-highlight)]", c = o(() => new Set(i), [i]), r = o(
    () => s.flatMap((e) => e.items).filter((e) => e.value !== null && c.has(String(e.value))),
    [s, c]
  ), f = o(
    () => s.map((e) => ({
      hasSelection: e.items.some((a) => a.value !== null && c.has(String(a.value))),
      hasSelectableItems: e.items.some((a) => a.value !== null)
    })),
    [s, c]
  );
  return /* @__PURE__ */ n(j, { value: i, onChange: C, children: [
    !b && r.length > 0 && /* @__PURE__ */ n("div", { ref: y, children: [
      /* @__PURE__ */ n(h, { className: "flex items-center justify-between px-[var(--spacing-2)] py-[var(--spacing-1-5)]", children: [
        /* @__PURE__ */ t(g, { type: "xs", weight: "medium", color: "muted", children: "Ausgewählt" }),
        /* @__PURE__ */ t("button", { type: "button", className: m, onClick: w, children: "Aufheben" })
      ] }),
      /* @__PURE__ */ t(x, { children: r.map((e) => /* @__PURE__ */ t(
        u,
        {
          item: e,
          variant: "checkbox",
          inputValue: l,
          onItemSelect: d,
          renderItem: p,
          commandValue: `__selected__${String(e.value)}`
        },
        `selected-${e.value}`
      )) })
    ] }),
    s.map((e, a) => /* @__PURE__ */ n($, { children: [
      (a > 0 || !b && r.length > 0) && /* @__PURE__ */ t(A, {}),
      /* @__PURE__ */ n(h, { className: "flex items-center justify-between px-[var(--spacing-2)] py-[var(--spacing-1-5)]", children: [
        /* @__PURE__ */ t(g, { type: "xs", weight: "medium", color: "muted", children: e.heading }),
        /* @__PURE__ */ n(h, { className: "flex items-center gap-[var(--spacing-2)]", children: [
          f[a].hasSelection && /* @__PURE__ */ t("button", { type: "button", className: m, onClick: () => S(e), children: "Aufheben" }),
          f[a].hasSelectableItems && /* @__PURE__ */ t("button", { type: "button", className: m, onClick: () => k(e), children: "Alle wählen" })
        ] })
      ] }),
      /* @__PURE__ */ t(x, { children: e.items.map((v) => /* @__PURE__ */ t(
        u,
        {
          item: v,
          variant: "checkbox",
          inputValue: l,
          onItemSelect: d,
          renderItem: p
        },
        `${e.heading}-${v.value}`
      )) })
    ] }, `group-${e.heading}-${a}`)),
    /* @__PURE__ */ t(_, { inputValue: l, noResultsLabel: N })
  ] });
};
export {
  D as default
};
//# sourceMappingURL=CommandSelected.js.map
