// Force strict mode and setup for ESM
"use strict";
import {
  ConfigContext,
  SessionPicker,
  SettingsContext
} from "./chunk-IXDLDUHL.js";
import "./chunk-5OLAJ72I.js";
import "./chunk-6U3J52CF.js";
import "./chunk-5GOVVXEV.js";
import {
  KeypressProvider
} from "./chunk-RWKXZNQI.js";
import "./chunk-KSPVDFE4.js";
import "./chunk-MRO43B25.js";
import "./chunk-ZCPNAKVV.js";
import "./chunk-SMXULRAN.js";
import {
  Box_default,
  render_default,
  require_jsx_runtime,
  use_app_default
} from "./chunk-QSH43RBM.js";
import {
  require_react
} from "./chunk-KYMBIKIW.js";
import "./chunk-I4H7PRWQ.js";
import "./chunk-3GONHQOA.js";
import "./chunk-EIPGJSQP.js";
import "./chunk-ZDGYN5JJ.js";
import "./chunk-KHDZHZMH.js";
import "./chunk-YTN7HXEJ.js";
import "./chunk-3BPQCJOE.js";
import "./chunk-TLRYABYP.js";
import "./chunk-CF6BB3LT.js";
import "./chunk-34N4MKYG.js";
import {
  writeStdoutLine
} from "./chunk-Y6Z2O3WR.js";
import "./chunk-QYUE6W3T.js";
import {
  SessionService,
  getGitBranch
} from "./chunk-35BVDZGM.js";
import "./chunk-K5PGHDBN.js";
import "./chunk-SKAZWEV5.js";
import "./chunk-XJYUPHRC.js";
import "./chunk-QLDPRILK.js";
import "./chunk-BVSVIN45.js";
import "./chunk-SBBN4BWR.js";
import "./chunk-S7AKE7HL.js";
import "./chunk-2MPVVENX.js";
import "./chunk-ZTQ26VBE.js";
import "./chunk-O2VBQ3Y2.js";
import "./chunk-MLZQVCF3.js";
import "./chunk-LQ7TMOCE.js";
import "./chunk-LD2XBG6Z.js";
import "./chunk-HYCC3XM3.js";
import "./chunk-NL4C3H6C.js";
import "./chunk-JOLIREYR.js";
import "./chunk-DDMOU62Q.js";
import "./chunk-NY5MEIAL.js";
import "./chunk-3PJXIDKI.js";
import "./chunk-UWCTAVOD.js";
import "./chunk-OFEVLU4C.js";
import "./chunk-OMX7CUOE.js";
import "./chunk-RD6YJJJ6.js";
import "./chunk-SKQZZVAV.js";
import "./chunk-BUUQ5HPX.js";
import "./chunk-BX5YO7UW.js";
import "./chunk-UO5GVXQE.js";
import "./chunk-KMGMKW5Q.js";
import "./chunk-22IFUCVR.js";
import "./chunk-3227DZO4.js";
import "./chunk-U3KSMM7G.js";
import "./chunk-BKXBARJZ.js";
import "./chunk-EJYJYJZ2.js";
import "./chunk-55ZMG67I.js";
import "./chunk-H6BD2ELD.js";
import "./chunk-5IFG2VC4.js";
import "./chunk-64WXLC72.js";
import "./chunk-UX4SGCGN.js";
import "./chunk-YDUDLS3E.js";
import "./chunk-ZERZSAZL.js";
import "./chunk-QN5NZ3UQ.js";
import "./chunk-BR4QREVK.js";
import "./chunk-Z2Z3GUXZ.js";
import {
  init_esbuild_shims
} from "./chunk-A4BMJM77.js";
import {
  __name,
  __toESM
} from "./chunk-J2S4EL5Y.js";

// packages/cli/src/ui/components/StandaloneSessionPicker.tsx
init_esbuild_shims();
var import_react = __toESM(require_react(), 1);
var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
var PREVIEW_CONFIG_STUB = {
  getShouldUseNodePtyShell: /* @__PURE__ */ __name(() => false, "getShouldUseNodePtyShell"),
  getIdeMode: /* @__PURE__ */ __name(() => false, "getIdeMode"),
  isTrustedFolder: /* @__PURE__ */ __name(() => false, "isTrustedFolder"),
  getToolRegistry: /* @__PURE__ */ __name(() => ({ getTool: /* @__PURE__ */ __name(() => void 0, "getTool") }), "getToolRegistry"),
  getContentGenerator: /* @__PURE__ */ __name(() => ({ useSummarizedThinking: /* @__PURE__ */ __name(() => false, "useSummarizedThinking") }), "getContentGenerator")
};
var PREVIEW_SETTINGS_STUB = {
  merged: { ui: {} }
};
function StandalonePickerScreen({
  sessionService,
  onSelect,
  onCancel,
  currentBranch,
  initialSessions
}) {
  const { exit } = use_app_default();
  const [isExiting, setIsExiting] = (0, import_react.useState)(false);
  const handleExit = /* @__PURE__ */ __name(() => {
    setIsExiting(true);
    exit();
  }, "handleExit");
  if (isExiting) {
    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box_default, {});
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfigContext.Provider, { value: PREVIEW_CONFIG_STUB, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SettingsContext.Provider, { value: PREVIEW_SETTINGS_STUB, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    SessionPicker,
    {
      sessionService,
      onSelect: (id) => {
        onSelect(id);
        handleExit();
      },
      onCancel: () => {
        onCancel();
        handleExit();
      },
      currentBranch,
      centerSelection: true,
      initialSessions,
      enablePreview: true
    }
  ) }) });
}
__name(StandalonePickerScreen, "StandalonePickerScreen");
function clearScreen() {
  process.stdout.write("\x1B[2J\x1B[H");
}
__name(clearScreen, "clearScreen");
async function showResumeSessionPicker(cwd = process.cwd(), initialSessions) {
  const sessionService = new SessionService(cwd);
  const hasSession = await sessionService.loadLastSession();
  if (!hasSession) {
    writeStdoutLine("No sessions found. Start a new session with `qwen`.");
    return void 0;
  }
  clearScreen();
  const wasRaw = process.stdin.isRaw;
  if (process.stdin.isTTY && !wasRaw) {
    process.stdin.setRawMode(true);
  }
  return new Promise((resolve) => {
    let selectedId;
    const { unmount, waitUntilExit } = render_default(
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        KeypressProvider,
        {
          kittyProtocolEnabled: false,
          pasteWorkaround: process.platform === "win32" || parseInt(process.versions.node.split(".")[0], 10) < 20,
          children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            StandalonePickerScreen,
            {
              sessionService,
              onSelect: (id) => {
                selectedId = id;
              },
              onCancel: () => {
                selectedId = void 0;
              },
              currentBranch: getGitBranch(cwd),
              initialSessions
            }
          )
        }
      ),
      {
        exitOnCtrlC: false
      }
    );
    waitUntilExit().then(() => {
      unmount();
      clearScreen();
      if (process.stdin.isTTY && !wasRaw && !selectedId) {
        process.stdin.setRawMode(false);
      }
      resolve(selectedId);
    });
  });
}
__name(showResumeSessionPicker, "showResumeSessionPicker");
export {
  showResumeSessionPicker
};
/**
 * @license
 * Copyright 2025 Qwen Code
 * SPDX-License-Identifier: Apache-2.0
 */
