@use 'sass:map';
@use 'sass:math';

@use 'mixins/mixins' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

@include b(textarea) {
  @include set-component-css-var('input', $input);
}

@include b(textarea) {
  position: relative;
  display: inline-block;
  width: 100%;
  vertical-align: bottom;
  font-size: var(--el-font-size-base);

  @include e(inner) {
    display: block;
    resize: vertical;
    padding: 6px 12px;
    line-height: 1.5;
    box-sizing: border-box;
    width: 100%;
    font-size: inherit;
    font-family: inherit;
    color: var(--el-input-text-color, map.get($input, 'text-color'));
    background-color: var(--el-input-bg-color, map.get($input, 'bg-color'));
    background-image: none;
    border: var(--el-input-border, map.get($input, 'border'));
    border-radius: var(
      --el-input-border-radius,
      map.get($input, 'border-radius')
    );
    transition: var(--el-transition-border);

    &::placeholder {
      color: var(
        --el-input-placeholder-color,
        map.get($input, 'placeholder-color')
      );
    }

    &:hover {
      border-color: var(
        --el-input-hover-border,
        map.get($input, 'hover-border')
      );
    }

    &:focus {
      outline: none;
      border-color: var(
        --el-input-focus-border,
        map.get($input, 'focus-border')
      );
      box-shadow: var(--el-input-focus-shadow, map.get($input, 'focus-shadow'));
    }
  }

  & .#{$namespace}-input__count {
    color: var(--el-text-color-placeholder);
    background: var(--el-color-white);
    position: absolute;
    font-size: 12px;
    line-height: 14px;
    bottom: 5px;
    right: 10px;
  }

  @include when(disabled) {
    .#{$namespace}-textarea__inner {
      background-color: map.get($input-disabled, 'fill');
      border-color: map.get($input-disabled, 'border');
      color: map.get($input-disabled, 'text-color');
      cursor: not-allowed;

      &::placeholder {
        color: map.get($input-disabled, 'placeholder-color');
      }
    }
  }

  @include when(exceed) {
    .#{$namespace}-textarea__inner {
      border-color: var(--el-color-danger);
    }

    .#{$namespace}-input__count {
      color: var(--el-color-danger);
    }
  }
}

