import { Button } from 'antd'
import React, { useState } from 'react'
import ReactDOM from 'react-dom'
import { initAuthClient, Lang } from './components'
import { ApprowGuard } from './components/ApprowGuard'

import {
  GuardMode,
  // LoginMethods,
  UserConfig,
  // LoginMethods,
  // RegisterMethods,
  // GuardScenes,
  // SocialConnections,
} from './components/ApprowGuard/types/GuardConfig'
import reportWebVitals from './reportWebVitals'

const App = () => {
  const [lang, setLang] = useState<Lang>('zh-CN')

  const config: UserConfig = {
    mode: GuardMode.Normal,
    // appHost: 'https://sample-sso.approw.com',
    // apiHost: 'http://console.approw.localhost:3000',
    // apiHost: 'http://192.168.50.57:3000',
    // loginMethods: Object.values(LoginMethods),
    // logo:
    //   'https://files.approw.co/user-contents/photos/0a4c99ff-b8ce-4030-aaaf-584c807cb21c.png',
    // title: 'Approw',
    // defaultLoginMethod: LoginMethods.LDAP,
    // registerMethods: Object.values(RegisterMethods),
    // defaultRegisterMethod: RegisterMethods.Email,
    // defaultScenes: GuardScenes.Login,
    // socialConnections: Object.values(SocialConnections),
    // enterpriseConnections: ["oidc1"],
    // appDomain: 'oidc1.approw.com',
    // appId: '5f17a529f64fb009b794a2ff',
    // isSSO: true,
    // zIndex: 300,
    // text: {
    //   loginTabs: {
    //     [LoginMethods.Password]: '密码登录一下',
    //   },
    //   loginBtn: {
    //     loading: 'fuck',
    //   },
    // },
    // mode: GuardMode.Modal,
    // contentCss: `
    //   html, body {
    //     background-color: #fff;
    //   }
    // `,
    // // autoRegister: true,
    // socialConnections: [SocialConnections.AppleWeb],
    localesConfig: {
      defaultLang: 'en-US',
      isShowChange: true,
      onChange: (value) => {
        console.log('...........')
        console.log(value)
      },
    },
    lang: lang,
  }

  const [visible, setVisible] = useState(false)

  // useEffect(() => {
  //   setTimeout(() => setVisible(true), 3000)
  // }, [])

  initAuthClient({
    appId: '60adc2ffca277ee9a84ee25a',
    // appHost: 'http://console.approw.localhost:3000',
  })

  return (
    // eslint-disable-next-line react/jsx-no-undef
    <>
      <Button
        type="primary"
        onClick={() => {
          setVisible(!visible)
        }}
      >
        开关
      </Button>
      <Button
        type="primary"
        onClick={() => {
          setLang('zh-CN')
        }}
      >
        中文
      </Button>
      <Button
        type="primary"
        onClick={() => {
          setLang('en-US')
        }}
      >
        English
      </Button>
      <ApprowGuard
        visible={visible}
        // onLoginTabChange={(v) => console.log(v)}
        // onRegisterTabChange={(v) => console.log(v)}
        // onClose={() => {
        //   setVisible(false)
        //   setTimeout(() => {
        //     setVisible(true)
        //   }, 2000)
        // }}
        onClose={() => {
          setVisible(false)
        }}
        // onLoad={(a) => console.log(a, '加载完成')}
        // onPwdResetError={(e) => console.log(e)}
        appId="60adc2ffca277ee9a84ee25a"
        // appId="5fd877fb0ba0421962eced94"
        config={config}
      />
    </>
  )
}

ReactDOM.render(<App />, document.getElementById('root'))

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals()
