import { defineComponent } from 'vue'
import sutdentDownLoad from '@/common/images/student_download.png'
import teacherDownLoad from '@/common/images/teacher_download.png'
import styles from '../../index.module.less'
import { ElButton } from 'element-plus'
import { getUserType } from '@/helpers/utils'
import { getUserInfo, state } from '@/state'
export const getAssetsHomeFile = (fileName: string) => {
  const path = `../../images/${fileName}`
  const modules = import.meta.globEager('../../images/*')
  return modules[path].default
}
export default defineComponent({
  name: 'register-success',
  props: {
    onClose: {
      type: Function,
      default: () => {}
    },
    onTypeChange: {
      type: Function,
      default: (type: any) => {}
    },
    type: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      registerType: 'student'
    }
  },
  async mounted() {
    if (this.type) {
      this.registerType = this.type
    } else {
      try {
        // 获取用户信息
        await getUserInfo()
      } catch {
        //
      }
      this.registerType = getUserType() === 'STUDENT' ? 'student' : 'teacher'
    }
  },
  render() {
    return (
      <div class={['text-center']}>
        <h2 class="text-2xl font-semibold text-[#333] mb-6 flex flex-col items-center">
          {this.type ? '酷乐秀' : '登录成功'}
          <i class="w-12 h-1 bg-[#2DC7AA] inline-block leading-none rounded-sm mt-1"></i>
        </h2>

        {this.registerType === 'teacher' ? (
          <img
            src={teacherDownLoad}
            class="mx-auto w-[192px] h-[192px] align-middle border-4 border-solid border-[#2DC7AA] rounded-[10px]"
          />
        ) : (
          <img
            src={sutdentDownLoad}
            class="mx-auto w-[192px] h-[192px] align-middle border-4 border-solid border-[#2DC7AA] rounded-[10px]"
          />
        )}

        {/* <h3 class="text-lg text=[#333] pt-4 pb-2">注册成功</h3> */}
        <div
          class={[styles.scanTxt, 'leading-6 text-lg text-[#333] pt-4 pb-2']}
        >
          {!this.type && (
            <p>
              恭喜您已成功登录酷乐秀
              {this.registerType === 'teacher' ? '老师' : '学生'}账号！
            </p>
          )}
          <p>
            {/* <span> */}
            下载酷乐秀
            {this.registerType === 'teacher' ? '老师' : '学生'}端APP
            {/* </span> */}
            发现更大的世界
          </p>
        </div>

        <ElButton
          type="primary"
          class="w-full mt-4"
          round
          style={{ height: '48px' }}
          onClick={() => {
            if (
              this.registerType == 'teacher' &&
              state.user.data.entryFlag !== 1
            ) {
              // this.type = 'teacher-auth'

              this.onTypeChange('teacher-auth')
            } else {
              this.onClose()
            }
          }}
        >
          知道了
        </ElButton>
      </div>
    )
  }
})
