import {
	EDITTIMELINEITEM,
	// RULEFORMINIT,
	ADDTIMELINEITEM,
	WAYSITEM,
} from '../constant/index.js';

export const addData = (datas, t) => {
	let item =
		datas.ruleForm.documentStatus === 'a'
			? JSON.parse(JSON.stringify(ADDTIMELINEITEM))
			: JSON.parse(JSON.stringify(EDITTIMELINEITEM));
	let waysItem = JSON.parse(JSON.stringify(WAYSITEM));
	//隐藏上一个添加审批方式按钮
	datas.timelineList.forEach((item) => {
		item.isNewAdd = false;
	});
	let length = datas.timelineList.length;
	item.id = length - 1;
	//显示下一个添加审批方式按钮
	datas.timelineList.splice(item.id, 0, item);

	//审批方式最多为3个,到达3个则不再显示添加审批方式按钮
	// if (datas.timelineList.length > 5) {
	// 	datas.timelineList.forEach((item) => {
	// 		item.isNewAdd = false;
	// 		item.isAdd = false;
	// 	});
	// }

	datas.ruleForm.details[datas.detailsIndex].ways.push(waysItem);

	let sum = 1;
	datas.timelineList.forEach((item) => {
		if (item.isLine) {
			sum++;
		}
		if (sum === datas.timelineList.length) {
			item.isLine = true;
		} else {
			datas.timelineList[datas.timelineList.length - 1].isLine = false;
		}
	});
};
