// generic drawing of more complex things


// ripple effect animations

@keyframes ripple {
  to { background-size: 1000% 1000%; }
}

@keyframes ripple-on-slider {
  to { background-size: auto, 1000% 1000%; }
}

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

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


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

  @if $t == normal {
    transition: $transition, border-image $ripple-fade-in-duration $ease-out;
    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $fc 0%,
                                  transparent 0%)
                                  0 0 0 / 0 0 0px;
    box-shadow: inset 0 0 0 9999px transparent, inset 0 -1px if($fc == $primary, $track, $fc);
    background-color: $fill;
    color: $text;
  }

  @if $t == hover {
    box-shadow: inset 0 0 0 9999px $overlay-hover, inset 0 -1px if($fc == $primary, $track, $fc);
  }

  @if $t == focus {
    box-shadow: inset 0 0 0 9999px $overlay-focus, inset 0 -1px if($fc == $primary, $track, $fc);
  }

  @if $t == checked {
    border-image: radial-gradient(circle closest-corner at center calc(100% - 1px),
                                  $fc 100%,
                                  transparent 0%)
                                  0 0 2 / 0 0 2px;
  }

  @if $t == disabled {
    box-shadow: inset 0 0 0 9999px transparent, inset 0 -1px $track-disabled;
    background-color: $fill;
    color: $text-disabled;
  }

  @if $t == raised-normal {
    transition: $transition;
    border-image: none;
    box-shadow: $shadow-1;
    background-color: if($fc == $primary, $base, $fc);
    color: if($fc == $primary, $text, on($fc));
  }

  @if $t == raised-hover {
    box-shadow: $shadow-2;
  }

  @if $t == raised-focus {
    border-image: none;
    box-shadow: $shadow-2;
  }

  @if $t == raised-disabled {
    box-shadow: $shadow-1;
    background-color: $base-alt;
    color: $text-disabled;
  }
}


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

  @if $t == normal {
    transition: $transition,
                background-size $ripple-fade-out-duration $ease-out,
                background-image $ripple-fade-out-opacity-duration $ease-out;
    outline: none;
    box-shadow: inset 0 0 0 9999px transparent, $shadow-1;
    background-color: $surface;
    background-image: radial-gradient(circle, transparent 10%, transparent 0%);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 1000% 1000%;
    color: $text;
  }

  @if $t == hover {
    box-shadow: inset 0 0 0 9999px transparent, $shadow-2;
    color: $text;
  }

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

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

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

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

  @if $t == checked-disabled {
    box-shadow: inset 0 0 0 9999px $overlay-checked;
    background-color: $fill;
    color: $text-disabled;
  }

  @if $t == flat-normal {
    transition: $transition,
                border-image $ripple-fade-in-duration $ease-out,
                background-size $ripple-fade-out-duration $ease-out,
                background-image $ripple-fade-out-opacity-duration $ease-out;
    outline: none;
    box-shadow: inset 0 0 0 9999px transparent;
    background-color: transparent;
    background-image: radial-gradient(circle, transparent 10%, transparent 0%);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 1000% 1000%;
    color: $text-secondary;
  }

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

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

  @if $t == flat-active {
    transition: $transition,
                border-image $ripple-fade-in-duration $ease-out,
                background-size 0ms,
                background-image 0ms;
    animation: ripple $ripple-fade-in-duration $ease-out forwards;
    box-shadow: inset 0 0 0 9999px $overlay-hover;
    background-image: radial-gradient(circle, $overlay-active 10%, transparent 0%);
    background-size: 0% 0%;
    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
//
// possible $p values:
// top, bottom, right, left
//

  $_position: center $p;

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

  background-image: -gtk-gradient(radial,
                                  $_position, 0,
                                  $_position, 0.75,
                                  to(rgba($primary, 0.24)),
                                  to(transparent));

  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) {
//
// undershoot
//
// $p: position
//
// possible $p values:
// top, bottom, right, left
//

  $_undershoot_color_dark: $track;
  $_undershoot_color_light: rgba($base, 0.3);

  $_gradient_dir: left;
  $_dash_bg_size: 12px 1px;
  $_gradient_repeat: repeat-x;
  $_bg_pos: left $p;

  @if ($p == left) or ($p == right) {
    $_gradient_dir: top;
    $_dash_bg_size: 1px 12px;
    $_gradient_repeat: repeat-y;
    $_bg_pos: $p top;
  }

  background-color: transparent; // shouldn't be needed, but better to be sure

  background-image: linear-gradient(to $_gradient_dir, // this is the dashed line
                                    $_undershoot_color_light 50%,
                                    $_undershoot_color_dark 50%);

  padding-#{$p}: 1px;
  background-size: $_dash_bg_size;
  background-repeat: $_gradient_repeat;
  background-origin: content-box;
  background-position: $_bg_pos;
}
