@import '../settings/base';

$tooltip_max_width: 300px;
$tooltip_max_height: 140px;
$tooltip_arrow: #{$css_prefix}_c_tooltip__arrow;
$tooltip_arrow_width: 7px;
$tooltip_border_width: 1px;
$tooltip_arrow_distance: 4px;
$tooltip_distance: $tooltip_arrow_width - $tooltip_border_width + $tooltip_arrow_distance;
$tooltip_arrow_offset: 8px;
$tooltip_arrow_color: $color_gray_k6;

@mixin popper($arrow, $arrow_width, $arrow_offset, $arrow_distance, $distance, $bc) {
  position: absolute;

  &[x-placement^="top"] {
    padding-bottom: $distance;
  }
  &[x-placement^="right"] {
    padding-left: $distance;
  }
  &[x-placement^="bottom"] {
    padding-top: $distance;
  }
  &[x-placement^="left"] {
    padding-right: $distance;
  }

  &[x-placement^="top"] .#{$arrow} {
    bottom: $arrow_distance;
    border-width: $arrow_width $arrow_width 0;
    border-top-color: $bc;
  }
  &[x-placement="top"] .#{$arrow} {
    left: 50%;
    margin-left: -$arrow-width;
  }
  &[x-placement="top-start"] .#{$arrow} {
    left: $arrow_offset;
  }
  &[x-placement="top-end"] .#{$arrow} {
    right: $arrow_offset;
  }

  &[x-placement^="right"] .#{$arrow} {
    left: $arrow_distance;
    border-width: $arrow_width $arrow_width $arrow_width 0;
    border-right-color: $bc;
  }
  &[x-placement="right"] .#{$arrow} {
    top: 50%;
    margin-top: - $arrow_width;
  }
  &[x-placement="right-start"] .#{$arrow} {
    top: $arrow_offset;
  }
  &[x-placement="right-end"] .#{$arrow} {
    bottom: $arrow_offset;
  }

  &[x-placement^="bottom"] .#{$arrow} {
    top: $arrow_distance;
    border-width: 0 $arrow-width $arrow-width;
    border-bottom-color: $bc;
  }

  &[x-placement="bottom"] .#{$arrow} {
    left: 50%;
    margin-left: -$arrow_width;
  }
  &[x-placement="bottom-start"] .#{$arrow} {
    left: $arrow_offset;
  }
  &[x-placement="bottom-end"] .#{$arrow} {
    left: $arrow_offset;
  }

  &[x-placement^="left"] .#{$arrow} {
    right: $arrow_distance;
    border-width: $arrow_width 0 $arrow_width $arrow_width;
    border-left-color: $bc;
  }
  &[x-placement="left"] .#{$arrow} {
    top: 50%;
    margin-top: -$arrow_width;
  }
  &[x-placement="left-start"] .#{$arrow} {
    top: $arrow_offset;
  }
  &[x-placement="left-end"] .#{$arrow} {
    bottom: $arrow_offset;
  }

}

