"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue
} from "@open-mercato/ui/primitives/select";
function PipelineStageSelect({
  id,
  stages,
  value,
  onChange,
  disabled = false,
  placeholder,
  formatCount
}) {
  const selectedIndex = React.useMemo(
    () => value ? stages.findIndex((stage) => stage.id === value) : -1,
    [stages, value]
  );
  const selectedStage = selectedIndex >= 0 ? stages[selectedIndex] : null;
  return /* @__PURE__ */ jsxs(
    Select,
    {
      value: typeof value === "string" && value ? value : void 0,
      onValueChange: (next) => onChange(next ?? ""),
      disabled: disabled || !stages.length,
      children: [
        /* @__PURE__ */ jsx(SelectTrigger, { id, size: "default", children: /* @__PURE__ */ jsx(SelectValue, { placeholder, children: selectedStage ? /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 items-center gap-2 truncate", children: [
          /* @__PURE__ */ jsx("span", { className: "truncate", children: selectedStage.label }),
          /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: formatCount(selectedIndex + 1, stages.length) })
        ] }) : null }) }),
        /* @__PURE__ */ jsx(SelectContent, { children: stages.map((stage, index) => /* @__PURE__ */ jsxs(SelectItem, { value: stage.id, children: [
          /* @__PURE__ */ jsx("span", { className: "truncate", children: stage.label }),
          /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: formatCount(index + 1, stages.length) })
        ] }, stage.id)) })
      ]
    }
  );
}
var PipelineStageSelect_default = PipelineStageSelect;
export {
  PipelineStageSelect,
  PipelineStageSelect_default as default
};
//# sourceMappingURL=PipelineStageSelect.js.map
