// 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 $ripple-fade-out-duration $ease-out,
                box-shadow $ripple-fade-out-duration $ease-out;
    box-shadow: inset 0 0 0 1px transparent;
    background-color: $base;
    color: $text;

    @if $variant == "light" {
      border-color: $border;
      border-bottom-color: $border-bottom;
    } @else {
      border-color: $border-bottom;
      border-top-color: $border;
    }
  }

  @if $t == hover {
    background-color: $base;
    box-shadow: inset 0 0 0 1px transparent;
    border-color: $text-disabled;
  }

  @if $t == focus {
    background-color: $base;
    box-shadow: inset 0 0 0 1px if($fc == $primary, $text-disabled, $fc);
    border-color: if($fc == $primary, $text-disabled, $fc);
  }

  @if $t == disabled {
    box-shadow: inset 0 0 0 1px transparent;
    background-color: $base-alt;
    color: $text-disabled;
    border-color: $fill;
  }

  @if $t == round-normal {
    transition: $transition,
                border-image $ripple-fade-out-duration $ease-out;
    background-color: if($fc == $primary, $base, $fc);
    color: if($fc == $primary, $text, on($fc));
    border-image-width: 4px 4px 4px 4px;
    border-image-slice: 4 4 4 4;
    border-image-repeat: stretch;
    border-image-source: -gtk-scaled(url("assets/entry-normal#{$asset-suffix}.png"),url("assets/entry-normal#{$asset-suffix}@2.png"));
  }

  @if $t == round-hover {
    border-image-source: -gtk-scaled(url("assets/entry-normal#{$asset-suffix}.png"),url("assets/entry-normal#{$asset-suffix}@2.png"));
  }

  @if $t == round-focus {
    border-image-source: -gtk-scaled(url("assets/entry-focus#{$asset-suffix}.png"),url("assets/entry-focus#{$asset-suffix}@2.png"));
  }

  @if $t == round-disabled {
    border-image-source: -gtk-scaled(url("assets/entry-disabled#{$asset-suffix}.png"),url("assets/entry-disabled#{$asset-suffix}@2.png"));
    background-color: $base-alt;
    color: $text-disabled;
  }
}


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

  @if $t == normal {
    transition: $transition,
                border $ripple-fade-out-duration $ease-out,
                box-shadow $ripple-fade-out-duration $ease-out;
    outline: none;
    box-shadow: inset 0 0 0 1px transparent, 0 0 0 2px transparent;
    background-color: $base;
    color: $text;

    @if $variant == "light" {
      border-color: $border;
      border-bottom-color: $border-bottom;
    } @else {
      border-color: $border-bottom;
      border-top-color: $border;
    }
  }

  @if $t == hover {
    box-shadow: inset 0 0 0 1px transparent, 0 0 0 2px transparent;
    // background-color: $base;
    border-color: $track;
  }

  @if $t == focus {
    box-shadow: inset 0 0 0 1px transparent, 0 0 0 2px $text-secondary;
    border-color: transparent;
    background-clip: padding-box;
  }

  @if $t == active {
    animation: none;
    transition: $transition,
                border $ripple-fade-out-duration $ease-out,
                box-shadow $ripple-fade-out-duration $ease-out;
    box-shadow: inset 0 0 0 1px $track, 0 0 0 2px transparent;
  }

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

  @if $t == checked {
    box-shadow: inset 0 0 0 1px transparent, 0 0 0 2px transparent;
    background-clip: border-box;
    background-color: $primary;
    color: on($primary);
    border-color: lighten($primary, 5%);
    border-bottom-color: darken($primary, 5%);
    transition: $transition, background-color $ripple-fade-out-duration $ease-out;
  }

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

  @if $t == checked-disabled {
    box-shadow: none;
    background-color: rgba($primary, 0.35);
    border-color: rgba($primary, 0.35);
    background-clip: padding-box;
    color: rgba(on($primary), 0.5);
  }

  @if $t == flat-normal {
    transition: $transition,
                box-shadow $ripple-fade-out-duration $ease-out;
    outline: none;
    box-shadow: inset 0 0 0 9999px transparent;
    background-color: transparent;
    border: none;
    color: $text-secondary;
  }

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

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

  @if $t == flat-active {
    animation: none;
    transition: $transition,
                box-shadow $ripple-fade-out-duration $ease-out;
    box-shadow: inset 0 0 0 9999px $overlay-active;
    background-color: transparent;
    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, $t:normal, $c:$text) {
//
// overshoot
//
// $p: position
// $t: type
// $c: base color
//
// possible $p values:
// top, bottom, right, left
//
// possible $t values:
// normal, backdrop
//

  $_small_gradient_length: 5%;
  $_big_gradient_length: 100%;

  $_position: center top;
  $_small_gradient_size: 100% $_small_gradient_length;
  $_big_gradient_size: 100% $_big_gradient_length;

  @if $p==bottom {
    $_position: center bottom;
    $_linear_gradient_direction: to top;
  }

  @else if $p==right {
    $_position: right center;
    $_small_gradient_size: $_small_gradient_length 100%;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  @else if $p==left {
    $_position: left center;
    $_small_gradient_size: $_small_gradient_length 100%;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  $_small_gradient_color: $c;
  $_big_gradient_color: $c;

  @if $c==$text {
    $_small_gradient_color: $border;
    $_big_gradient_color: $text;

    @if $t==backdrop { $_small_gradient_color: $fill; }
  }

  $_small_gradient: -gtk-gradient(radial,
                                  $_position, 0,
                                  $_position, 0.5,
                                  to($_small_gradient_color),
                                  to(rgba($_small_gradient_color, 0)));

  $_big_gradient: -gtk-gradient(radial,
                                $_position, 0,
                                $_position, 0.6,
                                from(rgba($_big_gradient_color, 0.07)),
                                to(rgba($_big_gradient_color, 0)));

  @if $t==normal {
    background-image: $_small_gradient, $_big_gradient;
    background-size: $_small_gradient_size, $_big_gradient_size;
  }

  @else if $t==backdrop {
    background-image: $_small_gradient;
    background-size: $_small_gradient_size;
  }

  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: transparent;

  $_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;
  margin: 0 4px;

  @if ($p == left) or ($p == right) {
    margin: 4px 0;
  }
}
