//
// 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.
//

//-----------------------------
// Pagination Nav
//-----------------------------

@import '../../globals/scss/colors';
@import '../../globals/scss/vars';
@import '../../globals/scss/theme';
@import '../../globals/scss/typography';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';
@import '../../globals/scss/css--reset';

/// Pseudo underline
/// @access private
/// @group pagination-nav
@mixin pseudo-underline() {
  &:not(.#{$prefix}--pagination-nav__page--direction) {
    &::after {
      position: absolute;
      bottom: 0;
      left: 50%;
      display: block;
      width: 0;
      height: $carbon--spacing-02;
      background-color: $interactive-01;
      opacity: 0;
      transition: width $duration--fast-02 motion(standard, productive);
      content: '';
    }
  }

  .#{$prefix}--pagination-nav__page--active + &::after,
  &.#{$prefix}--pagination-nav__page--active::after {
    left: calc(50% - #{$carbon--spacing-05 / 2});
    width: $carbon--spacing-05;
    opacity: 1;
  }
}

/// Pagination nav base styles
/// @access private
/// @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 [$carbon--spacing-09]
/// @param {Value} $button-padding [1.0625rem $carbon--spacing-02]
/// @param {Number} $button-direction-size [$carbon--spacing-09]
/// @param {Number} $select-icon-top-position [$carbon--spacing-05]
/// @param {Number} $select-icon-left-position [$carbon--spacing-05]
@mixin pagination-nav(
  $text-color: $text-02,
  $text-color-active: $text-02,
  $background-color-hover: $hover-ui,
  $background-color-active: initial,
  $font-weight: 400,
  $item-padding: 0,
  $button-min-width: $carbon--spacing-09,
  $button-padding: 1.0625rem $carbon--spacing-02,
  $button-direction-size: $carbon--spacing-09,
  $select-icon-top-position: $carbon--spacing-05,
  $select-icon-left-position: $carbon--spacing-05
) {
  .#{$prefix}--pagination-nav {
    @include reset;
    @include type-style('body-short-01');

    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-01');
    @include button-reset($width: false);

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

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

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

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

    @include pseudo-underline();

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

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

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

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

  .#{$prefix}--pagination-nav__page--select {
    max-height: $button-min-width;
    text-indent: calc(50% - 4.5px);
    appearance: none;
    // 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 / 2});
    left: calc(50% - #{$select-icon-top-position / 2});
    pointer-events: none;
  }

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

@include exports('pagination-nav') {
  @include pagination-nav;
}
