@mixin hover($color: $input-hover-border-color) {
  border-color: mix(#fff, $color, 20%);

  @include theme-border-color($__common-input_hover_border-color);
}

@mixin hover-error() {
  border-color: $error-color;

  @include theme-border-color($__common-input-error_hover_border-color);
}

@mixin active($color: $input-hover-border-color) {
  border-color: mix(#fff, $color, 20%);
  outline: 0;
  box-shadow: $mixin-input-active-box-shadow;

  @include theme-border-color($__common-input_focus_border-color);
  @include theme-box-shadow($__common-input_focus_box-shadow);
}

@mixin active-error() {
  border-color: $error-color;
  outline: 0;
  box-shadow: $mixin-input-active-error-box-shadow;

  @include theme-border-color($__common-input-error_hover_border-color);
  @include theme-box-shadow($__common-input-error_focus_box-shadow);
}

@mixin disabled() {
  background-color: $input-disabled-bg;
  opacity: 1;
  cursor: $cursor-disabled;
  color: $mixin-input-disabled-color;

  @include theme-background-color($__common-input_disabled_background-color);
  @include theme-font-color($__common-input_disabled_font-color);

  &:hover {
    @include hover($input-border-color);
    @include theme-border-color($__common-input_disabled-hover_border-color);
  }
}

@mixin readonly() {
  background-color: $input-readonly-bg;
  opacity: $mixin-input-readonly-opacity;
  color: $input-readonly-color;

  @include theme-background-color($__common-input_readonly_background-color);
  @include theme-font-color($__common-input_readonly_font-color);
  @include theme-opacity($__common-input_readonly_opacity);

  &:hover {
    border-color: $mixin-input-border-readonly-color;

    @include theme-border-color($__common-input_readonly-hover_border-color);
  }

  &:focus {
    @include theme-border-color($__common-input_readonly-hover_border-color);
    @include theme-box-shadow($__common-input_readonly_box-shadow);
  }
}

@mixin editable() {
  // background-color: $input-readonly-bg;
  // opacity: .5;
  // color: #ccc;
}

@mixin input-large() {
  @if $--size-switch == yes {
    font-size: $--size-font-size-base;
    @include computed-height($--size-height-base + 4);
  } @else {
    font-size: $font-size-base;
    padding: $input-padding-vertical-large $input-padding-horizontal;
    height: $input-height-large;
  }
}

@mixin input-small() {
  @if $--size-switch == yes {
    font-size: $--size-font-size-base;
    @include computed-height($--size-height-base - 4);
    line-height: min($--size-height-base - 6px - max(($--size-height-base - 4px - $--size-line-height-base) / 2 - 1px, 0), $--size-line-height-base);
  } @else {
    padding: $input-padding-vertical-small $input-padding-horizontal;
    height: $input-height-small;
  }
  border-radius: $btn-border-radius-small;
}

@mixin input() {
  display: inline-block;
  width: 100%;
  @if $--size-switch == yes {
    font-size: $--size-font-size-base;
    @include computed-height($--size-height-base);
  } @else {
    height: $input-height-base;
    // line-height: $line-height-base;
    padding: $input-padding-vertical-base $input-padding-horizontal;
    font-size: $font-size-small;
  }
  border: 1px solid $input-border-color;
  border-radius: $btn-border-radius;
  color: $input-color;
  background-color: $input-bg;
  background-image: none;
  position: relative;
  cursor: text;
  overflow: hidden; /* 溢出隐藏 */
  text-overflow: ellipsis; /* 以省略号...显示 */
  white-space: nowrap; /* 强制不换行 */

  @include theme-border-color($__common-input_border-color);
  @include theme-font-color($__common-input_font-color);
  @include theme-background-color($__common-input_background-color);
  @include structure-font-size($__input-default_font-size, 0);
  @include placeholder();
  transition:
    border $transition-time $ease-in-out,
    background $transition-time $ease-in-out,
    box-shadow $transition-time $ease-in-out;

  &:hover {
    @include hover();
  }

  &:focus {
    @include active();
  }

  &-disabled,
  fieldset[disabled] & {
    @include disabled();
  }

  &-readonly,
  fieldset[readonly] & {
    @include readonly();
  }

  &-editable,
  fieldset[readonly] & {
    @include editable();
  }
  // Size
  &-large {
    @include input-large();
    @include structure-font-size($__input-default_font-size,2);
  }

  &-small {
    @include input-small();
  }
}

@mixin input-error() {
  border: 1px solid $error-color;

  @include theme-border-color($__common-input-error_border-color);

  &:hover {
    @include hover-error;
    // @include theme-border-color($__common-input-error_hover_border-color);
  }

  &:focus {
    @include active-error;
  }
}

@mixin changed() {
  color: $changed-color !important;

  @include theme-font-color($__common-input_changed_font-color, $--important);
}

@mixin input-required($inputClass) {
  display: inline-block;
  color: $input-required-icon-color;
  position: absolute;
  line-height: $input-height-base;
  left: 3px;
  z-index: 1;
}

@mixin input-group($inputClass) {
  display: inline-table;
  width: 100%;
  border-collapse: separate;
  font-size: $font-size-small;

  @include structure-font-size($__input-default_font-size, 0);

  &-large {
    font-size: $font-size-base;

    @include structure-font-size($__input-default_font-size, 2);
  }

  // Undo padding and float of grid classes
  &[class*="col-"] {
    float: none;
    padding-left: 0;
    padding-right: 0;
  }

  > [class*="col-"] {
    padding-right: 8px;
  }

  &-prepend {
    border-right: 0;
  }

  &-append {
    border-left: 0;
  }

  &-prepend,
  &-append,
  > .#{$inputClass} {
    display: table-cell;

    &:not(:first-child):not(:last-child) {
      border-radius: 0;
    }
  }
  &-with-prepend .#{$inputClass} {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
  &-with-append .#{$inputClass} {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  &-prepend .#{$css-prefix}btn,
  &-append .#{$css-prefix}btn {
    border-color: transparent;
    background-color: transparent;
    color: inherit;
    margin: -($input-padding-vertical-base + 4) (-$input-padding-horizontal);

    @include theme-border-color($__common-input-group-pend-btn_border-color);
    @include theme-background-color($__common-input-group-pend-btn_background-color);
  }

  &-prepend,
  &-append {
    width: 1px; // To make addon/wrap as small as possible
    white-space: nowrap;
    vertical-align: middle;
    @if $--size-switch == yes {
      @include computed-height();
      font-size: $--size-font-size-base;
      .iconfont {
        line-height: $--size-font-size-base;
        vertical-align: middle;
      }
    } @else {
      padding: $input-padding-vertical-base $input-padding-horizontal;
      font-size: inherit;
      line-height: 1;
    }
    font-weight: normal;
    color: $input-color;
    text-align: center;
    background-color: #eee;
    border: 1px solid $input-border-color;
    border-radius: $border-radius-base;

    @include theme-font-color($__common-input-group-pend_font-color);
    @include theme-background-color($__common-input-group-pend_background-color);
    @include theme-border-color($__common-input-group-pend_border-color);

    // Reset Select's style in addon
    .#{$css-prefix}select {
      margin: -($input-padding-vertical-base + 1) (-$input-padding-horizontal); // lesshint spaceAroundOperator: false

      &-selection {
        background-color: inherit;
        margin: -1px;
        border: 1px solid transparent;

        @include theme-background-color($__common-input-group-pend-selection_background-color);
        @include theme-border-color($__common-input-group-pend-selection_border-color);
      }

      &-visible .#{$css-prefix}select-selection {
        box-shadow: none;

        @include theme-box-shadow($__common-input-group-pend-selection_box-shadow);
        @include theme-border-color($__common-input-group-pend-selection_bordere-color);
      }
    }
  }

  .#{$inputClass} {
    width: 100%;
    float: left;
    margin-bottom: 0;
    position: relative;
    z-index: 2;
  }

  // &-prepend,
  // &-append {

  // }

  // Reset rounded corners
  > span > .#{$inputClass}:first-child,
  > .#{$inputClass}:first-child,
  &-prepend {
    border-bottom-right-radius: 0 !important;
    border-top-right-radius: 0 !important;

    // Reset Select's style in addon
    .#{$css-prefix}-select .#{$css-prefix}-select-selection {
      border-bottom-right-radius: 0;
      border-top-right-radius: 0;
    }
  }

  > .#{$inputClass}:last-child,
  &-append {
    border-bottom-left-radius: 0 !important;
    border-top-left-radius: 0 !important;

    // Reset Select's style in addon
    .#{$css-prefix}-select .#{$css-prefix}-select-selection {
      border-bottom-left-radius: 0;
      border-top-left-radius: 0;
    }
  }

  // Sizing options
  &-large .#{$inputClass},
  &-large > &-prepend,
  &-large > &-append {
    @include input-large();
  }

  &-small .#{$inputClass},
  &-small > &-prepend,
  &-small > &-append {
    @include input-small();
  }

  .verify-tip {
    top: $input-height-base;
    left: 10px;
  }
}

@mixin input-group-error {
  &-prepend,
  &-append {
    background-color: #fff;
    border: 1px solid $error-color;

    @include theme-background-color($__common-input-group-error-pend_background-color);
    @include theme-border-color($__common-input-group-error-pend_border-color);
    .#{$css-prefix}select {
      &-selection {
        background-color: inherit;
        border: 1px solid transparent;
      }
    }
  }

  &-prepend {
    border-right: 0;
  }

  &-append {
    border-left: 0;
  }
}
