//
// 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 "./keyframes";
@import "./mixins";
@import "./variables";
@import "@material/animation/variables";
@import "@material/line-ripple/mdc-line-ripple";
@import "@material/notched-outline/mdc-notched-outline";
@import "@material/floating-label/mdc-floating-label";
@import "@material/typography/mixins";
@import "@material/ripple/common";
@import "@material/ripple/mixins";
@import "@material/rtl/mixins";

// postcss-bem-linter: define select
.mdc-select {
  @include mdc-select-container-fill-color(transparent);
  @include mdc-select-dd-arrow-svg-bg_;
  @include mdc-select-ink-color($mdc-select-ink-color);
  @include mdc-select-label-color($mdc-select-label-color);
  @include mdc-select-bottom-line-color($mdc-select-bottom-line-idle-color);

  // Focused state colors
  @include mdc-select-focused-bottom-line-color(primary);
  @include mdc-select-focused-label-color($mdc-select-focused-label-color);

  // Hover state colors
  @include mdc-select-hover-bottom-line-color($mdc-select-bottom-line-hover-color);

  display: inline-flex;
  position: relative;
  box-sizing: border-box;
  height: 52px;
  background-repeat: no-repeat;
  background-position: right 8px bottom 12px;

  @include mdc-rtl {
    background-position: left 8px bottom 12px;
  }

  &__native-control {
    @include mdc-rtl-reflexive-property(padding, 0, $mdc-select-arrow-padding);
    @include mdc-typography(subtitle1);

    &::-ms-expand {
      display: none;
    }

    &::-ms-value {
      background-color: transparent;
      color: inherit;
    }

    // counteracts the extra text padding that Firefox adds by default
    @-moz-document url-prefix("") {
      text-indent: -2px;
    }

    // stylelint-disable-next-line selector-max-type, plugin/selector-bem-pattern
    > option {
      color: inherit; // Override default user agent stylesheet
    }

    width: 100%;
    padding-top: 20px;
    padding-bottom: 4px;
    border: none;
    border-bottom: 1px solid;
    border-radius: 0;
    outline: none;
    background-color: transparent;
    color: inherit; // Override default user agent stylesheet
    white-space: nowrap;
    cursor: pointer;
    appearance: none;
  }

  // stylelint-disable-next-line plugin/selector-bem-pattern
  .mdc-floating-label {
    pointer-events: none;
  }

  @include mdc-select-focused-line-ripple_ {
    &::after {
      transform: scale(1, 2);
      opacity: 1;
    }
  }
}

.mdc-select--box {
  @include mdc-select-container-fill-color($mdc-select-box-fill-color);
  @include mdc-ripple-surface;
  @include mdc-ripple-radius-bounded;
  // Select Box intentionally omits press ripple, so each state needs to be specified individually
  @include mdc-states-base-color($mdc-select-ink-color);
  @include mdc-states-hover-opacity(mdc-states-opacity($mdc-select-ink-color, hover));
  @include mdc-states-focus-opacity(mdc-states-opacity($mdc-select-ink-color, focus));

  height: 56px;
  border-radius: 4px 4px 0 0;
  background-position: right 10px center;
  overflow: hidden;

  @include mdc-rtl {
    background-position: left 10px center;
  }

  .mdc-select__native-control {
    @include mdc-rtl-reflexive-property(padding, $mdc-select-label-padding, $mdc-select-arrow-padding);

    height: 56px;
    border-radius: 4px 4px 0 0;
  }

  // stylelint-disable plugin/selector-bem-pattern
  .mdc-floating-label {
    @include mdc-rtl-reflexive-position(left, 16px);

    bottom: 12px;
    line-height: 1.75rem;

    &--float-above {
      transform: translateY(-40%) scale(.75, .75);
    }
  }
  // stylelint-enable plugin/selector-bem-pattern
}

.mdc-select--outlined {
  @include mdc-select-outline-color($mdc-select-outlined-idle-border);
  @include mdc-select-hover-outline-color($mdc-select-outlined-hover-border);
  @include mdc-select-focused-outline-color(primary);
  @include mdc-floating-label-float-position($mdc-select-outlined-label-position-y);
  @include mdc-floating-label-shake-animation(text-field-outlined);
  @include mdc-select-outline-corner-radius($mdc-select-border-radius);

  height: 56px;
  border: none;
  background-position: right 10px center;

  @include mdc-rtl {
    background-position: left 10px center;
  }

  .mdc-select__native-control {
    @include mdc-rtl-reflexive-property(padding, $mdc-select-label-padding, $mdc-select-arrow-padding);

    display: flex;
    padding-top: 12px;
    padding-bottom: 12px;
    border: none;
    background-color: transparent;
    z-index: 1;
  }

  // stylelint-disable-next-line plugin/selector-bem-pattern
  .mdc-floating-label {
    @include mdc-rtl-reflexive-position(left, 16px);

    position: absolute;
    bottom: 20px;
  }
}

.mdc-select--disabled {
  @include mdc-select-dd-arrow-svg-bg_($mdc-select-disabled-arrow-color);

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

  // stylelint-disable plugin/selector-bem-pattern
  .mdc-line-ripple {
    display: none;
  }

  .mdc-select__native-control {
    border-bottom-style: dotted;
    color: $mdc-select-disabled-ink-color;
  }
  // stylelint-enable plugin/selector-bem-pattern

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

  &.mdc-select--outlined {
    // stylelint-disable-next-line plugin/selector-bem-pattern
    .mdc-select__native-control {
      border-bottom-style: none;
    }

    @include mdc-select-outline-color_($mdc-select-outlined-disabled-border);
  }

  cursor: default;
  pointer-events: none;
}
