import conditionObjectBase from "../condition-object-base.js"
import * as ext from '@/utils'

export default {
	...conditionObjectBase,
	key: 'daterange',
	title: '时间',
	template: 'date-range',
	neverCache: true,
	modelAsParam: true,
	disableAllByForce: true,
	getList: function(param) {
		// 设置两个默认时间
		let current = param[this.key]
		if (current?.length == 2) {
			return Promise.resolve([current])
		} else {
			return Promise.resolve([ext.getDefaultDateRange()])
		}
	},
	getCode: function(item) {
		return item
	},
	getLabel: function(item) {
		return item
	},
	codeEquals(codeL, codeR) {
		if (Array.isArray(codeL) && Array.isArray(codeR)) {
			return JSON.stringify(codeL) == JSON.stringify(codeR)
		}
		return codeL == codeR
	},
	_valid(val) {
		return Array.isArray(val) && val.length == 2
	}
}
