@mixin tether($themePrefix: "tether") {
  .#{$themePrefix}-element, .#{$themePrefix}-element * {
    &, &:after, &:before {
      box-sizing: border-box;
    }
  }

  .#{$themePrefix}-element {
    @include normalize;

    position: absolute;
    display: none;
    &.#{$themePrefix}__visible {
      display: block;
    }
  }
}

@mixin tether-theme-arrows($themePrefix: "tether", $arrowSize: 16px, $arrowPointerEvents: null, $backgroundColor: white, $color: inherit) {
  .#{$themePrefix}-element {
    max-width: 100%;
    max-height: 100%;
    .#{$themePrefix}-content {
      border-radius: 5px;
      position: relative;
      font-family: inherit;
      background: $backgroundColor;
      color: $color;
      padding: 1em;
      font-size: 14px;
      line-height: 1.3em;
      box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
      max-width: 400px;
      pointer-events: none;

      &:before {
        content: "";
        display: block;
        position: absolute;
        width: 0;
        height: 0;
        border-color: transparent;
        border-width: $arrowSize;
        border-style: solid;
        pointer-events: $arrowPointerEvents;
      }
    }
    // Centers and middles
    &.#{$themePrefix}-element-attached-bottom.#{$themePrefix}-element-attached-center .#{$themePrefix}-content {
      margin-bottom: $arrowSize;
      &:before {
        top: 100%;
        left: 50%;
        margin-left: -$arrowSize;
        border-top-color: $backgroundColor;
      }
    }
    &.#{$themePrefix}-element-attached-top.#{$themePrefix}-element-attached-center .#{$themePrefix}-content {
      margin-top: $arrowSize;
      &:before {
        bottom: 100%;
        left: 50%;
        margin-left: -$arrowSize;
        border-bottom-color: $backgroundColor;
      }
    }
    &.#{$themePrefix}-element-attached-right.#{$themePrefix}-element-attached-middle .#{$themePrefix}-content {
      margin-right: $arrowSize;
      &:before {
        left: 100%;
        top: 50%;
        margin-top: -$arrowSize;
        border-left-color: $backgroundColor;
      }
    }
    &.#{$themePrefix}-element-attached-left.#{$themePrefix}-element-attached-middle .#{$themePrefix}-content {
      margin-left: $arrowSize;
      &:before {
        right: 100%;
        top: 50%;
        margin-top: -$arrowSize;
        border-right-color: $backgroundColor;
      }
    }
    // Top and bottom corners
    &.#{$themePrefix}-element-attached-top.#{$themePrefix}-element-attached-left.#{$themePrefix}-target-attached-bottom .#{$themePrefix}-content {
      margin-top: $arrowSize;
      &:before {
        bottom: 100%;
        left: $arrowSize;
        border-bottom-color: $backgroundColor;
      }
    }
    &.#{$themePrefix}-element-attached-top.#{$themePrefix}-element-attached-right.#{$themePrefix}-target-attached-bottom .#{$themePrefix}-content {
      margin-top: $arrowSize;
      &:before {
        bottom: 100%;
        right: $arrowSize;
        border-bottom-color: $backgroundColor;
      }
    }
    &.#{$themePrefix}-element-attached-bottom.#{$themePrefix}-element-attached-left.#{$themePrefix}-target-attached-top .#{$themePrefix}-content {
      margin-bottom: $arrowSize;
      &:before {
        top: 100%;
        left: $arrowSize;
        border-top-color: $backgroundColor;
      }
    }
    &.#{$themePrefix}-element-attached-bottom.#{$themePrefix}-element-attached-right.#{$themePrefix}-target-attached-top .#{$themePrefix}-content {
      margin-bottom: $arrowSize;
      &:before {
        top: 100%;
        right: $arrowSize;
        border-top-color: $backgroundColor;
      }
    }
    // Side corners
    &.#{$themePrefix}-element-attached-top.#{$themePrefix}-element-attached-right.#{$themePrefix}-target-attached-left .#{$themePrefix}-content {
      margin-right: $arrowSize;
      &:before {
        top: $arrowSize;
        left: 100%;
        border-left-color: $backgroundColor;
      }
    }
    &.#{$themePrefix}-element-attached-top.#{$themePrefix}-element-attached-left.#{$themePrefix}-target-attached-right .#{$themePrefix}-content {
      margin-left: $arrowSize;
      &:before {
        top: $arrowSize;
        right: 100%;
        border-right-color: $backgroundColor;
      }
    }
    &.#{$themePrefix}-element-attached-bottom.#{$themePrefix}-element-attached-right.#{$themePrefix}-target-attached-left .#{$themePrefix}-content {
      margin-right: $arrowSize;
      &:before {
        bottom: $arrowSize;
        left: 100%;
        border-left-color: $backgroundColor;
      }
    }
    &.#{$themePrefix}-element-attached-bottom.#{$themePrefix}-element-attached-left.#{$themePrefix}-target-attached-right .#{$themePrefix}-content {
      margin-left: $arrowSize;
      &:before {
        bottom: $arrowSize;
        right: 100%;
        border-right-color: $backgroundColor;
      }
    }
  }
}

$tether_theme-prefix: "xbuyButton-widget-tether";
$tether_arrow-size: 8px;
$tether_background-color: #ffffff;
$tether_color: #4a4a4a;

@include tether($themePrefix: $tether_theme-prefix);
@include tether-theme-arrows($themePrefix: $tether_theme-prefix, $arrowSize: $tether_arrow-size, $backgroundColor: $tether_background-color, $color: $tether_color);
