@import '../../style/themes/default';
@import '../../style/color/colors.less';
@import '../../checkbox/style/index.less';
@import './mixin.less';

@tree-prefix-cls: ~'fm-tree';
@tree-padding-xs: 8px;
@tree-border-radius-base: 2px;
@tree-disabled-color: fade(#000, 25%);
@tree-node-hover-bg: #f5f5f5;
@tree-node-prefix-cls: ~'@{tree-prefix-cls}-treenode';
@tree-title-height: 24px;
@tree-title-width: 30px;
@tree-child-padding: 18px;
@tree-node-selected-bg: @primary-2;
.fmCheckboxFn(@checkboxPrefixCls: ~'fm-tree-checkbox');

.fmTreeFn(@tree-prefix-cls) {

  .@{tree-prefix-cls}-search {
    margin-bottom: 10px;
    .@{tree-prefix-cls}-search-icon {
      font-size: 20px;
      color: #888;
    }
  }

  .@{tree-prefix-cls} {
    .reset-component;
    border-radius: @tree-border-radius-base;
    transition: background-color 0.3s;

    &-rtl {
      direction: rtl;
    }

    &-focused:not(:hover):not(&-active-focused) {
      background: @primary-1;
    }

    .filter-node {
      .@{tree-prefix-cls}-title {
        color: @highlight-color !important;
        font-weight: 500 !important;
      }
    }

    // =================== Virtual List ===================
    &-list-holder-inner {
      align-items: flex-start;
    }

    &.@{tree-prefix-cls}-block-node {
      .@{tree-prefix-cls}-list-holder-inner {
        align-items: stretch;

        // >>> Title
        .@{tree-prefix-cls}-node-content-wrapper {
          flex: auto;
        }
      }
    }

    // ===================== TreeNode =====================
    .@{tree-node-prefix-cls} {
      display: flex;
      align-items: flex-start;
      padding: 0 0 (@tree-padding-xs / 2) 0;
      outline: none;

      &-rtl {
        direction: rtl;
      }
      // Disabled
      &-disabled {
        // >>> Title
        .@{tree-prefix-cls}-node-content-wrapper {
          color: @tree-disabled-color;
          cursor: not-allowed;
          &:hover {
            background: transparent;
          }
        }
      }

      &-active .@{tree-prefix-cls}-node-content-wrapper {
        background: @tree-node-hover-bg;
      }
    }

    // >>> Indent
    &-indent {
      align-self: stretch;
      white-space: nowrap;
      user-select: none;

      &-unit {
        display: inline-block;
        width: @tree-title-height;
      }
    }

    // >>> Switcher
    & &-switcher {
      .fmTreeSwitcherIcon();
      color: rgba(0, 0, 0, 0.65);
      flex: none;

      width: @tree-title-width;
      height: @tree-title-height;
      margin: 0;
      line-height: @tree-title-height;
      text-align: center;
      cursor: pointer;

      &-noop {
        cursor: default;
      }

      &_close {
        .@{tree-prefix-cls}-switcher-icon {
          svg {
            transform: rotate(-90deg);

            .@{tree-prefix-cls}-rtl& {
              transform: rotate(90deg);
            }
          }
        }
      }
    }

    // >>> Checkbox
    & &-checkbox {
      top: initial;
      margin: ((@tree-title-height - @checkbox-size) / 2) 8px 0 0;
    }

    // >>> Title
    & &-node-content-wrapper {
      min-height: @tree-title-height;
      margin: 0;
      padding: 0 4px;
      color: inherit;
      line-height: @tree-title-height;
      background: transparent;
      border-radius: @tree-border-radius-base;
      cursor: pointer;
      transition: all 0.3s;

      &:hover {
        background-color: @tree-node-hover-bg;
      }
      &.@{tree-prefix-cls}-node-selected {
        background-color: @tree-node-selected-bg;
      }

      // Icon
      .@{tree-prefix-cls}-iconEle {
        display: inline-block;
        width: @tree-title-height;
        height: @tree-title-height;
        line-height: @tree-title-height;
        text-align: center;
        vertical-align: top;
        &:empty {
          display: none;
        }
      }
    }

    // ===================== Loading ======================
    .@{tree-node-prefix-cls}-loading {
      // Icon
      .@{tree-prefix-cls}-iconEle {
        display: none;
      }
    }
  }
}

.fmTreeFn(@tree-prefix-cls);
