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

@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';
@import '../../globals/scss/vars';

/// Data table sort styles
/// @access private
/// @group data-table
@mixin data-table-sort {
  // -------------------------------------
  // Sortable table
  // -------------------------------------
  .#{$prefix}--data-table--sort th,
  .#{$prefix}--data-table--sort
    th:first-of-type:not(.#{$prefix}--table-column-checkbox):not(.#{$prefix}--table-expand) {
    padding: 0;
  }

  .#{$prefix}--data-table--sort th {
    height: $layout-04;
    border-top: none;
    border-bottom: none;
  }

  .#{$prefix}--data-table--sort td {
    padding-left: $spacing-03;
    padding-right: $spacing-03;
  }

  .#{$prefix}--data-table--sort th:first-of-type .#{$prefix}--table-sort {
    padding-left: $spacing-04;
  }

  // -------------------------------------
  // Th > Button
  // -------------------------------------
  .#{$prefix}--table-sort {
    @include button-reset(false);
    position: relative;
    font: inherit;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    color: $text-01;
    padding: 0 $spacing-03;
    height: 100%;
    background-color: $ui-03;
    transition: background-color $duration--fast-01 motion(entrance, productive),
      outline $duration--fast-01 motion(entrance, productive);
  }

  .#{$prefix}--table-sort:focus {
    @include focus-outline('outline');
  }

  .#{$prefix}--table-sort:hover {
    background: $data-table-column-hover;
  }

  // changes opacity when th is inactive (see line 161)
  .#{$prefix}--table-sort:focus svg,
  .#{$prefix}--table-sort:hover svg {
    opacity: 1;
  }

  // -------------------------------------
  //Th > Button > Svg (Sort Icons)
  // -------------------------------------
  // inactive icons
  .#{$prefix}--table-sort .#{$prefix}--table-sort__icon-inactive {
    display: block;
  }

  .#{$prefix}--table-sort .#{$prefix}--table-sort__icon {
    display: none;
  }

  .#{$prefix}--table-sort__icon-unsorted {
    position: relative;
    left: rem(2px);
    margin-left: $spacing-03;
    margin-right: 0;
    opacity: 0;
    fill: $ui-05;
    width: auto;
    min-width: $layout-01;
  }

  // active icons
  .#{$prefix}--table-sort.#{$prefix}--table-sort--active
    .#{$prefix}--table-sort__icon-unsorted {
    display: none;
  }

  .#{$prefix}--table-sort.#{$prefix}--table-sort--active
    .#{$prefix}--table-sort__icon {
    display: block;
    opacity: 1; //changes opacity when th is active (see line 125)
  }

  .#{$prefix}--table-sort--ascending .#{$prefix}--table-sort__icon {
    transform: rotate(180deg);
  }

  .#{$prefix}--table-sort__icon {
    position: relative;
    left: rem(2px);
    margin-left: $spacing-03;
    margin-right: 0;
    transition: transform $transition--base $carbon--standard-easing;
    transform: rotate(0);
    opacity: 0;
    fill: $ui-05;
    width: auto;
    min-width: $layout-01;
  }

  //----------------------------------------------------------------------------
  // Compact, Short, Tall Sortable
  //----------------------------------------------------------------------------
  // Sortable compact
  .#{$prefix}--data-table--compact.#{$prefix}--data-table--sort th {
    height: rem(24px);
  }

  .#{$prefix}--data-table--compact.#{$prefix}--data-table--sort
    th
    .#{$prefix}--table-sort {
    padding-top: 0;
    padding-bottom: 0;
  }

  // Sortable Short
  .#{$prefix}--data-table--short.#{$prefix}--data-table--sort th {
    height: rem(32px);
  }

  .#{$prefix}--data-table--short.#{$prefix}--data-table--sort
    th
    .#{$prefix}--table-sort {
    padding-top: 0;
    padding-bottom: 0;
  }

  // Sortable Tall
  .#{$prefix}--data-table--tall.#{$prefix}--data-table--sort th {
    height: rem(64px);
  }

  .#{$prefix}--data-table--tall.#{$prefix}--data-table--sort
    th
    .#{$prefix}--table-sort {
    padding-top: 0;
    padding-bottom: 0;
  }

  .#{$prefix}--data-table--tall.#{$prefix}--data-table--sort
    th
    .#{$prefix}--table-sort
    svg {
    align-self: flex-start;
    top: $spacing-03;
  }

  .#{$prefix}--data-table--tall.#{$prefix}--data-table--sort
    th
    .#{$prefix}--table-sort
    .#{$prefix}--table-header-label {
    align-self: flex-start;
    position: relative;
    top: rem(-8px);
    max-height: 3rem;
    display: -webkit-box; // weird text truncation style used
    -webkit-line-clamp: 2; // because we need text to wrap
    -webkit-box-orient: vertical; // can't use white-space: nowrap
  }
}

@include exports('data-table-sort') {
  @include data-table-sort;
}