@include b(input) {
  @include set-component-css-var('input', $input);

  position: relative;
  font-size: var(--el-input-font-size);
  display: inline-flex;
  width: 100%;
  line-height: var(--el-input-line-height);
  @include scroll-bar;

  & .#{$namespace}-input__clear {
    color: var(--el-input-icon-color);

    cursor: pointer;
    transition: var(--el-transition-color);

    &:hover {
      color: var(--el-input-clear-hover-color);
    }
  }

  & .#{$namespace}-input__count {
    height: 100%;
    display: inline-flex;
    align-items: center;
    color: var(--el-text-color-secondary);
    font-size: 12px;

    .#{$namespace}-input__count-inner {
      background: $color-white;
      line-height: initial;
      display: inline-block;
      padding: 0 5px;
    }
  }

  @include e(inner) {
    -webkit-appearance: none;
    background-color: var(--el-input-bg-color, map.get($input, 'bg-color'));
    background-image: none;
    border-radius: var(
      --el-input-border-radius,
      map.get($input, 'border-radius')
    );
    border: var(--el-input-border);
    box-sizing: border-box;
    color: var(--el-input-text-color);
    display: inline-block;
    font-size: inherit;
    height: var(--el-input-height);
    line-height: var(--el-input-line-height);
    outline: none;
    padding: 0 var(--el-input-inner-padding);
    transition: var(--el-transition-border);
    width: 100%;

    &::placeholder {
      color: var(
        --el-input-placeholder-color,
        map.get($input, 'placeholder-color')
      );
    }

    &:hover {
      border-color: var(
        --el-input-hover-border,
        map.get($input, 'hover-border')
      );
    }

    &:focus {
      outline: none;
      border-color: var(
        --el-input-focus-border,
        map.get($input, 'focus-border')
      );
      box-shadow: var(--el-input-focus-shadow, map.get($input, 'focus-shadow'));
    }
  }

  @include e(suffix) {
    display: inline-flex;

    position: absolute;
    height: 100%;
    right: var(--el-input-inner-padding);
    top: 0;
    text-align: center;
    color: var(--el-input-icon-color, map.get($input, 'icon-color'));
    transition: all var(--el-transition-duration);
    pointer-events: none;
  }

  @include e(suffix-inner) {
    pointer-events: all;
    display: inline-flex;
  }

  @include e(prefix) {
    display: inline-flex;
    position: absolute;
    height: 100%;
    left: var(--el-input-suffix-position);
    top: 0;
    text-align: center;
    color: var(--el-input-icon-color, map.get($input, 'icon-color'));
    transition: all var(--el-transition-duration);
  }

  @include e(prefix-inner) {
    pointer-events: all;
    display: inline-flex;
  }

  @include e(icon) {
    width: var(--el-input-icon-wrap-width);
    font-size: var(--el-input-icon-font-size);
    height: inherit;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all var(--el-transition-duration);
  }

  @include e(validateIcon) {
    pointer-events: none;
  }

  @include when(active) {
    .#{$namespace}-input__inner {
      outline: none;
      border-color: var(
        --el-input-focus-border,
        map.get($input, 'focus-color')
      );
    }
  }

  @include when(disabled) {
    .#{$namespace}-input__inner {
      background-color: map.get($input-disabled, 'fill');
      border-color: map.get($input-disabled, 'border');
      color: map.get($input-disabled, 'text-color');
      cursor: not-allowed;

      &::placeholder {
        color: map.get($input-disabled, 'placeholder-color');
      }
    }

    .#{$namespace}-input__icon {
      cursor: not-allowed;
    }
  }

  @include when(exceed) {
    .#{$namespace}-input__inner {
      border-color: var(--el-color-danger);
    }

    .#{$namespace}-input__suffix {
      .#{$namespace}-input__count {
        color: var(--el-color-danger);
      }
    }
  }

  @include m(suffix) {
    .#{$namespace}-input__inner {
      padding-right: var(--el-input-suffix-padding);
    }
    @include m(password-clear) {
      .#{$namespace}-input__inner {
        padding-right: var(--el-input-double-suffix-padding);
      }
    }

    .#{$namespace}-input__inner {
      padding-right: 30px;
    }
  }

  @include m(prefix) {
    .#{$namespace}-input__inner {
      padding-left: var(--el-input-suffix-padding);
    }
  }

  @each $size in (large, medium, small) {
    @include m($size) {
      $wrapWidth: map.get($input-icon-wrap-width, $size);
      $iconSize: map.get($input-icon-font-size, $size);
      $innerPadding: map.get($input-inner-padding, $size);
      $suffixPosition: $innerPadding - math.div($wrapWidth - $iconSize, 2);
      --el-input-append-padding: #{map.get($input-append-padding, $size)};
      --el-input-append-select-margin: #{-
        (map.get($input-append-padding, $size))};
      --el-input-append-min-width: #{map.get($input-append-min-width, $size)};
      --el-input-font-size: #{map.get($input-font-size, $size)};
      --el-input-line-height: #{map.get($input-line-height, $size)};
      --el-input-inner-padding: #{$innerPadding};
      --el-input-border-radius: #{map.get($input-border-radius, $size)};
      --el-input-height: #{map.get($input-height, $size)};
      --el-input-number-width: #{map.get($input-number-width, $size)};
      --el-input-icon-wrap-width: #{$wrapWidth};
      --el-input-icon-font-size: #{$iconSize};
      --el-input-suffix-position: #{$suffixPosition};
      --el-input-suffix-padding: #{$wrapWidth + $suffixPosition + 4px};
      --el-input-double-suffix-padding: #{$wrapWidth * 2 + $suffixPosition + 4px};
    }
  }
}

@include b(input-group) {
  line-height: normal;
  display: inline-table;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;

  > .#{$namespace}-input__inner {
    vertical-align: middle;
    display: table-cell;
  }

  @include e((append, prepend)) {
    background-color: var(--el-bg-color-base);
    color: var(--el-text-color-secondary);
    vertical-align: middle;
    text-align: center;
    display: table-cell;
    position: relative;
    border: $border-base;
    border-radius: var(--el-input-border-radius);
    padding: 0 var(--el-input-append-padding);
    width: var(--el-input-append-min-width);
    white-space: nowrap;

    &:focus {
      outline: none;
    }

    .#{$namespace}-select,
    .#{$namespace}-button {
      margin: -2px var(--el-input-append-select-margin);
    }

    button.#{$namespace}-button,
    button.#{$namespace}-button:hover,
    div.#{$namespace}-select .#{$namespace}-input__inner,
    div.#{$namespace}-select:hover .#{$namespace}-input__inner {
      border-color: transparent;
      background-color: transparent;
      color: inherit;
      border-top: 0;
      border-bottom: 0;
    }

    .#{$namespace}-button,
    .#{$namespace}-input {
      font-size: inherit;
    }
  }

  @include e(prepend) {
    border-right: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  @include e(append) {
    border-left: 0;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  @include m(prepend) {
    .#{$namespace}-input__inner {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }
    .#{$namespace}-select
      .#{$namespace}-input.is-focus
      .#{$namespace}-input__inner {
      border-color: transparent;
    }
  }

  @include m(append) {
    .#{$namespace}-input__inner {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }
    .#{$namespace}-select
      .#{$namespace}-input.is-focus
      .#{$namespace}-input__inner {
      border-color: transparent;
    }
  }
}
