@import "mixins/mixins";
@import "common/var";

@include b(table) {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  flex: 1;
  width: 100%;
  max-width: 100%;
  background-color: $--color-white;
  font-size: 14px;
  color: $--color-text-content;

  @include e(empty-block) {
    min-height: 60px;
    text-align: center;
    width: 100%;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    padding: 28px 0;
  }

  @include e(empty-text) {
    line-height: 20px;
    width: 50%;
    color: $--color-text-auxiliary;
  }

  // 展开行
  @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 0.2s ease-in-out;
    height: 20px;

    @include m(expanded) {
      transform: rotate(90deg);
    }

    > .xb-icon {
      position: absolute;
      left: 50%;
      top: 50%;
      margin-left: -5px;
      margin-top: -5px;
    }
  }

  @include e(expanded-cell) {
    background-color: $--color-white;

    // 纯属为了增加权重
    &[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 m(fit) {
    border-right: 0;
    border-bottom: 0;

    th.gutter, td.gutter {
      border-right-width: 1px;
    }
  }

  @include m(scrollable-x) {
    .xb-table__body-wrapper {
      overflow-x: auto;
    }
  }

  @include m(scrollable-y) {
    .xb-table__body-wrapper {
      overflow-y: auto;
      z-index: 1;
    }
    .xb-table__header-wrapper{
      box-shadow:0px 6px 10px -2px rgba(85,85,85,0.16);
      position: relative;
      z-index: 2;
    }
    .xb-table__fixed,.xb-table__fixed-right{
      z-index: 3;
    }
    .xb-table__body-wrapper, .xb-table__fixed,  .xb-table__fixed-right{
      .xb-table__body{
        tbody tr:first-child{
          td{
            border-top: 1px solid rgba(255,255,255,0);
          }
        }
      }
    }
    .is-scrolling-left + .xb-table__fixed{
      .xb-table__fixed-header-wrapper{
        box-shadow:0px 6px 10px -2px rgba(85,85,85,0.16);
        position: relative;
        z-index: 4;
      }
    }
    .is-scrolling-right + .xb-table__fixed-right, .is-scrolling-right + .xb-table__fixed + .xb-table__fixed-right{
      .xb-table__fixed-header-wrapper{
        box-shadow:0px 6px 10px -2px rgba(85,85,85,0.16);
        position: relative;
        z-index: 4;
      }
    }
  }

  thead {
    color: $--color-text-title;
    font-weight: $--font-weight-base;
  }

  tr {
    background-color: $--color-white;

    input[type="checkbox"] {
      margin: 0;
    }
    &.success-row{
      background-color:$--table-success-row-bg-color;
    }
    &.danger-row{
      background-color:$--table-danger-row-bg-color;
    }
  }

  th, td {
    min-width: 0;
    box-sizing: border-box;
    text-overflow: ellipsis;
    vertical-align: middle;
    position: relative;
    text-align: left;
    overflow: hidden;

    &.gutter {
      width: 15px;
      border-right-width: 0;
      border-bottom-width: 0;
      padding: 0;
    }

    &.is-hidden {
      > * {
        visibility: hidden;
      }
    }
  }

  th{
    padding: 12.5px 0;
    font-size: $--font-size-base + 2px;
    font-weight: $--font-weight-base;
    overflow: hidden;
    user-select: none;
    background-color: $--table-th-bg-color;
    line-height: 23px;
    div{
      font-weight: $--font-weight-base;
    }

    > .cell {
      display: inline-block;
      box-sizing: border-box;
      position: relative;
      vertical-align: middle;
      width: 100%;

      &.highlight {
        color: $--color-text-title;
      }
    }
    &.required > div::before {
      display: inline-block;
      content: "";
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #ff4d51;
      margin-right: 5px;
      vertical-align: middle;
    }
  }
  

  td {
    padding: 6px 0;
    border-top: $--table-border;
    div {
      box-sizing: border-box;
    }

    @include when(center) {
      text-align: center;
    }

    @include when(right) {
      text-align: right;
    }

    &.gutter {
      width: 0;
    }
    .cell{
      line-height: 35px;
      height: 35px;
    }
  }

  @include m(big) {
    font-size:$--font-size-base;
    th {
      padding: 16.5px 0;
    }
    td .cell{
      line-height: 43px;
      height: 43px;
    }
  }
  @include m(medium) {
    font-size:$--font-size-base;
    th {
      padding: 12.5px 0;
    }
    td .cell{
      line-height: 35px;
      height: 35px;
    }
  }
  @include m(small) {
    font-size: $--font-size-base - 2px;
    th{
      padding: 8.5px 0;
      font-size: $--font-size-base;
      i{
        font-size: 14px;
      }
    }
    td .cell{
      line-height: 27px;
      height: 27px;
    }
  }

  th.is-sortable {
    cursor: pointer;
  }

  .cell {
    text-overflow: ellipsis;
    white-space: normal;
    word-break: break-all;
    line-height: 23px;
    height: 23px;
    padding-left: 20px;
    padding-right: 20px;
    white-space: nowrap;

    &.xb-tooltip {
      white-space: nowrap;
      min-width: 50px;
    }
  }

  // 表格底部伪 border，总是有的
  &::before {
    // @include extend-rule(border-pseudo);
    left: 0;
    bottom: 0;
    width: 100%;
    height: 1px;
  }

  // table--border
  @include m(border) {
    border:$--table-border;

    &.xb-loading-parent--relative {
      border-color: transparent;
    }

    th, td {
      border-left: $--table-border;
      &:first-child{
        border-left: 0;
        .cell {
          padding-left: 10px;
        }
      }
    }

    th.gutter:last-of-type {
      border-bottom: $--table-border;
    }

    & th {
      &:last-child{
        border-left: 0;
      }
    }
  }

  @include m(hidden) {
    visibility: hidden;
  }

  @include e((fixed, fixed-right)) {
    position: absolute;
    top: 0;
    left: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    background: $--color-white;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 0;
      background-color: $--color-white;
      z-index: 4;
    }
  }

  @include e(fixed-right-patch) {
    position: absolute;
    top: -1px;
    right: 0;
    background-color: $--table-th-bg-color;
    border-bottom: $--table-border;
  }

  @include e(fixed) {
    box-shadow: 4px 0px 12px 0px rgba(157,157,157,0.16);
  }

  @include e(fixed-right) {
    top: 0;
    left: auto;
    right: 0;
    box-shadow: 4px -12px 10px 10px rgba(157,157,157,0.16);

    .xb-table__fixed-header-wrapper,
    .xb-table__fixed-body-wrapper,
    .xb-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: $--color-white;
      color: $--color-text-content;
    }
  }

  @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-th-bg-color;
      color: $--color-text-title;
    }
  }

  @include e(body-wrapper) {
    overflow: hidden;
    position: relative;

    @include when(scrolling-none) {
      ~ .xb-table__fixed,
      ~ .xb-table__fixed-right {
        box-shadow: none;
      }
    }

    @include when(scrolling-left) {
      ~ .xb-table__fixed {
        box-shadow: none;
      }
    }

    @include when(scrolling-right) {
      ~ .xb-table__fixed-right {
        box-shadow: none;
      }
    }

    .xb-table--border {
      @include when(scrolling-right) {
        ~ .xb-table__fixed-right {
          border-left: $--table-border;
        }
      }

      @include when(scrolling-left) {
        ~ .xb-table__fixed {
          border-right: $--table-border;
        }
      }
    }
  }

  .caret-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    height: 20.5px;
    width: 24px;
    vertical-align: middle;
    cursor: pointer;
    overflow: initial;
    position: relative;
  }

  .sort-caret {
    width: 0;
    height: 0;
    border: solid 5px transparent;
    position: absolute;
    left: 7px;

    &.ascending {
      border-bottom-color: $--table-sort-caret-color;
      top: -2px;
    }

    &.descending {
      border-top-color: $--table-sort-caret-color;
      bottom: 0px;
    }
  }

  .ascending .sort-caret.ascending {
    border-bottom-color: $--table-sort-caret-color;
  }

  .descending .sort-caret.descending {
    border-top-color: $--table-sort-caret-color;
  }

  .hidden-columns {
    visibility: hidden;
    position: absolute;
    z-index: -1;
  }

  @include m(striped) {
    & .xb-table__body {
      & tr.xb-table__row--striped {
        td {
          background: $--color-bg-ckb;
        }

        &.current-row td {
          background-color: $--table-hover-bg-color;
        }
      }
    }
  }

  @include e(body) {
    tr.hover-row {
      &, &.xb-table__row--striped {
        &, &.current-row {
          > td {
            background-color: $--table-hover-bg-color;
          }
        }
      }
    }

    tr.current-row > td {
      background-color: $--table-hover-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;
    line-height: 23px;
    cursor: pointer;

    & i {
      color: $--color-text-auxiliary;
      font-size: 17px;
      transform: scale(1);
      vertical-align: text-bottom;
      padding-left: 7px;
    }
  }

  @include m(enable-row-transition) {
    .xb-table__body td {
      transition: background-color .25s ease;
    }
  }

  @include m(enable-row-hover) {
    .xb-table__body tr:hover > td {
      background-color: $--table-hover-bg-color;
    }
  }

  @include m(fluid-height) {
    .xb-table__fixed,
    .xb-table__fixed-right {
      bottom: 0;
      overflow: hidden;
    }
  }

  [class*=xb-table__row--level] {
    .xb-table__expand-icon {
      display: inline-block;
      width: 20px;
      line-height: 20px;
      height: 20px;
      text-align: center;
      margin-right: 3px;
    }
  }

  .xb-table__body-wrapper::-webkit-scrollbar{
    width: 7px;
    height: 7px;
    background-color: #FFFFFF;
  }
  .xb-table__body-wrapper::-webkit-scrollbar-thumb{
    border-radius: 100px;
    height: 80%;
    width: 85%;
    background: #DDDDDD;
  }
  .xb-table__body-wrapper::-webkit-scrollbar-track{
    // box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    border-radius: 3.5px;
    background: #FFFFFF;
  }

  .xb-dropdown{
    .xb-button{
      margin-right: 5px;
    }
  }
}
