import { useEffect } from 'react'
import wxLogin from './wxLogin'

const CONFIG = {
	test: {
		appid: 'wx853a8d12eea0e682',
		url: 'https://piaoquantv.yishihui.com'
	},
	prod: {
		appid: 'wx73a6cb4d85be594f',
		url: 'https://www.piaoquantv.com'
	}
}

const Setting = () => {

	useEffect(() => {
		// 获取链接参数 code
		const code = new URLSearchParams(window.location.search).get('code')
		if (code) {
			// 获取用户信息
			getPiaoQuanUserInfo(code)
		} else { 
			renderQrcode()
		}
	}, [])

	const getPiaoQuanUserInfo = async (code: string) => {
		console.log(code)
	}

	const renderQrcode = () => {
		const env = window.location.host === ('content.piaoquantv.com') ? 'prod' : 'test'
		wxLogin({
			id: 'code',
			appid: CONFIG[env].appid,
			scope: 'snsapi_login',
			redirect_uri: encodeURIComponent(CONFIG[env].url + '?jumpTo=contentCooper'),
		})
	}

  return (
		<div className='w-full h-full'>
			<div className='px-6 py-1 flex flex-row justify-between items-center border-b border-gray-300'>
				<div className='text-2xl font-bold'>视频上传归属用户</div>
			</div>
			<div className='px-4 py-2 max-h-[calc(100vh-200px)] h-[calc(100vh-200px)] overflow-y-auto'>
				<div id='code'></div>
			</div>
			
		</div>
  )
}

export default Setting
