import { useAppStore } from "@/store/useAppStore"

const okspinId = process.env.ADVERTISER_APP_ID

export const setupOkSpin = () => {
	// #ifdef H5
	const appStore = useAppStore()
	if (appStore.phoneNumberPrefix === '+92' && okspinId) {
		let head = document.getElementsByTagName('body')[0];
		let script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = 'https://s.oksp.in/js/tag.js?aa=' + okspinId
		head.appendChild(script)
		console.log('okspin', 'init', okspinId)
	}
	// #endif
}

// okspin打点
const pushEvent = (eid, data) => {
	// #ifdef H5
	const appStore = useAppStore()
	if (appStore.phoneNumberPrefix === '+92' && okspinId) {
		window._okTag = window._okTag || []
		window._okTag.push({
			"eid": eid,
			"data": data
		})
		console.log('okspin', eid)
	}
	// #endif
}


export const okSpin = {
	register: () => {
		pushEvent('register', {})
	},
	login: () => {
		pushEvent('login', {})
	},
	purchase: () => {
		pushEvent('purchase', {})
	}
}
