<!-- 移动端 教程页面 -->
<template>
	<div class="course-page">
		<div class="course-page-tips">
			<img class="tip-icon" src="./../../static/img/icon-h5-topc.png" />
			<span class="tip-text">{{ tipTextCpd }}</span>
		</div>
		<div class="course-page-pics-wrap" :style="{ transform: translastCpd }">
			<img class="pic" v-for="(item, index) in course" :key="index" :src="item" />
		</div>
		<div class="course-page-pagination">
			<div class="spon" v-for="(item, index) in course" :key="index" :class="active === index ? 'active' : ''"></div>
		</div>
		<div class="course-page-btns">
			<div v-if="active > 0" class="course-page-btns-btn back" @click="back">Back</div>
			<div v-if="active < this.course.length - 1" class="course-page-btns-btn next" @click="next">Next</div>
			<div v-if="active < this.course.length && (isLottaryCpd || isTreasureCpd || isCommonCpd)" @click="retweer" class="course-page-btns-btn retweer">Retweet</div>
		</div>
	</div>
</template>

<script>
import { postRequest } from '../../http';
import { PlayType } from '../../types';
import { getQueryString } from '../../utils/help';

export default {
	name: 'course',
	data() {
		return {
			active: 0,
			course: [],
		};
	},
	computed: {
		translastCpd() {
			return `translateX(${-this.active * 100}vw)`;
		},
		isLottaryCpd() {
			return this.playType === PlayType.lottery;
		},
		isCommonCpd() {
			return this.playType === PlayType.common;
		},
		isTreasureCpd() {
			return this.playType === PlayType.Treasure;
		},
		isTimeExpiredCpd() {
			return this.useful === '0';
		},
		tipTextCpd() {
			if (this.isLottaryCpd) {
				return 'Install DeNet chrome extension to claim your prize';
			} else if (this.isCommonCpd || this.is) {
				return 'Install Denet Chrome Extension to complete the quest';
			} else {
				return 'How to install Denet Chrome Extension';
			}
		},
	},
	methods: {
		getCource() {
			postRequest(`/base/guide/getAllMobilePageGuide`, {}).then(({ code, data }) => {
				if (code == 0) {
					console.log('%c [ data ]-78', 'font-size:13px; background:pink; color:#bf2c9f;', data);
					if (this.useful === 1) {
						this.course = data.withRewardGuideImages;
					} else {
						this.course = data.withoutRewardGuideImages;
					}
				}
			});
		},
		next() {
			if (this.active < this.course.length - 1) {
				this.active++;
			} else {
				window.location.replace(`https://twitter.com/intent/retweet?tweet_id=${this.postId}`);
			}
		},
		back() {
			this.active--;
		},
		retweer() {
			window.open(`https://twitter.com/intent/retweet?tweet_id=${this.postId}`);
		},
	},
	mounted() {
		this.getCource();
		this.useful = getQueryString('useful');
		this.playType = getQueryString('playType');
		this.rewardType = getQueryString('rewardType');
		this.postId = getQueryString('postId');
	},
};
</script>

<style lang="scss" scoped>
body {
	background-color: #f5f5f5;
}
.course-page {
	min-height: 100vh;
	max-height: 100vh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: space-between;

	&-tips {
		width: 100%;
		height: 80px;
		background: #94a7b6;
		display: flex;
		padding: 0 20px;
		align-items: center;
		font-weight: 600;
		font-size: 16px;
		line-height: 22px;
		color: #fff;
		.tip-icon {
			width: 36px;
			margin-right: 20px;
		}
	}
	&-pics-wrap {
		display: flex;
		transition: all 0.5s;
		.pic {
			width: 100%;
		}
	}
	&-pagination {
		display: flex;
		justify-content: center;
		align-items: center;
		.spon {
			width: 8px;
			height: 8px;
			background: #d9d9d9;
			margin: 0 3px;
			border-radius: 50%;
		}
		.active {
			background: #1d9bf0;
		}
	}
	&-btns {
		width: 100%;
		display: flex;
		padding: 0 8px 30px;
		&-btn {
			flex: 1;
			margin: 0 8px;
			height: 54px;
			line-height: 54px;
			text-align: center;
			border-radius: 60px;
		}
		&-btn:active {
			-webkit-tap-highlight-color: transparent;
		}
		.back {
			background: rgba(29, 155, 240, 0.01);
			border: 1px solid #e8e8e8;
			color: #3d3d3d;
		}
		.next {
			background: rgba(0, 0, 0, 0.01);
			border: 1px solid #b5e1ff;
			color: #1d9bf0;
		}
		.retweer {
			background: #1d9bf0;
			border: 1px solid #1d9bf0;
			color: #fff;
		}
	}
}
</style>
