<template>
	<xn-form-container
		title="发送邮件"
		:width="1000"
		:visible="visible"
		:destroy-on-close="true"
		:bodyStyle="{ 'padding-top': '0px' }"
		@close="onClose"
	>
		<a-tabs v-model:activeKey="activeKey">
			<a-tab-pane :key="1" tab="本地邮件">
				<localEmailSend ref="LocalEmailSend" @loadingStart="loadingStart" @loadingEnd="loadingEnd" />
			</a-tab-pane>
			<a-tab-pane :key="2" tab="阿里云邮件">
				<aliyunEmailSend ref="AliyunEmailSend" @loadingStart="loadingStart" @loadingEnd="loadingEnd" />
			</a-tab-pane>
			<a-tab-pane :key="3" tab="腾讯云邮件">
				<tencentEmailSend ref="TencentEmailSend" @loadingStart="loadingStart" @loadingEnd="loadingEnd" />
			</a-tab-pane>
		</a-tabs>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" @click="onSubmit" :loading="sendLoading">发送</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="emailForm">
	import localEmailSend from './send/localEmailSend.vue'
	import aliyunEmailSend from './send/aliyunEmailSend.vue'
	import tencentEmailSend from './send/tencentEmailSend.vue'

	const LocalEmailSend = ref()
	const AliyunEmailSend = ref()
	const TencentEmailSend = ref()

	// 默认是关闭状态
	let visible = $ref(false)
	const activeKey = ref(1)
	const sendLoading = ref(false)
	// 打开抽屉
	const onOpen = () => {
		visible = true
	}
	// 关闭抽屉
	const onClose = () => {
		visible = false
	}
	// 验证并提交数据
	const onSubmit = () => {
		const tabActiveKey = activeKey.value
		if (tabActiveKey === 1) {
			LocalEmailSend.value.send()
		} else if (tabActiveKey === 2) {
			AliyunEmailSend.value.send()
		} else if (tabActiveKey === 3) {
			TencentEmailSend.value.send()
		}
	}
	// 请求loading开始
	const loadingStart = () => {
		sendLoading.value = true
	}
	// 请求loading结束
	const loadingEnd = () => {
		sendLoading.value = false
	}
	// 调用这个函数将子组件的一些数据和方法暴露出去
	defineExpose({
		onOpen
	})
</script>
