<template>
  <div
    :class="classObj"
    class="app-wrapper"
    :style="{ '--current-color': theme }"
  >
    <!-- <div
      v-if="device === 'mobile' && sidebar.opened"
      class="drawer-bg"
      @click="handleClickOutside"
    /> -->
    <!-- <sidebar v-if="!sidebar.hide && !isCustomerTerminal" class="sidebar-container" /> -->
    <div
      :class="{ hasTagsView: needTagsView, sidebarHide: true }"
      class="main-container"
    >
      <div :class="{ 'fixed-header': fixedHeader }">
        <navbar :isCustomerTerminal="isCustomerTerminal" />
        <!-- <tags-view v-if="needTagsView" /> -->
      </div>
      <app-main />
      <right-panel>
        <settings />
      </right-panel>
    </div>
  </div>
</template>

<script>
import RightPanel from "@/components/RightPanel";
import { AppMain, Navbar, Settings, Sidebar, TagsView } from "./components";
import ResizeMixin from "./mixin/ResizeHandler";
import { mapState } from "vuex";
import variables from "@/assets/styles/variables.scss";

export default {
  name: "Layout",
  data() {
    return {
      isCustomerTerminal: null,
    };
  },
  components: {
    AppMain,
    Navbar,
    RightPanel,
    Settings,
    Sidebar,
    TagsView,
  },
  mixins: [ResizeMixin],
  computed: {
    ...mapState({
      theme: (state) => {
        return "#409EFF";
      },
      sideTheme: (state) => {
        return "theme-light";
      },
      sidebar: (state) => {
        return { hide: false, opened: true, withoutAnimation: false };
      },
      device: (state) => state.app.device,
      needTagsView: (state) => {
        return false;
      },
      fixedHeader: (state) => {
        return true;
      },
    }),
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === "mobile",
      };
    },
    variables() {
      return variables;
    },
  },
  beforeMount() {
    const s = this;
    setTimeout(function () {
      console.log(s.fixedHeader);
    }, 1000);
    // 一直打开顶部菜单
    this.$store.dispatch("settings/changeSetting", {
      key: "topNav",
      value: true,
    });

    // 打开顶部固定
    this.$store.dispatch("settings/changeSetting", {
      key: "fixedHeader",
      value: true,
    });

    // 左侧菜单白色风格
    this.$store.dispatch("settings/changeSetting", {
      key: "sideTheme",
      value: "theme-light",
    });

    // primary颜色
    this.$store.dispatch('settings/changeSetting', {
        key: 'theme',
        value: this.$config.primarycolor
    })

    // 根据地址判断是否关闭tagView
    const urls = [
      "/index",
      "/customer/catalogue",
      "/customer/literature",
      "/customer/myapp",
      "/customer/myres",
      "/customer/system",
      "/customer/search",
    ];
    this.isCustomerTerminal = urls.indexOf(this.$route.path) >= 0;
    if (this.isCustomerTerminal) {
      this.$store.dispatch("settings/changeSetting", {
        key: "tagsView",
        value: false,
      });
    } else {
      this.$store.dispatch("settings/changeSetting", {
        key: "tagsView",
        value: true,
      });
    }
  },
  methods: {
    handleClickOutside() {
      this.$store.dispatch("app/closeSideBar", { withoutAnimation: false });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/mixin.scss";
@import "~@/assets/styles/variables.scss";

.app-wrapper {
  @include clearfix;
  position: relative;
  height: 100%;
  width: 100%;

  &.mobile.openSidebar {
    position: fixed;
    top: 0;
  }
}

.drawer-bg {
  background: #000;
  opacity: 0.3;
  width: 100%;
  top: 0;
  height: 100%;
  position: absolute;
  z-index: 999;
}

.fixed-header {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 9;
  width: calc(100% - #{$base-sidebar-width});
  transition: width 0.28s;
}

.hideSidebar .fixed-header {
  width: calc(100% - 54px);
}

.sidebarHide .fixed-header {
  width: 100%;
}

.mobile .fixed-header {
  width: 100%;
}
</style>
