<template>
	<view class="setting-page">
		<view class="group">
			<view class="item" @click="navigateTo('/pages/legal/agreement')">
				<text class="label">用户协议</text>
				<uv-icon name="arrow-right" size="16" color="#c8c8c8"></uv-icon>
			</view>
			<view class="item" @click="navigateTo('/pages/legal/privacy')">
				<text class="label">隐私政策</text>
				<uv-icon name="arrow-right" size="16" color="#c8c8c8"></uv-icon>
			</view>
		</view>
		<view class="group">
			<view class="item" @click="handleLogout">
				<text class="label">退出登录</text>
				<uv-icon name="arrow-right" size="16" color="#c8c8c8"></uv-icon>
			</view>
		</view>
	</view>
</template>

<script setup>
import { userLogout } from '@/config/api/user.js'

const navigateTo = (url) => {
	uni.navigateTo({ url })
}

const handleLogout = async () => {
	uni.showModal({
		title: '提示',
		content: '确定要退出登录吗？',
		success: async (res) => {
			if (res.confirm) {
				const response = await userLogout();
				if (response.code == 200) {
					uni.showToast({ title: '退出成功', icon: 'none' })
					setTimeout(() => {
						uni.removeStorageSync('token')
						uni.removeStorageSync('userInfo')
						uni.reLaunch({ url: '/pages/login/index' })
					}, 1200)
				}
			}
		}
	})
}
</script>

<style lang="scss" scoped>
	.setting-page {
		min-height: 100vh;
		background-color: #f6f6f6;
		padding-bottom: env(safe-area-inset-bottom);
	}

	.group {
		margin-top: 20rpx;
		background-color: #ffffff;
		border-top: 1rpx solid #f0f0f0;
		border-bottom: 1rpx solid #f0f0f0;
	}

	.item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 28rpx 30rpx;
		border-top: 1rpx solid #f5f5f5;
	}

	.item:first-child {
		border-top: none;
	}

	.label {
		font-size: 30rpx;
		color: #333333;
	}
</style>