@use 'sass:map';

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

@mixin remove-margin {
  & + button.btn-prev[type='button'] {
    margin-left: 0;
  }

  & + .#{$namespace}-pager {
    .number {
      &:first-child {
        margin-left: 0;
      }
      &:last-child {
        margin-right: 0;
      }
    }
  }
}

@mixin pagination-button {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: var(--el-pagination-font-size);
  min-width: var(--el-pagination-button-width);
  height: var(--el-pagination-button-height);
  line-height: var(--el-pagination-button-height);
  box-sizing: border-box;
}

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

  white-space: nowrap;
  padding: 2px 5px;
  color: var(--el-pagination-text-color);
  font-weight: normal;
  display: flex;
  align-items: center;
  @include utils-clearfix;

  span:not([class*='suffix']),
  button {
    @include pagination-button;
  }

  .#{$namespace}-input__inner {
    text-align: center;
    -moz-appearance: textfield;
    line-height: normal;
  }

  .#{$namespace}-select .#{$namespace}-input {
    width: 128px;
  }

  button {
    border: none;
    padding: 0 6px;
    background: transparent;

    &:focus {
      outline: none;
    }

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

    &:disabled {
      color: var(--el-pagination-button-disabled-color);
      background-color: var(--el-pagination-button-disabled-bg-color);
      cursor: not-allowed;
    }
  }

  .btn-prev,
  .btn-next {
    background: center center no-repeat;
    background-size: 16px;
    background-color: var(--el-pagination-bg-color);
    cursor: pointer;
    margin: 0;
    color: var(--el-pagination-button-color);
    border: var(--el-border-base);
    .#{$namespace}-icon {
      display: block;
      font-size: 12px;
      font-weight: bold;
      width: inherit;
    }
  }

  .#{$namespace}-pager li.is-disabled {
    color: var(--el-text-color-placeholder);
    cursor: not-allowed;
  }

  @include m(small) {
    .btn-prev,
    .btn-next,
    .#{$namespace}-pager li,
    .#{$namespace}-pager li.btn-quicknext,
    .#{$namespace}-pager li.btn-quickprev,
    .#{$namespace}-pager li:last-child {
      border-color: transparent;
      font-size: var(--el-font-size-small);
      line-height: var(--el-pagination-line-height-extra-small);
      height: var(--el-pagination-height-extra-small);
      min-width: 24px;
    }

    .arrow.is-disabled {
      visibility: hidden;
    }

    .more::before,
    li.more::before {
      line-height: var(--el-pagination-line-height-extra-small);
    }

    span:not([class*='suffix']),
    button {
      height: var(--el-pagination-height-extra-small);
      line-height: var(--el-pagination-line-height-extra-small);
      font-size: var(--el-font-size-extra-small);
    }

    @include e(editor) {
      height: var(--el-pagination-line-height-extra-small);
      &.#{$namespace}-input .#{$namespace}-input__inner {
        height: var(--el-pagination-height-extra-small);
      }
    }

    .#{$namespace}-input__inner,
    .#{$namespace}-input--small {
      height: var(--el-pagination-height-extra-small) !important;
      line-height: var(--el-pagination-line-height-extra-small);
    }

    .#{$namespace}-input__suffix {
      line-height: var(--el-pagination-line-height-extra-small);
      .#{$namespace}-input__suffix-inner {
        line-height: var(--el-pagination-line-height-extra-small);
        i.#{$namespace}-select__caret {
          line-height: var(--el-pagination-line-height-extra-small);
        }
      }
    }

    .#{$namespace}-select .#{$namespace}-input {
      width: 100px;
    }
  }

  @include e(sizes) {
    margin: 0 16px 0 0;
    font-weight: normal;
    color: var(--el-text-color-regular);
    @include remove-margin();
  }

  @include e(total) {
    margin-right: 16px;
    font-weight: normal;
    color: var(--el-text-color-regular);
    @include remove-margin();
    &[disabled='true'] {
      color: var(--el-text-color-placeholder);
    }
  }

  @include e(jump) {
    margin-left: 16px;
    font-weight: normal;
    color: var(--el-text-color-regular);

    .#{$namespace}-input__inner {
      padding: 0 3px;
    }

    &[disabled='true'] {
      color: var(--el-text-color-placeholder);
    }
  }

  @include e(rightwrapper) {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }

  @include e(editor) {
    line-height: 18px;
    margin: 0 8px;
    height: var(--el-pagination-button-height);
    min-width: 56px;

    text-align: center;
    box-sizing: border-box;
    border-radius: var(--el-pagination-border-radius);

    &.#{$namespace}-input {
      width: 50px;
    }

    &.#{$namespace}-input .#{$namespace}-input__inner {
      height: var(--el-pagination-button-height);
    }

    .#{$namespace}-input__inner::-webkit-inner-spin-button,
    .#{$namespace}-input__inner::-webkit-outer-spin-button {
      -webkit-appearance: none;
      margin: 0;
    }
  }

  @include when(background) {
    .btn-prev,
    .btn-next,
    .#{$namespace}-pager li {
      margin: 0 4px;
      background-color: var(--el-pagination-button-bg-color);
      color: var(--el-text-color-regular);
      min-width: 32px;
      border-radius: 2px;

      &.is-disabled {
        color: var(--el-text-color-placeholder);
        background-color: var(--el-disabled-bg-color);
      }
      @include when(first) {
        margin-left: 0;
      }
      @include when(last) {
        margin-right: 0;
      }
    }

    .btn-prev,
    .btn-next {
      padding: 0;

      &:disabled {
        color: var(--el-text-color-placeholder);
        background-color: var(--el-disabled-bg-color);
      }
      &:hover:not([disabled]) {
        color: var(--el-pagination-hover-color);
      }
    }

    .#{$namespace}-pager li:not(.is-disabled) {
      &:hover {
        color: var(--el-pagination-hover-color);
      }

      &.is-active {
        background-color: var(--el-color-primary);
        color: var(--el-color-white);
        font-weight: bold;
      }
    }

    &.#{$namespace}-pagination--small {
      .btn-prev,
      .btn-next,
      .#{$namespace}-pager li {
        min-width: 24px;
      }
    }
  }
}

@include b(pager) {
  user-select: none;
  list-style: none;
  font-size: 0;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;

  li {
    padding: 0 4px;
    background: var(--el-pagination-bg-color);
    @include pagination-button;
    cursor: pointer;
    text-align: center;
    margin-left: var(--el-pagination-item-margin);
    border: var(--el-border-base);

    &.btn-quickprev:hover {
      cursor: pointer;
    }

    &.btn-quicknext:hover {
      cursor: pointer;
    }

    &.btn-quicknext,
    &.btn-quickprev {
      line-height: var(--el-pagination-button-height);
      color: var(--el-pagination-button-color);

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

      svg {
        pointer-events: none;
      }
    }

    &:focus-visible {
      outline: 1px solid var(--el-pagination-hover-color);
    }

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

    &.is-active {
      color: var(--el-pagination-hover-color);
      cursor: default;
      border-color: var(--el-color-primary);
    }
  }

  & + button.btn-next[type='button'] {
    margin-right: 0;
    margin-left: var(--el-pagination-item-margin);
  }
}
