// Drawing mixins

// generic drawing of more complex things

//
// Helper mixin for drawing visible focus rings
//
// If $target is specified, the focus ring is applied to the specified child element.
// If $outer is true, the focus ring extends outward. Otherwise, it extends inward.
// If $within is true, use focus-within instead of focus:focus-visible
//
@mixin focus-ring($target: null, $width: 2px, $offset: -$width, $outer: false, $focus-state: ':focus:focus-visible', $fc: $focus_border_color, $transition: null) {
  & #{$target} {
    outline: 0 solid transparent;
    outline-offset: if($outer, $offset + 4px, $offset + $width + 4px);
    transition: $focus_transition, $transition;
  }

  &#{$focus-state} #{$target} {
    outline-color: $fc;
    outline-width: $width;
    outline-offset: $offset;
  }
}

@mixin undershoot($p, $c: $shade_color, $neighbor: false) {
//
// 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} {
    box-shadow: inset $_border_pos if($contrast == 'high', $border_color, gtkalpha($c, .75));
    background: linear-gradient(to $_direction, gtkalpha($c, .75), transparent 4px);
  }
}

@mixin overshoot($p) {
//
// overshoot
//
// $p: position
//
// possible $p values:
// top, bottom, right, left
//

  $_small_gradient_length: 3%;
  $_big_gradient_length: 50%;

  $_small_gradient_size: 100% $_small_gradient_length;
  $_big_gradient_size: 100% $_big_gradient_length;

  @if $p==right or $p==left {
    $_small_gradient_size: $_small_gradient_length 100%;
    $_big_gradient_size: $_big_gradient_length 100%;
  }

  $_small_gradient: radial-gradient(farthest-side at $p,
                                    gtkalpha(currentColor, 0.12) 85%,
                                    gtkalpha(currentColor, 0));

  $_big_gradient: radial-gradient(farthest-side at $p,
                                  gtkalpha(currentColor, 0.05),
                                  gtkalpha(currentColor, 0));

  background-image: $_small_gradient, $_big_gradient;
  background-size: $_small_gradient_size, $_big_gradient_size;

  background-repeat: no-repeat;
  background-position: $p;

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

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

  @if $contrast == 'high' {
    > border {
      min-width: 1px;
      min-height: 1px;
      background: $border_color;
    }
  }

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