/* Lightning Design System 0.9.1 */
// Copyright (c) 2015, salesforce.com, inc. All rights reserved.

// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
// Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



.#{$css-prefix}table {
  background-color: $color-background-alt;

  // Cells
  th,
  td {
    padding: $spacing-x-small;
    white-space: nowrap;

    &.#{$css-prefix}text-center {
      text-align: center;
    }

    &.#{$css-prefix}text-right {
      text-align: right;
    }
  }

  // First and Last Cell of a row
  tr > th:first-child,
  tr > td:first-child {
    padding-left: $spacing-large;
  }

  tr > th:last-child,
  tr > td:last-child {
    padding-right: $spacing-large;
  }

  // Table Heading Cells
  th {
    font-weight: $font-weight-regular;
  }

  // Default Table Row Hover
  &:not(.#{$css-prefix}no-row-hover) tbody tr:hover {
    > td,
    > th {
      background-color: $color-background-row-hover;
    }
  }

  // Selected Table Row + Hover
  tbody tr.#{$css-prefix}is-selected,
  &:not(.#{$css-prefix}no-row-hover) tr.#{$css-prefix}is-selected:hover {

    > td,
    > th {
      background-color: $color-background-row-selected;
    }
  }

  // Selected Cell
  td.#{$css-prefix}is-selected,
  td.#{$css-prefix}is-selected:hover {
    box-shadow: $color-border-selection 0 0 0 $border-width-thick inset;
  }

  // Deal with truncation
  .#{$css-prefix}truncate {
    min-width: rem(52px);
    max-width: rem(240px);
  }

  // By default, nowrap is applied
  .#{$css-prefix}cell-wrap {
    white-space: normal;
  }

  // Apply to cell with checkbox and actions
  .#{$css-prefix}cell-shrink {
    width: 1%;
  }
}

// Add vertical borders to a table
.#{$css-prefix}table--bordered {

  border: {
    top: $border-width-thin solid $color-border;
    bottom: $border-width-thin solid $color-border;
  }

  // More than one row in thead
  thead > tr + tr > th {
    border-top: $border-width-thin solid $color-border;
  }

  // Cells
  td,
  th {
    border-top: $border-width-thin solid $color-border;
  }

  // Default Table Row Hover
  &:not(.#{$css-prefix}no-row-hover) tbody tr:hover > td,
  &:not(.#{$css-prefix}no-row-hover) tbody tr:hover > th  {
    box-shadow: $color-border 0 ($border-width-thin * -1) 0 inset;
  }

  // Selected Table Row + Hover
  &:not(.#{$css-prefix}no-row-hover) .#{$css-prefix}is-selected:hover > td,
  &:not(.#{$css-prefix}no-row-hover) .#{$css-prefix}is-selected:hover > th {
    border-color: $color-border-selection;
    box-shadow: $color-border-selection 0 ($border-width-thick * -1) 0 inset;

    &.#{$css-prefix}is-selected {
      box-shadow: $color-border-selection 0 ($border-width-thin * -1) 0 $border-width-thick inset
    }
  }
}

// Add alternating strips to rows
.#{$css-prefix}table--striped {

  tr:nth-of-type(even) > td {
    background-color: $color-background-row-hover;
  }
}

// Applies move cursor to moveable cell
.#{$css-prefix}is-sortable {
  cursor: pointer;

  .#{$css-prefix}button {
    visibility: hidden;
    margin-left: $spacing-x-small;
  }

  .#{$css-prefix}button__icon {
    fill: $color-text-link;
  }

  &:hover {
    background-color: $color-background-row-hover;
    color: $color-text-link;

    .#{$css-prefix}button {
      visibility: visible;
    }

    .#{$css-prefix}button__icon {
      fill: $color-text-link;
    }
  }
}
