<script setup>

import "@/lib/array.js"
import {ref} from "vue"
import TLabel from "@/components/ui/TLabel.vue";
import "@/configs/definitions.js"

const props = defineProps(["v-cond", "isOn", "isReverse"])

const {cond, components} = (function () {
	return {
		cond: ref(props.vCond),
		components: ref(window.REQUEST_COND_COMPONENTS)
	}
})()

const typeName = function (cond) {
	let c = components.value.$find(function (k, v) {
		return v.type == cond.type
	})
	if (c != null) {
		return c.name;
	}
	return cond.param + " " + cond.operator
}

const updateConds = function (conds, simpleCond) {
	for (let k in simpleCond) {
		if (simpleCond.hasOwnProperty(k)) {
			cond.value[k] = simpleCond[k]
		}
	}
}

const notifyChange = function () {

}

defineExpose({
	updateConds,
	notifyChange
})

</script>

<template>
	<div>
		<TLabel outlined="" :class="{disabled:!isOn, red:isReverse}">
			<var v-if="cond.type.length == 0 || cond.type == 'params'" style="font-style: normal">{{ cond.param }}
				<var>{{ cond.operator }}</var></var>
			<var v-if="cond.type.length > 0 && cond.type != 'params'" style="font-style: normal">{{ typeName(cond) }}: </var>
			{{ cond.value }}
			<sup v-if="cond.isCaseInsensitive" title="不区分大小写"><i class="icon info small"></i></sup>
		</TLabel>
	</div>
</template>

<style scoped>
</style>
