//
// Author: Vishnu Baliga (Twitter: https://twitter.com/Vishnu_Baliga)
// Github-Repo: https://github.com/VishnuBaliga/SpikeTip
// Website: https://vishnubaliga.github.io/SpikeTip/
// License: MIT
// -----------------------------------------

//
// Variables
// -----------------------------------------


$spiketip-base-size: 10px !default;
$spiketip-arrow-height: 6px;

$spiketip-bg: fade-out(#111,0.1) !default; 
$spiketip-bg--success: rgba(#4CAF50,0.9); //success-color
$spiketip-bg--error: rgba(#F44336,0.9); //error-color
$spiketip-bg--warning: rgba(#FFC107,0.9); //warning-color
$spiketip-bg--info: rgba(#03A9F4,0.9); //info-color

//
// Mixins
// -----------------------------------------

@mixin svg-arrow ($color, $position: top) {

  $degrees: 0;
  $height:  6px;
  $width:   18px;

  @if ($position == bottom or $position == bottom-left or $position == bottom-right) {
    $degrees: 180 18 6;
    } @else if ($position == left) {
      $degrees: -90 18 18;
      $width: 6px;
      $height: 18px;
      } @else if ($position == right) {
        $degrees: 90 6 6;
        $width: 6px;
        $height: 18px;
      }

      background: no-repeat url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http://www.w3.org/2000/svg%22%20width%3D%22#{$width * 2}%22%20height%3D%22#{$height * 2}%22%3E%3Cpath%20fill%3D%22#{$color}%22%20transform%3D%22rotate(#{$degrees})%22%20d%3D%22M2.658,0.000%20C-13.615,0.000%2050.938,0.000%2034.662,0.000%20C28.662,0.000%2023.035,12.002%2018.660,12.002%20C14.285,12.002%208.594,0.000%202.658,0.000%20Z%22/%3E%3C/svg%3E');
      background-size: 100% auto;
      width: $width;
      height: $height;
    }

    @mixin transition ($args...) {
      -webkit-transition: $args;
      -moz-transition: $args;
      -ms-transition: $args;
      -o-transition: $args;
      transition: $args;
    }

    @mixin transform ($val) {
      -webkit-transform: $val;
      -moz-transform: $val;
      -ms-transform: $val;
      transform: $val;
    }

    @mixin transform-origin ($val) {
      -webkit-transform-origin: $val;
      -moz-transform-origin: $val;
      -ms-transform-origin: $val;
      transform-origin: $val;
    }

    @mixin opacity ($trans) {
      filter: alpha(opactiy=($trans * 100));
      -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=#{$trans * 100})";
      -moz-opacity: $trans;
      -khtml-opacity: $trans;
      opacity: $trans;
    }

    @mixin base-effects () {
      @include opacity(0);
      pointer-events: none;
      @include transition(all .18s ease-out .18s);
    }

    @mixin no-effects () {
      @include transition(none);
    }

    @mixin normalized-text() {
      font-family: sans-serif !important;
      font-weight: normal !important;
      font-style: normal !important;
      text-shadow: none !important;
      font-size: $spiketip-base-size + 2 !important;
    }


//
// Styles
// -----------------------------------------

// IE 11 button bugfix
button[spiketip-title] {
  overflow: visible;
}

[spiketip-title] {
  position: relative; // alt. absolute or fixed

  // Fixing iOS Safari event issue. 
  cursor: pointer;

  &:after {
    @include base-effects();
    @include normalized-text();
    background: $spiketip-bg;
    border-radius: 4px;
    color: #fff;
    content: attr(spiketip-title);
    padding: .5em 1em;
    position: absolute;
    white-space: nowrap;
    z-index: 10;
  }

  &:before {
    @include svg-arrow($spiketip-bg);
    @include base-effects();

    content: '';
    position: absolute;
    z-index: 10;
  }

  &:hover, &[spiketip-visible] {
    &:before,
    &:after {
      @include opacity(1);
      pointer-events: auto;
    }
  }

  &.font-awesome:after {
    font-family: FontAwesome;
  }

  &[spiketip-break] {
    &:after {
      white-space: pre;
    }
  }

  &[spiketip-blunt] {
    &:before,
    &:after {
      @include no-effects();
    }
  }

  &[spiketip-pos="top"] {
    &:after {
      bottom: 100%;
      left: 50%;
      margin-bottom: 5px + $spiketip-arrow-height;
      @include transform(translate(-50%, 10px));
      @include transform-origin(top);
    }
    &:before {
      bottom: 100%;
      left: 50%;
      margin-bottom: 5px;
      @include transform(translate(-50%, 10px));
      @include transform-origin(top);
    }

    &:hover, &[spiketip-visible] {
      &:after {
        @include transform(translate(-50%, 0));
      }

      &:before {
        @include transform(translate(-50%, 0));
      }
    }
  }

  &[spiketip-pos="top-left"] {
    &:after {
      bottom: 100%;
      left: 0;
      margin-bottom: 5px + $spiketip-arrow-height;
      @include transform(translate(0, 10px));
      @include transform-origin(top);
    }
    &:before {
      bottom: 100%;
      left: 5px;
      margin-bottom: 5px;
      @include transform(translate(0, 10px));
      @include transform-origin(top);
    }

    &:hover, &[spiketip-visible] {
      &:after {
        @include transform(translate(0, 0));
      }

      &:before {
        @include transform(translate(0, 0));
      }
    }
  }

  &[spiketip-pos="top-right"] {
    &:after {
      bottom: 100%;
      right: 0;
      margin-bottom: 5px + $spiketip-arrow-height;
      @include transform(translate(0, 10px));
      @include transform-origin(top);
    }
    &:before {
      bottom: 100%;
      right: 5px;
      margin-bottom: 5px;
      @include transform(translate(0, 10px));
      @include transform-origin(top);
    }

    &:hover, &[spiketip-visible] {
      &:after {
        @include transform(translate(0, 0));
      }

      &:before {
        @include transform(translate(0, 0));
      }
    }
  }

  &[spiketip-pos='bottom'] {
    &:after {
      left: 50%;
      margin-top: 5px + $spiketip-arrow-height;
      top: 100%;
      @include transform(translate(-50%, -10px));
    }

    &:before {
      @include svg-arrow($spiketip-bg, 'bottom');

      left: 50%;
      margin-top: 5px;
      top: 100%;
      @include transform(translate(-50%, -10px));
    }

    &:hover, &[spiketip-visible] {
      &:after {
        @include transform(translate(-50%, 0));
      }

      &:before {
        @include transform(translate(-50%, 0));
      }
    }
  }

  &[spiketip-pos='bottom-left'] {
    &:after {
      left: 0;
      margin-top: 5px + $spiketip-arrow-height;
      top: 100%;
      @include transform(translate(0, -10px));
    }

    &:before {
      @include svg-arrow($spiketip-bg, 'bottom');

      left: 5px;
      margin-top: 5px;
      top: 100%;
      @include transform(translate(0, -10px));
    }

    &:hover, &[spiketip-visible] {
      &:after {
        @include transform(translate(0, 0));
      }

      &:before {
        @include transform(translate(0, 0));
      }
    }
  }

  &[spiketip-pos='bottom-right'] {
    &:after {
      right: 0;
      margin-top: 5px + $spiketip-arrow-height;
      top: 100%;
      @include transform(translate(0, -10px));
    }

    &:before {
      @include svg-arrow($spiketip-bg, 'bottom');

      right: 5px;
      margin-top: 5px;
      top: 100%;
      @include transform(translate(0, -10px));
    }

    &:hover, &[spiketip-visible] {
      &:after {
        @include transform(translate(0, 0));
      }

      &:before {
        @include transform(translate(0, 0));
      }
    }
  }

  &[spiketip-pos='left'] {
    &:after {
      margin-right: 5px + $spiketip-arrow-height;
      right: 100%;
      top: 50%;
      @include transform(translate(10px, -50%));
    }

    &:before {
      @include svg-arrow($spiketip-bg, 'left');

      margin-right: 5px;
      right: 100%;
      top: 50%;
      @include transform(translate(10px, -50%));
    }

    &:hover, &[spiketip-visible] {
      &:after {
        @include transform(translate(0, -50%));
      }

      &:before {
        @include transform(translate(0, -50%));
      }
    }

  }

  &[spiketip-pos='right'] {
    &:after {

      left: 100%;
      margin-left: 5px + $spiketip-arrow-height;
      top: 50%;
      @include transform(translate(-10px, -50%));
    }

    &:before {
      @include svg-arrow($spiketip-bg, 'right');

      left: 100%;
      margin-left: 5px;
      top: 50%;
      @include transform(translate(-10px, -50%));
    }

    &:hover, &[spiketip-visible] {
      &:after {
        @include transform(translate(0, -50%));
      }

      &:before {
        @include transform(translate(0, -50%));
      }
    }
  }



// Size options - 'sm','md','lg','xl', 'auto'  
  &[spiketip-length='sm'] {
    &:after {
      white-space: normal;
      width: 80px;
    }
  }

  &[spiketip-length='md'] {
    &:after {
      white-space: normal;
      width: 150px;
    }
  }

  &[spiketip-length='lg'] {
    &:after {
      white-space: normal;
      width: 260px;
    }
  }

  &[spiketip-length='xl'] {
    &:after {
      white-space: normal;
      width: 380px;

      @media screen and (max-width: 768px) {
        white-space: normal;
        width: 90vw;
      }
    }
  }

  &[spiketip-length='auto'] {
    &:after {
      white-space: normal;
      width: 100%;
    }
  }
}


// Color options - 'success','error','warning','info'
 
$colors-list: $spiketip-bg--success $spiketip-bg--error $spiketip-bg--warning $spiketip-bg--info;
$colors-list-name: 'success','error','warning','info'; 
$arrow-position: 'top', 'bottom', 'left', 'right','top-right', 'top-left', 'bottom-right', 'bottom-left';

@each $current-color in $colors-list { 
  $i: index($colors-list, $current-color); 
    @each $position in $arrow-position { 
      [spiketip-title][spiketip-pos='#{$position}'][spiketip-color='#{nth($colors-list-name, $i)}']{
        &:after { 
          background: $current-color; 
        } 
        &:before {
          @include svg-arrow($current-color,'#{$position}');
        }
      } 
    }
}