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

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

@include b(input-number) {
  @include set-component-css-var('input', $input);
  position: relative;
  display: inline-block;
  width: var(--el-input-number-width);
  line-height: var(--el-input-number-line-height);

  .#{$namespace}-input {
    display: block;

    &__inner {
      -webkit-appearance: none;
      -moz-appearance: textfield;
      &::-webkit-inner-spin-button,
      &::-webkit-outer-spin-button {
        margin: 0;
        -webkit-appearance: none;
      }
      // 8是给中间输入框的左右padding，大中小尺寸都是8px
      padding-left: var(--el-input-number-inner-padding);
      padding-right: var(--el-input-number-inner-padding);
      text-align: center;
    }
  }

  .#{$namespace}-icon {
    vertical-align: text-bottom;
  }

  @include e((increase, decrease)) {
    position: absolute;
    z-index: 1;
    top: 1px;
    width: var(--el-input-height);
    height: auto;
    text-align: center;
    background: var(--el-bg-color-base);
    color: var(--el-text-color-primary);
    cursor: pointer;
    font-size: 13px;
    user-select: none;

    &:hover {
      color: var(--el-color-primary);

      & ~ .#{$namespace}-input:not(.is-disabled) .#{$namespace}-input__inner {
        border-color: var(--el-input-focus-border);
      }
    }

    &.is-disabled {
      color: var(--el-disabled-text-color);
      cursor: not-allowed;
    }
  }

  @include e(increase) {
    right: 1px;
    border-radius: 0 var(--el-border-radius-base) var(--el-border-radius-base) 0;
    border-left: var(--el-border-base);
  }

  @include e(decrease) {
    left: 1px;
    border-radius: var(--el-border-radius-base) 0 0 var(--el-border-radius-base);
    border-right: var(--el-border-base);
  }

  @include when(disabled) {
    @include e((increase, decrease)) {
      border-color: var(--el-disabled-border-color);
      color: var(--el-disabled-border-color);

      &:hover {
        color: var(--el-disabled-border-color);
        cursor: not-allowed;
      }
    }
  }

  @each $size in (large, medium, small) {
    @include m($size) {
      --el-input-number-width: #{map.get($input-number-width, $size)};
      --el-input-number-line-height: #{map.get($input-height, $size) - 2};
      --el-input-number-inner-padding: #{map.get($input-height, $size) + 8};
      --el-input-height: #{map.get($input-height, $size)};
    }
  }

  @include m(small) {
    @include e((increase, decrease)) {
      [class*='#{$namespace}-icon'] {
        transform: scale(0.9);
      }
    }
  }

  @include when(without-controls) {
    .#{$namespace}-input__inner {
      padding-left: map.get($input-inner-padding, 'medium');
      padding-right: map.get($input-inner-padding, 'medium');
    }
  }

  @include when(controls-right) {
    .#{$namespace}-input__inner {
      padding-left: map.get($input-inner-padding, 'medium');
      padding-right: var(--el-input-number-inner-padding);
    }

    @include e((increase, decrease)) {
      height: auto;
      line-height: #{math.div(map.get($input-height, 'default') - 2, 2)};

      [class*='#{$namespace}-icon'] {
        transform: scale(0.75);
        transform-origin: top;
      }
    }

    @include e(increase) {
      border-radius: 0 var(--el-border-radius-base) 0 0;
      border-bottom: var(--el-border-base);
    }

    @include e(decrease) {
      right: 1px;
      bottom: 1px;
      top: auto;
      left: auto;
      border-right: none;
      border-left: var(--el-border-base);
      border-radius: 0 0 var(--el-border-radius-base) 0;
    }

    @each $size in (large, medium, small) {
      &[class*='#{$size}'] {
        [class*='increase'],
        [class*='decrease'] {
          height: #{math.div(map.get($input-height, $size) - 2, 2)};
          line-height: #{math.div(map.get($input-height, $size) - 2, 2)};
        }
      }
    }
  }
}
