@import "mixins/mixins";
@import "common/var";
@import "button";
@import "./popper";

@include b(dropdown) {
  display: inline-block;
  position: relative;
  color: $--color-text-regular;
  font-size: $--font-size-base;

  .el-button-group {
    display: block;

    .el-button {
      float: none;
    }
  }

  & .el-dropdown__caret-button {
    padding-left: 5px;
    padding-right: 5px;
    position: relative;
    border-left: none;

    &::before {
      $gap: 5px;

      content: "";
      position: absolute;
      display: block;
      width: 1px;
      top: $gap;
      bottom: $gap;
      left: 0;
      background: mix(white, transparent, 50%);
    }

    &.el-button--default::before {
      background: mix($--button-default-border-color, transparent, 50%);
    }

    &:hover {
      &:not(.is-disabled)::before {
        top: 0;
        bottom: 0;
      }
    }

    & .el-dropdown__icon {
      padding-left: 0;
    }
  }

  @include e(icon) {
    font-size: 14px;
    margin: 0 3px;
  }

  .el-dropdown-selfdefine {

    // 自定义
    &:focus:active,
    &:focus:not(.focusing) {
      outline-width: 0;
    }

    .bi-iconfont-chevron-down {
      font-size: 14px;
      margin-left: 8px;
    }
  }

  .el-dropdown--popper-btn-type {
    display: flex;
    align-items: center;
    height: 36px;
    border-radius: 4px;
    color: $--button-primary-font-color;
    background-color: $--button-primary-background-color;
    border-color: $--button-primary-border-color;
    cursor: pointer;

    div {

      &:first-child {
        padding: 8px 16px;
        border-right: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 4px;
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;

      }

      &:last-child {
        margin-left: 0;
        padding: 8px 9px;
        border-radius: 4px;
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;

        i {
          margin-left: 0;
        }
      }
    }

    &:hover,
    &:focus {
      div {
        background: mix($--color-white, $--button-primary-border-color, $--button-hover-tint-percent);
        color: $--button-primary-font-color;
      }
    }

    &:active {
      div {
        background: mix($--color-black, $--button-primary-border-color, $--button-active-shade-percent);
        color: $--button-primary-font-color;
        outline: none;
      }
    }
  }

  .el-dropdown--popper-btn-count {
    width: 42px;
    height: 24px;
    line-height: 24px;
    background-color: #F0F3FC;
    border-radius: 4px;
    text-align: center;
    color: #3F4249;
    cursor: pointer;
  }

  [disabled] {
    cursor: not-allowed;
    color: $--font-color-disabled-base;

    &.el-dropdown--popper-btn-type {
      cursor: not-allowed;

      div {

        &,
        &:hover,
        &:focus,
        &:active {
          color: $--color-white;
          background-color: mix($--button-primary-border-color, $--color-white);
        }
      }
    }
  }
}

