/**
 * Centralized lazy module loader for heavy dependencies
 * Provides singleton pattern for loading and configuring expensive modules
 */
/**
 * Singleton class for lazy-loading heavy npm packages
 */
class LazyModuleLoader {
    // Chrono (natural language date parser)
    chronoModule;
    // Inquirer (interactive prompts)
    inquirerModule;
    // Lodash (utility library)
    lodashModule;
    markedConfigured = false;
    // Marked (markdown parser) and marked-terminal (terminal renderer)
    markedModule;
    markedTerminalModule;
    // YAML parser
    yamlModule;
    /**
     * Generic lazy loader for any module
     * Returns the entire module namespace
     */
    async load(moduleName) {
        return import(moduleName);
    }
    /**
     * Load chrono (natural language date parser)
     * Example: const chrono = await lazyModuleLoader.loadChrono()
     */
    async loadChrono() {
        if (!this.chronoModule) {
            this.chronoModule = await import('chrono-node');
        }
        return this.chronoModule;
    }
    /**
     * Load date-fns functions
     * Example: const {formatDistanceToNow} = await lazyModuleLoader.loadDateFns()
     */
    async loadDateFns() {
        return import('date-fns');
    }
    /**
     * Load inquirer (interactive prompts)
     * Example: const inquirer = await lazyModuleLoader.loadInquirer()
     */
    async loadInquirer() {
        if (!this.inquirerModule) {
            const inquirer = await import('inquirer');
            this.inquirerModule = inquirer.default;
        }
        return this.inquirerModule;
    }
    /**
     * Load lodash utility library
     * Example: const _ = await lazyModuleLoader.loadLodash()
     */
    async loadLodash() {
        if (!this.lodashModule) {
            const lodash = await import('lodash');
            this.lodashModule = lodash.default;
        }
        return this.lodashModule;
    }
    /**
     * Load marked (markdown parser) configured for terminal output
     * Lazy-loads both marked and marked-terminal, configures once
     */
    async loadMarked() {
        if (!this.markedModule) {
            // Load both marked and marked-terminal in parallel
            const [marked, markedTerminal] = await Promise.all([
                import('marked'),
                import('marked-terminal'),
            ]);
            this.markedModule = marked;
            this.markedTerminalModule = markedTerminal;
            // Configure marked with terminal renderer (only once)
            if (!this.markedConfigured) {
                marked.marked.use(markedTerminal.markedTerminal({ emoji: false }));
                this.markedConfigured = true;
            }
        }
        return this.markedModule.marked;
    }
    /**
     * Load yaml parser
     * Example: const {parse} = await lazyModuleLoader.loadYaml()
     */
    async loadYaml() {
        if (!this.yamlModule) {
            this.yamlModule = await import('yaml');
        }
        return this.yamlModule;
    }
}
// Export singleton instance
export const lazyModuleLoader = new LazyModuleLoader();
