<script setup>

import {onMounted, ref} from "vue"
import TInputText from "@/components/ui/TInputText.vue";
import CodeLabel from "@/components/common/CodeLabel.vue";

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

const valueInputRef = ref()
const {cond} = (function () {
	let cond = {
		isRequest: true,
		param: "${userAgent}",
		operator: "not regexp",
		value: "",
		isCaseInsensitive: false
	}
	if (props.vCond != null && typeof props.vCond.value == "string") {
		cond.value = props.vCond.value
	}
	return {
		cond: ref(cond)
	}
})()

const changeCaseInsensitive = function (isCaseInsensitive) {
	cond.value.isCaseInsensitive = isCaseInsensitive
}

onMounted(() => {
	valueInputRef.value.focus()
})

defineExpose({
	changeCaseInsensitive
})

</script>

<template>
	<div>
		<input type="hidden" name="condJSON" :value="JSON.stringify(cond)"/>
		<TInputText type="text" v-model="cond.value" ref="valueInputRef" class="w-full"/>
		<p class="comment">匹配User-Agent的正则表达式，比如
			<CodeLabel>Android|iPhone</CodeLabel>
			，如果匹配，则排除此条件。
		</p>
	</div>
</template>

<style scoped>
</style>
