@import "variables";

/* Base */
@function bool($value: false) {
  @if $value == false
      or $value == ""
      or $value == "false"
      or $value == 'false'
      or $value == 0
      or $value == null {
    @return false;
  }
  @return true;
}

/// Slightly lighten a color
/// @access public
/// @param {Color} $color - color to tint
/// @param {Number} $percentage - percentage of `$color` in returned color
/// @return {Color}
@function tint($color, $percentage) {
  @return mix(white, $color, $percentage);
}

/// Slightly darken a color
/// @access public
/// @param {Color} $color - color to shade
/// @param {Number} $percentage - percentage of `$color` in returned color
/// @return {Color}
@function shade($color, $percentage) {
  @return mix(black, $color, $percentage);
}

/* Theme */
@function theme-filter($map, $included: (), $excluded: ()) {
  $filtered: ();

  @if $included == () {
    $included: map-keys($map);
  }

  @each $key in $included {
    @if not map-has-key($map, $key) {
      @error 'There is no `#{$key}` class in your variations list.';
    }

    @if not index($excluded, $key) {
      $filtered: append($filtered, $key, 'comma');
    }
  }

  @return $filtered;
}

@function theme-get($key) {
  $value: map-get($theme-map, $key);

  @if not $value {
    @error 'The entity `#{$entity}` doesn\'t have a value for `#{$key}`.';
  }

  @return $value;
}

@function theme-pull($key, $entity: $theme-loop-entity, $map: $themes) {
  $entity-map: map-get($map, $entity);

  @if not $entity-map {
    @error 'There is no `#{$entity}` entity in your variations list.';
  }

  $value: map-get($entity-map, $key);

  @if not $value {
    @error 'The entity `#{$entity}` doesn\'t have a value for `#{$key}`.';
  }

  @return $value;
}
