<template>
    <div class="homeRecommend_max openSignUp">
        <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
						class="login_footer_item_text"
						@click="turnToWindow(
							'https://code-create.com.hk/aida-terms-and-conditions/'
						)"
					>
						Terms&Conditions
					</div>
					<div
						class="login_footer_item_text"
						@click="turnToWindow(
							'https://code-create.com.hk/aida-subscription-agreement/'
						)"
					>
						Privacy Policy
					</div>
                </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="cutLangue">
					<div @click="()=>isSelectSuccessively = !isSelectSuccessively">
						<i class="fi fi-rr-globe"></i>
						<!-- <a-switch :checked="isSelectSuccessively" @click="()=>isSelectSuccessively = !isSelectSuccessively" checked-children="EN" un-checked-children="CN"/> -->
						{{ isSelectSuccessively? 'CN':'EN'}}
					</div>
				</div>
				<div class="gallery_btn" @click="setLogin">Login</div>
			</div>
        </header>
		<signUp ref="signUp" :isSelectSuccessively="isSelectSuccessively"></signUp>
    </div>
	
</template>
<script >
import { defineComponent, toRefs, reactive, ref , nextTick,computed, onMounted, onBeforeUnmount } from "vue";
import { setCookie, getCookie, WriteCookie,clonAllCookie } from "@/tool/cookie";
import { Https } from "@/tool/https";
import { useStore } from "vuex";
import { useRouter } from 'vue-router';
import signUp from '@/component/mainPage/signUp/index.vue'
export default defineComponent({
    components: {
		signUp,
    },
	setup(){
        const store = useStore();
		const router = useRouter();
		let data = reactive({
			homeRecommendMax:null,
			signUp:null,
			isSelectSuccessively:false,
		})
		let isMoblie = ref(false)
		let userDetail = computed(()=>{
			return store.state.UserHabit.userDetail
		})
		let setLogin = ()=>{
			router.push("/login");
		}
		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)
			
		}
		onMounted(()=>{
			window.addEventListener('resize',updataIsMoblie)
		})
		onBeforeUnmount(() => {
			window.removeEventListener('resize', updataIsMoblie);
			
		});
		return {
			...toRefs(data),
			userDetail,
			setLogin,
			logout,
			goHome,
			isMoblie,
		}
	},
    data() {
        return {
        };
    },
	watch: {
		// credits.value(newVal,oldVal){
		// 	console.log(String(newVal).length);
		// }
	},
    mounted() {
		
    },
    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;
	
	
	&.openSignUp{
		.homeRecommend_heade{
			position: relative;
			background: #fff !important;
			.login_footer_item_text{
				display: block;
			}
		}
		
		.homeRecommend_content_adminTop{
			display: none;
		}
	}
}
.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;
	}
	.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;
			}
		}
		> .cutLangue{
			display: flex;
			align-items: center;
			margin-right: 4rem;
			> i{
				font-size: 5rem;
			}
			> div{
				cursor: pointer;
				display: flex;
				align-items: center;
				> i{
					font-size: 3.5rem;
					display: flex;
					margin-right: 1rem;
				}
			}
			> button{
				height: 4rem;
				min-width: 8rem;
			}
			> .text{
				margin-right: 1rem;
			}
		}
	}
    .homeRecommend_logo {
        width: 14.4rem;
        height: 3.2rem;
		margin-top: 0;
    }
	.login_footer_item_text{
		margin-left: 5rem;
		text-decoration: underline;
		display: none;
		cursor: pointer;
	}
    .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;
            }
        }
    }
    
}
</style>
