@use "../variables";

@mixin caret-down() {
    border-top: variables.$caret-width solid;
    border-right: variables.$caret-width solid transparent;
    border-bottom: 0;
    border-left: variables.$caret-width solid transparent;
}

@mixin caret-up() {
    border-top: 0;
    border-right: variables.$caret-width solid transparent;
    border-bottom: variables.$caret-width solid;
    border-left: variables.$caret-width solid transparent;
}

@mixin caret-right() {
    border-top: variables.$caret-width solid transparent;
    border-right: 0;
    border-bottom: variables.$caret-width solid transparent;
    border-left: variables.$caret-width solid;
}

@mixin caret-left() {
    border-top: variables.$caret-width solid transparent;
    border-right: variables.$caret-width solid;
    border-bottom: variables.$caret-width solid transparent;
}

@mixin caret($direction: down) {
    @if variables.$enable-caret {
        &::after {
            display: inline-block;
            margin-left: variables.$caret-spacing;
            vertical-align: variables.$caret-vertical-align;
            content: '';
            @if $direction == down {
                @include caret-down();
            } @else if $direction == up {
                @include caret-up();
            } @else if $direction == right {
                @include caret-right();
            }
        }

        @if $direction == left {
            &::after {
                display: none;
            }

            &::before {
                display: inline-block;
                margin-right: variables.$caret-spacing;
                vertical-align: variables.$caret-vertical-align;
                content: '';
                @include caret-left();
            }
        }

        &:empty::after {
            margin-left: 0;
        }
    }
}
