/// Grab the property and value of one of the $gorko-config utilities
/// that the generator will generate a class for.
///
/// @param {string} $key - The configured utility’s key
/// @param {string} $value-key - The value key that you are looking for within the utilty
///
@import 'get-namespace';

@function get-config-value($key, $value-key) {

  $utility: map-get($gorko-config, $key);
  $property: map-get($utility, 'property');
  $use-css-vars: map-get($utility, 'css-vars');
  $items: map-get($utility, 'items');
  $vars-key: '';

  @if ($use-css-vars) {
    
    /// If this utility class is using vars, we need to extract which var it is using
    $vars: map-get($gorko-config, 'css-vars');
    /// The standard $items expression will have returned a string in this context
    $vars-key: $items;

    // Re-assign the items to be custom properties instead
    $items: map-get($vars, $vars-key);

    // Validate this is going to return a value
    @if not(map-get($items, $value-key)) {
      @warn #{'Value: ‘' + $value-key + '’ doesn’t exist in ‘' + $vars-key + '’' };
      @return false;
    }

    $namespace: get-namespace('css-vars');

    // We've got all we need so generate that custom property reference with var
    @return ('property': #{$property}, 'value': var(--#{$namespace + $vars-key + '-' + $value-key}));

  } @else {
    // No CSS vars so we need to find a property and key match
    $item-value: map-get($items, $value-key);

    @if ($property and $item-value) {
      @return ('property': #{$property}, 'value': #{$item-value});
    } @else {
      @if ($property) {
        @warn #{'Value: ‘' + $value-key + '’ doesn’t exist in ‘' + $key + '’' };
      }

      @if ($item-value) {
        @warn #{'Utility ‘' + $key + '’ doesn’t exist'};
      }

      @return false;
    }
  }
}
