import { dirname, relative } from "node:path";
import { MarkdownRenderer, MarkdownSite } from "./markdown.js";
export class MdxSite extends MarkdownSite {
}
export class MdxRenderer extends MarkdownRenderer {
    #imports = new Map();
    render() {
        let imports = "";
        for (const [importPath, symbols] of this.#imports) {
            if (symbols.defaultAlias && symbols.namedImports.size > 0) {
                imports += `import ${symbols.defaultAlias}, { ${Array.from(symbols.namedImports).join(", ")} } from "${importPath}";\n`;
            }
            else if (symbols.defaultAlias) {
                imports += `import ${symbols.defaultAlias} from "${importPath}";\n`;
            }
            else {
                imports += `import { ${Array.from(symbols.namedImports).join(", ")} } from "${importPath}";\n`;
            }
        }
        const parentData = super.render();
        const data = (imports ? imports + "\n\n" : "") + parentData;
        return data;
    }
    insertDefaultImport(importPath, symbol) {
        if (!this.#imports.has(importPath)) {
            this.#imports.set(importPath, {
                defaultAlias: undefined,
                namedImports: new Set(),
            });
        }
        // Will never be undefined due to the above. I wish TypeScript could narrow
        // map/set .has() calls
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        this.#imports.get(importPath).defaultAlias = symbol;
    }
    insertNamedImport(importPath, symbol) {
        if (!this.#imports.has(importPath)) {
            this.#imports.set(importPath, {
                defaultAlias: undefined,
                namedImports: new Set(),
            });
        }
        this.#imports.get(importPath)?.namedImports.add(symbol);
    }
    insertThirdPartyImport(symbol, importPath) {
        this.insertNamedImport(importPath, symbol);
    }
    getRelativeImportPath(startPath, endPath) {
        let importPath = relative(dirname(startPath), endPath);
        // Check if this is an import to a file in the same directory, which
        // for some reason relative doesn't include the ./ in
        if (!importPath.startsWith("./") && !importPath.startsWith("../")) {
            importPath = `./${importPath}`;
        }
        return importPath;
    }
}
//# sourceMappingURL=mdx.js.map