/*
 * EdGEL Mixins
 * --------------------------------------------------
 * All function prefixed "edgel-" when imported
 */

@use "bootstrap" as bs;
@use "../settings" as edgel;

/* Box shadows */
@mixin shadow() {
  $shadow: 0 4px 6px -5px rgba(0, 0, 0, .3), 0 0 1px rgba(0, 0, 0, .1);
  @include bs.box-shadow($shadow);
}

@mixin shadow-light() {
  $shadow: 0 2px 1px -1px rgba(0, 0, 0, .15);
  @include bs.box-shadow($shadow);
}

/* Top line border */
@mixin topline($width: 8px) {
  border-top: $width solid edgel.$brand-color;
}

/* Brand background with special link text colour */
@mixin brand-bg() {
  color: edgel.$brand-bg-text;
  background-color: edgel.$brand-color;
  a:not(.btn) {
    &,
    &:visited {
      color: edgel.$brand-link-color;
    }
    &:hover,
    &:focus {
      color: edgel.$brand-link-hover;
    }
  }
}

/* Dark grey background with special link text colour */
@mixin dark-bg() {
  color: edgel.$white;
  background-color: edgel.$dark;
  a:not(.btn) {
    color: edgel.$dark-link-color;
    &:hover,
    &:focus {
      color: edgel.$dark-link-color;
    }
  }
}

@function px-rem($px) {
  @return #{$px / edgel.$rfs-rem-value}rem;
}

@function rem-px($rem) {
  @return #{$rem * edgel.$rfs-rem-value}px;
}

/* Width-restricting container */
@mixin container($vertical-space-sm: null, $vertical-space: null, $top: true) {
  width: 100%;
  max-width: edgel.$font-size-base * 90;
  padding-top: if($top, edgel.space($vertical-space-sm), null);
  padding-right: edgel.space(3);
  padding-bottom: edgel.space($vertical-space-sm);
  padding-left: edgel.space(3);
  margin-right: auto;
  margin-left: auto;

  @include bs.media-breakpoint-up(md) {
    padding-top: if($top, edgel.space($vertical-space), null);
    padding-right: edgel.space(5);
    padding-bottom: edgel.space($vertical-space);
    padding-left: edgel.space(5);
  }
}

/* Scale images */
@mixin scale($property, $x1, $x2, $v1: 500px, $v2: 1500px) {
  @if $x2 <= $x1 {
    @error "$x2 must be greater than $x1";
  }
  @if $v2 <= $v1 {
    @error "$v2 must be greater than $v1";
  }
  @if unit($x1) != unit($x2) or unit($x1) != unit($v1) or unit($x1) != unit($v2) {
    @error "All parameter units must match";
  }

  $gradient: (($x2 - $x1) / ($v2 - $v1));
  $offset: $x1 - $v1 * $gradient;

  // stylelint-disable-next-line function-disallowed-list
  #{$property}: calc(#{$offset} + #{$gradient} * 100vw);
  @media (min-width: $v2) {
    #{$property}: $x2;
  }
}
