// Force strict mode and setup for ESM
"use strict";
import {
  ConfigContext,
  SessionPicker,
  SettingsContext
} from "./chunk-LYAX6C4V.js";
import "./chunk-FEFLNVIQ.js";
import "./chunk-DHGNDIWP.js";
import "./chunk-4WGODMVR.js";
import "./chunk-FS674JW4.js";
import "./chunk-HTDPNADQ.js";
import "./chunk-45IOTAUS.js";
import {
  KeypressProvider
} from "./chunk-IBXAXCTR.js";
import "./chunk-NBD76HUW.js";
import {
  require_jsx_runtime
} from "./chunk-SV5PQVQE.js";
import {
  Box_default,
  render_default,
  use_app_default
} from "./chunk-2IIJTXYF.js";
import "./chunk-JQWZJKCL.js";
import "./chunk-IGTHU3T4.js";
import "./chunk-KW7NOTN6.js";
import {
  require_react
} from "./chunk-5QWWOFGG.js";
import "./chunk-YDLJGZHL.js";
import "./chunk-KMJCEUDX.js";
import "./chunk-2MIN6GRR.js";
import "./chunk-QHTIBUWB.js";
import "./chunk-QTERJVPZ.js";
import "./chunk-F2FAKYCW.js";
import "./chunk-E5Z2AVNV.js";
import "./chunk-57OAHC2Y.js";
import "./chunk-65735MAF.js";
import "./chunk-RKUWKYED.js";
import "./chunk-GOXKNSDZ.js";
import "./chunk-IDS7MSUP.js";
import "./chunk-RNNQYOBE.js";
import "./chunk-Y26TPMQ7.js";
import "./chunk-6PEXNQTX.js";
import "./chunk-4QPH7TD4.js";
import "./chunk-ALGGS7UH.js";
import "./chunk-MR3PXB6E.js";
import {
  writeStdoutLine
} from "./chunk-OWAK7LMW.js";
import {
  SessionService,
  getGitBranch
} from "./chunk-HVFUW4JT.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-TWPJO254.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-AOHY3QJ3.js";
import "./chunk-5NNHICSA.js";
import "./chunk-SHN4KHDK.js";
import "./chunk-JXVC2PL3.js";
import "./chunk-KRXPRVGL.js";
import "./chunk-6PVPNMXU.js";
import "./chunk-OV2BALJJ.js";
import "./chunk-IRH27ZC2.js";
import "./chunk-QHWCP53L.js";
import "./chunk-TEGJSJDF.js";
import "./chunk-TIRRPCFS.js";
import "./chunk-O6GEWCJA.js";
import "./chunk-T26EAKDL.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-4KP2F2TE.js";
import "./chunk-3APUUXRF.js";
import "./chunk-THVU3RNH.js";
import "./chunk-LHKCY7DY.js";
import "./chunk-6FMJLI5M.js";
import "./chunk-CBBP4BMC.js";
import "./chunk-S6LOFUVP.js";
import "./chunk-K623ENWT.js";
import "./chunk-AQ37AY7B.js";
import "./chunk-N4ACHWNH.js";
import "./chunk-ZPJWUGCS.js";
import "./chunk-D4HTUMGX.js";
import "./chunk-NAVJD2PQ.js";
import "./chunk-LOY7RWQG.js";
import "./chunk-E6CJ2SMM.js";
import "./chunk-DGEIYUC3.js";
import "./chunk-MPHPFVKK.js";
import "./chunk-GLNBDYUX.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-JHNMFZLP.js";
import "./chunk-Z3S5EMOW.js";
import "./chunk-2J3OJGTL.js";
import "./chunk-P3QQPMQA.js";
import "./chunk-XQK4XXTN.js";
import "./chunk-GLCZKT5V.js";
import "./chunk-QDK4F2N5.js";
import "./chunk-SCUZ3ZCL.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-3I6DUGQD.js";
import "./chunk-7ULQIS27.js";
import "./chunk-MM7TH7ZM.js";
import "./chunk-6WSXKTJR.js";
import "./chunk-46UV252V.js";
import "./chunk-ZBVS26BY.js";
import "./chunk-Q3T5KA2V.js";
import "./chunk-R2XWGR75.js";
import "./chunk-HC45LTEN.js";
import "./chunk-QARJNL2V.js";
import "./chunk-W4RQUHY3.js";
import "./chunk-G7XXKQYS.js";
import "./chunk-E2BHWIDT.js";
import "./chunk-VOQXFAY5.js";
import "./chunk-GGBZ7ETQ.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
 */
