<template>
	<view class="policy-dialog" v-if="visible" @click="onMaskClick">
		<view class="dialog-content" @click.stop>
			<view class="dialog-header">
				<text class="dialog-title">{{ title }}</text>
				<view class="close-btn" @click="onClose">
					<uni-icons type="closeempty" size="20" color="#999"></uni-icons>
				</view>
			</view>

			<scroll-view scroll-y class="dialog-body">
				<view class="policy-content">
					<rich-text :nodes="content" class="policy-text"></rich-text>
				</view>
			</scroll-view>

			<view class="dialog-footer">
				<button class="confirm-btn" @click="onClose">我知道了</button>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref, watch } from 'vue'

const props = defineProps({
	visible: {
		type: Boolean,
		default: false
	},
	title: {
		type: String,
		default: ''
	},
	content: {
		type: String,
		default: ''
	},
	maskClosable: {
		type: Boolean,
		default: true
	}
})

const emit = defineEmits(['update:visible', 'close'])

const onClose = () => {
	emit('update:visible', false)
	emit('close')
}

const onMaskClick = () => {
	if (props.maskClosable) {
		onClose()
	}
}
</script>

<style lang="scss" scoped>
.policy-dialog {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 9999;
	padding: 40rpx;
}

.dialog-content {
	width: 100%;
	max-height: 80vh;
	background: #fff;
	border-radius: 32rpx;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.dialog-header {
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	padding: 32rpx;
	border-bottom: 1rpx solid #f5f5f5;
}

.dialog-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
}

.close-btn {
	position: absolute;
	right: 32rpx;
	top: 50%;
	transform: translateY(-50%);
}

.dialog-body {
	flex: 1;
	overflow-y: auto;
}

.policy-content {
	padding: 32rpx 40rpx 40rpx 40rpx;
	line-height: 1.8;
}

.policy-text {
	display: block;
	font-size: 28rpx;
	color: #666;
	line-height: 1.8;
	word-break: break-all;
}

.dialog-footer {
	padding: 24rpx 32rpx;
	border-top: 1rpx solid #f5f5f5;
}

.confirm-btn {
	width: 100%;
	height: 88rpx;
	background: linear-gradient(90deg, #ffd53f, #ff9500);
	color: #333;
	border: none;
	border-radius: 44rpx;
	font-size: 30rpx;
	font-weight: bold;
}
</style>
