$height-input: point(5);
$border-box-correction: 36px;
$size-icon: point(4);

%transition-input {
  transition-duration: $transition-sm-slow;
  transition-timing-function: $transition-easing-default;
}


.tao__form-label {
  margin-left: $border-radius-default / 4;
  transition-property: color;
  @extend %transition-input;
}

.tao__form-group {
  .tao__input {
    width: 100%;
  }
  select {
    background: $color-ui-lighter;
    -webkit-appearance: none;
    -moz-appearance: none;
    -ms-progress-appearance: none;
    appearance: none;
    &::-ms-expand {
      display: none;
    }
  }
  textarea.tao__input {
    padding: point(1);
    height: auto;
    resize: vertical;
    line-height: 1.4;
  }
  &.no-resize {
    textarea.tao__input {
      resize: none;
    }
  }
}

.tao__select-wrapper {
  position: relative;
  .tao__icon {
    transition: transform $transition-sm-fast $transition-easing-default;
    right: $spacing-margin-xxsmall;
    top: 50%;
    transform: translateY(-50%) rotateZ(90deg);
  }
  select:focus {
    + .tao__icon {
      transform: translateY(-50%) rotateZ(270deg);
    }
  }
  &.is-focused {
    + label {
      color: $color-brand-darker;
    }
  }
}

.form__secondary-label {
  white-space: nowrap;
  line-height: $border-box-correction;
  padding: 0 $spacing-margin-xxsmall 0 $spacing-margin-xsmall;
  + .tao__input {
    border-radius: 0 $border-radius-normal $border-radius-normal 0;
    border-left: $color-ui-transparent;
  }
}

.tao__form-input {
  min-height: $height-input;
  transition-property: box-shadow, border-color;
  @extend %transition-input;
  order: 1;
  cursor: text;
  &:hover:not(.disabled) {
    border-color: $color-brand-darker;
  }
  &.disabled {
    background: rgba($color-ui-darker, $opacity-low-minimum);
    border-color: rgba($color-text-03, $opacity-medium-half);
    .tao__input:disabled {
      background: transparent;
    }
    .icon__form {
      &:hover, &:focus {
        color: $color-text-03;
      }
    }
  }
  .tao__input {
    max-width: 100%;
    min-width: 1px;
    @extend .border-none;
    @extend .bg-transparent;
    height: $border-box-correction;
    &:focus {
      box-shadow: none;
    }
  }
  &.form__focus {
    box-shadow: $box-shadow-button-width rgba($color-brand-darker, $opacity-low-maximum);
    border-color: $color-brand-darker;
    .form__secondary-label {
      color: $color-brand-darker;
    }
    + label {
      color: $color-brand-darker;
    }
  }
  .icon__form {
    order: 2;
    border: none;
    height: $size-icon;
    min-width: $size-icon;
    transition-property: color, background, opacity;
    @extend %transition-input;
    &:enabled:hover, &:focus {
      color: $color-brand-darker;
      background: rgba($color-brand-darker, $opacity-low-half);
    }
    &:focus {
      outline: none;
    }
  }
}


.tao__input {
  @extend .rounded;
  @extend .font-medium;
  padding: 0 $spacing-padding-xxsmall;
  height:  $height-input;
  font-family: $font-family-01;
  transition-property: box-shadow, border-color;
  @extend %transition-input;
  order: 1;
  &:hover:enabled {
    border-color: $color-brand-darker;
  }
  &:focus {
    outline: none;
    border-color: $color-brand-darker;
    box-shadow: $box-shadow-button-width rgba($color-brand-darker, $opacity-low-maximum);
    + label {
      color: $color-brand-darker;
    }
  }
  &::placeholder {
    color: rgba($color-ui-darker, $opacity-low-maximum);
  }
  &:disabled {
    cursor: not-allowed;
    background: rgba($color-text-02, $opacity-low-minimum);
    border-color: rgba($color-text-03, $opacity-medium-half);
  }
}

%border-action-error {
  border-color: $color-action-error;
}

%color-action-error {
  color: $color-action-error;
}

.tao__form-group--error {
  > .tao__input {
    @extend %border-action-error;
  }
  .tao__form-input {
    border-color: $color-action-error !important;
    .form__secondary-label {
      @extend %color-action-error;
    }
    &.form__focus {
      box-shadow: $box-shadow-button-width rgba($color-action-error, $opacity-low-maximum);
      + label {
        @extend %color-action-error;
      }
    }
  }
  label {
    @extend %color-action-error;
  }
  > .tao__input {
    @extend %border-action-error;
    &:hover {
      @extend %border-action-error;
    }
    &:focus {
      box-shadow: $box-shadow-button-width rgba($color-action-error, $opacity-low-maximum);
      + label {
        @extend %color-action-error;
      }
    }
  }
}

.tao__form-group--loading {
  &::before {
    border: $border-width-default solid rgba($color-text-03, $opacity-high-half);
    border-radius: $border-radius-circle;
    border-right-color: $color-ui-transparent;
    border-top-color: $color-ui-transparent;
    content: '';
    display: block;
    height: point(2);
    width: point(2);
    position: absolute;
    right: point(1.5);
    bottom: point(1.5);
    z-index: 9;
    animation: spin $transition-bounce-slow infinite linear;
  }
  &.tao__form-group--loading-icon,
  &.tao__form-group-dropdown {
    &::before {
      right: point(5);
    }
  }
}

.tao__form-error {
  top: 100%;
  white-space: nowrap;
}

.left-position {
  left: $spacing-margin-xxxsmall;
}

.right-position {
  right: $spacing-margin-xxxsmall;
}

@keyframes spin {
  0% { transform: rotateZ(0deg); }
  25% { transform: rotateZ(90deg - 10deg); }
  75% { transform: rotateZ(270deg + 10deg); }
  100% { transform: rotateZ(360deg); }
}