/* $sideBarWidth: vertical 模式下主体内容距离网页文档左侧的距离 */
@mixin merge-style($sideBarWidth) {
  $menuActiveText: #7a80b4;

  @media screen and (width >= 150px) and (width <= 420px) {
    .app-main-nofixed-header {
      overflow-y: hidden;
    }
  }

  @media screen and (width >= 420px) {
    .app-main-nofixed-header {
      overflow: hidden;
    }
  }

  /* 修复 windows 下双滚动条问题 https://github.com/pure-admin/vue-pure-admin/pull/936#issuecomment-1968125992 */
  .el-popper.pure-scrollbar {
    overflow: hidden;
  }

  /* popper menu 超出内容区可滚动 */
  .pure-scrollbar {
    max-height: calc(100vh - calc(50px * 2.5));
    overflow: hidden auto;
  }

  .sub-menu-icon {
    margin-right: 5px;
    font-size: 18px;

    svg {
      width: 18px;
      height: 18px;
    }
  }

  .set-icon,
  .fullscreen-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 48px;
    cursor: pointer;
  }

  .main-container::after {
    position: absolute;
    top: 0;
    right: 0;
    width: 25px; /* 与 padding-right 相同 */
    height: 100%;
    content: "";

    // background-color: #d5e8fb; /* 背景颜色设置为蓝色 */
    background-color: #d5e8fb; /* 背景颜色设置为蓝色 */
    // z-index: -1; /* 确保伪元素位于背景之后 */
  }

  .main-container {
    position: relative;
    height: 100vh;

    // border: 1px solid red;
    min-height: 100%;

    // width: 1250px;
    padding-right: 50px;
    margin-left: $sideBarWidth;

    // background: #f0f2f5;
    background: #fff;

    /* main-content 属性动画 */
    transition: margin-left var(--pure-transition-duration);

    .el-scrollbar__wrap {
      height: 100%;
      overflow: auto;
    }
  }

  .main-container::before {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 9;
    width: 100%;
    height: 20px;
    content: "";
    background-color: #d5e8fb;
  }

  .fixed-header {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 998;
    width: calc(100% - #{$sideBarWidth});

    /* fixed-header 属性左上角动画 */
    transition: width var(--pure-transition-duration);
  }

  .main-hidden {
    margin-left: 0 !important;

    .fixed-header {
      width: 100% !important;

      + .app-main {
        padding-top: 37px !important;
      }
    }
  }

  .sidebar-container {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1001;
    width: $sideBarWidth !important;
    height: 100%;
    overflow: visible;
    font-size: 0;
    background: $menuBg;

    // border-right: 1px solid var(--pure-border-color);

    /* 展开动画 */
    transition: width var(--pure-transition-duration);

    .scrollbar-wrapper {
      overflow-x: hidden !important;
    }

    .el-scrollbar__bar.is-vertical {
      right: 0;
    }

    &.has-logo {
      .el-scrollbar.pc {
        /* logo: 48px、leftCollapse: 40px、leftCollapse-shadow: 4px */
        height: calc(100% - 92px);
      }

      /* logo: 48px */
      .el-scrollbar.mobile {
        height: calc(100% - 48px);
      }
    }

    &.no-logo {
      .el-scrollbar.pc {
        /* leftCollapse: 40px、leftCollapse-shadow: 4px */
        height: calc(100% - 44px);
      }

      .el-scrollbar.mobile {
        height: 100%;
      }
    }

    .is-horizontal {
      display: none;
    }

    a {
      display: flex;
      flex-wrap: wrap;
      width: 100%;
    }

    .el-menu {
      height: 100%;
      background-color: transparent !important;
      border: none;
    }

    .el-menu-item,
    .el-sub-menu__title {
      height: 50px;

      // color: $menuText;

      background-color: transparent !important;

      &:hover {
        color: $menuTitleHover !important;
      }

      div,
      span {
        height: 50px;
        line-height: 50px;
      }
    }

    .submenu-title-noDropdown,
    .el-sub-menu__title {
      &:hover {
        background-color: transparent;
      }
    }

    .is-active > .el-sub-menu__title,
    .is-active.submenu-title-noDropdown {
      // color: $menuText !important;
      color: black !important;

      i {
        // color: $menuText !important;
        color: black !important;
      }
    }

    .is-active {
      color: $subMenuActiveText !important;
      transition: color 0.3s;
    }

    .el-menu-item.is-active.nest-menu > * {
      z-index: 1;
      color: #fff;
    }

    .el-menu-item.is-active.nest-menu::before {
      position: absolute;
      inset: 0 8px;
      margin: 4px 0;
      clear: both;
      content: "";
      background: var(--el-color-primary) !important;
      border-radius: 3px;
    }

    .el-menu .el-menu--inline .el-sub-menu__title,
    & .el-sub-menu .el-menu-item {
      min-width: $sideBarWidth !important;
      font-size: 14px;

      // background-color: $subMenuBg !important;
      // background-color: #689df3 !important;
      background-color: #d5e8fb !important;
    }

    /* 有子集的激活菜单左侧小竖条 */
    .el-menu--collapse
      .is-active.outer-most.el-sub-menu
      > .el-sub-menu__title::before {
      position: absolute;
      top: 0;
      left: 0;
      width: 2px;
      height: 100%;
      clear: both;
      content: "";
      background-color: $menuActiveBefore;
      transition: all var(--pure-transition-duration) ease-in-out;
      transform: translateY(0);
    }

    .el-menu--collapse .outer-most.el-sub-menu > .el-sub-menu__title::before {
      position: absolute;
      top: 50%;
      display: block;
      width: 3px;
      height: 0;
      content: "";
      transform: translateY(-50%);
    }

    /* 无子集的激活菜单背景 */
    .is-active.submenu-title-noDropdown.outer-most > * {
      z-index: 1;
      font-size: 14px !important;

      // color: #fff;
      color: blue !important;
    }

    .is-active.submenu-title-noDropdown.outer-most::before {
      position: absolute;
      inset: 0 8px;
      margin: 4px 0;
      clear: both;
      content: "";

      // border: 1px solid red;
      // background: var(--el-color-primary) !important;
      background: #c2daf7 !important;
      border-radius: 3px;
    }
  }

  /* vertical 菜单折叠 */
  .el-menu--vertical {
    .el-menu--popup {
      // background-color: $subMenuBg !important;
      background-color: #022bbd !important;

      .el-menu-item {
        span {
          font-size: 14px;
        }
      }
    }

    & > .el-menu {
      i {
        margin-right: 20px;
      }
    }

    .is-active > .el-sub-menu__title,
    .is-active.submenu-title-noDropdown {
      // color: $subMenuActiveText !important;
      color: black !important;

      i {
        // color: $subMenuActiveText !important;
        color: black !important;

        // color: red !important;
      }
    }

    /* 子菜单中还有子菜单 */
    .el-menu .el-sub-menu__title {
      min-width: $sideBarWidth !important;
      font-size: 14px;
      background-color: $subMenuBg !important;
    }

    .el-menu-item,
    .el-sub-menu__title {
      height: 50px;
      line-height: 50px;

      // color: $menuText;
      color: black;
      background-color: $subMenuBg;

      &:hover {
        color: $menuTitleHover !important;
      }
    }

    .is-active {
      color: $subMenuActiveText !important;
      transition: color 0.3s;
    }

    // 子菜单选中状态
    .el-menu-item.is-active.nest-menu > * {
      z-index: 1;

      // color: #409eff;
      color: #0052d9;
    }

    .el-menu-item.is-active.nest-menu::before {
      position: absolute;
      inset: 0 8px;
      clear: both;
      content: "";

      // background: var(--el-color-primary) !important;
      // border: 1px solid red;
      background: #bfd4f6 !important;
      border-radius: 3px;
    }

    .el-menu-item,
    .el-sub-menu {
      .iconfont {
        font-size: 18px;
      }

      .el-menu-tooltip__trigger {
        width: 54px;
        padding: 0;
      }
    }
  }

  /* horizontal 菜单 */
  .el-menu--horizontal {
    & > .el-sub-menu .el-sub-menu__icon-arrow {
      position: static !important;
      margin-top: 0;
    }

    /* 无子菜单时激活 border-bottom */
    a > .is-active.submenu-title-noDropdown {
      border-bottom: 2px solid var(--el-menu-active-color);
    }

    .el-menu--popup {
      // background-color: $subMenuBg !important;
      background-color: #022bbd !important;

      a > .is-active.submenu-title-noDropdown {
        border-bottom: none;
      }

      .el-menu-item {
        color: $menuText;

        // background-color: $subMenuBg;
        background-color: #022bbd;

        span {
          font-size: 14px;
        }
      }

      .el-sub-menu__title {
        color: $menuText;
      }
    }

    /* 子菜单中还有子菜单 */
    .el-menu .el-sub-menu__title {
      min-width: $sideBarWidth !important;
      font-size: 14px;
      background-color: $subMenuBg !important;

      &:hover {
        color: $menuTitleHover !important;
      }
    }

    .is-active > .el-sub-menu__title,
    .is-active.submenu-title-noDropdown {
      // color: $subMenuActiveText !important;
      color: $subMenuActiveText !important;

      // border: 1px solid green;

      i {
        // color: $subMenuActiveText !important;
      }
    }

    .nest-menu .el-sub-menu > .el-sub-menu__title,
    .el-menu-item {
      // 鼠标悬停颜色
      &:hover {
        // color: $menuTitleHover !important;
        color: #fff !important;
      }
    }

    .el-menu-item.is-active {
      z-index: 10;
      color: #ffffffe6 !important;
      transition: color 0.3s;
    }

    .el-menu-item.is-active.nest-menu > * {
      z-index: 1;
      color: #fff;
    }

    .el-menu-item.is-active.nest-menu::before {
      position: absolute;
      inset: 0 5px;
      clear: both;
      content: "";
      background: var(--el-color-primary) !important;
      border-radius: 3px;
    }
  }

  .horizontal-header {
    display: flex;
    align-items: center;
    justify-content: space-around;
    width: 100%;
    height: 48px;

    // border: 1px solid red;
    background: $menuBg;

    .horizontal-header-left {
      display: flex;
      align-items: center;
      width: auto;
      min-width: 200px;
      height: 100%;
      padding-left: 10px;
      cursor: pointer;
      transition: all var(--pure-transition-duration) ease;

      img {
        display: inline-block;
        height: 32px;
      }

      span {
        display: inline-block;
        height: 32px;
        margin: 2px 0 0 12px;
        overflow: hidden;
        font-size: 18px;
        font-weight: 600;
        line-height: 32px;
        color: $subMenuActiveText;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    .horizontal-header-menu {
      flex: 1;
      align-items: center;
      min-width: 0;
      height: 100%;
    }

    .horizontal-header-right {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      min-width: 340px;

      // color: $subMenuActiveText;
      color: $menuText;

      /* 搜索 */
      .search-container,
      /* 全屏 */
      .fullscreen-icon,
      /* 消息通知 */
      .dropdown-badge,
      /* 用户名 */
      .el-dropdown-link,
      /* 设置 */
      .set-icon {
        &:hover {
          // background: $menuHover;
          color: black;

          // background: $subMenuActiveText;
        }
      }

      .dropdown-badge {
        height: 48px;
        color: $subMenuActiveText;
      }

      .el-dropdown-link {
        display: flex;
        align-items: center;
        justify-content: space-around;
        height: 48px;
        padding: 10px;

        // color: $subMenuActiveText;
        color: #fff;
        cursor: pointer;

        p {
          font-size: 14px;
        }

        img {
          width: 22px;
          height: 22px;
          border-radius: 50%;
        }
      }
    }

    .el-menu {
      width: 100% !important;
      height: 100%;
      background-color: transparent;
      border: none;
    }

    // 菜单未选中时的颜色
    .el-menu-item,
    .el-sub-menu__title {
      // border: 1px solid red;

      padding-right: var(--el-menu-base-level-padding);
      font-size: 14px;

      // color: $menuText;
      // opacity: 0.8;
      font-weight: 500;
      line-height: 22px;
      color: #ffffffc5;
      letter-spacing: 0;

      // color: black;

      &:hover {
        // color: $menuTitleHover !important;
      }
    }

    .submenu-title-noDropdown,
    .el-sub-menu__title {
      height: 48px;
      line-height: 48px;
      background: $menuBg;

      svg {
        position: static !important;
      }
    }

    .is-active > .el-sub-menu__title,
    .is-active.submenu-title-noDropdown {
      color: $subMenuActiveText !important;

      i {
        color: $subMenuActiveText !important;
      }
    }

    // 选中字体颜色
    .is-active {
      font-size: 14px;
      font-weight: 500;
      line-height: 22px;
      color: #ffffffe6;
      letter-spacing: 0;

      // color: $subMenuActiveText !important;
      transition: color 0.3s;
    }
  }

  .el-menu--collapse .el-menu .el-sub-menu {
    min-width: $sideBarWidth !important;
  }

  /* 手机端 */
  .mobile {
    .fixed-header {
      width: 100% !important;
      transition: width var(--pure-transition-duration);
    }

    .main-container {
      margin-left: 0 !important;
    }

    .sidebar-container {
      width: $sideBarWidth;
      transition: transform var(--pure-transition-duration);
    }

    &.hideSidebar {
      .sidebar-container {
        pointer-events: none;
        transition-duration: 0.3s;
        transform: translate3d(-$sideBarWidth, 0, 0);
      }
    }
  }
}

body[layout="vertical"] {
  $sideBarWidth: 210px;

  @include merge-style($sideBarWidth);

  .el-menu--collapse {
    width: 54px;
  }

  .sidebar-logo-container {
    background: $sidebarLogo;
  }

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

    .sidebar-container {
      width: 54px !important;
      transition: width var(--pure-transition-duration);

      .is-active.submenu-title-noDropdown.outer-most {
        background: transparent !important;
      }
    }

    .main-container {
      margin-left: 54px;
    }

    /* 菜单折叠 */
    .el-menu--collapse {
      .el-sub-menu {
        & > .el-sub-menu__title {
          & > span {
            width: 100%;
            height: 100%;
            text-align: center;
            visibility: visible;
          }
        }
      }

      .submenu-title-noDropdown {
        background: transparent !important;
      }

      .el-sub-menu__title {
        padding: 0;
      }
    }

    .sub-menu-icon {
      margin-right: 0;
    }
  }

  /* 搜索 */
  .search-container,
  /* 全屏 */
  .fullscreen-icon,
  /* 消息通知 */
  .dropdown-badge,
  /* 用户名 */
  .el-dropdown-link,
  /* 设置 */
  .set-icon {
    &:hover {
      background: #f6f6f6;
    }
  }
}

body[layout="horizontal"] {
  $sideBarWidth: 0;

  @include merge-style($sideBarWidth);

  .fixed-header,
  .main-container {
    transition: none !important;
  }

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

body[layout="mix"] {
  $sideBarWidth: 210px;

  @include merge-style($sideBarWidth);

  .el-menu--collapse {
    width: 54px;
  }

  .el-menu {
    --el-menu-hover-bg-color: transparent !important;
  }

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

    .sidebar-container {
      width: 54px !important;
      transition: width var(--pure-transition-duration);

      .is-active.submenu-title-noDropdown.outer-most {
        background: transparent !important;
      }
    }

    .main-container {
      margin-left: 54px;
    }

    /* 菜单折叠 */
    .el-menu--collapse {
      .el-sub-menu {
        & > .el-sub-menu__title {
          padding: 0;

          & > span {
            width: 100%;
            height: 100%;
            text-align: center;
            visibility: visible;
          }
        }
      }
    }
  }
}
