@use "sass:map";
@use "sass:list";
@use "utilities.scss" as *;
@use "../variables/gradientsDnLight.scss" as *;
@use "../variables/gradientsDnDark.scss" as *;
@forward "../variables/gradientsList.scss";

@mixin ds-gradient($component, $theme: light) {
  $tmpMap: map.get($gradientsDnLight, $component);

  @if $theme == dark {
    $tmpMap: map.get($gradientsDnDark, $component);
  }

  $angle: map.get($tmpMap, "angle");
  $stops: map.get($tmpMap, "stops");

  @if map.get($tmpMap, "type") == "linear" {
    --ds-gradient-#{$component}: linear-gradient(
      #{$angle}deg,
      #{_get-stop($tmpMap, "color", 1)} #{_get-stop($tmpMap, "position", 1) * 100%},
      #{_get-stop($tmpMap, "color", 2)} #{_get-stop($tmpMap, "position", 2) * 100%}
    );
  }
}

@function ds-get-gradient($component) {
  @return var($component);
}

@function _get-stop($map, $key, $index) {
  @return map.get(list.nth(map.get($map, "stops"), $index), $key);
}

@mixin get-gradient-scheme($type: light) {
  @each $key in map.keys($gradientsDnLight) {
    @include ds-gradient($key, $type);
  }
}
