// @ts-nocheck
import React from 'react';
import { Tooltip } from 'antd4';
import { FM } from '@/locales';

import { WeChat_svg, Ckcest_Icon_svg } from '@/data';

import styles from './styles.less';

const OtherOAuthLoginGroup = (props) => {
  const handleWeChartLogin = () => {
    const isInWechat = /MicroMessenger/.test(window.navigator.userAgent);

    const { location, match,setIsShowQRCode } = props || {};
    const { url: callbackUrl } = match || {};
    const { query } = location || {};
    const { callback } = query || {};

    //TODO 恢复线上的链接
    // const cbUrl = `https://www.aminer.cn/wechatlogin`;
    const cbUrl = `https://www.aminer.cn/wechatlogin?callback=${
      callback || callbackUrl || ''
    }&loginType=${isInWechat ? 'wechat' : ''}`;
    const url = `https://open.weixin.qq.com/connect/qrconnect?appid=wxb232d145fe483574&redirect_uri=${encodeURIComponent(
      cbUrl,
    )}&response_type=code&scope=snsapi_login&state=eyJyZXNwb25zZV90eXBlIjoidG9rZW4iLCJyZWRpcmVjdF91cmkiOiJodHRwczovL3d3dy5hbWluZXIuY24vd2VjaGF0bG9naW4iLCJjbGllbnRfaWQiOiJhMjI3Mjk5Yy0wZmE0LTRjYmUtOTVhOC1hOGFmN2NlNDgzN2MiLCJzdGF0ZSI6IlNUQVRFIn0=#wechat_redirect`;
    const weixinUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0165f336953edc6c&redirect_uri=${encodeURIComponent(
      cbUrl,
    )}&response_type=code&scope=snsapi_userinfo&state=aminer`;
    if (window) {
      window.location.href = isInWechat ? weixinUrl : url;
    }
  };

  const signInByCKCEST = () => {
    if (window) {
      const url = `https://sso.ckcest.cn/login?service=https://api.aminer.cn/api/auth/ckcestauth/signin?forward=${window.location.protocol}//${window.location.host}/ckcest/sso`;
      window.open(
        url,
        '_blank',
        'width=1230,height=710,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=yes,directories=no,status=no,location=no',
      );
    }
  };

  return (
    <div className={styles.otherLoginGroup}>
      <div className={styles.title}>
        <FM id="common.other.login.title" defaultMessage="Or sign in using" />
      </div>
      <div className={styles.loginTypeList}>
        {/* <Tooltip
          title={
            <FM
              id="common.wechat.icon.tooltip.title"
              defaultMessage="weChat Login"
            />
          }
        > */}
        <div
          className={styles.loginTypeItem}
          onClick={() => props?.setIsShowQRCode(true)}
          // onClick={handleWeChartLogin}
        >
          <WeChat_svg />
        </div>
        <div className={styles.loginTypeItem} onClick={signInByCKCEST}>
          <Ckcest_Icon_svg />
        </div>
        {/* </Tooltip> */}

        {/*<Tooltip*/}
        {/*  title={*/}
        {/*    intl.formatMessage({*/}
        {/*      id: `common.ckest.icon.tooltip.title`,*/}
        {/*      defaultMessage: '工程院登录',*/}
        {/*    })*/}
        {/*  }*/}
        {/*>*/}
        {/*  <div*/}
        {/*    className={styles.loginTypeItem}*/}
        {/*    onClick={signInByCKCEST}*/}
        {/*  >*/}
        {/*    <Ckcest_logo_svg*/}
        {/*      className={styles.weChatIcon}*/}
        {/*    />*/}
        {/*  </div>*/}
        {/*</Tooltip>*/}
      </div>
    </div>
  );
};

export default OtherOAuthLoginGroup;
