<template>
  <div class="bottom-panel">
    <!-- <div class="tool-item active">水库</div>
    <div class="tool-item">水闸</div>
    <div class="tool-item">堤防</div> -->
    <div
      v-for="(item, index) in layerData"
      :class="['tool-item', { active: selectedKeys.includes(item.id) }]"
      @click="handleChangeLayer(item)"
    >
      {{ item.nameCn }}
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from "vue";
import { useProjectStore } from "@/store/modules/project";
const projectStore = useProjectStore();

defineOptions({
  name: "bottom-panel",
});
const activeLayers = ref([]);
const listName = ref(["水库点", "堤防", "水闸"]);
const layerData: any = computed(() => {
  const list = [];
  listName.value.forEach((item, index) => {
    const layer = projectStore.getLayerByName(item);
    if (layer) {
      list.push(layer);
    }
  });
  return list;
});
const selectedKeys = computed(() => projectStore.selectedLayerKeys);
function handleChangeLayer(item: any) {
  if (activeLayers.value.includes(item.id)) {
    activeLayers.value = activeLayers.value.filter((id: any) => id !== item.id);
    projectStore.setLayerVisibility(item.id, false);
  } else {
    activeLayers.value.push(item.id);
    projectStore.setLayerVisibility(item.id, true);
  }
}
</script>

<style scoped lang="less">
.bottom-panel {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  .tool-item {
    width: 152px;
    height: 48px;
    border-radius: 4px;

    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;

    background: url("@/assets/bottom/btn-bg.png") no-repeat;
    backdrop-filter: blur(10px);

    font-family: Source Han Sans;
    font-size: 20px;
    font-weight: 500;
    line-height: 23.4px;
    text-align: right;
    letter-spacing: 0px;

    color: #ffffff;
    cursor: pointer;
    &:hover,
    &.active {
      background: url("@/assets/bottom/btn-bg-active.png") no-repeat;
    }
  }
}
</style>
