@import '../../../styles/assets/mixin.scss';
$table-prefix: #{$prefixCls}table;

td {
  padding: 0;
}
.#{$prefixCls}table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  background-color: $table-bg;
  font-size: $table-font-size;
  color: $table-color;
  line-height: $table-line-height;

  .react-resizable-handle {
    position: absolute;
    width: 10px;
    height: 100%;
    bottom: 0;
    right: -5px;
    cursor: col-resize;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    border: none;
  }
  // 表头
  &-head {
    width: 100%;
    height: $table-header-height;
    color: $table-header-color;
    background-color: $table-header-bg;
    font-size: $table-header-font-size;

    tr {
      height: $table-header-height;
    }

    // 表头元素
    &-item {
      text-align: left;
      font-weight: $table-header-weight;

      &.center {
        text-align: center;
        padding-left: 0 !important;
      }

      // 带筛选
      &.with-search {
        vertical-align: top;
        padding-top: 8px;
        padding-bottom: 5px;
      }

      // 筛选
      &-search {
        &-wrap {
          margin-top: 2px;
        }
        &-input {
          width: 100%;
        }
      }
    }
    // 表头排序
    &-sort {
      display: inline-flex;
      align-items: center;
      &-button {
        display: inline-flex;
        flex-direction: column;
        align-items: center;
      }
      &-icon {
        // 为了扩展可点击区域
        width: 13px;
        height: 8px;
        padding: 0 2px;
        fill: $table-header-sort-bg;
        margin-left: 2px;
        cursor: pointer;

        &.asc {
          margin-bottom: 2px;
          // margin-bottom: -1px;
        }
        &.desc {
          transform: rotate(180deg);
        }
        &.table-active {
          fill: $table-header-sort-active-bg;
        }
        &:hover {
          fill: $table-header-sort-hover-bg;
        }
      }
    }
  }

  &-select-check {
    vertical-align: middle;
  }

  &-header-wrap {
    background-color: $table-header-bg;
  }

  // 表格行
  &-body-row {
    width: 100%;
    height: 40px;
    color: $text-color;

    > td {
      text-align: center;
    }

    &.active {
      background-color: $table-row-selected-bg;
      border-left: $table-row-selected-before;
    }
    &.show-expand {
      background-color: $table-row-has-expand-bg;
    }

    &.clickable {
      cursor: pointer;
    }

    .operations-wrap {
      a {
        display: inline-block;
        padding: 0 10px;
        border-right: 1px solid #e0e2e1;

        &:last-child {
          border-right: none;
        }
      }
    }

    &.has-expand {
      cursor: pointer;

      &.disabled {
        cursor: not-allowed;
      }
    }
    .table-body-has-child-icon {
      cursor: pointer;
      margin-top: 2px;
      width: 16px;
      height: 16px;
      margin-right: 10px;
      vertical-align: top;
    }
  }
  &-body-expand-row {
    background-color: $table-row-expand-bg;

    // 展开图标
    &-icon {
      width: 10px;
      height: 10px;
      fill: $table-row-has-expand-icon-color;
      transition: transform 0.2s;
      vertical-align: middle;

      &.expand {
        transform: rotate(90deg);
      }
    }

    &-wrap {
      position: relative;
      // padding: 10px;

      &::before {
        z-index: 1;
        content: '';
        display: block;
        width: 100%;
        height: 8px;
        position: absolute;
        left: 0;
        top: 0;
        opacity: 0.3;
        background-image: linear-gradient(
          -180deg,
          rgba(34, 44, 67, 0.4),
          rgba(34, 44, 67, 0)
        );
      }
      .table {
        border: none;
      }
    }
  }

  // 每列元素
  &-row-item {
    // 带有限制标识
    &.limit {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    &-empty-label {
      color: $text-color-shallow;
    }
  }

  // 带footer
  &-with-footer {
    position: relative;
    >.table{
      margin-bottom: 0;
    }
    &-select {
      box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.2);
      background-color: $white;
      padding: $padding-md;
      display: flex;
      align-items: center;
      color: $text-color-secondary;
      border-top: 1px solid $border-color-base;
      &-info {
        font-size: $font-size-sm;
      }
      &-content {
        margin-left: auto;
      }

      &-exit-btn {
        margin-left: $margin-md;
      }
    }
    &-sticky{
      position: sticky;
      bottom: 0;
    }
  }
  // 带边框样式
  &.border {
    border: 1px solid $table-border-color;

    &,
    & > .#{$table-prefix}-header-wrap > table {
      & > .#{$table-prefix}-head {
        border-bottom: 1px solid $table-border-color;

        .#{$table-prefix}-head-item {
          border-right: 1px solid $table-border-color;
          position: relative;

          &.expand,
          &.with-select {
            border-right: none;
          }

          &:last-child[colspan] {
            border-right: none;
          }
          &[rowspan='1'] {
            border-bottom: 1px solid $table-border-color;
          }
        }
      }
    }

    &,
    & > .#{$table-prefix}-body-wrap > table {
      & > .#{$table-prefix}-body {
        border-bottom: none;
        & > .#{$table-prefix}-body-row,
        & > .#{$table-prefix}-body-expand-row {
          border-bottom: 1px solid $table-border-color;

          &:last-child {
            border-bottom: none;
          }
        }
      }
    }

    // .#{$table-prefix}-body-row {
    //   &:last-child,
    //   &:last-of-type {
    //     border-bottom: none;
    //   }
    // }
    & > .#{$table-prefix}-body-wrap > table {
      & > .#{$table-prefix}-body {
        border-bottom: none;
      }
    }
  }
  // 带背景样式，建议废弃，但是保留
  &.background {
    background-color: $table-has-bg;

    &.hover {
      .#{$table-prefix}-body-row:hover {
        background-color: $table-row-hover-color;
      }
    }
  }

  &.dark {
    border: none;

    & > .#{$table-prefix}-body {
      border-top: none;
    }

    &,
    & > .#{$table-prefix}-header-wrap > table {
      & > .#{$table-prefix}-head {
        background-color: $table-header-dark-bg;
        color: #ffffff;
        border-bottom: none;

        .#{$table-prefix}-head-item {
          border-right-color: $table-header-dark-border-color;
          border-bottom-color: $table-header-dark-border-color;

          &[rowspan='1'] {
            border-bottom: 1px solid $table-header-dark-border-color;
          }
        }

        .#{$table-prefix}-head-item-sort-icon {
          fill: $table-header-sort-dark-bg;

          &:hover,
          &.table-active {
            fill: $table-header-sort-hover-bg;
          }
        }

        .#{$table-prefix}-header-select-item {
          .drop-down-icon {
            border-color: #fff transparent transparent transparent;
          }
        }

        .Select-input {
          font-size: 12px;
        }
        .Select-placeholder {
          font-size: 12px;
        }
        // 下面的是老样式
        .table-header-select-item {
          .Select-control {
            background-color: $table-header-dark-bg;
            border-color: $table-header-dark-bg;
          }
          .is-open .Select-control {
            background-color: $table-head-active-color;
            border-color: $table-head-active-color;
            box-shadow: none;
          }
        }
      }
    }

    // 针对带边框的情况
    &.border {
      border-bottom: 1px solid $table-border-color;

      &,
      & > .#{$table-prefix}-body-wrap > table {
        & > .#{$table-prefix}-body {
          border: 1px solid $table-border-color;
          border-top: none;
          border-bottom: none;
        }
      }
    }
  }

  // 间断行样式
  &.striped {
    .#{$table-prefix}-body-row {
      &:nth-child(2n) {
        background-color: $table-row-striped-bg;
      }
      &:hover {
        background-color: $table-row-striped-hover-bg;
      }
    }

    &.hover {
      .#{$table-prefix}-body-row {
        &:hover {
          background-color: $table-row-striped-hover-bg;
        }
      }
    }
  }

  &.click {
    .#{$table-prefix}-body-row {
      cursor: pointer;
    }
  }
  &.hover {
    .#{$table-prefix}-body-row {
      a {
        color: $text-color;
      }
      &:hover {
        background-color: $table-row-hover-bg;
        a {
          text-decoration: underline;

          &:hover {
            color: $text-color-red;
          }

          &.blue {
            text-decoration: none;
            color: $text-color-blue;
          }
          &.red {
            text-decoration: none;
            color: $text-color-red;
          }
          &.disabled {
            cursor: not-allowed;
            text-decoration: none;
            color: $text-color-gray;
          }
        }
      }
      &.show-expand {
        background-color: $table-row-has-expand-bg;
      }
    }
  }
}

.table-show-more {
  cursor: pointer;
}
.table-sort-button {
  display: inline-block;
  vertical-align: top;
  margin-left: 5px;
  .topTriangle {
    margin-bottom: 2px;
  }
}
.table-body-wrap {
  overflow-y: scroll;

  @include scrollbar();
}

.table-header-select-item {
  display: flex;
  white-space: nowrap;
  align-items: center;
  padding-left: 10px;

  &.focus {
    background-color: $table-head-active-color;
  }
  .select {
    border: none !important;
    box-shadow: none !important;

    .drop-down-icon {
      stroke: #fff;
    }
    .Select-input {
      line-height: 30px;
    }
  }

  .select-single-value {
    font-weight: normal;
  }
}
