<template>
	<view class="agreement-mask" v-if="show" @click.stop="closePopup">
		<!-- 弹窗主体：支持自定义边框、背景 -->
		<view 
			class="agreement-popup" 
			@click.stop
			:style="{
				border: popupBorder,
				backgroundColor: popupBg,
				borderRadius: popupRadius
			}"
			:class="popupClass"
		>
			<view class="popup-content">
				<!-- 动态图标：支持自定义大小、边距 -->
				<image 
					v-if="showIcon && icon" 
					:src="icon" 
					mode="aspectFit" 
					class="svg"
					:style="iconStyle"
				></image>
				
				<view class="text-content">
					<!-- 动态标题：支持自定义颜色、字体大小 -->
					<view 
						class="popup-Title" 
						v-if="title"
						:style="{
							color: titleColor,
							fontSize: titleSize,
							padding: titlePadding
						}"
					>
						{{ title }}
					</view>
					
					<!-- 动态消息内容：支持自定义颜色、换行、字体大小 -->
					<view 
						class="popup-Message" 
						v-if="message"
						:style="{
							color: messageColor,
							fontSize: messageSize,
							whiteSpace: messageWrap ? 'normal' : 'nowrap',
							padding: messagePadding
						}"
					>
						{{ message }}
					</view>
				</view>
			</view>
			
			<!-- 按钮组：支持自定义按钮样式 -->
			<view class="popup-buttons" :style="{ marginTop: buttonGroupMargin }">
				<button 
					v-if="showCancel" 
					class="btn cancelBtn" 
					@click="handleCancel"
					:style="{
						border: cancelBtnBorder,
						color: cancelBtnColor,
						backgroundColor: cancelBtnBg,
						fontSize: cancelBtnSize,
						borderRadius: buttonRadius,
						margin: buttonMargin
					}"
					:class="cancelBtnClass"
				>
					{{ cancelText }}
				</button>
				
				<button 
					class="btn agreeBtn" 
					@click="handleConfirm"
					:style="{
						backgroundColor: confirmBtnBg,
						color: confirmBtnColor,
						fontSize: confirmBtnSize,
						borderRadius: buttonRadius,
						margin: buttonMargin
					}"
					:class="confirmBtnClass"
				>
					{{ confirmText }}
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'CustomPopup',
		props: {
			// 基础控制
			show: {
				type: Boolean,
				default: false
			},
			title: {
				type: String,
				default: ''
			},
			message: {
				type: String,
				default: ''
			},
			confirmText: {
				type: String,
				default: '确定'
			},
			cancelText: {
				type: String,
				default: '取消'
			},
			showCancel: {
				type: Boolean,
				default: false
			},
			showIcon: {
				type: Boolean,
				default: true
			},
			icon: {
				type: String,
				default: ''
			},
			// 文本换行控制
			messageWrap: {
				type: Boolean,
				default: false // 默认不换行，true则自动换行
			},
			
			// 弹窗样式自定义
			popupBorder: {
				type: String,
				default: '1px solid rgba(187, 230, 0, 0.3)'
			},
			popupBg: {
				type: String,
				default: 'rgb(42, 42, 42)'
			},
			popupRadius: {
				type: String,
				default: '40rpx'
			},
			popupClass: {
				type: String,
				default: ''
			},
			
			// 标题样式自定义
			titleColor: {
				type: String,
				default: 'rgba(255, 255, 255, 0.86)'
			},
			titleSize: {
				type: String,
				default: '32rpx'
			},
			titlePadding: {
				type: String,
				default: '10rpx 0 10rpx'
			},
			
			// 消息样式自定义
			messageColor: {
				type: String,
				default: 'rgba(255, 255, 255, 0.7)'
			},
			messageSize: {
				type: String,
				default: '28rpx'
			},
			messagePadding: {
				type: String,
				default: '10rpx 20rpx 30rpx'
			},
			
			// 图标样式自定义
			iconStyle: {
				type: Object,
				default: () => ({
					width: '72rpx',
					height: '60rpx',
					marginBottom: '20rpx'
				})
			},
			
			// 按钮组样式
			buttonGroupMargin: {
				type: String,
				default: '20rpx'
			},
			buttonRadius: {
				type: String,
				default: '40rpx'
			},
			buttonMargin: {
				type: String,
				default: '0 10rpx'
			},
			
			// 确认按钮样式
			confirmBtnBg: {
				type: String,
				default: 'rgba(187, 230, 0, 1)'
			},
			confirmBtnColor: {
				type: String,
				default: '#232323'
			},
			confirmBtnSize: {
				type: String,
				default: '24rpx'
			},
			confirmBtnClass: {
				type: String,
				default: ''
			},
			
			// 取消按钮样式
			cancelBtnBorder: {
				type: String,
				default: '1px solid rgba(255, 255, 255, 0.3)'
			},
			cancelBtnColor: {
				type: String,
				default: 'rgba(255, 255, 255, 0.7)'
			},
			cancelBtnBg: {
				type: String,
				default: 'transparent'
			},
			cancelBtnSize: {
				type: String,
				default: '24rpx'
			},
			cancelBtnClass: {
				type: String,
				default: ''
			}
		},
		methods: {
			handleConfirm() {
				this.$emit('confirm')
				this.$emit('update:show', false)
			},
			handleCancel() {
				this.$emit('cancel')
				this.$emit('update:show', false)
			},
			closePopup() {
				this.$emit('close')
				this.$emit('update:show', false)
			}
		}
	}
</script>

<style scoped>
	/* 遮罩层：全屏覆盖 */
	.agreement-mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 1);
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 9999;
	}

	/* 弹窗主体：基础样式 */
	.agreement-popup {
		width: 66%;
		padding: 30rpx;
		text-align: center;
	}

	/* 内容区域布局 */
	.popup-content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.text-content {
		width: 100%;
	}

	/* 按钮基础样式（不包含可变样式） */
	.popup-buttons {
		display: flex;
		justify-content: center;
	}

	.btn {
		height: 60rpx;
		line-height: 60rpx;
		padding: 0 30rpx;
		min-width: 170rpx;
		border: none;
	}

	/* 解决按钮默认样式冲突 */
	.btn::after {
		border: none;
	}
</style>