//
// 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/@carbon/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;
  }

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

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

    display: block;
    width: rem(224px);
    min-width: rem(128px);
    max-width: rem(448px);

    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;

    // 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;
    -moz-appearance: none;
    -webkit-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-background-color;
      border-bottom-color: $disabled-background-color;
      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: $disabled-background-color;
      cursor: not-allowed;
    }
  }

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

  .#{$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;
  }

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

  // 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 {
    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-background-color;
  }

  .#{$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;
}
