"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 ChatGPTUsageCapOverlay_exports = {};
__export(ChatGPTUsageCapOverlay_exports, {
  default: () => ChatGPTUsageCapOverlay_default
});
module.exports = __toCommonJS(ChatGPTUsageCapOverlay_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_ink = require("ink");
var import_chatgpt_rate_limit = require("../../utils/chatgpt-rate-limit.js");
const ChatGPTUsageCapOverlay = (0, import_react.forwardRef)(function ChatGPTUsageCapOverlay2({
  isVisible,
  currentModelDisplayName,
  fallbackModelDisplayName,
  usedDefaultFallback,
  apiKeyConfigured,
  status,
  onConfirm,
  onClose
}, ref) {
  (0, import_react.useImperativeHandle)(
    ref,
    () => ({
      handleInput: (_input, key) => {
        if (!isVisible) {
          return false;
        }
        if (key.escape) {
          onClose();
          return true;
        }
        if (key.return) {
          onConfirm();
          return true;
        }
        return true;
      }
    }),
    [isVisible, onClose, onConfirm]
  );
  if (!isVisible) {
    return null;
  }
  const actionLabel = apiKeyConfigured ? `Switch this session to ${fallbackModelDisplayName} via OpenAI API key` : `Add an OpenAI API key and switch this session to ${fallbackModelDisplayName}`;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
    import_ink.Box,
    {
      flexDirection: "column",
      borderStyle: "round",
      borderColor: "yellow",
      paddingX: 1,
      marginTop: 1,
      children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { marginBottom: 1, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { bold: true, color: "yellowBright", children: "ChatGPT usage cap reached" }) }),
        status && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { marginBottom: 1, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: (0, import_chatgpt_rate_limit.getChatGPTRateLimitHint)(status) }) }),
        /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { flexDirection: "column", marginBottom: 1, children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "gray", children: [
            currentModelDisplayName,
            " is currently running through ChatGPT Login."
          ] }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { children: actionLabel })
        ] }),
        usedDefaultFallback && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { marginBottom: 1, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "gray", children: [
          "The current ChatGPT model is not available through the OpenAI API path, so Dexto will use ",
          fallbackModelDisplayName,
          " for this session."
        ] }) }),
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: "Enter to continue \u2022 Esc to dismiss" }) })
      ]
    }
  );
});
var ChatGPTUsageCapOverlay_default = ChatGPTUsageCapOverlay;
