function formatLocation(longitude, latitude) {
	if (typeof longitude === 'string' && typeof latitude === 'string') {
		longitude = parseFloat(longitude)
		latitude = parseFloat(latitude)
	}

	longitude = longitude.toFixed(2)
	latitude = latitude.toFixed(2)

	return {
		longitude: longitude.toString().split('.'),
		latitude: latitude.toString().split('.')
	}
}

const formatPosition = function(res) {
	let postChildren = function(params) {

		if (params.length == 0) return [];

		let child = []
		params.map((item, index) => {
			child.push({
				label: item,
				value: item,
			})
		})
		return child
	}

	if (res && res.categories && res.categories.length > 0) {
		const {
			categories = []
		} = res;

		let result = []
		categories.map((item, index) => {
			result.push({
				label: item.name,
				value: item.name,
				children: postChildren(item.sub_categories || [])
			})
		})

		return result

	} else {
		return []
	}
}

const getLabel = function(options, initValue, i, result) {

	if (i > initValue.length - 1) {
		console.log(result)
		return result
	}

	if (initValue && initValue.length > 0) {
		let tempOption = options.filter(item => {
			return item.value == initValue[i]
		})

		let tempObject = tempOption[0]
		result.push({
			label: tempObject.label,
			value: tempObject.value,
		})

		i++
		return getLabel(tempObject.children, initValue, i, result)
	}
}

const genderOptions = [{
		label: '男',
		value: "0",
	},
	{
		label: '女',
		value: "1",
	}
];

const commonOptions = [{
		label: '是',
		value: "yes",
	},
	{
		label: '否',
		value: "no",
	}
];

const marriedOptions = [{
		label: '已婚',
		value: "1",
	},
	{
		label: '未婚',
		value: "2",
	},
];

const degreeOptions = [{
		label: '不限',
		value: '1'
	},
	{
		label: '初中',
		value: '2'
	},
	{
		label: '高中',
		value: '3'
	},
	{
		label: '中专/技校',
		value: '8'
	},
	{
		label: '大专',
		value: '4'
	},
	{
		label: '本科',
		value: '5'
	},
	{
		label: '硕士',
		value: '6'
	},
	{
		label: '博士',
		value: '7'
	},
	{
		label: 'MBA/EMBA',
		value: '9'
	},
];

//岗位类别
const positionTypeOptions = [{
		value: '',
		label: "全部",
	},
	{
		value: 'manufacture',
		label: "智能制造",
	},
	{
		value: 'preschool',
		label: "学前教育",
	}, {
		value: 'healthy',
		label: "智慧康养",
	}, {
		value: 'software',
		label: "大数据与软件",
	}, {
		value: 'other',
		label: "其他",
	},
];

//岗位性质
const positionPropOptions = [{
		value: 'part_time',
		label: "兼职",
	},
	{
		value: 'internship',
		label: "实习",
	}, {
		value: 'full_time',
		label: "全职",
	}, {
		value: 'other',
		label: "其他",
	},
];

//薪资类型
const salaryTypeOptions = [{
	value: 'negotiable',
	label: "薪资面议",
}, {
	// 	value: 'annual',
	// 	label: "年薪",
	// },{
	value: 'monthly',
	label: "月薪",
}, {
	value: 'daily',
	label: "日薪",
}, {
	label: "时薪",
	value: 'hourly',
}, ];

const schoolTypeOptions = [{
	label: '高职(高专)院校',
	value: 'vocational'
}, {
	label: '中等职业技术学院',
	value: "secondary_vocational",
}, {
	label: '技工学校(技校)',
	value: "technical",
}, {
	label: '全日制大学',
	value: "full_time",
}, {
	label: '民办独立学院',
	value: "civilian_run",
}, {
	label: '其他',
	value: "other",
}]

const unitOptions = [{ //计费单位
		label: '时',
		value: "hourly",
	},
	{
		label: '月',
		value: "monthly",
	},
];

const unitTypeOptions = [{ //委托招聘计费类型
		label: '打包服务费',
		value: "packing",
	},
	{
		label: '招聘服务费',
		value: "recruiting",
	},
];

const ageTypeOptions = [{ //年龄类型
		label: '年满16周岁',
		value: "16years",
	},
	{
		label: '年满18周岁',
		value: "18years",
	},
];


module.exports = {
	formatLocation,
	formatPosition,
	getLabel,
	genderOptions,
	marriedOptions,
	degreeOptions,
	positionTypeOptions,
	positionPropOptions,
	salaryTypeOptions,
	schoolTypeOptions,
	unitOptions,
	ageTypeOptions,
	commonOptions,
	unitTypeOptions
}