//-----------------------------
// Select
//-----------------------------

@import '../../globals/scss/vars';
@import '../../globals/scss/colors';
@import '../../globals/scss/css--reset';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/typography';
@import '../../globals/scss/spacing';
@import '@carbon/import-once/scss/import-once';
@import '../Form/form';

@include exports('select') {
  .#{$prefix}--select {
    @include reset;
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    order: 2;
  }

  .#{$prefix}--select-input {
    @include font-family;
    @include typescale('zeta');
    height: $input-height;
    appearance: none;
    display: block;
    width: 100%;
    padding: 0 $spacing-lg 0 $spacing-xs;
    color: var(--text-01);
    background-color: var(--field-01);
    border: $input-border;
    order: 2;
    border-radius: 0;
    cursor: pointer;

    // Hide default select arrow in IE10+
    &::-ms-expand {
      display: none;
    }

    & ~ .#{$prefix}--label {
      order: 1;
    }

    &:focus {
      @include focus-outline('border');
    }

    &[data-invalid],
    &[data-invalid]:focus {
      // box-shadow: 0 2px 0 0 var(--support-01);
    }

    &:focus ~ .#{$prefix}--label {
      color: var(--interactive-01);
    }

    &[data-invalid]:focus ~ .#{$prefix}--label {
      color: var(--support-01);
    }

    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    ~ .#{$prefix}--form-requirement {
      order: 3;
      color: var(--support-01);
      font-weight: 400;
      margin-top: $spacing-2xs;

      &::before {
        display: none;
      }
    }
  }

  .#{$prefix}--select--light .#{$prefix}--select-input {
    background: var(--field-02);
  }

  .#{$prefix}--select__arrow {
    fill: var(--interactive-01);
    position: absolute;
    right: 0.6rem;
    bottom: 1rem;
    width: rem(10px);
    height: rem(5px);
    pointer-events: none;
  }

  //TODO: Check validity
  [data-invalid] ~ .#{$prefix}--select__arrow {
    // bottom: 2.25rem;  //remove, it displaces the arrow icon
  }

  .#{$prefix}--select-optgroup,
  .#{$prefix}--select-option {
    color: var(--text-01); // For the options to show in IE11
  }

  .#{$prefix}--select-option[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
  }

  // Override some Firefox user-agent styles
  @-moz-document url-prefix() {
    .#{$prefix}--select-option {
      background-color: var(--ui-01);
      color: var(--text-01);
    }

    .#{$prefix}--select-optgroup {
      color: var(--text-01);
    }
  }

  .#{$prefix}--select--small {
    //TODO: work in progress
    .#{$prefix}--select-input {
      font-size: 0.8em;
      height: 30px;
      padding-right: 1.7rem;
    }
    .#{$prefix}--select__arrow {
      right: 0.6rem;
      bottom: 0.785rem;
    }
  }

  .#{$prefix}--select--inline {
    display: grid;
    grid-template-columns: auto auto;

    // Targets IE10+ browsers: Display grid auto not supported
    @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
      display: flex;
      flex-direction: row;
      align-items: center;
    }

    .#{$prefix}--label {
      white-space: nowrap;
      margin: 0 $spacing-xs 0 0;
      font-weight: 400;
      align-self: center;
    }

    .#{$prefix}--select-input {
      background-color: transparent;
      color: var(--interactive-01);
      font-weight: 600;
      box-shadow: none;

      &:hover {
        background-color: $color__white;
      }

      &:focus {
        @include focus-outline('border');
      }

      ~ .#{$prefix}--select__arrow {
        bottom: auto;
        top: 1rem;
      }

      &[data-invalid] {
        color: var(--text-01);
        outline-offset: 2px;

        &:focus {
          outline: 1px solid var(--support-01);
          box-shadow: none;
        }
      }

      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }

      ~ .#{$prefix}--form-requirement {
        grid-column-start: 2;

        // Targets IE10+ browsers: Display grid auto not supported
        @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
          position: absolute;
          bottom: -1.5rem;
        }
      }
    }
  }

  .#{$prefix}--select-input:disabled ~ .#{$prefix}--select__arrow {
    opacity: 0.5;
  }

  //Skeleton State
  .#{$prefix}--select.#{$prefix}--skeleton {
    @include skeleton;
    width: 100%;
    height: 2.5rem;
  }

  .#{$prefix}--select.#{$prefix}--skeleton .#{$prefix}--select-input {
    display: none;
  }
}
