/**
 * Bootstrap functions
 *
 * These are required for variable setting, hence why this does not appear under
 * tools.
 */

@use "colours" as *;
@use "variables" as *;
@import "bootstrap/scss/functions";

// Helper function for spacing values elsewhere
@function space($i) {
  @return map-get($spacers, $i);
}

// Helper function to determine button hover colour
@function brand-highlight-colour($value, $shade-amount, $tint-amount) {
  $max-ratio: 0;
  $max-ratio-color: null;
  $light-hovers: tint-color($value, $tint-amount), $gray-100, shade-color($value, $shade-amount);
  $dark-hovers: shade-color($value, $shade-amount), $gray-900, tint-color($value, $tint-amount);

  $contrast: color-contrast($value);
  $hovers: if($contrast == $color-contrast-light, $dark-hovers, $light-hovers);
  @each $hover-colour in $hovers {
    $hover-ratio: contrast-ratio($value, $hover-colour);
    $hover-text-contrast-ratio: contrast-ratio($hover-colour, $contrast);

    @if ($hover-ratio > $btn-min-hover-contrast-ratio and $hover-text-contrast-ratio > $min-contrast-ratio) {
      @return $hover-colour;
    } @else if $hover-ratio > $max-ratio {
      $max-ratio: $hover-ratio;
      $max-ratio-color: $hover-colour;
    }
  }

  @warn "Found no hover color leading to #{$btn-min-hover-contrast-ratio}:1 contrast ratio against #{$value}...";
  @return $max-ratio-color;
}
