<template>
	<uni-popup ref="prizePopup" type="center" maskBackgroundColor="rgba(0,0,0,0.8)">
		<view class="prize-detail-popup" v-if="visible">
			<!-- 顶部装饰 -->
			<view class="popup-header">
				<image class="header-decoration" :src="$img1('common/reward_notice.png')" mode="aspectFit"></image>
			</view>
			
			<!-- 中奖信息区域 -->
			<view class="prize-info">
				<!-- 用户头像 -->
				<view class="avatar-wrapper">
					<image 
						class="avatar" 
						:src="announcement.userAvatar || defaultAvatar" 
						mode="aspectFill"
					></image>
				</view>
				
				<!-- 用户名 -->
				<view class="user-name">{{ announcement.userName || '幸运用户' }}</view>
				
				<!-- 中奖提示文字 -->
				<view class="prize-tip">恭喜抽中</view>
				
				<!-- 奖品等级 -->
				<view class="prize-level" v-if="announcement.prizeLevel">
					<text class="level-text">{{ announcement.prizeLevel }}</text>
				</view>
				
				<!-- 奖品名称 - Requirements 4.2 -->
				<view class="prize-name">{{ announcement.prizeName || '神秘奖品' }}</view>
			</view>
			
			<!-- 我也要玩按钮 - Requirements 4.3, 4.4 -->
			<view class="action-area">
				<view class="play-btn" @click="handlePlayClick">
					<text class="btn-text">我也要玩</text>
				</view>
			</view>
			
			<!-- 关闭按钮 -->
			<view class="close-btn" @click="close">
				<image :src="$img1('common/close.png')" mode="aspectFit"></image>
			</view>
		</view>
	</uni-popup>
</template>

<script>
/**
 * 中奖详情弹窗组件
 * 
 * @description 展示中奖公告的详细信息，包含奖品名称和"我也要玩"按钮
 * @property {Object} announcement - 公告数据对象
 *   @property {String} announcement.userAvatar - 用户头像URL
 *   @property {String} announcement.userName - 用户名称
 *   @property {String} announcement.prizeLevel - 奖品等级
 *   @property {String} announcement.prizeName - 奖品名称
 * @event {Function} play - 点击"我也要玩"按钮时触发
 * 
 * Validates: Requirements 4.1, 4.2, 4.3, 4.4
 */
export default {
	name: 'PrizeDetailPopup',
	
	props: {
		// 公告数据
		announcement: {
			type: Object,
			default: () => ({})
		}
	},
	
	data() {
		return {
			visible: false
		};
	},
	
	computed: {
		/**
		 * 默认头像URL
		 */
		defaultAvatar() {
			return this.$img1('common/logo.png');
		}
	},
	
	methods: {
		/**
		 * 打开弹窗
		 * Validates: Requirements 4.1
		 */
		open() {
			this.visible = true;
			
			this.$nextTick(() => {
				if (this.$refs.prizePopup) {
					// 小程序环境下需要额外延迟
					setTimeout(() => {
						this.$refs.prizePopup.open();
					}, 50);
				}
			});
		},
		
		/**
		 * 关闭弹窗
		 */
		close() {
			this.visible = false;
			if (this.$refs.prizePopup) {
				this.$refs.prizePopup.close();
			}
		},
		
		/**
		 * 点击"我也要玩"按钮
		 * Validates: Requirements 4.3, 4.4
		 */
		handlePlayClick() {
			// 关闭弹窗 - Requirements 4.4
			this.close();
			
			// 触发play事件
			this.$emit('play', this.announcement);
		}
	}
};
</script>

<style lang="scss" scoped>
.prize-detail-popup {
	width: 600rpx;
	background: linear-gradient(180deg, #FFF8E1 0%, #FFFFFF 100%);
	border-radius: 30rpx;
	padding: 40rpx 30rpx;
	box-sizing: border-box;
	position: relative;
	
	// 顶部装饰
	.popup-header {
		display: flex;
		justify-content: center;
		margin-bottom: 20rpx;
		
		.header-decoration {
			width: 120rpx;
			height: 120rpx;
		}
	}
	
	// 中奖信息区域
	.prize-info {
		display: flex;
		flex-direction: column;
		align-items: center;
		
		// 用户头像
		.avatar-wrapper {
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
			overflow: hidden;
			border: 4rpx solid #FFD700;
			box-shadow: 0 4rpx 12rpx rgba(255, 215, 0, 0.3);
			margin-bottom: 20rpx;
			
			.avatar {
				width: 100%;
				height: 100%;
			}
		}
		
		// 用户名
		.user-name {
			font-size: 32rpx;
			font-weight: bold;
			color: #333333;
			margin-bottom: 16rpx;
		}
		
		// 中奖提示
		.prize-tip {
			font-size: 28rpx;
			color: #666666;
			margin-bottom: 12rpx;
		}
		
		// 奖品等级
		.prize-level {
			background: linear-gradient(90deg, #FFD700 0%, #FFA500 100%);
			padding: 8rpx 30rpx;
			border-radius: 20rpx;
			margin-bottom: 16rpx;
			
			.level-text {
				font-size: 26rpx;
				font-weight: bold;
				color: #FFFFFF;
				text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
			}
		}
		
		// 奖品名称 - Requirements 4.2
		.prize-name {
			font-size: 36rpx;
			font-weight: bold;
			color: #E65100;
			text-align: center;
			padding: 0 20rpx;
			margin-bottom: 30rpx;
		}
	}
	
	// 操作区域
	.action-area {
		display: flex;
		justify-content: center;
		margin-top: 20rpx;
		
		// 我也要玩按钮 - Requirements 4.3
		.play-btn {
			width: 400rpx;
			height: 88rpx;
			background: linear-gradient(90deg, #FF6B00 0%, #FF9500 100%);
			border-radius: 44rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			box-shadow: 0 6rpx 16rpx rgba(255, 107, 0, 0.4);
			
			&:active {
				transform: scale(0.98);
				opacity: 0.9;
			}
			
			.btn-text {
				font-size: 32rpx;
				font-weight: bold;
				color: #FFFFFF;
				letter-spacing: 4rpx;
			}
		}
	}
	
	// 关闭按钮
	.close-btn {
		width: 48rpx;
		height: 48rpx;
		position: absolute;
		left: 50%;
		bottom: -80rpx;
		transform: translateX(-50%);
		
		image {
			width: 100%;
			height: 100%;
		}
	}
}
</style>
