import * as constants from './constants';
import { fromJS } from 'immutable';

const defaultState = fromJS({
	clientList: [],
	columns: [
		{ data: "clientname" },
		{ data: "companyname" },
		{ data: "telephone" },
		{ data: "phone" },
		{ data: "qq" },
		{ data: "department" },
		{ data: "position" },
		{ data: "office" },
		{ data: "local" },

		{ data: "local" },
		{ data: "local" },

		{ data: "address" },
		{ data: "ride" },
		{ data: "landmarks" },
		{ data: "stay" },
		{ data: "mark" },

		{ data: "mark" },
		{ data: "mark" },
		{ data: "mark" },
		{ data: "mark" },
	],
	columnsData:[
		{columnsName:'联系人',columnsValue:true},
		{columnsName:'客户名称',columnsValue:true},
		{columnsName:'手机',columnsValue:true},
		{columnsName:'电话',columnsValue:true},
		{columnsName:'QQ',columnsValue:true},
		{columnsName:'部门',columnsValue:true},
		{columnsName:'职务',columnsValue:true},
		{columnsName:'办公室',columnsValue:true},
		{columnsName:'地区',columnsValue:true},
		{columnsName:'个人标签',columnsValue:true},
		{columnsName:'协作标签',columnsValue:true},
		{columnsName:'地址',columnsValue:true},
		{columnsName:'乘车',columnsValue:true},
		{columnsName:'地标',columnsValue:true},
		{columnsName:'住宿',columnsValue:true},
		{columnsName:'备注',columnsValue:true},
		{columnsName:'软件锁',columnsValue:true},
		{columnsName:'大司空',columnsValue:true},
		{columnsName:'养护云',columnsValue:true},
		{columnsName:'创建人',columnsValue:true},
	],
	
});

export default (state = defaultState, action) => {
	let columnsData=state.get('columnsData').toJS();

	switch (action.type) {
		case constants.TOGGLE_COLUMNS:
			columnsData[action.data].columnsValue=!columnsData[action.data].columnsValue;
			//存储
			localStorage.setItem('contact_client_Column_'+action.data, columnsData[action.data].columnsValue);
			return state.set('columnsData', fromJS(columnsData));
		case constants.TOGGLE_COLUMNS_ALL:
			for(var i=1;i<=columnsData.length;i++){
				var isAccept=localStorage.getItem("contact_client_Column_"+i);
				if(isAccept==='false'){
					columnsData[i].columnsValue=false;
					action.dt.handleColumnVisible(i,false);
				}
			}
			return state.set('columnsData', fromJS(columnsData));
		case constants.CHANGE_CLIENT_DATA:
			return state.set('clientList', action.data);
		default:
			return state;
	}
	// switch(action.type) {
	// 	case constants.SEARCH_FOCUS:
	// 		return state.set('focused', true);
	// 	case constants.SEARCH_BLUR:
	// 		return state.set('focused', false);
	// 	case constants.CHANGE_LIST:
	// 		return state.merge({
	// 			list: action.data,
	// 			totalPage: action.totalPage
	// 		});
	// 	case constants.MOUSE_ENTER:
	// 		return state.set('mouseIn', true);
	// 	case constants.MOUSE_LEAVE:
	// 		return state.set('mouseIn', false);
	// 	case constants.CHANGE_PAGE:
	// 		return state.set('page', action.page);
	// 	default:
	// 		return state;
	// }

}