/**
 * @type String
 */

$utility-prefix: 'u-' !default;

/**
 * @type Map
 */

$breakpoints: (
  "sm": max-width 25em,
  "md": 25em,
  "lg": 50em,
) !default;

/**
 * @type List
 */

$breakpoint-prefix-keys: ('sm', 'md', 'lg') !default;

/**
 * Prefix classes per breakpoint (e.g. `.md-Grid--2col`)
 *
 * @param {String} $class - The class name
 * @param {List}   $breakpoints ($breakpoint-prefix-default-map)
 * @param {Bool}   $include-unprefixed (true)
 * @param {String} $glue (-) - Character to join `$class` with `$breakpoints` key.
 *
 * @requires {mixin}    at-breakpoint
 * @requires {variable} $utility-prefix
 * @requires {variable} $breakpoints
 * @requires {variable} $breakpoint-prefix-keys
 * @requires {function} map-filter-key
 *
 * @link https://github.com/suitcss/grid-layouts
 */

@mixin breakpoint-prefix(
  $class,
  $breakpoints: $breakpoint-prefix-keys,
  $include-unprefixed: true,
  $glue: "-"
) {

  $types: ".", "#", "%";
  $type: str_slice($class, 0, 1);
  $name: str_slice($class, 2);
  $prefix: '';

  @if index($types, $type) != 1 {
    @warn "The first parameter must begin with one of the following: #{$types}";
  }

  // Account for SUIT's utility class naming convention
  @if str_slice($name, 0, 2) == $utility-prefix {
    $prefix: $utility-prefix;
    $name: str_slice($name, 3);
  }

  @if $include-unprefixed {

    // .[u-]ClassName
    #{$type}#{$prefix}#{$name} {
      @content;
    }
  }

  @each $key in $breakpoints {
    @include at-breakpoint($key) {

      // .[u-]sm-ClassName
      #{$type}#{$prefix}#{$key}#{$glue}#{$name} {
        @content;
      }
    }
  }
}
