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 SERVER_TYPE_OPTIONS = [
  {
    type: "stdio",
    label: "STDIO",
    description: "Local process (npx, uvx, node, python)",
    icon: "\u25B6\uFE0F"
  },
  {
    type: "http",
    label: "HTTP",
    description: "Remote HTTP server",
    icon: "\u{1F310}"
  },
  {
    type: "sse",
    label: "SSE",
    description: "Server-Sent Events endpoint",
    icon: "\u{1F4E1}"
  }
];
const McpCustomTypeSelector = forwardRef(
  function McpCustomTypeSelector2({ isVisible, onSelect, onClose }, ref) {
    const baseSelectorRef = useRef(null);
    useImperativeHandle(
      ref,
      () => ({
        handleInput: (input, key) => {
          return baseSelectorRef.current?.handleInput(input, key) ?? false;
        }
      }),
      []
    );
    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.type);
    };
    return /* @__PURE__ */ jsx(
      BaseSelector,
      {
        ref: baseSelectorRef,
        items: SERVER_TYPE_OPTIONS,
        isVisible,
        isLoading: false,
        selectedIndex,
        onSelectIndex: setSelectedIndex,
        onSelect: handleSelect,
        onClose,
        formatItem,
        title: "Select Server Type",
        borderColor: "yellowBright",
        emptyMessage: "No options available"
      }
    );
  }
);
var McpCustomTypeSelector_default = McpCustomTypeSelector;
export {
  McpCustomTypeSelector_default as default
};
