@use 'sass:map';

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

@mixin pagination-button {
  @include flex(center, center);
  font-size: getCssVar(pagination-font-size);
  min-width: getCssVar(pagination-button-width);
  height: getCssVar(pagination-button-height);
  line-height: getCssVar(pagination-button-height);
  color: getCssVar(pagination-button-color);
  background: getCssVar(pagination-bg-color);
  padding: 0 4px;
  border: none;
  border-radius: getCssVar(pagination-border-radius);
  cursor: pointer;
  text-align: center;
  box-sizing: border-box;
  margin: 0 getCssVar(pagination-button-margin);
  transition: getCssVar(transition-ease);

  * {
    pointer-events: none;
  }

  &:focus {
    outline: none;
  }

  &:hover {
    background-color: getCssVar(pagination-button-bg-hover);
  }

  &:active {
    transform: scale(0.93);
  }

  &:disabled,
  &.is-disabled {
    opacity: 0.4;
    pointer-events: none;
    user-select: none;
  }

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

@include b(pagination) {
  @include set-component-var(pagination, $pagination);
  @include set-var-value(color, getCssVar(primary));

  @include flex(flex-start, center);
  white-space: nowrap;
  color: getCssVar(pagination-text-color);
  font-weight: normal;

  @include when(square) {
    * {
      border-radius: 0px;
    }
  }

  @include when(circle) {
    .btn-prev,
    .btn-next,
    .#{$namespace}-pager button,
    .#{$namespace}-pager__aria-active {
      border-radius: 50%;
    }
  }

  @include when(not-margin) {
    .#{$namespace}-pager button {
      border-radius: 0px;
      margin: 0;
    }

    .btn-prev {
      border-radius: 12px 0px 0px 12px;
      margin-right: 0;
    }
    .btn-next {
      border-radius: 0px 12px 12px 0px;
      margin-left: 0;
    }
  }

  @include when(buttons-dotted) {
    .btn-prev,
    .btn-next {
      width: 15px;
      height: 12px;
      min-width: 15px;
      padding: 0px;
      background: transparent;
      i {
        width: 6px;
        height: 6px;
        &:before {
          width: 1px;
        }
        &:after {
          height: 1px;
        }
      }
    }

    .#{$namespace}-pager > button {
      min-width: 12px;
      max-width: 12px;
      width: 12px;
      height: 12px;

      @include when(active) {
        transform: scale(1);
      }
    }

    .#{$namespace}-pager__aria-active {
      width: 12px;
      height: 12px;
      box-shadow: 0px 2px 10px 0px getColor('color', 0.4);
      transform: scale(1);

      @include when(change) {
        transform: scale(1.2);
      }
    }
  }

  @include meb(false, original, #{$namespace}-input) {
    text-align: center;
    -moz-appearance: textfield;
  }

  .#{$namespace}-select {
    @include set-var-value(
      select-min-height,
      getCssVar(pagination-button-height)
    );
  }
  @include meb(false, input, #{$namespace}-select) {
    width: 128px;
    height: getCssVar(pagination-button-height);
    line-height: getCssVar(pagination-button-height);
    font-size: getCssVar(pagination-font-size);
  }

  button {
    @include pagination-button;
  }

  .btn-prev,
  .btn-next {
    .#{$namespace}-icon {
      display: block;
      font-size: 12px;
      font-weight: bold;
      width: inherit;
    }
  }

  & > * {
    @include when(first) {
      margin-left: 0 !important;
    }
    @include when(last) {
      margin-right: 0 !important;
    }
  }

  .btn-prev {
    margin-left: getCssVar('pagination-item-gap');
  }

  @include e(progress) {
    width: 100%;
    height: 3px;
    background: getColor('gray-3');
    position: absolute;
    bottom: -8px;
    border-radius: 10px;

    .progress {
      width: 0px;
      background: getColor('color', 1);
      height: 100%;
      position: relative;
      border-radius: inherit;
      transition: all 0.25s ease;
      max-width: 100%;
    }
  }

  @include e(sizes) {
    margin-left: getCssVar('pagination-item-gap');
    font-weight: normal;
    color: getCssVar('text-color', 'regular');
  }

  @include e(total) {
    margin-left: getCssVar('pagination-item-gap');
    font-weight: normal;
    color: getCssVar('text-color', 'regular');

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

  @include e(jump) {
    display: flex;
    align-items: center;
    margin-left: getCssVar('pagination-item-gap');
    font-weight: normal;
    color: getCssVar('text-color', 'regular');

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

    @include e(goto) {
      margin-right: 8px;
    }

    @include e(editor) {
      text-align: center;
      box-sizing: border-box;
      width: 56px;
      height: getCssVar(pagination-button-height);
      line-height: getCssVar(pagination-button-height);

      &::-webkit-inner-spin-button,
      &::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
      }
    }

    @include e(classifier) {
      margin-left: 8px;
    }
  }

  @include e(rightwrapper) {
    flex: 1;
    @include flex(flex-end, center);
  }

  @include when(background) {
    .btn-prev,
    .btn-next,
    .#{$namespace}-pager button {
      margin: 0 4px;
      background-color: getCssVar(pagination-button-bg-color);

      &.is-active {
        background-color: getCssVar(color-primary);
        color: getCssVar(color-white);
      }

      &:disabled,
      &.is-disabled {
        color: getCssVar(text-color, placeholder);
        background-color: getCssVar(disabled-bg-color);

        &.is-active {
          color: getCssVar(text-color, secondary);
          background-color: getCssVar(fill-color, dark);
        }
      }
    }

    .btn-prev {
      margin-left: getCssVar(pagination-item-gap);
    }
  }

  @include m(small) {
    .btn-prev,
    .btn-next,
    .#{$namespace}-pager button {
      height: getCssVar(pagination-button-height-small);
      line-height: getCssVar(pagination-button-height-small);
      font-size: getCssVar(pagination-font-size-small);
      min-width: getCssVar(pagination-button-width-small);
    }

    span:not([class*='suffix']),
    button {
      font-size: getCssVar(pagination-font-size-small);
    }

    .#{$namespace}-select {
      @include set-var-value(
        select-min-height,
        getCssVar(pagination-button-height)
      );

      .#{$namespace}-input {
        width: 100px;
        font-size: getCssVar(pagination-font-size-small);
        height: getCssVar(pagination-button-height-small);
        line-height: getCssVar(pagination-button-height-small);
      }
    }
  }
}

