<template>
    <div class="homeRecommend_max">
        <header class="homeRecommend_heade">
            <div class="homeRecommend_right_content">
                <div class="homeRecommend_user_content">
                    <img
						class="homeRecommend_logo"
						@click="turnToNewPage('https://www.aidlab.hk/en/')"
						src="@/assets/images/loginPage/aida_logo.png"
					/>
                </div>
            </div>
			<div class="homeRecommend_right">
				<div class="gallery_btn" v-if="userDetail.systemUser != -1 && !isMoblie" @click="goHome">Home</div>
				<div class="gallery_btn white" v-if="userDetail.systemUser != -1" @click="logout">log off</div>
			</div>
			<div class="homeRecommend_right" v-if="userDetail.systemUser == -1">
				<div class="gallery_btn" @click="setLogin">Login</div>
				<div class="gallery_btn white" @click="setRegister">Sign up</div>
			</div>
        </header>
		<div class="homeRecommend_content_body">
			<!-- <div class="homeRecommend_content_body_recommend">
				<img src="@/assets/images/homePage/home-bg.png">
				<div class="content_body_recommend_center content_body_text">
					<div class="content_body_recommend_center_title">
						<h1>AiDA</h1>
						<h3>bloom your creativity</h3>
					</div>
				</div>
			</div> -->
			<div class="homeRecommend_content_body_recommend" id="aaaa">
				<div class="content_body_recommend_left mdhidden">
					<img class="content_body_img1 content_body_img" src="/image/mainImg/img1.png" alt="">
					<img class="content_body_img2 content_body_img" src="/image/mainImg/img2.png" alt="">
					<img class="content_body_img3 content_body_img" src="/image/mainImg/img3.png" alt="">
					<img class="content_body_img4 content_body_img" src="/image/mainImg/img4.png" alt="">
				</div>
				<div class="content_body_recommend_center content_body_text">
					<div class="content_body_recommend_center_title">
						<h1>AiDA</h1>
						<h3>bloom your creativity</h3>
					</div>
				</div>
				<div class="content_body_recommend_right mdhidden">
					<img class="content_body_img1 content_body_img" src="/image/mainImg/img5.png" alt="">
					<img class="content_body_img2 content_body_img" src="/image/mainImg/img6.png" alt="">
					<img class="content_body_img3 content_body_img" src="/image/mainImg/img7.png" alt="">
					<img class="content_body_img4 content_body_img" src="/image/mainImg/img8.png" alt="">
				</div>
			</div>
			<Works :isScroll="false"></Works>
		</div>
		<div class="homeRecommend_content_adminTop" @click="setAdminUp">
			<i class="fi fi-rr-arrow-small-up"></i>
		</div>
    </div>
	