.#{$css_prefix}_c_tooltip {
  display: inline-block;

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

  &__popper {
    @include popper($tooltip_arrow, $tooltip_arrow_width, $tooltip_arrow_offset, $tooltip_arrow_distance, $tooltip_distance, $tooltip_arrow_color);

    &[x-placement^="top"] .#{$tooltip_arrow}::after {
      content: " ";
      bottom: 1px;
      left: -$tooltip_arrow_width;
      border-bottom-width: 0;
      border-top-color: $color_gray_k9;
    }

    &[x-placement^="right"] .#{$tooltip_arrow}::after {
      content: " ";
      left: 1px;
      bottom: -$tooltip_arrow_width;
      border-left-width: 0;
      border-right-color: $color_gray_k9;
    }

    &[x-placement^="bottom"] .#{$tooltip_arrow}::after {
      content: " ";
      top: 1px;
      left: -$tooltip_arrow_width;
      border-top-width: 0;
      border-bottom-color: $color_gray_k9;
    }

    &[x-placement^="left"] .#{$tooltip_arrow}::after {
      content: " ";
      right: 1px;
      bottom: -$tooltip_arrow_width;
      border-right-width: 0;
      border-left-color: $color_gray_k9;
    }

    &--dark {
      .#{$tooltip_arrow} {
        filter: none;
      }

      &[x-placement^="top"] .#{$tooltip_arrow}, &[x-placement^="top"] .#{$tooltip_arrow}::after {
        border-top-color: #000;
      }

      &[x-placement^="right"] .#{$tooltip_arrow}, &[x-placement^="right"] .#{$tooltip_arrow}::after {
        border-right-color: #000;
      }

      &[x-placement^="bottom"] .#{$tooltip_arrow}, &[x-placement^="bottom"] .#{$tooltip_arrow}::after {
        border-bottom-color: #000;
      }

      &[x-placement^="left"] .#{$tooltip_arrow}, &[x-placement^="left"] .#{$tooltip_arrow}::after {
        border-left-color: #000;
      }

      .#{$css_prefix}_c_tooltip__inner {
        border: none;
        box-shadow: none;
        background-color: #000;
      }

      .#{$css_prefix}_c_tooltip__inner_content {
        color: $color_gray_k9;
      }
    }
  }

  &__arrow {
    position: absolute;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.03));

    &::after {
      content: "";
      display: block;
      width: 0;
      height: 0;
      position: absolute;
      border-color: transparent;
      border-style: solid;
      border-width: $tooltip_arrow_width;
    }
  }

  &__inner {
    padding: 12px 16px;
    background-color: $color_gray_k9;
    border-radius: 2px;
    border: $tooltip_border_width solid $color_gray_k6;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12);
  }

  &__inner_content {
    max-width: calc(#{$tooltip_max_width} - 32px - 2px);
    max-height: calc(#{$tooltip_max_height} - 24px - 2px);
    overflow-x: hidden;
    overflow-y: scroll;
    color: $color_gray_k2;
    font-size: $fontsize_small;
    line-height: $lineheight_base;
    white-space: normal;

    //特殊内容
    .ysim_pkg_content {
      &:not(:last-child) {
        margin-bottom: 16px;
      }
      &__title {
        margin-bottom: 4px;
        font-weight: 500;
      }
      &__main {
        margin: 0;
      }
    }
  }

  //markdown 内容后续可以统一样式
  &__markdown {
    h1 {
      margin: 0 0 10px;
      font-size: 14px;
      font-weight: 500;
      line-height: 1.5;
      color: #333;
    }
    h2, h3, h4, h5 {
      margin: 0 0 10px;
      font-size: 12px;
      font-weight: 500;
      line-height: 1.5;
      color: #333;
    }
    ul, ol, p {
      margin: 0 !important;
      padding: 0 !important;
    }

    p, ul, ol {
      font-size: 12px !important;
    }

    p {
      line-height: 1.5 !important;
    }

    ul, ol {
      line-height: 1.5 !important;
    }

    ul, ol {
      margin-left: 10px !important;
    }

    p, ul, ol {
      margin-bottom: 10px !important;
    }

    p.p_followed {
      margin-bottom: 6px !important;
    }

    p:last-child, ul:last-child, ol:last-child {
      margin-bottom: 0px !important;
    }

    ul li, ol li {
      list-style-type: initial;
      margin-bottom: 6px !important;
    }

    ul li:last-child, ol li:last-child {
      margin-bottom: 0px !important;
    }

    ol li {
      list-style-type: decimal;
    }

    a, a strong {
      color: #1282f0;
      font-weight: normal;
    }

    a:hover, a:hover strong {
      text-decoration: underline;
    }

    ul, ol {
      list-style: initial;
      margin-left: 10px !important;
    }

    img {
      max-width: 100%;
      margin-bottom: 10px;
      display: block;
    }

    img + img {
      margin-top: 16px;
    }

    em, strong {
      font-size: 12px;
      color: #333;
      font-weight: bold;
    }
  }
}