
// @require _/map/functions.scss
// @require _/unit/functions.scss

/* BREAKPOINTS */

@function breakpoint-exists ( $breakpoint ) {

  @return map-has-key( $breakpoints, $breakpoint );

}

@function breakpoint-previous ( $breakpoint ) {

  @return map-previous( $breakpoints, $breakpoint );

}

@function breakpoint-next ( $breakpoint ) {

  @return map-next( $breakpoints, $breakpoint );

}

@function breakpoint-min ( $breakpoint ) {

  @if breakpoint-exists( $breakpoint ) {

    $value: map-get( $breakpoints, $breakpoint );

    @return if( unit-strip( $value ) != 0, $value, null );

  }

}

@function breakpoint-max ( $breakpoint ) {

  $value: breakpoint-next( $breakpoint );

  @return if( $value, breakpoint-min( $value ) - $breakpoint-epsilon, null );

}

/* CLASSES */

@function breakpoints-get-classes () {

  $classes: ();

  @each $breakpoint, $value in $breakpoints {

    $classes: append( $classes, breakpoint-get-class( $breakpoint ) );

  }

  @return $classes;

}

@function breakpoint-get-class ( $breakpoint ) {

  //TODO: Write in a more general way, using a str-repeat and a map

  $classes: (
    'xxxxsmall': 'xxxxs',
    'xxxsmall': 'xxxs',
    'xxsmall': 'xxs',
    'xsmall': 'xs',
    'small': 'sm',
    'medium': 'md',
    'large': 'lg',
    'xlarge': 'xl',
    'xxlarge': 'xxl',
    'xxxlarge': 'xxxl',
    'xxxxlarge': 'xxxxl'
  );

  @if map-has-key( $classes, $breakpoint ) {

    @return map-get( $classes, $breakpoint );

  } @else {

    // Fall back to the bare key

    @return $breakpoint;

  }

}
