@use "sass:math";

@use "sass:color";
@use "colors";
@use "variables";

@mixin clearfix() {
  &:after {
    content: "";
    display: table;
    clear: both;
  }
}

@keyframes spinning {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@mixin spinning($duration: 1s, $iteration: infinite) {
  animation-duration: $duration;
  animation-name: spinning;
  animation-iteration-count: $iteration;
}

@mixin opacity($opacity: 100) {
  opacity: $opacity * 0.01;
}

@mixin selection($r, $g, $b) {
  ::selection { background: rgb($r, $g, $b); }
  img::selection { background: transparent; }
}

@mixin square($size:100%) {
  box-sizing: border-box;
  display: block;
  width: $size;
  height: $size;
}

@mixin gradient($start: #555, $end: #333) {
  background-color: color.mix($start, $end, 60%);
  background-image: linear-gradient(to bottom, $start, $end); // The standard
}

@mixin border-top-radius($radius) {
  border-top-right-radius: $radius;
  border-top-left-radius: $radius;
}

@mixin border-right-radius($radius) {
  border-bottom-right-radius: $radius;
  border-top-right-radius: $radius;
}

@mixin border-bottom-radius($radius) {
  border-bottom-right-radius: $radius;
  border-bottom-left-radius: $radius;
}

@mixin border-left-radius($radius) {
  border-bottom-left-radius: $radius;
  border-top-left-radius: $radius;
}

@mixin bordered($top-color: #eee, $right-color: #eee, $bottom-color: #eee, $left-color: #eee) {
  border-top: 1px solid $top-color;
  border-right: 1px solid $right-color;
  border-bottom: 1px solid $bottom-color;
  border-left: 1px solid $left-color;
}

@mixin retina-image($file, $type, $width, $height) {
  background-image: url($file + '.' + $type);

  @media only screen and (min-resolution: 2dppx) {
    & {
      background-image: url($file + '@2x.' + $type);
      background-size: $width $height;
    }
  }
}

@mixin transition($transition: all linear .2s) {
  transition: $transition;
}

@mixin blur($radius) {
  filter: blur($radius);
}

@mixin rotate($deg) {
    transform: rotate($deg);
}

@mixin arrow-top($color: #fff, $size: 5px, $left: 5px) {
  &:after {
    bottom: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
    border-bottom-color: $color;
    border-width: $size;
    left: $left;
  }
}

@mixin arrow-bottom($color: #fff, $size: 5px, $left: 5px) {
  &:after {
    top: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
    border-top-color: $color;
    border-width: $size;
    left: $left;
  }
}

@mixin arrow-left($color: #fff, $size: 5px, $top: 5px) {
  &:after {
    right: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
    border-right-color: $color;
    border-width: $size;
    top: $top;
  }
}

@mixin arrow-right($color: #fff, $size: 5px, $top: 5px) {
  &:after {
    left: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
    border-left-color: $color;
    border-width: $size;
    top: $top;
  }
}

@mixin close($r: 0, $g: 0, $b: 0) {
  padding: 4px 6px;
  line-height: 1;
  font-size: 20px;
  cursor: pointer;
  color: rgba($r, $g, $b, 1);
  text-decoration: none;
  @include opacity(50);
  &:before {
    content: '\00D7';
  }
  &:hover {
    @include opacity(100);
  }
}

@mixin striped($color: rgba(255, 255, 255, .2), $angle: 45deg) {
  background-image: linear-gradient($angle, $color 25%, transparent 25%, transparent 50%, $color 50%, $color 75%, transparent 75%, transparent);
}

@mixin animation($animation) {
  animation: $animation;
}

@mixin fadeIn($duration: .25s) {
  @keyframes fadeIn {
    0% {
      opacity: 0;
    }

    100% {
      opacity: 1;
    }
  }

  animation-duration: $duration;
  animation-name: fadeIn;
  animation-iteration-count: 1;
}

// Grid
@mixin column($num) {
  width: math.div(math.div(variables.$grid-width - (variables.$grid-gutter-width * ($num - 1)), $num), (variables.$grid-width * 0.01)) * .01;
}

@mixin columns($factor, $num) {
  width: (math.div(math.div(variables.$grid-width - (variables.$grid-gutter-width * ($num - 1)), $num), (variables.$grid-width * 0.01)) * $factor) + (math.div(variables.$grid-gutter-width, (variables.$grid-width * 0.01)) * ($factor - 1)) * .01;
}

// Buttons
@mixin create-button($base-color, $hover-color, $text-color, $active-shadow: .5) {

  color: rgba(color.channel($text-color, "red", $space: rgb), color.channel($text-color, "green", $space: rgb), color.channel($text-color, "blue", $space: rgb), 1);
  background: $base-color;

  &:hover,
  &:active,
  &:focus {
    color: rgba(color.channel($text-color, "red", $space: rgb), color.channel($text-color, "green", $space: rgb), color.channel($text-color, "blue", $space: rgb), 1);
    background: $hover-color;
  }
  
  &:hover {
    transform: translateY(0) scale(1.05, 1.05);
  }

  &:focus,
  &:active {
    transform: translateY(0) scale(.95, .95);
    background: color.adjust($hover-color,$lightness: -5%);
    box-shadow: 0 0 10px color.adjust($hover-color,$lightness: -15%) inset;
  }

  &.btn-active {
    box-shadow: 0 1px 4px rgba(0, 0, 0, $active-shadow) inset;
  }

  &.btn-active,
  &.btn-disabled,
  &.btn[disabled] {
    cursor: not-allowed;
    color: rgba(color.channel($text-color, "red", $space: rgb), color.channel($text-color, "green", $space: rgb), color.channel($text-color, "blue", $space: rgb), .5);
    background: $hover-color;

    &:hover {
      color: rgba(color.channel($text-color, "red", $space: rgb), color.channel($text-color, "green", $space: rgb), color.channel($text-color, "blue", $space: rgb), .5);
      transform: scale(1,1);
    }

    &:active,
    &:focus {
      transform: scale(1,1);
      box-shadow: 0 0 0;
    }
  }

  &.btn-disabled,
  &.btn[disabled] {
    background: color.adjust($hover-color, $saturation: -50%);
  }

  &.btn-outline {
    background: none;
    border-color: $base-color;
    color: $base-color;
    &:hover {
      color: rgba(color.channel($text-color, "red", $space: rgb), color.channel($text-color, "green", $space: rgb), color.channel($text-color, "blue", $space: rgb), 1);
      background: $base-color;
    }
  }

  &.btn-outline.btn[disabled],
  &.btn-outline.btn-disabled {
    background: none;
    box-shadow: none;
    color: rgba(color.channel($base-color, "red", $space: rgb), color.channel($base-color, "green", $space: rgb), color.channel($base-color, "blue", $space: rgb), .5);
    border: 1px solid rgba(color.channel($base-color, "red", $space: rgb), color.channel($base-color, "green", $space: rgb), color.channel($base-color, "blue", $space: rgb), .3);
  }
  &.btn-outline.btn-active {
    background: none;
    color: rgba(color.channel($base-color, "red", $space: rgb), color.channel($base-color, "green", $space: rgb), color.channel($base-color, "blue", $space: rgb), 1);
    border: none;
    box-shadow: 0 1px 3px rgba(color.channel($hover-color, "red", $space: rgb), color.channel($hover-color, "green", $space: rgb), color.channel($hover-color, "blue", $space: rgb), .6) inset;
  }
}

// Theme-aware button using CSS custom properties
// $color-var: the custom property name (e.g. --ply-blue)
// $text-color: text color for the filled button
@mixin create-theme-button($color-var, $text-color: #fff) {
  color: $text-color;
  background: var(#{$color-var}-1);

  &:hover,
  &:active,
  &:focus {
    color: $text-color;
    background: var(#{$color-var}-2);
  }

  &:hover {
    transform: translateY(0) scale(1.05, 1.05);
  }

  &:focus,
  &:active {
    transform: translateY(0) scale(.95, .95);
    background: var(#{$color-var}-3);
    box-shadow: 0 0 10px rgba(0, 0, 0, .15) inset;
  }

  &.btn-active {
    box-shadow: 0 1px 4px rgba(0, 0, 0, .5) inset;
  }

  &.btn-active,
  &.btn-disabled,
  &.btn[disabled] {
    cursor: not-allowed;
    opacity: 0.5;
    background: var(#{$color-var}-2);

    &:hover {
      opacity: 0.5;
      transform: scale(1,1);
    }

    &:active,
    &:focus {
      transform: scale(1,1);
      box-shadow: 0 0 0;
    }
  }

  &.btn-disabled,
  &.btn[disabled] {
    background: var(#{$color-var}-2);
  }

  &.btn-outline {
    background: none;
    border-color: var(#{$color-var}-1);
    color: var(#{$color-var}-1);
    opacity: 1;

    &:hover {
      color: $text-color;
      background: var(#{$color-var}-1);
    }
  }

  &.btn-outline.btn[disabled],
  &.btn-outline.btn-disabled {
    background: none;
    box-shadow: none;
    opacity: 0.4;
    border: 1px solid var(#{$color-var}-1);
    color: var(#{$color-var}-1);
  }

  &.btn-outline.btn-active {
    background: none;
    color: var(#{$color-var}-1);
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3) inset;
  }
}

@mixin text-shadow($x: 2px, $y: 2px, $distance: 5px, $color: rgba(0,0,0,.5)) {
    text-shadow: $x $y $distance $color;
}

@mixin box-shadow($x: 2px, $y: 2px, $distance: 5px, $color: rgba(0,0,0,.5)) {
    box-shadow: $x $y $distance $color;
}

@mixin color-opacity($color: colors.$color-white, $opacity: 0.5) {
  background-color: rgba($color, $opacity);
}

@mixin centered($space: auto) {
  margin: $space auto;
}

@mixin uppercase() {
  text-transform: uppercase;
}
