<template>
  <div class="node">
    <div class="node-body" @click="$emit('selected')">
      <!-- 左侧移动按钮，仅在非 viewer 模式下展示，level > 1 -->
      <div
        v-if="level > 1 && diagramMode !== 'viewer'"
        class="node-body-left"
        @click.stop="$emit('leftMove')"
      >
        <i class="x-icon-arrow-left x-iconfont"></i>
      </div>

      <div class="node-body-main">
        <div class="node-body-main-header">
          <span class="title">
            <i class="x-icon-s-operation x-iconfont"></i>
            <span class="name">{{ config.name ? config.name : '并行任务' + level }}</span>
          </span>
          <span v-if="diagramMode !== 'viewer'" class="option">
            <a-tooltip placement="top">
              <template slot="title">复制分支</template>
              <i class="x-icon-copy-document x-iconfont" @click.stop="$emit('copy')"></i>
            </a-tooltip>
            <i class="x-icon-close x-iconfont" @click.stop="$emit('delNode')"></i>
          </span>
        </div>
        <div class="node-body-main-content">
          <span>gggg（同时进行）</span>
        </div>
      </div>

      <!-- 右侧移动按钮，仅在非 viewer 模式下展示，level < size -->
      <div
        v-if="level < size && diagramMode !== 'viewer'"
        class="node-body-right"
        @click.stop="$emit('rightMove')"
      >
        <i class="x-icon-arrow-right x-iconfont"></i>
      </div>
    </div>

    <div class="node-footer">
      <!-- 添加节点按钮，仅在非 viewer 模式下展示 -->
      <div v-if="diagramMode !== 'viewer'" class="btn">
        <InsertButton @insertNode="handleInsertNode" />
      </div>
    </div>
  </div>
</template>

<script>
import InsertButton from '@/views/workFlow/designer/common/InsertButton.vue';
//并发节点
export default {
  name: 'ConcurrentNode',
  components: {
    InsertButton
  },
  props: {
    config: {
      type: Object,
      default: () => ({})
    },
    level: {
      type: Number,
      default: 0
    },
    size: {
      type: Number,
      default: 0
    }
  },
  computed: {
    diagramMode() {
      return this.$store.state.workflow.diagramMode;
    }
  },
  methods: {
    handleInsertNode(type) {
      this.$emit('insertNode', type);
    }
  }
};
</script>

<style lang="less" scoped>
.node {
  padding: 30px 55px 0;
  width: 220px;
  .node-body {
    overflow: hidden;
    cursor: pointer;
    min-height: 80px;
    max-height: 120px;
    position: relative;
    border-radius: 5px;
    background-color: white;
    box-shadow: 0px 0px 5px 0px #d8d8d8;

    &:hover {
      .node-body-left,
      .node-body-right {
        i {
          display: block !important;
        }
      }
      .node-body-main {
        .option {
          display: inline-block !important;
        }
      }
      box-shadow: 0px 0px 3px 0px @primaryColor;
    }

    .node-body-left,
    .node-body-right {
      display: flex;
      align-items: center;
      position: absolute;
      height: 100%;
      i {
        display: none;
      }
      &:hover {
        background-color: #ececec;
      }
    }

    .node-body-left {
      left: 0;
    }

    .node-body-right {
      right: 0;
    }

    .node-body-main {
      position: absolute;
      width: 188px;
      left: 17px;
      display: inline-block;

      .node-body-main-header {
        padding: 10px 0px 5px;
        font-size: xx-small;
        position: relative;

        .title {
          color: #718dff;

          .name {
            display: inline-block;
            height: 14px;
            width: 130px;
            margin-left: 2px;
          }
        }

        .option {
          position: absolute;
          right: 0;
          display: none;
          font-size: medium;

          i {
            color: #888888;
            padding: 0 3px;
          }
        }
      }

      .node-body-main-content {
        padding: 6px;
        color: #656363;
        font-size: 14px;

        i {
          position: absolute;
          top: 55%;
          right: 10px;
          font-size: medium;
        }
      }
    }
  }

  .node-footer {
    position: relative;

    .btn {
      width: 100%;
      display: flex;
      height: 70px;
      padding: 20px 0 32px;
      justify-content: center;
    }

    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: -1;
      margin: auto;
      width: 2px;
      height: 100%;
      background-color: #cacaca;
    }
  }
}
</style>
