"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Footer_exports = {};
__export(Footer_exports, {
  Footer: () => Footer
});
module.exports = __toCommonJS(Footer_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_node_path = __toESM(require("node:path"), 1);
var import_ink = require("ink");
var import_llm = require("@dexto/llm");
var import_core = require("@dexto/core");
var import_llm_provider_display = require("../utils/llm-provider-display.js");
var import_chatgpt_rate_limit = require("../utils/chatgpt-rate-limit.js");
var import_agent_backend = require("../agent-backend.js");
function Footer({
  agent,
  sessionId,
  modelName,
  cwd,
  branchName,
  autoApproveEdits,
  bypassPermissions,
  planModeActive,
  isShellMode,
  chatgptRateLimitStatus
}) {
  const displayPath = cwd ? import_node_path.default.basename(cwd) || cwd : "";
  const displayModelName = (0, import_llm.getModelDisplayName)(modelName);
  const [contextLeft, setContextLeft] = (0, import_react.useState)(null);
  const [, setLlmTick] = (0, import_react.useState)(0);
  const llmConfig = sessionId ? agent.getCurrentLLMConfig(sessionId) : null;
  const provider = llmConfig?.provider ?? null;
  const providerLabel = provider ? (0, import_llm_provider_display.getLLMProviderDisplayName)(provider, llmConfig?.baseURL) : null;
  const reasoningProfile = provider && llmConfig ? (0, import_llm.getReasoningProfile)(provider, llmConfig.model) : null;
  const reasoningVariant = llmConfig?.reasoning?.variant ?? reasoningProfile?.defaultVariant ?? void 0;
  const showReasoningVariant = reasoningProfile?.capable === true && typeof reasoningVariant === "string";
  const isChatGPTLogin = provider === "openai-compatible" && (0, import_core.parseCodexBaseURL)(llmConfig?.baseURL)?.authMode === "chatgpt";
  const showChatGPTRateLimitHint = isChatGPTLogin && (0, import_chatgpt_rate_limit.shouldShowChatGPTRateLimitHint)(chatgptRateLimitStatus);
  const chatGPTRateLimitHint = showChatGPTRateLimitHint && chatgptRateLimitStatus ? (0, import_chatgpt_rate_limit.getChatGPTRateLimitHint)(chatgptRateLimitStatus) : null;
  const chatGPTRateLimitColor = chatgptRateLimitStatus?.exceeded ? "redBright" : (chatgptRateLimitStatus?.usedPercent ?? 0) >= 90 ? "yellowBright" : "yellow";
  (0, import_react.useEffect)(() => {
    if (!(0, import_agent_backend.supportsContextStats)(agent)) {
      setContextLeft(null);
      return;
    }
    if (!sessionId) {
      setContextLeft(null);
      return;
    }
    let cancelled = false;
    let refreshId = 0;
    const refreshContext = async () => {
      const requestId = ++refreshId;
      try {
        const stats = await agent.getContextStats(sessionId);
        if (cancelled || requestId !== refreshId) return;
        const percentLeft = Math.max(0, Math.min(100, 100 - stats.usagePercent));
        setContextLeft({
          percentLeft
        });
      } catch {
        if (!cancelled) {
          setContextLeft(null);
        }
      }
    };
    refreshContext();
    const controller = new AbortController();
    const { signal } = controller;
    const sessionEvents = [
      "llm:response",
      "llm:switched",
      "context:compacted",
      "context:pruned",
      "context:cleared",
      "message:dequeued",
      "session:reset"
    ];
    const handleEvent = (payload) => {
      if (payload.sessionId && payload.sessionId !== sessionId) return;
      refreshContext();
    };
    const handleLlmSwitched = (payload) => {
      if (payload.sessionIds && !payload.sessionIds.includes(sessionId)) return;
      refreshContext();
      setLlmTick((prev) => prev + 1);
    };
    for (const eventName of sessionEvents) {
      if (eventName === "llm:switched") {
        agent.on(eventName, handleLlmSwitched, { signal });
      } else {
        agent.on(eventName, handleEvent, { signal });
      }
    }
    return () => {
      cancelled = true;
      controller.abort();
    };
  }, [agent, sessionId]);
  const pathColor = isShellMode ? "yellow" : "blue";
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { flexDirection: "column", paddingX: 1, children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { flexDirection: "row", justifyContent: "space-between", children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: pathColor, children: displayPath }),
        branchName && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "gray", children: [
          " (",
          branchName,
          ")"
        ] })
      ] }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { children: [
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "cyan", children: displayModelName }),
        providerLabel && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "gray", children: [
          " (",
          providerLabel,
          ")"
        ] }),
        showReasoningVariant && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: " \xB7 r:" }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "magentaBright", children: reasoningVariant })
        ] })
      ] })
    ] }),
    contextLeft && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Text, { color: "gray", children: [
      contextLeft.percentLeft,
      "% context left"
    ] }) }),
    chatGPTRateLimitHint && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: chatGPTRateLimitColor, children: chatGPTRateLimitHint }) }),
    isShellMode && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "yellow", bold: true, children: "!" }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: " for shell mode" })
    ] }),
    planModeActive && !isShellMode && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "magentaBright", children: "plan mode" }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: " (shift + tab to cycle)" })
    ] }),
    autoApproveEdits && !planModeActive && !isShellMode && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "yellowBright", children: "accept edits" }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: " (shift + tab to cycle)" })
    ] }),
    bypassPermissions && !planModeActive && !autoApproveEdits && !isShellMode && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ink.Box, { children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "redBright", bold: true, children: "bypass permissions" }),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ink.Text, { color: "gray", children: " (shift + tab to cycle)" })
    ] })
  ] });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Footer
});