@include b(pager) {
  @include flex(flex-start, center);
  position: relative;
  font-size: getCssVar('pagination-font-size');
  padding: 0;
  margin: 0;

  .is-loading {
    border-radius: 50%;
    opacity: 0.5;
    pointer-events: none;
    user-select: none;
    position: relative;
  }

  .is-disabled {
    opacity: 0.4;
    pointer-events: none;
    user-select: none;
  }

  @include e(aria-active) {
    @include flex(center, center);
    background-color: getColor(color);
    color: $color-white;
    border-radius: getCssVar(pagination-border-radius);
    position: absolute;
    transition: getCssVar(transition-ease);
    z-index: 100;
    font-size: inherit;
    box-shadow: 0px 5px 20px 0px getColor('color', 0.3);
    cursor: default;
    width: getCssVar(pagination-button-width);
    height: getCssVar(pagination-button-height);

    &:active {
      transform: scale(1.05);
    }

    @include when(change) {
      transform: scale(1.1);
    }
  }

  .more {
    position: relative;
  }

  .more {
    span {
      opacity: 1;
      visibility: visible;
      transition: getCssVar(transition-ease);
    }

    svg {
      position: absolute;
      top: 50%;
      left: 50%;
      transition: getCssVar(transition-ease);
      opacity: 0;
      visibility: hidden;
    }

    &.btn-quickprev svg {
      transform: translate(calc(-50% + 4px), -50%);
    }

    &.btn-quicknext svg {
      transform: translate(calc(-50% - 4px), -50%);
    }

    &:hover {
      svg {
        transform: translate(-50%, -50%);
        opacity: 1;
        visibility: visible;
      }

      span {
        opacity: 0;
        visibility: hidden;
      }
    }
  }
}

@keyframes pager-rotate {
  100% {
    transform: rotate(360deg);
  }
}
