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

//-----------------------------
// Text
//-----------------------------
@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 '../../globals/scss/tooltip';
@import '../form/form';

/// Text input styles
/// @access private
/// @group text-input
@mixin text-input {
  .#{$prefix}--text-input {
    @include reset;
    @include type-style('body-short-01');
    @include focus-outline('reset');
    background-color: $field-01;
    width: 100%;
    height: rem(40px);
    padding: 0 $carbon--spacing-05;
    color: $text-01;
    border: none;
    border-bottom: 1px solid $ui-04;
    transition: background-color $duration--fast-01 motion(standard, productive),
      outline $duration--fast-01 motion(standard, productive);

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

    &-wrapper svg[hidden] {
      display: none;
    }
  }

  .#{$prefix}--password-input {
    padding-right: $carbon--spacing-08;
  }

  .#{$prefix}--text-input::-webkit-input-placeholder {
    @include placeholder-colors;
  }

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

  //-----------------------------
  // Disabled & Error icon spacing
  //-----------------------------
  .#{$prefix}--text-input__field-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;

    .#{$prefix}--text-input__invalid-icon {
      position: absolute;
      right: $carbon--spacing-05;
      fill: $support-01;
    }

    // TODO: deprecate this style block
    .#{$prefix}--text-input--password__visibility {
      @include tooltip--trigger('icon', 'bottom');
      @include tooltip--placement('icon', 'bottom', 'center');
    }

    .#{$prefix}--text-input--password__visibility,
    // TODO: remove selector above
    .#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger {
      position: absolute;
      height: rem(16px);
      width: rem(16px);
      right: $carbon--spacing-05;
      padding: 0;
      border: 0;
      background: none;
      cursor: pointer;

      svg {
        fill: $icon-02;
      }
    }

    .#{$prefix}--text-input--invalid {
      padding-right: $carbon--spacing-08;
    }

    .#{$prefix}--text-input--invalid.#{$prefix}--password-input {
      padding-right: rem(64px);
    }

    .#{$prefix}--text-input--invalid
      + .#{$prefix}--text-input--password__visibility,
    // TODO: remove selector above
    .#{$prefix}--text-input--invalid
      + .#{$prefix}--text-input--password__visibility__toggle {
      right: $carbon--spacing-05;
    }
  }

  .#{$prefix}--password-input-wrapper .#{$prefix}--text-input__invalid-icon {
    right: $carbon--spacing-08;
  }

  .#{$prefix}--text-input:disabled
    + .#{$prefix}--text-input--password__visibility
    svg,
  // TODO: remove selector above
  .#{$prefix}--text-input:disabled
    + .#{$prefix}--text-input--password__visibility__toggle
    svg {
    opacity: 0.5;
    cursor: not-allowed;
  }

  //-----------------------------
  // Disabled
  //-----------------------------
  .#{$prefix}--text-input:disabled {
    cursor: not-allowed;
    outline: none;
    background-color: $disabled-01;
    border-bottom: 1px solid transparent;
    color: $disabled-02;
  }

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

  .#{$prefix}--text-input:disabled::placeholder {
    opacity: 1;
    color: $disabled-02;
  }

  //-----------------------------
  // Error
  //-----------------------------
  .#{$prefix}--text-input--invalid {
    @include focus-outline('invalid');
    box-shadow: none;

    .#{$prefix}--text-input--password__visibility,
    // TODO: remove selector above
    .#{$prefix}--text-input--password__visibility__toggle {
      right: $carbon--spacing-08;
    }
  }
}

@include exports('text-input') {
  @include text-input;
}
