<template>
	<view>
		<sell-container ref="sellContainer"></sell-container>
		<ActivityHost ref="activityHost" :enable-upsell="false"></ActivityHost>
	</view>
</template>

<script>
import ActivityHost from "@/components/activity-host.vue";

export default {
	components: {
		ActivityHost
	},
	data() {
		return {
			pendingActivityOptions: {}
		}
	},
	onLoad(options) {
		this.pendingActivityOptions = options || {};
	},
	onReady() {
		this.$nextTick(() => {
			if (this.hasActivityEntryOptions(this.pendingActivityOptions)) {
				this.$refs.activityHost?.handlePageOptions(this.pendingActivityOptions);
			}
			this.pendingActivityOptions = {};
		});
	},
	onShow() {
		this.$updateCartBadge();
	},
	onShareAppMessage(res) {
		return this.$refs.activityHost?.getShareAppMessage(res) || {
			title: "书嗨",
			path: "/pages/sell/index",
		};
	},
	onShareTimeline(res) {
		return this.$refs.activityHost?.getShareTimeline(res) || {
			title: "书嗨",
			path: "/pages/sell/index",
		};
	},
	onPullDownRefresh() {
		if (this.$refs.sellContainer) {
			this.$refs.sellContainer.hasShareList();
			this.$refs.sellContainer.getIndexCateInfo();
		}
		setTimeout(() => {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	onPageScroll(e) {
		const comp = this.$refs.sellContainer;
		if (!comp) return;
		comp.scrollTop = e.scrollTop;
	},
	methods: {
		hasActivityEntryOptions(options = {}) {
			return !!(options.scene || options.reduceCode || options.upsellCode);
		}
	}
}
</script>

<style>
/* Empty style as content is in the component */
</style>
