<template>

	<view v-if="loading" class="skeleton-container">
		<!-- 接单状态骨架屏 -->
		<view class="skeleton-status-section">
			<view class="skeleton-title"></view>
			<view class="skeleton-status-button"></view>
		</view>

		<!-- 热门接单区域骨架屏 -->
		<view class="skeleton-map-section">
			<view class="skeleton-title"></view>
			<view class="skeleton-map-placeholder"></view>
			<view class="skeleton-map-tip"></view>
		</view>

		<!-- 服务范围骨架屏 -->
		<view class="skeleton-service-section">
			<view class="skeleton-title"></view>
			<view class="skeleton-service-card">
				<view class="skeleton-icon"></view>
				<view class="skeleton-text"></view>
				<view class="skeleton-switch"></view>
			</view>
		</view>

		<!-- 提示信息骨架屏 -->
		<view class="skeleton-tip-section">
			<view class="skeleton-tip-card">
				<view class="skeleton-icon"></view>
				<view class="skeleton-tip-text"></view>
			</view>
			<view class="skeleton-tip-card">
				<view class="skeleton-icon"></view>
				<view class="skeleton-tip-text"></view>
			</view>
		</view>
	</view>

	<view v-else class="online-management-page">
		<!-- 接单状态 -->
		<view class="status-section">
			<view class="status-card">
				<text class="section-title">接单状态</text>
				<view class="status-button" @click="toggleStatus()" :class="{ 'online': isOnline, 'offline': !isOnline }">
					<text class="status-text">{{ isOnline ? '接单中 · 点击下线' : '已下线 · 点击上线' }}</text>
				</view>
			</view>
		</view>

		<!-- 热门接单区域 -->
		<view class="map-section">
			<text class="section-title">热门接单区域</text>
			<view class="map-container">
				<!-- 地图占位，使用黑边白底样式 -->
				<view class="map-placeholder">
					<view class="map-content">
						<!-- 模拟地图上的区域标记 -->
						<view class="map-area red-area"></view>
						<view class="map-area yellow-area"></view>
						<view class="map-area green-area"></view>
						<text class="map-label">地图加载中...</text>
					</view>
				</view>
				<text class="map-tip">红色区域订单更多，建议在此范围内接单</text>
			</view>
		</view>

		<!-- 服务范围 -->
		<text class="section-title">服务范围</text>
		<view class="service-card">
			<view class="range-setting">
				<view class="range-left">
					<up-icon name="map" size="20" color="#1890ff" style="margin-right: 16rpx;"></up-icon>
					<text class="range-text">手动划定接单范围</text>
				</view>
				<up-switch v-model="manualRangeEnabled" size="20" @change="handleRangeSwitchChange"></up-switch>
			</view>
		</view>

		<!-- 提示信息 -->
		<view class="tip-card info">
			<up-icon name="info-circle" size="20" color="#1890ff" style="margin-right: 16rpx;"></up-icon>
			<text class="tip-text">上线后系统将自动推送附近订单，您可在'任务'查看并抢单。</text>
		</view>
		<view class="tip-card warning">
			<up-icon name="warning" size="20" color="#fa8c16" style="margin-right: 16rpx;"></up-icon>
			<text class="tip-text">请确保在服务区域内接单，超出范围可能影响配送效率和收入。</text>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { onLoad } from '@dcloudio/uni-app';
	import { ref } from 'vue';

	let loading = ref(true)

	// 接单状态
	const isOnline = ref(true);

	// 是否启用手动划定范围
	const manualRangeEnabled = ref(false);

	onLoad(() => {
		setTimeout(()=>{
			loading.value=false
		},1000)
	})

	// 切换在线状态
	const toggleStatus = () => {
		const newStatus = !isOnline.value;
		// 显示确认对话框
		uni.showModal({
			title: newStatus ? '确认上线' : '确认下线',
			content: newStatus ? '上线后将接收订单推送，确定要上线吗？' : '下线后将停止接收订单推送，确定要下线吗？',
			success: (res) => {
				if (res.confirm) {
					isOnline.value = newStatus;
					uni.showToast({
						title: newStatus ? '已成功上线' : '已成功下线',
						icon: 'success'
					});
				}
			}
		});
	};

	// 处理范围开关变化
	const handleRangeSwitchChange = (value : boolean) => {
		manualRangeEnabled.value = value;
	};
</script>

