import chalk from "chalk";
import { supportsHyperlinks } from "./supports-hyperlinks.js";
// OSC 8 hyperlink escape sequences
// Format: \e]8;;URL\e\\TEXT\e]8;;\e\\
// Using \x07 (BEL) as terminator which is more widely supported
const OSC8_START = "\x1b]8;;";
const OSC8_END = "\x07";
/**
 * Create a clickable hyperlink using OSC 8 escape sequences.
 * Falls back to plain URL if the terminal doesn't support hyperlinks.
 *
 * @param url - The URL to link to
 * @param content - Optional content to display as the link text.
 *   If provided and hyperlinks are supported, this text is shown as a clickable link.
 *   If hyperlinks are not supported, content is ignored and only the URL is shown.
 */
export function createHyperlink(url, content) {
    if (!supportsHyperlinks()) {
        return url;
    }
    // Apply basic ANSI blue color — wrap-ansi preserves this across line breaks.
    // RGB colors (like theme colors) are NOT preserved by wrap-ansi with OSC 8.
    const displayText = content ?? url;
    const coloredText = chalk.blue(displayText);
    return `${OSC8_START}${url}${OSC8_END}${coloredText}${OSC8_START}${OSC8_END}`;
}
//# sourceMappingURL=hyperlink.js.map