/**
 * Mixins
 * Contains global SCSS mixins
 */

/// Clearfix
@mixin clearfix() {
  &:after {
    display: table;
    content: '';
    clear: both;
  }
}

/// Image replacement
@mixin ir {
  text-indent: 100%;
  white-space: nowrap;
  overflow: hidden;
  border: 0;                     // Remove the default border from elements like <button>
  font: 0/0 a;                   // Crush the text down to take up no space
  text-shadow: none;             // Remove any text shadows
  color: transparent;            // Hide any residual text in Safari 4 and any mobile devices that may need it
  background-color: transparent; // Hide the default background color on elements like <button>
}

/// Invisible elements
@mixin element-invisible {
  border: 0;
  height: 1px;
  overflow: hidden;
  padding: 0;
  position: absolute !important;
  width: 1px;
  clip: rect(1px, 1px, 1px, 1px);
}

/// Show an invisible element
@mixin element-invisible-off {
  position: static !important;
  clip: auto;
  height: auto;
  width: auto;
  overflow: auto;
}

/// Show invisible element when focused
@mixin element-focusable {
  @include element-invisible;

  &:active,
  &:focus {
    @include element-invisible-off;
  }
}

/// Mixin to calculate rem size
@function calculateRem($size) {
  $remSize: $size / 16px;
  @return #{$remSize}rem;
}
@mixin fontsize($size) {
  font-size: $size;
  font-size: calculateRem($size);
}

/// Full width mixin to break content out into gutters
@mixin full-width() {
  width: 100vw;
  position: relative;
  left: 50%;
  margin-left: -50vw;
}

/// Content Gutter
@mixin gutter {
  padding-left: 16px;
  padding-right: 16px;

  @media screen and (min-width: $break-medium) {
    padding-left: 50px;
    padding-right: 50px;
  }

  @media screen and (min-width: $break-large) {
    padding-left: 80px;
    padding-right: 80px;
  }
}

/// Maximum width Object
@mixin content-full {
  max-width: $content-max;
  margin-left: auto;
  margin-right: auto;
}

/// Gradient overlay
@mixin gradient-overlay {
  &::after {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    height: 100%;
    width: 100%;
    background: linear-gradient(to bottom, rgba($color-white, 0) 0%, rgba($color-white, 0) 45%, $color-black 100%);
    content: '';
  }
}

/// Placeholder mixin
@mixin placeholder {
  &::-webkit-input-placeholder {
    @content
  }

  &:-moz-placeholder {
    @content
  }

  &::-moz-placeholder {
    @content
  }

  &:-ms-input-placeholder {
    @content
  }
}


/// CTA mixin
/// Parameters:
/// button = primary or secondary - sets the button type
/// background = light or dark - sets the focus state

// to do: remove anchor and make sure the padding is within the anchor tag

@mixin cta($button, $background) {
  @if $button == primary {
        display: block;
        color: $color-white;
        border-radius: .5rem;
        background-color: $color-green-dark;
        font-weight: 800;
        max-width: fit-content;
        transition: 300ms all ease;
        font-family: $font-acumen-cond;
        &:hover {
          background-color: $color-green-light;
          color: $color-green-dark;
        }
  } @else if $button == secondary {
        display: block;
        color: $color-white;
        background-color: $color-blue-dark;
        font-weight: 800;
        max-width: fit-content;
        transition: 300ms all ease;
        font-family: $font-acumen-cond;
        &:hover {
          background-color: $color-blue-light;
          color: $color-blue-dark;
        }
  }

  @if $background == light {
      &:focus {
        outline: 2px solid $color-white;
        outline-offset: 2px;
      }
  } @else if $background == dark {
      &:focus {
        outline: 2px solid $color-black;
        outline-offset: 2px;
      }
  }

    font-size: 1rem;
    line-height: 1.3;
    padding: 11px 18px;
    @media (min-width: $break-medium) {
        font-size: 1.111rem;
        line-height: 1;
        padding: 16px 24px;
    }
    @media (min-width: $break-large) {
        font-size: 2rem;
        line-height: 1;
        padding: 24px 48px;
    }
}

@function str-replace($string, $search, $replace: '') {
    $index: str-index($string, $search);

    @if $index {
        @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
    }

    @return $string;
}

// Parameters:
// $border-color = sets the outline color
// $fill-color = sets fill/background color
// $font-color = sets font and arrow color
// $hover-border = sets hover border
// $hover-fill = sets hover fill/background color
// $hover-font = sets hover font color
@mixin cta-arrow($border-color: $color-green-dark, $fill-color: $color-green-dark, $font-color: $color-green-light, $hover-border: $color-green-light, $hover-fill: $color-green-light, $hover-font: $color-green-dark) {
    position: relative;
    display: inline-block;
    font-weight: 600;
    font-family: $font-acumen;
    color: $font-color;
    border: 1px solid $border-color;
    background-color: $fill-color;
    border-radius: 8px;
    &:after {
        content: '';
        display: inline-block;
        vertical-align: middle;
        position: absolute;
        bottom: 13px;
        right: 13px;
        margin: 0 0 0 3px;
        background-image: url("data:image/svg+xml,%3Csvg width='22' height='14' viewBox='0 0 22 14' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M15.0287 0L22 7.03333L15.0287 14H11.8758L17.586 8.26667H0V5.76667H17.586L11.8758 0H15.0287Z' fill='#{str-replace(#{$font-color}, '#', '%23')}'/%3E%3C/svg%3E");
        background-size: cover;
    }
    &:hover {
        color: $hover-font;
        background-color: $hover-fill;
        border-color: $hover-border;
        &:after {
            background-image: url("data:image/svg+xml,%3Csvg width='22' height='14' viewBox='0 0 22 14' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M15.0287 0L22 7.03333L15.0287 14H11.8758L17.586 8.26667H0V5.76667H17.586L11.8758 0H15.0287Z' fill='#{str-replace(#{$hover-font}, '#', '%23')}'/%3E%3C/svg%3E");
        }
    }

    padding: 8px 40px 11px 16px;
    @include fontsize(14px);
    line-height: 18px;
    &:after {
        bottom: 14px;
        width: 17px;
        height: 11px;
    }
    @media (min-width: $break-medium) {
        padding: 9px 50px 11px 16px;
        @include fontsize(18px);
        line-height: 23px;
        &:after {
            width: 19px;
            height: 12px;
        }
    }
    @media (min-width: $break-large) {
        padding: 9px 45px 11px 16px;
        @include fontsize(24px);
        line-height: 24px;
        &:after {
            width: 22px;
            height: 14px;
        }
    }
}

