<template>
  <el-link v-if="userType === UserType.ADMIN" type="primary" @click="handleClick" :disabled="id == null">{{name | defaultValue}}</el-link>
  <span v-else >{{name | defaultValue}}</span>
</template>

<script>
import { mapGetters } from 'vuex'
import { UserType } from '@/utils/constants'

export default {
  name: 'UserLink',
  props: {
    id: {
      type: String,
      default: null
    },
    name: {
      type: String,
      default: null,
    }
  },
  computed: {
    UserType() {
      return UserType
    },
    ...mapGetters(['userType'])
  },
  methods: {
    handleClick() {
      this.$emit('click');
      this.$router.push({path: `/smUser/user/${this.id}`})
    }
  }
}
</script>
