@import '../../global/mixins/form-items';
@import '../../global/mixins/exports';

@include exports('ray-select') {
  .#{$ray-class-prefix}select {
    @include required-support('select');
    @include icon-support('select');
    @include prepend-support('select');

    border: $ray-border-width solid $ray-color-gray-60;
    background-color: $ray-color-white;
    border-radius: $ray-border-radius;
    position: relative;
    height: $ray-field-height;
    display: flex;
    align-items: stretch;

    // __icon--right is DEPRECATED in favor of __icon--end, and will be
    // removed in a future release of Ray. Use of __icon-right may result
    // in confusing behavior for RTL language sensitive layouts.
    &__icon--right,
    &__icon--end {
      @include icon;
      // need to add spacing to compensate for the arrow
      right: calc((#{$ray-field-h-spacing} * 2) + #{$ray-field-h-spacing});

      [dir='rtl'] & {
        right: 0;
        left: calc((#{$ray-field-h-spacing} * 2) + #{$ray-field-h-spacing});
      }
    }

    &::after {
      content: '';
      pointer-events: none;
      position: absolute;
      right: $ray-field-h-spacing;
      top: 0px;
      bottom: 0px;
      width: 0px;
      height: 0px;
      margin: auto;
      border-left: 6px solid transparent;
      border-right: 6px solid transparent;
      border-top: 8px solid $ray-color-gray-60;
      border-radius: 2px;

      [dir='rtl'] & {
        right: calc(100% - (2 * #{$ray-field-h-spacing}));
      }
    }

    &__wrapper {
      position: relative;
      flex: 1;
    }

    &__label {
      @include label;
      pointer-events: none;
      z-index: 2;
      cursor: pointer;
    }

    &__input {
      appearance: none;
      font-family: inherit;
      border-radius: $ray-border-radius;
      width: 100%;
      height: 100%;
      font-size: $ray-field-label-size;
      display: block;
      background-color: transparent;
      padding: 0 1.75rem 0 $ray-field-h-spacing;
      outline: 0;
      border: 0;
      cursor: pointer;
      color: rgba(0, 0, 0, 0);

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

      [dir='rtl'] & {
        padding: 0 $ray-field-h-spacing 0 1.75rem;
      }
    }

    &--placeholder-mode {
      .#{$ray-class-prefix}select__input {
        color: rgba(0, 0, 0, 0);
      }
    }

    &--has-value {
      .#{$ray-class-prefix}select__label {
        @include label--active;
      }

      .#{$ray-class-prefix}select__input {
        color: $ray-color-black;
      }
    }

    &--error {
      border-color: $ray-color-red-50;

      &::after {
        border-top-color: $ray-color-red-50;
      }

      .#{$ray-class-prefix}select__label {
        color: $ray-color-red-50;
      }
    }

    &--active {
      border-color: $ray-color-blue-50;

      .#{$ray-class-prefix}select__input {
        color: $ray-color-black;
      }

      .#{$ray-class-prefix}select__label {
        color: $ray-color-blue-50;
      }

      &.#{$ray-class-prefix}select--placeholder-mode {
        .#{$ray-class-prefix}select__label {
          @include label--active;
        }

        .#{$ray-class-prefix}select__input {
          color: $ray-color-text-light;
        }
      }

      &.#{$ray-class-prefix}select--has-value {
        .#{$ray-class-prefix}select__input {
          color: $ray-color-blue-50;
        }
      }

      &::after {
        border-top-color: $ray-color-blue-50;
      }
    }

    &--compact {
      height: $ray-field-height-compact;

      .#{$ray-class-prefix}select__label {
        display: flex;
        align-items: center;
        padding-top: 0;
        padding-bottom: 0;
      }
    }

    &--disabled {
      border-color: rgba($ray-color-gray-60, 0.4);

      &::after {
        border-top-color: rgba($ray-color-gray-60, 0.4);
      }

      .#{$ray-class-prefix}select__input {
        color: rgba($ray-color-gray-60, 0.4);
        cursor: not-allowed;
      }

      .#{$ray-class-prefix}select__label {
        color: rgba($ray-color-gray-60, 0.4);
      }
    }

    &--simple {
      flex: 1;
      border: none;
      background-color: transparent;
      border-radius: 0;

      &__input {
        font-size: ($ray-field-label-size * 1.2);
        width: rem(69px);
        padding-right: 3 * $ray-field-h-spacing;

        [dir='rtl'] & {
          padding-right: $ray-field-h-spacing;
          padding-left: 3 * $ray-field-h-spacing;
        }

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