// CSS3 Flexible Box Model and property defaults

// Custom shorthand notation for flexbox
@mixin box($orient: inline-axis, $pack: start, $align: stretch) {
  @include _bourbon-deprecate-for-prefixing("box");

  @include display-box;
  @include box-orient($orient);
  @include box-pack($pack);
  @include box-align($align);
}

@mixin display-box {
  @include _bourbon-deprecate-for-prefixing("display-box");

  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox; // IE 10
  display: box;
}

@mixin box-orient($orient: inline-axis) {
  @include _bourbon-deprecate-for-prefixing("box-orient");

// horizontal|vertical|inline-axis|block-axis|inherit
  @include prefixer(box-orient, $orient, webkit moz spec);
}

@mixin box-pack($pack: start) {
  @include _bourbon-deprecate-for-prefixing("box-pack");

// start|end|center|justify
  @include prefixer(box-pack, $pack, webkit moz spec);
  -ms-flex-pack: $pack; // IE 10
}

@mixin box-align($align: stretch) {
  @include _bourbon-deprecate-for-prefixing("box-align");

// start|end|center|baseline|stretch
  @include prefixer(box-align, $align, webkit moz spec);
  -ms-flex-align: $align; // IE 10
}

@mixin box-direction($direction: normal) {
  @include _bourbon-deprecate-for-prefixing("box-direction");

// normal|reverse|inherit
  @include prefixer(box-direction, $direction, webkit moz spec);
  -ms-flex-direction: $direction; // IE 10
}

@mixin box-lines($lines: single) {
  @include _bourbon-deprecate-for-prefixing("box-lines");

// single|multiple
  @include prefixer(box-lines, $lines, webkit moz spec);
}

@mixin box-ordinal-group($int: 1) {
  @include _bourbon-deprecate-for-prefixing("box-ordinal-group");

  @include prefixer(box-ordinal-group, $int, webkit moz spec);
  -ms-flex-order: $int; // IE 10
}

@mixin box-flex($value: 0) {
  @include _bourbon-deprecate-for-prefixing("box-flex");

  @include prefixer(box-flex, $value, webkit moz spec);
  -ms-flex: $value; // IE 10
}

@mixin box-flex-group($int: 1) {
  @include _bourbon-deprecate-for-prefixing("box-flex-group");

  @include prefixer(box-flex-group, $int, webkit moz spec);
}

// CSS3 Flexible Box Model and property defaults
// Unified attributes for 2009, 2011, and 2012 flavours.

// 2009 - display (box | inline-box)
// 2011 - display (flexbox | inline-flexbox)
// 2012 - display (flex | inline-flex)
@mixin display($value) {
  @include _bourbon-deprecate-for-prefixing("display");

// flex | inline-flex
  @if $value == "flex" {
    // 2009
    display: -webkit-box;
    display: -moz-box;
    display: box;

    // 2012
    display: -webkit-flex;
    display: -moz-flex;
    display: -ms-flexbox; // 2011 (IE 10)
    display: flex;
  } @else if $value == "inline-flex" {
    display: -webkit-inline-box;
    display: -moz-inline-box;
    display: inline-box;

    display: -webkit-inline-flex;
    display: -moz-inline-flex;
    display: -ms-inline-flexbox;
    display: inline-flex;
  } @else {
    display: $value;
  }
}

// 2009 - box-flex (integer)
// 2011 - flex (decimal | width decimal)
// 2012 - flex (integer integer width)
@mixin flex($value) {
  @include _bourbon-deprecate-for-prefixing("flex");

  // Grab flex-grow for older browsers.
  $flex-grow: nth($value, 1);

  // 2009
  @include prefixer(box-flex, $flex-grow, webkit moz spec);

  // 2011 (IE 10), 2012
  @include prefixer(flex, $value, webkit moz ms spec);
}

// 2009 - box-orient ( horizontal | vertical | inline-axis | block-axis)
//      - box-direction (normal | reverse)
// 2011 - flex-direction (row | row-reverse | column | column-reverse)
// 2012 - flex-direction (row | row-reverse | column | column-reverse)
@mixin flex-direction($value: row) {
  @include _bourbon-deprecate-for-prefixing("flex-direction");

  // Alt values.
  $value-2009: $value;
  $value-2011: $value;
  $direction: normal;

  @if $value == row {
    $value-2009: horizontal;
  } @else if $value == "row-reverse" {
    $value-2009: horizontal;
    $direction: reverse;
  } @else if $value == column {
    $value-2009: vertical;
  } @else if $value == "column-reverse" {
    $value-2009: vertical;
    $direction: reverse;
  }

  // 2009
  @include prefixer(box-orient, $value-2009, webkit moz spec);
  @include prefixer(box-direction, $direction, webkit moz spec);

  // 2012
  @include prefixer(flex-direction, $value, webkit moz spec);

  // 2011 (IE 10)
  -ms-flex-direction: $value;
}

