<script setup>
import {inject} from "vue";

const Tea = inject("$Tea")
const popupState = inject("$popupState", null)

const props = defineProps({
	href: String,
	active: Boolean
})

const onClick = (e) => {
	if (popupState == null) {
		return
	}

	let url = ""
	if (typeof props.href == "string") {
		url = props.href
	}

	if (/^(http|https):\/\//i.test(url)) {
		return
	}

	e.preventDefault()

	Tea.reloadViewData(url)

	// TODO 如果是多个不同路径URL之间相互跳转，则以新弹窗的形式打开
}
</script>

<template>
	<a :href="href" @click="onClick" :class="{active: active}">
		<slot></slot>
	</a>
</template>

<style scoped>

</style>