import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { Provider } from 'react-redux'
import { RouterProvider } from 'react-router-dom'
import { ConfigProvider } from 'antd'
import zhCN from 'antd/locale/zh_CN'
import { store } from '@/store'
import { router } from '@/router'
import { setUnauthorizedHandler } from '@/api/request'
import { loggedOut } from '@/store/auth'
import './styles/global.css'

setUnauthorizedHandler(() => {
  store.dispatch(loggedOut())
  if (location.pathname !== '/login') location.assign('/login')
})

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <Provider store={store}>
      <ConfigProvider locale={zhCN} theme={{ token: { colorPrimary: '#2f7adf', borderRadius: 2 } }}>
        <RouterProvider router={router} />
      </ConfigProvider>
    </Provider>
  </StrictMode>,
)
