/**
 * ============================================================
 * FreePBX SIP Plugin - Registry Bootstrap
 *
 * Auto-registers plugin with the app's plugin registry system
 * ============================================================
 */

import { getGlobalPluginRegistry } from "@/contexts/plugin-registry";

import SIPConnections from './pages/admin/SIPConnections';
import SIPExtensions from './pages/admin/SIPExtensions';
import SIPAssignments from './pages/admin/SIPAssignments';

export function bootstrapSIPPlugin() {
  const registry = getGlobalPluginRegistry();
  if (!registry) {
    console.warn('[FreePBX SIP] Plugin registry not available');
    return;
  }

  // Register admin menu items
  registry.registerAdminMenuItem({
    id: 'freepbx-connections',
    pluginName: 'free-pbx',
    label: 'SIP Connections',
    path: '/admin/sip/connections',
    component: SIPConnections,
    order: 50,
  });

  registry.registerAdminMenuItem({
    id: 'freepbx-extensions',
    pluginName: 'free-pbx',
    label: 'SIP Extensions',
    path: '/admin/sip/extensions',
    component: SIPExtensions,
    order: 51,
  });

  registry.registerAdminMenuItem({
    id: 'freepbx-assignments',
    pluginName: 'free-pbx',
    label: 'SIP Assignments',
    path: '/admin/sip/assignments',
    component: SIPAssignments,
    order: 52,
  });

  registry.markPluginLoaded('free-pbx');
  console.log('[FreePBX SIP] Plugin registered');
}

// Auto-bootstrap on load
if (typeof window !== 'undefined') {
  setTimeout(() => {
    bootstrapSIPPlugin();
  }, 100);
}
