@import "mixins/mixins";
@import "checkbox";
@import "tag";
@import "tooltip";
@import "common/var";

@include b(table) {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  height: fit-content;
  width: 100%;
  max-width: 100%;
  background-color: $table-bg-color;
  font-size: $table-font-size;
  color: $table-font-color;

  @include e(empty-block) {
    min-width: 60px;
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  @include e(empty-text) {
    line-height: 60px;
    width: 50%;
    color: $text-color-gradual-3;
  }

  @include e(expand-column) {
    .cell {
      padding: 0;
      text-align: center;
    }
  }

  @include e(expand-icon) {
    position: relative;
    cursor: pointer;
    color: #666;
    font-size: 12px;
    transition: transform .2s ease-in-out;
    height: 20px;

    @include mf(expanded) {
      transform: rotate(90deg);
    }
    > .#{$namespace}-icon {
      position: absolute;
      left: 50%;
      top: 50%;
      margin-left: -5px;
      margin-top: -5px;
    }
  }

  @include e(expanded-cell) {
    background-color: $table-expanded-cell-bg-color;

    &[class*=cell] {
      padding: 20px 50px;
    }

    &:hover {
      background-color: transparent !important;
    }
  }

  @include e(placeholder) {
    display: inline-block;
    width: 20px;
  }

  @include e(append-wrapper) {
    overflow: hidden;
  }

  @include mf(fit) {
    border-right: 0;
    border-bottom: 0;
    th.gutter, td.gutter {
      border-right-width: 1px;
    }
  }

  @include mf(scrollable-x) {
    .#{$namespace}-table_body-wrapper {
      overflow-x: auto;
    }
  }

  @include mf(scrollable-y) {
    .#{$namespace}-table_body-wrapper {
      overflow-y: auto;
    }
  }

  thead {
    color: $table-header-font-color;
    font-weight: 500;

    &.ro-group {
      th {
        background: $table-header-bg-color;
      }
    }
  }

  th, td {
    padding: $table-header-padding;
    min-width: 0;
    box-sizing: border-box;
    text-overflow: ellipsis;
    vertical-align: middle;
    position: relative;
    text-align: left;

    @include pf(center) {
      text-align: center;
    }
    @include pf(right) {
      text-align: right;
    }

    &.gutter {
      width: 15px;
      border-right-width: 0;
      border-bottom-width: 0;
      padding: 0;
    }

    &.ro-hidden {
      > * {
        visibility: hidden;
      }
    }
  }

  @include mf(medium) {
    th, td {
      padding: 10px 0;
    }
  }
  @include mf(small) {
    font-size: 12px;
    th, td {
      padding: 10px 0;
    }
  }
  @include mf(mini) {
    font-size: 12px;
    th, td {
      padding: 10px 0;
    }
  }
  tr {
    background-color: $table-body-bg-color;

    input[type="checkbox"] {
      margin: 0;
    }
  }
  th.ro-leaf, td {
    border-bottom: $table-border;
  }
  th.ro-sortable {
    cursor: pointer;
  }

  th {
    overflow: hidden;
    user-select: none;
    background-color: $table-header-bg-color;

    > .cell {
      display: inline-block;
      box-sizing: border-box;
      position: relative;
      vertical-align: middle;
      width: 100%;

      &.highlight {
        color: $table-highlight-color;
      }
    }

    &.required > div::before {
      display: inline-block;
      content: "";
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #ff4d51;
      margin-right: 5px;
      vertical-align: middle;
    }
  }

  td {
    div {
      box-sizing: border-box;
    }

    &.gutter {
      width: 0;
    }
  }

  .cell {
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    word-break: break-all;
    line-height: 23px;
    padding-left: 10px;
    padding-right: 10px;

    &.#{$namespace}-tooltip {
      white-space: nowrap;
      min-width: 50px;
    }
  }

  @include mf((border, group)) {
    border: $table-border;

    @include share-rule(border-pseude) {
      content: '';
      position: absolute;
      background-color: $table-border-color;
      z-index: 1;
    }

    &::after {
      @include extend-rule(border-pseudo);
      top: 0;
      right: 0;
      width: 1px;
      height: 100%;
    }
  }

  &::before {
    @include extend-rule(border-pseudo);
    left: 0;
    bottom: 0;
    width: 100%;
    height: 1px;
  }

  @include mf(border) {
    border-right: none;
    border-bottom: none;

    th, td {
      border-right: $table-border;

      &:first-child .cell {
        padding-left: 10px;
      }
    }
    th.gutter:last-of-type {
      border-bottom: $table-border;
      border-bottom-width: 1px;
    }
    & th {
      border-bottom: $table-border;
    }
  }

  @include mf(hidden) {
    visibility: hidden;
  }

  @include e((fixed, fixed-right)) {
    position: absolute;
    top: 0;
    left: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    box-shadow: $table-fixed-box-shadow;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      right: 0;
      width: 100%;
      height: 1px;
      background-color: $table-fixed-bg-color;
      z-index: 4;
    }
  }

  @include e(fixed-right-patch) {
    position: absolute;
    top: -1px;
    right: 0;
    background-color: $table-fixed-right-patch-bg-color;
    border-bottom: $table-border;
  }

  @include e(fixed-right) {
    top: 0;
    left: auto;
    right: 0;

    .#{$namespace}-table_fixed-header-wrapper,
    .#{$namespace}-table_fixed-body-wrapper,
    .#{$namespace}-table_fixed-footer-wrapper {
      left: auto;
      right: 0;
    }
  }

  @include e(fixed-header-wrapper) {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 3;
  }

  @include e(fixed-footer-wrapper) {
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 3;
    & tbody td {
      border-top: $table-border;
      background-color: $table-row-hover-background-color;
      color: $table-font-color;
    }
  }

  @include e(fixed-body-wrapper) {
    position: absolute;
    left: 0;
    top: 37px;
    overflow: hidden;
    z-index: 3;
  }

  @include e((header-wrapper, body-wrapper, footer-wrapper)) {
    width: 100%;
  }

  @include e(footer-wrapper) {
    margin-top: -1px;
    td {
      border-top: $table-border;
    }
  }

  @include e((header, body, footer)) {
    table-layout: fixed;
    border-collapse: separate;
  }
  @include e((header-wrapper, footer-wrapper)) {
    overflow: hidden;

    & tbody td {
      background-color: $table-row-hover-background-color;
      color: $table-font-color;
    }
  }
  &_body-wrapper {
    overflow: hidden;
    position: relative;

    @include pf(scrolling-none) {
      ~ .#{$namespace}-table_fixed,
      ~ .#{$namespace}-table_fixed-right {
        box-shadow: none;
      }
    }

    @include pf(scrolling-left) {
      ~ .#{$namespace}-table_fixed {
        box-shadow: none;
      }
    }

    @include pf(scrolling-right) {
      ~ .#{$namespace}-table_fixed-right {
        box-shadow: none;
      }
    }

    .#{$namespace}-table-border {
      @include pf(scrolling-right) {
        ~ .#{$namespace}-table_fixed-right {
          border-left: $table-border;
        }
      }

      @include pf(scrolling-left) {
        ~ .#{$namespace}-table_fixed {
          border-right: $table-border;
        }
      }
    }
  }

  .caret-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    height: 14px;
    width: 24px;
    vertical-align: middle;
    cursor: pointer;
    overflow: initial;
    position: relative;
  }

  .sort-caret {
    width: 0;
    height: 0;
    border: 5px solid transparent;
    position: absolute;
    left: 7px;

    &.ascending {
      border-bottom-color: $table-ascending-border-color;
      top: -5px;
    }

    &.descending {
      border-top-color: $table-ascending-border-color;
      bottom: -3px;
    }
  }
  .ascending .sort-caret.ascending {
    border-bottom-color: $primary-color;
  }

  .descending .sort-caret.descending {
    border-top-color: $primary-color;
  }

  .hidden-columns {
    visibility: hidden;
    position: absolute;
    z-index: -1;
  }

  @include mf(striped) {
    & .#{$namespace}-table_body {
      & tr.#{$namespace}-table_row-striped {
        td {
          background: #FAFAFA;
        }

        &.current-row td {
          background-color: $table-current-row-bg-color;
        }
      }
    }
  }

  @include e(body) {
    tr.hover-row {
      &, &.#{$namespace}-table_row-striped {
        &, &.current-row {
          > td {
            background-color: $table-row-hover-background-color;
          }
        }
      }
    }

    tr.current-row > td {
      background-color: $table-current-row-bg-color;
    }
  }

  @include e(column-resize-proxy) {
    position: absolute;
    left: 200px;
    top: 0;
    bottom: 0;
    width: 0;
    border-left: $table-border;
    z-index: 10;
  }

  @include e(column-filter-trigger) {
    display: inline-block;
    cursor: pointer;

    & i {
      color: $info-color;
      font-size: 12px;
      vertical-align: middle;
      transform: scale(.75);
    }
  }

  @include mf(enable-row-transition) {
    .#{$namespace}-table_body td {
      transition: background-color .25s ease;
    }
  }

  @include mf(enable-row-hover) {
    .#{$namespace}-table_body tr:hover > td {
      background-color: $table-row-hover-background-color;
    }
  }

  @include mf(fluid-height) {
    .#{$namespace}-table_fixed,
    .#{$namespace}-table_fixed-right {
      bottom: 0;
      overflow: hidden;
    }
  }

  [class*=#{$namespace}-table_row-level] {
    .#{$namespace}-table_expand-icon {
      display: inline-block;
      width: 20px;
      line-height: 20px;
      height: 20px;
      text-align: center;
      margin-right: 3px;
    }
  }

  .success-row {
    background-color: $table-row-success-row-bg-color;
  }
  .warning-row {
    background-color: $table-row-warning-row-bg-color;
  }
  .primary-row {
    background-color: $table-row-primary-row-bg-color;
  }
  .info-row {
    background-color: $table-row-info-row-bg-color;
  }
  .danger-row {
    background-color: $table-row-danger-row-bg-color;
  }

}
