import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'
import { reportError } from './api'

// 全局错误捕获：JS 运行时异常
window.onerror = (_message, source, lineno, colno, error) => {
  if (error) {
    reportError(error, { source, lineno, colno })
  }
}

// 全局错误捕获：未处理的 Promise rejection
window.onunhandledrejection = (event: PromiseRejectionEvent) => {
  const error = event.reason instanceof Error
    ? event.reason
    : new Error(String(event.reason))
  reportError(error, { type: 'unhandledrejection' })
}

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