// Force strict mode and setup for ESM
"use strict";
import {
  ConfigContext,
  SessionPicker,
  SettingsContext
} from "./chunk-KBUR6JXA.js";
import {
  KeypressProvider
} from "./chunk-J6DGAYJ2.js";
import "./chunk-53OZLDF6.js";
import "./chunk-XU2SISL3.js";
import "./chunk-3LGZEYOF.js";
import "./chunk-4WGODMVR.js";
import "./chunk-LBWNSLJK.js";
import "./chunk-4UZYVB3A.js";
import "./chunk-U25CMJYY.js";
import {
  require_jsx_runtime
} from "./chunk-SV5PQVQE.js";
import {
  Box_default,
  render_default,
  use_app_default
} from "./chunk-2IIJTXYF.js";
import {
  require_react
} from "./chunk-5QWWOFGG.js";
import "./chunk-PWCQRLM5.js";
import "./chunk-2XXBJXNM.js";
import "./chunk-KKN2IE7Q.js";
import "./chunk-KW7NOTN6.js";
import "./chunk-4NFY2S7N.js";
import "./chunk-5LS57ZI3.js";
import "./chunk-2MIN6GRR.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-EKTCKZV5.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-35ZISENN.js";
import "./chunk-3SH53ANB.js";
import "./chunk-P7RKN76O.js";
import "./chunk-RKUWKYED.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-FAH5P34O.js";
import "./chunk-XY77A4MO.js";
import "./chunk-6PEXNQTX.js";
import "./chunk-OAW4O3MF.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import {
  SessionService,
  getGitBranch
} from "./chunk-VDNAD6JC.js";
import "./chunk-GOFAQQZA.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-TWPJO254.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-VA5NLVPT.js";
import "./chunk-I7JDGNG6.js";
import "./chunk-A6SX5TAH.js";
import "./chunk-33FNCQSY.js";
import "./chunk-6PVPNMXU.js";
import "./chunk-QP2X3YUW.js";
import "./chunk-IRH27ZC2.js";
import "./chunk-QHWCP53L.js";
import "./chunk-MOHAWIAW.js";
import "./chunk-X6QNZOTC.js";
import "./chunk-O6GEWCJA.js";
import "./chunk-T26EAKDL.js";
import "./chunk-ZPJWUGCS.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-MISUEWB4.js";
import "./chunk-KRXPRVGL.js";
import "./chunk-A5YZ3FA2.js";
import "./chunk-YAVY33G4.js";
import "./chunk-2UISUFHQ.js";
import "./chunk-HFVW54NL.js";
import "./chunk-TZTBZ25J.js";
import "./chunk-S6LOFUVP.js";
import "./chunk-SRY26X4H.js";
import "./chunk-K623ENWT.js";
import "./chunk-AQ37AY7B.js";
import "./chunk-432XCUHF.js";
import "./chunk-XC656O42.js";
import "./chunk-NAVJD2PQ.js";
import "./chunk-QYPT3QUD.js";
import "./chunk-QMBEW7EW.js";
import "./chunk-DGEIYUC3.js";
import "./chunk-MPHPFVKK.js";
import "./chunk-GLNBDYUX.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-5CPNLKAW.js";
import "./chunk-RPYYTL7E.js";
import "./chunk-2J3OJGTL.js";
import "./chunk-P3QQPMQA.js";
import "./chunk-6O5DVH27.js";
import "./chunk-GLCZKT5V.js";
import "./chunk-2DNKEBXY.js";
import "./chunk-N7ZZBTIU.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-E4WHKETF.js";
import "./chunk-UEJESCS7.js";
import "./chunk-CFDR3GNL.js";
import "./chunk-O4Z6JR7D.js";
import "./chunk-46UV252V.js";
import "./chunk-ZBVS26BY.js";
import "./chunk-BFHXDAR7.js";
import "./chunk-TYERNYH4.js";
import "./chunk-UH7Z7Y45.js";
import "./chunk-O2ZYHG33.js";
import "./chunk-W4RQUHY3.js";
import "./chunk-G7XXKQYS.js";
import "./chunk-3RXUYQJI.js";
import "./chunk-VOQXFAY5.js";
import "./chunk-3D43T7XT.js";
import {
  writeStdoutLine
} from "./chunk-OWAK7LMW.js";
import "./chunk-75DOP5OR.js";
import "./chunk-DMTGGOSA.js";
import "./chunk-YQ3U5MUC.js";
import "./chunk-AMDSOFFV.js";
import "./chunk-QUGAUQGJ.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
 */
