// import 'default-passive-events';

import App from './App'
import store from './store/index'

import { Provider } from 'react-redux'
import { createRoot } from 'react-dom/client'

import { ConfigProvider } from 'antd'

// 兼容360浏览器
import { StyleProvider, legacyLogicalPropertiesTransformer } from '@ant-design/cssinjs'

import 'dayjs/locale/zh-cn'
import locale from 'antd/locale/zh_CN'

const container = document.getElementById('root') as HTMLElement
const root = createRoot(container)

root.render(
  <ConfigProvider
    locale={locale}
    theme={{
      token: {
        colorPrimary: ' #534638'
      }
    }}
  >
    <Provider store={store}>
      <StyleProvider hashPriority='high' transformers={[legacyLogicalPropertiesTransformer]}>
        <App />
      </StyleProvider>
    </Provider>
  </ConfigProvider>
)

//旧版本浏览器，按 Backspace 键会回退到上一个页面
const handleBackspace = (e: KeyboardEvent) => {
  const target = e.target as HTMLElement | null
  // 判断是否在可输入区域（input/textarea/内容可编辑元素）
  const isInputArea = target?.matches('input, textarea, [contenteditable="true"]')

  // 非输入区域按下Backspace时阻止回退行为
  if (e.key === 'Backspace' && !isInputArea) {
    e.preventDefault()
  }
}
document.addEventListener('keydown', handleBackspace)
