// 组件允许单个组件打包，因此默认引入公共基础样式

@import "../../base.less";

@import "./_var.less";

@import "./_mixin.less";

@import "../../mixins/_layout.less";

@import "../../mixins/_reset.less";

a.@{prefix}-menu__item {
  text-decoration: none;
  color: unset;

  &:hover,
  &:active {
    color: inherit;
  }
}

// head-menu
.@{prefix}-head-menu {
  .reset;

  position: relative;
  width: 100%;
  background-color: @menu-theme-light;

  &__inner {
    display: flex;
    height: @comp-size-xxxl;

    li + li {
      margin-left: @comp-margin-s;
    }

    .@{prefix}-menu {
      &:first-child {
        margin-left: @comp-margin-xxl;
      }
    }
  }

  .@{prefix}-menu__logo:not(:empty) {
    height: 100%;
    margin-right: @comp-margin-xxxl;
  }

  .@{prefix}-menu {
    flex: 1;
    display: flex;
    align-items: center;
    // overflow: auto hidden;
  }

  .@{prefix}-menu__operations {
    &:not(:empty) {
      position: relative;
      display: flex;
      align-items: center;
      height: var(--td-comp-size-xxxl);
      line-height: 64px;
      text-align: right;
      margin-right: @comp-margin-s;
      overflow: hidden;
    }

    &-icon {
      width: @head-menu-item-height;
      height: @head-menu-item-height;
      padding: @comp-paddingTB-s @comp-paddingLR-s;
      line-height: @head-menu-item-height;
      box-sizing: border-box;
    }
  }

  .@{prefix}-submenu {
    > .@{prefix}-menu__item {
      overflow: unset;

      &::before {
        content: "";
        display: block;
        position: absolute;
        bottom: -20px;
        left: 0;
        right: 0;
        height: 20px;
      }
    }
  }

  .@{prefix}-menu__item {
    height: @head-menu-item-height;
    line-height: @head-menu-item-height;
    padding: 0 @comp-paddingLR-l;
    justify-content: center;
    transition: all @anim-duration-slow cubic-bezier(.645, .045, .355, 1);
  }

  &__submenu {
    border-top: 1px solid @head-menu-submenu-border-color;
    padding-left: 0;
  }

  .@{prefix}-menu__popup {
    top: calc(@head-menu-item-height + 12px);
    left: 0;
    min-width: 100%;
    box-sizing: content-box;
    transform-origin: center top;
    border: solid .5px @menu-border-color;

    .@{prefix}-menu__item {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      white-space: nowrap;
      padding-left: @comp-paddingLR-s;
      padding-right: @comp-paddingLR-s;
      min-width: 100%;
      margin-left: 0;
      color: @head-menu-popup-item-color;
      box-sizing: border-box;

      &.@{prefix}-is-active {
        color: @menu-light-active-color;

        .l-icon {
          color: @menu-light-active-color;
        }
      }
    }

    li + li {
      margin-top: @comp-margin-xxs;
      margin-left: 0;
    }
  }

  .@{prefix}-fake-arrow {
    margin-left: @comp-margin-m;
  }

  // 多层情况
  .@{prefix}-menu__popup-inner {
    .@{prefix}-menu__popup {
      top: -8px;
      left: calc(100% + 16px);
      transform-origin: left top;
    }

    .@{prefix}-menu__item {
      text-align: left;
      padding: 0 16px;
      justify-content: space-between;
    }

    .@{prefix}-submenu-icon {
      transform: rotate(270deg);
    }
  }
}

