import dva from 'dva'
import undoable, { includeAction } from 'redux-undo'
import indexRouter from './routes/router'
import mainModel from './models/main'
import homeModel from './models/home'
import dataSource from './models/dataSource'
import dataSourceDetail from './models/dataSourceDetail'
import dataConnect from './models/dataConnect'
import chart from './models/chart'
import chartDesigner from './models/chartDesigner'
import dashboard from './models/dashboard'
import dashboardDesigner from './models/dashboardDesigner';
import userGroup from './models/userGroup'
import user from './models/user'
import chartPolicy from './models/chartPolicy'
import dataSourcePolicy from './models/dataSourcePolicy'
import dataList from './models/dataList'
import authority from './models/authority'
import logs from './models/logs'
import recent from './models/recent'
import createLoading from 'dva-loading';
import './utils/baseUtils'
import './themes/default/index.less'

// 1. Initialize
const app = dva({
    onReducer: reducer => (state, action) => {
        const newState = undoable(reducer, {
            limit: 10,
            filter: includeAction(['chartDesigner/setField', 'chartDesigner/setFields']), // 只对图表编辑界面的部分action生效
        })(state, action);
        return { ...newState };
    },
});

// 2. Plugins
app.use(createLoading());

// 3. Model
app.model(homeModel); // 通用action
app.model(mainModel); // 通用action
app.model(dataConnect); // 数据链接
app.model(dataSource); // 数据源
app.model(dataSourceDetail); // 数据源详细数据
app.model(chart);  // 图表
app.model(chartDesigner); // 图表设计
app.model(dashboard);  //报告与报表
app.model(dashboardDesigner); // 报表设计
app.model(userGroup); // 用户组
app.model(user); // 用户
app.model(chartPolicy); // 图表策略
app.model(dataSourcePolicy); // 数据源策略
app.model(dataList); // 数据列表
app.model(recent); // 最近访问记录
app.model(authority); // 权限控制
app.model(logs); // 操作日志

// 4. Router
app.router(indexRouter);

// 5. Start
app.start('#root');
