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 SESSION_OPTIONS = [
  { action: "list", label: "list", description: "List all sessions", icon: "\u{1F4CB}" },
  { action: "switch", label: "switch", description: "Switch to another session", icon: "\u{1F504}" },
  { action: "history", label: "history", description: "Show session history", icon: "\u{1F4DC}" },
  { action: "delete", label: "delete", description: "Delete a session", icon: "\u{1F5D1}\uFE0F" }
];
const SessionSubcommandSelector = forwardRef(function SessionSubcommandSelector2({ isVisible, onSelect, onClose }, ref) {
  const baseSelectorRef = useRef(null);
  useImperativeHandle(
    ref,
    () => ({
      handleInput: (input, key) => {
        return baseSelectorRef.current?.handleInput(input, key) ?? false;
      }
    }),
    []
  );
  const [options] = useState(SESSION_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: "Session Management",
      borderColor: "blue",
      emptyMessage: "No options available"
    }
  );
});
var SessionSubcommandSelector_default = SessionSubcommandSelector;
export {
  SessionSubcommandSelector_default as default
};
