// =============================================================================
// =ALEKSI - CONST
// =============================================================================
////
//// @group aleksi-general
//// @author [Yoannis Jamar](http://yoannis.me)
//// @author [Hugo Giraudel]((http://hugogiraudel.com)

@import "aleksi/general/throw";

$constants: () !default;

// =define( $name, $value)
// -----------------------------------------------------------------------------
/// Defines a constant
///
/// @param {string} $name - the name of the constant to define
/// @param {any} $value - the value of the new constant
///
/// @return {any} - the constant's value
/// @throw {warning} - if the constant is already defined
///
/// @access public
/// @since 0.6.0

@function define($name, $value)
{
  @if map-has-key($constants, $name) {
    $w: throw-warning('define(): can not alter existing constant `#{$name}`. Returning constant\'s current value.');
    @return map-get($constants, $name);
  }

  // add constant to constants table
  $constants: map-merge($constants, ('#{$name}': $value)) !global;
  @return $value;
}

// =define( $name, $value)
// -----------------------------------------------------------------------------
/// Mixin to invoke the define function
///
/// @param {string} $name - the name of the constant to define
/// @param {any} $value - the value of the new constant
///
/// @throw {warning} - if the constant is already defined
///
/// @access public
/// @since 0.6.0

@mixin define($name, $value) {
  $c: define($name, $value);
}