<template>
  <div>
    <ul class="te-navbar">
      <li class="brand" v-if="showLogo">
        <i v-if="!system.logo_url" :class="system.logo"></i>
        <img v-if="system.logo_url" :src="system.logo_url" />
      </li>
      <li class="info">
        <span>{{ system.name }}</span>
      </li>
      <li class="user dropdown">
        <i class="fa fa-user-circle-o" aria-hidden="true"></i>
        <div class="content">
          <a
            v-for="item in dropdowns"
            :key="item.name"
            :href="item.url ? item.url : '#'"
            @click="item.click ? item.click : clickDropdown(item)"
          >
            <i v-if="item.icon" :class="item.icon" aria-hidden="true"></i>
            {{ item.name }}</a
          >
        </div>
      </li>
      <li
        class="navs"
        :class="k.selected ? 'active' : ''"
        v-for="(k, i) in menus"
        :key="i"
        @click="navChanged(k)"
      >
        <a :href="k.url">{{ k.name }}</a>
      </li>
      <li></li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "TeNavbar",
  props: {
    system: {
      type: Object,
      default: () => {
        return {};
      },
    },
    showLogo: {
      type: Boolean,
      default: true,
    },
    dropdowns: {
      type: Array,
      default: function () {
        return [
          { icon: "fa fa-user-o", name: "admin" },
          { icon: "fa fa-sign-out", name: "退出", url: "/login" },
        ];
      },
    },
    menus: {
      type: Array,
    },
  },
  data() {
    return {};
  },
  methods: {
    clickDropdown(item) {
      this.$emit("clickDropdown", item);
    },
    themeChanging() {
      this.$emit("themeChanging");
    },
    setting() {
      this.$emit("setting");
    },
    navChanged(item) {
      if (!this.menus) {
        return;
      }
      this.menus.forEach(function (v) {
        v.selected = false;
        if (item == v) {
          v.selected = true;
        }
      });
      this.$emit("navChanged", item);
    },
  },
};
</script>

<style>
/* 头区域 */

.te-navbar {
  background-color: var(--banner-bg-color);
  height: var(--banner-height);
  line-height: var(--banner-height);
  list-style-type: none;
  margin: 0;
  padding: 0;
}
.te-navbar li {
  float: left;
  display: block;
  color:var(--banner-color);
  text-align: center;
  height: 100%;
}
.te-navbar .brand {
  width: calc((var(--menu-width) + var(--submenu-origin-width)) / 2);
  font-size: 1.3rem;
}
.te-navbar .brand img {
  width: 50px;
  vertical-align: middle;
}
.te-navbar .info {
  text-align: left;
  padding: 0px 50px;
  padding-right: 100px;
  font-weight: 500;
  font-size: 1.1rem;
}
.te-navbar .navs {
  float: right;
  font-size: 0.9rem;
  margin: 0px 2px;
}
.te-navbar .user {
  padding: 0px 40px;
  padding-left: 100px;
  float: right;
  font-size: 1.8rem;
}
.te-navbar > li > a {
  display: block;
  color:var(--banner-color);
  text-align: center;
  text-decoration: none;
  padding: 0px 10px;
}

.te-navbar > li:hover:not(.active) > a {
  background-color: #4caf50;
}

.te-navbar > li.active {
  background-color: #4caf50;
}
.dropdown {
  cursor: pointer;
  position: relative;
  display: inline-block;
}
.dropdown .content {
  display: none;
  position: absolute;
  font-size: 0.8rem;
  right: 10px;
  z-index: 2048;
  background-color: var(--menu-color);
  border: 1px solid var(--footer-bg-color);
  min-width: 100px;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  padding: 6px 6px;
}

.dropdown .content a {
  display: block;
  color: var(--def-font-color);
  height: calc(var(--pop-menu-height) * 0.8);
  line-height: calc(var(--pop-menu-height) * 0.8);
  text-decoration: none;
}
.dropdown .content a:hover {
  color: var(--menu-active-bg-color);
}
.dropdown .content a i {
  width: 16px;
  /* margin-right: 10px; */
}

.dropdown:hover .content {
  display: block;
}
@media screen and (max-width: 1200px) {
  .te-navbar .user {
    padding: 0px 10px;
  }
}
</style>