/// PROCESS COLLECTION MIXIN
/// Takes a passed collection and finds utility classes to generate.
/// It’ll loop through breakpoints, too and generate responsive utilities
/// where required
///
/// @param {map} $collection - The '$gorko-config' config item
/// @param {string} $prefix - An optional prefix that is stuck to the front of selectors
/// @param {string} $selector - The CSS selector that should be generated
/// @param {bool} $is-breakpoint - A flag for the responsive generation to use to determine wether to run or not
///
@import 'generate-css';
@import 'get-namespace';

@mixin process-collection($collection, $prefix, $selector, $is-breakpoint) {
  $items: map-get($collection, 'items');
  $output: map-get($collection, 'output');
  $property: map-get($collection, 'property');
  $use-css-vars: map-get($collection, 'css-vars');
  $vars-key: '';

  $selector: get-namespace('classes') + $selector;

  /// If this collection is using CSS vars, the items come from the
  /// 'css-vars' map in $gorko-config
  @if ($use-css-vars) {
    $vars: map-get($gorko-config, 'css-vars');
    $vars-key: map-get($collection, 'items');
    $items: map-get($vars, $vars-key);
  }

  /// It'll only run if $items and $property aren't null. This means it'll ignore the breakpoints and design tokens, for example.
  @if ($property and $items) {
    @if ($output == 'responsive') {

      @include generate-css(
        #{$prefix + $selector},
        $property,
        $items,
        $use-css-vars,
        $vars-key
      );
    }

    @if ($output == 'standard') {
      @if ($is-breakpoint != true) {
        @include generate-css(
          #{$prefix + $selector},
          $property,
          $items,
          $use-css-vars,
          $vars-key
        );
      }
    }
  }
}
