$component-name: $lib-name + "-table";
$table-border-color: $border-color-base;
$table-header-bg: $background-color-disabled;
$table-stripe-row-bg: $neutral-color-5;
$table-row-hover-bg: $neutral-color-4;
$order-triangle-height: 4px;

.#{$component-name} {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  border-right: none;
  border-bottom: none;
  background: $background-color-base;
  &::before {
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 20;
    width: 100%;
    height: 1px;
    background: $table-border-color;
    content: "";
  }
  &.#{$component-name}--border {
    border: 1px solid $table-border-color;
    border-right: none;
    border-bottom: none;
    &::after {
      position: absolute;
      top: 0;
      right: 0;
      z-index: 20;
      width: 1px;
      height: 100%;
      background: $table-border-color;
      content: "";
    }
    .fixed-left-table-wrapper.no-shadow::after,
    .fixed-right-table-wrapper.no-shadow::after {
      position: absolute;
      content: "";
      top: 0;
      width: 1px;
      height: 100%;
      background: $table-border-color;
    }
    .fixed-left-table-wrapper.no-shadow::after {
      right: 0;
    }
    .fixed-right-table-wrapper.no-shadow::after {
      right: left;
    }
  }
  .hidden-content {
    visibility: hidden;
    position: absolute;
    z-index: -1;
  }
  .table-header-wrapper,
  .table-body-wrapper {
    overflow: hidden;
    &.flex-wrapper {
      display: flex;
    }
  }
  .#{$component-name}-header,
  .#{$component-name}-body {
    table-layout: fixed;
    // fix scroller line-height
    line-height: 1;
  }
  .table-header-row {
    background: $table-header-bg;
    &.border-top {
      .table-header-cell {
        border-top: 1px solid #e4eaf1;
      }
    }

    .table-header-cell {
      &.hover-bg,
      &.resizable-bg:hover {
        background: $table-row-hover-bg;
      }
    }
  }
  .table-row {
    transition: background $transition-time;
    &:hover,
    &.hover-state {
      background: $table-row-hover-bg;
      .fix-left, .fix-right {
        background: $table-row-hover-bg;
      }
    }
    &.striped-row {
      background: $table-stripe-row-bg;
      &:hover,
      &.hover-state {
        background: $table-row-hover-bg;
        .fix-left, .fix-right {
          background: $table-row-hover-bg;
        }
      }
      .fix-left, .fix-right {
        background: $table-stripe-row-bg;
      }
    }
  }
  .table-header-cell,
  .table-cell {
    box-sizing: border-box;
    &.right-border {
      border-right: 1px solid $table-border-color;
    }
    &.bottom-border {
      border-bottom: 1px solid $table-border-color;
    }

    &-content {
      text-align: left;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      padding: 0 4px;
      &.icon-column {
        cursor: pointer;
      }
    }
    &.align-left{
      .table-cell-content,
      .table-header-cell-content {
        text-align: left;
        &.flex-wrapper, &.flex-cell {
          justify-content: flex-start;
        }
      }
    }
    &.align-right{
      .table-cell-content,
      .table-header-cell-content {
        text-align: right;
        &.flex-wrapper, &.flex-cell {
          justify-content: flex-end;
        }
      }
    }
    &.align-center {
      .table-cell-content,
      .table-header-cell-content {
        text-align: center;
        &.flex-wrapper, &.flex-cell {
          justify-content: center;
        }
      }
    }
  }

  .table-header-cell {
    &.sortable-column {
      .table-header-text {
        cursor: pointer;
        user-select: none;
      }
    }
  }
  .table-header-cell-content,
  .table-cell-content {
    padding: 10px 12px;
    font-size: 14px;
    line-height: 18px;
    text-overflow: ellipsis;
    overflow-wrap: break-word;
    &.align-left {
      text-align: left;
    }
    &.align-center {
      text-align: center;
    }
    &.align-right {
      text-align: right;
    }
    &.icon-column {
      .expand-icon {
        cursor: pointer;
        color: $sub-text-color-light;
        font-size: 14px;
        &:hover {
          color: $primary-color;
        }
      }
    }
  }

  .table-header-cell-content {
    font-weight: 500;
    color: $title-color-light;
    &.flex-cell {
      display: flex;
      align-items: center;
      .table-header-text.sortable-column {
        cursor: pointer;
        user-select: none;
      }
      &.align-left {
        justify-content: flex-start;
      }
      &.align-center {
        justify-content: center;
      }
      &.align-right {
        justify-content: flex-start;
        flex-direction: row-reverse;
      }
    }
    .column-order-area {
      display: inline-flex;
      flex-direction: column;
      justify-content: space-between;
      height: 18px;
      padding: 0 4px;
      cursor: pointer;
      .ascending-order,
      .descending-order {
        cursor: pointer;
        border-style: solid;
        border-width: $order-triangle-height;
      }
      .ascending-order {
        border-color: transparent transparent $disabled-text-color-light transparent;
      }
      .descending-order {
        border-color: $disabled-text-color-light transparent transparent transparent;
      }
    }
  }
  .asc .column-order-area .ascending-order {
    border-color: transparent transparent $primary-color transparent;
  }
  .desc .column-order-area .descending-order {
    border-color: $primary-color transparent transparent transparent;
  }
  .table-cell-content {
    color: $content-color-light;
    @for $i from 1 through 9 {
      &.row-level-#{$i} {
        padding-left: 8px + 20px * ($i - 1);
      }
    }
    &.flex-wrapper {
      display: flex;
    }
    .unfold-icon {
      margin-right: 8px;
      cursor: pointer;
      color: $sub-text-color-light;
      font-size: 12px;
      transition: transform $transition-time;
      &:hover {
        color: $primary-color;
      }
      &.rotate-down {
        transform: rotate(90deg);
      }
    }
  }
  .tree-branch-text {
    cursor: pointer;
  }
  .ellipsis-text,
  .ellipsis-text .tree-branch-text {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  &.affix-table-header {
    .affix {
      position: fixed;
      top: 0;
      z-index: 5;
      background: $background-color-base;
    }
  }
  .fixed-left-table-wrapper,
  .fixed-right-table-wrapper {
    position: absolute;
    top: 0;
    z-index: 10;
    overflow: hidden;
    background: $background-color-base;
    box-shadow: $box-shadow-base;
    &.no-shadow {
      box-shadow: none;
      .transparent-border {
        border-right-color: $table-border-color;
      }
    }
    .affix {
      z-index: 15;
      background: transparent;
    }
    .table-header-wrapper,
    .table-body-wrapper {
      position: absolute;
    }
  }
  .fixed-left-table-wrapper {
    left: 0;
    .transparent-border {
      border-right-color: transparent;
    }
  }
  .fixed-right-table-wrapper {
    right: 0;
    .table-header-wrapper,
    .table-body-wrapper {
      right: 0;
    }
  }
  .table-empty-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 50px;
    .table-empty-text {
      font-size: 14px;
      color: $sub-text-color-light;
    }
  }
  .table-column-resize-proxy {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    border-left: 1px solid $table-border-color;
    z-index: 25;
  }

  .base-table {
    border-spacing: 0;
    border: none;
    width: 100%;
    table-layout: fixed;

    .fix-left, .fix-right {
      z-index: 1;
      background: #fff;
      transition: background $transition-time;
    }

    &__head {
      .fix-left, .fix-right {
        background: inherit;
      }
    }


    &__content {
      .table-row {
        border-bottom: 1px solid $border-color-base;
      }
    }

    .table-header-row {
      .table-cell,
      .table-header-cell {
        box-sizing: border-box;
        font-size: 14px;
      }
      .table-header-cell {
        position: relative;
        font-weight: 500;
        color: #252d39;
        &.sortable-column {
          cursor: pointer;
        }
        .resize-handle {
          position: absolute;
          right: 0;
          width: 10px;
          height: 100%;
          top: 0;
          cursor: col-resize;
        }
      }
    }

    &.border-right {
      .table-header-row .table-header-cell,
      .table-row .table-cell {
        &:not(.last-fix-left) {
          &:not(:last-child) {
            border-right: 1px solid $border-color-base;
          }
        }
      }
    }
    &.border-bottom {
      .table-row .table-cell {
        border-bottom: 1px solid $border-color-base;
      }
    }
  }

  &.hit-left {
    .base-table {
      &.border-right {
        .table-header-row .table-header-cell,
        .table-row .table-cell {
          &.last-fix-left {
            border-right: 1px solid $border-color-base;
          }
        }
      }
    }
  }

  &.scrollable-x {
    .table-body-scroller {
      &.#{$lib-name}-h-scrollbar {
        z-index: 6;
      }
      &.#{$lib-name}-v-scrollbar {
        z-index: 16;
      }
    }
    .table-header-cell,
    .table-cell {
      &.hidden-column {
        visibility: hidden;
      }
    }

    &:not(.hit-left) {
      .fix-left.last-fix-left{
        &:after {
          position: absolute;
          top: 0;
          bottom: -1px;
          right: 0;
          width: 30px;
          transition: box-shadow .3s;
          content: "";
          transform: translateX(100%);
          box-shadow: inset 8px 0 8px -8px rgba(0, 0, 0, .14);
          pointer-events: none;
        }
      }
    }

    &:not(.hit-right) {
      .fix-right.first-fix-right {
        &:after {
          position: absolute;
          top: 0;
          left: 0;
          bottom: -1px;
          width: 30px;
          transition: box-shadow .3s;
          content: "";
          transform: translateX(-100%);
          box-shadow: inset -8px 0 8px -8px rgba(0, 0, 0, .14);
          pointer-events: none;
        }
      }
    }
  }
}
