/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// This is a heavily modified version of the style file originally distributed here:
// https://github.com/react-tools/react-table/blob/master/src/index.styl
// Released originally under the MIT License https://github.com/react-tools/react-table/blob/master/LICENSE

@import '../variables';

$easeOutQuad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
$easeOutBack: cubic-bezier(0.175, 0.885, 0.32, 1.275);
$expandSize: 7px;
$border-color: rgba(0, 0, 0, 0.15);

.ReactTable {
  position: relative;
  display: flex;
  flex-direction: column;

  * {
    box-sizing: border-box;
  }

  .rt-table {
    flex: auto 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    border-collapse: collapse;
    overflow: auto;
  }

  .rt-thead {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    user-select: none;

    &.-headerGroups {
      background: rgba(0, 0, 0, 0.03);
      border-bottom: 1px solid $border-color;
    }
    &.-filters {
      border-bottom: 1px solid $border-color;

      .rt-th {
        border-right: 1px solid $border-color;
      }
    }

    &.-header {
      box-shadow: 0 1px 0 0 $border-color;
    }

    .rt-tr {
      text-align: left;
    }

    .rt-th,
    .rt-td {
      //padding: 5px 5px;
      line-height: normal;
      position: relative;
      border-right: 1px solid $border-color;
      transition: box-shadow 0.3s $easeOutBack;
      box-shadow: inset 0 0 0 0 transparent;

      &.-sort-asc {
        box-shadow: inset 0 3px 0 0 #8489a1;
      }

      &.-sort-desc {
        box-shadow: inset 0 -3px 0 0 #8489a1;
      }

      &.-cursor-pointer {
        cursor: pointer;
      }
    }

    .rt-resizable-header {
      overflow: visible;
      &:last-child {
        overflow: hidden;
      }
    }
    .rt-resizable-header-content {
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .rt-header-pivot {
      border-right-color: $border-color;
    }
    .rt-header-pivot:after,
    .rt-header-pivot:before {
      left: 100%;
      top: 50%;
      border: solid transparent;
      content: ' ';
      height: 0;
      width: 0;
      position: absolute;
      pointer-events: none;
    }
    .rt-header-pivot:after {
      border-color: rgba(255, 255, 255, 0);
      border-left-color: #fff;
      border-width: 8px;
      margin-top: -8px;
    }
    .rt-header-pivot:before {
      border-color: rgba(102, 102, 102, 0);
      border-left-color: #f7f7f7;
      border-width: 10px;
      margin-top: -10px;
    }
  }
  .rt-tbody {
    flex: 99999 1 auto;
    display: flex;
    flex-direction: column;
    overflow: auto;
    overflow-x: hidden; // Prevents strange double horizontal scroll bar
    // z-index:0
    .rt-tr-group {
      border-bottom: 1px solid $border-color;
      &:last-child {
        border-bottom: 0;
      }
    }
    .rt-td {
      border-right: 1px solid $border-color;
    }
    .rt-expandable {
      cursor: pointer;
      text-overflow: clip;
    }
  }

  .rt-tr-group {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }
  .rt-tr {
    flex: 1 0 auto;
    display: inline-flex;
  }
  .rt-th,
  .rt-td {
    flex: 1 0 0px;
    white-space: nowrap;
    text-overflow: ellipsis;
    position: relative;
    overflow: hidden;
  }
  &.-hidden {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    opacity: 0 !important;
  }
  .rt-expander {
    display: inline-block;
    position: relative;
    color: transparent;
    margin: 0 10px;
    &:after {
      content: '';
      position: absolute;
      width: 0;
      height: 0;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%) rotate(-90deg);
      border-left: ($expandSize * 0.72) solid transparent;
      border-right: ($expandSize * 0.72) solid transparent;
      border-top: $expandSize solid rgba(255, 255, 255, 0.8);
      transition: all 0.3s $easeOutBack;
      cursor: pointer;
    }
    &.-open:after {
      transform: translate(-50%, -50%) rotate(0deg);
    }
  }
  .rt-resizer {
    display: inline-block;
    position: absolute;
    width: 36px;
    top: 0;
    bottom: 0;
    right: -18px;
    cursor: col-resize;
    z-index: 10;
  }

  .rt-tfoot {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0px 15px 0px black;

    .rt-td {
      border-right: 1px solid $border-color;
      &:last-child {
        border-right: 0;
      }
    }
  }

  &.-striped {
    .rt-tr.-odd {
      background: rgba(255, 255, 255, 0.025);
    }
  }
  &.-highlight {
    .rt-tbody {
      .rt-tr:not(.-padRow):hover {
        background: rgba(0, 0, 0, 0.05);
      }
    }
  }

  .rt-noData {
    display: block;
    position: absolute;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
    z-index: 1;
    padding: 20px;
    color: rgba(255, 255, 255, 0.5);
    border-radius: 5px;
  }
  .-loading {
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: rgba(76, 76, 76, 0.8);
    transition: all 0.3s ease;
    z-index: -1;
    opacity: 0;
    pointer-events: none;

    * > div {
      position: absolute;
      display: block;
      text-align: center;
      width: 100%;
      top: 50%;
      left: 0;
      font-size: 15px;
      color: rgba(0, 0, 0, 0.6);
      transform: translateY(-52%);
      transition: all 0.3s $easeOutQuad;
    }
    &.-active {
      opacity: 1;
      z-index: 2;
      pointer-events: all;
      * > div {
        transform: translateY(50%);
      }
    }
  }
  .rt-resizing {
    .rt-th,
    .rt-td {
      cursor: col-resize;
      user-select: none;
    }
  }
}
