<template>
  <div :class="classObj" class="app-wrapper zap-home" :style="{'--current-color': theme}">
    <!-- 一级导航水平 start -->
    <!-- <el-header style="width:100%"> -->
    <div class="zap-header" :style="{backgroundColor: variables.menuBg}">
      <div style="display:flex;align-items:center;">
        <img class="zap-home-logo" src="../assets/images/home_logo.png" alt="">
        <div class="zap-home-name">融信宝</div>
      </div>
      <div style="display: flex; align-items: center;">
        <div class="zap-home-search">
          <img class="zap-home-search__icon" src="../assets/images/home_search.png" alt="">
          <el-input class="zap-home-search__input" placeholder="输入搜索关键词"></el-input>
        </div>
        <img class="zap-home-header__icon" src="../assets/images/nav_icon1.png" alt="">
        <img class="zap-home-header__icon" src="../assets/images/nav_icon2.png" alt="">
        <!-- <user /> -->
        <img class="zap-avatar" :src="avatar" alt="">
        <P class="zap-username">{{name}}</P>
      </div>
    </div>
    <!-- </el-header> -->
    <!-- 一级导航水平 end -->
    <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside"/>
    <sidebar class="sidebar-container" />
    <div :class="{hasTagsView:needTagsView}" class="main-container">
      <div :class="{'fixed-header':fixedHeader}">
        <navbar />
        <tags-view v-if="needTagsView" />
      </div>
      <app-main />
      <right-panel v-if="showSettings">
        <settings />
      </right-panel>
    </div>
  </div>
</template>

<script>
import RightPanel from '@/components/RightPanel'
import { AppMain, Navbar, Settings, Sidebar, TagsView, Horizontalbar, User } from './components'
import ResizeMixin from './mixin/ResizeHandler'
import { mapGetters, mapState } from "vuex"
import variables from '@/assets/styles/variables.scss'
export default {
  name: 'Layout',
  components: {
    AppMain,
    Navbar,
    RightPanel,
    Settings,
    Sidebar,
    Horizontalbar,
    TagsView,
    User
  },
  mixins: [ResizeMixin],
  computed: {
    ...mapState({
      settings: state => state.settings,
      theme: state => state.settings.theme,
      sideTheme: state => state.settings.sideTheme,
      sidebar: state => state.app.sidebar,
      device: state => state.app.device,
      showSettings: state => state.settings.showSettings,
      needTagsView: state => state.settings.tagsView,
      fixedHeader: state => state.settings.fixedHeader
    }),
    ...mapGetters(["permission_routes", "sidebar", "avatar", "name"]),
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile'
      }
    },
    variables() {
      return variables;
    },
    activeMenu() {
        const route = this.$route;
        const { matched } = route;
        // if set path, the sidebar will highlight the path you set
        if (matched[0]) {
          return matched[0].path;
        }
        return '';
    },
  },
  methods: {
    handleClickOutside() {
      this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
    }
  }
}
</script>
<style lang="scss">
.zap-home{
  .el-input--medium .el-input__inner{
    font-size: 16px;
    border-color: transparent;
  }
}
</style>
<style lang="scss" scoped>
  @import "~@/assets/styles/mixin.scss";
  @import "~@/assets/styles/variables.scss";
  .horizontalbar-container{
    // display: flex;
    justify-content: space-between;
    padding-left: 270px;
    z-index:5;
    .el-menu-item{
      padding: 0 2%;
    
      
    }
  }
  .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% - #{$sideBarWidth});
    transition: width 0.28s;
  }

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

  .mobile .fixed-header {
    width: 100%;
  }
  .zap-header{
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    z-index: 99;
  }
  .zap-home-logo{
    width: 215px;
    height: 60px;
  }
  .zap-home-name{
    display: inline-block;
    height: 60px;
    line-height: 60px;
    text-align: center;
    padding: 0 16px;
    font-size: 16px;
    color: #ffffff;
    background-image: linear-gradient(
      #3b72d8, 
      #3b72d8), 
    linear-gradient(
      #588dff, 
      #588dff);
    background-blend-mode: normal, 
      normal;
  }
  .zap-home-search{
    display: flex;
    align-items: center;
    width: 395px;
    height: 40px;
    padding: 0 22px;
    background-image: linear-gradient(
      #ffffff, 
      #ffffff), 
    linear-gradient(
      #f7f7f7, 
      #f7f7f7);
    background-blend-mode: normal, 
      normal;
    border-radius: 19px;
    border: solid 1px #ebebeb;
  }
  .zap-home-search__icon{
    width: 21px;
    height: 22px;
  }
  .zap-home-search__input{
    
  }
  .zap-home-header__icon{
    width: 26px;
    height: 26px ;
    &:nth-of-type(1){
      margin-left: 40px;
    }
    &:nth-of-type(2){
      margin-left: 30px;
    }
  }
  .zap-avatar{
    width: 40px;
    height: 40px;
    margin-left: 40px;
    border-radius: 50%;
  }
  .zap-username{
    margin-left: 10px;
    margin-right: 24px;
    font-size: 14px;
    color: #ffffff;
  }
</style>
