// ============================================================================
// :: Input
// ============================================================================
/**
 * An input field where to user can insert a value and can be send using forms
 * towards the server.
 */

// ============================================================================
// :: Settings
// ============================================================================
$padding-horizontal: 2rem;
$icon-width: 2rem;

// ============================================================================
// :: Root
// ============================================================================
.a-input {
  position: relative;

  display: inline-block;
}

// ============================================================================
// :: Elements
// ============================================================================
.a-input__label {
  display: block;

  margin-bottom: 1rem;

  font-family: $font-family-sora;
  font-weight: $font-weight-bold;
  font-size: $font-size-1x-small;
  line-height: $line-height-1x-small;

  color: $text-color-base;

  @include respond-at($breakpoint-tablet-default) {
    font-size: $font-size-base;
    line-height: $line-height-base;
  }
}

.a-input__container {
  position: relative;
}

.a-input__currency {
  display: flex;
  align-items: center;
  position: absolute;
  left: 1px;
  top: 1px;
  bottom: 1px;
  font-family: $font-family-sora;
  font-weight: $font-weight-regular;
  font-size: $font-size-1x-small;
  line-height: $line-height-1x-small;
  padding: 1.2rem 0 1.2rem $padding-horizontal;
  pointer-events: none;

  @include respond-at($breakpoint-tablet-default) {
    font-size: $font-size-base;
    line-height: $line-height-base;
  }
}

%__input__field {
  width: 100%;
  padding: 1.2rem $padding-horizontal;
  min-height: 45px;

  background-color: $background-color-white;
  border: $border-width-base solid $border-color-1x-light;
  border-radius: $border-radius-base;

  transition: border-color 0.2s ease-in-out;

  line-height: 1;

  @include placeholder() {
    font-family: $font-family-sora;
    font-weight: $font-weight-regular;
    font-size: $font-size-1x-small;
    line-height: $line-height-1x-small;

    color: $text-color-medium;

    @include respond-at($breakpoint-tablet-default) {
      font-size: $font-size-base;
      line-height: $line-height-base;
    }
  }

  &:focus {
    outline: 0.2rem solid $primary-color-base;
    outline-offset: 0.2rem;
  }

  &[disabled] {
    background-color: $background-color-base;

    cursor: not-allowed;

    pointer-events: none;
  }
}

.a-input__field {
  @extend %__input__field;

  &[type="date"] {
    -webkit-appearance: none;

    &::-webkit-inner-spin-button,
    &::-webkit-calendar-picker-indicator {
      display: none;
      -webkit-appearance: none;
    }
  }
}

.a-input__feedback {
  margin-top: 0.5rem;
}

.a-input__feedback-message {
  font-size: $font-size-1x-small;

  @include respond-at($breakpoint-tablet-default) {
    font-size: $font-size-base;
  }
}

.a-input__toggle-password {
  @extend %__icon-eye;

  position: absolute;
  top: 50%;
  right: 2rem;

  width: 2rem;
  height: 2rem;

  opacity: 0.5;

  transform: translateY(-50%);

  cursor: pointer;

  &::before {
    position: absolute;
    top: 50%;
    left: 50%;

    font-size: $icon-size-1x-large;

    transform: translate(-50%, -50%);
  }

  &:hover {
    opacity: 1;
  }
}

.a-input__link {
  display: block;
  margin-top: 1rem;

  text-decoration: underline;
  text-align: right;

  @include respond-at($breakpoint-tablet-default) {
    text-align: left;
  }
}

// ============================================================================
// :: Modifiers
// ============================================================================
.a-input--textarea {
  .a-input__field {
    resize: none;
  }
}

.a-input--select {
  .a-input__container {
    @extend %__icon-chevron-down;

    &:before {
      position: absolute;
      top: 50%;
      right: 1.5rem;
      transform: translateY(-50%);

      font-size: $icon-size-1x-large;

      pointer-events: none;
    }
  }

  .a-input__field {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 4rem;

    &::-ms-expand {
      display: none;
    }
  }
}

%__input__field__large {
  font-size: $font-size-3x-large;
  line-height: $line-height-3x-large;
  font-weight: $font-weight-bold;

  @include respond-at($breakpoint-tablet-default) {
    font-size: $font-size-4x-large;
    line-height: $line-height-4x-large;
  }
}

.a-input--currency {
  .a-input__field {
    padding-left: 34px;

    &::-webkit-outer-spin-button,
    &::-webkit-inner-spin-button {
      /* display: none; <- Crashes Chrome on hover */
      -webkit-appearance: none;
      margin: 0;
      /* <-- Apparently some margin are still there even though it's hidden */
    }

    &[type="number"] {
      -moz-appearance: textfield;
      /* Firefox */
    }

    @include respond-at($breakpoint-tablet-default) {
      padding-left: 34px;
    }
  }
}

.a-input--large {
  .a-input__currency {
    font-size: $font-size-3x-large;
    line-height: $line-height-3x-large;
    font-weight: $font-weight-bold;

    @include respond-at($breakpoint-tablet-default) {
      font-size: $font-size-4x-large;
      line-height: $line-height-4x-large;
    }
  }

  .a-input__field {
    font-size: $font-size-3x-large;
    line-height: $line-height-3x-large;
    font-weight: $font-weight-bold;

    @include respond-at($breakpoint-tablet-default) {
      font-size: $font-size-4x-large;
      line-height: $line-height-4x-large;
    }

    @include placeholder() {
      font-size: $font-size-3x-large;
      line-height: $line-height-3x-large;
      font-weight: $font-weight-bold;
      color: $text-color-disabled;

      @include respond-at($breakpoint-tablet-default) {
        font-size: $font-size-4x-large;
        line-height: $line-height-4x-large;
      }
    }
  }
}

.a-input--large.a-input--currency {
  .a-input__field {
    padding-left: 45px;

    @include respond-at($breakpoint-tablet-default) {
      padding-left: 75px;
    }
  }
}

html[data-text-zoom="large"],
html[data-text-zoom="xlarge"] {
  .a-input--large.a-input--currency {
    .a-input__field {
      padding-left: 65px;
    }
  }
}

.a-input__container--with-icon {

  // Style the icon
  &::before {
    position: absolute;
    top: 50%;
    right: $padding-horizontal;
    transform: translateY(-50%);

    font-size: $icon-size-1x-large;

    color: $text-color-base;
  }

  .a-input__field {
    padding-right: ($padding-horizontal * 2) + $icon-width;
  }
}

// ============================================================================
// :: States
// ============================================================================
.a-input {
  &.is-success {
    .a-input__field {
      border-color: $ui-success;
    }

    .a-input__feedback-message {
      color: $ui-success;
    }
  }

  &.is-error {
    .a-input__field {
      border-color: $ui-error;
    }

    .a-input__feedback-message {
      color: $ui-error;
    }
  }

  &.is-disabled {
    .a-input__field {
      background-color: $background-color-base;

      cursor: not-allowed;

      pointer-events: none;
    }
  }
}