// Helper mixin for setting sensible grid defaults depending on variables.scss.
// This mixin will create a simple grid with $grid-column-count columns if no parameters are given.
// Optionally you can define your own grid layout as needed by passing $columns and $area-names.
// _
// @param $columns-definition
//   A definition for grid columns like "3fr 3fr 6fr 4fr" or "repeat(8, 2fr)".
// @param $area-names
//   If you want to use named grid areas, you can pass name strings like "media text meta".
// @param $row-gap
//   If you want to set a custom row gap, you can do so by passing a size like '2rem'.
// _
// @usage
//   .gridContainer {
//       // Includes the default grid with 16 columns.
//       @include grid();
//   }
// _
//   .customGridContainer {
//       // Includes a custom grid with 2 areas.
//       @include grid(4fr 12fr, "sidebar main");
//   }
// _
//   .multiRowGridContainer {
//       // Includes a custom grid with 2 areas and 3 rows.
//       @include grid(4fr 12fr, "logo header" "sidebar main" "copy footer");
//   }
// _
//   .multiRowGridContainerWithRowGap {
//       // Includes a custom grid with 2 areas and 3 rows and a row-gap of $grid-gutter.
//       @include grid(4fr 12fr, "logo header" "sidebar main" "copy footer", $grid-gutter);
//   }

@mixin grid($columns-definition: false, $area-names: false, $row-gap: 0) {
  display: grid;
  grid-template-rows: auto;
  max-width: $grid-layout-max-width;
  column-gap: $grid-gutter;
  row-gap: $row-gap;
  @if $columns-definition {
    grid-template-columns: $columns-definition;
  } @else {
    grid-template-columns: repeat($grid-column-count, 1fr);
  }
  @if $area-names {
    grid-template-areas: $area-names;
  }
}

@mixin content-grid-default() {
  grid-column: 2 / 16;

  @include breakpoint(m) {
    grid-column: 4 / 14;
  }
}

// Helper mixin for breakpoints.
// _
// @param $name
//   The name of the breakpoint you want to use as defined in _variables.scss.
// _
// @usage
//   .responsiveContainer {
//       @include breakpoint(m) {
//          padding: 1rem;
//       }
//   }

@mixin breakpoint($name: xs) {
  // prettier-ignore
  @media screen and (#{map_get($breakpoints, $name)}) { // stylelint-disable-line media-query-no-invalid
    @content;
  }
}

// Helper mixin for quickly setting a font style from the list in _variables.scss.
// _
// @param $name
//   The name of the font style as listed in _variables.scss.
// _
// @usage
//   .textContainer {
//      @include typo(h1);
//   }

@mixin typo($name: body) {
  @error 'Mixing hase been removed';
}

// Helper mixin for making an image fit to its's container.
// _
// The expected behaviour will be like background-size: cover, but with real images.
// Optionally it is possible to define a min-height or max-height.
// _
// @param $max-height
//   Optional max-height value.
// @param $min-height
//   Optional min-height value.
// _
// @usage
//   .imgContainer {
//     @include image-fit();
//   }

@mixin image-fit($max-height: false, $min-height: false) {
  .media--blazy,
  figure,
  picture {
    display: block;
    width: 100%;
    height: 100%;
  }
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    @if $max-height != false {
      max-height: $max-height;
    }
    @if $min-height != false {
      min-height: $min-height;
    }
  }
}

// Helper mixin for adding an icon to an element via scss.
// Optionally you can select another fontawesome set of icons and the location of the icon (::before or ::after).
// _
// @param $icon
//   The icon name in the fontawesome library (f.e. "arrow-up" or "bars").
// @param $iconset
//   Optional iconset for fontawesome library (f.e. for using "twitter" icon you have to define "fab" because it is
//   in the "brands" set of fontawesome which has the shorthand "fab").
//   Possible values with the free version of fontawesome: "fas" & "fab".
// @param $position
//   Optional overriding-possibility for the position of the icon. By default they are appended to a ::before element.
//   If for some reason you need the icon to be in the ::after element, you can pass 'after' as the third parameter.
// _
// @usage
//    .elementWithArrowIcon {
//        @include icon(arrow-up);
//    }
// _
//    .elementWithTwitterIcon {
//        @include icon(twitter, fab);
//    }
// _
//    .elementWithArrowIconAfterContent {
//        @include icon(arrow-up, fas, after);
//    }

@mixin icon($icon: arrow-right, $iconset: fas, $position: before) {
  &:#{$position} {
    @include fa-icon;
    @extend %#{$iconset};
    @content;

    content: "#{map_get($fa-icons, $icon)}";
  }
}

// Helper mixin for defining the profile image circle size and styling.

@mixin profile-circle() {
  position: relative;
  overflow: hidden;
  width: 4rem;
  min-width: 4rem;
  height: 4rem;
  border: 1px solid $color-bg-light;
  border-radius: 50%;

  .field {
    margin: 0;
    padding: 0;
  }

  img {
    width: 100%;
    height: auto;
    vertical-align: bottom;
  }

  @include breakpoint(m) {
    width: 7rem;
    min-width: 7rem;
    height: 7rem;
  }
}

// Helper mixin for defining social links styling.

@mixin social-links() {
  // width: fit-content;
  max-width: 100%;
  margin: 0 auto $grid-gutter auto;

  // @include breakpoint(l) {
  // @include grid(repeat(10, 1fr));
  // }

  .field__item {
    display: block;

    // width: fit-content;
    // max-width: 100%;

    // @include breakpoint(l) {
    // &:nth-child(odd) {
    // grid-column: 1/6;
    // }
    // &:nth-child(even) {
    // grid-column: 7/11;
    // }
    // }

    &.field-email a {
      @include icon(envelope);
    }
    &.field-phone a {
      @include icon(phone);
    }
    &.field-url a {
      @include icon(globe);
    }
    &.field-legal-url a {
      @include icon(section);
    }

    > a {
      display: inline-block;

      // padding-bottom: 0.25rem;
      // padding-top: 0.25rem;
      // padding-left: 2px; // A little nicer hover bg.

      margin: 0.25rem 0;
      padding: 0.5rem 1rem;

      // overflow: hidden;
      word-break: keep-all;

      // text-overflow: ellipsis;
      // white-space: nowrap;
      // max-width: 100%;

      &:focus,
      &:hover {
        color: $color-text-inverted;
      }

      &:active {
        color: $color-interaction;
      }

      .platform-url {
        display: none;
      }

      &::before,
      i {
        margin-right: 0.5rem;
        vertical-align: bottom;
        font-size: $font-size-icon;
      }
    }
  }
}

// Helper mixin for defining screenreader-only text.

@mixin visually-hidden() {
  position: absolute !important;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px); // stylelint-disable-line property-no-deprecated
  width: 1px;
  height: 1px;
  overflow-wrap: normal;
}

// Default clearfix implementation to be used in conjunction with floating elements.
// _
// @usage
//   .box {
//     @include clearfix;
//     .child {
//       float:left;
//     }
//  }

@mixin clearfix() {
  // stylelint-disable-next-line nesting-selector-no-missing-scoping-root
  &::after {
    display: table;
    clear: both;
    content: "";
  }
}

// prettier-ignore
@mixin all-headings {
  h1, .h1,
  h2, .h2,
  h3, .h3,
  h4, .h4,
  h5, .h5,
  h6, .h6 {
    @content;
  }
}
