<!--家长端课程管理页面-->
<template>
	<view class="main_box">
		<!-- 选中孩子信息 -->
		<view class="child_info_bar" v-if="selectedChild">
			<view class="child_avatar">
				<image :src="selectedChild.avatar" mode="aspectFill"></image>
			</view>
			<view class="child_details">
				<view class="child_name">{{ selectedChild.name }}</view>
				<view class="child_class">{{ selectedChild.class_name || '未分配班级' }}</view>
			</view>
			<view class="course_stats">
				<view class="stat_item">
					<text class="stat_number">{{ selectedChild.remaining_courses || 0 }}</text>
					<text class="stat_label">剩余课时</text>
				</view>
			</view>
		</view>
		
		<!-- 课程列表 -->
		<view class="course_list">
			<view class="section_title">课程信息</view>
			<view class="course_items">
				<view 
					v-for="course in courseList" 
					:key="course.id"
					class="course_item"
					@click="viewCourseDetail(course)"
				>
					<view class="course_main">
						<view class="course_header">
							<view class="course_name">{{ course.course_name }}</view>
							<view class="course_status" :class="course.status">{{ course.status === 'active' ? '进行中' : '已结束' }}</view>
						</view>
						<view class="course_details">
							<view class="detail_row">
								<text class="detail_label">授课教师：</text>
								<text class="detail_value">{{ course.teacher_name }}</text>
							</view>
							<view class="detail_row">
								<text class="detail_label">上课校区：</text>
								<text class="detail_value">{{ course.campus_name }}</text>
							</view>
							<view class="detail_row">
								<text class="detail_label">上课时间：</text>
								<text class="detail_value">{{ course.schedule_time }}</text>
							</view>
							<view class="detail_row">
								<text class="detail_label">课程进度：</text>
								<text class="detail_value">{{ course.progress }}</text>
							</view>
							<view class="detail_row" v-if="course.next_class">
								<text class="detail_label">下节课时间：</text>
								<text class="detail_value next_class">{{ course.next_class }}</text>
							</view>
						</view>
					</view>
					<view class="course_arrow">
						<image :src="$util.img('/uniapp_src/static/images/index/right_arrow.png')" class="arrow-icon"></image>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 空状态 -->
		<view class="empty_state" v-if="!loading && courseList.length === 0">
			<image :src="$util.img('/uniapp_src/static/images/common/empty.png')" class="empty_icon"></image>
			<view class="empty_text">暂无课程信息</view>
		</view>
		
		<!-- 加载状态 -->
		<view class="loading_state" v-if="loading">
			<view class="loading_text">加载中...</view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex'
import apiRoute from '@/api/apiRoute.js'

export default {
	data() {
		return {
			courseList: [],
			loading: false,
			childId: null
		}
	},
	computed: {
		...mapState(['selectedChild'])
	},
	onLoad(options) {
		this.childId = options.childId
		this.loadCourseList()
	},
	methods: {
		async loadCourseList() {
			if (!this.childId) {
				uni.showToast({
					title: '缺少孩子ID参数',
					icon: 'none'
				})
				return
			}
			
			this.loading = true
			try {
				const response = await apiRoute.parent_getChildCourses({
					child_id: this.childId
				})
				
				if (response.code === 1) {
					this.courseList = response.data.data || []
				} else {
					uni.showToast({
						title: response.msg || '获取课程列表失败',
						icon: 'none'
					})
				}
			} catch (error) {
				console.error('获取课程列表失败:', error)
				uni.showToast({
					title: '获取课程列表失败',
					icon: 'none'
				})
			} finally {
				this.loading = false
			}
		},
		
		viewCourseDetail(course) {
			this.$navigateTo({
				url: `/pages/parent/courses/course-detail?courseId=${course.id}&childId=${this.childId}`
			})
		}
	}
}
</script>

<style lang="less" scoped>
.main_box {
	background: #f8f9fa;
	min-height: 100vh;
	padding: 20rpx;
}

.child_info_bar {
	background: #fff;
	border-radius: 16rpx;
	padding: 24rpx;
	margin-bottom: 20rpx;
	display: flex;
	align-items: center;
	gap: 20rpx;
	box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	
	.child_avatar {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		overflow: hidden;
		
		image {
			width: 100%;
			height: 100%;
		}
	}
	
	.child_details {
		flex: 1;
		
		.child_name {
			font-size: 28rpx;
			font-weight: 600;
			color: #333;
			margin-bottom: 8rpx;
		}
		
		.child_class {
			font-size: 24rpx;
			color: #666;
		}
	}
	
	.course_stats {
		.stat_item {
			display: flex;
			flex-direction: column;
			align-items: center;
			
			.stat_number {
				font-size: 28rpx;
				font-weight: 600;
				color: #29d3b4;
				margin-bottom: 4rpx;
			}
			
			.stat_label {
				font-size: 22rpx;
				color: #999;
			}
		}
	}
}

.course_list {
	.section_title {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
		margin-bottom: 24rpx;
		padding-left: 8rpx;
	}
	
	.course_items {
		display: flex;
		flex-direction: column;
		gap: 16rpx;
	}
}

.course_item {
	background: #fff;
	border-radius: 16rpx;
	padding: 28rpx;
	display: flex;
	align-items: center;
	gap: 20rpx;
	box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	
	.course_main {
		flex: 1;
		
		.course_header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 16rpx;
			
			.course_name {
				font-size: 30rpx;
				font-weight: 600;
				color: #333;
			}
			
			.course_status {
				font-size: 22rpx;
				padding: 4rpx 12rpx;
				border-radius: 12rpx;
				
				&.active {
					background: rgba(41, 211, 180, 0.1);
					color: #29d3b4;
				}
				
				&.inactive {
					background: #f0f0f0;
					color: #999;
				}
			}
		}
		
		.course_details {
			.detail_row {
				display: flex;
				margin-bottom: 8rpx;
				
				.detail_label {
					font-size: 24rpx;
					color: #666;
					min-width: 160rpx;
				}
				
				.detail_value {
					font-size: 24rpx;
					color: #333;
					flex: 1;
					
					&.next_class {
						color: #29d3b4;
						font-weight: 600;
					}
				}
			}
		}
	}
	
	.course_arrow {
		.arrow-icon {
			width: 24rpx;
			height: 24rpx;
			opacity: 0.4;
		}
	}
}

.empty_state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 120rpx 0;
	
	.empty_icon {
		width: 160rpx;
		height: 160rpx;
		margin-bottom: 32rpx;
		opacity: 0.3;
	}
	
	.empty_text {
		font-size: 28rpx;
		color: #999;
	}
}

.loading_state {
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 60rpx 0;
	
	.loading_text {
		font-size: 28rpx;
		color: #666;
	}
}
</style>