<template>
  <div class="fullheight eip-front-wrapper">
    <div
      class="eip-front-wrapper"
      :class="classObj"
      :style="{
        '--containerBgColor': variables[`${style}-container-background`],
        '--topBarBgColor': variables[`${style}-top-bar-background`],
        background: variables[`${style}-container-background`],
        '--topColor': variables[`${style}-tab-color`],
        '--background': variables[`${style}-top-bar-background`],
        '--menuColor': variables[`${style}-menu-color`],
      }"
    >
      <div
        v-if="'horizontal' === layout"
        class="layout-container-horizontal"
        :class="{
          fixed: header === 'fixed',
          'no-tabs-bar': tabsBar === 'false' || tabsBar === false,
        }"
      >
        <div :class="header === 'fixed' ? 'fixed-header' : ''">
          <app-top-bar />
          <div
            v-if="tabsBar === 'true' || tabsBar === true"
            :class="{ 'tag-view-show': tabsBar }"
          >
            <div
              class="app-main"
              :style="{
                background: variables[`${style}-top-bar-background`],
              }"
            >
              <app-tabs-bar />
            </div>
          </div>
        </div>
        <div class="app-main main-padding horizontal-container">
          <div class="app-main-container">
            <app-main />
          </div>
        </div>
      </div>
      <div
        v-else
        class="layout-container-vertical"
        :class="{
          fixed: header === 'fixed',
          'no-tabs-bar': tabsBar === 'false' || tabsBar === false,
        }"
      >
        <app-sidebar />
        <div class="app-main" :class="collapse ? 'is-collapse-main' : ''">
          <div :class="header === 'fixed' ? 'fixed-header' : ''">
            <app-nav-bar />
            <app-tabs-bar />
          </div>
          <div class="app-main-container">
            <app-main />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import AppSidebar from './sidebar'
  import AppNavBar from './navBar'
  import AppTopBar from './topBar'
  import AppTabsBar from './tabsBar'
  import AppMain from './main'
  import variables from '@/styles/variables.scss'
  import { mapGetters } from 'vuex'
  export default {
    name: 'Index',
    components: {
      AppSidebar,
      AppNavBar,
      AppTabsBar,
      AppMain,
      AppTopBar,
    },
    props: {
      id: {
        type: String,
        default: '',
      },
      menuId: {
        type: String,
        default: '',
      },
    },
    computed: {
      ...mapGetters({
        tabsBar: 'app/tabsBar',
        collapse: 'settings/collapse',
        header: 'app/header',
        device: 'settings/device',
        fullScreenState: 'routes/fullScreenState',
        style: 'app/style',
        tileMenus: 'app/tileMenus',
        layout: 'app/layout',
      }),
      classObj() {
        return {
          mobile: this.device === 'mobile',
        }
      },
      variables() {
        return variables
      },
    },
    watch: {
      id: {
        handler(newVal, oldVal) {
          if (newVal !== oldVal) {
            this.$store.dispatch('app/getAppInfo', newVal).catch(() => {
              window.location.href = `${window.context.front}/403`
            })
            this.$store.dispatch('app/getMenus', newVal)
            this.$baseEventBus.$emit('theme')
          }
        },
        immediate: true,
      },
    },
  }
</script>

