import { jsx as _jsx } from "react/jsx-runtime";
import { pathToFileURL } from "node:url";
import { Text } from "ink";
import { truncateCells } from "./design/textLayout.js";
export function FilePathLink(props) {
    const label = typeof props.children === "string"
        ? props.children
        : props.filePath;
    const model = filePathLinkModel(props.filePath, label, {
        width: props.width,
        osc8: process.env.DEEPSEEKCODE_OSC8_LINKS === "1",
    });
    return (_jsx(Text, { color: props.color, dimColor: props.dimColor, children: model.linkedText }));
}
export function filePathLinkModel(filePath, label = filePath, options = {}) {
    const href = pathToFileURL(filePath).href;
    const visible = options.width ? truncateCells(label, options.width) : label;
    return {
        href,
        label: visible,
        linkedText: options.osc8 ? osc8Link(href, visible) : visible,
    };
}
export function isLikelyLocalPath(value) {
    return /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\") || value.startsWith("/");
}
function osc8Link(href, label) {
    return `\u001B]8;;${href}\u0007${label}\u001B]8;;\u0007`;
}
