//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

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

@import '../../globals/scss/vars';
@import '../../globals/scss/css--reset';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/typography';
@import '../../globals/scss/vendor/@rocketsoftware/elements/scss/import-once/import-once';
@import '../form/form';

/// Select styles
/// @access private
/// @group select
@mixin select {
  .#{$prefix}--select {
    @include reset;

    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
  }

  .#{$prefix}--select-input__wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
  }

  .#{$prefix}--select-input {
    @include type-style('body-short-01');
    @include focus-outline('reset');

    display: block;
    width: 100%;
    height: rem(40px);
    padding: 0 $spacing-09 0 $spacing-05;
    color: $text-01;
    background-color: $field-01;
    border: none;
    border-bottom: 1px solid $ui-04;
    border-radius: 0;
    cursor: pointer;
    // reset disabled <select> opacity
    opacity: 1;

    // Do not transition on background-color (see: https://github.com/carbon-design-system/carbon/issues/4464)
    transition: outline $duration--fast-01 motion(standard, productive);
    appearance: none;

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

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

    // Select text renders a little high on Firefox
    @-moz-document url-prefix() {
      // Removes dotted inner focus
      &:-moz-focusring,
      &::-moz-focus-inner {
        color: transparent;
        text-shadow: 0 0 0 #000000;
        background-image: none;
      }
    }

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

      color: $text-01;
    }

    &:disabled,
    &:hover:disabled {
      color: $disabled-02;
      background-color: $disabled-01;
      border-bottom-color: $disabled-01;
      cursor: not-allowed;
    }
  }

  .#{$prefix}--select-input--sm {
    height: rem(32px);
    max-height: rem(32px);
  }

  .#{$prefix}--select-input--xl {
    height: rem(48px);
    max-height: rem(48px);
  }

  .#{$prefix}--select--disabled .#{$prefix}--label,
  .#{$prefix}--select--disabled .#{$prefix}--form__helper-text {
    color: $disabled-02;
  }

  .#{$prefix}--select-input__wrapper[data-invalid] .#{$prefix}--select-input {
    padding-right: carbon--mini-units(10);
  }

  .#{$prefix}--select-input:disabled ~ .#{$prefix}--select__arrow {
    fill: $disabled-02;
  }

  .#{$prefix}--select--light .#{$prefix}--select-input {
    background-color: $field-02;

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

    &:disabled,
    &:hover:disabled {
      color: $disabled-02;
      background-color: $field-02;
      cursor: not-allowed;
    }
  }

  .#{$prefix}--select__arrow {
    position: absolute;
    top: 0;
    right: $spacing-05;
    height: 100%;
    pointer-events: none;
    fill: $ui-05;

    // Windows, Firefox HCM Fix
    @media screen and (-ms-high-contrast: active),
      screen and (prefers-contrast) {
      // `ButtonText` is a CSS2 system color to help improve colors in HCM
      path {
        fill: ButtonText;
      }
    }
  }

  .#{$prefix}--select-input__wrapper[data-invalid]
    .#{$prefix}--select-input
    ~ .#{$prefix}--select__invalid-icon {
    position: absolute;
    right: $spacing-09;
    fill: $support-01;
  }

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

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

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

  .#{$prefix}--select--inline {
    display: flex;
    flex-direction: row;
    align-items: center;
  }

  .#{$prefix}--select--inline.#{$prefix}--select--invalid .#{$prefix}--label,
  .#{$prefix}--select--inline.#{$prefix}--select--invalid
    .#{$prefix}--form__helper-text {
    align-self: flex-start;
    // Offset label text margin
    margin-top: rem(13px);
  }

  .#{$prefix}--select--inline .#{$prefix}--form__helper-text {
    margin-bottom: 0;
    margin-left: $spacing-03;
  }

  .#{$prefix}--select--inline .#{$prefix}--label {
    margin: 0 $carbon--spacing-03 0 0;
    white-space: nowrap;
  }

  .#{$prefix}--select--inline .#{$prefix}--select-input {
    width: auto;
    padding-right: $spacing-07;
    padding-left: $carbon--spacing-03;
    color: $text-01;
    background-color: transparent;
    border-bottom: none;
  }

  .#{$prefix}--select--inline .#{$prefix}--select-input[disabled],
  .#{$prefix}--select--inline .#{$prefix}--select-input[disabled]:hover {
    background-color: $disabled-01;
  }

  .#{$prefix}--select--inline .#{$prefix}--select__arrow {
    right: $carbon--spacing-03;
  }

  .#{$prefix}--select--inline.#{$prefix}--select--invalid
    .#{$prefix}--select-input {
    padding-right: rem(56px);
  }

  .#{$prefix}--select--inline.#{$prefix}--select--invalid
    .#{$prefix}--select-input
    ~ .#{$prefix}--select__invalid-icon {
    right: $spacing-07;
  }

  .#{$prefix}--select--inline .#{$prefix}--select-input:disabled {
    color: $disabled;
    cursor: not-allowed;

    ~ * {
      cursor: not-allowed;
    }
  }

  //Skeleton State
  .#{$prefix}--select.#{$prefix}--skeleton {
    @include skeleton;

    width: 100%;
    height: 2.5rem;
  }

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

@include exports('select') {
  @include select;
}
