import { n as theme, t as isRich } from "./theme-DrO_HVcw.js";
import { n as stylePromptMessage, t as renderDenchCloudRecommendationBanner } from "./dench-cloud-banner-Du3uFoUw.js";
import { spawn } from "node:child_process";
import process from "node:process";
import { isCancel, select } from "@clack/prompts";

//#region src/cli/dench-cloud-welcome.ts
const DENCH_LOGIN_URL = "https://dench.com/login";
async function openUrlInBrowser(url) {
	const [command, ...args] = process.platform === "darwin" ? ["open", url] : process.platform === "win32" ? [
		"cmd",
		"/c",
		"start",
		"",
		url
	] : ["xdg-open", url];
	return await new Promise((resolve) => {
		const child = spawn(command, args, {
			stdio: "ignore",
			detached: true
		});
		child.once("error", () => resolve(false));
		child.once("spawn", () => {
			child.unref();
			resolve(true);
		});
	});
}
/**
* The bare `npx denchclaw` flow: show the Dench Cloud banner, offer a single
* "Continue with Dench.com" action that opens dench.com/login, then end the
* session. The full local setup lives under `npx denchclaw bootstrap`.
*/
async function runDenchCloudWelcome() {
	const log = (line) => process.stdout.write(`${line}\n`);
	log(renderDenchCloudRecommendationBanner());
	if (!Boolean(process.stdin.isTTY && process.stdout.isTTY)) {
		log(`Continue with Dench.com: ${DENCH_LOGIN_URL}`);
		return;
	}
	if (isCancel(await select({
		message: stylePromptMessage("Get started with Dench Cloud"),
		options: [{
			value: "continue",
			label: "Continue with Dench.com"
		}]
	}))) return;
	const opened = await openUrlInBrowser(DENCH_LOGIN_URL);
	const url = isRich() ? theme.accentBright(DENCH_LOGIN_URL) : DENCH_LOGIN_URL;
	log("");
	log(opened ? `  Opening ${url} in your browser…` : `  Open ${url} in your browser to continue.`);
	log("");
}

//#endregion
export { runDenchCloudWelcome };