<template>
	<view v-if="visible" class="share-popup-overlay" @tap="handleOverlayClick">
		<view class="share-popup-container" @tap.stop>
			<!-- 背景 -->
			<image class="share-popup-bg" :src="`${$baseUrl}homepage/Q3Res/xingmaLabPosterBtnConBg.png`"
				mode="aspectFit"></image>

			<!-- 标题 -->
			<view class="share-popup-title">
				<view class="close-btn" @tap="handleClose">
					<image class="close-icon" :src="`${$baseUrl}homepage/Q3Res/xingmaLabPosterBtnConCloseBtn.png`"
						mode="aspectFit"></image>
				</view>
			</view>

			<!-- 按钮区域 -->
			<view class="share-popup-buttons">
				<!-- 分享给好友 -->
				<view class="share-button-item">
					<button open-type="share" class="share-button-trigger" @tap="handleShareToFriend">
						<view class="button-icon button-icon-share">
							<image class="icon-image"
								:src="`${$baseUrl}homepage/Q3Res/xingmaLabPosterBtnConShareBtn.png`" mode="aspectFit">
							</image>
						</view>
					</button>
				</view>

				<!-- 生成分享海报 -->
				<view class="share-button-item" @tap="handleGeneratePoster">
					<view class="button-icon button-icon-poster">
						<image class="icon-image"
							:src="`${$baseUrl}homepage/Q3Res/xingmaLabPosterBtnConShowPosterBtn.png`" mode="aspectFit">
						</image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { getCurrentInstance } from 'vue'

const { proxy } = getCurrentInstance()
const $baseUrl = proxy.$baseUrl

const props = defineProps({
	visible: {
		type: Boolean,
		default: false
	}
})

const emit = defineEmits(['close', 'shareToFriend', 'generatePoster'])

// 关闭弹窗
const handleClose = () => {
	emit('close')
}

// 点击遮罩关闭
const handleOverlayClick = () => {
	handleClose()
}

// 分享给好友
const handleShareToFriend = () => {
	emit('shareToFriend')
	handleClose()
}

// 生成分享海报
const handleGeneratePoster = () => {
	emit('generatePoster')
	handleClose()
}
</script>

<style lang="less" scoped>
.share-popup-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background-color: rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: flex-end;
	justify-content: center;
	z-index: 9999;
}

.share-popup-container {
	position: relative;
	width: 750rpx;
	height: 432rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.share-popup-bg {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: 0;
}

.share-popup-title {
	position: relative;
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	padding-top: 60rpx;
	z-index: 1;
}

.title-text {
	font-size: 36rpx;
	font-weight: 500;
	color: #333333;
}

.close-btn {
	position: absolute;
	right: 40rpx;
	top: 50%;
	transform: translateY(-50%);
	width: 48rpx;
	height: 48rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.close-icon {
	width: 48rpx;
	height: 48rpx;
}

.share-popup-buttons {
	position: relative;
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-around;
	padding: 80rpx 60rpx 0;
	z-index: 1;
}

.share-button-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	position: relative;
}

.share-button-trigger {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background: transparent;
	border: none;
	padding: 0;
	margin: 0;
	line-height: normal;
}

.share-button-trigger::after {
	border: none;
}

.button-icon {
	margin-bottom: 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.button-icon-share {
	width: 148rpx;
	height: 202rpx;
}

.button-icon-poster {
	width: 170rpx;
	height: 202rpx;
}

.icon-image {
	width: 100%;
	height: 100%;
}

.button-text {
	font-size: 28rpx;
	color: #333333;
}
</style>
