$aui-select-arrow-width: 13px;
$aui-select-arrow-top-default: $aui-field-default-height * .525; // Center with label
$aui-select-color: $aui-color-dark;
$aui-select-color-secondary: $aui-color-gray40;
$aui-select-border: $aui-color-gray50;
$aui-select-border-hover: $aui-color-black;
$aui-select-border-focus: $aui-color-black;
$aui-select-border-dirty: $aui-color-black;
$aui-select-color-arrow: $aui-field-placeholder-color;
$aui-select-color-arrow-dirty: $aui-select-color;

.aui-select {
  display: block;
  position: relative;
  margin: 0;
  padding: 0;
  padding-top: $aui-field-floating-label-padding;
  font-size: 1rem;
  line-height: $aui-field-line-height;
  box-sizing: border-box;


  &:hover {
    .aui-select__focus-line {
      background: $aui-select-border-hover;
    }
  }

  &__input {
    display: block;
    margin: 0;
    padding-right: #{rem($aui-select-arrow-width) + unit(2)};
    width: 100%;
    min-height: $aui-field-default-height;
    font-family: $aui-font-default;
    font-size: inherit;
    font-weight: $aui-font-weight-normal;
    line-height: inherit;
    color: $aui-field-placeholder-color;
    background: none;
    border: none;
    border-bottom: 1px solid $aui-select-border;
    border-radius: 0;
    box-shadow: none;
    transition: color, border;
    transition-duration: $aui-field-transition-duration;
    transition-timing-function: $aui-easing;
    appearance: none;
    outline: 0;

    // HACK IE: Remove arrow.
    &::-ms-expand {
      display: none;
    }

    // HACK [1] IE: Remove blue background when selected.
    // HACK [2] IE: Use placeholder color, if default value is selected.
    &::-ms-value {
      background: none; // [1]
      color: $aui-field-placeholder-color; // [2]
    }

    // HACK Firefox, IE: Fix styling on backgrounds other than white.
    option {
      color: $aui-select-color;
      background: white;

      &:disabled {
        color: $aui-field-placeholder-color;
      }
    }

    // NOTE Don't use this kind of a hack to remove the dotted outline in Mozilla.
    // color: transparent;
    // text-shadow: 0 0 0 #333;
  }

  // HACK Firefox: Fix vertical aligment.
  // https://bugzilla.mozilla.org/show_bug.cgi?id=610733
  @-moz-document url-prefix() {
    .aui-select__input {
      padding-top: (9 / 16 * 1em);
    }
  }

  &__label {
    display: block;
    position: absolute;
    top: $aui-field-label-y;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    color: $aui-field-placeholder-color;
    font-size: inherit;
    font-weight: $aui-font-weight-normal;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition-property: top, font-size, color, opacity;
    transition-duration: $aui-field-transition-duration;
    transition-timing-function: $aui-easing;
    opacity: 1;
    pointer-events: none;
  }

  // Arrow icon
  &::after {
    content: '';
    display: block;
    position: absolute;
    //top: $aui-select-arrow-top-default;
    top: $aui-select-arrow-top-default + $aui-field-floating-label-padding;
    right: 0;
    width: $aui-select-arrow-width;
    height: 8px;
    background: url('data:image/svg+xml,#{aui-svg-dropdown-arrow($aui-select-color-arrow)}') center center no-repeat;
    transform: translateY(-50%);
    transition: background .25s linear;
    pointer-events: none;
  }

  // Focus line will be injected by JS
  &__focus-line {
    display: block;
    position: relative;
    width: 100%;
    margin-top: -1px;
    height: 1px;
    background: $aui-select-border;
    opacity: 1;
    transition-property:  background;
    transition-duration: $aui-field-transition-duration;
  }

  &__description {
    display: block;
    color: $aui-select-color-secondary;
    transition: color $aui-field-transition-duration linear;
    margin-top: unit(3.5);
    font-size: rem(13);
    line-height: $aui-field-error-line-height;
  }

  &__error {
    display: flex;
    align-items: center;
    line-height: $aui-field-error-line-height;
    margin-top: unit(3.5);
    font-size: rem(13);
    color: $aui-field-error-color;

    &::before {
      content: '';
      display: inline-block;
      margin-right: rem(16px);
      width: 40px;
      height: 24px;
      background: url('data:image/svg+xml,#{aui-svg-caution($aui-field-error-color)}') center center no-repeat;

      @include aui-respond-to('large') {
        margin-right: unit(2);
        width: 24px;
        height: 24px;
      }
    }
  }

  /**
   * Variant: floating-label
   */
  // &.aui-select--floating-label {
  //   // padding-top: $aui-field-floating-label-padding;

  //   // Arrow icon
  //   &::after {
  //     top: $aui-select-arrow-top-default + $aui-field-floating-label-padding;
  //   }
  // }

  .aui-js &.aui-select--floating-label &__label {
    top: $aui-field-label-y + $aui-field-floating-label-padding + 0.0925rem;
  }

  &.aui-select--floating-label {
    .aui-select__input {
      opacity: 0;

      &:focus,
      &:not(:focus)
      {
        opacity: 1;
      }
    }

    // Arrow icon
    &::after {
      top: $aui-select-arrow-top-default + $aui-field-floating-label-padding;
    }
  }

  /**
   * States
   */

  // Hover state
  &:not(.is-disabled):not(.is-invalid) {
    .aui-select__input:hover {
      border-color: $aui-select-border-hover;
    }
  }

  // Focus state
  &.is-focused {
    .aui-select__label {
      opacity: 0;
    }

    &.aui-select--floating-label .aui-select__label {
      top: 0;
      font-size: .75rem;
      opacity: 1;
    }

    .aui-select__input {
      outline: none;
      box-shadow: none;
      border-color: $aui-select-border-focus;
    }

    .aui-select__focus-line {
      //opacity: 1;
      opacity: 0;
    }
  }

  // Disabled state
  &.is-disabled {
    //opacity: $aui-field-disabled-opacity;
    color: $aui-color-gray40;
    cursor: not-allowed;

    .aui-select__input {
      cursor: not-allowed;
    }

    .aui-select__focus-line {
      opacity: 1;
    }
  }

  // Dirty state
  &.is-dirty {
    &::after {
      // Arrow icon
      background-image: url('data:image/svg+xml,#{aui-svg-dropdown-arrow($aui-select-color-arrow-dirty)}');
    }

    .aui-select__label {
      opacity: 0;
    }

    &.aui-select--floating-label .aui-select__label {
      top: 0;
      font-size: .75rem;
      opacity: 1;
    }

    .aui-select__input {
      border-color: $aui-select-border-dirty;
      color: $aui-select-color;

      // Style color on IE10+ when selected
      &::-ms-value {
        color: $aui-select-color;
      }
    }
  }

  // Invalid state
  &.is-invalid {
    &,
    &:not(.is-dirty) .aui-select__input,
    .aui-select__label {
      color: $aui-field-error-color;
    }

    // Arrow icon
    &::after {
      background-image: url('data:image/svg+xml,#{aui-svg-dropdown-arrow($aui-field-error-color)}');
    }

    .aui-select__input {
      border-color: $aui-field-error-color;
    }

    .aui-select__focus-line {
      background: $aui-field-error-color;
    }
  }
}
