"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { Check, ChevronDown, ChevronsDown, ChevronsUp, Equal } from "lucide-react";
import { cn } from "@open-mercato/shared/lib/utils";
import { Button } from "@open-mercato/ui/primitives/button";
import { CONTROL_BORDER, DROPDOWN_PANEL_CLASS, useDropdownDismiss } from "./inputs.js";
const PRIORITY_META = {
  low: { Icon: ChevronsDown, color: "text-status-info-text" },
  medium: { Icon: Equal, color: "text-muted-foreground" },
  high: { Icon: ChevronsUp, color: "text-status-error-text" }
};
const PRIORITY_ORDER = ["high", "medium", "low"];
function PriorityField({
  value,
  labels,
  ariaLabel,
  onChange
}) {
  const [open, setOpen] = React.useState(false);
  const close = React.useCallback(() => setOpen(false), []);
  const rootRef = useDropdownDismiss(open, close);
  const selected = PRIORITY_META[value];
  const SelectedIcon = selected.Icon;
  return /* @__PURE__ */ jsxs(
    "div",
    {
      ref: rootRef,
      className: "relative w-full",
      onBlur: (event) => {
        if (!event.currentTarget.contains(event.relatedTarget)) setOpen(false);
      },
      children: [
        /* @__PURE__ */ jsxs(
          Button,
          {
            type: "button",
            variant: "outline",
            "aria-haspopup": "listbox",
            "aria-expanded": open,
            "aria-label": ariaLabel,
            onClick: () => setOpen((previous) => !previous),
            className: cn("h-9 w-full justify-between bg-background px-3 font-normal shadow-none", CONTROL_BORDER),
            children: [
              /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [
                /* @__PURE__ */ jsx(SelectedIcon, { "aria-hidden": true, className: cn("size-4 shrink-0", selected.color) }),
                /* @__PURE__ */ jsx("span", { className: "truncate text-sm text-foreground", children: labels[value] })
              ] }),
              /* @__PURE__ */ jsx(ChevronDown, { "aria-hidden": true, className: "size-4 shrink-0 opacity-60" })
            ]
          }
        ),
        open ? /* @__PURE__ */ jsx("div", { role: "listbox", "aria-label": ariaLabel, className: DROPDOWN_PANEL_CLASS, children: PRIORITY_ORDER.map((priority) => {
          const meta = PRIORITY_META[priority];
          const Icon = meta.Icon;
          const active = priority === value;
          return /* @__PURE__ */ jsxs(
            Button,
            {
              type: "button",
              variant: "ghost",
              role: "option",
              "aria-selected": active,
              onClick: () => {
                onChange(priority);
                setOpen(false);
              },
              className: cn("h-auto w-full justify-start gap-2 px-2 py-1.5 text-left text-sm font-normal", active && "bg-muted"),
              children: [
                /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, className: cn("size-4 shrink-0", meta.color) }),
                /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-foreground", children: labels[priority] }),
                /* @__PURE__ */ jsx(Check, { "aria-hidden": true, className: cn("size-4 shrink-0", active ? "opacity-100" : "opacity-0") })
              ]
            },
            priority
          );
        }) }) : null
      ]
    }
  );
}
export {
  PriorityField
};
//# sourceMappingURL=PriorityField.js.map
