//
// Copyright 2018 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 "@material/floating-label/mixins";
@import "@material/theme/mixins";
@import "@material/line-ripple/mixins";
@import "@material/notched-outline/mixins";

// Public

@mixin mdc-select-ink-color($color) {
  &:not(.mdc-select--disabled) {
    @include mdc-select-ink-color_($color);
  }
}

@mixin mdc-select-container-fill-color($color) {
  &:not(.mdc-select--disabled) {
    @include mdc-select-container-fill-color_($color);
  }
}

@mixin mdc-select-focused-label-color($color) {
  &:not(.mdc-select--disabled) {
    .mdc-select__native-control:focus ~ .mdc-floating-label {
      @include mdc-floating-label-ink-color(mdc-theme-prop-value($color));
    }
  }
}

@mixin mdc-select-hover-bottom-line-color($color) {
  &:not(.mdc-select--disabled) .mdc-select__native-control:hover {
    @include mdc-select-native-control-bottom-line-color_($color);
  }
}

@mixin mdc-select-bottom-line-color($color) {
  &:not(.mdc-select--disabled) {
    @include mdc-select-bottom-line-color_($color);
  }
}

@mixin mdc-select-focused-bottom-line-color($color) {
  &:not(.mdc-select--disabled) {
    @include mdc-select-focused-line-ripple-color_($color);
  }
}

@mixin mdc-select-label-color($color) {
  &:not(.mdc-select--disabled) .mdc-floating-label {
    @include mdc-floating-label-ink-color($color);
  }
}

@mixin mdc-select-outline-color($color) {
  &:not(.mdc-select--disabled) {
    @include mdc-select-outline-color_($color);
  }
}

@mixin mdc-select-hover-outline-color($color) {
  &:not(.mdc-select--disabled) {
    @include mdc-select-hover-outline-color_($color);
  }
}

@mixin mdc-select-focused-outline-color($color) {
  &:not(.mdc-select--disabled) {
    @include mdc-select-focused-outline-color_($color);
  }
}

@mixin mdc-select-corner-radius($radius) {
  border-radius: $radius $radius 0 0;
}

@mixin mdc-select-outline-corner-radius($radius) {
  // NOTE: idle and notched state border radius mixins
  // are broken into 2 different mixins, otherwise
  // we would be overly specific (big no, no). The cause of
  // this is because .mdc-notched-outline and .mdc-notched-outline__idle
  // are siblings. .mdc-notched-outline__idle needs to be a child of
  // .mdc-notched-outline in order to remedy this issue.
  .mdc-notched-outline {
    @include mdc-notched-outline-corner-radius($radius);
  }

  @include mdc-notched-outline-idle-corner-radius($radius);
}

// Private
@mixin mdc-select-focused-line-ripple_ {
  .mdc-select__native-control:focus ~ .mdc-line-ripple {
    @content;
  }
}

@mixin mdc-select-focused-outline_ {
  .mdc-select__native-control:focus ~ .mdc-notched-outline {
    @include mdc-notched-outline-stroke-width(2px);
    @content;
  }
}

@mixin mdc-select-ink-color_($color) {
  .mdc-select__native-control {
    @include mdc-theme-prop(color, $color);
  }
}

@mixin mdc-select-container-fill-color_($color) {
  @include mdc-theme-prop(background-color, $color);
}

@mixin mdc-select-bottom-line-color_($color) {
  .mdc-select__native-control {
    @include mdc-select-native-control-bottom-line-color_($color);
  }
}

@mixin mdc-select-native-control-bottom-line-color_($color) {
  border-bottom-color: $color;
}

@mixin mdc-select-focused-line-ripple-color_($color) {
  @include mdc-select-focused-line-ripple_ {
    @include mdc-line-ripple-color($color);
  }
}

@mixin mdc-select-dd-arrow-svg-bg_($fill-hex-number: 000000, $opacity: .54) {
  background-image: url("data:image/svg+xml,%3Csvg%20width%3D%2210px%22%20height%3D%225px%22%20viewBox%3D%227%2010%2010%205%22%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%3E%0A%20%20%20%20%3Cpolygon%20id%3D%22Shape%22%20stroke%3D%22none%22%20fill%3D%22%23#{$fill-hex-number}%22%20fill-rule%3D%22evenodd%22%20opacity%3D%22#{$opacity}%22%20points%3D%227%2010%2012%2015%2017%2010%22%3E%3C%2Fpolygon%3E%0A%3C%2Fsvg%3E");
}

@mixin mdc-select-outline-color_($color) {
  // NOTE: outlined version of select wants the "idle" and
  // "notched" outline to have the same color. This covers two cases:
  // 1) text field renders with NO value in the "idle" state
  // 2) text field renders with a value in the "notched" state
  @include mdc-notched-outline-idle-color($color);
  @include mdc-notched-outline-color($color);
}

@mixin mdc-select-hover-outline-color_($color) {
  &:not(.mdc-select__native-control:focus) .mdc-select__native-control:hover ~ {
    @include mdc-notched-outline-idle-color($color);

    // stylelint-disable-next-line selector-max-specificity
    .mdc-notched-outline {
      @include mdc-notched-outline-color($color);
    }
  }
}

@mixin mdc-select-focused-outline-color_($color) {
  @include mdc-select-focused-outline_ {
    @include mdc-notched-outline-color($color);
  }
}
