//
// Copyright 2017 Google Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions://
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

@import "./variables";

// Applies the correct theme color style to the specified property.
// $property is typically color or background-color, but can be any CSS property that accepts color values.
// $style should be one of the map keys in $mdc-theme-property-values (_variables.scss), or a color value.
// $edgeOptOut controls whether to feature-detect around Edge to avoid emitting CSS variables for it,
// intended for use in cases where interactions with pseudo-element styles cause problems due to Edge bugs.
@mixin mdc-theme-prop($property, $style, $important: false, $edgeOptOut: false) {
  @if mdc-theme-is-valid-theme-prop-value_($style) {
    @if $important {
      #{$property}: $style !important;
    } @else {
      #{$property}: $style;
    }
  } @else {
    @if not map-has-key($mdc-theme-property-values, $style) {
      @error "Invalid style: '#{$style}'. Choose one of: #{map-keys($mdc-theme-property-values)}";
    }

    $value: map-get($mdc-theme-property-values, $style);

    @if $important {
      #{$property}: $value !important;

      @if $edgeOptOut {
        // stylelint-disable max-nesting-depth
        @at-root {
          @supports not (-ms-ime-align:auto) {
            // stylelint-disable scss/selector-no-redundant-nesting-selector
            & {
              /* @alternate */
              #{$property}: var(--mdc-theme-#{$style}, $value) !important;
            }
            // stylelint-enable scss/selector-no-redundant-nesting-selector
          }
        }
        // stylelint-enable max-nesting-depth
      } @else {
        /* @alternate */
        #{$property}: var(--mdc-theme-#{$style}, $value) !important;
      }
    } @else {
      #{$property}: $value;

      @if $edgeOptOut {
        // stylelint-disable max-nesting-depth
        @at-root {
          @supports not (-ms-ime-align:auto) {
            // stylelint-disable scss/selector-no-redundant-nesting-selector
            & {
              /* @alternate */
              #{$property}: var(--mdc-theme-#{$style}, $value);
            }
            // stylelint-enable scss/selector-no-redundant-nesting-selector
          }
        }
        // stylelint-enable max-nesting-depth
      } @else {
        /* @alternate */
        #{$property}: var(--mdc-theme-#{$style}, $value);
      }
    }
  }
}
