<template>
  <el-row class="profile">
    <el-col :sm="4" :md="4" :lg="4" class="info-picture">
      <img
        class="profile-picture"
        src="@/assets/image/dashboard-profile-default.png"
        alt="profile picture"
      />
      <div v-if="role == 1" class="username">{{ user.name || '--' }}</div>
    </el-col>
    <el-col :sm="20" :md="20" :lg="20" class="information">
      <div v-if="role != 1" class="username row">{{ user.name || '--' }}</div>
      <el-row :gutter="10" class="row">
        <el-col :sm="10" :md="10">
          <span>{{ t('Dashboard.Profile.Role') }}</span>
          <template v-for="(department, index) in departmentOptions" :key="index">
            <span v-if="user.departmentId == department.value" class="label">
              {{ t(department.label) }}
            </span>
          </template>
          <span v-if="!user.departmentId" class="label">
            {{ t('Dashboard.Role.item0') }}
          </span>
        </el-col>
        <el-col :sm="8" :md="8">
          <span>{{ t('Dashboard.Profile.User') }}</span>
          <span class="label">{{ user.name || '--' }}</span>
        </el-col>
        <el-col v-if="role == 5" :sm="6" :md="6">
          <span>{{ t('Dashboard.Profile.Location') }}</span>
          <span class="label">
            {{ isZhCn ? user.groupName || '--' : user.groupEnName || '--' }}
          </span>
        </el-col>
      </el-row>
      <el-row :gutter="10" class="row">
        <el-col :sm="10" :md="10">
          <span>{{ t('Dashboard.Profile.Email') }}</span>
          <span class="label">{{ user.email || '--' }}</span>
        </el-col>
        <el-col :sm="14" :md="14">
          <span>{{ t('Dashboard.Profile.LastIP') }}</span>
          <span class="label">{{ user.lastIp || '--' }}</span>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>
<script setup lang="ts">
  import { computed, inject, onMounted, ref } from 'vue'
  import { useI18n } from 'vue-i18n'
  import store from '@/vuexStore'
  const Session = inject('session')
  const { t } = useI18n()

  const role = ref(null)
  const departmentOptions = [
    { value: '1', label: 'Dashboard.Role.item1' },
    { value: '2', label: 'Dashboard.Role.item2' },
    { value: '3', label: 'Dashboard.Role.item3' },
    { value: '4', label: 'Dashboard.Role.item4' },
    { value: '5', label: 'Dashboard.Role.item5' },
  ]

  const user = computed(() => {
    return JSON.parse(Session.Get('user', true))
  })
  const isZhCn = computed(() => store.state.home.isZhCn)
  onMounted(async () => {
    console.log(user.value)
    role.value = user.value.departmentId
  })
</script>

<style scoped lang="scss">
  .profile {
    background-color: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    /*height: 170px;*/
    padding: 20px 0;
    color: #797979;
    display: flex;
    flex-wrap: wrap;

    .info-picture {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      align-items: center;
      .profile-picture {
        width: 120px;
        height: 128px;
        overflow: hidden;
        border-radius: 128px;
      }
      .username {
        width: 100%;
        font-weight: 700;
        color: #0d0d0d;
        margin-top: 10px;
        font-size: 14px;
      }
    }

    .information {
      text-align: left;
      padding: 0 20px;
      display: flex;
      flex-wrap: wrap;
      align-items: center;

      .username {
        font-weight: 700;
        color: #0d0d0d;
        font-size: 14px;
      }

      .row {
        width: 100%;
        line-height: 28px;
        white-space: nowrap;

        .el-col {
          overflow: hidden;

          .label {
            padding-left: 1em;
            text-overflow: ellipsis;
            overflow: hidden;
          }

          .link {
            margin-left: 1em;
            border: 1px solid rgb(245, 245, 245);
            padding: 2px 20px;
            //min-width: 240px;

            &:focus {
              outline: none;
            }
          }

          .btn-copy {
            margin-left: 20px;
            padding: 4px 10px;
            border-right: 4px;
            background-color: rgba(84, 129, 214, 1);
            color: #ffffff;
            cursor: pointer;
            transition: all 0.25s linear;

            &:hover {
              background-color: rgba(84, 129, 214, 0.8);
            }
          }
        }
      }
    }
  }
</style>
