//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@use "../../config" as *;
@use "../../motion" as *;
@use "../../spacing" as *;
@use "../../type" as *;
@use "../../theme" as *;
@use "../../utilities/button-reset";
@use "../../utilities/convert" as *;
@use "../../utilities/focus-outline" as *;
@use "../../utilities/high-contrast-mode" as *;
@use "../../utilities/visually-hidden" as *;
@use "mixins" as *;

/// Pagination nav base styles
/// @access public
/// @group pagination-nav
/// @param {Color} $text-color [$text-02]
/// @param {Color} $text-color-active [$text-02]
/// @param {Color} $background-color-hover [$hover-ui]
/// @param {Color} $background-color-active [initial]
/// @param {Number} $font-weight [400]
/// @param {Number} $item-padding [0]
/// @param {Number} $button-min-width [$spacing-09]
/// @param {Value} $button-padding [1.0625rem $spacing-02]
/// @param {Number} $button-direction-size [$spacing-09]
/// @param {Number} $select-icon-top-position [$spacing-05]
/// @param {Number} $select-icon-left-position [$spacing-05]
@mixin pagination-nav(
  $color: $text-body-secondary,
  $text-color-active: $text-body-secondary,
  $background-color-hover: $background-hover,
  $background-color-active: initial,
  $font-weight: 400,
  $item-padding: 0,
  $button-min-width: $spacing-09,
  $button-padding: 1.0625rem $spacing-02,
  $button-direction-size: $spacing-09,
  $select-icon-top-position: $spacing-05,
  $select-icon-left-position: $spacing-05
) {
  .#{$prefix}--pagination-nav {
    @include reset;
    @include type-style("body-short");

    line-height: 0;
  }

  .#{$prefix}--pagination-nav__list {
    display: flex;
    align-items: center;
    list-style: none;
  }

  .#{$prefix}--pagination-nav__list-item {
    padding: $item-padding;

    &:first-child {
      padding-left: 0;
    }

    &:last-child {
      padding-right: 0;
    }
  }

  .#{$prefix}--pagination-nav__page {
    @include type-style("body-short");
    @include button-reset.reset($width: false);

    position: relative;
    display: block;
    min-width: $button-min-width;
    padding: $button-padding;
    border-radius: 0;
    color: $text-body-secondary;
    font-weight: $font-weight;
    line-height: 1;
    outline: 0;
    text-align: center;
    text-decoration: none;
    transition: background-color $duration-fast-02 motion(standard, productive),
      color $duration-fast-02 motion(standard, productive);
    user-select: none;

    &:hover {
      background-color: $background-color-hover;
      color: $text-body-secondary;
    }

    &:focus {
      @include focus-outline("outline");
    }

    &:disabled,
    &.#{$prefix}--pagination-nav__page--disabled {
      background: none;
      color: rgba($text-body-secondary, 0.5);
      outline: none;
      pointer-events: none;
    }

    @include pseudo-underline();

    &.#{$prefix}--pagination-nav__page--active {
      background-color: $background-color-active;
      color: $text-color-active;
      font-weight: 600;
    }

    .#{$prefix}--pagination-nav__icon {
      fill: currentColor;
      pointer-events: none;
    }
  }

  .#{$prefix}--pagination-nav__page--direction {
    display: flex;
    width: $button-direction-size;
    height: $button-direction-size;
    align-items: center;
    justify-content: center;
    line-height: 0;
  }

  .#{$prefix}--pagination-nav__select {
    position: relative;
  }

  .#{$prefix}--pagination-nav__page--select {
    max-height: $button-min-width;
    appearance: none;
    text-indent: calc(50% - 4.5px);
    // Override some Firefox user-agent styles
    @-moz-document url-prefix() {
      text-indent: 0;
    }
  }

  .#{$prefix}--pagination-nav__select-icon-wrapper {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;

    @include pseudo-underline();

    .#{$prefix}--pagination-nav__page--active + & {
      .#{$prefix}--pagination-nav__select-icon {
        display: none;
      }
    }
  }

  .#{$prefix}--pagination-nav__select-icon {
    position: absolute;
    top: calc(50% - #{$select-icon-top-position * 0.5});
    left: calc(50% - #{$select-icon-top-position * 0.5});
    pointer-events: none;
  }

  .#{$prefix}--pagination-nav__accessibility-label {
    @include visually-hidden;
  }
}
