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

//== Style for input-group: input with label, with button or dropdown...
.@{input-prefix-cls}-group {
  &-wrapper {
    &-rtl {
      direction: rtl;
    }
  }
  &-rtl {
    direction: rtl;
  }
}

// affix
@input-affix-margin: 4 * @hd;

.@{input-prefix-cls} {
  &-affix-wrapper&-affix-wrapper-rtl {
    > input.@{input-prefix-cls} {
      border: none;
      outline: none;
    }
  }

  &-affix-wrapper-rtl {
    .@{input-prefix-cls}-prefix {
      margin: 0 0 0 @input-affix-margin;
    }

    .@{input-prefix-cls}-suffix {
      margin: 0 @input-affix-margin 0 0;
    }
  }

  &-textarea {
    &-rtl {
      direction: rtl;
    }

    &-rtl&-show-count::after {
      text-align: left;
    }
  }
}

// allow-clear
.@{input-prefix-cls}-clear-icon {
  &:last-child {
    .@{input-prefix-cls}-affix-wrapper-rtl & {
      margin-right: @input-affix-margin;
      margin-left: 0;
    }
  }

  .@{input-prefix-cls}-affix-wrapper-rtl & {
    right: auto;
    left: 8 * @hd;
  }
}

// mixin
@input-rtl-cls: ~'@{input-prefix-cls}-rtl';

.active() {
  .@{input-rtl-cls} & {
    border-right-width: 0;
    border-left-width: @border-width-base !important;
  }
}

.hover() {
  .@{input-rtl-cls} & {
    border-right-width: 0;
    border-left-width: @border-width-base !important;
  }
}

.input() {
  &-rtl {
    direction: rtl;
  }
}

// label input
.input-group(@inputClass) {
  > .@{inputClass}-rtl:first-child,
  &-rtl &-addon:first-child {
    border-radius: 0 @border-radius-base @border-radius-base 0;
  }

  &-addon:first-child {
    .@{inputClass}-group-rtl & {
      border-right: @border-width-base @border-style-base @input-border-color;
      border-left: 0;
    }
  }

  &-addon:last-child {
    .@{inputClass}-group-rtl & {
      border-right: 0;
      border-left: @border-width-base @border-style-base @input-border-color;
    }
  }

  > .@{inputClass}:last-child,
  &-addon:last-child {
    .@{inputClass}-group-rtl& {
      border-radius: @border-radius-base 0 0 @border-radius-base;
    }
  }

  .@{inputClass}-affix-wrapper {
    &:not(:first-child) {
      .@{inputClass}-group-rtl& {
        border-radius: @border-radius-base 0 0 @border-radius-base;
      }
    }

    &:not(:last-child) {
      .@{inputClass}-group-rtl& {
        border-radius: 0 @border-radius-base @border-radius-base 0;
      }
    }
  }

  &&-compact {
    & > *:not(:last-child) {
      .@{inputClass}-group-rtl& {
        margin-right: 0;
        margin-left: -@border-width-base;
        border-left-width: @border-width-base;
      }
    }

    & > *:first-child,
    & > .@{ant-prefix}-select:first-child > .@{ant-prefix}-select-selector,
    & > .@{ant-prefix}-select-auto-complete:first-child .@{input-prefix-cls},
    & > .@{ant-prefix}-cascader-picker:first-child .@{input-prefix-cls} {
      .@{inputClass}-group-rtl& {
        border-radius: 0 @border-radius-base @border-radius-base 0;
      }
    }

    & > *:last-child,
    & > .@{ant-prefix}-select:last-child > .@{ant-prefix}-select-selector,
    & > .@{ant-prefix}-select-auto-complete:last-child .@{input-prefix-cls},
    & > .@{ant-prefix}-cascader-picker:last-child .@{input-prefix-cls},
    & > .@{ant-prefix}-cascader-picker-focused:last-child .@{input-prefix-cls} {
      .@{inputClass}-group-rtl& {
        border-left-width: @border-width-base;
        border-radius: @border-radius-base 0 0 @border-radius-base;
      }
    }

    .@{input-prefix-cls}-group-wrapper-rtl + .@{input-prefix-cls}-group-wrapper-rtl {
      margin-right: -1 * @hd;
      margin-left: 0;
    }

    .@{input-prefix-cls}-group-wrapper-rtl:not(:last-child) {
      &.@{input-prefix-cls}-search > .@{input-prefix-cls}-group {
        & > .@{input-prefix-cls} {
          border-radius: 0 @border-radius-base @border-radius-base 0;
        }
      }
    }
  }
}

// search-input
@search-prefix: ~'@{input-prefix-cls}-search';
@search-rtl-cls: ~'@{search-prefix}-rtl';

.@{search-prefix}-rtl {
  direction: rtl;

  .@{input-prefix-cls} {
    &:hover,
    &:focus {
      + .@{input-prefix-cls}-group-addon .@{search-prefix}-button:not(.@{ant-prefix}-btn-primary) {
        border-right-color: @input-hover-border-color;
        border-left-color: @border-color-base;
      }
    }
  }

  > .@{input-prefix-cls}-group {
    > .@{input-prefix-cls}-affix-wrapper {
      &:hover,
      &-focused {
        border-right-color: @input-hover-border-color;
      }
    }

    > .@{input-prefix-cls}-group-addon {
      right: -1 * @hd;
      left: auto;
      .@{search-prefix}-button {
        border-radius: @border-radius-base 0 0 @border-radius-base;
      }
    }
  }
}
