$__current-scope__: null !global;
$__undefined__: "__undefined-#{unique-id()}__" !global;

@function Scope($parent: $__current-scope__) {
  $scope-id: unquote("@#{unique-id()}");
  $scope-parent: $parent;

  @return ("_id": $scope-id, "_parent": $scope-parent);
}

@function __scope($map: ()) {
  @if $map == false {
    $scope: _static-get($__current-scope__);
    $__current-scope__: __get($scope, "_parent") !global;

    @return true;
  }

  $scope: __new(Scope);
  $scope-id: __get($scope, "_id");
  $__current-scope__: $scope-id !global;

  @if __is-map($map) {
    $scope: map-merge($scope, $map);
  }

  @return _static-set($__current-scope__, $scope);
}

@function __this($key: $__undefined__, $value: $__undefined__) {
  @if __is-undefined($key) and __is-undefined($value) {
    @return _static-get($__current-scope__);
  }

  @if __is-undefined($value) {
    @return _static-get($__current-scope__ $key);
  }

  @return _static-set($__current-scope__ $key, $value);
}
