// Inspired by React UI and Bootstrap
@use 'sass:list';
@use 'sass:map';
@use 'sass:meta';
@use 'string';

@mixin generate($utility, $infix) {
    $values: map.get($utility, values);

    // If the values are a list or string, convert it into a map
    @if meta.type-of($values) == 'string' or meta.type-of(list.nth($values, 1)) != 'list' {
        $values: list.zip($values, $values);
    }

    @each $key, $value in $values {
        $properties: map.get($utility, property);
        $property-class: map.get($utility, class);

        // Don't prefix if value key is null (e.g. with shadow class)
        $property-class-modifier: if($key, '-' + $key, '');

        // Remove default postfix from class name
        $property-class-modifier: string.replace($property-class-modifier, '-default', '');

        .#{$property-class + $infix + $property-class-modifier} {
            @each $property in $properties {
                // stylelint-disable-next-line declaration-no-important
                #{$property}: $value !important;
            }
        }
    }
}
