<template>
  <div
    class="x6-vue-shape left-content-group-content-item"
    :class="[{ 'business-img': !nameVal }]"
    :data-componentid="nodeData?.componentId"
    :data-componentname="nodeData?.componentName"
    :data-componentcode="nodeData?.componentCode"
  >
    <div class="icon">
      <img :src="activeIconSrc" alt="" />
    </div>
    <div class="span" v-if="nameVal">
      <a-tooltip placement="topLeft" :title="nameVal">
        <span class="x6-vue-shape-name-class">{{ nameVal }}</span>
      </a-tooltip>
    </div>
  </div>
</template>

<script>
import { defineComponent, onMounted, computed } from 'vue';

export default defineComponent({
  props: {
    // 节点信息
    nodeData: {
      type: Object
    },
    // 图片列表
    iconList: {
      type: Array,
      default: []
    }
  },
  setup(props) {
    // 名称
    const nameVal = computed(() => {
      if (props.nodeData?.name) {
        return props.nodeData?.name;
      }
      return '';
    });

    /**
     * 图标
     */
    const activeIconSrc = computed(() => {
      const icon = props.iconList.find(t => t.name == props.nodeData.componentCode);
      return icon ? icon.url : '';
    });

    onMounted(() => {});

    return {
      nameVal,
      activeIconSrc
    };
  }
});
</script>

<style scoped lang="less">
.x6-vue-shape {
  cursor: move;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 69px;
  position: relative;
  padding: 10px 4px;
  box-sizing: border-box;

  &:hover {
    box-shadow: 0 0 8px 1px #ccc;
  }

  .icon {
    width: 24px;
    height: 24px;

    .svg-img {
      width: 24px;
      height: 24px;
    }
  }

  .span {
    margin-top: 4px;
    text-align: center;
    width: 100%;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
  }
  .x6-vue-shape-name-class {
    color: #60666b;
    font-size: 15px;
  }
}

.business-img {
  padding: 0;
  height: 50px;

  .icon {
    width: auto;
    height: auto;
  }

  img {
    width: 30px;
    height: 30px;
  }
}
</style>
