//
// 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.
//

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

/// Form styles
/// @access private
/// @group form
@mixin form {
  .#{$prefix}--fieldset {
    @include reset;

    margin-bottom: $carbon--spacing-07;
  }

  .#{$prefix}--form-item {
    @include type-style('body-short-01');

    display: flex;
    // We specify `auto` as the default value so that the form item does
    // not collapse in IE11 due to a `flex-basis` of 0 only working with
    // `flex-direction: row`
    flex: 1 1 auto;
    flex-direction: column;
    align-items: flex-start;
  }

  .#{$prefix}--label {
    @include reset;
    @include type-style('label-01');

    display: inline-block;
    margin-bottom: $carbon--spacing-03;
    color: $text-02;
    font-weight: $input-label-weight;
    line-height: 1rem;
    vertical-align: baseline;
  }

  .#{$prefix}--label .#{$prefix}--tooltip__trigger {
    // When tooltip trigger is put in form label the trigger button should fit in the size of label
    // https://github.com/IBM/carbon-components-react/issues/115
    @include type-style('label-01');
  }

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

    width: rem(75px);
    height: rem(14px);
  }

  input[type='number'] {
    font-family: carbon--font-family('mono');
  }

  input[data-invalid]:not(:focus),
  .#{$prefix}--number[data-invalid] input[type='number']:not(:focus),
  .#{$prefix}--text-input__field-wrapper[data-invalid]
    > .#{$prefix}--text-input--invalid:not(:focus),
  .#{$prefix}--text-area__wrapper[data-invalid]
    > .#{$prefix}--text-area--invalid:not(:focus),
  .#{$prefix}--select-input__wrapper[data-invalid]
    .#{$prefix}--select-input:not(:focus),
  .#{$prefix}--list-box[data-invalid]:not(:focus),
  .#{$prefix}--combo-box[data-invalid] .#{$prefix}--text-input:not(:focus) {
    @include focus-outline('invalid');
  }

  input[data-invalid],
  [data-invalid],
  .#{$prefix}--number[data-invalid] .#{$prefix}--number__input-wrapper,
  .#{$prefix}--date-picker-input__wrapper,
  .#{$prefix}--time-picker--invalid,
  .#{$prefix}--text-input__field-wrapper[data-invalid],
  .#{$prefix}--text-input--warn,
  .#{$prefix}--text-area__wrapper[data-invalid],
  .#{$prefix}--select-input__wrapper[data-invalid],
  .#{$prefix}--time-picker[data-invalid],
  .#{$prefix}--list-box[data-invalid] {
    ~ .#{$prefix}--form-requirement {
      display: block;
      max-height: rem(200px);
      overflow: visible;
      font-weight: 400;
    }
  }

  input[data-invalid],
  [data-invalid],
  .#{$prefix}--number[data-invalid] .#{$prefix}--number__input-wrapper,
  .#{$prefix}--date-picker-input__wrapper,
  .#{$prefix}--time-picker--invalid,
  .#{$prefix}--text-input__field-wrapper[data-invalid],
  .#{$prefix}--text-area__wrapper[data-invalid],
  .#{$prefix}--select-input__wrapper[data-invalid],
  .#{$prefix}--time-picker[data-invalid],
  .#{$prefix}--list-box[data-invalid] {
    ~ .#{$prefix}--form-requirement {
      color: $text-error;
    }
  }

  //Fluid Form
  .#{$prefix}--form--fluid .#{$prefix}--text-input__field-wrapper[data-invalid],
  .#{$prefix}--form--fluid .#{$prefix}--text-input__field-wrapper[data-warn] {
    display: block;
  }

  .#{$prefix}--form--fluid .#{$prefix}--fieldset {
    margin: 0;
  }

  .#{$prefix}--form--fluid input[data-invalid] {
    outline: none;
  }

  .#{$prefix}--form--fluid .#{$prefix}--form-requirement {
    margin: 0;
    padding: $carbon--spacing-03 rem(40px) $carbon--spacing-03
      $carbon--spacing-05;
  }

  // Fix for red ring when input is marked required in Firefox, refs #744
  input:not(output):not([data-invalid]):-moz-ui-invalid {
    box-shadow: none;
  }

  .#{$prefix}--form-requirement {
    @include reset;
    @include type-style('caption-01');

    display: none;
    max-height: 0;

    margin: $carbon--spacing-02 0 0;
    overflow: hidden;
  }

  .#{$prefix}--select--inline .#{$prefix}--form__helper-text {
    margin-top: 0;
  }

  .#{$prefix}--form__helper-text {
    @include type-style('helper-text-01');

    z-index: 0;
    // Added to prevent error text from displaying under helper text in Safari (#6392)
    width: 100%;
    margin-top: $carbon--spacing-02;
    color: $text-02;
    opacity: 1;
  }

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

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