// Force strict mode and setup for ESM
"use strict";
import {
  ConfigContext,
  SessionPicker
} from "./chunk-2XC4VKX2.js";
import "./chunk-P5SJQ7F4.js";
import {
  SettingsContext
} from "./chunk-XH6LHW34.js";
import {
  KeypressProvider
} from "./chunk-HA265XCO.js";
import "./chunk-4WGODMVR.js";
import "./chunk-KW7NOTN6.js";
import "./chunk-DOPUYNXO.js";
import {
  Box_default,
  render_default,
  require_jsx_runtime,
  use_app_default
} from "./chunk-OWT2CAEQ.js";
import "./chunk-NHDKSOEY.js";
import "./chunk-Z5KRRYDS.js";
import "./chunk-7X7TEQNX.js";
import {
  require_react
} from "./chunk-HTHUX2T5.js";
import "./chunk-Q6TUALBE.js";
import "./chunk-2LLVTJVN.js";
import "./chunk-SUARMD4Q.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-E5Z2AVNV.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-P776QK5M.js";
import "./chunk-BYFID5BL.js";
import "./chunk-RKUWKYED.js";
import "./chunk-W7RFHI5L.js";
import "./chunk-ENW2BPUW.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-QRUIS3DN.js";
import "./chunk-FXXY6GR5.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import {
  writeStdoutLine
} from "./chunk-YUZI3WAC.js";
import {
  SessionService,
  getGitBranch
} from "./chunk-KN5EBZLT.js";
import "./chunk-T4TZQJ7W.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-A2HWMJVO.js";
import "./chunk-RCEEXIOO.js";
import "./chunk-KKRTYONM.js";
import "./chunk-TV6K2FB4.js";
import "./chunk-E2UVIFI2.js";
import "./chunk-XU457J4V.js";
import "./chunk-VDDGDZMA.js";
import "./chunk-SPJQO2CE.js";
import "./chunk-SZRN75WQ.js";
import "./chunk-HTO4JFDZ.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-F333XEAU.js";
import "./chunk-6AM5D4ME.js";
import "./chunk-2Z5UX4KI.js";
import "./chunk-ARKANCNX.js";
import "./chunk-L5U3ELZX.js";
import "./chunk-TYLOFD2U.js";
import "./chunk-D5K5YBSN.js";
import "./chunk-4WKAA4KS.js";
import "./chunk-CR3C7WXL.js";
import "./chunk-RTV5TUYB.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-FBU7WRZI.js";
import "./chunk-Y66VOBRP.js";
import "./chunk-WTNZ6DXB.js";
import "./chunk-JGUT3LWZ.js";
import "./chunk-OKAIGAYW.js";
import "./chunk-ZPAHLFZU.js";
import "./chunk-JESCGQM3.js";
import "./chunk-WIEO4CWB.js";
import "./chunk-XVNQMZ2I.js";
import "./chunk-FEOZBUMT.js";
import "./chunk-VRR65QYW.js";
import "./chunk-A4UCTEB5.js";
import "./chunk-XWRJCPHC.js";
import "./chunk-4LD5APFL.js";
import "./chunk-TYAMGABM.js";
import "./chunk-FCMNKVXT.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-LQIDP6K5.js";
import "./chunk-7NFB7LBQ.js";
import "./chunk-B3ILMEBG.js";
import "./chunk-75DOP5OR.js";
import "./chunk-DMTGGOSA.js";
import "./chunk-YQ3U5MUC.js";
import "./chunk-TB6UDU4T.js";
import {
  init_esbuild_shims
} from "./chunk-5O2XNYP6.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
 */
