<template>
	<view class="account-delete-page">
		<view class="warning-card">
			<uni-icons type="info-filled" size="48" color="#f44336"></uni-icons>
			<text class="warning-title">账号注销须知</text>
			<text class="warning-text">注销账号后，以下数据将被永久删除且不可恢复：</text>
			<view class="warning-list">
				<text class="warning-item">• 个人信息及宠物档案</text>
				<text class="warning-item">• 历史订单记录</text>
				<text class="warning-item">• 评价与投诉记录</text>
				<text class="warning-item">• 账户余额（如有）</text>
			</view>
		</view>
		<view class="confirm-section">
			<view class="check-row">
				<checkbox-group @change="onCheckChange">
					<label class="check-label">
						<checkbox :checked="confirmed" color="#f44336" style="transform: scale(0.7);" />
						<text>我已了解上述风险，确认注销</text>
					</label>
				</checkbox-group>
			</view>
			<button class="delete-btn" :disabled="!confirmed" @click="onDelete">确认注销账号</button>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue'
import { cancelUser } from '@/api/system/user'

const confirmed = ref(false)
const onCheckChange = () => { confirmed.value = !confirmed.value }
const onDelete = () => {
	uni.showModal({
		title: '最终确认',
		content: '账号注销后无法恢复，确定继续吗？',
		confirmColor: '#f44336',
		success: async (res) => {
			if (res.confirm) {
				try {
					// @Author: Antigravity
					await cancelUser()
					uni.showToast({ title: '账号已注销', icon: 'success' })
					// 注销成功后清除 token 并跳转回登录页
					uni.removeStorageSync('token')
					setTimeout(() => uni.reLaunch({ url: '/pages/login/index' }), 1500)
				} catch (error) {
					// 错误处理由 request.js 统一提示，此处无需额外处理
				}
			}
		}
	})
}
</script>

<style lang="scss" scoped>
.account-delete-page {
	min-height: 100vh;
	background: #f7f8fa;
	padding: 40rpx 32rpx;
}

.warning-card {
	background: #fff;
	border-radius: 24rpx;
	padding: 48rpx 32rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
}

.warning-title {
	font-size: 36rpx;
	font-weight: 800;
	color: #f44336;
	margin: 24rpx 0 16rpx;
}

.warning-text {
	font-size: 28rpx;
	color: #666;
	margin-bottom: 24rpx;
}

.warning-list {
	align-self: flex-start;
}

.warning-item {
	display: block;
	font-size: 26rpx;
	color: #999;
	line-height: 2;
}

.confirm-section {
	margin-top: 48rpx;
}

.check-row {
	margin-bottom: 32rpx;
}

.check-label {
	display: flex;
	align-items: center;
	font-size: 26rpx;
	color: #666;
}

.delete-btn {
	width: 100%;
	height: 96rpx;
	background: #f44336;
	color: #fff;
	border: none;
	border-radius: 48rpx;
	font-size: 32rpx;
	font-weight: bold;
	line-height: 96rpx;
}

.delete-btn[disabled] {
	background: #ccc;
}
</style>
