//
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

@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 literal 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 type-of($style) == "color" or $style == "currentColor" {
    @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);
      }
    }
  }
}
