import { cpSync } from 'fs';
import { dirname, resolve } from 'path';
import { DefaultTheme, JSX, RendererEvent } from 'typedoc';
import { fileURLToPath } from 'url';
import { GitHubThemeContext } from './GitHubThemeContext.js';
export class GitHubTheme extends DefaultTheme {
    constructor(renderer) {
        super(renderer);
        // copy the complete assets
        renderer.on(RendererEvent.END, (event) => {
            const from = resolve(dirname(fileURLToPath(import.meta.url)), '../src/assets/');
            const to = resolve(event.outputDirectory, 'assets/');
            cpSync(from, to, { recursive: true });
        });
        // link the css file
        renderer.hooks.on('head.end', (event) => (JSX.createElement(JSX.Fragment, null,
            JSX.createElement("link", { rel: "stylesheet", href: event.relativeURL('assets/typedoc-github-style.css') }))));
        // set the Shiki theme
        renderer.application.on('bootstrapEnd', () => {
            if (!this.application.options.isSet('lightHighlightTheme')) {
                this.application.options.setValue('lightHighlightTheme', 'github-light-default');
            }
            if (!this.application.options.isSet('darkHighlightTheme')) {
                this.application.options.setValue('darkHighlightTheme', 'github-dark-default');
            }
        });
    }
    getRenderContext(pageEvent) {
        return new GitHubThemeContext(this.router, this, pageEvent, this.application.options);
    }
}
