<template>
  <div class="comp-content">
    <div class="content">
      <el-image v-if="imgUrl" class="img" :src="imgUrl" fit="cover" />
      <div class="avatar">
        <el-icon :size="26"><User /></el-icon>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue';
import { User } from '@element-plus/icons-vue';

interface Props {
  fileId: any;
}

const props = withDefaults(defineProps<Props>(), {
  fileId: '',
});

const env = import.meta.env;
const imgUrl = ref('');

watch(
  () => props.fileId,
  (val: any) => {
    if (val) {
      imgUrl.value = `${env.VITE_API_IMAGE_PREVIEW_URL}/data/previewImage?fileId=${val}`;
    } else {
      imgUrl.value = '';
    }
  },
  { deep: true, immediate: true }
);
</script>

<style lang="scss" scoped>
.comp-content {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  .content {
    width: 100%;
    height: 100%;
    .img {
      width: 100%;
      height: 100%;
    }
    .avatar {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      background-color: var(--el-fill-color);
    }
  }
}
</style>
