@import "variables";

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

  & + .nv-pager {
    .number {
      &:first-child {
        @apply ml-0;
      }

      &:last-child {
        @apply mr-0;
      }
    }
  }
}

@mixin pagination-button {
  @apply flex items-center justify-center box-border;
  font-size: $pagination-font-size;
  min-width: $pagination-button-width;
  height: $pagination-button-height;
  line-height: $pagination-button-height;
}

.nv-pagination {
  @apply whitespace-nowrap font-normal flex items-center;
  color: $pagination-text-color;

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

  input[type=number] {
    @apply text-center;
    -moz-appearance: textfield;
    line-height: normal;
  }

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

    &:focus {
      outline: none;
    }

    &:hover {
      @apply text-primary;
    }

    &:disabled {
      @apply cursor-not-allowed;
      color: $pagination-button-disabled-color;
      background-color: $pagination-button-disabled-bg-color;
    }
  }

  .btn-prev,
  .btn-next {
    @apply cursor-pointer m-0 p-0;
    background-color: $pagination-bg-color;
    color: $pagination-button-color;
  }

  .nv-pager li.is-disabled {
    @apply cursor-not-allowed;
  }

  &.nv-pagination--small {
    .btn-prev,
    .btn-next,
    .nv-pager li,
    .nv-pager li.btn-quicknext,
    .nv-pager li.btn-quickprev,
    .nv-pager li:last-child {
      border-color: transparent;
      font-size: $pagination-font-size-small;
      line-height: $pagination-line-height-small;
      height: $pagination-height-small;
      min-width: $pagination-width-small;
    }

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

    .more::before,
    li.more::before {
      line-height: $pagination-line-height-small;
    }

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

    .nv-pagination__editor {
      height: $pagination-line-height-small;

      &.nv-input .nv-input__inner {
        height: $pagination-height-small;
      }
    }

    .nv-input__inner,
    .nv-input--small {
      height: $pagination-height-small !important;
      line-height: $pagination-line-height-small;
    }

    .nv-input__suffix {
      line-height: $pagination-line-height-small;

      .nv-input__suffix-inner {
        line-height: $pagination-line-height-small;

        i.nv-select__caret {
          line-height: $pagination-line-height-small;
        }
      }
    }

    .nv-select .nv-input {
      width: 100px;
    }
  }

  .nv-pagination__sizes {
    @apply flex items-center;

    margin: 0 16px 0 0;
    font-weight: normal;
    @include remove-margin();
  }

  .nv-pagination__total {
    margin-right: 16px;
    font-weight: normal;
    @include remove-margin();
  }

  .nv-pagination__jump {
    margin-left: 16px;
    font-weight: normal;

    .nv-input__inner {
      padding: 0 3px;
    }
  }

  .nv-pagination__rightwrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }

  .nv-pagination__editor {
    line-height: 18px;
    margin: 0 8px;
    height: $pagination-button-height;
    min-width: 56px;
    text-align: center;
    box-sizing: border-box;
    border-radius: $pagination-border-radius;


    &.nv-input .nv-input__inner {
      height: $pagination-button-height;
    }

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

  &.is-background {
    .btn-prev,
    .btn-next,
    .nv-pager li {
      margin: 0 4px;
      background-color: $pagination-button-bg-color;
      min-width: 32px;
      border-radius: $pagination-border-radius;

      &.is-disabled {
        background-color: $pagination-disabled-bg-color;
      }

      &.is-first {
        @apply ml-0;
      }

      &.is-last {
        @apply mr-0;
      }
    }

    .btn-prev,
    .btn-next {
      @apply p-0;

      &:disabled {
        @apply opacity-75;
        background-color: $pagination-disabled-bg-color;
      }

      &:hover:not([disabled]) {
        @apply text-primary;
      }
    }

    .nv-pager li:not(.is-disabled) {
      &:hover {
        @apply text-primary;
      }

      &.is-active {
        @apply bg-primary text-white font-bold;
      }
    }

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

    .nv-pagination__sizes {
      &.is-last {
        margin-left: 16px;
      }
    }
  }
}

.nv-pager {
  @apply select-none list-none p-0 m-0 flex items-center;
  font-size: 0;

  li {
    @apply cursor-pointer text-center;
    padding: 0 4px;
    background: $pagination-bg-color;
    @include pagination-button;

    &.btn-quickprev:hover,
    &.btn-quicknext:hover {
      @apply cursor-pointer;
    }

    &.btn-quicknext,
    &.btn-quickprev {
      @apply p-0;
      line-height: 32px;
      color: $pagination-button-color;

      &.is-disabled {
        @apply cursor-not-allowed;
      }

      svg {
        @apply pointer-events-none;
      }
    }

    &.is-disabled {
      @apply opacity-75;
    }

    &.is-active + li {
      @apply border-l-0;
    }

    &:not(.is-disabled) {
      &:focus-visible {
        @apply outline outline-1 outline-primary;
      }

      &:hover {
        @apply text-primary;
      }
    }

    &.is-active {
      @apply text-primary cursor-default;
    }
  }

  & + button.btn-next[type='button'] {
    @apply mr-0;
  }
}
