<template>
  <div class="legend">
    <MenuCard
      :menuData="{
        type: 'legend',
        title: '图例',
        ifChange: false,
        boxWidth: legendData.boxWidth,
        boxHeight: legendData.boxHeight,
        menuIndex: legendData.menuIndex,
        subMenuIndex: legendData.subMenuIndex ? legendData.subMenuIndex : '',
      }"
    >
      <div class="legend-container">
        <div
          class="legend-container-left"
          :style="{
            width: legendData.leftWidth ? legendData.leftWidth : '50%',
          }"
        >
          <div
            class="legend-icon"
            v-for="(item, index) in legendData.legendIcon"
            :key="index"
            :style="{ background: item.background, border: item.border }"
          ></div>
        </div>
        <div
          class="legend-container-right"
          :style="{
            width: legendData.rightWidth ? legendData.rightWidth : '50%',
          }"
        >
          <el-popover
            placement="right-start"
            width="200"
            :content="item.info"
            trigger="hover"
            v-for="item in legendData.legendTitle"
            :key="item.name"
          >
            <div
              slot="reference"
              class="legend-title"
              :style="{
                width:
                  legendData.rightItemWidth + 'px'
                    ? legendData.rightItemWidth + 'px'
                    : '50px',
              }"
            >
              {{ item.name }}
            </div>
          </el-popover>
          <!-- <div
            class="legend-title"
            v-for="item in legendData.legendTitle"
            :key="item"
            :style="{
              width:
                legendData.rightItemWidth + 'px'
                  ? legendData.rightItemWidth + 'px'
                  : '50px',
            }"
          >
            {{ item }}
          </div> -->
        </div>
      </div>
    </MenuCard>
  </div>
</template>
<script>
import MenuCard from "@/components/layout/MenuCard.vue";
/**
 * 通用图例
 */
export default {
  name: "Legend",
  components: {
    MenuCard,
  },
  props: ["legendData"],
  data() {
    return {};
  },
  mounted() {},
  destroy() {},
  methods: {},
};
</script>
<style lang="less" scoped>
@commonBorderColor: #00aaff;
.tooltip {
  display: block !important;
  padding: 4px;
  z-index: 10000;

  .tooltip-inner {
    background: black;
    color: white;
    border-radius: 16px;
    padding: 5px 10px 4px;
  }

  .tooltip-arrow {
    display: none;
  }

  &[aria-hidden="true"] {
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.15s, visibility 0.15s;
  }

  &[aria-hidden="false"] {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.15s;
  }
}

.legend {
  pointer-events: auto;
  .legend-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    &-left {
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
      display: flex;
      flex-direction: column;
      justify-content: space-evenly;
      .legend-icon {
        width: 25px;
        height: 15px;
        background: @commonBorderColor;
        border-radius: 2px;
        margin: 0 auto;
      }
    }
    &-right {
      height: 100%;
      position: absolute;
      right: 0;
      top: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-evenly;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      .legend-title {
        // width: 50px;
        height: 20px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        color: white;
        pointer-events: auto;
      }
    }
  }
}
</style>
