"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 StreamSelector_exports = {};
__export(StreamSelector_exports, {
  default: () => StreamSelector_default
});
module.exports = __toCommonJS(StreamSelector_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");
var import_streaming_state = require("../../state/streaming-state.js");
const StreamSelector = (0, import_react.forwardRef)(
  function StreamSelector2({ isVisible, onSelect, onClose }, ref) {
    const baseSelectorRef = (0, import_react.useRef)(null);
    (0, import_react.useImperativeHandle)(
      ref,
      () => ({
        handleInput: (input, key) => {
          return baseSelectorRef.current?.handleInput(input, key) ?? false;
        }
      }),
      []
    );
    const [options, setOptions] = (0, import_react.useState)([]);
    const [selectedIndex, setSelectedIndex] = (0, import_react.useState)(0);
    (0, import_react.useEffect)(() => {
      if (!isVisible) return;
      const currentEnabled = (0, import_streaming_state.isStreamingEnabled)();
      const optionList = [
        {
          id: "enabled",
          label: "Enabled (Experimental)",
          description: "Show responses as they are generated",
          icon: "\u25B6\uFE0F",
          isCurrent: currentEnabled
        },
        {
          id: "disabled",
          label: "Disabled",
          description: "Show complete response when finished (default)",
          icon: "\u23F8\uFE0F",
          isCurrent: !currentEnabled
        }
      ];
      setOptions(optionList);
      setSelectedIndex(currentEnabled ? 0 : 1);
    }, [isVisible]);
    const formatItem = (option, isSelected) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { children: [
        option.icon,
        " "
      ] }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: isSelected ? "cyan" : "gray", bold: isSelected, children: option.label }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: isSelected ? "white" : "gray", children: [
        " - ",
        option.description
      ] }),
      option.isCurrent && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "green", bold: true, children: [
        " ",
        "\u2713"
      ] })
    ] });
    const handleSelect = (option) => {
      const enabled = option.id === "enabled";
      (0, import_streaming_state.setStreamingEnabled)(enabled);
      onSelect(enabled);
    };
    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_BaseSelector.BaseSelector,
      {
        ref: baseSelectorRef,
        items: options,
        isVisible,
        isLoading: false,
        selectedIndex,
        onSelectIndex: setSelectedIndex,
        onSelect: handleSelect,
        onClose,
        formatItem,
        title: "Streaming Mode",
        borderColor: "cyan",
        emptyMessage: "No options available"
      }
    );
  }
);
var StreamSelector_default = StreamSelector;
