"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var McpServerActions_exports = {};
__export(McpServerActions_exports, {
  default: () => McpServerActions_default
});
module.exports = __toCommonJS(McpServerActions_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_ink = require("ink");
var import_BaseSelector = require("../base/BaseSelector.js");
const McpServerActions = (0, import_react.forwardRef)(
  function McpServerActions2({ isVisible, server, onAction, onClose }, ref) {
    const baseSelectorRef = (0, import_react.useRef)(null);
    const [selectedIndex, setSelectedIndex] = (0, import_react.useState)(0);
    (0, import_react.useImperativeHandle)(
      ref,
      () => ({
        handleInput: (input, key) => {
          return baseSelectorRef.current?.handleInput(input, key) ?? false;
        }
      }),
      []
    );
    (0, import_react.useEffect)(() => {
      if (isVisible) {
        setSelectedIndex(0);
      }
    }, [isVisible, server]);
    const items = (0, import_react.useMemo)(() => {
      if (!server) return [];
      const actions = [];
      if (server.enabled) {
        actions.push({
          id: "disable",
          type: "disable",
          label: "Disable server",
          icon: "\u23F8\uFE0F",
          color: "orange"
        });
      } else {
        actions.push({
          id: "enable",
          type: "enable",
          label: "Enable server",
          icon: "\u25B6\uFE0F",
          color: "green"
        });
      }
      if (server.status === "auth-required") {
        actions.push({
          id: "authenticate",
          type: "authenticate",
          label: "Authenticate server",
          icon: "\u{1F510}",
          color: "yellow"
        });
      }
      actions.push({
        id: "delete",
        type: "delete",
        label: "Delete server",
        icon: "\u{1F5D1}\uFE0F",
        color: "red"
      });
      actions.push({
        id: "back",
        type: "back",
        label: "Back to server list",
        icon: "\u2190",
        color: "gray"
      });
      return actions;
    }, [server]);
    const formatItem = (item, isSelected) => {
      return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { children: [
          item.icon,
          " "
        ] }),
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: isSelected ? item.color : "gray", bold: isSelected, children: item.label })
      ] });
    };
    const handleSelect = (item) => {
      if (!server) return;
      onAction({ type: item.type, server });
    };
    if (!server) return null;
    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_BaseSelector.BaseSelector,
      {
        ref: baseSelectorRef,
        items,
        isVisible,
        isLoading: false,
        selectedIndex,
        onSelectIndex: setSelectedIndex,
        onSelect: handleSelect,
        onClose,
        formatItem,
        title: `Server: ${server.name}`,
        borderColor: "magenta",
        emptyMessage: "No actions available"
      }
    );
  }
);
var McpServerActions_default = McpServerActions;
