<template>
	<view class="visitor">
		<view class="visitor-block">
			<view style="display: flex;">
				<image class="visitor_img" src="/static/logo.png" mode="aspectFil">
				</image>
				<text class="visitor-text" @click="gologin">立即登录</text>
			</view>
			<wd-cell-group border class="visitor-list">
				<wd-cell v-for="item in menuItems" :title="item.name" is-link @click="handleMenuClick(item)">
				</wd-cell>
			</wd-cell-group>
		</view>
	</view>
	<wd-action-sheet v-model="isShareSheetOpen" title="选择分享渠道" :panels="panels" @select="handleShare" />
</template>

<script setup lang="ts">
	import { ref } from 'vue'

	const menuItems = ref([
		{
			name: '分享APP'
		},
		{
			name: '关于我们',
		}
	])

	const isShareSheetOpen = ref(false)

	const panels = ref([
		{
			iconUrl: '/static/contact-person.png',
			title: '微信消息'
		},
		{
			iconUrl: '/static/moments.png',
			title: '朋友圈'
		}
	])

	// 打开分享菜单
	const openShareSheet = () => {
		isShareSheetOpen.value = true
	}

	// 选择分享渠道后执行分享逻辑
	const handleShare = (action) => {
		console.log(action, 'action');
		isShareSheetOpen.value = false // 关闭菜单
		if (action.index == 0) {
			// 分享到好友
			uni.share({
				provider: "weixin",
				scene: "WXSceneSession",
				type: 0,
				href: '',
				title: "吴门医述",
				summary: "我正在使用吴门医述提升自己，赶紧跟我一起来体验吧！",
				imageUrl: "static/icon/home_icon_logo.png",
				success: function (res) {
					console.log("success:" + JSON.stringify(res));
				},
				fail: function (err) {
					console.log("fail:" + JSON.stringify(err));
				},
			});
		} else if (action.index == 1) {
			// 分享到朋友圈
			uni.share({
				provider: "weixin",
				scene: "WXSceneTimeline",
				type: 0,
				href: '',
				title: "吴门医述",
				summary: "我正在使用吴门医述提升自己，赶紧跟我一起来体验吧！",
				imageUrl: "static/icon/home_icon_logo.png",
				success: function (res) {
					console.log("success:" + JSON.stringify(res));
				},
				fail: function (err) {
					console.log("fail:" + JSON.stringify(err));
				},
			});
		}
	}
	

	const handleMenuClick = (item : { name : string }) => {
		if (item.name === '关于我们') {
			uni.navigateTo({
				url: '/pages/user/about/index'
			})
		} else {
			isShareSheetOpen.value = true
		}
	}
	const gologin = () => {
		uni.navigateTo({
			url: '/pages/login/login'
		})
	}
</script>

<style lang="scss" scoped>
	.visitor {
		background: #f4f7ff;
		min-height: 100vh;
	}

	.visitor-block {
		padding: 40rpx 20rpx;

		.visitor_img {
			width: 150rpx;
			height: 150rpx;
			background-color: #fff;
			border-radius: 60px;
		}

		.visitor-text {
			margin-top: 30rpx;
			margin-left: 20rpx;
			font-weight: bold;
			font-size: 36rpx;
		}
	}

	.visitor-list {
		background: #fff;
		border-radius: 15rpx;
		overflow: hidden;
		margin-top: 40rpx;
		font-weight: bold;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}
</style>