// generic drawing of more complex things


// ripple effect animations

@keyframes ripple_effect {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.001,
                                    to(gtkalpha(currentColor, $lower_opacity / 2)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, 0));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.4,
                                    to(gtkalpha(currentColor, $lower_opacity / 2)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, $lower_opacity / 2));
  }
}

@keyframes flat_ripple_effect {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.001,
                                    to(gtkalpha(currentColor, $lower_opacity / 2)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, $lower_opacity / 2));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.4,
                                    to(gtkalpha(currentColor, $lower_opacity / 2)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, $lower_opacity / 2));
  }
}

@keyframes list_ripple_effect {
  from {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.001,
                                    to(gtkalpha(currentColor, $lower_opacity / 2)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, 0));
  }
  to {
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.4,
                                    to(gtkalpha(currentColor, $lower_opacity / 2)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, 0));
  }
}

// entries

@mixin entry($t, $fc:$primary_color) {
//
// Entries drawing function
//
// $t: entry type
// $fc: focus color
//
// possible $t values:
// normal, focus, insensitive, flat-normal, flat-focus, flat-insensitive;
//

  @if $t==normal {
    transition: $longer_transition, $shadow_transition;
    box-shadow: $shadow_1;
    background-color: if($fc!=$primary_color, $fc, $base_color);
    color: if($fc!=$primary_color, $inverse_fg_color, $fg_color);
  }

  @if $t==focus {
    box-shadow: $shadow_2;
  }

  @if $t==insensitive {
    color: $disabled_fg_color;
    background-color: $alt_base_color;
  }

  @if $t==flat-normal {
    transition: $longer_transition;
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.001,
                                to($fc),
                                to(transparent))
                                0 0 0 / 0 0 0px;
    border-radius: 0;
    box-shadow: inset 0 -1px if($fc!=$primary_color, $fc, $fill_color);
    background-color: transparent;
    color: $fg_color;
  }

  @if $t==flat-focus {
    border-image: -gtk-gradient(radial,
                                center bottom, 0,
                                center bottom, 0.5,
                                to($fc),
                                to(transparent))
                                0 0 2 / 0 0 2px;
    box-shadow: inset 0 -2px $fc;
    transition: $longer_transition, box-shadow 0 $longer_duration;
  }

  @if $t==flat-insensitive {
    box-shadow: inset 0 -1px $fill_color;
    background-color: transparent;
    color: $disabled_fg_color;
  }
}

// buttons

@mixin button($t, $c:$lighter_bg_color, $tc:$fg_color) {
//
// Button drawing function
//
// $t:    button type,
// $c:    base button color for colored* types
// $tc:   optional text color for colored* types
//
// possible $t values:
// normal, hover, active, insensitive, checked, checked-insensitive,
// flat-normal, flat-hover, flat-active, flat-insensitive, flat-checked, flat-checked-insensitive;
//

  @if $t==normal {
    transition: $longer_transition, $shadow_transition;
    box-shadow: $shadow_1;
    background-color: $c;
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to(gtkalpha(currentColor, 0)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, 0));
    color: $secondary_fg_color;
  }

  @else if $t==hover {
    box-shadow: $shadow_2;
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to(gtkalpha(currentColor, 0)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, 0));
    color: $fg_color;
  }

  @else if $t==active {
    transition: $longer_transition, $shadow_transition, background-image 0;
    animation: ripple_effect $longer_duration $deceleration_curve forwards;
    box-shadow: $shadow_2;
    color: $fg_color;
  }

  @else if $t==insensitive {
    box-shadow: none;
    background-color: $fill_color;
    color: if($tc!=$fg_color, $disabled_fg_color, $disabled_secondary_fg_color);

    > .label { color: inherit; }
  }

  @else if $t==checked {
    background-color: $primary_color;
    color: $inverse_fg_color;
  }

  @else if $t==checked-insensitive {
    background-color: $fill_color;
    color: scale-alpha($primary_color, $disabled_opacity);
    > .label { color: inherit; }
  }

  @else if $t==flat-normal {
    transition: $longer_transition;
    box-shadow: none;
    background-color: transparent;
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to(gtkalpha(currentColor, 0)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, 0));
    color: gtkalpha(currentColor, $secondary_opacity);
  }

  @else if $t==flat-hover {
    box-shadow: none;
    background-image: -gtk-gradient(radial,
                                    center center, 0,
                                    center center, 0.5,
                                    to(gtkalpha(currentColor, 0)),
                                    to(transparent)),
                      linear-gradient(to bottom, gtkalpha(currentColor, $lower_opacity / 2));
    color: currentColor;
  }

  @else if $t==flat-active {
    transition: $longer_transition, background-image 0;
    animation: flat_ripple_effect $longer_duration $deceleration_curve forwards;
    box-shadow: none;
    color: currentColor;
  }

  @else if $t==flat-insensitive {
    box-shadow: none;
    background-color: transparent;
    color: if($tc != $fg_color, gtkalpha(currentColor, $disabled_opacity), gtkalpha(currentColor, $secondary_opacity * $disabled_opacity));

    > .label { color: inherit; }
  }

  @else if $t==flat-checked {
    background-color: $fill_color;
    color: currentColor;
  }

  @else if $t==flat-checked-insensitive {
    background-color: $fill_color;
    color: gtkalpha(currentColor, $disabled_opacity);

    > .label { color: inherit; }
  }
}

@mixin overshoot($p, $t:normal, $c:$alt_primary_color) {
//
// 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-image: -gtk-gradient(radial,
                                  $_position, 0,
                                  $_position, 0.75,
                                  to(scale-alpha($c, $lower_opacity)),
                                  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: scale-alpha($fg_color, $lower_opacity);
  $_undershoot_color_light: scale-alpha($base_color, $lower_opacity);

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

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

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

  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;
}
