$input-color: rgb(68,68,68) !default;
$input-bg-color: $white !default;
$input-border-color: rgb(191, 191, 191) !default;
$input-placeholder-color: rgb(191, 191, 191) !default;
$input-radius: $radius !default;

$input-hover-border-color: $grey !default;

$input-active-border-color: rgb(191, 191, 191) !default;

$input-disabled-color: rgb(191, 191, 191) !default;
$input-disabled-bg-color: $grey-lighter !default;
$input-disabled-border-color: rgb(214, 214, 214) !default;

$input-padding: .75em .5em !default;
$input-textarea-padding: 1em .5em !default;

$input-arrow: rgb(68, 68, 68) !default;

$label-color: rgb(95, 95, 95) !default;

$help-color: rgb(163, 163, 163) !default;
$help-size: .75em !default;

$input-large-padding: 1.125em .75em;

@mixin input {
  @extend %control;
  background-color: $input-bg-color;
  border-color: $input-border-color;
  color: $input-color;

  @include placeholder {
    color: $input-placeholder-color;
  }

  &:hover {
    border-color: $input-hover-border-color;
  }

  &:focus,
  &:active {
    border-color: $input-active-border-color;
  }

  &[disabled] {
    color: $input-disabled-color;
    background-color: $input-disabled-bg-color;
    border-color: $input-disabled-border-color;
  }
}

.input,
.textarea {
  @include input;
  line-height: 1.5;

  max-width: 100%;
  width: 100%;

  @each $name, $pair in $colors {
    $color: nth($pair, 1);

    &.is-#{$name} {
      border-color: $color;
    }
  }
}

.input {
  padding: $input-padding;

  &.is-large {
    padding: $input-large-padding;
  }
}

.textarea {
  display: block;
  max-width: 100%;
  min-width: 100%;
  padding: $input-textarea-padding;
  resize: vertical;

  &:not([rows]) {
    max-height: 600px;
    min-height: 120px;
  }

  &[rows] {
    height: initial;
  }

  // Modifiers
  &.has-fixed-size {
    resize: none
  }
}

.select {
  display: inline-block;
  position: relative;
  vertical-align: top;

  &:not(.is-multiple):not(.is-loading) {
    &::after {
      @extend %arrow;

      position: absolute;
      top: 50%;
      border-top-color: $input-arrow;
      right: .75em;
      z-index: 4;
    }
  }

  select {
    @include input;
    padding: $input-padding;
    cursor: pointer;
    display: block;
    font-size: 1em;
    max-width: 100%;
    outline: none;

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

    &[disabled]:hover {
      border-color: $input-disabled-border-color;
    }

    &:not([multiple]) {
      padding-right: 2.5em;
    }

    &[multiple] {
      height: auto;
      padding: 0;

      option {
        padding: 0.5em 1em;
      }
    }
  }

  &.is-large select {
    padding: $input-large-padding;

    &:not([multiple]) {
      padding-right: 2.5em;
    }
  }

  // Colors
  @each $name, $pair in $colors {
    $color: nth($pair, 1);

    &.is-#{$name} {
      &:not(:hover)::after {
        border-top-color: $color;
      }

      select {
        border-color: $color;
      }
    }
  }

  &.is-fullwidth {
    width: 100%;

    select {
      width: 100%;
    }
  }

  &.is-loading {
    &::after {
      @extend %loader;
      margin-top: 0;
      position: absolute;
      right: 0.625em;
      top: 1em;
      transform: none;
    }
  }
}

.checkbox,
.radio {
  cursor: pointer;
  display: inline-block;
  line-height: 1.25;
  position: relative;
  input {
    cursor: pointer
  }

  &[disabled] {
    color: $input-disabled-color;
    cursor: not-allowed;
  }
}

.radio {
  & + .radio {
    margin-left: 0.5em
  }
}

.field label:not(.checkbox):not(.radio),
.label {
  display: block;
  color: $label-color;

  & + .help {
    margin-left: auto;
    font-size: 1em;
  }

  &:not(:last-child) {
    margin-bottom: .5em;
  }
}

.help {
  display: block;
  font-size: $help-size;
  margin-top: 0.25rem;
  color: $help-color;

  @each $name, $pair in $colors {
    $color: nth($pair, 1);

    &.is-#{$name} {
      color: $color
    }
  }
}

// Containers

.field {
  &:not(:last-child) {
    margin-bottom: 0.75rem;
  }
}