// default-menu
.@{prefix}-default-menu {
  .reset;

  position: relative;
  width: @default-menu-width;
  display: inline-block;
  background: @menu-theme-light;
  transition: width @anim-duration-slow cubic-bezier(.645, .045, .355, 1);
  white-space: nowrap;

  .@{prefix}-menu__item {
    color: @default-menu-item-color--light;
  }

  &.@{prefix}-is-collapsed {
    width: @default-menu-collapse-width;

    .@{prefix}-menu {
      .@{prefix}-menu__item {
        padding: 0 14px;
        justify-content: center;
        .@{prefix}-menu__item-link {
          display: none;
        }
      }
    }

    .@{prefix}-fake-arrow {
      display: none;
    }

    .@{prefix}-menu__item {
      text-overflow: initial;

      &.@{prefix}-is-active.@{prefix}-is-opened {
        color: @default-menu-active-color;
        background-color: @menu-item-active-bg--light;

        .l-icon {
          color: @default-menu-active-color;
        }
      }

      &.@{prefix}-menu__item--plain::after {
        content: "";
      }

      span {
        display: none;
      }

      .l-icon {
        margin-right: initial;
      }
    }

    .@{prefix}-menu__popup {
      .@{prefix}-menu__item {
        padding-left: @comp-paddingLR-s;
        padding-right: @comp-paddingLR-s;
        justify-content: flex-start;

        span {
          display: inline;
        }

        &.@{prefix}-menu__item--plain::after {
          content: "";
        }
      }

      .@{prefix}-fake-arrow {
        display: block;
      }
    }

    .@{prefix}-submenu {
      &-icon {
        display: none;
      }

      .@{prefix}-menu__popup {
        .@{prefix}-submenu-icon {
          display: initial;
        }
      }

      > .@{prefix}-menu__item {
        min-width: initial;

        &::after {
          content: "";
          display: block;
          position: absolute;
          right: -20px;
          top: 0;
          bottom: 0;
          width: 20px;
        }
      }
    }

    .@{prefix}-menu-group__title {
      padding: 0;
      font-size: 0;

      &::after {
        content: "";
        display: block;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        height: 1px;
        width: 20px;
        background: @menu-group-title-bg--collapse;
      }
    }

    .@{prefix}-menu__operations {
      text-align: center;

      &-icon {
        display: block;
      }
    }
  }

  &__inner {
    display: flex;
    flex-direction: column;
    height: 100%;

    .@{prefix}-menu__logo:not(:empty) {
      box-sizing: border-box;
      width: 100%;
      height: @menu-height-default;
      border-bottom: 1px solid @menu-border-color;
    }

    .@{prefix}-menu {
      padding: @comp-paddingTB-l @comp-paddingLR-s;
      position: relative;
      // overflow: hidden auto;
      flex: 1;

      &--scroll {
        overflow-y: auto;
      }
    }

    .@{prefix}-menu-group {
      &__title {
        position: relative;
        padding: @comp-paddingTB-l @comp-paddingLR-l @comp-paddingTB-xs @comp-paddingLR-l;
        color: @menu-menu-group-title-color;
        font-size: @menu-extra-font-size;
        box-sizing: border-box;
      }
    }
  }

  .@{prefix}-submenu {
    margin-bottom: @comp-margin-xs;
    position: relative;
  }

  .@{prefix}-menu__operations {
    &:not(:empty) {
      width: 100%;
      position: relative;
      padding: @comp-paddingTB-s @comp-paddingLR-l;
      top: 0;
      left: 0;
      text-align: left;
      border-top: solid 1px @menu-border-color;
      box-sizing: border-box;
    }

    &-icon {
      width: 32px;
      height: 32px;
      padding: @comp-paddingTB-s @comp-paddingLR-s;
      cursor: pointer;
      color: @menu-operations-color;
      box-sizing: border-box;
    }
  }

  .@{prefix}-menu__item {
    &.@{prefix}-is-opened {
      margin: @comp-margin-xs 0;
      color: @menu-color-light;
      background-color: unset;

      .l-icon {
        color: @menu-color-light;
      }
    }
  }

  .@{prefix}-menu__sub {
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height @anim-duration-base @anim-time-fn-easing;

    &.@{prefix}-is-opened {
      max-height: calc(100vh - @menu-height-default * 2);
    }

    .@{prefix}-menu__item {
      padding-left: var(--padding-left, 32px);
    }
  }

  .@{prefix}-menu__item {
    position: relative;
    margin: @comp-margin-xs 0;
    padding: 0 10px 0 16px;
    height: @default-menu-item-height;
    line-height: @default-menu-item-height;
    border-bottom: 0;
    text-align: left;
    border-radius: @border-radius-default;
    transition: background-color @anim-duration-slow @anim-time-fn-easing,
      padding @anim-duration-slow @anim-time-fn-easing;
    box-sizing: border-box;

    &:first-child {
      margin-top: 0;
    }

    &:last-child {
      margin-bottom: 0;
    }

    .l-icon {
      width: 20px;
      height: 20px;
    }

    .@{prefix}-fake-arrow {
      margin-left: auto;
      min-width: 16px;
    }

    &.@{prefix}-is-active:not(.@{prefix}-is-opened) {
      color: @default-menu-active-color;
      background-color: @menu-item-active-bg--light;

      .l-icon {
        color: @default-menu-active-color;
      }
    }

    &:hover:not(.@{prefix}-is-active):not(.@{prefix}-is-disabled) {
      background: @menu-light-active-bg;
    }
  }

  .@{prefix}-menu__popup {
    top: 0;
    left: calc(100% + @pop-padding-m);

    .@{prefix}-menu__item, .@{prefix}-submenu {
      margin: @comp-margin-xxs 0 0 0;

      &:first-child {
        margin-top: 0;
      }
    }
  }

  &.@{prefix}-menu--dark {
    background: @menu-theme-dark;

    .@{prefix}-menu__item {
      color: @default-menu-item-color--dark;
    }

    .@{prefix}-menu__logo:not(:empty) {
      border-bottom-color: @menu-border-color--dark;
    }

    .@{prefix}-menu__operations:not(:empty) {
      border-top-color: @menu-border-color--dark;
    }

    .@{prefix}-menu__item {
      &:hover:not(.@{prefix}-is-active):not(.@{prefix}-is-disabled) {
        background-color: @menu-border-color--dark;
      }

      &.@{prefix}-is-active:not(.@{prefix}-is-opened) {
        color: @menu-item-active-color--dark;
        background-color: @default-menu-active-color--dark;

        .l-icon {
          color: @menu-item-active-color--dark;
        }
      }

      &.@{prefix}-is-opened.@{prefix}-is-active {
        background-color: transparent;
      }
    }

    .@{prefix}-menu__popup {
      background: @menu-theme-dark;

      .@{prefix}-menu__item {
        &.@{prefix}-is-active {
          background-color: @default-menu-active-color--dark;
        }
      }
    }

    .@{prefix}-menu__popup {
      background: @menu-theme-dark;
    }

    .@{prefix}-menu-group__title {
      color: @menu-menu-group-title-color--dark;
    }

    &.@{prefix}-is-collapsed {
      .@{prefix}-menu-group__title:after {
        background-color: @menu-group-title-bg--collapse--dark;
      }

      .@{prefix}-menu__item {

        &.@{prefix}-is-active.@{prefix}-is-opened {
          background-color: @default-menu-active-color--dark;
          color: @menu-item-active-color--dark;

          .l-icon {
            color: @menu-item-active-color--dark;
          }
        }
      }
    }
  }
}