<style lang="scss" scoped>
  @mixin fix-header {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: $base-z-index - 2;
    width: 100%;
    overflow: hidden;
  }
  .eip-front-wrapper {
    position: relative;
    width: $base-full-width;
    height: $base-full-height;

    .layout-container-horizontal {
      position: relative;
      height: calc(100% - #{$base-top-bar-height} - #{$base-tabs-bar-height});
      // overflow-y: auto;
      &.fixed {
        padding-top: calc(#{$base-top-bar-height} + #{$base-tabs-bar-height});
      }

      &.fixed.no-tabs-bar {
        padding-top: $base-top-bar-height;
      }

      ::v-deep {
        .app-main {
          width: $base-full-width;
          .tabs-bar-container {
            padding-right: 0;
          }
        }

        .fixed-header {
          @include fix-header;
        }

        .tag-view-show {
          background: var(--topBarBgColor);
          margin-top: 1px;
          box-shadow: $base-box-shadow;
        }

        .nav-bar-container {
          .fold-unfold {
            display: none;
          }
        }

        .main-padding {
          .app-main-container {
            margin-top: $base-content-margin;
            background: var(--containerBgColor);
          }
        }
      }
    }

    .layout-container-vertical {
      position: relative;
      height: calc(100% - #{$base-top-bar-height} - #{$base-tabs-bar-height});
      .mask {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: $base-z-index - 1;
        width: 100%;
        height: 100vh;
        overflow: hidden;
        background: #000;
        opacity: 0.5;
      }

      &.fixed {
        padding-top: calc(#{$base-nav-bar-height} + #{$base-tabs-bar-height});
      }

      &.fixed.no-tabs-bar {
        padding-top: $base-nav-bar-height;
      }

      .app-main {
        position: relative;
        height: 100%;
        overflow: auto;
        margin-left: $base-left-menu-width;
        transition: $base-transition;
        //隐藏滚动条
        &::-webkit-scrollbar {
          width: 0;
          background-color: transparent;
        }
        /*火狐下隐藏滚动条*/
        scrollbar-width: none;
        ::v-deep {
          .fixed-header {
            @include fix-header;

            left: $base-left-menu-width;
            width: $base-right-content-width;
            box-shadow: $base-box-shadow;
            transition: $base-transition;
          }

          .nav-bar-container {
            position: relative;
            box-sizing: border-box;
          }

          .tabs-bar-container {
            box-sizing: border-box;
          }

          .app-main-container {
            width: calc(100% - #{$base-content-margin}* 2);
            height: calc(
              100vh - #{$base-top-bar-height} - #{$base-tabs-bar-height} - #{$base-content-margin}*
                2
            );
            overflow-y: auto;
            margin: $base-content-margin;
            background: var(--containerBgColor);
            border-radius: $base-border-radius;

            //隐藏滚动条
            &::-webkit-scrollbar {
              width: 0;
              background-color: transparent;
            }
            /*火狐下隐藏滚动条*/
            scrollbar-width: none;
          }
        }

        &.is-collapse-main {
          width: calc(100% - 70px);
          margin-left: $base-left-menu-width-min;

          ::v-deep {
            .fixed-header {
              left: $base-left-menu-width-min;
              width: calc(100% - 65px);
            }
          }
        }
      }
    }
    .horizontal-container {
      display: flex;
      height: 100%;
      .app-main-container {
        margin: auto;
        width: 90% !important;
        overflow-y: auto;
        height: calc(100% - #{$base-content-margin});
        //隐藏滚动条
        &::-webkit-scrollbar {
          width: 0;
          background-color: transparent;
        }
        /*火狐下隐藏滚动条*/
        scrollbar-width: none;
      }

      .appcontent-div__content {
        width: 100%;
      }
    }

    ::v-deep .data_view__title {
      border-bottom: 1px solid #f2f2f2;
      padding-bottom: 5px;
      margin-top: 0;
    }
    .layout-container-vertical {
      .app-main {
        .app-main-container {
          // margin: 24px;
          ::v-deep .base-main {
            background-color: #f9fafc;
          }
        }
      }
    }
    ::v-deep .data_view {
      // height: 770px;
      height: 100%;
      section.el-container.data-preview-wrap {
        height: 100%;
        // padding: 5px;
      }
    }
    ::v-deep .template-preview-container.app-main-height {
      height: 90%;
    }

    /* 手机端开始 */
    &.mobile {
      ::v-deep {
        .el-pager,
        .el-pagination__jump {
          display: none;
        }

        .layout-container-vertical {
          .el-scrollbar.side-bar-container.is-collapse {
            width: 0;
          }

          .app-main {
            width: 100%;
            margin-left: 0;
          }
        }

        .app-main {
          .fixed-header {
            left: 0 !important;
            width: 100% !important;
          }
        }
      }
    }

    /* 手机端结束 */
  }
</style>
