// RenderKit
// github.com/matteobertoldo/renderkit
// Licensed under MIT Open Source

////
/// @group shapes
////

/// Creates a CSS triangle, which can be used for dropdown arrows, dropdown pips, and more. Use this mixin inside a `&::before` or `&::after` selector, to attach the triangle to an existing element.
/// @param {Number} $triangle-size - Width of the triangle.
/// @param {Color} $triangle-color - Color of the triangle.
/// @param {Keyword} $triangle-direction - Direction the triangle points. Can be `up`, `right`, `down`, or `left`.
@mixin triangle($triangle-size, $triangle-color, $triangle-direction: down) {
    display: block;
    width: 0;
    height: 0;
    border: inset $triangle-size;

    @if ($triangle-direction == down) {
        border-color: $triangle-color transparent transparent;
        border-top-style: solid;
        border-bottom-width: 0;
    } @else if ($triangle-direction == up) {
        border-color: transparent transparent $triangle-color;
        border-bottom-style: solid;
        border-top-width: 0;
	} @else if ($triangle-direction == right) {
        border-color: transparent transparent transparent $triangle-color;
        border-left-style: solid;
        border-right-width: 0;
	} @else if ($triangle-direction == left) {
        border-color: transparent $triangle-color transparent transparent;
        border-right-style: solid;
        border-left-width: 0;
	}
}

/// Local map for all arrow shape directions.
/// @type Map
/// @access private
$arrow-shape-direction: (
    down: 45deg,
    up: -135deg,
    right: -45deg,
    left: 135deg
);

/// Creates a CSS arrow, which can be used for dropdown arrows, dropdown pips, and more. Use this mixin inside a `&::before` or `&::after` selector, to attach the arrow to an existing element.
/// @param {Number} $arrow-width - Width of the arrow.
/// @param {Number} $arrow-height - Height of the arrow.
/// @param {Color} $arrow-color - Color of the arrow.
/// @param {Number} $arrow-border-width - The border width of the arrow.
/// @param {Keyword} $arrow-direction [null] - The direction of the arrow. Can be `up`, `right`, `down`, or `left`.
@mixin arrow($arrow-width, $arrow-height, $arrow-color, $arrow-border-width, $arrow-direction: null) {
    display: block;
    width: $arrow-width;
    height: $arrow-height;
    border: solid $arrow-color;
    border-width: 0 $arrow-border-width $arrow-border-width 0;

    @if ($arrow-direction == down) {
        transform: rotate(45deg);
	} @else if ($arrow-direction == up) {
        transform: rotate(-135deg);
	} @else if ($arrow-direction == right) {
        transform: rotate(-45deg);
	} @else if ($arrow-direction == left) {
        transform: rotate(135deg);
	}
}

/// Creates a CSS "cross" shape, which can be used for modals and more.
/// @param {Number} $shape-cross-size - Size of the "cross" shape.
/// @param {Number} $shape-cross-line-size - Size of lines "cross" shape.
/// @param {Color} $shape-cross-color - Color of the "cross" shape.
@mixin shape-cross($shape-cross-size, $shape-cross-line-size, $shape-cross-color) {
    display: block;
    position: relative;
    width: $shape-cross-size;
    height: $shape-cross-size;
    border: 0;
    background: none;
    margin: 0;
    padding: 0;

    &::before,
    &::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 0;
        width: 100%;
        height: $shape-cross-line-size;
        background-color: $shape-cross-color;
        margin-top: - rem($shape-cross-line-size / 2);
    }

    &::before {
        transform: rotate(45deg);
    }

    &::after {
        transform: rotate(-45deg);
    }
}
