import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { useState, useEffect, forwardRef, useRef, useImperativeHandle } from "react";
import { Text } from "ink";
import { BaseSelector } from "../base/BaseSelector.js";
const MCP_OPTIONS = [
  { action: "list", label: "list", description: "List connected servers", icon: "\u{1F4CB}" },
  {
    action: "add-preset",
    label: "add preset",
    description: "Add from registry presets",
    icon: "\u{1F4E6}"
  },
  {
    action: "add-custom",
    label: "add custom",
    description: "Add custom server (stdio/http/sse)",
    icon: "\u2699\uFE0F"
  },
  { action: "remove", label: "remove", description: "Remove a server", icon: "\u{1F5D1}\uFE0F" }
];
const McpSelector = forwardRef(function McpSelector2({ isVisible, onSelect, onClose }, ref) {
  const baseSelectorRef = useRef(null);
  useImperativeHandle(
    ref,
    () => ({
      handleInput: (input, key) => {
        return baseSelectorRef.current?.handleInput(input, key) ?? false;
      }
    }),
    []
  );
  const [options] = useState(MCP_OPTIONS);
  const [selectedIndex, setSelectedIndex] = useState(0);
  useEffect(() => {
    if (isVisible) {
      setSelectedIndex(0);
    }
  }, [isVisible]);
  const formatItem = (option, isSelected) => /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsxs(Text, { children: [
      option.icon,
      " "
    ] }),
    /* @__PURE__ */ jsx(Text, { color: isSelected ? "cyan" : "gray", bold: isSelected, children: option.label }),
    /* @__PURE__ */ jsxs(Text, { color: isSelected ? "white" : "gray", children: [
      " - ",
      option.description
    ] })
  ] });
  const handleSelect = (option) => {
    onSelect(option.action);
  };
  return /* @__PURE__ */ jsx(
    BaseSelector,
    {
      ref: baseSelectorRef,
      items: options,
      isVisible,
      isLoading: false,
      selectedIndex,
      onSelectIndex: setSelectedIndex,
      onSelect: handleSelect,
      onClose,
      formatItem,
      title: "MCP Servers",
      borderColor: "magenta",
      emptyMessage: "No options available"
    }
  );
});
var McpSelector_default = McpSelector;
export {
  McpSelector_default as default
};
