@import "mixins/mixins";
@import "common/var";
@import "common/transition";
@import "checkbox";

@include b(tree) {
  position: relative;
  cursor: default;
  background: $--color-white;
  color: $--color-text-1;

  @include e(empty-block) {
    position: relative;
    line-height: 22px;
    color: $--select-dropdown-empty-color;
    font-size: $--select-font-size;
    padding: $--select-dropdown-empty-padding;
    margin: 0;
    text-align: center;
  }

  @include e(empty-text) {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: $--color-text-2;
    font-size: $--font-size-body-3;
    width: 100%;
  }

  @include e(drop-indicator) {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background-color: $--primary-6;
  }

  @include e(icon) {
    display: inline-block;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    line-height: 16px;
    font-size: $--font-size-title-1;
    text-align: center;
    padding: 4px;
  }


  .is-current > .el-tree-node-is-leaf  .el-tree-node__wrap:not(.is-disabled) {
    .el-tree-node__label {
      color: $--primary-6;
    }
    .el-checkbox + .el-tree-node__label {
      color: $--color-text-1;
    }
  }
  .is-current > .el-tree-node__content:not(.el-tree-node__children) .el-tree-node__wrap:not(.is-disabled) {
    .el-tree-node__label {
      color: $--primary-6;
    }
    .el-checkbox + .el-tree-node__label {
      color: $--color-text-1;
    }
  }
}

@include b(tree-node) {
  white-space: nowrap;
  outline: none;

  @include when(drop-inner) {
    > .el-tree-node__content .el-tree-node__label {
      background-color: $--primary-6;
      color: #fff;
    }
  }

  @include e(content) {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 10px 0;

    & > .el-tree-node__expand-icon {
      padding: 1px;
      margin-right: 5px;
    }
    & > label.el-checkbox {
      margin-right: 8px;
    }
    .el-tree-node-indent {
      position: relative;
      flex-shrink: 0;
      align-self: stretch;
      &-block {
        position: relative;
        display: inline-block;
        width: 4px;
        height: 100%;

        &::after {
          position: absolute;
          right: -7px;
          box-sizing: border-box;
          width: 1px;
          border-left: $--border-1 solid $--border-color-base;
          transform: translate(50%);
          content: "";
          top: 0;
          bottom: 0;
        }
      }

      &-block-lineless:after {
        display: none
      }
    }

    .el-tree.is-dragging & {
      cursor: move;

      & * {
        pointer-events: none;
      }
    }

    .el-tree.is-dragging.is-drop-not-allow & {
      cursor: not-allowed;
    }
    &.el-tree-node__content_disabled:hover {
      background-color: #fff!important;
    }

    &:hover {
      background-color: $--color-fill-3;
      .el-tree-node__wrap:not(.is-disabled) .operation {
        visibility: visible;
      }
      .el-tree-node__wrap {
        .el-tree-node__expand-icon:not(.is-leaf):not(.el-icon-file):hover {
          &:before {
            background-color: $--color-text-active;
            // border-radius: 50%;
            border-radius: $--border-radius-circle;
          }
        }
      }
      .el-checkbox:not(.is-checked):not(.is-disabled):not(.is-indeterminate):hover {
        background-color: $--color-text-active;
        // border-radius: 50%;
        border-radius: $--border-radius-circle;
        .el-checkbox__input:hover {
          background-color: $--color-text-active;
        }
      }
    }

    @include when(active) {
      background-color: $--primary-1;
      color: $--primary-6;
      .is-focusable{
        color: $--primary-6;
      }
    }
  }

  @include e(wrap) {
    display: flex;
    align-items: flex-start;
    width: 100%;

    .el-checkbox {
      margin-top: 0;
    }
    
    @include when(disabled) {
      cursor: not-allowed;

      .el-tree-caret-right, .el-tree-node__label {
        // 自定义图标在disabled状态下不能改变颜色
        color: $--color-text-4;
      }
    }

    @include when(focusable) {
      color: $--color-text-1;
    }
  }

  @include e(expand-icon) {
    cursor: pointer;
    color: $--color-text-1;
    font-size: $--font-size-title-1;

    transform: rotate(0deg);
    transition: transform 0.3s ease-in-out;

    &.expanded {
      transform: rotate(90deg);
    }

    &.is-leaf {
      color: transparent;
      cursor: default;
    }
  }

  @include e(label) {
    font-size: $--font-size-body-3;
    margin: $--tree-node-margin;
    line-height: 22px;
    width: 100%;
    white-space: pre-wrap;

    &.overflow-hidden {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    i {
      margin-right: 10px;
    }

    .operation {
      float: right;
      margin-right: 8px;
      visibility: hidden;
      i {
        color: $--color-text-2;
        cursor: pointer;
        width: 24px;
        height: 24px;
        line-height: 24px;
        font-size: $--font-size-title-1;
        text-align: center;
        margin: 0;
        padding: 0;
        &:hover {
          background: $--color-bg-4;
          border-radius: $--border-radius-circle;
        }
      }
      i + i {
        margin-left: 8px;
      }
    }
  }

  @include e(loading-icon) {
    margin-right: 8px;
    font-size: $--font-size-body-3;
    color: $--color-text-2;
  }

  & > .el-tree-node__children {
    // overflow: hidden;
    background-color: transparent;
  }

  &.is-expanded > .el-tree-node__children {
    display: block;
  }
}

.el-tree-node-is-leaf:not(.el-tree-node-is-tail) {
  .el-tree-node-indent:after {
    position: absolute;
    right: -11px;
    box-sizing: border-box;
    width: 1px;
    border-left: $--border-1 solid $--color-fill-4;
    transform: translate(50%);
    content: "";
    top: 35px;
    bottom: -10px;
  }
}

.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  background-color: $--primary-1;
}
