/**
 * BlocklyEditor Module
 *
 * Entry point for Blockly integration in Noodl.
 * Exports components, blocks, and generators for visual logic building.
 *
 * @module BlocklyEditor
 */

import { initNoodlBlocks } from './NoodlBlocks';
import { initNoodlGenerators } from './NoodlGenerators';
// Initialize globals (IODetector, code generation)
import '../../utils/BlocklyEditorGlobals';

// Main component
export { BlocklyWorkspace } from './BlocklyWorkspace';
export type { BlocklyWorkspaceProps } from './BlocklyWorkspace';

// Block definitions and generators
export { initNoodlBlocks } from './NoodlBlocks';
export { initNoodlGenerators, generateCode } from './NoodlGenerators';

// Track initialization to prevent double-registration
let blocklyInitialized = false;

/**
 * Initialize all Noodl Blockly extensions
 * Call this once at app startup before using Blockly components
 * Safe to call multiple times - will only initialize once
 */
export function initBlocklyIntegration() {
  if (blocklyInitialized) {
    console.log('⏭️  [Blockly] Already initialized, skipping');
    return;
  }

  console.log('🔧 [Blockly] Initializing Noodl Blockly integration');

  // Initialize custom blocks
  initNoodlBlocks();

  // Initialize code generators
  initNoodlGenerators();

  // Note: BlocklyEditorGlobals auto-initializes via side-effect import above

  blocklyInitialized = true;
  console.log('✅ [Blockly] Integration initialized');
}
