@charset "UTF-8";

/// Provides a quick method for setting an element’s position. Use a `null`
/// value to “skip” a side.
///
/// @argument {string} $position [relative]
///   A CSS position value.
///
/// @argument {arglist} $coordinates [null]
///   List of lengths, defined as CSS shorthand.
///
/// @example scss
///   .element {
///     @include position(absolute, 0 null null 10em);
///   }
///
/// @example css
///   .element {
///     left: 10em;
///     position: absolute;
///     top: 0;
///   }
///
/// @require {function} _is-length
///
/// @require {function} _unpack

@mixin position(
    $position: relative,
    $coordinates: null
  ) {

  @if type-of($position) == list {
    $coordinates: $position;
    $position: relative;
  }

  $coordinates: _unpack($coordinates);

  $offsets: (
    top:    nth($coordinates, 1),
    right:  nth($coordinates, 2),
    bottom: nth($coordinates, 3),
    left:   nth($coordinates, 4),
  );

  position: $position;

  @each $offset, $value in $offsets {
    @if _is-length($value) {
      #{$offset}: $value;
    }
  }
}
