<script setup>

import {ref} from "vue"
import CodeLabel from "@/components/common/CodeLabel.vue";

const {vars} = (function () {
	return {
		vars: ref([])
	}
})()

const update = function (variablesString) {
	vars.value = []
	variablesString.replace(/\${.+?}/g, function (v) {
		let def = findVar(v)
		if (def == null) {
			return v
		}
		vars.value.push(def)
	})
}

const findVar = function (name) {
	let def = null
	window.REQUEST_VARIABLES.forEach(function (v) {
		if (v.code == name) {
			def = v
		}
	})
	return def
}


defineExpose({
	update
})

</script>

<template>
<span>
	<span v-for="(v, index) in vars"><CodeLabel :title="v.description">{{ v.code }}</CodeLabel> - {{ v.name }}<span v-if="index < vars.length-1">；</span></span>
</span>
</template>

<style scoped>
</style>
