import { jsxs as t, jsx as a } from "react/jsx-runtime";
import { memo as k, useRef as y, useCallback as i, useMemo as w } from "react";
import { f as N } from "../../../../CommandPrimitive-DexRxw-2.js";
import { COMMAND_VARIANT as o } from "../../constants/index.js";
import D from "../../utils/highlightMatch.js";
import m from "../../../box/Box.js";
import A from "../../../checkbox/Checkbox.js";
import p from "../../../text/Text.js";
import E from "../../../icon/Icon.js";
import I from "../../../avatar/Avatar.js";
import { c as S } from "../../../../index-BtlgVD4m.js";
const M = ({ item: e, variant: n, inputValue: h, onItemSelect: u, renderItem: c, commandValue: C }) => {
  const s = y(null), d = i((r) => {
    var l;
    r.key === "Enter" && (r.preventDefault(), (l = s.current) == null || l.click());
  }, []), f = i((r) => {
    r.stopPropagation();
  }, []), x = w(() => {
    const r = D(e.label, h), l = /* @__PURE__ */ a(p, { type: "small", as: "span", weight: "regular", truncate: !0, children: r }), g = /* @__PURE__ */ t(m, { className: "flex flex-col", children: [
      l,
      /* @__PURE__ */ a(p, { type: "xs", weight: "regular", color: "muted", truncate: !0, children: e.description })
    ] }), v = /* @__PURE__ */ t(m, { className: "flex flex-row items-center gap-[var(--spacing-2)]", children: [
      /* @__PURE__ */ a("div", { onClick: f, children: /* @__PURE__ */ a(A, { value: e.value, ref: s, "aria-label": e.label, onKeyDown: d }) }),
      c ? c(e) : /* @__PURE__ */ a(p, { type: "small", weight: "regular", truncate: !0, children: e.label })
    ] });
    return {
      [o.CHECKBOX]: v,
      [o.SIMPLE]: l,
      [o.DETAILED]: g,
      [o.CARD]: /* @__PURE__ */ t(m, { className: "flex flex-row items-start gap-[var(--spacing-2)]", children: [
        /* @__PURE__ */ a(I, { shape: "square", imageUrl: e.imageUrl, text: e.label }),
        g
      ] })
    }[n] || l;
  }, [n, h, e, c, d, f]), b = i(
    (r) => {
      u(r);
    },
    [u]
  );
  return /* @__PURE__ */ t(
    N,
    {
      htmlFor: String(e.value),
      keywords: [e.label, String(e.value)],
      value: C ?? String(e.value),
      onSelect: n === o.CHECKBOX ? () => {
        var r;
        return (r = s.current) == null ? void 0 : r.click();
      } : () => b(e),
      className: "p-0 pr-[var(--spacing-2)]",
      children: [
        /* @__PURE__ */ a("div", { className: "w-full px-[var(--spacing-2)] py-[var(--spacing-1-5)]", children: x }),
        /* @__PURE__ */ a(E, { name: "Check", size: 16, "aria-hidden": !0, className: S("ml-auto", e.selected ? "opacity-100" : "opacity-0") })
      ]
    },
    String(e.value)
  );
}, z = k(M);
export {
  z as default
};
//# sourceMappingURL=CommandItem.js.map
