//
// University of Edinburgh brand colours
// --------------------------------------------------
//
// In compilation, the $brand-color and $brand-link-color variables are
// looked up using the $brand key variable, set in the entry SASS file.
//
// The RGB colour values in this file have been approved for use in the
// University brand and have been tested for accessibility/contrast.
//
// Advice on what colours can be used while maintaining the University
// brand is available from Communications and Marketing.

@use "functions";
@use "colours";

$brand: "red" !default;
$google-fonts: false !default;
$custom-font-path: null !default;

@mixin configure($brand: null, $google-fonts: null, $custom-font-path: null) {
  @if $brand {
    $brand: $brand !global;
  }
  @if $google-fonts {
    $google-fonts: $google-fonts !global;
  }
  @if $custom-font-path {
    $custom-font-path: $custom-font-path !global;
  }
}

@function palette($brand) {
  $edgel-colours: (
    "blue-bright":          #007288,
    "blue-bright-link":     #e0ffff,
    "blue-muted":           #004f71,
    "blue-muted-link":      #c5eff7,
    "blue-university":      #041e42,
    "blue-university-link": #19b5fe,
    "brown":                #6d4f47,
    "brown-link":           #ffd700,
    "burgundy":             #a50034,
    "burgundy-link":        #f7ca18,
    "centre-sport-exercise":      #78624a,
    "centre-sport-exercise-link": #ffe75c,
    "green-dark":           #154734,
    "green-dark-link":      #f2ca27,
    "grey-dark":            colours.$gray-900,
    "grey-dark-link":       colours.$dark-link-hover-color,
    "grey-spruce":          #333f48,
    "grey-spruce-link":     #add8e6,
    "jade":                 #487a7b,
    "jade-link":            #e0ffff,
    "pink":                 #d0006f,
    "pink-link":            #80ffff,
    "purple":               #830065,
    "purple-link":          #81cfe0,
    "red":                  #d50032,
    "red-link":             #e4f1fe
  );

  $brand-color: map-get($edgel-colours, $brand);
  @if ($brand-color == null) {
    @error "Brand colour #{$brand} not known";
  }

  $brand-link-color: map-get($edgel-colours, "#{$brand}-link");
  @if ($brand-link-color == null) {
    @error "Link colour for #{$brand} brand colour not known";
  }

  $brand-bg-text: functions.color-contrast($brand-color);
  $brand-hover: functions.brand-highlight-colour($brand-color, colours.$btn-hover-bg-shade-amount, colours.$btn-hover-bg-tint-amount);
  $brand-link-hover: $brand-link-color;
  $brand-as-link: $brand-color;
  $brand-as-link-hover: functions.brand-highlight-colour($brand-color, colours.$btn-active-bg-shade-amount, colours.$btn-active-bg-tint-amount);

  // If the brand colour is light and does not have enough contrast against
  // white, we override the colours to maintain contrast.
  //  * White text on brand colour background becomes black(-ish).
  //  * Brand colour used for a link becomes dark grey.
  @if ($brand-bg-text != colours.$color-contrast-light) {
    $brand-bg-text: colours.$color-contrast-dark;
    $brand-as-link: colours.$gray-600;
    $brand-as-link-hover: colours.$color-contrast-dark;
  }

  @return (
    brand-color: $brand-color,
    brand-hover: $brand-hover,
    brand-link-color: $brand-bg-text,
    brand-link-hover: $brand-link-hover,
    brand-bg-text: $brand-bg-text,
    brand-as-link: $brand-as-link,
    brand-as-link-hover: $brand-as-link-hover
  );
}

// eslint-disable-next-line scss/dollar-variable-default
$edgel-palette: palette($brand);
$brand-color: map-get($edgel-palette, "brand-color") !default;
$brand-hover: map-get($edgel-palette, "brand-hover") !default;
$brand-link-color: map-get($edgel-palette, "brand-link-color") !default;
$brand-link-hover: map-get($edgel-palette, "brand-link-hover") !default;
$brand-bg-text: map-get($edgel-palette, "brand-bg-text") !default;
$brand-as-link: map-get($edgel-palette, "brand-as-link") !default;
$brand-as-link-hover: map-get($edgel-palette, "brand-as-link-hover") !default;

$use-google-fonts: $google-fonts !default;
$font-path: $custom-font-path !default;
