@import '../../style/themes/default';
@import '../../style/mixins/index';

@input-affix-width: 18px;

// size mixins for input
.input-lg() {
  height: @input-height-lg;
  line-height: @input-height-lg;
  padding: @input-padding-vertical-lg @input-padding-horizontal-lg;
  font-size: @font-size-md;
}

.input-sm() {
  height: @input-height-sm;
  line-height: @input-height-sm;
  padding: @input-padding-vertical-sm @input-padding-horizontal-sm;
}

// input status
// == when focus or actived
.active(@color: @outline-color) {
  border-color: @font-ba; // ~`colorPalette('@{color}', 5) `;
  border-right-width: @border-width-base !important;
  outline: 0;
  box-shadow: @input-outline-offset @outline-blur-size @outline-width fade(@color, 20%);
}

// == when hoverd
.hover(@color: @input-hover-border-color) {
  border-color: @font-ba;// ~`colorPalette('@{color}', 5) `;
  border-right-width: @border-width-base !important;
}

.disabled() {
  color: @disabled-color;
  background-color: @input-disabled-bg;
  cursor: not-allowed;
  opacity: 1;
  &:hover {
    .hover(@input-border-color);
  }
}

// Basic style for input
.input() {
  position: relative;
  display: inline-block;
  width: @input-width-sm;
  height: @input-height-base;
  padding: @input-padding-vertical-base @input-padding-horizontal-base;
  color: @input-color;
  font-size: @font-size-base;
  line-height: @input-height-base;
  background-color: @input-bg;
  background-image: none;
  border: @border-width-base @border-style-base @input-border-color;
  border-radius: @border-radius-base;
  transition: all 0.3s;
  .placeholder(); // Reset placeholder

  &:hover {
    .hover();
  }

  &:focus {
    .active();
  }

  &-disabled {
    .disabled();
  }

  &[disabled] {
    .disabled();
  }

  // Reset height for `textarea`s
  textarea& {
    max-width: 100%; // prevent textearea resize from coming out of its container
    height: auto;
    min-height: @input-height-base;
    vertical-align: bottom;
    padding: 4px 10px;
    transition: all 0.3s, height 0s;
    line-height: 1.5;
  }

  // Size
  &-lg {
    .input-lg();
  }

  &-sm {
    .input-sm();
  }
}

