<template>
  <a-layout-header
    :class="[layout, headerTheme, headerThememode, 'admin-header']"
  >
    <div :class="['admin-header-wide', layout, pageWidth]">
      <router-link
        v-if="isMobile || layout === 'head'"
        to="/"
        :class="['logo', isMobile ? null : 'pc', headerTheme]"
      >
        <img
          width="32"
          :src="sysLogo ? api + sysLogo : require('@/assets/img/logo.png')"
        />
        <h1 class="title" v-if="!isMobile" style="padding-left: 10px">
          {{ sysName ? sysName : systemName }}
        </h1>
      </router-link>
      <a-divider v-if="isMobile" type="vertical" />
      <a-icon
        v-if="layout !== 'head'"
        class="trigger"
        :type="collapsed ? 'menu-unfold' : 'menu-fold'"
        @click="toggleCollapse"
      />
      <!-- <HeaderSite /> -->
      <div
        v-if="layout !== 'side' && !isMobile"
        class="admin-header-menu"
        :style="`width: ${menuWidth};`"
      >
        <i-menu
          class="head-menu"
          :theme="headerTheme"
          mode="horizontal"
          :options="menuData"
          @select="onSelect"
        />
      </div>
      <div :class="['admin-header-right', headerTheme, 'flex', 'aic']">
        <a-button
          v-permission="[1]"
          type="primary"
          class="mr10"
          @click="visibleInit = true"
          >初始化区域数据</a-button
        >
        <a-tooltip class="header-item" title="返回门户" placement="bottom">
          <a :href="portalUrl + (path ? path : '')">
            <a-icon type="home" /> 返回门户
          </a>
        </a-tooltip>
        <!-- <a-tooltip class="header-item" title="数据可视化" placement="bottom">
          <a href="" target="_blank"> <a-icon type="setting" /> 数据可视化 </a>
        </a-tooltip> -->
        <!-- <header-notice class="header-item" /> -->
        <!-- <header-avatar class="header-item" /> -->
        <!-- <a-dropdown class="lang header-item">
          <div><a-icon type="global" /> {{ langAlias }}</div>
          <a-menu
            @click="(val) => setLang(val.key)"
            :selected-keys="[lang]"
            slot="overlay"
          >
            <a-menu-item v-for="lang in langList" :key="lang.key">{{
              lang.key.toLowerCase() + " " + lang.name
            }}</a-menu-item>
          </a-menu>
        </a-dropdown> -->
      </div>
    </div>
    <!-- 初始化区域数据弹窗 -->
    <InitArea :visibleInit.sync="visibleInit"></InitArea>
  </a-layout-header>
</template>

<script>
// import HeaderSearch from './HeaderSearch'
// import HeaderNotice from './HeaderNotice'
// import HeaderSite from "./HeaderSite";
// import HeaderAvatar from "./HeaderAvatar";
import InitArea from "../../components/initarea/InitArea.vue";
import IMenu from "@/components/menu/menu";
import { mapState, mapMutations } from "vuex";

export default {
  name: "AdminHeader",
  components: { IMenu, InitArea },
  props: ["collapsed", "menuData"],
  data() {
    return {
      api: process.env.VUE_APP_API_IMG_URL,
      systemName: process.env.VUE_APP_sysName,
      visibleInit: false,
      langList: [
        { key: "CN", name: "简体中文", alias: "简体" },
        { key: "HK", name: "繁體中文", alias: "繁體" },
        { key: "US", name: "English", alias: "English" },
      ],
      searchActive: false,
      portalUrl: process.env.VUE_APP_API_portal_URL + "/#",
    };
  },
  computed: {
    ...mapState("site", ["sysName", "sysLogo", "path"]),
    ...mapState("setting", [
      "theme",
      "isMobile",
      "layout",
      "systemName",
      "lang",
      "pageWidth",
    ]),
    headerTheme() {
      if (
        this.layout == "side" &&
        this.theme.mode == "dark" &&
        !this.isMobile
      ) {
        return "light";
      }
      return this.theme.mode;
    },
    headerThememode() {
      return `header-${this.theme.mode}`;
    },
    langAlias() {
      let lang = this.langList.find((item) => item.key == this.lang);
      return lang.alias;
    },
    menuWidth() {
      const { layout, searchActive } = this;
      const headWidth = layout === "head" ? "100% - 188px" : "100%";
      const extraWidth = searchActive ? "600px" : "500px";
      return `calc(${headWidth} - ${extraWidth})`;
    },
  },
  created() {
    document.title = this.sysName ? this.sysName : this.systemName; // 设置项目标题
  },
  methods: {
    toggleCollapse() {
      this.$emit("toggleCollapse");
    },
    onSelect(obj) {
      this.$emit("menuSelect", obj);
    },
    ...mapMutations("setting", ["setLang"]),
  },
};
</script>

<style lang="less" scoped>
@import "index";
.title {
  font-weight: bold;
  font-size: 18px;
  max-width: 200px;
  line-height: normal;
}
</style>
