// Foundation for Sites by ZURB
// foundation.zurb.com
// Licensed under MIT Open Source

////
/// @group flexbox utilities
////

/// Quickly disable/enable count of flexbox source ordering.
/// @type Boolean
$flex-source-ordering-count-enable: false !default;

/// Default value for the count of source ordering.
/// @type Number
$flex-source-ordering-count: 6 !default;

/// Quickly disable/enable Responsive breakpoints for Vanilla Flex Helpers.
/// @type Boolean
$flexbox-responsive-breakpoints: true !default;

/// Sets the text direction of the CSS. Can be either `ltr` or `rtl`.
/// @group typography
/// @type Keyword
$global-text-direction: ltr !default;

// Internal variable that contains the flex justifying options
$-zf-flex-justify: -zf-flex-justify($global-text-direction);

/// Vanilla flexbox classes.
/// @group flexbox utilities
/// @access private
@mixin flex-helpers {
    .flex-container {
        @include flex;
    }

    .flex-child-auto {
        flex: 1 1 auto;
    }

    .flex-child-grow {
        flex: 1 0 auto;
    }

    .flex-child-shrink {
        flex: 0 1 auto;
    }

    @each $dir, $prop in $-zf-flex-direction {
        .flex-dir-#{$dir} {
            @include flex-direction($prop);
        }
    }

    @if ($flexbox-responsive-breakpoints) {
        @each $size in $breakpoint-classes {
            @include breakpoint($size) {
                @if $size != $-zf-zero-breakpoint {
                    .#{$size}-flex-container {
                        @include flex;
                    }

                    .#{$size}-flex-child-auto {
                        flex: 1 1 auto;
                    }

                    .#{$size}-flex-child-grow {
                        flex: 1 0 auto;
                    }

                    .#{$size}-flex-child-shrink {
                        flex: 0 1 auto;
                    }

                    @each $dir, $prop in $-zf-flex-direction {
                        .#{$size}-flex-dir-#{$dir} {
                            @include flex-direction($prop);
                        }
                    }
                }
            }
        }
    }
}

/// Foundation flex flex classes
///
/// The ability to enable or disable `flex-source-ordering` has been added.
/// @link https://foundation.zurb.com/sites/docs/flexbox-utilities.html
/// @link https://foundation.zurb.com/sites/docs/flexbox-utilities.html#source-ordering
/// @group _global renderkit
@mixin foundation-flex-classes {
    @each $hdir, $prop in $-zf-flex-justify {
        .align-#{$hdir} {
            @include flex-align($x: $hdir);
        }
    }

    @each $vdir, $prop in $-zf-flex-align {
        .align-#{$vdir} {
            @include flex-align($y: $vdir);
        }

        .align-self-#{$vdir} {
            @include flex-align-self($y: $vdir);
        }
    }

    .align-center-middle {
        @include flex-align($x: center, $y: middle);
        align-content: center;
    }

    @if ($flex-source-ordering-count-enable) {
        @include -zf-each-breakpoint {
            @for $i from 1 through $flex-source-ordering-count {
                .#{$-zf-size}-order-#{$i} {
                    @include flex-order($i);
                }
            }
        }
    }

    @include flex-helpers;
}
