//
// Copyright 2019 Stijn de Witt. Some rights reserved.
// Licensed under the MIT Open Source license. 
// https://opensource.org/licenses/MIT
// See LICENSE for details.
//
// Based on code copyright 2018 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// http://www.apache.org/licenses/LICENSE-2.0
// See LICENSE-MDC for details.
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under these licenses is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the licenses for the specific language governing permissions and
// limitations under these licenses.
// 

@import "./keyframes";
@import "./mixins";
@import "./variables";
@import "../animation/variables";
@import "../line-ripple/mdc-line-ripple";
@import "../floating-label/mdc-floating-label";
@import "../typography/mixins";
@import "../ripple/common";
@import "../ripple/mixins";
@import "../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;
  overflow: hidden;

  @include mdc-rtl {
    background-position: left 8px bottom 12px;
  }

  &__native-control {
    @include mdc-rtl-reflexive-property(padding, 0, $mdc-select-arrow-padding);
    @include typography(subtitle1);

    &::-ms-expand {
      display: none;
    }

    // counteracts the extra text padding that Firefox adds by default
    @-moz-document url-prefix("") {
      text-indent: -2px;
    }

    width: 100%;
    padding-top: 20px;
    padding-bottom: 4px;
    border: none;
    border-bottom: 1px solid;
    border-radius: 0;
    outline: none;
    background-color: transparent;
    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),
    $has-nested-focusable-element: true
  );

  height: 56px;
  border-radius: 4px 4px 0 0;
  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);

    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--disabled {
  @include mdc-select-dd-arrow-svg-bg_($mdc-select-disabled-arrow-color);

  &.mdc-select--box {
    @include mdc-select-container-fill-color_($mdc-select-box-disabled-fill-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;
  }
  // stylelint-enable plugin/selector-bem-pattern

  .mdc-select__native-control {
    border-bottom-style: dotted;
  }

  opacity: .38;
  cursor: default;
  pointer-events: none;
}
