<script setup lang="ts">
import { computed } from 'vue'
import { getLevelProgress } from '@/utils'

const props = defineProps<{
  userInfo: any
  reverseLevel?: boolean
  // 显示真实名字
  showName?: boolean
}>()

defineOptions({ name: 'UserFigureBig' })

// resourceUrl
// homePageResourceUrl
// personalInfoResourceUrl
const nicknameBg = computed(() => {
  const obj = props.userInfo?.personInUsePersonalities?.find((i: anyObj) => i.remark === 4)
  return obj?.personalInfoResourceUrl || obj?.homePageResourceUrl || obj?.resourceUrl
})
const currentLevelProgress = computed(() =>
  getLevelProgress(props.userInfo?.englishSubjectExpLevelVo),
)

const currentLevelProgressText = computed(() => {
  // console.log(props.userInfo)
  if (!props.userInfo?.englishSubjectExpLevelVo) return '0/0'
  const { currentLevelNum, currentExpEnd, currentExp, currentExpStart, nextExp } =
    props.userInfo?.englishSubjectExpLevelVo || {}
  return currentLevelNum === 60
    ? `${currentExpEnd}/${currentExpEnd}`
    : `${currentExp - currentExpStart}/${nextExp - currentExpStart}`
})
</script>

<template>
  <div class="user-figure-big">
    <div class="photo_name">
      <UserHead size="120" :personalList="userInfo.personInUsePersonalities" />
      <div class="name">{{ showName ? userInfo.name : userInfo.nickName }}</div>
    </div>
    <div class="item">
      <div class="personal">
        <Icon class="sex" :name="userInfo.sex === 1 ? 'boy_icon' : 'girl_icon'" size="48"></Icon>
        <div
          class="nickname"
          :style="{
            'background-image': `url(${nicknameBg})`,
            'background-repeat': 'no-repeat',
            'background-size': '100% 100%',
          }"
        >
          <LineFont class="name" :text="userInfo.nickName" size="28" border="6" />
        </div>
      </div>
      <div class="level">
        <LineFont
          class="number"
          :reverse="reverseLevel"
          :text="`等级${userInfo.englishSubjectExpLevelVo?.currentLevelNum}`"
          size="24"
          border="4"
        />
        <div class="progress">
          <el-progress
            text-inside
            :percentage="currentLevelProgress"
            color="#4CEA91"
            :show-text="false"
          >
            <LineFont :text="currentLevelProgressText" size="12" border="2" />
          </el-progress>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.user-figure-big {
  position: relative;
  display: flex;
  padding: $space-4_h 0 $space-3_h 3vh;
  height: 21.67vh;
  box-sizing: border-box;

  .photo_name {
    position: relative;
    .name {
      position: absolute;
      top: 11.67vh;
      left: 50%;
      transform: translateX(-50%);
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 2.5vh;
      width: 11.33vh;
      height: 4vh;
      background: rgba(185, 209, 234, 1);
      box-shadow: 0 0 0.5vh 0 rgba(76, 116, 158, 1) inset;
      color: #fff;
      text-shadow: 0 0.33vh 0.17vh rgba(0, 0, 0, 0.25);
      line-height: 3vh;
      text-align: center;
      font-size: $font-size-3;
      font-family: $font-special;
      z-index: -1;
    }
  }

  .item {
    position: absolute;
    left: 15.5vh;
    width: 42.5vh;
    .personal {
      display: flex;
      align-items: center;
      .sex {
        margin-top: 3.67vh;
      }
      .nickname {
        position: relative;
        width: 29.67vh;
        height: 10vh;
        line-height: 4vh;
        margin-left: 1.67vh;
        background-repeat: no-repeat;
        background-position: center;
        padding: 0 2vh;
        @include single_ellipsis;

        .name {
          position: absolute;
          bottom: 1.75vh;
          left: 50%;
          transform: translateX(-50%);
        }
      }
    }
    .level {
      width: 40.5vh;
      display: flex;
      align-items: center;
      column-gap: 2vh;
      //   justify-content: space-between;
      margin-top: 1.83vh;
      // color: rgba(75, 75, 104, 1);
      //   :deep(.title-outline.is-reverse) {
      //     color: #4b4b68;
      //   }

      span {
        white-space: nowrap;
      }

      .progress {
        width: 26vh;

        :deep(.el-progress-bar__innerText) {
          margin: -0.5vh 1.83vh 0 0.42vh;
        }

        :deep(.x-line-font) {
          // font-family: $font-text;
        }
      }
      :deep(.el-progress-bar__outer) {
        height: 2vh !important;
        background: rgba(0, 0, 0, 0.65);
      }
    }
  }
}
</style>
