<template>
  <div :class="{'line': row === 1, 'lines': row > 1}"
       :title="hoverTip ? content: null"
       :style="{'--row':row}">
    <slot name="pre"></slot>
    <div style="display: flex;flex-wrap: wrap;">
      <div v-for="(user,index) in userInfo" :key="index" class="avatar_name">
        <div class="user">
          <div class="circle-user">
            <Tooltip :content="user.name" placement="bottom-start" width="45">
            </Tooltip>
          </div>
          <div v-if="user.icon && mode === 'preview'"
               class="el-timeline-item__node" :style="{
                      backgroundColor: user.color
                    }">
            <el-icon v-if="user.icon" size="15" :class="user.class">
              <component :is="user.icon"/>
            </el-icon>
          </div>
        </div>
        <div class="arrow" v-if="(index+1)%3!==0&&userInfo.length!==1&&(index+1)!==userInfo.length&&showArrow">
          <el-icon size="20">
            <Right/>
          </el-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {Loading, Close, CircleCheckFilled, MoreFilled, Right} from '@element-plus/icons-vue'
import {defineProps} from "vue";

const props = defineProps({
  row: {
    type: Number,
    default: 1
  },
  hoverTip: {
    type: Boolean,
    default: false
  },
  userInfo: {
    type: Array,
    default: []
  },
  mode: {
    type: String,
    default: 'design'
  },
  //是否显示箭头
  showArrow: {
    type: Boolean,
    default: true
  }
})

const init = () => {
  for (let user of props.userInfo) {
    initUser(user)
  }
}

const initUser = (user) => {
  let state = user.state
  //创建节点
  if (state === 'CREATE') {
    user["icon"] = CircleCheckFilled
    user["color"] = "#0bbd87"
  }
  //审批通过
  if (state === 'AGREE' || state === 'AUTO_PASS') {
    user["icon"] = CircleCheckFilled
    user["color"] = "#0bbd87"
  }
  //审批处理中
  if (state === 'RUNNING') {
    user["icon"] = Loading
    user["color"] = "#f78f5f"
    user["class"] = 'is-loading'
  }
  //拒绝后评论
  if (state === 'REFUSE') {
    user["icon"] = Close
    user["color"] = "#f56c6c"
  }
  if (state === 'PASS') {
    user["icon"] = MoreFilled
    user["color"] = "#c0c4cc"
  }
  return user;
}

init()
</script>

<style scoped lang="scss">
.circle-user {
  width: 50px;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  border: 1px solid #ACACAC;
  position: relative;

  .circle-icon {
    width: 10px;
    height: 10px;
    position: absolute;
    top: auto !important;
    bottom: -9px;
    right: 15px !important;
  }
}

.avatar_name {
  display: flex;
  align-items: center;
  margin-bottom: 5px;

  .user {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 1px;
    /*width: 45px;*/
    position: relative;
  }
}

.el-timeline-item__node {
  position: absolute;
  bottom: 0;
  right: 1px;
}

</style>
