@use 'sass:meta';
@use 'sass:list';
@use '../../functions/is-global-value' as *;

/// Applies position values to an element.
///
/// @param {String} $position [absolute] - The position value for the element.
/// @param {Number} $top [0] - The `top` value for the element.
/// @param {Number} $left [0] - The `left` value for the element.
/// @param {Number} $bottom [null] - The `bottom` value for the element.
/// @param {Number} $right [null] - The `right` value for the element.
/// @param {Number} $z-index [null] - The z-index value for the element.
///
/// @group Utilities
@mixin position(
  $position: absolute,
  $top: 0,
  $left: 0,
  $bottom: null,
  $right: null,
  $z-index: null
) {
  @if $position != relative and
    $position != absolute and
    $position != fixed and
    $position != sticky and
    not is-global-value($position)
  {
    @error 'The $position value of #{meta.inspect($position)} used in the ' +
        '[ position() ] mixin is invalid. You must choose between ' +
        'absolute, relative, fixed, or sticky positioning. Additionally, ' +
        'you may choose any of the CSS global values.';
  }

  position: $position;

  @if $top {
    top: $top;
  }

  @if $left {
    left: $left;
  }

  @if $bottom {
    bottom: $bottom;
  }

  @if $right {
    right: $right;
  }

  @if $z-index {
    z-index: $z-index;
  }
}
