import { at as Popover, dt as CommandGroup, ft as CommandItem, kn as cn, lt as Command, ot as PopoverAnchor, pt as CommandList, st as PopoverContent, ut as CommandEmpty } from "./src-CJw6JbdS.mjs";
import { useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { CheckIcon, ChevronDownIcon } from "lucide-react";
//#region ../../platform/ui-components/src/components/Combobox.tsx
function Combobox({ options, value, onValueChange, placeholder = "Select...", emptyText = "No results found.", disabled = false }) {
	const [open, setOpen] = useState(false);
	const [search, setSearch] = useState("");
	const selectedOption = options.find((opt) => opt.value === value);
	const filtered = search ? options.filter((opt) => opt.label.toLowerCase().includes(search.toLowerCase())) : options;
	return /* @__PURE__ */ jsx(Command, {
		className: "overflow-visible bg-transparent",
		children: /* @__PURE__ */ jsxs(Popover, {
			open,
			onOpenChange: setOpen,
			modal: true,
			children: [/* @__PURE__ */ jsx(PopoverAnchor, {
				asChild: true,
				children: /* @__PURE__ */ jsxs("div", {
					className: cn("border-input flex h-9 w-full items-center rounded-md border bg-transparent shadow-xs transition-[color,box-shadow]", open && "border-ring ring-ring/50 ring-[3px]", disabled && "cursor-not-allowed opacity-50"),
					children: [/* @__PURE__ */ jsx("input", {
						role: "combobox",
						"aria-expanded": open,
						disabled,
						placeholder: selectedOption ? selectedOption.label : placeholder,
						value: open ? search : "",
						className: cn("placeholder:text-foreground h-full w-full rounded-md bg-transparent px-3 text-sm outline-none disabled:cursor-not-allowed", !open && !selectedOption && "placeholder:text-muted-foreground"),
						onChange: (e) => {
							setSearch(e.target.value);
							if (!open) setOpen(true);
						},
						onClick: () => setOpen(true),
						onKeyDown: (e) => {
							if (e.key === "Escape") {
								setOpen(false);
								setSearch("");
							}
						}
					}), /* @__PURE__ */ jsx(ChevronDownIcon, { className: "mr-2 size-4 shrink-0 opacity-50" })]
				})
			}), /* @__PURE__ */ jsx(PopoverContent, {
				className: "bg-popover w-[var(--radix-popover-trigger-width)] rounded-md border p-0 shadow-md",
				align: "start",
				onOpenAutoFocus: (e) => e.preventDefault(),
				children: /* @__PURE__ */ jsxs(CommandList, { children: [filtered.length === 0 && /* @__PURE__ */ jsx(CommandEmpty, { children: emptyText }), /* @__PURE__ */ jsx(CommandGroup, { children: filtered.map((opt) => /* @__PURE__ */ jsxs(CommandItem, {
					value: opt.label,
					onSelect: () => {
						onValueChange(opt.value === value ? "" : opt.value);
						setOpen(false);
						setSearch("");
					},
					children: [opt.label, /* @__PURE__ */ jsx(CheckIcon, { className: cn("ml-auto size-4", value === opt.value ? "opacity-100" : "opacity-0") })]
				}, opt.value)) })] })
			})]
		})
	});
}
//#endregion
export { Combobox as t };

//# sourceMappingURL=Combobox-D8LKqQ19.mjs.map