import {dateHandle} from "../../../utils/dateHandle.js";
const {dateDiff} = dateHandle;
/**
 * 主题数据 
 */
export const themeList = [{
		id: 0, 
		title: '个案追踪', 
		des: '评价诊疗服务的内涵质量以及对各种诊疗规范、临床路径等的执行力',
	},{
		id: 1, 
		title: '系统追踪', 
		des: '评价对各种质量与安全管理制度与流程的执行力、医院服务的连贯性及多学科综合的服务能力',
}];
// 查核计划里的数据

export const checkPlanList = [
		{id: 'week', value: 1, label: '每周', model: 7},
		{id: 'month', value: 2, label: '每月', model: 30},
		{id: 'twoMonth', value: 3, label: '每两月', model: 60},
		{id: 'quarter', value: 4, label: '每季度', model: 90},
		{id: 'halfAYear', value: 5, label: '每半年', model: 180},
		{id: 'custom', value: 6, label: '天', model: null},
	];
/**
 * 底部按钮数据
 */
export const normalBtnGroup = [
	{id: 'pre', label: '上一步'},
	{id: 'next', label: '下一步'}
];
export const btnGroupPlan1 = [
	{id: 'pre', label: '上一步'},
	{id: 'checkPlanCreate', label: '生成查核计划'}
];
export const btnGroupPlan2 = [
	{id: 'checkPlanCallback', label: '返回'},
	{id: 'next', label: '下一步'}
];
export const btnGroupSituationPreview = [
	{id: 'pre', label: '上一步'},
	{id: 'situationPreviewOK', label: '完成'}
];

export const firstStepBtnGroup = [
	{id: 'goback', label: '返回'},
	{id: 'next', label: '下一步'}
];


/**
 * 增加树形数据字段，以适配公共组件
 * @param {Object} data
 */
export const conditionOptions = function(data) {
	if(!data) return [];
	let options = data.map((item)=>{
		return {
			...item,
			key: item.id,
			label: item.name,
			children: conditionOptions(item.child)
		}
	});
	return options;
}
			
/**
 * 创建
 * 构造条件提交结果
 */
export const optionsHandle = (arr, conditionIds) => {
	let options = [...arr].map((item)=>{
		return {
			...item,
			selectFlag: conditionIds.includes(item.id),
			child: optionsHandle(item.child, conditionIds)
		}
	});
	return options;
}
/**
 * 构造查核组提交数据
 */
export const checkGroup = function({list, checkedItem}) {
	let _list = [...list].map((ntem)=>{
		return {
			...ntem,
			selectFlag: ntem.id === checkedItem.id ? true : false
		}
	});
	return _list;
}
/**
 * 构造查核地图提交数据
 */
export const checkDep = function(list) {
	return list.map((item, i)=>{
		return {
			...item,
			sort: i+1,
			enableFlag: item.status === 'disable' ? false : true,
		}
	});
}

/**
 * 编辑
 * 条件树遍历，获取选中项的id
 */
export const initConditionIds = (arr, result) => {
	arr.map((item)=>{
		if(item.selectFlag || item.selectFlag === 'true') {
			result.push(item.id);
		}
		if(item.child && item.child.length > 0) {
			initConditionIds(item.child, result);
		}
	})
}

// 构造条件回显数据
export const editCondition = ({depType, filterCondition})=>{
	let conditionIds = [];
	initConditionIds(filterCondition, conditionIds);
	return {
		depType, // 门急诊类型 1-门诊 2-急诊
		conditionIds, // 选中的key
		options: conditionOptions(filterCondition), // 树形节点数据
		defaultOpen: filterCondition.length > 0 ? [filterCondition[0].id]:[], // 默认展开的项
	}
}
// 构造查核组回显数据
export const editCheckRent = ({checkGroup}) =>{
	let obj = checkGroup.find((item)=>item.selectFlag || item.selectFlag === 'true');
	return { // 查核组页面数据 
		list: checkGroup,
		checkedItem: obj ? obj : {id: null}
	}
}
// 查核地图数据
export const editCheckMap = ({checkDep}) =>{
	return { // 查核地图数据
		list: checkDep.map((item)=>{
			return {
				...item,
				status: 'normal'
			}
		}).sort((a,b)=>{
			if(a.sort && b.sort)
				return a.sort - b.sort;
		}), // 列表数据
		actionItem: {id: '', pointList: []}, // 当前操作的列表项
		deptList: [], // 新增单位数据
	}
}
// 查核计划数据
export const editCheckPlan = ({planConfig, planList}) =>{
	let checkedItem = checkPlanList.find((item)=>item.value === planConfig.frequency);
	return { // 查核计划
		checkedItem: checkedItem?checkedItem: {id: 'month', value: 2, label: '每月', model: 30}, // 选中的取模方式对象
		dateObj: { // 保存开始日期结束日期的对象
			start: planConfig.startDate,
			end: planConfig.endDate,
			dayNum: dateDiff(planConfig.startDat, planConfig.endDate) // 两个日期间隔的天数
		}, 
		checkList: planList.map((item)=>{
			return item.startDate
		}), // 核查计划数组
	}
}
// 预览数据
export const editSituationPreview = ({name, remindPlanDay,remindPlanHour,remindCheckDay,situationType,subtotal,showNotApplicable}) => {
	return {
		sitName: name,
		preDay: remindPlanDay,
		preH: remindPlanHour,
		startDay: remindCheckDay,
		situationType:situationType,
		subtotal:subtotal,
		showNotApplicable:showNotApplicable
	}
} 
// 判断两个数组全等
export const arrayEquality = (arr1,arr2) =>{
	let flage = true;
	arr1.map((item, i)=>{
		if(item !== arr2[i]){
			flage = false;
		}
	});
	return flage;
}
