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

@yee-input-affix-width: 19px;
@yee-input-affix-with-clear-btn-width: 38px;

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

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

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

// == when hoverd
.yee-hover(@yee-color: @yee-input-hover-border-color) {
  border-color: @yee-color;
  border-right-width: @yee-border-width-base !important;
}

.yee-disabled() {
  color: @yee-disabled-color;
  background-color: @yee-input-disabled-bg;
  cursor: not-allowed;
  opacity: 1;

  &:hover {
    .yee-hover(@yee-input-border-color);
  }
}

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

  &:hover {
    .yee-hover();
  }

  &:focus {
    .yee-active();
  }

  &-disabled {
    .yee-disabled();
  }

  &[disabled] {
    .yee-disabled();
  }

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

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

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

// label input
.yee-input-group(@inputClass) {
  position: relative;
  display: table;
  width: 100%;
  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 !important;
  }

  .@{inputClass} {
    float: left;
    width: 100%;
    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;
    padding: 0 @yee-input-padding-horizontal-base;
    color: @yee-input-color;
    font-weight: normal;
    font-size: @yee-font-size-base;
    text-align: center;
    background-color: @yee-input-addon-bg;
    border: @yee-border-width-base @yee-border-style-base @yee-input-border-color;
    border-radius: @yee-border-radius-base;
    transition: all 0.3s;

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

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

      &-open,
      &-focused {
        .@{yee-prefix}-select-selection {
          color: @yee-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;

    // Reset Select's style in addon
    .@{yee-prefix}-select .@{yee-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;

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

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

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

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

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

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

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

    &-addon,
    &-wrap,
    > .@{inputClass} {
      &:not(:first-child):not(:last-child) {
        border-right-width: @yee-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: -@yee-border-width-base;
      border-right-width: @yee-border-width-base;
    }

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

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

      &:hover {
        z-index: 1;
      }

      &:focus {
        z-index: 1;
      }
    }

    & > .@{yee-prefix}-select-focused {
      z-index: 1;
    }

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

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

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

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

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

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

  // Should not break align of icon & text
  // https://github.com/ant-design/ant-design/issues/18087
  // https://github.com/ant-design/ant-design/issues/17414
  // https://github.com/ant-design/ant-design/pull/17684
  // https://codesandbox.io/embed/pensive-paper-di2wk
  // https://codesandbox.io/embed/nifty-benz-gb7ml
  .@{inputClass}-prefix,
  .@{inputClass}-suffix {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    color: @yee-input-color;
    line-height: 0;
    transform: translateY(-50%);

    :not(.anticon) {
      line-height: @yee-line-height-base;
    }
  }

  .@{inputClass}-disabled ~ .@{inputClass}-suffix {
    .anticon {
      color: @yee-disabled-color;
      cursor: not-allowed;
    }
  }

  .@{inputClass}-prefix {
    left: @yee-input-padding-horizontal-base + 1px;
  }

  .@{inputClass}-suffix {
    right: @yee-input-padding-horizontal-base + 1px;
  }

  .@{inputClass}:not(:first-child) {
    padding-left: @yee-input-padding-horizontal-base + @yee-input-affix-width;
  }

  .@{inputClass}:not(:last-child) {
    padding-right: @yee-input-padding-horizontal-base + @yee-input-affix-width;
  }

  &.@{inputClass}-affix-wrapper-input-with-clear-btn .@{inputClass}:not(:last-child) {
    padding-right: @yee-input-padding-horizontal-base + @yee-input-affix-with-clear-btn-width;
  }

  &.@{inputClass}-affix-wrapper-textarea-with-clear-btn .@{inputClass} {
    padding-right: 22px;
  }
}

.yee-clear-icon() {
  color: @yee-disabled-color;
  font-size: @yee-font-size-sm;
  // https://github.com/ant-design/ant-design/pull/18151
  // https://codesandbox.io/s/wizardly-sun-u10br
  cursor: pointer;
  transition: color 0.3s;

  &:hover {
    color: @yee-text-color-secondary;
  }

  &:active {
    color: @yee-text-color;
  }

  + i {
    margin-left: 6px;
  }
}
