/**
 * Theme any css property based on the current palette, accepting a themable
 * value that will give an contrasted
 * ---
 * Usage example:
 *
 * $foo-palette: (
 *   primary: md-get-palette-color(indigo, 500),
 *   accent: md-get-palette-color(pink, 500),
 *   theme: "light"
 * );
 *
 * ---
 * @access public
 * ---
 * @param {color} $type —  The desired color based on material palette
 * @param {string} $type —  A valid hue
 */

@function md-get-palette-color($color, $hue) {
  @return map-get(map-get($md-palette, $color), $hue);
}


/**
 * Get the current theme mode from the current theme
 * ---
 * Usage example:
 *
 * $theme-mode: md-get-theme-mode()
 *
 * ---
 * @access private
 */

@function md-get-theme-mode() {
  @return map-get($md-theme-palette, theme);
}


/**
 * Theme any css property based on the current palette, accepting a themable
 * value that will give an contrasted
 * ---
 * Usage example:
 *
 * .md-foo {
 *   min-width: 88px;
 *   height: 40px;
 *   background: md-theme(primary);
 * }
 *
 * ---
 * @access public
 * ---
 * @param {string} $type —  The themable value
 */

@function md-theme($type, $background: "") {
  $color-theme: null;

  @if $type == "primary" or $type == "accent" {
    @return md-get-color-by-type($type, null);
  } @else {
    $color-theme: map-get($md-theme-palette, theme);

    @if $background != "" {
      $color-theme: md-pick-contrast(md-get-color-by-type($background, $color-theme));
    }

    @return md-get-color-by-theme($color-theme, $type);
  }
}


/**
 * Get a color based on type by theme
 * ---
 * Usage example:
 *
 * $color: md-get-color-by-theme(dark, primary)
 *
 * ---
 * @access public
 * ---
 * @param {string} $color-theme —  The theme color | Accepts dark or light
 * @param {string} $type —  The color type
 */

@function md-get-color-by-theme($color-theme, $type) {
  $theme: map-get($md-color-levels, $color-theme);

  @return map-get($theme, $type);
}


/**
 * Get a color based on type only
 * ---
 * Usage example:
 *
 * $color1: md-get-color-by-type(background, dark)
 * $color1: md-get-color-by-type(accent)
 *
 * ---
 * @access public
 * ---
 * @param {string} $type —  The color type
 * @param {string} $theme —  The fallback theme
 */

@function md-get-color-by-type($type, $theme) {
  $newColor: map-get($md-theme-palette, $type);

  @if $newColor == null {
    $newColor: md-get-color-by-theme($theme, $type);
  }

  @return $newColor
}
