import './utils/storageShim' // 必须在最前面导入，处理 localStorage 权限问题
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
import ErrorBoundary from './components/ErrorBoundary.jsx'
import { registerSW } from 'virtual:pwa-register'

console.log('[MengyaNote] 应用启动...');
console.log('[MengyaNote] 环境:', import.meta.env.MODE);
console.log('[MengyaNote] API地址:', import.meta.env.VITE_API_BASE || 'http://192.168.1.233:2424');

// PWA：注册 Service Worker，有新版本时自动更新
registerSW({
  onNeedRefresh() {},
  onOfflineReady() {
    console.log('[MengyaNote] 内容已缓存，可离线使用');
  }
});

createRoot(document.getElementById('root')).render(
  <StrictMode>
    <ErrorBoundary>
      <App />
    </ErrorBoundary>
  </StrictMode>,
)
