<template>
	<view class="privacy-mask" v-if="show" @click="handleMaskClick">
		<view class="privacy-popup" @click.stop>
			<view class="popup-header">
				<text class="popup-title">请先阅读并同意协议</text>
				<view class="popup-close" @click="handleClose">✕</view>
			</view>
			<scroll-view class="popup-body" scroll-y>
				<view class="popup-content">
					<view class="section-text">
						我已仔细阅读并同意
						<text class="privacy-link" @click="goToUserAgreement">《用户协议》</text>和
						<text class="privacy-link" @click="goToPrivacy">《隐私政策》</text>
						全部内容。
					</view>
				</view>
			</scroll-view>
			<view class="popup-footer">
				<button class="popup-btn disagree-btn" @click="handleDisagree">不同意</button>
				<button class="popup-btn agree-btn" @click="handleAgree">同意</button>
			</view>
		</view>
	</view>
</template>

<script setup>
defineProps({
	show: {
		type: Boolean,
		default: false
	}
})

const emit = defineEmits(['agree', 'disagree', 'close', 'update:show'])

const handleAgree = () => {
	emit('agree')
}

const handleDisagree = () => {
	emit('disagree')
}

const handleClose = () => {
	emit('close')
	emit('update:show', false)
}

const handleMaskClick = () => {
	emit('close')
	emit('update:show', false)
}

// 打开用户协议
const goToUserAgreement = () => {
	// #ifdef APP-PLUS
	plus.runtime.openURL('https://wuye.ckdzkj.com/parivw/ownler_xieyi.html')
	// #endif
	// #ifdef H5
	window.open('https://wuye.ckdzkj.com/parivw/ownler_xieyi.html')
	// #endif
}

// 打开隐私政策
const goToPrivacy = () => {
	// #ifdef APP-PLUS
	plus.runtime.openURL('https://wuye.ckdzkj.com/parivw/owner.html')
	// #endif
	// #ifdef H5
	window.open('https://wuye.ckdzkj.com/parivw/owner.html')
	// #endif
}
</script>

<style scoped>
.privacy-mask {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	z-index: 9999;
	display: flex;
	align-items: center;
	justify-content: center;
}

.privacy-popup {
	width: 640rpx;
	max-height: 80vh;
	background: #fff;
	border-radius: 16rpx;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.popup-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 28rpx 30rpx 16rpx;
	border-bottom: 1rpx solid #eee;
}

.popup-title {
	font-size: 32rpx;
	font-weight: 600;
	color: #333;
}

.popup-close {
	width: 48rpx;
	height: 48rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 28rpx;
	color: #999;
	border-radius: 50%;
	background: #f5f5f5;
}

.popup-body {
	flex: 1;
	padding: 24rpx 30rpx;
	max-height: 50vh;
	box-sizing: border-box;
}

.popup-content .section-text {
	font-size: 26rpx;
	line-height: 1.8;
	color: #666;
	text-align: justify;
}

.privacy-link {
	color: #007aff;
}

.popup-footer {
	display: flex;
	padding: 20rpx 30rpx 30rpx;
	gap: 20rpx;
	border-top: 1rpx solid #eee;
}

.popup-btn {
	flex: 1;
	height: 80rpx;
	line-height: 80rpx;
	border-radius: 8rpx;
	font-size: 28rpx;
	border: none;
	padding: 0;
	margin: 0;
}

.popup-btn::after {
	border: none;
}

.disagree-btn {
	background: #f5f5f5;
	color: #666;
}

.agree-btn {
	background: #007aff;
	color: #fff;
}
</style>
