import { jsx, jsxs } from "react/jsx-runtime";
import { useState, useEffect, forwardRef, useRef, useImperativeHandle } from "react";
import { Box, Text } from "ink";
import { BaseSelector } from "../base/BaseSelector.js";
const CHOICES = [
  {
    id: "registry",
    type: "registry",
    label: "Explore registry",
    description: "Browse available MCP server presets",
    icon: "\u{1F4E6}"
  },
  {
    id: "custom",
    type: "custom",
    label: "Add custom server",
    description: "Configure your own MCP server",
    icon: "\u2699\uFE0F"
  },
  {
    id: "back",
    type: "back",
    label: "Back",
    description: "Return to server list",
    icon: "\u2190"
  }
];
const McpAddChoice = forwardRef(function McpAddChoice2({ isVisible, onSelect, onClose }, ref) {
  const baseSelectorRef = useRef(null);
  const [selectedIndex, setSelectedIndex] = useState(0);
  useImperativeHandle(
    ref,
    () => ({
      handleInput: (input, key) => {
        return baseSelectorRef.current?.handleInput(input, key) ?? false;
      }
    }),
    []
  );
  useEffect(() => {
    if (isVisible) {
      setSelectedIndex(0);
    }
  }, [isVisible]);
  const formatItem = (item, isSelected) => /* @__PURE__ */ jsxs(Box, { children: [
    /* @__PURE__ */ jsxs(Text, { children: [
      item.icon,
      " "
    ] }),
    /* @__PURE__ */ jsx(Text, { color: isSelected ? "cyan" : "gray", bold: isSelected, children: item.label }),
    /* @__PURE__ */ jsxs(Text, { color: isSelected ? "white" : "gray", children: [
      " - ",
      item.description
    ] })
  ] });
  const handleSelect = (item) => {
    onSelect(item.type);
  };
  return /* @__PURE__ */ jsx(
    BaseSelector,
    {
      ref: baseSelectorRef,
      items: CHOICES,
      isVisible,
      isLoading: false,
      selectedIndex,
      onSelectIndex: setSelectedIndex,
      onSelect: handleSelect,
      onClose,
      formatItem,
      title: "Add MCP Server",
      borderColor: "green",
      emptyMessage: "No options available"
    }
  );
});
var McpAddChoice_default = McpAddChoice;
export {
  McpAddChoice_default as default
};
