import {
  PAPER_W,
  PAPER_H,
  SVG_BORDER_PROP,
  CONTENT_MT,
  CONTENT_ML,
  ANCHORPROP,
  CONTENT_START_X,
  CONTENT_START_Y,
  INFO_W,
  INFO_H,
  INFO_ITEM_GAP,
  INFO_ITEM_MARGIN,
  ID_LENGTH,
  INFO_LEFT_X,
  INFO_LEFT_W,
  ID_TITLE_H,
  ID_TITLE_Y,
  NUMBER_CELL_H,
  NUMBER_ITEM_W,
  NUMBER_ITEM_H,
  NUMBER_ITEM_MT,
  NUMBER_ITEM_ML
} from '../../utils/sheetConfig'
export default {
	state: {
		count: 0,
		pages: 1,
		isNewPage: false,
		isAutoCreate:false,
		needFixArr: [26],
		paperItem:{
			name:''
		},
		editorInfos: {
			
		},
		sheetConfig: {
			// 答题卡宽高
			pageConfig: {
				width: PAPER_W,
				height: PAPER_H
			},
			// 答题卡四个定位锚点
			pageAnchor: [
				[ANCHORPROP.gapX, ANCHORPROP.gapY, ANCHORPROP.width, ANCHORPROP.height],
				[PAPER_W - ANCHORPROP.width - ANCHORPROP.gapX, ANCHORPROP.gapY, ANCHORPROP.width, ANCHORPROP
				.height],
				[ANCHORPROP.gapX, PAPER_H - ANCHORPROP.height - ANCHORPROP.gapY, ANCHORPROP.width, ANCHORPROP
					.height],
				[PAPER_W - ANCHORPROP.width - ANCHORPROP.gapX, PAPER_H - ANCHORPROP.height - ANCHORPROP.gapY,
					ANCHORPROP.width, ANCHORPROP.height
				]
			],
			// 答题卡外框
			outerRect: [SVG_BORDER_PROP.x, SVG_BORDER_PROP.y, SVG_BORDER_PROP.width, SVG_BORDER_PROP.height],
			// 基本信息框
			baseInfoRect: [CONTENT_START_X, CONTENT_START_Y, INFO_W, INFO_H],
			// 客观题框
			objectiveRect: [],
			// 填空题框
			completeRect: [],
			// 主观题框
			subjectiveRect: []
		}
	},

	mutations: {
		setCreateModal(state,val){
			state.isAutoCreate = val === 'auto'
		},
		setPaper(state,val){
			state.paperItem = val
		},
		setPaperItems(state,val){
			state.paperItem.item = val
		},
		deleteItem(state,val){
			let index = state.paperItem.item.map(i => i.id).indexOf(val)
			state.paperItem.item.splice(index,1)
		},
		addPage(state) {
			state.pages++
		},
		clearPage(state) {
			state.pages = 1
		},
		changeNewPage(state, val) {
			state.isNewPage = val
		},
		addFixItem(state, val) {
			state.needFixArr.push(val)
		},
		clearFixArr(state) {
			state.needFixArr = []
		},
		clearIsNewPage(state){
			state.isNewPage = false
			state.editorInfos = {
				
			}
		},
		setEditorHeight(state, val) {
			if (state.editorInfos[val.id]) {
				state.editorInfos[val.id].height = val.height
				if(val.content){
					state.editorInfos[val.id].content = val.content
				}
			} else {
				state.editorInfos[val.id] = {
					height: val.height,
					content: val.content
				}
			}
		}
	},

}
