<template>
  <el-menu
    :default-active="defaultMenu"
    class="el-menu-list"
    mode="horizontal"
    :collapse-transition="true"
    active-text-color="#4886f8"
    @select="handleSelect"
  >
    <el-submenu v-for="item in menuArr" :key="item.id" :index="item.id">
      <template slot="title">{{ item.label }}</template>
      <el-menu-item v-for="ot in item.children" :key="ot.id" :index="ot.id">{{ ot.label }}</el-menu-item>
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  props: {
    menuArr: {
      type: Array,
      default: () => []
    },
    defaultMenu: {
      type: String,
      default: ''
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      this.$emit('onMenuSelect', {
        subKey: key,
        parentKey: keyPath[0]
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.el-menu-list {
  border-bottom: 0;
  width: fit-content !important;
  display: flex;
  align-items: center;
  ::v-deep .el-submenu {
    .el-submenu__title {
      border: 1px solid #dcdfe6;
      border-bottom-color: #dcdfe6 !important;
      height: 36px;
      line-height: 36px;
      color: #606266;
    }
    &.is-active {
      .el-submenu__title {
        border: 0;
        background-color: #4886f8;
        color: #ffffff !important;
      }
      .el-submenu__icon-arrow {
        color: #ffffff !important;
      }
    }
    &:first-child {
      border-right: 0;
      .el-submenu__title {
        border-radius: 4px 0 0 4px;
      }
    }
    &:last-child {
      border-left: 0;
      .el-submenu__title {
        border-radius: 0 4px 4px 0;
      }
    }
  }
}
</style>