</template>
<script >
import { defineComponent, toRefs, reactive, ref , nextTick,computed, onMounted, onBeforeUnmount } from "vue";
import { isEmail } from "@/tool/util";
import { setCookie, getCookie, WriteCookie,clonAllCookie } from "@/tool/cookie";
import VerificationCodeInput from "@/component/LoginPage/verificationCodeInput.vue";
import Habit from "@/component/Detail/habit.vue";
import { Https } from "@/tool/https";
import { Modal, message } from "ant-design-vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import Works from "@/views/HomeView/Works.vue";
import { useStore } from "vuex";
import { setLang } from "@/tool/guide";
import { useI18n } from "vue-i18n";
import { useRouter } from 'vue-router';
import { gsap, TweenMax } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
export default defineComponent({
    components: {
        VerificationCodeInput,
		Habit,
		Works,
    },
	setup(){
        const store = useStore();
		const router = useRouter();
		let registerModel = ref()
		let data = reactive({
		})
		let isMoblie = ref(false)
		let userDetail = computed(()=>{
			return store.state.UserHabit.userDetail
		})
		let setLogin = ()=>{
			router.push("/login");
		}
		let setAdminUp = ()=>{
			let scrollDom = document.querySelector('.homeRecommend_content_body')
			scrollDom.scrollTo({
				top: 0,
				behavior: 'smooth' // 平滑滚动到顶部
			});
		}
		let logout = ()=>{
			let userInfo = store.state.UserHabit.userDetail;
			let data = {
                userId: userInfo?.userId,
            };
			store.commit('createDetail')
			store.commit('createProbject')
			if(!data.userId) return
			Https.axiosPost(Https.httpUrls.accountLogout, data).then((rv) => {
				clonAllCookie();
			});
		}
		let goHome = ()=>{
			router.push('/home');
		}
		let time
		let updataIsMoblie = ()=>{
			clearTimeout(time)
			time = setTimeout(()=>{
				if(window.innerWidth < 768){
					isMoblie.value = true
				}else{
					isMoblie.value = false
				}    
			},500)
			
		}
		const setRegister = ()=>{
			router.push('/register');
		}
		onMounted(()=>{
			if(window.innerWidth < 768){
				isMoblie.value = true
			}else{
				isMoblie.value = false
			} 
			window.addEventListener('resize',updataIsMoblie)
		})
		onBeforeUnmount(() => {
			window.removeEventListener('resize', updataIsMoblie);
		});
		return {
			...toRefs(data),
			userDetail,
			setLogin,
			registerModel,
			setAdminUp,
			logout,
			goHome,
			isMoblie,
			setRegister,
		}
	},
    data() {
        return {
        };
    },
	watch: {
		// credits.value(newVal,oldVal){
		// 	console.log(String(newVal).length);
		// }
	},
    mounted() {
		nextTick().then(()=>{

			let dom = document.querySelector('.homeRecommend_content_body')
			let codeTween = document.querySelectorAll('.homeRecommend_content_body_recommend .content_body_img')
			let codeTweenText = document.querySelectorAll('.homeRecommend_content_body_recommend .content_body_text')
			for (let index = 0; index < codeTween.length; index++) {
				gsap.from(codeTween[index],.5, {scale:.6 },);
				gsap.registerPlugin(ScrollTrigger);
				let tl1 = gsap.timeline();
				tl1.to(codeTween[index],1, {y:'-30px',opacity:0},)
				ScrollTrigger.create({
					trigger: codeTween[index], // 触发器元素
					start: "top 0%", // 滚动触发器的起始滚动位置
					end: '200% 20%',   // 滚动触发器的结束滚动位置
					// markers: true, // 开启标注功能
					scrub: true,
					animation:tl1,
					scroller:dom,//设置指定元素为滚动依据
					scrub:2,
					// onUpdate:(v)=>{
					// 	if(v.progress < 0.1){
					// 		v.trigger?.classList.remove('active')
					// 	}else{
					// 		v.trigger?.classList.add('active')
					// 		// v.trigger?.classList.add('active')
					// 	}
					// }
				});
			}
			gsap.registerPlugin(ScrollTrigger);
			let tl1 = gsap.timeline();
			tl1.from(codeTweenText,1, {'margin-top':'30px',opacity:1},)
			ScrollTrigger.create({
				trigger: codeTweenText, // 触发器元素
				start: "top 0%", // 滚动触发器的起始滚动位置
				end: '200% 20%',   // 滚动触发器的结束滚动位置
				// markers: true, // 开启标注功能
				scrub: true,
				animation:tl1,
				scroller:dom,//设置指定元素为滚动依据
				scrub:2,
				
			});
		})
    },
    methods: {
		turnToNewPage(url) {
            window.open(url);
        },
		turnToWindow(url) {
            window.open(url);
        },
    },
});
</script>

