/**
 * Component: Flexbox
 */
@include comp('flexbox') {
  position: relative;

  border: none;
  padding: 0;
  margin: 0;

  min-width: 0;
  min-height: 0;

  flex: 1;

  display: flex;
  flex-flow: row wrap;
  align-content: flex-start;
  align-items: flex-start;
  justify-content: flex-start;

  text-decoration: none;
  color: inherit;
  background-color: transparent;

  & > img {
    position: relative;
    max-width: 100%;
    height: auto;
  }

  @each $direction in $type-flex-direction {
    @include prop(
      (
        'direction': $direction,
      )
    ) {
      flex-direction: $direction;

      @if $direction == 'column' or $direction == 'column-reverse' {
        > * {
          flex: none;
          max-width: 100%;
        }
      }
    }
  }

  @each $wrap in $type-flex-wrap {
    @include prop(
      (
        'wrap': $wrap,
      )
    ) {
      flex-wrap: $wrap;
    }
  }

  @each $justify in $type-flex-justify {
    @include prop(
      (
        'justify': $justify,
      )
    ) {
      @if $justify == start or $justify == end {
        $justify: flex-#{$justify};
      }
      justify-content: $justify;
    }
  }

  @each $align in $type-flex-align {
    @include prop(
      (
        'align': $align,
      )
    ) {
      @if $align == start or $align == end {
        align-items: flex-#{$align};
        align-content: flex-#{$align};
      } @else {
        align-items: $align;
        align-content: $align;
      }
    }
    @include prop(
      (
        'align-self': $align,
      )
    ) {
      @if $align == start or $align == end {
        align-self: flex-#{$align};
      } @else {
        align-self: $align;
      }
    }
  }

  @include when('gap') {
    margin: rem(-$gap-base / 2);
    > .#{class-comp('flexbox')} {
      padding: rem($gap-base / 2);
      @include when('gap') {
        margin: 0;
        padding: 0;

        max-width: 100%;
        max-height: 100%;
      }
    }
  }

  @each $gap, $value in $gap-map {
    @include prop(
      (
        'gap': $gap,
      )
    ) {
      margin: rem(-$value / 2);
      > .#{class-comp('flexbox')} {
        padding: rem($value / 2);

        &.#{class-prop('gap', $gap)} {
          margin: 0;
          padding: 0;

          max-width: 100%;
          max-height: 100%;
        }
      }
    }
  }

  @each $preset in $type-flex-preset {
    @include prop(
      (
        'flex': $preset,
      )
    ) {
      @if $preset == expand {
        flex: 1;
      } @else {
        flex: $preset;
      }
    }
  }

  @include when('percentage') {
    flex: 1 0 100%;
  }

  @include when('hidden') {
    display: none;
  }
}
