import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, IndexRoute, Redirect, browserHistory } from 'react-router';

// 引入单个页面（包括嵌套的子页面）
import Login from './pages/login';
import NotFoundPage from './pages/nofind';
import Mmain from './pages/main/mmain';
import MSearch from './pages/msearch';
import About from './pages/about';
import MachineOEE from './pages/dashboard/userboard';
import { Auth } from './Utils/help';
import DownloadPage from './pages/download';
import BasePage from './pages/common/basepage'
import EnergyAnalysis from './pages/dashboard/energyanalysis';
import EnergyAnalysisDetail from './pages/dashboard/energyanalysisdetail';
import OEE from './pages/dashboard/oee';
import OEEDetail from './pages/dashboard/oeedetail';
import QualitySpc from './pages/dashboard/qualityspc';
// import QualitySpcDetail from './pages/dashboard/qualityspcdetail';
import Sasoprodstatus from './pages/dashboard/sasoprodstatus';
import MacState from './pages/dashboard/macstatelist';
import macstateparameterlist from './pages/dashboard/macstateparameterlist';
import alertlist from './pages/dashboard/alertlist';
import AlertDetail from './pages/dashboard/alertdetail';
import Subscription from './pages/dashboard/subscription';
import maintenance from './pages/dashboard/maintenance';
import maintenancedetail from './pages/dashboard/maintenancedetail';
import WorkshopList from './pages/dashboard/workshoplist';
import MactypeList from './pages/dashboard/mactypelist';
import switchmachine from './pages/dashboard/switchmachine';
import speed from './pages/dashboard/speed';
import macalert from './pages/dashboard/macalert';
import MacStatusList from './pages/dashboard/macstatuslist';
import MacStatusNowInfo from './pages/dashboard/macstatusnowinfo';
import dbalert from './pages/dashboard/dbalert';
import MacStatusOEE from './pages/dashboard/macstatusoee';
import todayopen from './pages/dashboard/todayopen';
import mactypealert from './pages/dashboard/mactypealert';
import maintain from './pages/dashboard/maintain';
import maintaindetail from './pages/dashboard/maintaindetail';
import machealthchecklog from './pages/dashboard/machealthchecklog';
import machealthchecklogdetail from './pages/dashboard/machealthchecklogdetail';
import mactypealertdetail from './pages/dashboard/mactypealertdetail';
import repairs from './pages/dashboard/repairs'
import myallbills from './pages/dashboard/myallbills'
import repairsdetail from './pages/dashboard/repairsdetail'
import CostOEEMap from './pages/dashboard/costoeemap'
import maintainsituation from './pages/dashboard/maintainsituation'
import maintainsituationperiod from './pages/dashboard/maintainsituationperiod'
import myrepairsdetail from './pages/dashboard/myrepairsdetail'
import devrepairsdetail from './pages/dashboard/devrepairsdetail'
import Output from './pages/dashboard/Output'
import wastnum from './pages/dashboard/wastnum'
import wastnumdetail from './pages/dashboard/wastnumdetail'
import RepairsSundry from './pages/dashboard/repairssundry'
import spotcheck from './pages/dashboard/spotcheck';
import spotcheckdetail from './pages/dashboard/spotcheckdetail';
import DingTalkWork from './pages/dingtalkwork';


window.globalpresenttab = 'dashboard'



// 引入垫片兼容IE
require('es5-shim');
require('console-polyfill');

const requireAuth = (nextState, replace) => {
    if (!Auth.isAdmin()) {
        // Redirect to Home page if not an Admin
        replace({ pathname: '/login' })
    }
}
//function requireAuth(nextState, replaceState) {
//  if (!hasLogin()) {
//   replaceState({ nextPathname: nextState.location.pathname }, '/signIn');
//  }
//}
// 配置路由，并将路由注入到id为init的DOM元素中
ReactDOM.render(
    <Router history={browserHistory} >
        <Route path="/login" component={Login} />
        <Route path="/app" component={DownloadPage} />
        <Route path="/" onEnter={requireAuth} >
            <IndexRoute component={Mmain} />
            <Route path='home' component={Mmain} />
            <Route path='page' component={BasePage}>
                <Route path='/about' component={About} />
                <Route path='/machineoee' component={MachineOEE} />
                <Route path='/energyanalysis' component={EnergyAnalysis} />
                <Route path='/energyanalysisdetail' component={EnergyAnalysisDetail} />
                <Route path='/oee' component={OEE} />
                <Route path='/oeedetail' component={OEEDetail} />
                <Route path='/qualityspc' component={QualitySpc} />
                {/* <Route path='/qualityspcdetail' component={QualitySpcDetail} /> */}
                <Route path='/macstate' component={MacState} />
                <Route path='/macstatep' component={macstateparameterlist} />
                <Route path='/sasoprodstatus' component={Sasoprodstatus} />
                <Route path='/alertlist' component={alertlist} />
                <Route path='/alertdetail' component={AlertDetail} />
                <Route path='/subscription' component={Subscription} />
                <Route path='/maintenance' component={maintenance} />
                <Route path='/maintenancedetail' component={maintenancedetail} />
                <Route path='/workshoplist' component={WorkshopList} />
                <Route path='/mactypelist' component={MactypeList} />
                <Route path='/switchmachine' component={switchmachine} />
                <Route path='/speed' component={speed} />
                <Route path='/macalert' component={macalert} />
                <Route path='/macstatuslist' component={MacStatusList} />
                <Route path='/macstatusnowinfo' component={MacStatusNowInfo} />
                <Route path='/dbalert' component={dbalert} />
                <Route path='/macstatusoee' component={MacStatusOEE} />
                <Route path='/todayopen' component={todayopen} />
                <Route path='/mactypealert' component={mactypealert} />
                <Route path='/maintain' component={maintain} />
                <Route path='/maintaindetail' component={maintaindetail} />
                <Route path='/machealthchecklog' component={machealthchecklog} />
                <Route path='/machealthchecklogdetail' component={machealthchecklogdetail} />
                <Route path='/mactypealertdetail' component={mactypealertdetail} />
                <Route path='/repairs' component={repairs} />
                <Route path='/myallbills' component={myallbills} />
                <Route path='/repairsdetail' component={repairsdetail} />
                <Route path='/costoeemap' component={CostOEEMap} />
                <Route path='/maintainsituation' component={maintainsituation} />
                <Route path='/myrepairsdetail' component={myrepairsdetail} />
                <Route path='/devrepairsdetail' component={devrepairsdetail} />
                <Route path='/Output' component={Output} />
                <Route path='/wastnum' component={wastnum} />
                <Route path='/wastnumdetail' component={wastnumdetail} />
                <Route path='/repairssundry' component={RepairsSundry} />
                <Route path='/maintainsituationperiod'  component={maintainsituationperiod}/>
                <Route path='/spotcheck' component={spotcheck} />
                <Route path='/spotcheckdetail' component={spotcheckdetail} />
                <Route path='/dingtalkwork' component={DingTalkWork} />
            </Route>
        </Route>
        <Route path='/scan' component={MSearch} />
        {/* 404 */}
        <Route path='404' component={NotFoundPage} />
        {/* 其他重定向到 404 */}
        <Redirect from='*' to='404' />
    </Router>
    , document.querySelector('#init')
)