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: "agent",
    scope: "agent",
    label: "For this agent only",
    description: "Stored in agent config directory",
    recommended: true
  },
  {
    id: "shared",
    scope: "shared",
    label: "For all agents (shared)",
    description: "Stored in ~/.dexto/commands/"
  }
];
const PromptAddChoice = forwardRef(
  function PromptAddChoice2({ isVisible, onSelect, onClose }, ref) {
    const baseSelectorRef = useRef(null);
    const [selectedIndex, setSelectedIndex] = useState(0);
    useEffect(() => {
      if (isVisible) {
        setSelectedIndex(0);
      }
    }, [isVisible]);
    useImperativeHandle(
      ref,
      () => ({
        handleInput: (input, key) => {
          return baseSelectorRef.current?.handleInput(input, key) ?? false;
        }
      }),
      []
    );
    const formatItem = (item, isSelected) => {
      return /* @__PURE__ */ jsxs(Box, { children: [
        /* @__PURE__ */ jsx(Text, { color: isSelected ? "cyan" : "white", bold: isSelected, children: item.label }),
        item.recommended && /* @__PURE__ */ jsx(Text, { color: isSelected ? "green" : "gray", children: " (Recommended)" }),
        /* @__PURE__ */ jsxs(Text, { color: "gray", children: [
          " \xB7 ",
          item.description
        ] })
      ] });
    };
    const handleSelect = (item) => {
      onSelect(item.scope);
    };
    return /* @__PURE__ */ jsx(
      BaseSelector,
      {
        ref: baseSelectorRef,
        items: CHOICES,
        isVisible,
        selectedIndex,
        onSelectIndex: setSelectedIndex,
        onSelect: handleSelect,
        onClose,
        formatItem,
        title: "Add Prompt",
        borderColor: "yellowBright",
        emptyMessage: "No options available"
      }
    );
  }
);
var PromptAddChoice_default = PromptAddChoice;
export {
  PromptAddChoice_default as default
};
