@import "mixins/mixins";
@import "common/var";

@include b(tooltip) {
  &:focus:not(.focusing), &:focus:hover {
    outline-width: 0;
  }
  @include e(popper) {
    position: absolute;
    // 修复抖动，默认给一个位置
    top: -9999px;
    border-radius: $--border-radius-base;
    padding: $--tooltip-padding;
    z-index: $--index-popper;
    font-size: $--tooltip-font-size;
    line-height: 20px;
    min-width: 10px;
    word-wrap: break-word;
    box-shadow: $--box-shadow-base;

    .popper__arrow,
    .popper__arrow::after {
      position: absolute;
      display: block;
      width: 0;
      height: 0;
      border-color: transparent;
      border-style: solid;
    }

    .popper__arrow {
      border-width: $--tooltip-arrow-size;
    }

    .popper__arrow::after {
      content: " ";
      border-width: 4px;
    }

    &[x-placement^="top"] {
      margin-bottom: #{$--tooltip-arrow-size + 3px};
    }

    &[x-placement^="top"] .popper__arrow {
      bottom: -$--tooltip-arrow-size;
      border-top-color: $--tooltip-border-color;
      border-bottom-width: 0;

      &::after {
        bottom: 1px;
        margin-left: -4px;
        border-top-color: $--tooltip-fill;
        border-bottom-width: 0;
      }
    }

    &[x-placement^="bottom"] {
      margin-top: #{$--tooltip-arrow-size + 3px};
    }

    &[x-placement^="bottom"] .popper__arrow {
      top: -$--tooltip-arrow-size;
      border-top-width: 0;
      border-bottom-color: $--tooltip-border-color;

      &::after {
        top: 1px;
        margin-left: -4px;
        border-top-width: 0;
        border-bottom-color: $--tooltip-fill;
      }
    }

    &[x-placement^="right"] {
      margin-left: #{$--tooltip-arrow-size + 3px};
    }

    &[x-placement^="right"] .popper__arrow {
      left: -$--tooltip-arrow-size;
      border-right-color: $--tooltip-border-color;
      border-left-width: 0;

      &::after {
        bottom: -4px;
        left: 1px;
        border-right-color: $--tooltip-fill;
        border-left-width: 0;
      }
    }

    &[x-placement^="left"] {
      margin-right: #{$--tooltip-arrow-size + 3px};
    }

    &[x-placement^="left"] .popper__arrow {
      right: -$--tooltip-arrow-size;
      border-right-width: 0;
      border-left-color: $--tooltip-border-color;

      &::after {
        right: 1px;
        bottom: -4px;
        margin-left: -5px;
        border-right-width: 0;
        border-left-color: $--tooltip-fill;
      }
    }

    @include when(dark) {
      background: $--tooltip-fill;
      color: $--tooltip-color;
    }

    @include when(light) {
      background: $--tooltip-color;
      border: $--border-base;
      box-shadow: $--box-shadow-light;

      &[x-placement^="top"] .popper__arrow {
        border-top-color: $--border-color-base;
        &::after {
          border-top-color: $--tooltip-color;
        }
      }
      &[x-placement^="bottom"] .popper__arrow {
        border-bottom-color: $--border-color-base;
        &::after {
          border-bottom-color: $--tooltip-color;
        }
      }
      &[x-placement^="left"] .popper__arrow {
        border-left-color: $--border-color-base;
        &::after {
          border-left-color: $--tooltip-color;
        }
      }
      &[x-placement^="right"] .popper__arrow {
        border-right-color: $--border-color-base;
        &::after {
          border-right-color: $--tooltip-color;
        }
      }
    }
  }
}
