import { useEffect, useState } from 'react'
import wx from 'weixin-js-sdk'

export default function useWxXcx() {
  // 判断是不是微信小程序

  const [isWXxcx, setIsWXxcx] = useState(false)

  useEffect(() => {
    // 1. 先判断是否为微信环境
    const ua = navigator.userAgent.toLowerCase()
    const isWeChat = ua.includes('micromessenger')
    if (isWeChat) {
      // 2. 调用微信 JS-SDK 判断是否在小程序环境
      wx.miniProgram.getEnv((res: any) => {
        setIsWXxcx(res.miniprogram || false)
      })
      console.log(123)
    }
  }, [])

  return {
    isWXxcx
  }
}
