"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const React = require('react');
const index = require('../../../../node_modules/.pnpm/@radix-ui_react-popover@1.1.15_@types_react-dom@19.2.3_@types_react@19.2.6__@types_reac_5c5a3ca63b34dfe7d9d23f1e8cee675c/node_modules/@radix-ui/react-popover/dist/index.cjs');
const LucideIcons = require('lucide-react');
const utils = require('../lib/utils.cjs');
const button = require('./button.cjs');
const command = require('./command.cjs');
const popover = require('./popover.cjs');

function SearchSelect({
  options,
  value,
  onChange,
  placeholder = "Select option",
  emptyMessage = "No option found."
}) {
  const id = React.useId();
  const [open, setOpen] = React.useState(false);
  return /* @__PURE__ */ jsxRuntime.jsxs(popover.Popover, { open, onOpenChange: setOpen, modal: false, children: [
    /* @__PURE__ */ jsxRuntime.jsx(popover.PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
      button.Button,
      {
        id,
        variant: "outline",
        role: "combobox",
        "aria-expanded": open,
        className: "bg-background hover:bg-background border-input w-full justify-between px-3 font-normal outline-offset-0 outline-none focus-visible:outline-[3px]",
        children: [
          /* @__PURE__ */ jsxRuntime.jsx("span", { className: utils.cn("truncate", !value && "text-muted-foreground"), children: value ? options.find((option) => option.value === value)?.label : placeholder }),
          /* @__PURE__ */ jsxRuntime.jsx(
            LucideIcons.ChevronDownIcon,
            {
              size: 16,
              className: "text-muted-foreground/80 shrink-0",
              "aria-hidden": "true"
            }
          )
        ]
      }
    ) }),
    /* @__PURE__ */ jsxRuntime.jsx(
      index.Content,
      {
        align: "start",
        sideOffset: 4,
        className: utils.cn(
          "border-input bg-popover text-popover-foreground pointer-events-auto",
          "data-[state=open]:animate-in data-[state=closed]:animate-out",
          "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
          "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
          "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2",
          "data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
          "z-50 w-full min-w-[var(--radix-popper-anchor-width)] origin-(--radix-popover-content-transform-origin)",
          "rounded-md border p-0 shadow-md outline-hidden"
        ),
        children: /* @__PURE__ */ jsxRuntime.jsxs(command.Command, { children: [
          /* @__PURE__ */ jsxRuntime.jsx(command.CommandInput, { placeholder: "Search options..." }),
          /* @__PURE__ */ jsxRuntime.jsxs(command.CommandList, { children: [
            /* @__PURE__ */ jsxRuntime.jsx(command.CommandEmpty, { children: emptyMessage }),
            /* @__PURE__ */ jsxRuntime.jsx(command.CommandGroup, { children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsxs(
              command.CommandItem,
              {
                value: option.value,
                onSelect: (currentValue) => {
                  onChange(currentValue === value ? "" : currentValue);
                  setOpen(false);
                },
                children: [
                  option.label,
                  value === option.value && /* @__PURE__ */ jsxRuntime.jsx(LucideIcons.CheckIcon, { size: 16, className: "ml-auto" })
                ]
              },
              option.value
            )) })
          ] })
        ] })
      }
    )
  ] });
}

module.exports = SearchSelect;
