@import './global/variables.scss';
@import './global/mixins';

input {
  &:focus,
  &:active {
    outline: 0;
  }
}

.input-info,
.input-text-info {
  display: inline-block;
  padding-top: 6px;
  font-size: 12px;
  line-height: 18px;

  &.danger {
    color: $ron-burgundy;
  }
}

.input-text-wrap {
  position: relative;
  padding-top: 15px;
  margin-bottom: 20px;

  &:global(.has-units:not(.has-value)) {
    &:after {
      color: $slate-20;
    }
  }
  input[type='number']::-webkit-input-placeholder {
    color: $slate-20;
  }
  input[type='number']::-moz-placeholder {
    color: $slate-20;
  }
  input[type='number']:-ms-input-placeholder {
    color: $slate-20;
  }

  &.is-required {
    label::after {
      position: absolute;
      top: 6px;
      right: -9px;
      width: 4px;
      height: 4px;
      background: $ron-burgundy;
      border-radius: 4px;
      content: '';
    }
  }

  &.is-focused,
  &.has-value {
    .input-text-label {
      top: 0;
      font-size: 12px;
      line-height: 15px;
    }

    label::after {
      top: 4px;
    }
  }

  &.is-disabled {
    .input-text-label {
      color: $text-input-disabled-color;
    }

    [type='text'],
    [type='password'],
    [type='number'],
    [type='email'],
    [type='tel'] {
      pointer-events: none;
      border-bottom-color: $text-input-disabled-border;
    }
  }

  &.is-error,
  &.is-error.is-focused,
  &.is-error.has-value {
    [type='text'],
    [type='password'],
    [type='number'],
    [type='email'],
    [type='tel'] {
      border-bottom-color: $ron-burgundy;
      box-shadow: $ron-burgundy 0 1px 0;
    }
  }

  &.is-valid::after,
  &.is-invalid::after,
  &.is-search::after {
    @include icon-font-base;
    position: absolute;
    top: 19px;
    right: 0;
    pointer-events: none;
  }

  &.is-valid::after {
    color: $mantis;
    content: $icon-status-positive;
  }

  &.is-invalid::after {
    color: $ron-burgundy;
    content: $icon-status-negative;
  }

  &.is-search {
    &::after {
      content: $icon-search;
    }

    &.is-focused::after {
      font-weight: bold;
      color: $sg-blue;
    }
  }

  &.is-calendar {
    &::before {
      @include icon-font-base;
      position: absolute;
      top: 19px;
      right: 0;
      pointer-events: none;
      content: $icon-calendar;
    }

    &.is-focused::before {
      color: $sg-blue;
    }
  }

  &.has-units {
    &[class*='has-arrow-']::before,
    &[class*='has-space-']::before {
      @include icon-font-base;
      position: absolute;
      top: 20px;
      left: 0;
    }

    &.has-arrow-top::before,
    &.has-arrow-right::before,
    &.has-arrow-bottom::before,
    &.has-arrow-left::before {
      content: $icon-sort-asc;
    }

    &.has-space-top::before,
    &.has-space-right::before,
    &.has-space-bottom::before,
    &.has-space-left::before {
      content: $icon-space;
    }

    &.has-arrow-right::before,
    &.has-space-right::before {
      transform: rotate(90deg);
    }

    &.has-arrow-bottom::before,
    &.has-space-bottom::before {
      transform: rotate(180deg);
    }

    &.has-arrow-left::before,
    &.has-space-left::before {
      transform: rotate(-90deg);
    }

    &::after {
      position: absolute;
      top: 20px;
      right: 0;
      font-size: 12px;
      line-height: 18px;
      content: attr(data-units);
    }

    &[class*='has-arrow-'] [type='text'],
    &[class*='has-arrow-'] [type='number'],
    &[class*='has-space-'] [type='text'],
    &[class*='has-space-'] [type='number'] {
      padding-right: 15px;
      padding-left: 15px;
      text-align: right;
    }
  }

  &.is-large {
    .input-text-label {
      top: 15px;
      font-size: 18px;
      line-height: 27px;
    }

    [type='text'],
    [type='password'],
    [type='number'],
    [type='email'],
    [type='tel'] {
      font-size: 18px;
      line-height: 27px;
    }
  }

  &.is-large.is-focused,
  &.is-large.has-value {
    .input-text-label {
      top: 0;
      font-size: 12px;
      line-height: 15px;
    }
  }

  &.has-reset {
    display: flex;
    .input-text-label {
      left: 30px;
    }
  }

  [type='text'],
  [type='password'],
  [type='number'],
  [type='email'],
  [type='tel'] {
    display: block;
    width: 100%;
    padding: 0;
    font-size: 13px;
    line-height: 24px;
    color: $slate;
    background-color: transparent;
    border: 0;
    border-bottom: 1px solid $slate-20;
    box-shadow: transparent 0 1px 0;
    transition: 0.3s border-color, 0.3s box-shadow;

    &:focus {
      border-color: $sg-blue;
      box-shadow: $sg-blue 0 1px 0;
    }

    &:disabled {
      background: transparent;
    }
  }

  &.has-tooltip input {
    padding-right: 20px;
  }

  [type='number'] {
    padding-right: 20px;
    &::-webkit-inner-spin-button,
    &::-webkit-outer-spin-button {
      -webkit-appearance: none;
      -moz-appearance: textfield;
      margin: 0;
    }
  }
}

.input-text-label {
  position: absolute;
  top: 18px;
  display: inline-block;
  font-size: 13px;
  line-height: 18px;
  pointer-events: none;
  transition: 0.3s top, 0.3s font-size;
  transition-timing-function: cubic-bezier(0.02, 0.01, 0.47, 1);
}

:global .input-info-tooltip {
  position: absolute;
  top: 19px;
  right: 0;
}

.input-search-results {
  @include dropdown-shadow;
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background-color: $slate-02;
  border: 1px solid $slate-10;
  border-radius: $border-radius;

  .loading {
    display: none;

    &.is-visible {
      display: block;
    }
  }
}

.search-results-title,
.search-result {
  padding: 9px 18px 9px 30px;
  font-size: 13px;
  line-height: 18px;
}

.search-results-title {
  margin-bottom: 0;
  color: $slate;
  background-color: $text-input-search-title-bg;
}

.search-results {
  padding: 0;
  margin: 0;
}

.search-result {
  overflow: hidden;
  color: $slate-80;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: 0.3s color, 0.3s background-color;

  &:hover {
    color: $slate;
    cursor: pointer;
    background-color: $slate-05;
  }
}

.reset-button {
  font-size: 20px;
  line-height: 25px;
  margin-right: 10px;
  cursor: pointer;
}

.input-tooltip {
  position: absolute;
  right: 0;
  top: 19px;
}
