@import '../../style/themes/index';
@import '../../style/mixins/index';
@import '../../checkbox/style/mixin';
@import './mixin';
@import './directory';

@yee-tree-prefix-cls: ~'@{yee-prefix}-tree';
@yee-tree-showline-icon-color: @yee-text-color-secondary;
@yee-tree-node-padding: 4px;

.yeeCheckboxFn(@yee-checkbox-prefix-cls: ~'@{yee-prefix}-tree-checkbox');

.@{yee-tree-prefix-cls} {
  /* see https://github.com/ant-design/ant-design/issues/16259 */
  &-checkbox-checked::after {
    position: absolute;
    top: 16.67%;
    left: 0;
    width: 100%;
    height: 66.67%;
  }

  .yee-reset-component;

  margin: 0;
  padding: 0;

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

  li {
    margin: 0;
    padding: @yee-tree-node-padding 0;
    white-space: nowrap;
    list-style: none;
    outline: 0;
    span[draggable],
    span[draggable='true'] {
      line-height: @yee-tree-title-height - 4px;
      border-top: 2px transparent solid;
      border-bottom: 2px transparent solid;
      user-select: none;
      /* Required to make elements draggable in old WebKit */
      -khtml-user-drag: element;
      -webkit-user-drag: element;
    }
    &.drag-over {
      > span[draggable] {
        color: white;
        background-color: @yee-primary-color;
        opacity: 0.8;
      }
    }
    &.drag-over-gap-top {
      > span[draggable] {
        border-top-color: @yee-primary-color;
      }
    }
    &.drag-over-gap-bottom {
      > span[draggable] {
        border-bottom-color: @yee-primary-color;
      }
    }
    &.filter-node {
      > span {
        color: @yee-highlight-color !important;
        font-weight: 500 !important;
      }
    }

    // When node is loading
    &.@{yee-tree-prefix-cls}-treenode-loading {
      span {
        &.@{yee-tree-prefix-cls}-switcher {
          &.@{yee-tree-prefix-cls}-switcher_open,
          &.@{yee-tree-prefix-cls}-switcher_close {
            .@{yee-tree-prefix-cls}-switcher-loading-icon {
              position: absolute;
              left: 0;
              display: inline-block;
              width: 24px;
              height: @yee-tree-title-height;
              color: @yee-primary-color;
              font-size: 14px;
              transform: none;
              svg {
                position: absolute;
                top: 0;
                right: 0;
                bottom: 0;
                left: 0;
                margin: auto;
              }
            }

            :root &::after {
              opacity: 0;
            }
          }
        }
      }
    }

    ul {
      margin: 0;
      padding: 0 0 0 @yee-tree-child-padding;
    }
    .@{yee-tree-prefix-cls}-node-content-wrapper {
      display: inline-block;
      height: @yee-tree-title-height;
      margin: 0;
      padding: 0 5px;
      color: @yee-text-color;
      line-height: @yee-tree-title-height;
      text-decoration: none;
      vertical-align: top;
      border-radius: @yee-border-radius-sm;
      cursor: pointer;
      transition: all 0.3s;
      &:hover {
        background-color: @yee-tree-node-hover-bg;
      }
      &.@{yee-tree-prefix-cls}-node-selected {
        background-color: @yee-tree-node-selected-bg;
      }
    }
    span {
      &.@{yee-tree-prefix-cls}-checkbox {
        top: initial;
        height: @yee-tree-title-height;
        margin: 0 4px 0 2px;
        padding: ((@yee-tree-title-height - 16px) / 2) 0;
      }
      &.@{yee-tree-prefix-cls}-switcher,
      &.@{yee-tree-prefix-cls}-iconEle {
        display: inline-block;
        width: 24px;
        height: @yee-tree-title-height;
        margin: 0;
        line-height: @yee-tree-title-height;
        text-align: center;
        vertical-align: top;
        border: 0 none;
        outline: none;
        cursor: pointer;
      }

      &.@{yee-tree-prefix-cls}-iconEle:empty {
        display: none;
      }

      &.@{yee-tree-prefix-cls}-switcher {
        position: relative;

        &.@{yee-tree-prefix-cls}-switcher-noop {
          cursor: default;
        }
        &.@{yee-tree-prefix-cls}-switcher_open {
          .yee-antTreeSwitcherIcon();
        }
        &.@{yee-tree-prefix-cls}-switcher_close {
          .yee-antTreeSwitcherIcon();
          .@{yee-tree-prefix-cls}-switcher-icon {
            svg {
              transform: rotate(-90deg);
            }
          }
        }
      }
    }
    &:last-child > span {
      &.@{yee-tree-prefix-cls}-switcher,
      &.@{yee-tree-prefix-cls}-iconEle {
        &::before {
          display: none;
        }
      }
    }
  }

  > li {
    &:first-child {
      padding-top: 7px;
    }
    &:last-child {
      padding-bottom: 7px;
    }
  }
  &-child-tree {
    // https://github.com/ant-design/ant-design/issues/14958
    > li {
      // Provide additional padding between top child node and parent node
      &:first-child {
        padding-top: 2 * @yee-tree-node-padding;
      }

      // Hide additional padding between last child node and next parent node
      &:last-child {
        padding-bottom: 0;
      }
    }
  }
  li&-treenode-disabled {
    > span:not(.@{yee-tree-prefix-cls}-switcher),
    > .@{yee-tree-prefix-cls}-node-content-wrapper,
    > .@{yee-tree-prefix-cls}-node-content-wrapper span {
      color: @yee-disabled-color;
      cursor: not-allowed;
    }
    > .@{yee-tree-prefix-cls}-node-content-wrapper:hover {
      background: transparent;
    }
  }
  &-icon__open {
    margin-right: 2px;
    vertical-align: top;
  }
  &-icon__close {
    margin-right: 2px;
    vertical-align: top;
  }
  // Tree with line
  &&-show-line {
    li {
      position: relative;
      span {
        &.@{yee-tree-prefix-cls}-switcher {
          color: @yee-tree-showline-icon-color;
          background: @yee-component-background;
          &.@{yee-tree-prefix-cls}-switcher-noop {
            .yee-antTreeShowLineIcon('tree-doc-icon');
          }
          &.@{yee-tree-prefix-cls}-switcher_open {
            .yee-antTreeShowLineIcon('tree-showline-open-icon');
          }
          &.@{yee-tree-prefix-cls}-switcher_close {
            .yee-antTreeShowLineIcon('tree-showline-close-icon');
          }
        }
      }
    }
    li:not(:last-child)::before {
      position: absolute;
      left: 12px;
      width: 1px;
      height: 100%;
      height: calc(100% - 22px); // Remove additional height if support
      margin: 22px 0 0;
      border-left: 1px solid @yee-border-color-base;
      content: ' ';
    }
  }

  &.@{yee-tree-prefix-cls}-icon-hide {
    .@{yee-tree-prefix-cls}-treenode-loading {
      .@{yee-tree-prefix-cls}-iconEle {
        display: none;
      }
    }
  }

  &.@{yee-tree-prefix-cls}-block-node {
    li {
      .@{yee-tree-prefix-cls}-node-content-wrapper {
        width: ~'calc(100% - 24px)';
      }
      span {
        &.@{yee-tree-prefix-cls}-checkbox {
          + .@{yee-tree-prefix-cls}-node-content-wrapper {
            width: ~'calc(100% - 46px)';
          }
        }
      }
    }
  }
}
