@function each-color-stops-form($theme-colors) {
  @each $key, $theme-color in $theme-colors {
    $theme-colors: map.set(
      $theme-colors,
      $key,
      (
        --bs-gradient-from: $theme-color,
        --bs-gradient-stops: (
          var(--bs-gradient-from),
          var(--bs-gradient-to, to-rgb($theme-color, 0)),
        ),
      )
    );
  }
  @return $theme-colors;
}

@function each-color-stops-via($theme-colors) {
  @each $key, $theme-color in $theme-colors {
    $theme-colors: map.set(
      $theme-colors,
      $key,
      (
        var(--bs-gradient-from),
        $theme-color,
        var(--bs-gradient-to, to-rgb($theme-color, 0))
      )
    );
  }
  @return $theme-colors;
}

$utilities: map-merge(
  $utilities,
  (
    "gradient-color-stops-form": (
      property: --bs-gradient-from --bs-gradient-stops,
      class: from,
      variants: gradient-color-stops,
      values:
        each-color-stops-form(
          map-merge(
            (
              "transparent": transparent,
              "current": currentColor,
            ),
            $theme-colors
          )
        ),
    ),
    "gradient-color-stops-via": (
      property: --bs-gradient-stops,
      class: via,
      variants: gradient-color-stops,
      values:
        each-color-stops-via(
          map-merge(
            (
              "transparent": transparent,
              "current": currentColor,
            ),
            $theme-colors
          )
        ),
    ),
    "gradient-color-stops-to": (
      property: --bs-gradient-to,
      class: to,
      variants: gradient-color-stops,
      values:
        map-merge(
          (
            "transparent": transparent,
            "current": currentColor,
          ),
          $theme-colors
        ),
    ),
  )
);
