import { a as ne, b as ae } from "../../CommandPrimitive-DexRxw-2.js";
import { jsx as e, jsxs as v } from "react/jsx-runtime";
import { useRef as X, useMemo as te, Fragment as me } from "react";
import { COMMAND_VARIANT as _, BOX_SHADOW_STYLE as j } from "./constants/index.js";
import { useCommandState as de } from "./hooks/useCommandState.js";
import { useCommandInput as le } from "./hooks/useCommandInput.js";
import { useCommandSelection as se } from "./hooks/useCommandSelection.js";
import ue from "./components/command-loading/CommandLoading.js";
import ce from "./components/command-selected/CommandSelected.js";
import pe from "./components/command-content/CommandContent.js";
import be from "./components/command-empty/CommandEmpty.js";
import K from "../box/Box.js";
import ie from "../select/Select.js";
import $ from "./components/command-input/CommandInput.js";
import { Popover as Ce, PopoverAnchor as he, PopoverContent as fe } from "../popover/PopoverPrimitive.js";
import { c as S } from "../../index-BtlgVD4m.js";
const Ee = ({
  value: m,
  groups: s,
  loop: W,
  placeholder: x,
  maxLength: g,
  onValueChange: Y,
  defaultValue: q,
  shouldFilter: z,
  openOnFocus: J,
  variant: n = "simple",
  isLoading: A,
  loadingLabel: N,
  noResultsLabel: u,
  showLoadingOnType: d,
  hideContent: O,
  onItemSelect: P,
  onDebouncedValueChange: Q,
  delay: U,
  searchConfig: V,
  filter: Z,
  footer: c,
  isPopover: r = !1,
  selectionConfig: a,
  renderItem: p,
  inputType: F,
  disabled: b = !1,
  ref: T
}) => {
  const G = X(null), I = X(null), { open: o, setOpen: i, isPending: B, setIsPending: L, valueState: t, setValueState: w, availableRef: ee, inputRef: re } = de({
    value: m,
    defaultValue: q,
    onValueChange: Y,
    variant: n,
    showLoadingOnType: d,
    onDebouncedValueChange: Q,
    delay: U,
    isPopover: r,
    ref: T
  }), { handleInputOnValueChange: y, handleInputOnFocus: D } = le({
    open: o,
    setOpen: i,
    setValueState: w,
    setIsPending: L,
    showLoadingOnType: d,
    openOnFocus: J
  }), { handleContentItemOnSelect: C, handleCheckboxGroupChange: k, handleGroupSelectAll: E, handleGroupClear: M, handleClearAll: R } = se({
    value: m,
    variant: n,
    setValueState: w,
    setOpen: i,
    onItemSelect: P,
    commandListRef: I,
    selectedGroupRef: G
  }), oe = te(() => A || d && B ? /* @__PURE__ */ e(ue, { loadingLabel: N }) : n === _.CHECKBOX ? /* @__PURE__ */ e(
    ce,
    {
      value: m ?? [],
      groups: s,
      inputValue: t,
      selectedGroupRef: G,
      onCheckboxGroupChange: k,
      onItemSelect: C,
      onGroupClear: M,
      onGroupSelectAll: E,
      onClearAll: R,
      noResultsLabel: u,
      renderItem: p
    }
  ) : /* @__PURE__ */ v(me, { children: [
    /* @__PURE__ */ e(
      pe,
      {
        groups: s,
        variant: n,
        inputValue: t,
        checkboxValue: n === _.CHECKBOX ? m : [],
        onItemSelect: C,
        renderItem: p
      }
    ),
    /* @__PURE__ */ e(be, { inputValue: t, noResultsLabel: u })
  ] }), [
    A,
    d,
    B,
    s,
    n,
    t,
    m,
    C,
    k,
    E,
    M,
    R,
    u,
    N,
    p
  ]), l = "rounded-[var(--border-radius-lg)]", h = "rounded-t-[var(--border-radius-lg)]", H = /* @__PURE__ */ v(
    "div",
    {
      className: S(
        "bg-[var(--base-background)]",
        r ? l : "border border-[var(--base-border)] rounded-b-[var(--border-radius-lg)]"
      ),
      style: { boxShadow: j },
      children: [
        (a == null ? void 0 : a.enabled) && /* @__PURE__ */ e(K, { className: "p-[var(--spacing-2)] pb-0", children: /* @__PURE__ */ e(ie, { isPortal: !1, options: a.options, onChange: a.onSelect, value: a.value }) }),
        r && /* @__PURE__ */ e(
          $,
          {
            ref: re,
            maxLength: g,
            placeholder: x,
            value: t,
            onValueChange: y,
            onFocus: D,
            searchConfig: V,
            showFocusBorder: !0,
            className: S("border-b border-b-[var(--base-border)]", O && !c ? l : h),
            type: F,
            disabled: b
          }
        ),
        !O && /* @__PURE__ */ e(
          ne,
          {
            ref: I,
            className: "text-popover-foreground outline-none animate-in mt-[var(--spacing-1)]",
            onMouseDown: (f) => f.preventDefault(),
            children: oe
          }
        ),
        c && /* @__PURE__ */ e(K, { className: "px-[var(--spacing-3)] py-[var(--spacing-2)] border-t border-[var(--base-border)] bg-[var(--base-muted)] rounded-b-[var(--border-radius-lg)]", children: c })
      ]
    }
  );
  return /* @__PURE__ */ e(Ce, { open: o, onOpenChange: i, children: /* @__PURE__ */ e(he, { asChild: !0, children: /* @__PURE__ */ v(
    ae,
    {
      shouldFilter: z,
      loop: W,
      filter: Z,
      style: o ? { boxShadow: j } : void 0,
      ref: ee,
      className: S(
        o && !r ? `rounded-none ${h}` : l,
        b && "opacity-50 cursor-not-allowed pointer-events-none"
      ),
      children: [
        !r && /* @__PURE__ */ e(
          $,
          {
            maxLength: g,
            placeholder: x,
            value: t,
            onValueChange: y,
            onFocus: D,
            searchConfig: V,
            showFocusBorder: o,
            className: o ? h : l,
            type: F,
            disabled: b
          }
        ),
        r && H,
        !r && o && /* @__PURE__ */ e(
          fe,
          {
            className: "!p-0",
            side: "bottom",
            align: "start",
            sideOffset: 0,
            onOpenAutoFocus: (f) => f.preventDefault(),
            style: { width: "var(--radix-popover-trigger-width)" },
            children: H
          }
        )
      ]
    }
  ) }) });
};
export {
  Ee as default
};
//# sourceMappingURL=Command.js.map