<style lang="less" scoped>
.homeRecommend_max{
	position: relative;
	display: flex;
	height: 100%;
	flex-direction: column;
	
	.homeRecommend_content_body{
		flex: 1;
	}
}
.homeRecommend_heade {
    display: flex;
	justify-content: space-between;
	// padding: 0 30px;
	padding: 1rem 4rem;
    width: 100%;
    // height: 7rem;
	flex-shrink: 0;
    // background: rgba(255, 255, 255, 0.2);
    // border-bottom: 0.1rem solid rgba(3, 3, 3, 0.1);
    position: absolute;
    align-items: center;
	z-index: 2;
	@media (max-width: 768px) {
		z-index: 1000;
	}
	// background-color: #fff;
	.homeRecommend_right{
		width: 33%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		.gallery_btn{
			// color: #000;
			// background: #fff;
			// border: 2px solid #39215b;
			// margin-left: 2rem;
			width: 13rem;
			text-align: center;
			&.gallery_btn:nth-child(1){
			    margin-right: 3rem;
			}
		}
	}
    .homeRecommend_logo {
        width: 14.4rem;
        height: 3.2rem;
		margin-top: 0;
    }
	.login_footer_item_text{
		margin-left: 5rem;
		display: none;
	}
    .homeRecommend_right_content {
        top: 0;
		left: 0;
        display: flex;
		width: 40%;
		height: 100%;
		align-items: center;
		overflow: hidden;
        .homeRecommend_user_content {
            display: flex;
            align-items: center;
            position: relative;
            height: 3.7rem;
			&.marLeft2{
				margin-left: 2rem;
			}
            .username {
                font-size: 1.8rem;
                color: #1a1a1a;
                margin: 0 0.8rem;
				font-weight: 900;
				span{
					margin: .7rem;
				}
            }
            .icon-xiala {
                font-size: 1.4rem;
                cursor: pointer;
				transition: .3s all;
            }
            .icon_rotate {
                -moz-transform: rotate(180deg);
                -webkit-transform: rotate(180deg);
                transform: rotate(180deg);
                animation-direction: 0.5s;
            }
        }
    }
    
}
.homeRecommend_content_body{
	overflow-y: auto;
	overflow-x: hidden;
	&.homeRecommend_content_body::-webkit-scrollbar {
		display: none;
	}
	// .homeRecommend_content_body_recommend{
	// 	// display: flex;
	// 	// justify-content: center;
	// 	position: relative;
	// 	border-bottom: 1px solid #ececec;
	// 	width: 100%;
	// 	img{
	// 		width: 100%;
	// 	}
	// 	.content_body_recommend_center{
	// 		position: absolute;
	// 		top: 40%;
	// 		left: 36rem;
	// 		transform: translateY(-50%);
	// 		.content_body_recommend_center_title{
	// 			h1,h3{
	// 				color: #fff;
	// 			}
	// 			h1{
	// 				font-size: 15rem;
	// 				margin-bottom: 0;
	// 				line-height: 1;
	// 			}
	// 			h3{
	// 				font-size: 6rem;
	// 			}
	// 		}
			
	// 	}
	// }
	.homeRecommend_content_body_recommend{
		// display: flex;
		// justify-content: center;
		position: relative;
		border-bottom: 1px solid #ececec;
		
		.content_body_recommend_left,
		.content_body_recommend_right{
			position: absolute;
			top: 0;
			img{
				border-radius: 2rem;
				position: absolute;
				width: 20px;
				object-fit: cover;
			}
			
		}
		--margin:3rem;
		.content_body_recommend_right{
			right: 0;
			.content_body_img1{
				width: 25rem;
				height: 55rem;
				object-fit: cover;
				// top: 10rem;
				// right: calc(20rem + var(--margin));
				right: 0;
				top: 14rem;
			}
			.content_body_img2{
				top: calc(45rem + var(--margin));
				width: 15rem;
				height: 30rem;
				object-fit: cover;
				right: calc(41rem + var(--margin));
			}
			.content_body_img3{
				top: calc(40rem + var(--margin));
				width: 15rem;
				height: 30rem;
				object-fit: cover;
				right: calc(25rem + var(--margin));
			}
			.content_body_img4{
				width: 30rem;
				height: 25rem;
				object-fit: cover;
				top: calc(13rem);
				right: calc(25rem + var(--margin));
			}
			.content_body_img5{
				width: 20rem;
				height: 20rem;
				object-fit: cover;
				top: 15rem;
				right: 0;
			}
		}
		.content_body_recommend_left{
			left: 0;
			.content_body_img1{
				width: 25rem;
				height: 55rem;
				object-fit: cover;
				left: 0;
				top: 14rem;
				// top: 5rem;
				// left: calc(20rem + var(--margin));
			}
			.content_body_img2{
				width: 35rem;
				height: 27rem;
				object-fit: cover;
				top: calc(10rem + var(--margin));
				left: calc(25rem + var(--margin));
			}
			.content_body_img3{
				width: 22rem;
				height: 30rem;
				object-fit: cover;
				top: calc(40rem + var(--margin));
				left: calc(27rem + var(--margin));
			}
			.content_body_img4{
				width: 15rem;
				height: 18rem;
				object-fit: cover;
				top: calc(53rem + var(--margin));
				left: calc(45rem + var(--margin));
			}
			.content_body_img5{
				width: 20rem;
				height: 20rem;
				object-fit: cover;
				top: 51rem;
				left: calc(20rem + var(--margin));
			}
			.content_body_img6{
				width: 20rem;
				height: 20rem;
				object-fit: cover;
				top: 20rem;
				left: calc(0 + var(--margin));
			}
		}
		.content_body_recommend_center{
			padding: 20rem 0;
			text-align: center;
			width: 50%;
			position: relative;
			left: 50%;
			transform: translateX(-50%);
			z-index: 2;
			opacity: 0;
			@media (max-width: 768px) {
				width: 80%;
			}
			.content_body_recommend_center_title{
				h1{
					line-height: 1;
					font-size: 13rem;
					font-weight: 900;
					margin: 7rem;
					div{
						color: #341e57;
					}
				}
				h3{
					line-height: 1;
					margin: 7rem;
					font-size: 5rem;
					font-weight: 900;
				}
			}
			.content_body_recommend_center_btn{
				display: flex;
				justify-content: center;
				cursor: pointer;
				a{
					margin: 0 2rem;
				}
			}
		}
	}
}
.homeRecommend_content_adminTop{
	position: fixed;
	bottom: 5rem;
	right: 5rem;
	width: 7rem;
	height: 7rem;
	cursor: pointer;
	border-radius: 50%;
	box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
	display: flex;
    align-items: center;
    justify-content: center;
	background: #fff;
	z-index: 999;
	i{
		display: flex;
		font-size: 3rem;
		transition: all .3s;
	}
	&.homeRecommend_content_adminTop:hover{
		i{
			transform: scale(1.2);
		}
	}
}

</style>
