
/* PRIVATE */

@mixin _position-set-coordinate ( $type, $value ) {

  @if $value != false and $value != null {
    #{$type}: $value;
  }

}

/* POSITION */

@mixin position ( $position, $coordinates ) {

  @if $position != false and $position != null {
    position: $position;
  }

  $nr: length( $coordinates );

  @if $nr == 1 {

    $value: first( $coordinates );

    @include _position-set-coordinate( top, $value );
    @include _position-set-coordinate( right, $value );
    @include _position-set-coordinate( bottom, $value );
    @include _position-set-coordinate( left, $value );

  } @else if $nr == 2 {

    $value-y: first( $coordinates );
    $value-x: last( $coordinates );

    @include _position-set-coordinate( top, $value-y );
    @include _position-set-coordinate( right, $value-x );
    @include _position-set-coordinate( bottom, $value-y );
    @include _position-set-coordinate( left, $value-x );

  } @else if ( $nr == 3 ) {

    $value-top: first( $coordinates );
    $value-x: nth( $coordinates, 2 );
    $value-bottom: last( $coordinates );

    @include _position-set-coordinate( top, $value-top );
    @include _position-set-coordinate( right, $value-x );
    @include _position-set-coordinate( bottom, $value-bottom );
    @include _position-set-coordinate( left, $value-x );

  } @else if ( $nr == 4 ) {

    $value-top: first( $coordinates );
    $value-right: nth( $coordinates, 2 );
    $value-bottom: nth( $coordinates, 3 );
    $value-left: last( $coordinates );

    @include _position-set-coordinate( top, $value-top );
    @include _position-set-coordinate( right, $value-right );
    @include _position-set-coordinate( bottom, $value-bottom );
    @include _position-set-coordinate( left, $value-left );

  }

}

/* SPECIFIC */

@mixin absolute ( $coordinates ) {

  @include position ( absolute, $coordinates );

}

@mixin fixed ( $coordinates ) {

  @include position ( fixed, $coordinates );

}

@mixin relative ( $coordinates ) {

  @include position ( relative, $coordinates );

}

@mixin static ( $coordinates ) {

  @include position ( static, $coordinates );

}