// 2009 - box-lines (single | multiple)
// 2011 - flex-wrap (nowrap | wrap | wrap-reverse)
// 2012 - flex-wrap (nowrap | wrap | wrap-reverse)
@mixin flex-wrap($value: nowrap) {
  @include _bourbon-deprecate-for-prefixing("flex-wrap");

  // Alt values
  $alt-value: $value;
  @if $value == nowrap {
    $alt-value: single;
  } @else if $value == wrap {
    $alt-value: multiple;
  } @else if $value == "wrap-reverse" {
    $alt-value: multiple;
  }

  @include prefixer(box-lines, $alt-value, webkit moz spec);
  @include prefixer(flex-wrap, $value, webkit moz ms spec);
}

// 2009 - TODO: parse values into flex-direction/flex-wrap
// 2011 - TODO: parse values into flex-direction/flex-wrap
// 2012 - flex-flow (flex-direction || flex-wrap)
@mixin flex-flow($value) {
  @include _bourbon-deprecate-for-prefixing("flex-flow");

  @include prefixer(flex-flow, $value, webkit moz spec);
}

// 2009 - box-ordinal-group (integer)
// 2011 - flex-order (integer)
// 2012 - order (integer)
@mixin order($int: 0) {
  @include _bourbon-deprecate-for-prefixing("order");

  // 2009
  @include prefixer(box-ordinal-group, $int, webkit moz spec);

  // 2012
  @include prefixer(order, $int, webkit moz spec);

  // 2011 (IE 10)
  -ms-flex-order: $int;
}

// 2012 - flex-grow (number)
@mixin flex-grow($number: 0) {
  @include _bourbon-deprecate-for-prefixing("flex-grow");

  @include prefixer(flex-grow, $number, webkit moz spec);
  -ms-flex-positive: $number;
}

// 2012 - flex-shrink (number)
@mixin flex-shrink($number: 1) {
  @include _bourbon-deprecate-for-prefixing("flex-shrink");

  @include prefixer(flex-shrink, $number, webkit moz spec);
  -ms-flex-negative: $number;
}

// 2012 - flex-basis (number)
@mixin flex-basis($width: auto) {
  @include _bourbon-deprecate-for-prefixing("flex-basis");

  @include prefixer(flex-basis, $width, webkit moz spec);
  -ms-flex-preferred-size: $width;
}

// 2009 - box-pack (start | end | center | justify)
// 2011 - flex-pack (start | end | center | justify)
// 2012 - justify-content (flex-start | flex-end | center | space-between | space-around)
@mixin justify-content($value: flex-start) {
  @include _bourbon-deprecate-for-prefixing("justify-content");

  // Alt values.
  $alt-value: $value;
  @if $value == "flex-start" {
    $alt-value: start;
  } @else if $value == "flex-end" {
    $alt-value: end;
  } @else if $value == "space-between" {
    $alt-value: justify;
  } @else if $value == "space-around" {
    $alt-value: distribute;
  }

  // 2009
  @include prefixer(box-pack, $alt-value, webkit moz spec);

  // 2012
  @include prefixer(justify-content, $value, webkit moz ms o spec);

  // 2011 (IE 10)
  -ms-flex-pack: $alt-value;
}

// 2009 - box-align (start | end | center | baseline | stretch)
// 2011 - flex-align (start | end | center | baseline | stretch)
// 2012 - align-items (flex-start | flex-end | center | baseline | stretch)
@mixin align-items($value: stretch) {
  @include _bourbon-deprecate-for-prefixing("align-items");

  $alt-value: $value;

  @if $value == "flex-start" {
    $alt-value: start;
  } @else if $value == "flex-end" {
    $alt-value: end;
  }

  // 2009
  @include prefixer(box-align, $alt-value, webkit moz spec);

  // 2012
  @include prefixer(align-items, $value, webkit moz ms o spec);

  // 2011 (IE 10)
  -ms-flex-align: $alt-value;
}

// 2011 - flex-item-align (auto | start | end | center | baseline | stretch)
// 2012 - align-self (auto | flex-start | flex-end | center | baseline | stretch)
@mixin align-self($value: auto) {
  @include _bourbon-deprecate-for-prefixing("align-self");

  $value-2011: $value;
  @if $value == "flex-start" {
    $value-2011: start;
  } @else if $value == "flex-end" {
    $value-2011: end;
  }

  // 2012
  @include prefixer(align-self, $value, webkit moz spec);

  // 2011 (IE 10)
  -ms-flex-item-align: $value-2011;
}

// 2011 - flex-line-pack (start | end | center | justify | distribute | stretch)
// 2012 - align-content (flex-start | flex-end | center | space-between | space-around | stretch)
@mixin align-content($value: stretch) {
  @include _bourbon-deprecate-for-prefixing("align-content");

  $value-2011: $value;
  @if $value == "flex-start" {
    $value-2011: start;
  } @else if $value == "flex-end" {
    $value-2011: end;
  } @else if $value == "space-between" {
    $value-2011: justify;
  } @else if $value == "space-around" {
    $value-2011: distribute;
  }

  // 2012
  @include prefixer(align-content, $value, webkit moz spec);

  // 2011 (IE 10)
  -ms-flex-line-pack: $value-2011;
}
