@import "../../../styles/assets/mixin.scss";
$table-prefix: "#{$prefixCls}RCTable";
$tablePrefixCls: $table-prefix;
$border: $table-border-width solid $table-border-color;
$cell-padding: $thead-vertical-padding $thead-horizontal-padding;
$cell-margin: -$thead-vertical-padding -$thead-horizontal-padding;
$border-transparent: transparent;

@mixin tableBorder() {
  border: $border;
  border-right: 0;
  border-bottom: 0;
}

.#{$tablePrefixCls} {
  position: relative;
  box-sizing: border-box;
  color: $table-color;
  font-size: $table-font-size;
  line-height: $table-line-height;
  // border-right: 5px solid yellow;
  border-right: $border;

  &-rtl {
    direction: rtl;
  }

  // ================= Global =================
  table {
    width: 100%;
    border-spacing: 0px;
  }
  th {
    height: $table-th-height;
    font-weight: $thead-font-weight;
  }
  td {
    height: $table-td-height;
  }
  th,
  td {
    position: relative;
    box-sizing: border-box;
    padding: 0;
    padding: $cell-padding;
    white-space: normal;
    word-break: break-word;
    border: $border;
    border-top: 0;
    border-left: 0;
    transition: box-shadow 0.3s;

    .#{$tablePrefixCls}-rtl & {
      border-right: 0;
      border-left: $border;
    }
  }

  // ================== Cell ==================
  &-cell {
    &-fix-left,
    &-fix-right {
      z-index: 1;
    }

    // &-fix-right:last-child:not(&-fix-sticky) {
    //   border-right-color: transparent;
    // }

    .#{$tablePrefixCls}-rtl & {
      &-fix-right:last-child {
        border-right-color: $table-border-color;
      }

      &-fix-left:last-child {
        border-left-color: transparent;
      }
    }

    &-fix-left-first {
      .#{$tablePrefixCls}-rtl & {
        box-shadow: 1px 0 0 $table-border-color;
      }
    }

    &-fix-left-first::after,
    &-fix-left-last::after {
      position: absolute;
      top: 0;
      right: -1px;
      bottom: -1px;
      width: 20px;
      transform: translateX(100%);
      transition: box-shadow 0.3s;
      content: "";
      pointer-events: none;
    }

    &-fix-right-first,
    &-fix-right-last {
      box-shadow: -1px 0 0 $table-border-color;

      .#{$tablePrefixCls}-rtl & {
        box-shadow: none;
      }

      &::after {
        position: absolute;
        top: 0;
        bottom: -1px;
        left: -1px;
        width: 20px;
        transform: translateX(-100%);
        transition: box-shadow 0.3s;
        content: "";
        pointer-events: none;
      }
    }

    &#{&}-ellipsis {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;

      // Fixed first or last should special process
      &.#{$tablePrefixCls}-cell-fix-left-first,
      &.#{$tablePrefixCls}-cell-fix-left-last,
      &.#{$tablePrefixCls}-cell-fix-right-first &.#{$tablePrefixCls}-cell-fix-right-last {
        overflow: visible;

        .#{$tablePrefixCls}-cell-content {
          display: block;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }

    &#{&}-row-hover {
      background: $table-row-hover-bg;
    }
  }

  &-ping-left {
    .#{$tablePrefixCls}-cell-fix-left-first::after,
    .#{$tablePrefixCls}-cell-fix-left-last::after {
      box-shadow: inset 10px 0 8px -8px $table-border-color;
    }
  }

  &-ping-right {
    .#{$tablePrefixCls}-cell-fix-right-first::after,
    .#{$tablePrefixCls}-cell-fix-right-last::after {
      box-shadow: inset -10px 0 8px -8px $table-border-color;
    }
  }

  // ================= Expand =================
  &-expand-icon-col {
    width: $table-expand-icon-col-width;
  }

  &-row-expand-icon-cell {
    text-align: center;
  }

  // ================= Header =================
  thead {
    td,
    th {
      text-align: left;
      background: $table-header-bg;
    }
    th {
      border-bottom-color: #f4f6f9;
    }
    tr {
      th[rowspan] {
        border-bottom-color: $table-border-color;
      }
      th:last-child {
        border-right-color: $table-header-bg;
      }
    }
    tr:last-child {
      th {
        border-bottom-color: $table-border-color;
      }
    }

    .#{$tablePrefixCls}-cell-scrollbar::after {
      position: absolute;
      top: 0;
      bottom: 0;
      left: -1px;
      width: 1px;
      background: $table-header-bg;
      content: "";

      .#{$tablePrefixCls}-rtl & {
        right: -1px;
        left: auto;
      }
    }
  }

  &-header {
    @include tableBorder();
  }

  // ================= Empty ==================
  &-placeholder {
    text-align: center;
  }

  // ================== Body ==================
  tbody {
    tr {
      td,
      th {
        background: #fff;
      }
    }
  }

  &-content {
    @include tableBorder();
    border-radius: 0 0 0 0;
  }

  &-body {
    @include tableBorder();
    border-top: 0;
  }

  &-fixed-column &-body::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    // border-right: $border;
    border-right: $border-transparent;
    content: "";
  }

  // ================= Expand =================
  &-expanded-row {
    .#{$tablePrefixCls}-cell {
      box-shadow: inset 0 8px 8px -8px $table-border-color;
    }

    &-fixed {
      box-sizing: border-box;
      margin: $cell-margin;
      margin-right: -$thead-horizontal-padding - 2 * $table-border-width;
      padding: $cell-padding;

      &::after {
        position: absolute;
        top: 0;
        right: 1px;
        bottom: 0;
        width: 0;
        border-right: 1px solid $border-transparent;
        content: "";
      }
    }
  }

  &-row-expand-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    color: #aaa;
    line-height: 16px;
    text-align: center;
    vertical-align: middle;
    // border: 1px solid currentColor;
    cursor: pointer;

    &.#{$table-prefix}-row-expanded::after {
      content: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iOSIgaGVpZ2h0PSI2IiB2aWV3Qm94PSIwIDAgOSA2IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNOC41IDAuNUw0LjUgNS41TDAuNSAwLjUiIGZpbGw9IiM2NTY1NzIiIC8+Cjwvc3ZnPgogIA==");
    }

    &.#{$table-prefix}-row-collapsed::after {
      content: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNSIgaGVpZ2h0PSI4IiB2aWV3Qm94PSIwIDAgNSA4IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMCAwTDUgNEwwIDgiIGZpbGw9IiM2NTY1NzIiIC8+Cjwvc3ZnPgogIA==");
    }

    &.#{$table-prefix}-row-spaced {
      visibility: hidden;
    }
  }

  // ================= Title ==================
  &-title {
    padding: $cell-padding;
    border: $border;
    border-bottom: 0;
  }

  // ================= Footer =================
  &-footer {
    padding: $cell-padding;
    border: $border;
    border-top: 0;
  }

  tfoot {
    td {
      background: #fff;
    }
  }

  &-summary {
    border-top: $border;
    border-left: $border;
  }

  &-sticky {
    &-holder {
      position: sticky;
      z-index: 2;
    }

    &-scroll {
      position: sticky;
      bottom: 0;
      z-index: 2;
      display: flex;
      align-items: center;
      border-top: 1px solid #f3f3f3;
      opacity: 0.6;
      transition: transform 0.1s ease-in 0s;

      &:hover {
        transform: scaleY(1.2);
        transform-origin: center bottom;
      }

      &-bar {
        height: 8px;
        background-color: #bbb;
        border-radius: 4px;

        &:hover {
          background-color: #999;
        }

        &-active {
          background-color: #999;
        }
      }
    }
  }
  tbody {
    tr:hover {
      td {
        border-right-color: $table-row-hover-bg;
      }
    }
    tr {
      td {
        border-right-color: transparent;
        &:last-child {
          border-right-color: $border-transparent;
        }
      }
      .#{$tablePrefixCls}-cell-fix-right:last-child {
        border-right-color: $border-transparent;
      }
    }
  }
  //无边框模式
  &.no-border {
    border: transparent;
    .#{$tablePrefixCls}-content {
      border: transparent;
      td,
      th {
        border-right: transparent;
      }
      th {
        border-bottom: transparent;
      }
    }
  }
  // 去除thead分割线模式
  &.deleteTheadSplitLine {
    thead {
      tr {
        th {
          border-right-color: $table-header-bg;
          &:last-child {
            border-right-color: $table-border-color;
          }
        }
      }
    }
  }
}
