/* NOTE	思路：	见condition-mixins-data */
export default {
	props: {
		conditionsInput: {
			// 见computed.conditions
			// 独立模式时要求外部传入mixins-data产生的conditionsOutput
			type: Array,
			default: _ => []
		},
		errorsInput: {
			// 见computed.errors 非强制引入，一般呈现conditions中的error信息即可
			// 独立模式时***可能***要求外部传入mixins-data产生的errorsOutput
			type: Array,
			default: _ => []
		}
	},
	watch: {
		'conditionsOutput': function(newVal, oldVal) {
			console.log('mixins-view conditions changed:', newVal)
			this.conditions = newVal
		},
		'conditionsInput': function(newVal, oldVal) {
			console.log('mixins-view conditions changed:', newVal)
			this.conditions = newVal
		},
		'errorsInput': function(newVal, oldVal) {
			this.errors = newVal
		},
		'errorsOutput': function(newVal, oldVal) {
			this.errors = newVal
		},
	},
	data() {
		return {
			mixinsViewEnabled: true,
			conditions: [],
			errors: [],
		}
	},
	computed: {
		// conditions() {
		// 	// 如果是联合模式,直接取data.conditionOutput,否则取传入值(传入值由mixins-data提供)
		// 	// [{title:'',list:[{code:'',label:''}],key:'',error:''}]
		// 	let results = this.isCombineMode() ? this.conditionsOutput : this.conditionsInput
		// 	console.log('mixins-view conditions changed:', results)
		// 	return results
		// },
		// errors() {
		// 	// 这是condition-object.validate产生的原始错误，非强制引入，一般呈现conditions中的error信息即可
		// 	// 如果是联合模式,直接取data.errorsOutput,否则取传入值(传入值由mixins-data提供)
		// 	// [{title:'',list:[{code:'',label:''}],key:'',error:''}]
		// 	return this.isCombineMode() ? this.errorsOutput : this.errorsInput
		// },
	},
	mounted() {
		this.conditions = this.isCombineMode() ? this.conditionsOutput : this.conditionsInput
		this.errors = this.isCombineMode() ? this.errorsOutput : this.errorsInput
	},
	methods: {
		// 公共API
		isCombineMode() {
			// 此方法请与mixins-data保持一致
			return this.mixinsViewEnabled && this.mixinsDataEnabled
		},
		conditionChanged(key, newVal) {
			// 如果联合模式，修改属性值会直接被监听
			// 如果独立模式，则需要事件外抛来告知mixins.data
			if (this.isCombineMode() && typeof this.setModelValue == "function") {
				this.setModelValue(key, newVal)
			} else {
				this.$emit('conditionChanged', key, newVal)
			}
		}

		// 内部方法
	}
}
