import 'toss.assets/less/theme.less'
import 'toss.assets/scss/_base.scss'
import { hot } from 'react-hot-loader'
import React from 'react'
import { Provider } from 'react-redux'
import { Router, Switch } from 'react-router-dom'
import store from 'toss.store'
import { createHistory } from 'toss.history'
import { Table } from 'antd'
import { TableEmptyText } from 'toss.components'
import { lang } from 'toss.utils/lang'

window.lang = lang

// 初始化Ant Design相关功能
Table.defaultProps = Table.defaultProps || {}
Table.defaultProps.locale = {
  emptyText: <TableEmptyText />,
}

const AppEntry = hot(module)(({ history, routerOptions, children }) => {
  return (
    <Router history={history} {...routerOptions}>
      <Switch>{children}</Switch>
    </Router>
  )
})

const TossEntry = props => {
  const history = createHistory(props.historyType, {
    basename: props.basename,
    ...props.historyOptions,
  })

  return (
    <Provider store={store}>
      <AppEntry history={history} routerOptions={props.routerOptions}>
        {props.children}
      </AppEntry>
    </Provider>
  )
}

TossEntry.defaultProps = {
  routerOptions: {},
  historyOptions: {},
  historyType: 'browserHistory',
  basename: '/',
}

export default TossEntry
