// generic drawing of more complex things

// ripple effect animations

@keyframes ripple {
  from {
    background-image: radial-gradient(circle farthest-corner at center, $overlay-checked 30%, transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center, $overlay-checked 100%, transparent 0%);
  }
}

@keyframes ripple-on-slider {
  from {
    background-image: radial-gradient(circle farthest-corner at center, $overlay-active 0%, transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center, $overlay-active 100%, transparent 0%);
  }
}

@keyframes ripple-on-headerbar {
  from {
    background-image: radial-gradient(circle farthest-corner at center, $primary 30%, transparent 0%);
  }

  to {
    background-image: radial-gradient(circle farthest-corner at center, $primary 100%, transparent 0%);
  }
}

@mixin entry($t, $fc: $primary) {
//
// entry
//
// $t: entry type
// $fc: focus color
//

  @if $t == normal {
    transition: outline-color $ripple-fade-out-duration $ease-out,
                outline-width $ripple-fade-out-duration $ease-out,
                outline-offset $ripple-fade-out-duration $ease-out;
    outline: 0 solid transparent;
    outline-offset: 4px;
    background-color: $entry;
    color: if($fc == $primary, $text, $fc);
  }

  @if $t == hover {
    background-color: $overlay-hover;
    color: if($fc == $primary, $text, $fc);
    outline: 2px solid $overlay-hover;
    outline-offset: -2px;
  }

  @if $t == focus {
    background-color: $overlay-focus;
    color: if($fc == $primary, $text, $fc);
    outline: 2px solid if($fc == $primary, $track, $fc);
    outline-offset: -2px;
  }

  @if $t == checked {
    background-color: $entry;
    color: if($fc == $primary, $text, $fc);
    outline-color: if($fc == $primary, $primary, $fc);
    outline-width: 2px;
    outline-offset: -2px;
  }

  @if $t == disabled {
    background-color: $entry;
    color: if($fc == $primary, $text-disabled, rgba($fc, 0.35));
    outline: none;
    filter: none;
    opacity: 1;
  }
}


@mixin button($t) {
//
// button
//
// $t: button type
//

  @if $t == normal {
    transition: $transition,
                background-size 0,
                background-image 0;
    outline: none;
    box-shadow: inset 0 0 0 2px transparent;
    background-color: $button;
    background-image: radial-gradient(circle, transparent 0%, transparent 0%);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 1000% 1000%;
    color: $text;
  }

  @if $t == hover {
    background-color: $overlay-hover;
  }

  @if $t == focus {
    box-shadow: inset 0 0 0 2px $overlay-focus;
  }

  @if $t == active {
    transition: $transition,
                background-size 0ms,
                background-image 0ms,
                border 0ms;
    animation: ripple $ripple-fade-in-duration $ease-out forwards;
    background-color: $overlay-hover;
    background-image: radial-gradient(circle, $overlay-active 10%, transparent 0%);
    background-size: 100% 100%;
  }

  @if $t == disabled {
    box-shadow: none;
    background-color: $button;
    color: $text-disabled;
    filter: none;
    opacity: 1;
  }

  @if $t == checked {
    box-shadow: none;
    background-color: $primary;
    color: on($primary);
  }

  @if $t == checked-hover {
    box-shadow: inset 0 0 0 2px transparent;
  }

  @if $t == checked-disabled {
    background-color: $overlay-checked;
    color: $text-disabled;
  }

  @if $t == flat-normal {
    transition: $transition,
                background-size 0,
                background-image 0;
    outline: none;
    box-shadow: inset 0 0 0 2px transparent;
    background-color: transparent;
    background-image: radial-gradient(circle, transparent 0%, transparent 0%);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 1000% 1000%;
    color: $text-secondary;
  }

  @if $t == flat-hover {
    background-color: $overlay-hover;
    color: $text;
  }

  @if $t == flat-focus {
    box-shadow: inset 0 0 0 2px $overlay-focus;
    color: $text;
  }

  @if $t == flat-active {
    transition: $transition,
                background-size 0ms,
                background-image 0ms;
    animation: ripple $ripple-fade-in-duration $ease-out forwards;
    background-color: $overlay-hover;
    background-image: radial-gradient(circle, $overlay-active 10%, transparent 0%);
    background-size: 100% 100%;
    color: $text;
  }

  @if $t == flat-disabled {
    box-shadow: none;
    background-color: transparent;
    color: $text-secondary-disabled;
  }

  @if $t == flat-checked {
    background-color: $overlay-checked;
    color: $text;
  }

  @if $t == flat-checked-disabled {
    background-color: $overlay-checked;
    color: $text-disabled;
  }
}


@mixin overshoot($p) {
//
// overshoot
//
// $p: position
// $t: type
// $c: base color
//
// possible $p values:
// top, bottom, right, left
//
// possible $t values:
// normal, backdrop
//

  $_position: center $p;

  @if ($p == left) or ($p == right) {
    $_position: $p center;
  }

  background-size: 200% 70%;
  background-image: radial-gradient( farthest-side at $p, $fill 99%, transparent 100%);
  background-repeat: no-repeat;
  background-position: $_position;

  background-color: transparent; // reset some properties to be sure to not inherit them somehow
  border: none;                  //
  box-shadow: none;              //
}


@mixin undershoot($p, $c: $frame, $neighbor: false, $style: compact) {
//
// undershoot
//
// $p: position
// $c: shade color
// $neighbor: use ~ instead of >
//
// possible $p values:
// top, bottom, right, left
//

  $_border_pos: '';
  $_direction: '';
  $_selector: if($neighbor, '~', '>');

  @if $p==top {
    $_direction: bottom;
    $_border_pos: 0 1px;
  } @else if $p==bottom {
    $_direction: top;
    $_border_pos: 0 -1px;
  } @else if $p==left {
    $_direction: right;
    $_border_pos: 1px 0;
  } @else if $p==right {
    $_direction: left;
    $_border_pos: -1px 0;
  } @else {
    @error "Unknown position #{$p}"
  }

  #{$_selector} undershoot.#{$p} {
    @if $style == 'compact' {
      box-shadow: none;
    } @else {
      box-shadow: inset $_border_pos $border;
    }

    background: linear-gradient(to $_direction, gtkalpha($c, .75), transparent 4px);
  }
}
  
@mixin background-shadow($direction, $color) {
  background-image:
    linear-gradient($direction,
                    gtkalpha($color, 0.7),
                    gtkalpha($color, 0.14) 40px,
                    gtkalpha($color, 0) 56px),
    linear-gradient($direction,
                    gtkalpha($color, 0.4),
                    gtkalpha($color, 0.14) 7px,
                    gtkalpha($color, 0) 24px);
}

@mixin transition-shadows($color) {
  > dimming {
    background: $color;
  }

  > border {
    background: none;
  }

  > shadow {
    min-width: 56px;
    min-height: 56px;

    &.left  { @include background-shadow(to right,  $color); }
    &.right { @include background-shadow(to left,   $color); }
    &.up    { @include background-shadow(to bottom, $color); }
    &.down  { @include background-shadow(to top,    $color); }
  }
}
