@import (reference) "../../../assets/css/index";
@import "../../Checkbox/style/mixin";
@import "./mixin";
@import "./directory";

@tree-prefix-cls: ~"@{fishd-prefix}-tree";
@spin-prefix-cls: ~"@{fishd-prefix}-spin";
@tree-showline-icon-color: @text-color-secondary;
@tree-item-selected-bg: #d9e7ff;

.fishdCheckboxFn(@checkbox-prefix-cls: ~"@{fishd-prefix}-tree-checkbox");

.@{tree-prefix-cls} {
  .reset-component;
  margin: 0;
  padding: 0;
  max-width: 300px;

  &-title {
    display: inline-block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

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

  li {
    margin: 0;
    list-style: none;
    white-space: nowrap;
    outline: 0;
    span[draggable],
    span[draggable="true"] {
      user-select: none;
      border-top: 2px transparent solid;
      border-bottom: 2px transparent solid;
      /* Required to make elements draggable in old WebKit */
      -khtml-user-drag: element;
      -webkit-user-drag: element;

      line-height: @tree-title-height - 4px;
    }
    &.drag-over > span[draggable] {
      background-color: @primary-color;
      color: white;
      opacity: 0.8;
    }
    &.drag-over-gap-top > span[draggable] {
      border-top-color: @primary-color;
    }
    &.drag-over-gap-bottom > span[draggable] {
      border-bottom-color: @primary-color;
    }
    &.filter-node > span {
      /* stylelint-disable-next-line declaration-no-important */
      color: @highlight-color !important;
      /* stylelint-disable-next-line declaration-no-important */
      font-weight: 500 !important;
    }

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

      .@{tree-prefix-cls}-switcher-loading-icon svg {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        margin: auto;
      }

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

    ul {
      margin: 0;
      padding: 0 0 0 @tree-child-padding;
    }
    .@{tree-prefix-cls}-node-content-wrapper {
      display: inline-flex;
      align-items: center;
      width: ~"calc(100% - 24px)";
      padding: 0 4px;
      border-radius: @border-radius-sm;
      margin: 2px 0;
      cursor: pointer;
      text-decoration: none;
      vertical-align: top;
      color: @text-color;
      transition: all 0.3s;
      // height: @tree-title-height;
      line-height: @tree-title-height;
      &:hover {
        background-color: @item-hover-bg;
      }
      &.@{tree-prefix-cls}-node-selected {
        background-color: @tree-item-selected-bg;
      }

      .@{spin-prefix-cls}-spinning {
        margin-right: 8px;
        line-height: 0;
      }
    }
    .@{tree-prefix-cls}-iconCtner {
      display: inline-flex;
      align-items: center;
    }
  }

  li span {
    &.@{tree-prefix-cls}-checkbox {
      margin: 2px 4px;
      display: inline-flex;
      align-items: center;
      height: @tree-title-height;
      line-height: @tree-title-height;
      top: auto;
    }
    &.@{tree-prefix-cls}-switcher,
    &.@{tree-prefix-cls}-iconEle {
      color: @text-9;
      margin: 2px 8px 2px 0;
      width: 14px;
      height: @tree-title-height;
      line-height: @tree-title-height;
      display: inline-flex;
      align-items: center;
      vertical-align: top;
      border: 0 none;
      cursor: pointer;
      outline: none;
      text-align: center;
    }

    &.@{tree-prefix-cls}-switcher {
      position: relative;
      width: 12px;

      &.@{tree-prefix-cls}-switcher-noop {
        cursor: default;
      }
      &.@{tree-prefix-cls}-switcher_open {
        .fishdTreeSwitcherIcon();
      }
      &.@{tree-prefix-cls}-switcher_close {
        .fishdTreeSwitcherIcon();
      }
      &.@{tree-prefix-cls}-switcher_close .@{tree-prefix-cls}-switcher-icon {
        transform: rotate(-90deg) scale(0.666);
      }
    }
  }

  li:last-child > span {
    &.@{tree-prefix-cls}-switcher,
    &.@{tree-prefix-cls}-iconEle {
      &:before {
        display: none;
      }
    }
  }

  > li {
    &:first-child {
      padding-top: 7px;
    }
    &:last-child {
      padding-bottom: 7px;
    }
  }
  &-child-tree {
    display: none;
    &-open {
      display: block;
    }
  }
  li&-treenode-disabled {
    > span:not(.@{tree-prefix-cls}-switcher),
    > .@{tree-prefix-cls}-node-content-wrapper,
    > .@{tree-prefix-cls}-node-content-wrapper span {
      color: @disabled-color;
      cursor: not-allowed;
    }
    > .@{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.@{tree-prefix-cls}-switcher {
      background: @component-background;
      color: @tree-showline-icon-color;
      &.@{tree-prefix-cls}-switcher-noop {
        .fishdTreeShowLineIcon("tree-doc-icon");
      }
      &.@{tree-prefix-cls}-switcher_open {
        .fishdTreeShowLineIcon("tree-showline-open-icon");
      }
      &.@{tree-prefix-cls}-switcher_close {
        .fishdTreeShowLineIcon("tree-showline-close-icon");
      }
    }
  }

  &&-show-line li:not(:last-child):before {
    content: ' ';
    width: 1px;
    border-left: 1px solid @border-color-base;
    height: 100%;
    position: absolute;
    left: 6px;
    margin: 22px 0;
  }

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