@include b(dropdown-menu) {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  padding: 4px 0;
  margin: 6px 0;
  background-color: $--color-white;
  border: 1px solid $--border-color-lighter;
  border-radius: $--border-radius-base;
  box-shadow: $--dropdown-menu-box-shadow;
  border: 1px solid #DCDFE6;

  &.el-dropdown-menu--label {
    .el-dropdown-menu__item {
      line-height: 26px;
    }
  }

  .el-dropdown-menu-empty-text {
    margin: 10px 0;
    color: $--cascader-color-empty;
    list-style-type: none;

    .el-empty {
      padding-top: 28px;
      padding-bottom: 12px;

      .el-empty__image {
        width: 80px;
        height: 74px;
      }
    }
  }

  @include e(search) {
    list-style: none;
    padding: 16px 16px 0;
  }

  @include e(li) {
    list-style: none;
    line-height: 40px;
    padding: 0 12px;
    margin: 12px 16px 0px;
    font-size: $--font-size-base;
    color: $--color-text-regular;
    border-bottom: 1px solid $--border-color-lighter;

    cursor: pointer;
    outline: none;

    &:not(.is-disabled):hover,
    &:focus {
      // background-color: $--dropdown-menuItem-hover-fill;
      color: $--dropdown-menuItem-hover-color;
    }

    @include m(divided) {
      $divided-offset: 6px;

      position: relative;
      margin-top: $divided-offset;
      border-top: 1px solid $--border-color-lighter;

      &:before {
        content: "";
        height: $divided-offset;
        display: block;
        // margin: 0 -20px;
        background-color: $--color-white;
      }
    }

    @include when(disabled) {
      cursor: default;
      color: $--font-color-disabled-base;
      pointer-events: none;
    }

    @include when(selected) {
      color: $--dropdown-menuItem-hover-color;

      .bi-iconfont-check {
        position: absolute;
        line-height: 40px;
        right: 16px;
      }
    }
  }

  @include e(item) {
    display: flex;
    align-items: center;
    list-style: none;
    line-height: 36px;
    padding: 0 16px;
    margin: 0 4px;
    font-size: $--font-size-base;
    color: #2C4068;
    border-radius: 2px;
    cursor: pointer;
    outline: none;

    &:not(.is-disabled):hover,
    &:focus {
      background-color: $--dropdown-menuItem-hover-fill;
      // color: $--dropdown-menuItem-hover-color;
    }

    i {
      margin-right: 8px;
      color: $--color-primary;
    }

    @include m(divided) {
      $divided-offset: 6px;

      position: relative;
      margin-top: $divided-offset;
      border-top: 1px solid $--border-color-lighter;

      &:before {
        content: "";
        height: $divided-offset;
        display: block;
        // margin: 0 -20px;
        background-color: $--color-white;
      }
    }

    @include when(disabled) {
      cursor: default;
      color: $--font-color-disabled-base;
      pointer-events: none;
      cursor: not-allowed;
    }
  }

  @include m(medium) {
    padding: 6px 0;

    @include e(item) {
      line-height: 30px;
      padding: 0 17px;
      font-size: 14px;

      &.el-dropdown-menu__item--divided {
        $divided-offset: 6px;
        margin-top: $divided-offset;

        &:before {
          height: $divided-offset;
          margin: 0 -17px;
        }
      }
    }
  }

  @include m(small) {
    padding: 6px 0;

    @include e(item) {
      line-height: 27px;
      padding: 0 15px;
      font-size: 13px;

      &.el-dropdown-menu__item--divided {
        $divided-offset: 4px;
        margin-top: $divided-offset;

        &:before {
          height: $divided-offset;
          margin: 0 -15px;
        }
      }
    }
  }

  @include m(mini) {
    padding: 3px 0;

    @include e(item) {
      line-height: 24px;
      padding: 0 10px;
      font-size: 12px;

      &.el-dropdown-menu__item--divided {
        $divided-offset: 3px;
        margin-top: $divided-offset;

        &:before {
          height: $divided-offset;
          margin: 0 -10px;
        }
      }
    }
  }

  @include m(horizontal) {
    width: auto;
    max-width: 252px;
    padding: 0;

    &>div {
      display: flex;
      flex-flow: wrap;
    }

    li {
      position: relative;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 118px;
      height: 130px;
      padding: 0;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: $--color-text-regular;
      cursor: pointer;

      &:not(:last-of-type):nth-child(odd)::after {
        content: '';
        position: absolute;
        right: 0;
        width: 1px;
        height: 24px;
        border-radius: 3px;
        background-color: #DCDEE2;
      }

      &:not(.is-disabled):hover {
        background-color: transparent;
      }

      i {
        font-size: 32px;
        padding-bottom: 10px;
      }

      img {
        width: 32px;
        height: 32px;
        padding-bottom: 10px;
      }
    }
  }
}

@include b(dropdown-menu__is-search) {
  padding-bottom: 0;

  .el-input {
    width: calc(100% - 32px);
    height: 32px;
    line-height: 32px;
    margin: 0 16px;
    margin-top: 20px;

    .el-input__inner {
      width: 100%;
      height: 100%;
      border-radius: 4px;
    }

    i {
      line-height: 32px;
    }
  }

  .el-scrollbar__wrap {
    max-height: 274px;
  }

  .el-dropdown-menu__item {
    display: flex;
    align-items: center;
    position: relative;
    margin: 0 16px;
    margin-top: 10px;
    padding: 6px 18px 6px 12px;
    border-bottom: 1px solid #EEEFF3;

    &-highlight-text {
      color: $--color-primary;
    }

    &:last-child {
      border: none;
    }

    .el-dropdown-menu-i {
      width: 24px;
      height: 24px;
      line-height: 24px;
      margin-right: 12px;
      font-size: 24px;
    }

    .el-cascader-node__prefix {
      position: absolute;
      right: 0;
      left: unset;
      top: 50%;
      transform: translateY(-50%);
      margin: 0;
      font-size: 16px;
    }

    &.selected {
      color: $--color-primary;
    }
  }
}

@include b(dropdown-menu__is-remote-search) {
  .el-input {
    width: calc(100% - 24px);
    height: 32px;
    line-height: 32px;
    margin: 0 12px;
    margin-top: 4px;
    margin-bottom: 10px;

    .el-input__inner {
      width: 100%;
      height: 100%;
      border-radius: 4px;
    }

    i {
      line-height: 32px;
    }
  }

  .el-scrollbar__wrap {
    max-height: 274px;
  }

  .el-dropdown-menu__item {
    display: flex;
    align-items: center;
    height: 40px;
    line-height: 40px;
    position: relative;
    margin: 0;
    padding-right: 30px;

    .el-cascader-node__prefix {
      margin-right: 0;
    }

    &-highlight-text {
      color: $--color-primary;
    }

    &.selected {
      color: $--color-primary;
    }
  }
}