/* http://stackoverflow.com/a/6900392 */
@mixin unselectable() {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

@mixin default-cursor() {
    cursor: default;
}

@mixin debug() {
    border: 2px solid magenta !important;
}

@mixin size($width, $height: $width) {
    width: $width;
    height: $height;
}

@function opposite-direction($directions) {
    $opposite-directions: ();
    $direction-map: (
            'top': 'bottom',
            'right': 'left',
            'bottom': 'top',
            'left': 'right',
            'ltr': 'rtl',
            'rtl': 'ltr'
    );

    @each $direction in $directions {
        $opposite-direction: map-get($direction-map, $direction);
        @if $opposite-direction != null {
            $opposite-directions: append($opposite-directions, #{$opposite-direction});
        }
        @else {
            @warn "No opposite direction can be found for `#{$direction}`.";
        }
    }

    @return $opposite-directions;
}

// [Private]
// Position helper mixin
// Article about it: http://hugogiraudel.com/2013/08/05/offsets-sass-mixin/
// ---
// @param [string] $position: position type
// @param [list] $args: list of offsets and values
// ---
@mixin _position($position, $args) {
    @each $o in top right bottom left {
        $i: index($args, $o);
        @if $i
    and $i + 1 <= length($args)
    and type-of( nth($args, $i + 1) ) == number {
            #{$o}: nth($args, $i + 1);
        }
    }
    position: $position;
}

// Absolute positioning helper mixin
// Article about it: http://hugogiraudel.com/2013/08/05/offsets-sass-mixin/
// ---
// @param [list] $args: list of offsets and values
// ---
@mixin absolute($args) {
    @include _position(absolute, $args);
}

// Arrow helper mixin
// ---
// @param [string] $direction: arrow direction
// @param [list] $position: list of offsets and values
// @param [color] $color (inherit): arrow color
// @param [number] $size (1em): arrow size
// ---
@mixin triangle($direction, $position, $color: currentColor, $size: 1em) {
    // Make sure the direction is valid
    @if not index(top right bottom left, $direction) {
        @warn "Direction must be one of top, right, bottom or left.";
    } @else {
        @include absolute($position); // Position
        @include size(0); // Size
        content: '';
        z-index: 2;
        border-#{opposite-position($direction)}: $size * 1.5 solid $color;
        $perpendicular-borders: $size solid transparent;

        @if $direction == top or $direction == bottom {
            border-left: $perpendicular-borders;
            border-right: $perpendicular-borders;
        } @else if $direction == right or $direction == left {
            border-bottom: $perpendicular-borders;
            border-top: $perpendicular-borders;
        }
    }
}