<template>
  <div class="acyiveHeight">
    <div v-if="collectionsData.length > 0">
      <div
        v-for="elem in collectionsData"
        :key="elem.id"
        flex="cross:center"
        :style="{
          color: settings.sideTheme === 'theme-dark' ? '#fff' : '#4c4c4c',
        }"
        class="newsSider"
        :class="{ active: elem.id === activeIndex }"
        @mouseenter="openCollectChildren(elem)"
      >
        <i class="newsSider-icon el-icon-star-off"></i>
        <p class="newsSider-title" :class="{ active: elem.id === activeIndex }">
          {{ elem.meta.title }}
        </p>
      </div>
    </div>
    <div v-for="(item, index) in sidebarRouters" :key="index">
      <div
        v-if="!item.hidden && item.meta"
        flex="cross:center"
        :class="{ active: index === activeIndex }"
        :style="{
          color: settings.sideTheme === 'theme-dark' ? '#fff' : '#4c4c4c',
        }"
        class="newsSider"
        @mouseenter="openChildren(item, index)"
      >
        <i class="newsSider-icon iconfont" :class="item.meta.icon ? item.meta.icon :'el-icon-office-building'"> </i>
        <!-- <i class="newsSider-icon iconfont" :class="item.meta.icon"> </i> -->
        <p class="newsSider-title" :class="{ active: index === activeIndex }">
          {{ item.meta.title }}
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";
export default {
  props: {
    collectionsData: {
      type: Array,
      required: [],
    },
    sidebarRouters: {
      type: Array,
      required: [],
    },
    routePath: {
      type: String,
      required: "",
    },
  },
  computed: {
    ...mapState(["settings", "sidebar"]),
    sideTheme() {
      return this.$store.state.settings.sideTheme;
    },
  },
  watch: {
    sideTheme: {
      handler: function (val, oldVal) {
        if (val.sideTheme != "theme-dark") {
        }
        // this.theme = val;
        // this.changeBgColor(val);
      },
      immediate: true,
    },
  },
  data() {
    return {
      activeIndex: null,
    };
  },
  mounted() {
    this.activeIndex = null;
  },
  methods: {
    // 打开弹窗
    openChildren(item, index) {
      if (!item.children) {
        this.$store.dispatch("app/changeChildrenHide", false);
      } else {
      }
      this.$emit("openChildren", item);
      this.activeIndex = index;
    },
    openCollectChildren(data) {
      this.activeIndex = data.id;
      this.$emit("openChildren", data);
    },
  },
};
</script>

<style scoped lang="scss">
$activeColor: var(--bg-color, "#00aaff");

::v-deep .newsSider {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -ms-user-select: none;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  margin: 5px 0;
  color: #fff;

  &-icon {
    width: 40px;
    height: 40px;
    line-height: 40px;
    // background: white;
    // color: #147af8;
    font-size: 25px;
    border-radius: 4px;
    margin-bottom: 7px;
    text-align: center;
  }

  &-title {
    font-size: 13px;
    padding-bottom: 5px;
  }
}

.acyiveHeight {
  width: 128px;
  padding: 15px 5px;
  overflow-y: auto;
  height: 100%;
  border-right: 2px solid #d6d1d169;
}

::-webkit-scrollbar {
  width: 0 !important;
}

::-webkit-scrollbar {
  width: 0 !important;
  height: 0;
}

::v-deep .newsSider.active .newsSider-icon {
  color: #1478f6;
  background-color: #fff;
}

::v-deep .newsSider.active .newsSider-title {
  // color: #000;
}

::v-deep.newsSider + .newsSider {
  border-top: 1px solid #747474;
}
</style>
