/**
 * DNR-UI Runtime - Minimal reactive UI runtime
 * Generated by Dazzle Native Runtime
 * Version: 0.4.0 (Behaviour Layer Complete)
 *
 * This is the main entry point that exports all modules to the DNR global.
 */

// Import all modules
import {
  createSignal,
  createEffect,
  createMemo,
  createResource,
  batch
} from './signals.js';

import {
  getState,
  setState,
  updateState,
  registerState,
  globalLoading,
  globalError,
  notifications
} from './state.js';

import { apiClient } from './api-client.js';
import { showToast } from './toast.js';
import { createElement, render } from './dom.js';
import { registerComponent, getComponent } from './components.js';
import { registerAction, dispatch, executeAction, executeEffect } from './actions.js';
import { applyTheme } from './theme.js';
import { createApp } from './app.js';
import { initDevTools, toggleDevTools, openDevTools, closeDevTools } from './devtools.js';

// =============================================================================
// Global Export (IIFE version for non-module browsers)
// =============================================================================

const DNR = {
  // Signals & Reactivity
  createSignal,
  createEffect,
  createMemo,
  createResource,
  batch,

  // State Management
  getState,
  setState,
  updateState,
  registerState,
  globalLoading,
  globalError,
  notifications,

  // DOM
  createElement,
  render,

  // Components
  registerComponent,
  getComponent,

  // Actions & Effects
  registerAction,
  dispatch,
  executeAction,
  executeEffect,

  // Notifications
  showToast,

  // API Client
  api: apiClient,

  // Theme
  applyTheme,

  // App
  createApp,

  // DevTools
  devtools: {
    init: initDevTools,
    toggle: toggleDevTools,
    open: openDevTools,
    close: closeDevTools
  }
};

// Export for both module and global contexts
export { DNR };
export default DNR;

// Attach to window for non-module usage
if (typeof window !== 'undefined') {
  window.DNR = DNR;

  // Auto-initialize devtools in development mode
  // Check for DNR dev server (hot reload endpoint exists)
  if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
    // Initialize devtools when DOM is ready
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', initDevTools);
    } else {
      initDevTools();
    }
  }
}
