//
// 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 {
      background-color: $interactive-01;
      bottom: 0;
      content: '';
      display: block;
      height: $carbon--spacing-02;
      left: 50%;
      position: absolute;
      opacity: 0;
      transition: width $duration--fast-02 motion(standard, productive);
      width: 0;
    }
  }

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

/// 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 {
    align-items: center;
    display: flex;
    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);
    border-radius: 0;
    color: $text-color;
    display: block;
    font-weight: $font-weight;
    line-height: 1;
    min-width: $button-min-width;
    outline: 0;
    padding: $button-padding;
    position: relative;
    text-align: center;
    text-decoration: none;
    transition: background-color, color;
    transition: $duration--fast-02 motion(standard, productive);
    user-select: none;

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

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

    &:disabled,
    &.#{$prefix}--pagination-nav__page--disabled {
      background: none;
      color: rgba($text-color, 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;
      outline: none;
    }

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

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

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

  .#{$prefix}--pagination-nav__page--select {
    appearance: none;
    max-height: $button-min-width;
    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 {
    height: 100%;
    pointer-events: none;
    position: absolute;
    top: 0;
    width: 100%;

    @include pseudo-underline();

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

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

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

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