import { formatExamples, register } from "../registry.js";
import { getContextWithOpts } from "../context.js";
import { Command } from "commander";
//#region src/cli/commands/tailscale.ts
function createTailscaleCommand(_ctx) {
	return new Command("tailscale").description("Tailscale status for gateway remote access").addCommand(new Command("status").description("Show tailnet IP, hostname, and Serve/Funnel state").action(async () => {
		const { getTailnetIPv4, getTailnetHostname, isTailscaleInstalled } = await import("../../infra/tailscale.js");
		const { getTailscaleExposureState } = await import("../../gateway/tailscale-lifecycle.js");
		if (!await isTailscaleInstalled()) {
			console.log("Tailscale: not installed or not found in PATH");
			process.exit(1);
		}
		const ip = await getTailnetIPv4();
		let hostname = null;
		try {
			hostname = await getTailnetHostname();
		} catch {
			hostname = null;
		}
		const exposure = getTailscaleExposureState();
		console.log("Tailscale");
		console.log(`  Tailnet IPv4: ${ip ?? "(unavailable)"}`);
		console.log(`  MagicDNS:     ${hostname ?? "(unavailable)"}`);
		console.log(`  Gateway exposure: ${exposure.mode}${exposure.active ? " (active)" : ""}`);
		if (hostname && exposure.active) console.log(`  URL: https://${hostname}/`);
	})).addHelpText("after", formatExamples(["xopc tailscale status"]));
}
register({
	id: "tailscale",
	name: "tailscale",
	description: "Tailscale helpers for gateway exposure",
	factory: () => createTailscaleCommand(getContextWithOpts()),
	metadata: {
		category: "runtime",
		examples: ["xopc tailscale status"]
	}
});
//#endregion
export { createTailscaleCommand as default };

//# sourceMappingURL=tailscale.js.map