<style scoped lang="scss">
	/* 页面基础样式 */
	.online-management-page {
		margin: 20rpx;
	}


	/* 标题通用样式 */
	.section-title {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
		margin-bottom: 24rpx;
	}

	/* 状态区域 */
	.status-section {
		background-color: #fff;
		padding: 30rpx;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
	}

	.status-card {
		display: flex;
		flex-direction: column;
	}

	.status-button {
		height: 86rpx;
		border-radius: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		font-weight: 600;
		transition: all 0.3s ease;
	}

	.status-button.online {
		background-color: #52c41a;
		color: #fff;
	}

	.status-button.offline {
		background-color: #d9d9d9;
		color: #666;
	}

	.status-button:active {
		opacity: 0.8;
	}

	/* 地图区域 */
	.map-section {
		background-color: #fff;
		padding: 30rpx;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
	}

	.map-container {
		display: flex;
		flex-direction: column;
	}

	.map-placeholder {
		width: 100%;
		height: 500rpx;
		border: 2rpx solid #ddd;
		background-color: #fff;
		border-radius: 12rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
	}

	.map-content {
		width: 100%;
		height: 100%;
		position: relative;
		background-color: #f5f5f5;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	/* 地图上的区域标记 */
	.map-area {
		position: absolute;
		border-radius: 50%;
		opacity: 0.3;
	}

	.red-area {
		width: 300rpx;
		height: 300rpx;
		background-color: #ff4d4f;
		top: 120rpx;
		right: 150rpx;
		z-index: 3;
	}

	.yellow-area {
		width: 250rpx;
		height: 250rpx;
		background-color: #faad14;
		top: 80rpx;
		left: 120rpx;
		z-index: 2;
	}

	.green-area {
		width: 200rpx;
		height: 200rpx;
		background-color: #52c41a;
		bottom: 100rpx;
		right: 200rpx;
		z-index: 1;
	}

	.map-label {
		font-size: 28rpx;
		color: #999;
		z-index: 10;
	}

	.map-tip {
		font-size: 26rpx;
		color: #666;
		line-height: 1.5;
	}

	/* 服务范围 */
	.service-range-section {
		background-color: #fff;
		padding: 30rpx;
		margin-bottom: 20rpx;
	}

	.service-card {
		margin-top: 20rpx;
		background-color: #fff;
		border-radius: 20rpx;
		padding: 24rpx;
	}

	.range-setting {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.range-left {
		display: flex;
		align-items: center;
	}

	.range-text {
		font-size: 30rpx;
		color: #333;
	}

	/* 提示信息 */


	.tip-card {
		display: flex;
		align-items: flex-start;
		padding: 24rpx;
		margin-top: 20rpx;
		border-radius: 12rpx;
		font-size: 26rpx;
		line-height: 1.6;
	}

	.tip-card.info {
		background-color: #F6FFFB;
	}

	.tip-card.warning {
		background-color: #FFFFFF;
	}

	.tip-text {
		flex: 1;
	}

	/* 骨架屏样式 */
	.skeleton-container {
		margin: 20rpx;

	}

	.skeleton-status-section,
	.skeleton-map-section,
	.skeleton-service-section {
		background-color: #fff;
		padding: 30rpx;
		margin-bottom: 20rpx;
		border-radius: 20rpx;
	}

	.skeleton-tip-section {
		padding: 0;
	}

	.skeleton-title {
		height: 32rpx;
		width: 160rpx;
		background-color: #f0f0f0;
		border-radius: 4rpx;
		margin-bottom: 24rpx;
		animation: shimmer 1.5s infinite;
	}

	.skeleton-status-button {
		height: 86rpx;
		width: 100%;
		background-color: #f0f0f0;
		border-radius: 60rpx;
		animation: shimmer 1.5s infinite;
	}

	.skeleton-map-placeholder {
		height: 500rpx;
		width: 100%;
		background-color: #f0f0f0;
		border-radius: 12rpx;
		margin-bottom: 20rpx;
		animation: shimmer 1.5s infinite;
	}

	.skeleton-map-tip {
		height: 26rpx;
		width: 70%;
		background-color: #f0f0f0;
		border-radius: 4rpx;
		animation: shimmer 1.5s infinite;
	}

	.skeleton-service-card {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx;
		background-color: #fafafa;
		border-radius: 20rpx;
	}

	.skeleton-icon {
		width: 40rpx;
		height: 40rpx;
		background-color: #f0f0f0;
		border-radius: 4rpx;
		animation: shimmer 1.5s infinite;
	}

	.skeleton-text {
		height: 30rpx;
		width: 280rpx;
		background-color: #f0f0f0;
		border-radius: 4rpx;
		margin-left: 16rpx;
		animation: shimmer 1.5s infinite;
	}

	.skeleton-switch {
		width: 80rpx;
		height: 44rpx;
		background-color: #f0f0f0;
		border-radius: 22rpx;
		animation: shimmer 1.5s infinite;
	}

	.skeleton-tip-card {
		display: flex;
		align-items: center;
		padding: 24rpx;
		margin-bottom: 20rpx;
		background-color: #fff;
		border-radius: 12rpx;
	}

	.skeleton-tip-text {
		flex: 1;
		height: 26rpx;
		background-color: #f0f0f0;
		border-radius: 4rpx;
		margin-left: 16rpx;
		animation: shimmer 1.5s infinite;
	}

	/* 骨架屏闪烁动画 */
	@keyframes shimmer {
		0% {
			background-position: -1000px 0;
		}

		100% {
			background-position: 1000px 0;
		}
	}

	.skeleton-title,
	.skeleton-status-button,
	.skeleton-map-placeholder,
	.skeleton-map-tip,
	.skeleton-icon,
	.skeleton-text,
	.skeleton-switch,
	.skeleton-tip-text {
		background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
		background-size: 1000px 100%;
	}
</style>