@use "mixins/border-radius";
@use "variables";
@use "vendor/rfs";
@use "mixins/reset-text";

// Base class
.tooltip {
  position: absolute;
  z-index: variables.$zindex-tooltip;
  display: block;
  margin: variables.$tooltip-margin;
  // Our parent element can be arbitrary since tooltips are by default inserted as a sibling of their target element.
  // So reset our font and text properties to avoid inheriting weird values.
  @include reset-text.reset-text();
  @include rfs.font-size(variables.$tooltip-font-size);
  // Allow breaking very long words so they don't overflow the tooltip's bounds
  word-wrap: break-word;
  opacity: 0;

  &.show { opacity: variables.$tooltip-opacity; }

  .arrow {
    position: absolute;
    display: block;
    width: variables.$tooltip-arrow-width;
    height: variables.$tooltip-arrow-height;

    &::before {
      position: absolute;
      content: "";
      border-color: transparent;
      border-style: solid;
    }
  }
}

.bs-tooltip-top {
  padding: variables.$tooltip-arrow-height 0;

  .arrow {
    bottom: 0;

    &::before {
      top: 0;
      border-width: variables.$tooltip-arrow-height (variables.$tooltip-arrow-width * .5) 0;
      border-top-color: variables.$tooltip-arrow-color;
    }
  }
}

.bs-tooltip-right {
  padding: 0 variables.$tooltip-arrow-height;

  .arrow {
    left: 0;
    width: variables.$tooltip-arrow-height;
    height: variables.$tooltip-arrow-width;

    &::before {
      right: 0;
      border-width: (variables.$tooltip-arrow-width * .5) variables.$tooltip-arrow-height (variables.$tooltip-arrow-width * .5) 0;
      border-right-color: variables.$tooltip-arrow-color;
    }
  }
}

.bs-tooltip-bottom {
  padding: variables.$tooltip-arrow-height 0;

  .arrow {
    top: 0;

    &::before {
      bottom: 0;
      border-width: 0 (variables.$tooltip-arrow-width * .5) variables.$tooltip-arrow-height;
      border-bottom-color: variables.$tooltip-arrow-color;
    }
  }
}

.bs-tooltip-left {
  padding: 0 variables.$tooltip-arrow-height;

  .arrow {
    right: 0;
    width: variables.$tooltip-arrow-height;
    height: variables.$tooltip-arrow-width;

    &::before {
      left: 0;
      border-width: (variables.$tooltip-arrow-width * .5) 0 (variables.$tooltip-arrow-width * .5) variables.$tooltip-arrow-height;
      border-left-color: variables.$tooltip-arrow-color;
    }
  }
}

.bs-tooltip-auto {
  &[x-placement^="top"] {
    @extend .bs-tooltip-top;
  }
  &[x-placement^="right"] {
    @extend .bs-tooltip-right;
  }
  &[x-placement^="bottom"] {
    @extend .bs-tooltip-bottom;
  }
  &[x-placement^="left"] {
    @extend .bs-tooltip-left;
  }
}

// Wrapper for the tooltip content
.tooltip-inner {
  max-width: variables.$tooltip-max-width;
  padding: variables.$tooltip-padding-y variables.$tooltip-padding-x;
  color: variables.$tooltip-color;
  text-align: center;
  background-color: variables.$tooltip-bg;
  @include border-radius.border-radius(variables.$tooltip-border-radius);
}
