@import '../common/variables.less';

@tooltip-prefix-cls: ~"@{css-prefix}-tooltip";
@tooltip-arrow: ~"@{tooltip-prefix-cls}-arrow";
@tooltip-max-width: 250px;
@tooltip-arrow-width: 5px;
@tooltip-distance: @tooltip-arrow-width - 1+4;

.popper(@arrow, @arrow-width, @arrow-distance, @bg){
    display: block;
    visibility: visible;
    font-size: @font-size-small;
    line-height: @line-height-base;
    position: absolute;
    z-index: @zindex-tooltip;

    &[x-placement^="top"] {
        padding: @arrow-width 0 @arrow-distance 0;
    }
    &[x-placement^="right"] {
        padding: 0 @arrow-width 0 @arrow-distance;
    }
    &[x-placement^="bottom"] {
        padding: @arrow-distance 0 @arrow-width 0;
    }
    &[x-placement^="left"] {
        padding: 0 @arrow-distance 0 @arrow-width;
    }

    &[x-placement^="top"] .@{arrow} {
        bottom: @arrow-distance - @arrow-width;
        border-width: @arrow-width @arrow-width 0;
        border-top-color: @bg;
    }
    &[x-placement="top"] .@{arrow} {
        left: 50%;
        margin-left: -@arrow-width;
    }
    &[x-placement="top-start"] .@{arrow} {
        left: 16px;
    }
    &[x-placement="top-end"] .@{arrow} {
        right: 16px;
    }

    &[x-placement^="right"] .@{arrow} {
        left: @arrow-distance - @arrow-width;
        border-width: @arrow-width @arrow-width @arrow-width 0;
        border-right-color: @bg;
    }
    &[x-placement="right"] .@{arrow} {
        top: 50%;
        margin-top: -@arrow-width;
    }
    &[x-placement="right-start"] .@{arrow} {
        top: 8px;
    }
    &[x-placement="right-end"] .@{arrow} {
        bottom: 8px;
    }

    &[x-placement^="left"] .@{arrow} {
        right: @arrow-distance - @arrow-width;
        border-width: @arrow-width 0 @arrow-width @arrow-width;
        border-left-color: @bg;
    }
    &[x-placement="left"] .@{arrow} {
        top: 50%;
        margin-top: -@arrow-width;
    }
    &[x-placement="left-start"] .@{arrow} {
        top: 8px;
    }
    &[x-placement="left-end"] .@{arrow} {
        bottom: 8px;
    }

    &[x-placement^="bottom"] .@{arrow} {
        top: @arrow-distance - @arrow-width;
        border-width: 0 @arrow-width @arrow-width;
        border-bottom-color: @bg;
    }
    &[x-placement="bottom"] .@{arrow} {
        left: 50%;
        margin-left: -@arrow-width;
    }
    &[x-placement="bottom-start"] .@{arrow} {
        left: 16px;
    }
    &[x-placement="bottom-end"] .@{arrow} {
        right: 16px;
    }
}

.@{tooltip-prefix-cls} {
  display: inline-block;

  &-rel {
    display: inline-block;
    position: relative;
  }

  &-popper {
    .popper(@tooltip-arrow, @tooltip-arrow-width, @tooltip-distance, @tooltip-bg);
  }

  &-inner {
    width: max-content;
    max-width: @tooltip-max-width;
    min-height: 34px;
    padding: 8px 12px;
    color: @tooltip-color;
    text-align: left;
    text-decoration: none;
    background-color: @tooltip-bg;
    border-radius: @border-radius-small;
    box-shadow: @shadow-base;
    white-space: pre-wrap;
  }

  &-arrow {
    position: absolute;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
  }
}
