/**
 * Plugin Registry - Auto-registers all available plugins
 */

import pluginService from '../services/plugin-service.js';
import ClaudePlugin from './claude-plugin.js';

// Built-in plugins
const builtInPlugins = [
  ClaudePlugin
];

/**
 * Initialize all plugins
 */
export function initializePlugins() {
  for (const plugin of builtInPlugins) {
    try {
      pluginService.register(plugin);
    } catch (e) {
      console.error(`Failed to register plugin ${plugin.id}:`, e);
    }
  }
}

/**
 * Load a plugin from URL (for external plugins)
 */
export async function loadExternalPlugin(url) {
  try {
    const module = await import(url);
    if (module.default) {
      pluginService.register(module.default);
      return module.default;
    }
    throw new Error('Plugin module must have a default export');
  } catch (e) {
    console.error(`Failed to load plugin from ${url}:`, e);
    throw e;
  }
}

export default {
  initializePlugins,
  loadExternalPlugin
};