// menu
.@{prefix}-menu {
  color: @menu-color-light;
  font: @menu-font-size;
  .list-style-none();

  &--dark {
    color: @menu-color-dark;
  }

  &__logo {
    &:not(:empty) {
      display: flex;
      align-items: center;
    }
  }

  .@{prefix}-submenu {
    position: relative;

    &.@{prefix}-is-active {
      > .@{prefix}-menu__item {
        color: @menu-theme-dark;

        .l-icon {
          color: @menu-theme-dark;
        }
      }
    }

    .@{prefix}-submenu-icon {
      width: 16px;
      height: 16px;
    }

    &.@{prefix}-is-opened {
      & .@{prefix}-submenu-icon {
        transform: scaleY(-1);
      }
    }
  }

  &::-webkit-scrollbar {
    display: none;
  }

  &__spacer {
    &::before {
      content: "";
      display: block;
      position: absolute;
      z-index: 1;
    }

    @horizontal-spacer: 16px;

    &--left::before {
      left: -@horizontal-spacer;
      width: @horizontal-spacer;
      top: 0;
      bottom: 0;
    }

    &--top::before {
      top: -20px;
      left: 0;
      right: 0;
      height: 20px;
    }
  }

  &__item {
    position: relative;
    display: flex;
    align-items: center;
    height: 40px;
    line-height: 40px;
    text-align: center;
    color: @menu-item-color--light;
    cursor: pointer;
    // overflow: hidden;
    text-overflow: ellipsis;
    border-radius: @border-radius-default;

    ::selection {
      background: transparent;
    }

    &-spacer {
      overflow: unset;

      &::before {
        content: "";
        display: block;
        position: absolute;
        z-index: 1;
      }

      @horizontal-spacer: 16px;

      &--right::before {
        right: -@horizontal-spacer;
        width: @horizontal-spacer;
        top: 0;
        bottom: 0;
      }

      &--bottom::before {
        bottom: -20px;
        left: 0;
        right: 0;
        height: 20px;
      }
    }

    a {
      color: unset;
      text-decoration: none;

      &.@{prefix}-menu__item-link {
        color: unset;
        flex: 1;
      }
    }

    &.@{prefix}-is-active {
      color: @menu-item-active-color--light;
      background-color: @menu-item-active-bg--light;
    }

    &.@{prefix}-is-opened {
      color: @menu-item-active-color--light;
    }

    &:hover:not(.@{prefix}-is-active):not(.@{prefix}-is-opened):not(.@{prefix}-is-disabled) {
      background-color: @menu-item-hover-bg--light;
    }

    &.@{prefix}-is-disabled {
      color: @menu-item-disabled-color;
      cursor: not-allowed;
    }

    --ripple-color: @menu-item-animation-bg--light;
  }

  &__content {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .l-icon + &__content,
  .l-icon + &__item-link {
    margin-left: @comp-margin-s;
  }

  &--dark {
    &.@{prefix}-head-menu {
      background-color: @menu-theme-dark;

      .@{prefix}-menu__popup {
        background-color: @menu-theme-dark;
        border: solid .5px @menu-border-color--dark;
      }
    }

    .@{prefix}-menu__item {
      color: @menu-item-color--dark;

      &.@{prefix}-is-active {
        color: @menu-item-active-color--dark;
        background-color: @menu-item-active-bg--dark;
      }

      &.@{prefix}-is-opened {
        color: @menu-item-active-color--dark;

        .l-icon {
          color: @menu-item-active-color--dark;
        }
      }

      &.@{prefix}-is-disabled {
        color: @menu-item-disabled-color-dark;
      }

      &:hover:not(.@{prefix}-is-active):not(.@{prefix}-is-opened):not(.@{prefix}-is-disabled) {
        background-color: @menu-item-hover-bg--dark;
      }

      --ripple-color: @menu-item-animation-bg--dark;
    }

    .@{prefix}-menu__popup {
      background: @menu-theme-dark;

      .@{prefix}-menu__item {
        color: @menu-item-color--dark;
        border-radius: @border-radius-default;

        &.@{prefix}-is-active {
          color: @menu-item-active-color--dark;
          background-color: @menu-item-active-bg--dark;
        }

        &:hover:not(.@{prefix}-is-active) {
          background-color: @menu-item-hover-bg--dark;
        }
      }
    }

    .@{prefix}-head-menu__submenu {
      border-top: 1px solid transparent;
    }

    .@{prefix}-menu__operations {
      &-icon {
        color: @menu-theme-light;

        &:hover {
          background-color: @menu-item-active-bg--dark;
        }
      }
    }
  }

  &__popup {
    max-height: 0;
    overflow: hidden;
    transition: max-height @anim-duration-moderate @anim-time-fn-easing,
      width @anim-duration-moderate @anim-time-fn-easing,
      opacity @anim-duration-base linear;
    position: absolute;
    background: @menu-theme-light;
    z-index: @menu-outer-zindex;
    border-radius: @border-radius-medium;
    opacity: 0;
    .list-style-none();

    // 超过 2 级的弹出菜单，不需要动画
    .@{prefix}-menu__popup {
      transition: none;
    }

    &-wrapper {
      padding: @pop-padding-m;
      height: 100%;
      list-style: none;
      margin: 0;
    }

    .@{prefix}-fake-arrow {
      margin-left: @comp-margin-s;
    }

    &.@{prefix}-is-vertical {
      max-height: unset;
      width: 0;

      &.@{prefix}-is-opened {
        width: var(--popup-width, 160px);
      }

      .@{prefix}-menu__item {
        padding-left: @comp-paddingLR-l;
        padding-right: @comp-paddingLR-l;
      }
    }

    &.@{prefix}-is-horizontal {
      .@{prefix}-menu__item {
        padding-left: @comp-paddingLR-l;
        padding-right: @comp-paddingLR-l;
        white-space: nowrap;
      }

      li + li {
        margin-top: @comp-margin-xs;
      }
    }

    &.@{prefix}-is-opened {
      max-height: calc(100vh - @menu-height-default * 2);
      opacity: 1;
      box-shadow: @menu-default-shadow;
      overflow: visible;

      .@{prefix}-menu__popup {
        top: calc(0px - @pop-padding-m);
        left: 100%;
        overflow-x: hidden;
        overflow-y: auto;

        &::before {
          content: "";
          display: block;
          position: absolute;
          left: -@horizontal-spacer;
          width: @horizontal-spacer;
          top: 0;
          bottom: 0;
        }
        @horizontal-spacer: 16px;
      }
    }

    .@{prefix}-menu__item {
      color: @menu-popup-item-color;
      height: @comp-size-s;
      line-height: @comp-size-s;

      + .@{prefix}-menu__item {
        margin-left: 0;
      }

      &:hover:not(.@{prefix}-is-active) {
        background-color: @menu-popup-item-hover-bg;
      }
    }
  }

  &__operations {
    &-icon {
      margin-right: @comp-margin-l;
      border-radius: @border-radius-default;
      color: @menu-item-color--light;
      transition: background-color @anim-duration-moderate @anim-time-fn-easing;

      &:hover {
        background-color: @menu-item-active-bg--light;
      }
    }
  }
}

// opacity-transition
.@{prefix}-opacity-transition {
  transition: opacity @anim-duration-slow cubic-bezier(.55, 0, .1, 1);
}

.horizontal-collapse-transition
.@{prefix}-submenu__title
.@{prefix}-submenu__icon-arrow {
  transition: @anim-duration-base;
  opacity: 0;
}

.@{prefix}-menu__popup {
  top: 0;
  left: calc(100% - @pop-padding-m);

  .@{prefix}-menu__item, .@{prefix}-submenu {
    margin: @comp-margin-xxs 0 0 0;

    &:first-child {
      margin-top: 0;
    }
  }
}
