import { o as et } from "./rolldown-runtime.js";
import { i as at, t as ot } from "./vendor/react.js";
import { t as nt } from "./check.js";
import { t as rt } from "./search.js";
import { t as O } from "./Button.js";
import { t as P } from "./dist.js";
import { n as st, t as d } from "./utils.js";
import { t as it } from "./create-safe-context.js";
import { t as dt } from "./input3.js";
import { t as lt } from "./textarea.js";
import { t as ut } from "./close-button.js";
import { c as ct, d as G, f as mt, n as pt, r as gt, s as ft, t as xt, u as ht } from "./DialogTrigger.js";
var i = /* @__PURE__ */ et(at(), 1), a = ot();
function A({ ...t }) {
  return /* @__PURE__ */ (0, a.jsx)(gt, {
    "data-slot": "dialog",
    ...t
  });
}
function B({ ...t }) {
  return /* @__PURE__ */ (0, a.jsx)(xt, {
    "data-slot": "dialog-trigger",
    ...t
  });
}
function S({ ...t }) {
  return /* @__PURE__ */ (0, a.jsx)(ft, {
    "data-slot": "dialog-portal",
    ...t
  });
}
function $({ ...t }) {
  return /* @__PURE__ */ (0, a.jsx)(G, {
    "data-slot": "dialog-close",
    ...t
  });
}
function T({ className: t, disableAnimation: e, disableBackdropBlur: n, ...r }) {
  return /* @__PURE__ */ (0, a.jsx)(mt, {
    "data-slot": "dialog-overlay",
    className: d("bg-background/80/10 fixed inset-0 isolate z-50", !e && "data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 duration-100", !n && "supports-backdrop-filter:backdrop-blur-xs", t),
    ...r
  });
}
function V({ className: t, children: e, showCloseButton: n = !0, initialFocus: r, disableAnimation: s, disableBackdropBlur: m, ...u }) {
  return /* @__PURE__ */ (0, a.jsxs)(S, { children: [/* @__PURE__ */ (0, a.jsx)(T, {
    disableAnimation: s,
    disableBackdropBlur: m
  }), /* @__PURE__ */ (0, a.jsxs)(ct, {
    "data-slot": "dialog-content",
    className: d("bg-background ring-foreground/10 grid max-w-[calc(100%-2rem)] gap-6 rounded-xl p-6 text-sm ring-1 sm:max-w-md fixed top-1/2 left-1/2 z-50 w-full -translate-x-1/2 -translate-y-1/2 outline-none", !s && "data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 duration-100", t),
    ...u,
    children: [e, n && /* @__PURE__ */ (0, a.jsx)(G, { render: /* @__PURE__ */ (0, a.jsx)(ut, { className: "absolute top-4 end-4" }) })]
  })] });
}
function E({ className: t, ...e }) {
  return /* @__PURE__ */ (0, a.jsx)("div", {
    "data-slot": "dialog-header",
    className: d("gap-2 flex flex-col", t),
    ...e
  });
}
function F({ className: t, showCloseButton: e = !1, children: n, ...r }) {
  return /* @__PURE__ */ (0, a.jsxs)("div", {
    "data-slot": "dialog-footer",
    className: d("gap-2 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", t),
    ...r,
    children: [n, e && /* @__PURE__ */ (0, a.jsx)(G, {
      render: /* @__PURE__ */ (0, a.jsx)(O, {
        appearance: "outline",
        variant: "secondary"
      }),
      children: "Close"
    })]
  });
}
function K({ className: t, ...e }) {
  return /* @__PURE__ */ (0, a.jsx)(pt, {
    "data-slot": "dialog-title",
    className: d("leading-none font-medium", t),
    ...e
  });
}
function M({ className: t, ...e }) {
  return /* @__PURE__ */ (0, a.jsx)(ht, {
    "data-slot": "dialog-description",
    className: d("text-muted-foreground *:[a]:hover:text-foreground text-sm *:[a]:underline *:[a]:underline-offset-3", t),
    ...e
  });
}
B.displayName = "Dialog.Trigger";
S.displayName = "Dialog.Portal";
$.displayName = "Dialog.Close";
T.displayName = "Dialog.Overlay";
V.displayName = "Dialog.Content";
E.displayName = "Dialog.Header";
F.displayName = "Dialog.Footer";
K.displayName = "Dialog.Title";
M.displayName = "Dialog.Description";
A.displayName = "Dialog";
var bt = Object.assign(A, {
  Trigger: B,
  Portal: S,
  Close: $,
  Overlay: T,
  Content: V,
  Header: E,
  Footer: F,
  Title: K,
  Description: M
});
function L({ className: t, ...e }) {
  return /* @__PURE__ */ (0, a.jsx)("div", {
    "data-slot": "input-group",
    role: "group",
    className: d("border-input dark:bg-input/30 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 h-9 rounded-md border shadow-xs transition-[color,box-shadow] duration-200 ease-smooth motion-reduce:transition-none has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot][aria-invalid=true]]:ring-[3px] has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pe-1.5 has-[>[data-align=inline-start]]:[&>input]:ps-1.5 [[data-slot=combobox-content]_&]:focus-within:border-inherit [[data-slot=combobox-content]_&]:focus-within:ring-0 group/input-group relative flex w-full min-w-0 items-center outline-none has-[>textarea]:h-auto", t),
    ...e
  });
}
var vt = P("text-muted-foreground h-auto gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4 flex cursor-text items-center justify-center select-none", {
  variants: { align: {
    "inline-start": "ps-2 has-[>button]:ms-[-0.25rem] has-[>kbd]:ms-[-0.15rem] order-first",
    "inline-end": "pe-2 has-[>button]:me-[-0.25rem] has-[>kbd]:me-[-0.15rem] order-last",
    "block-start": "px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2 order-first w-full justify-start",
    "block-end": "px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2 order-last w-full justify-start"
  } },
  defaultVariants: { align: "inline-start" }
});
function H({ className: t, align: e = "inline-start", ...n }) {
  return /* @__PURE__ */ (0, a.jsx)("div", {
    role: "group",
    "data-slot": "input-group-addon",
    "data-align": e,
    className: d(vt({ align: e }), t),
    onClick: (r) => {
      r.target.closest("button") || r.currentTarget.parentElement?.querySelector("input")?.focus();
    },
    ...n
  });
}
var yt = P("gap-2 text-sm shadow-none flex items-center", {
  variants: { size: {
    xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
    sm: "",
    "icon-xs": "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
    "icon-sm": "size-8 p-0 has-[>svg]:p-0"
  } },
  defaultVariants: { size: "xs" }
});
function kt({ className: t, type: e = "button", appearance: n = "ghost", variant: r = "secondary", size: s = "xs", ...m }) {
  return /* @__PURE__ */ (0, a.jsx)(O, {
    type: e,
    "data-size": s,
    appearance: n,
    variant: r,
    className: d(yt({ size: s }), t),
    ...m
  });
}
function Nt({ className: t, ...e }) {
  return /* @__PURE__ */ (0, a.jsx)("span", {
    className: d("text-muted-foreground gap-2 text-sm [&_svg:not([class*='size-'])]:size-4 flex items-center [&_svg]:pointer-events-none", t),
    ...e
  });
}
function jt({ className: t, ...e }) {
  return /* @__PURE__ */ (0, a.jsx)(dt, {
    "data-slot": "input-group-control",
    className: d("rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent flex-1", t),
    ...e
  });
}
function Ct({ className: t, ...e }) {
  return /* @__PURE__ */ (0, a.jsx)(lt, {
    "data-slot": "input-group-control",
    className: d("rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent flex-1 resize-none", t),
    ...e
  });
}
L.displayName = "InputGroup";
H.displayName = "InputGroupAddon";
kt.displayName = "InputGroupButton";
Nt.displayName = "InputGroupText";
jt.displayName = "InputGroupInput";
Ct.displayName = "InputGroupTextarea";
var [Dt, z] = it("Command");
function It(t, e) {
  const n = t.toLowerCase(), r = e.toLowerCase().trim();
  return r ? n.includes(r) ? 1 : 0 : 1;
}
function w(t, e) {
  return (n) => {
    t?.(n), !n?.defaultPrevented && e(n);
  };
}
function q({ className: t, filter: e, children: n, ...r }) {
  const [s, m] = i.useState(""), [u, p] = i.useState(null), v = i.useId(), g = i.useRef(/* @__PURE__ */ new Map()), [y, b] = i.useState(0), k = i.useCallback((o) => (g.current.set(o.id, o), b((f) => f + 1), () => {
    g.current.delete(o.id), b((f) => f + 1);
  }), []), j = i.useCallback((o, f) => {
    const x = g.current.get(o);
    if (!x) return;
    const _ = {
      ...x,
      ...f
    };
    g.current.set(o, _), (x.value !== _.value || x.disabled !== _.disabled || x.searchValue !== _.searchValue) && b((tt) => tt + 1);
  }, []), C = e ?? It, c = i.useCallback((o) => s.trim() ? C(o.searchValue || o.value, s) > 0 : !0, [C, s]), l = i.useMemo(() => {
    const o = [];
    for (const [f, x] of g.current)
      x.disabled || c(x) && o.push(f);
    return o;
  }, [c, y]), h = i.useMemo(() => {
    let o = 0;
    for (const f of g.current.values()) c(f) && (o += 1);
    return o;
  }, [c, y]), N = i.useCallback(() => {
    if (!u) return;
    const o = g.current.get(u);
    !o || o.disabled || !c(o) || o.onSelect?.(o.value);
  }, [u, c]);
  i.useEffect(() => {
    if (l.length === 0) {
      p(null);
      return;
    }
    (!u || !l.includes(u)) && p(l[0]);
  }, [u, l]);
  const D = i.useCallback((o) => {
    if (l.length === 0) return;
    const f = u ? l.indexOf(u) : -1;
    if (o.key === "ArrowDown") {
      o.preventDefault();
      const x = l[Math.min(f + 1, l.length - 1)];
      p(x);
      return;
    }
    if (o.key === "ArrowUp") {
      o.preventDefault();
      const x = l[Math.max(f - 1, 0)];
      p(x);
      return;
    }
    if (o.key === "Home") {
      o.preventDefault(), p(l[0]);
      return;
    }
    if (o.key === "End") {
      o.preventDefault(), p(l[l.length - 1]);
      return;
    }
    if (o.key === "Enter") {
      if (o.metaKey || o.ctrlKey || o.altKey || o.shiftKey) return;
      o.preventDefault(), N();
    }
  }, [
    u,
    N,
    l
  ]), I = i.useMemo(() => ({
    search: s,
    setSearch: m,
    filter: e,
    activeId: u,
    setActiveId: p,
    registerItem: k,
    updateItem: j,
    getItemVisibility: c,
    visibleEnabledItemIds: l,
    visibleItemCount: h,
    onKeyDown: D,
    selectActiveItem: N,
    listId: v
  }), [
    u,
    e,
    c,
    D,
    v,
    k,
    s,
    N,
    j,
    l,
    h
  ]);
  return /* @__PURE__ */ (0, a.jsx)(Dt.Provider, {
    value: I,
    children: /* @__PURE__ */ (0, a.jsxs)("div", {
      "data-slot": "command",
      "cmdk-root": "",
      className: d("bg-popover text-popover-foreground rounded-xl! p-1 flex size-full flex-col overflow-hidden", t),
      ...r,
      children: [n, /* @__PURE__ */ (0, a.jsx)("div", {
        className: "sr-only",
        "aria-live": "polite",
        "aria-atomic": "true",
        role: "status",
        children: s.trim() ? h === 0 ? "No results found" : `${h} result${h === 1 ? "" : "s"} available` : ""
      })]
    })
  });
}
function R({ title: t = "Command Palette", description: e = "Search for a command to run...", children: n, className: r, showCloseButton: s = !1, ...m }) {
  return /* @__PURE__ */ (0, a.jsxs)(bt, {
    ...m,
    children: [/* @__PURE__ */ (0, a.jsxs)(E, {
      className: "sr-only",
      children: [/* @__PURE__ */ (0, a.jsx)(K, { children: t }), /* @__PURE__ */ (0, a.jsx)(M, { children: e })]
    }), /* @__PURE__ */ (0, a.jsx)(V, {
      className: d("rounded-xl! overflow-hidden p-0", r),
      showCloseButton: s,
      children: n
    })]
  });
}
function U({ className: t, render: e, onChange: n, onKeyDown: r, ...s }) {
  const { onKeyDown: m, search: u, setSearch: p, listId: v, activeId: g } = z(), y = w(n, i.useCallback((k) => {
    p(k.target.value);
  }, [p])), b = w(r, m);
  return e ? e({
    "data-slot": "command-input",
    "cmdk-input": "",
    role: "combobox",
    "aria-expanded": !0,
    "aria-autocomplete": "list",
    "aria-controls": v,
    "aria-activedescendant": g || void 0,
    value: u,
    onChange: y,
    onKeyDown: b
  }) : /* @__PURE__ */ (0, a.jsx)("div", {
    "data-slot": "command-input-wrapper",
    "cmdk-input-wrapper": "",
    className: "p-1 pb-0",
    children: /* @__PURE__ */ (0, a.jsxs)(L, {
      className: "bg-input/30 border-input/30 h-8! rounded-lg! shadow-none! *:data-[slot=input-group-addon]:ps-2!",
      children: [/* @__PURE__ */ (0, a.jsx)("input", {
        "data-slot": "command-input",
        "cmdk-input": "",
        role: "combobox",
        "aria-expanded": !0,
        "aria-autocomplete": "list",
        "aria-controls": v,
        "aria-activedescendant": g || void 0,
        className: d("w-full text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50", t),
        value: u,
        onChange: y,
        onKeyDown: b,
        ...s
      }), /* @__PURE__ */ (0, a.jsx)(H, { children: /* @__PURE__ */ (0, a.jsx)(rt, { className: "size-4 shrink-0 opacity-50" }) })]
    })
  });
}
function J({ className: t, ...e }) {
  const { listId: n } = z();
  return /* @__PURE__ */ (0, a.jsx)("div", {
    "data-slot": "command-list",
    "cmdk-list": "",
    role: "listbox",
    id: n,
    className: d("no-scrollbar max-h-72 scroll-py-1 outline-none overflow-x-hidden overflow-y-auto", t),
    ...e
  });
}
function Q({ className: t, ...e }) {
  const { visibleItemCount: n } = z();
  return n > 0 ? null : /* @__PURE__ */ (0, a.jsx)("div", {
    "data-slot": "command-empty",
    "cmdk-empty": "",
    className: d("py-6 text-center text-sm", t),
    ...e
  });
}
function W({ className: t, heading: e, children: n, ...r }) {
  const s = i.useId();
  return /* @__PURE__ */ (0, a.jsxs)("div", {
    "data-slot": "command-group",
    "cmdk-group": "",
    role: "group",
    "aria-labelledby": e != null ? s : void 0,
    className: d("text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-semibold [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wider", t),
    ...r,
    children: [e != null && /* @__PURE__ */ (0, a.jsx)("div", {
      "cmdk-group-heading": "",
      id: s,
      children: e
    }), n]
  });
}
function X({ className: t, ...e }) {
  return /* @__PURE__ */ (0, a.jsx)("hr", {
    "data-slot": "command-separator",
    "cmdk-separator": "",
    className: d("bg-border -mx-1 h-px w-auto", t),
    ...e
  });
}
function Y({ className: t, children: e, value: n, disabled: r = !1, onSelect: s, keywords: m, onClick: u, onKeyDown: p, onMouseMove: v, ...g }) {
  const { activeId: y, getItemVisibility: b, registerItem: k, setActiveId: j, updateItem: C } = z(), c = i.useId(), l = i.useMemo(() => [
    n,
    m?.join(" ") ?? "",
    st(e)
  ].filter(Boolean).join(" "), [
    e,
    m,
    n
  ]), h = b({
    value: n,
    searchValue: l
  }), N = y === c;
  i.useLayoutEffect(() => k({
    id: c,
    value: "",
    disabled: !1,
    searchValue: ""
  }), [c, k]), i.useEffect(() => {
    C(c, {
      value: n,
      disabled: r,
      onSelect: s,
      searchValue: l
    });
  }, [
    r,
    c,
    s,
    l,
    C,
    n
  ]);
  const D = i.useCallback(() => {
    r || !h || s?.(n);
  }, [
    r,
    s,
    n,
    h
  ]);
  return /* @__PURE__ */ (0, a.jsxs)("div", {
    id: c,
    "data-slot": "command-item",
    "cmdk-item": "",
    "data-disabled": r,
    "data-selected": N,
    role: "option",
    "aria-selected": N,
    "aria-disabled": r,
    hidden: !h,
    tabIndex: -1,
    className: d("data-selected:bg-muted data-selected:text-foreground data-selected:**:[svg]:text-foreground border-l-2 border-l-transparent data-selected:border-l-brand-500 relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none transition-colors duration-150 [&_svg:not([class*='size-'])]:size-4 [[data-slot=dialog-content]_&]:rounded-lg! group/command-item data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0", t),
    onMouseMove: w(v, () => j(c)),
    onClick: w(u, () => {
      j(c), D();
    }),
    onKeyDown: w(p, (I) => {
      r || !h || I.key !== "Enter" && I.key !== " " || (I.preventDefault(), j(c), D());
    }),
    ...g,
    children: [e, /* @__PURE__ */ (0, a.jsx)(nt, { className: "ms-auto opacity-0 group-has-[[data-slot=command-shortcut]]/command-item:hidden group-data-[checked=true]/command-item:opacity-100" })]
  });
}
function Z({ className: t, ...e }) {
  return /* @__PURE__ */ (0, a.jsx)("span", {
    "data-slot": "command-shortcut",
    className: d("text-muted-foreground group-data-selected/command-item:text-foreground ms-auto text-xs tracking-widest", t),
    ...e
  });
}
R.displayName = "Command.Dialog";
U.displayName = "Command.Input";
J.displayName = "Command.List";
Q.displayName = "Command.Empty";
W.displayName = "Command.Group";
X.displayName = "Command.Separator";
Y.displayName = "Command.Item";
Z.displayName = "Command.Shortcut";
q.displayName = "Command";
var At = Object.assign(q, {
  Dialog: R,
  Input: U,
  List: J,
  Empty: Q,
  Group: W,
  Separator: X,
  Item: Y,
  Shortcut: Z
});
export {
  Y as a,
  X as c,
  U as i,
  Q as n,
  J as o,
  W as r,
  At as s,
  R as t
};

//# sourceMappingURL=command.js.map