@use "sass:string";
@use "sass:list";
@use "sass:meta";
@use "sass:map";

// Mixin expand variables from nested map
// @in: map<key, map | value>
// @out: array<[array<keys>, value]>
@function map-flatten($map, $prefix: ()) {
  $result: ();

  @each $key, $value in $map {
    $path-key: list.append($prefix, $key);

    @if type-of($value) == "map" {
      $flatArray: map-flatten($value, $path-key);
      $result: list.join($result, $flatArray);
    } @else {
      $flat: ($path-key, $value);
      $result: list.append($result, $flat);
    }
  }

  @return $result;
}
