/**
 *
 * @ai-apps/angular v2.152.0 | _text-input.scss
 *
 * Copyright 2014, 2023 IBM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


//
// 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');

    width: 100%;
    height: rem(40px);
    padding: 0 $carbon--spacing-05;
    border: none;
    border-bottom: 1px solid $ui-04;
    background-color: $field-01;
    color: $text-01;
    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;
    }
  }

  // TODO V11: Remove xl selector
  .#{$prefix}--text-input--xl,
  .#{$prefix}--text-input--lg {
    height: rem(48px);
  }

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

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

  .#{$prefix}--text-input--sm.#{$prefix}--password-input {
    padding-right: $carbon--spacing-07;
  }

  .#{$prefix}--text-input--lg.#{$prefix}--password-input {
    padding-right: $carbon--spacing-09;
  }

  .#{$prefix}--text-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;
    width: 100%;
  }

  .#{$prefix}--text-input__invalid-icon,
  .#{$prefix}--text-input__readonly-icon {
    position: absolute;
    // top/transform used to center invalid icon in IE11
    top: 50%;
    right: $carbon--spacing-05;
    transform: translateY(-50%);
  }

  .#{$prefix}--text-input__invalid-icon {
    fill: $support-01;
  }

  .#{$prefix}--text-input__invalid-icon--warning {
    fill: $support-03;
  }

  .#{$prefix}--text-input__invalid-icon--warning path:first-of-type {
    fill: $carbon__black-100;
    opacity: 1;
  }

  // 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}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger {
    @include focus-outline('reset');

    position: absolute;
    right: 0;
    display: flex;
    width: rem(40px);
    height: 100%;
    min-height: auto;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    transition: outline $duration--fast-01 motion(standard, productive);
  }

  .#{$prefix}--text-input--sm
    + .#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger {
    width: rem(32px);
  }

  .#{$prefix}--text-input--lg
    + .#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger {
    width: rem(48px);
  }

  .#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger
    svg {
    fill: $icon-secondary;
    transition: fill $duration--fast-01 motion(standard, productive);

    // 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
      fill: ButtonText;
    }
  }

  .#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger:focus {
    @include focus-outline('outline');
  }

  .#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger:hover
    svg,
  .#{$prefix}--btn.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger:focus
    svg {
    fill: $icon-primary;
  }

  .#{$prefix}--text-input--invalid,
  .#{$prefix}--text-input--warning,
  .#{$prefix}--text-input-wrapper--readonly .#{$prefix}--text-input {
    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.#{$prefix}--tooltip__trigger svg {
    cursor: not-allowed;
    fill: $disabled-02;

    &:hover {
      fill: $disabled-02;
    }
  }

  //-----------------------------
  // Disabled
  //-----------------------------
  .#{$prefix}--text-input:disabled {
    @include focus-outline('reset');

    border-bottom: 1px solid transparent;
    background-color: $field;

    color: $text-disabled;
    cursor: not-allowed;
    // Needed to fix disabled text in Safari #6673
    -webkit-text-fill-color: $disabled-02;
  }

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

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

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

  //-----------------------------
  // Skeleton
  //-----------------------------
  .#{$prefix}--skeleton.#{$prefix}--text-input {
    @include skeleton;
  }

  //-----------------------------
  // Fluid Text Input
  //-----------------------------
  .#{$prefix}--form--fluid .#{$prefix}--text-input-wrapper {
    position: relative;
    background: $field-01;
    transition: background-color $duration--fast-01 motion(standard, productive),
      outline $duration--fast-01 motion(standard, productive);
  }

  .#{$prefix}--form--fluid .#{$prefix}--label {
    position: absolute;
    z-index: 1;
    top: rem(13px);
    left: $carbon--spacing-05;
    margin: 0;
  }

  .#{$prefix}--form--fluid .#{$prefix}--form__helper-text {
    display: none;
  }

  .#{$prefix}--form--fluid .#{$prefix}--text-input {
    min-height: rem(64px);
    padding: rem(32px) $carbon--spacing-05 rem(13px);
  }

  .#{$prefix}--text-input__divider,
  .#{$prefix}--form--fluid .#{$prefix}--text-input__divider {
    display: none;
  }

  .#{$prefix}--form--fluid .#{$prefix}--text-input--invalid,
  .#{$prefix}--form--fluid .#{$prefix}--text-input--warn {
    border-bottom: none;
  }

  .#{$prefix}--form--fluid
    .#{$prefix}--text-input--invalid
    + .#{$prefix}--text-input__divider,
  .#{$prefix}--form--fluid
    .#{$prefix}--text-input--warn
    + .#{$prefix}--text-input__divider {
    display: block;
    border-style: solid;
    border-color: $ui-03;
    border-bottom: none;
    margin: 0 1rem;
  }

  .#{$prefix}--form--fluid .#{$prefix}--text-input__invalid-icon {
    top: rem(80px);
  }

  .#{$prefix}--form--fluid .#{$prefix}--text-input-wrapper--light {
    background: $field-02;
  }

  .#{$prefix}--form--fluid
    .#{$prefix}--text-input__field-wrapper[data-invalid]
    > .#{$prefix}--text-input--invalid {
    @include focus-outline('reset');
  }

  .#{$prefix}--form--fluid
    .#{$prefix}--text-input__field-wrapper[data-invalid]:not(:focus) {
    @include focus-outline('invalid');
  }

  .#{$prefix}--form--fluid
    .#{$prefix}--text-input__field-wrapper[data-invalid]
    > .#{$prefix}--text-input--invalid:focus {
    @include focus-outline('outline');
  }

  //-----------------------------
  // Inline Text Input
  //-----------------------------

  .#{$prefix}--text-input-wrapper.#{$prefix}--text-input-wrapper--inline {
    flex-flow: row wrap;
  }

  .#{$prefix}--text-input-wrapper .#{$prefix}--label--inline {
    flex: 1;
    margin: rem(13px) 0 0 0;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  .#{$prefix}--text-input-wrapper .#{$prefix}--label--inline--sm {
    margin-top: rem(9px);
  }

  // TODO V11: Remove xl selector
  .#{$prefix}--text-input-wrapper .#{$prefix}--label--inline--xl,
  .#{$prefix}--text-input-wrapper .#{$prefix}--label--inline--lg {
    margin-top: rem(17px);
  }

  .#{$prefix}--text-input__label-helper-wrapper {
    max-width: rem(128px);
    flex: 2;
    flex-direction: column;
    margin-right: rem(24px);
    overflow-wrap: break-word;
  }

  .#{$prefix}--text-input-wrapper .#{$prefix}--form__helper-text--inline {
    margin-top: rem(2px);
  }

  .#{$prefix}--text-input__field-outer-wrapper {
    display: flex;
    width: 100%;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: flex-start;
  }

  .#{$prefix}--text-input__field-outer-wrapper--inline {
    flex: 8;
    flex-direction: column;
  }

  //-----------------------------
  // Readonly
  //-----------------------------

  .#{$prefix}--form--fluid .#{$prefix}--text-input-wrapper--readonly,
  .#{$prefix}--text-input-wrapper--readonly .#{$prefix}--text-input {
    background: transparent;
  }

  // Windows HCM fix
  .#{$prefix}--text-input--password__visibility,
    // TODO: remove selector above
  .#{$prefix}--btn.#{$prefix}--btn--icon-only.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger svg,
    .#{$prefix}--btn.#{$prefix}--btn--icon-only.#{$prefix}--text-input--password__visibility__toggle.#{$prefix}--tooltip__trigger:hover
    svg {
    @include high-contrast-mode('icon-fill');
  }
}

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