// label input
.input-group(@inputClass) {
  position: relative;
  display: inline;
  border-collapse: separate;
  border-spacing: 0;

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

  > [class*='col-'] {
    padding-right: 8px;
    &:last-child {
      padding-right: 0;
    }
  }

  &-addon,
  &-wrap,
  > .@{inputClass} {
    display: table-cell;

    &:not(:first-child):not(:last-child) {
      border-radius: 0;
    }
  }

  &-addon,
  &-wrap {
    width: 1px; // To make addon/wrap as small as possible
    white-space: nowrap;
    vertical-align: middle;
  }

  &-wrap > * {
    display: block;
  }

  .@{inputClass} {
    float: left;
    width: @input-width-sm;
    margin-bottom: 0;
    text-align: inherit;
    &:focus {
      z-index: 1; // Fix https://gw.alipayobjects.com/zos/rmsportal/DHNpoqfMXSfrSnlZvhsJ.png
      border-right-width: 1px;
    }
    &:hover {
      z-index: 1;
      border-right-width: 1px;
    }
  }

  &-addon {
    position: relative;
    float: left;
    padding: 0 @input-padding-horizontal-base;
    color: @input-color;
    font-weight: normal;
    font-size: @font-size-base;
    line-height: 28px;
    height: 28px;
    text-align: center;
    background-color: @input-addon-bg;
    border: @border-width-base @border-style-base @input-border-color;
    border-radius: @border-radius-base;
    transition: all 0.3s;

    // Reset Select's style in addon
    .@{yg-prefix}-select {
      margin: -(@input-padding-vertical-base + 1px) (-@input-padding-horizontal-base);

      .@{yg-prefix}-select-selection-selected-value {
        margin-left: -5px;
      }
      .@{yg-prefix}-select-selection {
        margin: -1px;
        background-color: inherit;
        border: @border-width-base @border-style-base transparent;
        box-shadow: none;
      }

      &-open,
      &-focused {
        .@{yg-prefix}-select-selection {
          color: @primary-color;
        }
      }
    }

    // Expand addon icon click area
    // https://github.com/ant-design/ant-design/issues/3714
    > i:only-child::after {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      content: '';
    }
  }

  // Reset rounded corners
  > .@{inputClass}:first-child,
  &-addon:first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    width: auto;

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

  > .@{inputClass}-affix-wrapper {
    &:not(:first-child) .@{inputClass} {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }

    &:not(:last-child) .@{inputClass} {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }
  }

  &-addon:first-child {
    border-right: 0;
  }
  &-addon:last-child {
    border-left: 0;
  }

  > .@{inputClass}:last-child,
  &-addon:last-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    width: auto;

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

  // Sizing options
  &-lg .@{inputClass},
  &-lg > &-addon {
    .input-lg();
  }

  &-sm .@{inputClass},
  &-sm > &-addon {
    .input-sm();
  }

  // Fix https://github.com/ant-design/ant-design/issues/5754
  &-lg .@{yg-prefix}-select-selection--single {
    height: @input-height-lg;
  }

  &-sm .@{yg-prefix}-select-selection--single {
    height: @input-height-sm;
  }

  .@{inputClass}-affix-wrapper {
    display: table-cell;
    float: left;
  }

  &&-compact {
    display: block;
    .clearfix;

    &-addon,
    &-wrap,
    > .@{inputClass} {
      &:not(:first-child):not(:last-child) {
        border-right-width: @border-width-base;
        &:hover {
          z-index: 1;
        }
        &:focus {
          z-index: 1;
        }
      }
    }

    & > * {
      display: inline-block;
      float: none;
      vertical-align: top; // https://github.com/ant-design/ant-design-pro/issues/139
      border-radius: 0;
    }

    & > *:not(:last-child) {
      margin-right: -@border-width-base;
      border-right-width: @border-width-base;
    }

    // Undo float for .yg-input-group .yg-input
    .@{inputClass} {
      float: none;
    }

    // reset border for Select, DatePicker, AutoComplete, Cascader, Mention, TimePicker
    & > .@{yg-prefix}-select > .@{yg-prefix}-select-selection,
    & > .@{yg-prefix}-calendar-picker .@{yg-prefix}-input,
    & > .@{yg-prefix}-select-auto-complete .@{yg-prefix}-input,
    & > .@{yg-prefix}-cascader-picker .@{yg-prefix}-input,
    & > .@{yg-prefix}-mention-wrapper .@{yg-prefix}-mention-editor,
    & > .@{yg-prefix}-time-picker .@{yg-prefix}-time-picker-input {
      border-right-width: @border-width-base;
      border-radius: 0;
      &:hover {
        z-index: 1;
      }
      &:focus {
        z-index: 1;
      }
    }

    & > *:first-child,
    & > .@{yg-prefix}-select:first-child > .@{yg-prefix}-select-selection,
    & > .@{yg-prefix}-calendar-picker:first-child .@{yg-prefix}-input,
    & > .@{yg-prefix}-select-auto-complete:first-child .@{yg-prefix}-input,
    & > .@{yg-prefix}-cascader-picker:first-child .@{yg-prefix}-input,
    & > .@{yg-prefix}-mention-wrapper:first-child .@{yg-prefix}-mention-editor,
    & > .@{yg-prefix}-time-picker:first-child .@{yg-prefix}-time-picker-input {
      border-top-left-radius: @border-radius-base;
      border-bottom-left-radius: @border-radius-base;
      border-right: none;
    }

    & > *:last-child,
    & > .@{yg-prefix}-select:last-child > .@{yg-prefix}-select-selection,
    & > .@{yg-prefix}-calendar-picker:last-child .@{yg-prefix}-input,
    & > .@{yg-prefix}-select-auto-complete:last-child .@{yg-prefix}-input,
    & > .@{yg-prefix}-cascader-picker:last-child .@{yg-prefix}-input,
    & > .@{yg-prefix}-cascader-picker-focused:last-child .@{yg-prefix}-input,
    & > .@{yg-prefix}-mention-wrapper:last-child .@{yg-prefix}-mention-editor,
    & > .@{yg-prefix}-time-picker:last-child .@{yg-prefix}-time-picker-input {
      border-right-width: @border-width-base;
      border-top-right-radius: @border-radius-base;
      border-bottom-right-radius: @border-radius-base;
    }

    // https://github.com/ant-design/ant-design/issues/12493
    & > .@{yg-prefix}-select-auto-complete .@{yg-prefix}-input {
      vertical-align: top;
    }
  }
}

.input-affix-wrapper(@inputClass) {
  position: relative;
  display: inline-block;
  text-align: start;

  &:hover .@{inputClass}:not(.@{inputClass}-disabled) {
    .hover();
  }

  .@{inputClass} {
    position: relative;
    text-align: inherit;
  }

  .@{inputClass}-prefix,
  .@{inputClass}-suffix {
    position: absolute;
    top: 50%;
    z-index: 2;
    color: @input-color;
    line-height: 0;
    transform: translateY(-50%);
    :not(.anticon) {
      line-height: @line-height-base;
    }
  }

  .@{inputClass}-prefix {
    left: @input-padding-horizontal-base;
  }

  .@{inputClass}-suffix {
    right: @input-padding-horizontal-base;
  }

  .@{inputClass}:not(:first-child) {
    padding-left: @input-padding-horizontal-base + @input-affix-width;
    width: @input-width-sm - @input-affix-width;
  }
  .@{inputClass}:not(:last-child) {
    padding-right: @input-padding-horizontal-base + @input-affix-width;
    width: @input-width-sm - @input-affix-width;
  }
  .@{inputClass}:not(:first-child):not(:last-child) {
    padding-left: @input-padding-horizontal-base + @input-affix-width;
    width: @input-width-sm - @input-affix-width*2;
  }

}
