<template>
  <m-card title="图例" :width="width" :height="height">
    <div class="legend-panel">
      <div v-for="item in legends" :key="item.name" class="legend-panel-row">
        <span
          class="legend-swatch"
          :style="{
            backgroundColor: item.fillColor,
            borderColor: item.strokeColor || item.fillColor,
          }"
        ></span>
        <span class="legend-name">{{ item.name }}</span>
      </div>
      <div v-if="!legends.length" class="legend-panel-empty">暂无图例</div>
    </div>
  </m-card>
</template>

<script setup>
import mCard from "@/components/mCard/index.vue"

defineProps({
  legends: {
    type: Array,
    default: () => [],
  },
  height: {
    type: Number,
    default: 278,
  },
  width: {
    type: Number,
    default: 398,
  },
})
</script>

<style lang="scss">
.legend-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  padding: 14px;

  &-row {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .legend-swatch {
    flex: 0 0 auto;
    width: 18px;
    height: 11px;
    margin-right: 7px;
    border: 1px solid;
    box-shadow: 0 0 12px rgba(48, 220, 255, 0.18);
  }

  .legend-name {
    min-width: 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  &-empty {
    grid-column: 1 / -1;
    color: rgba(255, 255, 255, 0.52);
    line-height: 80px;
    text-align: center;
  }
}
</style>
