// PE.js - Pandona Engine 核心库

import Engine from './Engine.js';

class PE {
  /**
   * 创建引擎实例
   * @returns {Engine} 引擎实例
   */
  static create() {
    return new Engine();
  }
  
  /**
   * 版本号
   */
  static get version() {
    return '1.0.0';
  }
  
  /**
   * 导航到指定路径的场景
   * @param {string} path - 场景路径
   */
  static navigateTo(path) {
    if (typeof window !== 'undefined' && window.PE_ENGINE) {
      window.PE_ENGINE.switchToPath(path);
    } else {
      console.warn('PE engine not initialized');
    }
  }
}

// 全局生命周期函数
const lifecycleHooks = {
  onLoad: (callback) => {
    if (typeof window !== 'undefined' && window.PE_ENGINE) {
      window.PE_ENGINE.onLoadCallbacks.push(callback);
    } else {
      console.warn('PE engine not initialized');
    }
  },
  onShow: (callback) => {
    if (typeof window !== 'undefined' && window.PE_ENGINE) {
      window.PE_ENGINE.onShowCallbacks.push(callback);
    } else {
      console.warn('PE engine not initialized');
    }
  },
  onHide: (callback) => {
    if (typeof window !== 'undefined' && window.PE_ENGINE) {
      window.PE_ENGINE.onHideCallbacks.push(callback);
    } else {
      console.warn('PE engine not initialized');
    }
  },
  onDestory: (callback) => {
    if (typeof window !== 'undefined' && window.PE_ENGINE) {
      window.PE_ENGINE.onDestoryCallbacks.push(callback);
    } else {
      console.warn('PE engine not initialized');
    }
  }
};

// 将生命周期函数添加到全局作用域
if (typeof window !== 'undefined') {
  window.onLoad = lifecycleHooks.onLoad;
  window.onShow = lifecycleHooks.onShow;
  window.onHide = lifecycleHooks.onHide;
  window.onDestory = lifecycleHooks.onDestory;
}

export default PE;
export { lifecycleHooks };