// These functions were taken from Bourbon:
// http://bourbon.io/docs/
@function ux-strip-unit($value) {
  @return ($value / ($value * 0 + 1));
}

// Convert pixel value to REM value
@function rem($size, $base-font-size: 16px) {
  @if not unitless($size) {
    $size: ux-strip-unit($size);
  }
  @return ($size / ux-strip-unit($base-font-size)) * 1rem;
}

// Unit conversion, inspired by:
// https://www.sitepoint.com/converting-typographic-units-sass/

@function pt-to-px($pt-value) {
  @return $pt-value * 1.3333 + 0px;
}

@function pt-to-rem($pt-value) {
  @return rem(pt-to-px($pt-value));
}

@function line-height($font-size, $line-height) {
  @return $line-height / $font-size;
}


// Round a number to specified digits.
// https://gist.github.com/terkel/4373420
//
// @param  {Number} $number A number to round
// @param  {Number} [$digits:0] Digits to output
// @param  {String} [$mode:round] (round|ceil|floor) How to round a number
// @return {Number} A rounded number
// @example
//        ux-round(0.333)    => 0
//        ux-round(0.333, 1) => 0.3
//        ux-round(0.333, 2) => 0.33
//        ux-round(0.666)    => 1
//        ux-round(0.666, 1) => 0.7
//        ux-round(0.666, 2) => 0.67
@function ux-round($number, $digits: 0, $mode: round) {
  $n: 1;
  // $number must be a number
  @if type-of($number) != number {
    @warn "#{ $number } is not a number.";
    @return $number;
  }
  // $digits must be a unitless number
  @if type-of($digits) != number {
    @warn "#{ $digits } is not a number.";
    @return $number;
  } @else if not unitless($digits) {
    @warn "#{ $digits } has a unit.";
    @return $number;
  }
  @if $digits > 0 {
    @for $i from 1 through $digits {
      $n: $n * 10;
    }
  }
  @if $mode == round {
    @return round($number * $n) / $n;
  } @else if $mode == ceil {
    @return ceil($number * $n) / $n;
  } @else if $mode == floor {
    @return floor($number * $n) / $n;
  } @else {
    @warn "#{ $mode } is undefined keyword.";
    @return $number;
  }
}


// CSS Grid Layout Functions
// These functions allow us to use css grid layout in modern browsers, with fallbacks for IE11

// Mimics the repeat function in CSS Grid Layout for IE11
// @include grid-template-columns(10px grid-repeat(4, 20px) 30px);
// @include grid-template-columns(10px 20px 20px 20px 20px 30px);
@function grid-repeat($repeat, $stuff: 1fr) {
  $list: ();
  @for $i from 1 through $repeat {
    $list: append($list, $stuff, space);
  }
  @return $list;
}


// Add Gap between the boxes
// https://gist.github.com/ksenzee/276d60f3e251b1dfafaf52ed8dbdb0de
// @param   {list}    $boxes - List with box sizes
// @param   {string}  $gap - Optional column gap
@function box-gap($boxes, $gap) {
  $box: ();

  @for $i from 1 through length($boxes) {
    $box: append($box, nth($boxes, $i), space);

    // Adding Gap Between
    @if $gap > 0 {
      // Not last Loop
      @if $i != length($boxes) {
        $box: append($box, $gap, space);
      }
    }
  }

  @return $box;
}
