@import '../../style/index';
@import './mixin.less';
@import './base.less';

@menu-prefix-cls: ~'@{klein-prefix}-menu';
@iconfont-css-prefix: ~'@{klein-prefix}-icon';

.@{menu-prefix-cls} {
  .reset-component();
  margin-bottom: 0;
  padding-left: 0; // Override default ul/ol
  color: @menu-item-color;
  font-size: @menu-item-font-size;
  line-height: 0; // Fix display inline-block gap
  text-align: left;
  list-style: none;
  background: @menu-bg;
  outline: none;
  box-shadow: @box-shadow-basic;
  transition: background 0.3s, width 0.3s cubic-bezier(0.2, 0, 0, 1) 0s;
  .clearfix();

  ul,
  ol {
    // margin: 0;
    padding: 0;
    list-style: none;
  }

  &-hidden {
    display: none;
  }

  &-item-group-title {
    padding: 9px 14px 9px 12px;
    color: @menu-item-group-title-color;
    font-size: @menu-item-group-title-font-size;
    line-height: @menu-item-group-height;
    transition: all 0.3s;
  }

  &-horizontal &-submenu {
    transition: border-color 0.3s @ease-in-out, background 0.3s @ease-in-out;
  }

  &-submenu,
  &-submenu-inline {
    transition: border-color 0.3s @ease-in-out, background 0.3s @ease-in-out,
      padding 0.15s @ease-in-out;
  }

  &-submenu-selected {
    color: @menu-highlight-color;
  }

  &-item:active,
  &-submenu-title:active {
    background: @menu-item-active-bg;
  }

  &-submenu &-sub {
    cursor: initial;
    transition: background 0.3s @ease-in-out, padding 0.3s @ease-in-out;
  }

  &-item a {
    color: @menu-item-color;
    text-decoration: none;
    // margin-top: -3px; // by weimob
    // display: inline-block; // by weimob
    // vertical-align: top; // by weimob

    &:hover {
      color: @menu-highlight-color;
    }

    &::before {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: transparent;
      content: '';
    }
  }

  &-item > .@{klein-prefix}-badge a {
    color: @menu-item-color;

    &:hover {
      color: @menu-highlight-color;
    }
  }

  &-item-divider {
    height: 1px;
    overflow: hidden;
    line-height: 0;
    background-color: @border-color-split;
  }

  &-item:hover,
  &-item-active,
  &:not(&-inline) &-submenu-open,
  &-submenu-active,
  &-submenu-title:hover {
    color: @menu-highlight-color;
  }

  &-horizontal &-item,
  &-horizontal &-submenu {
    margin-top: -1px;
  }

  &-horizontal > &-item:hover,
  &-horizontal > &-item-active,
  &-horizontal > &-submenu &-submenu-title:hover {
    background-color: transparent;
  }

  &-item-selected {
    color: @menu-highlight-color;

    a,
    a:hover {
      color: @menu-highlight-color;
    }
  }

  &:not(&-horizontal) &-item-selected {
    background-color: @menu-item-active-bg;
  }

  &-inline,
  &-vertical,
  &-vertical-left {
    padding: 4px 0;
    // border-right: @border-width-base @border-style-base @border-color-split;
  }

  &-vertical-right {
    border-left: @border-width-base @border-style-base @border-color-split;
  }

  &-vertical&-sub,
  &-vertical-left&-sub,
  &-vertical-right&-sub {
    max-height: calc(100vh - 100px);
    padding: 0;
    padding: 4px 0;
    overflow: hidden;
    border-right: 0;

    &:not([class*='-active']) {
      overflow-x: hidden;
      overflow-y: auto;
    }

    .@{menu-prefix-cls}-item {
      left: 0;
      margin-left: 0;
      border-right: 0;

      &::after {
        border-right: 0;
      }
    }

    > .@{menu-prefix-cls}-item,
    > .@{menu-prefix-cls}-submenu {
      transform-origin: 0 0;
    }
  }

  &-horizontal&-sub {
    min-width: 114px; // in case of submenu width is too big: https://codesandbox.io/s/qvpwm6mk66
  }

  &-horizontal &-item,
  &-horizontal &-submenu-title {
    transition: border-color 0.3s, background 0.3s;
  }

  &-item,
  &-submenu-title {
    position: relative;
    display: block;
    margin: 0;
    padding: @menu-item-padding;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 0.3s, background 0.3s, padding 0.15s @ease-in-out;

    .@{menu-prefix-cls}-item-icon,
    .@{iconfont-css-prefix}:not(.@{menu-prefix-cls}-submenu-arrowicon) {
      position: relative; // by weimob
      top: 2px; // by weimob
      min-width: 14px;
      margin-right: @menu-icon-margin-right;
      font-size: @font-size-lg;
      transition: font-size 0.15s @ease-out, margin 0.3s @ease-in-out,
        color 0.3s;

      + span {
        display: inline-block;
        vertical-align: top;
        opacity: 1;
        transition: opacity 0.3s @ease-in-out, width 0.3s @ease-in-out,
          color 0.3s;
        // margin-top: -2px;
      }
    }

    // by weimob /* --- */
    // .@{klein-prefix}-icon-customLine,
    .@{iconfont-css-prefix}:not(.@{menu-prefix-cls}-submenu-arrowicon) {
      top: 0; // by weimob
      min-width: 14px;
      margin-right: @menu-icon-margin-right;
      font-size: @font-size-lg;
      transition: font-size 0.15s @ease-out, margin 0.3s @ease-in-out,
        color 0.3s;

      + span {
        display: inline-block;
        vertical-align: top;
        opacity: 1;
        transition: opacity 0.3s @ease-in-out, width 0.3s @ease-in-out,
          color 0.3s;
      }
    }

    /* --- */

    &.@{menu-prefix-cls}-item-only-child {
      margin-top: @menu-item-vertical-margin;

      > .@{iconfont-css-prefix}:not(.@{menu-prefix-cls}-submenu-arrowicon),
      > .@{menu-prefix-cls}-item-icon {
        margin-right: 0;
      }
    }

    &.@{menu-prefix-cls}-item-only-child:first-child {
      margin-top: 0;
    }
  }

  & > &-item-divider {
    height: 1px;
    margin: 1px 0;
    padding: 0;
    overflow: hidden;
    line-height: 0;
    background-color: @border-color-split;
  }

  &-submenu {
    &-vertical {
      margin-top: @menu-item-vertical-margin;
    }

    &-vertical:first-child {
      margin-top: @menu-item-vertical-margin / 2;
    }

    &-vertical:last-child {
      // margin-bottom: @menu-item-vertical-margin/2;
    }

    &-popup {
      position: absolute;
      z-index: @zindex-dropdown;
      padding: 2px 0;
      background: transparent;
      border-radius: @border-radius-basic;
      box-shadow: none;
      transform-origin: 0 0;

      &::before {
        position: absolute;
        top: -7px;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: -1;
        width: 100%;
        height: 100%;
        opacity: 0.0001;
        content: ' ';
      }
    }

    &-placement-rightTop::before {
      top: 0;
      left: -7px;
    }

    > .@{menu-prefix-cls} {
      background-color: @menu-bg;
      // border-radius: @border-radius-basic;

      &-submenu-title::after {
        transition: transform 0.3s @ease-in-out;
      }
    }

    &-popup > .@{menu-prefix-cls} {
      background-color: @menu-popup-bg;
    }

    &-expand-icon,
    &-arrow {
      position: absolute;
      top: 50%;
      right: 16px;
      display: none;
      width: 10px;
      color: @menu-item-color;
      transform: translateY(-50%);
      transition: transform 0.3s @ease-in-out;
    }

    &-arrowicon {
      position: absolute;
      top: 50%;
      right: 16px;
      width: 16px;
      color: @menu-item-color;
      transform: translateY(-50%);
      transition: transform 0.3s @ease-in-out;
    }

    &:hover > &-title > &-expand-icon,
    &:hover > &-title > &-arrowicon {
      color: @menu-highlight-color;
    }

    &-horizontal &-arrowicon {
      display: none;
    }

    &-open&-inline > &-title > &-arrowicon {
      transform: rotate(180deg) translateY(50%);
    }
  }

  &-vertical &-submenu-selected,
  &-vertical-left &-submenu-selected,
  &-vertical-right &-submenu-selected {
    color: @menu-highlight-color;
  }

  &-horizontal {
    line-height: @menu-horizontal-line-height;
    border: 0;
    border-bottom: @border-width-base @border-style-base @border-color-split;
    box-shadow: none;

    &:not(.@{menu-prefix-cls}-dark) {
      > .@{menu-prefix-cls}-item,
      > .@{menu-prefix-cls}-submenu {
        margin: @menu-item-padding;
        margin-bottom: 0;
        padding: @menu-item-padding;
        padding-right: 0;
        padding-left: 0;

        &:hover,
        &-active,
        &-open,
        &-selected {
          color: @menu-highlight-color;
          border-bottom: 2px solid @menu-highlight-color;
        }
      }
    }

    > .@{menu-prefix-cls}-item,
    > .@{menu-prefix-cls}-submenu {
      position: relative;
      top: 1px;
      display: inline-block;
      vertical-align: bottom;
      border-bottom: 2px solid transparent;
    }

    > .@{menu-prefix-cls}-submenu > .@{menu-prefix-cls}-submenu-title {
      padding: 0;
    }

    > .@{menu-prefix-cls}-item {
      a {
        color: @menu-item-color;

        &:hover {
          color: @menu-highlight-color;
        }

        &::before {
          bottom: -2px;
        }
      }

      &-selected a {
        color: @menu-highlight-color;
      }
    }

    &::after {
      display: block;
      clear: both;
      height: 0;
      content: '\20';
    }
  }

  &-vertical,
  &-vertical-left,
  &-vertical-right,
  &-inline {
    .@{menu-prefix-cls}-item {
      position: relative;

      &::after {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        border-right: @menu-item-active-border-width solid @menu-highlight-color;
        transform: scaleY(0.0001);
        opacity: 0;
        transition: transform 0.15s @ease-out, opacity 0.15s @ease-out;
        content: '';
      }
    }

    .@{menu-prefix-cls}-item,
    .@{menu-prefix-cls}-submenu-title {
      height: @menu-item-height;
      // margin-top: @menu-item-vertical-margin;
      // margin-bottom: @menu-item-vertical-margin;
      padding: 0 24px;
      overflow: hidden;
      line-height: @menu-item-height;
      text-overflow: ellipsis;
    }

    .@{menu-prefix-cls}-item-group {
      margin-top: 8px;
    }

    // disable margin collapsed
    // .@{menu-prefix-cls}-submenu {
    //   padding-bottom: 0.02px;
    // }

    .@{menu-prefix-cls}-item:not(:last-child) {
      // margin-bottom: @menu-item-boundary-margin;
    }

    > .@{menu-prefix-cls}-item,
    > .@{menu-prefix-cls}-submenu > .@{menu-prefix-cls}-submenu-title {
      height: @menu-inline-toplevel-item-height;
      line-height: @menu-inline-toplevel-item-height;
    }
  }

  // ----------------------------------------------------
  &-vertical {
    .@{menu-prefix-cls}-item-group:not(:first-child) {
      margin-top: 4px;
    }

    .@{menu-prefix-cls}-submenu-title {
      padding-right: 34px;

      .@{menu-prefix-cls}-submenu-arrowicon {
        transform: rotate(-90deg);
      }
    }
  }

  &-inline {
    width: 100%;

    .@{menu-prefix-cls}-submenu-inline:not(:first-child) {
      margin-top: 8px;
    }

    .@{menu-prefix-cls}-selected,
    .@{menu-prefix-cls}-item-selected {
      &::after {
        transform: scaleY(1);
        opacity: 1;
        transition: transform 0.15s @ease-in-out, opacity 0.15s @ease-in-out;
      }
    }

    .@{menu-prefix-cls}-item,
    .@{menu-prefix-cls}-submenu-title {
      width: ~'calc(100% + 1px)';
    }

    .@{menu-prefix-cls}-submenu-title {
      padding-right: 44px;

      // by weimob
      .@{iconfont-css-prefix}:not(.@{menu-prefix-cls}-submenu-arrowicon) {
        margin-right: 12px;
      }
    }

    .@{menu-prefix-cls}-item-only-child {
      // background: #ccc;
      margin-bottom: 4px;
    }
  }

  // &-inline-collapsed {
  //   width: @menu-collapsed-width;

  //   >.@{menu-prefix-cls}-item,
  //   >.@{menu-prefix-cls}-item-group>.@{menu-prefix-cls}-item-group-list>.@{menu-prefix-cls}-item,
  //   >.@{menu-prefix-cls}-item-group>.@{menu-prefix-cls}-item-group-list>.@{menu-prefix-cls}-submenu>.@{menu-prefix-cls}-submenu-title,
  //   >.@{menu-prefix-cls}-submenu>.@{menu-prefix-cls}-submenu-title {
  //     left: 0;
  //     padding:~'calc(50% - @{menu-icon-size-lg} / 2)';
  //     text-overflow: clip;

  //     .@{menu-prefix-cls}-submenu-arrow {
  //       display: none;
  //     }

  //     .@{menu-prefix-cls}-item-icon,
  //     .@{iconfont-css-prefix} {
  //       margin: 0;
  //       font-size: @menu-icon-size-lg;
  //       line-height: @menu-item-height;

  //       +span {
  //         display: inline-block;
  //         max-width: 0;
  //         opacity: 0;
  //       }
  //     }
  //   }

  //   .@{menu-prefix-cls}-item-icon,
  //   .@{iconfont-css-prefix} {
  //     display: inline-block;
  //   }

  //   &-tooltip {
  //     pointer-events: none;

  //     .@{menu-prefix-cls}-item-icon,
  //     .@{iconfont-css-prefix} {
  //       display: none;
  //     }

  //     a {
  //       color: @text-color-dark;
  //     }
  //   }

  //   .@{menu-prefix-cls}-item-group-title {
  //     padding-right: 4px;
  //     padding-left: 4px;
  //     overflow: hidden;
  //     white-space: nowrap;
  //     text-overflow: ellipsis;
  //   }
  // }

  &-item-group-list {
    margin: 8px 0 0 0;
    padding: 0;

    .@{menu-prefix-cls}-item,
    .@{menu-prefix-cls}-submenu-title {
      padding: 0 24px;
    }
  }

  &-root&-vertical,
  &-root&-vertical-left,
  &-root&-vertical-right,
  &-root&-inline {
    box-shadow: none;
  }

  &-root&-inline-collapsed {
    .@{menu-prefix-cls}-item,
    .@{menu-prefix-cls}-submenu .@{menu-prefix-cls}-submenu-title {
      > .@{menu-prefix-cls}-inline-collapsed-noicon {
        font-size: @menu-icon-size-lg;
        text-align: center;
      }
    }
  }

  &-sub&-inline {
    padding-top: 4px;
    background: @menu-inline-submenu-bg;
    border: 0;
    border-radius: 0;
    box-shadow: none;

    & > .@{menu-prefix-cls}-item,
    & > .@{menu-prefix-cls}-submenu > .@{menu-prefix-cls}-submenu-title {
      height: @menu-item-height;
      margin-bottom: 4px;
      line-height: @menu-item-height;
      list-style-position: inside;
      list-style-type: disc;
    }

    & .@{menu-prefix-cls}-item-group-title {
      padding-right: 24px;
      padding-left: 40px;
    }
  }

  // Disabled state sets text to gray and nukes hover/tab effects
  &-item-disabled,
  &-submenu-disabled {
    color: @disable-color !important;
    background: none;
    border-color: transparent !important;
    cursor: not-allowed;

    a {
      color: @disable-color !important;
      pointer-events: none;
    }

    > .@{menu-prefix-cls}-submenu-title {
      color: @disable-color !important;
      cursor: not-allowed;

      > .@{menu-prefix-cls}-submenu-arrow {
        &::before,
        &::after {
          background: @disable-color !important;
        }
      }
    }
  }
}

.@{menu-prefix-cls}-submenu-placement-bottomLeft {
  > .@{menu-prefix-cls}-sub {
    padding: 0;

    .@{menu-prefix-cls}-item-icon {
      margin-right: 12px;
    }

    > .@{menu-prefix-cls}-item-only-child {
      margin-top: 0;
    }
  }
}

@import './dark';