//## Form button focus states
@mixin focus-light {
    outline-color: $color-white;
}

@mixin focus-dark {
    outline-color: $color-black;
}

a,
button,
input,
select,
textarea {
    &:focus {
        outline: 1px solid;
        outline-offset: 2px;
        transition: none;
        @include focus-light();
    }
}

/// Full width mixin to break content out into gutters
@mixin full-width() {
    width: calc(100vw - var(--scrollbar-width));
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}

@mixin fullwidth-with-sidebar {
  @include full-width();
  top: 0;
  position: absolute;
  display: block;
  height: 100%;
  z-index: -1;

  @media (min-width: $break-large) {
    .section-nav + .container & {
      margin-left: -12rem;
    }
  }
}

//## slide animation
@mixin slide-fade-in {
    opacity: 0;
    transition: transform .3s ease, opacity .3s ease;
    transform: translateY(1.875rem);

    &.js-active {
        opacity: 1;
        transform: translateY(0rem);
    }

    @media (min-width: $break-large) {
        .scroll-animate + .scroll-animate {
            transition-delay: .3s;
        }
    }
}

// Full width overrides for wide block content
@mixin is-full-width {
    @media (min-width: 1025px) {
        margin-left: -80px;
    }
}

// Border animation stuff
// $color = border color
@mixin animate-border($color) {

    &.border-animate {
        position: relative;
        transition: all .3s ease-out;

        .circle {
            &:after {
                opacity: 0;
            }
        }

        &.js-active {
          .circle {
            &:after {
                opacity: 1;
                transition: all 300ms;
            }
        }

        }
    }
    /* Top Border */
    &.border-animate:before {
        display: block;
        content: "";
        width: 0;
        height: 0;
        position: absolute;
        top: 0;
        border-radius: 0 10px 0 0;
        border-top: solid 2px $color;

        @media (min-width: $break-large) {
          border-top: solid 3px $color;
        }
    }
    /* Right Border */
    &.border-animate:after {
        display: block;
        content: "";
        width: 0;
        height: 0;
        position: absolute;
        right: 0;
        top: 5px;
        border-radius: 10px;
        border-right: solid 2px $color;

        @media (min-width: $break-large) {
          border-right: solid 3px $color;
        }
    }
    /* Bottom Border */
    &.border-animate > div:before {
        display: block;
        content: "";
        width: 0;
        height: 0;
        position: absolute;
        right: 5px;
        bottom: 0;
        border-radius: 10px;
        border-bottom: solid 2px $color;
        @media (min-width: $break-large) {
          border-bottom: solid 3px $color;
        }
    }
    /* Left Border */
    &.border-animate > div:after {
        display: block;
        content: "";
        width: 0;
        height: 0;
        position: absolute;
        left: 0;
        bottom: 5px;
        border-radius: 10px;
        border-left: solid 2px $color;
        @media (min-width: $break-large) {
          border-left: solid 3px $color;
        }
    }
    /*- Top Border Animation -*/
    &.border-animate.js-active:before {
        width: 100%;
        left: 0;
        height: 20px;
        border-radius: 10px;
        transition: width .2s ease-out, height .02s .18s;
    }
    /*- Right Border Animation -*/
    &.border-animate.js-active:after {
        animation: .2s .2s expanddown forwards;
    }
    /*- Bottom Border Animation -*/
    &.border-animate.js-active > div:before {
        animation: .2s .4s expandleft forwards;
    }
    /*- Left Border Animation -*/
    &.border-animate.js-active > div:after {
        animation: .2s .6s expandup forwards;
    }

    @keyframes expanddown {
        from {
            width: 1px;
            height: 0;
            position: absolute;
            right: 0;
            top: 6px;
            border-radius: 0;
            border-right: solid 3px $color;
        }
        90% {
            width: 1px;
            height: calc(100% - 5px);
            border-radius: 0;
            top: 5px;
        }
        to {
            height: 100%;
            width: 20px;
            top: 0;
            border-radius: 10px;
        }
    }

    @keyframes expandleft {
        from {
            width: 0;
            height: 0;
            position: absolute;
            right: 5px;
            bottom: 0;
            border-radius: 0;
            border-right: solid 3px $color;
        }
        90% {
            width: calc(100% - 6px);
            height: 1px;
            border-radius: 0;
            right: 5px;
        }
        to {
            height: 100%;
            width: 100%;
            right: 0;
            border-radius: 10px;
        }
    }

    @keyframes expandup {
        from {
            width: 0;
            height: 0;
            position: absolute;
            right: 0;
            bottom: 5px;
            border-radius: 0;
            border-left: solid 3px $color;
        }
        90% {
            width: 0;
            height: calc(100% - 5px);
            border-radius: 0;
            bottom: 5px;
        }
        to {
            height: 100%;
            width: 20px;
            bottom: 0;
            border-radius: 10px;
        }
    }
}