/*
 |--------------------------------------------------------------------------
 |  Default Grid Settings
 |--------------------------------------------------------------------------
 */

$bk-grid-settings-custom: null !default;
$bk-grid-settings: (
  units: (
    gutter: 1rem,
  ),
  breakpoints: (
    min: 320px,
    s: 600px,
    m: 800px,
    l: 1200px,
    max: 1600px
  )
);

// Merge Custom Map into Default Map
@if $bk-grid-settings-custom != null {
  $bk-grid-settings: map-merge($bk-grid-settings, $bk-grid-settings-custom);
}

// Check if Breakpoints exits
@if map-has_key($bk-grid-settings, breakpoints) {
  // Get Breakpoints to to check if min & max exists
  $bk-breakpoints-map: map-deep-get($bk-grid-settings, breakpoints);

  // Merge Breakpoints into breakpoints
  $bk-breakpoints-custom: (breakpoints: map-deep-get($bk-grid-settings, breakpoints));

  // When min and max is defined do the Action otherwise grumble
  @if map_has_key($bk-breakpoints-map, min) and map_has_key($bk-breakpoints-map, max) {

    // Clear default breakpoints if at least min and max are defined
    $bk-grid-settings: map_remove($bk-grid-settings, breakpoints);

    // Merge Custom Breakpoints into Map
    $bk-grid-settings: recursive-map-merge($bk-grid-settings, $bk-breakpoints-custom);

    // New empty Map
    $bk-breakpoints: () !default;

    // Loop over all Breakpoints
    @each $key, $value in $bk-breakpoints-map {
      // Get the From Value from the Breakpoint
      $_breakpoint: $value;

      // Merge Key / Value into Map
      $bk-breakpoints: map_merge($bk-breakpoints, ($key: $_breakpoint));
    }

    $breakpoints: $bk-breakpoints;
  } @else {
    @warn 'You have to set a "min" and "max" Breakpoint within your custom settings!';
  }
} @else {
  @warn 'You have to set a "min" and "max" Breakpoint within your custom settings!';
}
