@import "mixins/mixins";
@import "checkbox";
@import "tag";
@import "tooltip";
@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: $--table-font-color;
  .el-table__column-drag{
    position: absolute;
    right: 0;
    height: 100%;
    padding-left: 4px;
    i{
      display: block;
      width: 1px;
      height: 100%;
      background:linear-gradient(180deg,rgba(238,238,238,0.4) 0%,rgba(189,189,189,0.86) 52%,rgba(216,216,216,0.4) 100%);
    }
    &.is-drag{
      cursor: col-resize;
    }
    
  }
  // 表格中按钮优化
  .el-button{
    padding-top: 4px;
    padding-bottom: 4px;
    i{
      font-size: 14px;
    }
  }

  .el-table__scrollbar{
    .el-scrollbar__bar{
      z-index: 999;
    }
  }

  // 数据为空
  @include e(empty-block) {
    min-height: 60px;
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    @include when(empty) {
      position: absolute;
      top: 0;
      opacity: 1;
    }
  }

  @include e(empty-text) {
    // min-height doesn't work in IE10 and IE11 https://github.com/philipwalton/flexbugs#3-min-height-on-a-flex-container-wont-apply-to-its-flex-items
    // set empty text line height up to contrainer min-height as workaround.
    line-height: 60px;
    width: 50%;
    color: $--color-text-primary;
  }

  // 展开行
  @include e(expand-column) {
    .cell {
      padding: 0;
      text-align: center;
    }
  }

  @include e(expand-icon) {
    position: relative;
    cursor: pointer;
    color: $--icon-color;
    font-size: 12px;
    transition: transform 0.2s ease-in-out;
    height: 20px;

    @include m(expanded) {
      transform: rotate(90deg);
    }

    > .el-icon {
      position: absolute;
      left: 50%;
      top: 50%;
      margin-left: -5px;
      margin-top: -5px;
    }
  }

  @include e(expanded-cell) {
    background-color: $--color-white;

    // 纯属为了增加权重
    &[class*=cell] {
      padding: 10px;
    }

    &:hover {
      background-color: transparent !important;
    }
  }

  @include e(placeholder) {
    display: inline-block;
    width: 20px;
  }

  @include e(append-wrapper) {
    // 避免外边距重合 https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing
    overflow: hidden;
  }

  @include m(fit) {
    border-right: 0;
    border-bottom: 0;

    th.gutter, td.gutter {
      border-right-width: 1px;
    }
  }

  @include m(scrollable-x) {
    .el-table__body-wrapper {
      overflow-x: auto;
    }
  }

  @include m(scrollable-y) {
    .el-table__body-wrapper {
      overflow-y: auto;
    }
  }

  thead {
    color: $--table-header-font-color;
    font-weight: $--font-weight-primary;

    &.is-group {
      th {
        background: $--background-color-base;
      }
    }
  }

  th.el-table__column, td.el-table__column {
    padding: 8px 0;
    min-width: 0;
    box-sizing: border-box;
    text-overflow: ellipsis;
    vertical-align: middle;
    position: relative;
    text-align: left;

    @include when(center) {
      text-align: center;
    }

    @include when(right) {
      text-align: right;
    }

    &.gutter {
      width: 15px;
      border-right-width: 0;
      border-bottom-width: 0;
      padding: 0;
    }

    &.is-hidden {
      > * {
        visibility: hidden;
      }
    }

    &.el-table__column-fixed-left,
    &.el-table__column-fixed-right{
      position: sticky;
      z-index: 2;
    }
  }

  @include m(medium) {
    th.el-table__column, td.el-table__column {
      padding: 6px 0;
    }
  }

  @include m(small) {
    font-size: 12px;
    th.el-table__column, td.el-table__column {
      padding: 4px 0;
    }
  }

  @include m(mini) {
    font-size: 12px;
    th.el-table__column, td.el-table__column {
      padding: 2px 0;
    }
  }
  
  tr {
    background-color: $--color-white;
    input[type="checkbox"] {
      margin: 0;
    }
  }

  th.is-leaf, td.el-table__expanded-cell, td.el-table__column {
    border-bottom: $--table-border;
  }

  th.is-sortable {
    cursor: pointer;
  }

  th.el-table__column {
    white-space: nowrap;
    overflow: hidden;
    user-select: none;
    background-color: $--table-header-background-color;
    font-weight: $--font-weight-strengthen;
    color: $--color-text-primary;
    > div {
      display: table-cell;
      padding-left: 10px;
      padding-right: 10px;
      box-sizing: border-box;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    > .cell {
      display: inline-block;
      box-sizing: border-box;
      position: relative;
      vertical-align: middle;
      padding-left: 10px;
      padding-right: 10px;
      width: 100%;

      &.highlight {
        color: $--color-primary;
      }
    }

    &.required > div::before {
      display: inline-block;
      content: "";
      width: 8px;
      height: 8px;
      border-radius: $--border-radius-semi-circle;
      background: $--color-danger;
      margin-right: 5px;
      vertical-align: middle;
    }
  }

  td.el-table__column {
    &.el-table__column-fixed-left,
    &.el-table__column-fixed-right{
      background-color: #fff;
    }
    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;

    &.el-tooltip__cell {
      white-space: nowrap;
      min-width: 50px;
      width: 100%;
    }
  }

  td.el-table-column--selection,
  th.el-table-column--selection{
    > .cell{
      padding: 0;
    }
  }

  // 拥有多级表头
  @include m((group, border)) {
    border: $--table-border;

    .is-drag{
      visibility: hidden;
    }

    @include share-rule(border-pseudo) {
      content: '';
      position: absolute;
      background-color: $--table-border-color;
      z-index: 4;
    }

    // 表格右部伪 border
    &::after {
      @include extend-rule(border-pseudo);
      top: 0;
      right: 0;
      width: 1px;
      height: 100%;
    }
  }

  // 表格底部伪 border，总是有的
  &::before {
    @include extend-rule(border-pseudo);
    left: 0;
    bottom: 0;
    width: 100%;
    height: 1px;
  }

  // table--border
  @include m(border) {
    border-right: none;
    border-bottom: none;

    &.el-loading-parent--relative {
      border-color: transparent;
    }

    th.el-table__column.el-table--border__cell, 
    td.el-table__column.el-table--border__cell {
      border-right: $--table-border;

      &:first-child:not(.el-table-column--selection) .cell {
        padding-left: 10px;
      }
    }

    .el-table__header-wrapper th.gutter:last-of-type {
      border-bottom: $--table-border;
      background-color: $--table-header-background-color;
    }

    .el-table__footer-wrapper th.gutter:last-of-type {
      border-top: $--table-border;
      background-color: $--table-header-background-color;
    }
    .el-table__footer-wrapper {
      td.el-table__column-fixed-left,
      td.el-table__column-fixed-right{
        background-color: $--table-header-background-color;
      }
    }
    

    & th.el-table__column {
      border-bottom: $--table-border;
    }
    .el-table__fixed-right {
      border-left: $--table-border;
    }
  }

  @include m(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;
    will-change: auto;

    &::before {
      display: none;
      content: '';
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1px;
      background-color: $--border-color-base;
      z-index: 4;
    }
  }

  @include e(fixed-right-patch) {
    position: absolute;
    top: -1px;
    right: 0;
    border-bottom: $--table-border;
  }

  @include e(fixed-right) {
    top: 0;
    left: auto;
    right: 0;

    .el-table__fixed-header-wrapper,
    .el-table__fixed-body-wrapper,
    .el-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.el-table__column {
      border-top: $--table-border;
      background-color: $--table-header-background-color;
      color: $--table-font-color;
    }

    tfoot{
      tr{
        .el-table__column {
          border-top: $--table-border;
          border-bottom: none;
        }
      }
    }

    tbody ~ tfoot{
      tr:first-child{
        .el-table__column {
          border-top: none;
        }
      }
      tr + tr{
        .el-table__column {
          border-top: $--table-border;
        }
      }
    }
  }

  @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.el-table__column {
      border-top: $--table-border;
    }
    tfoot{
      tr{
        .el-table__column {
          border-top: $--table-border;
          border-bottom: none;
        }
      }
    }
    tbody ~ tfoot{
      tr:first-child{
        .el-table__column {
          border-top: none;
        }
      }
      tr + tr{
        .el-table__column {
          border-top: $--table-border;
        }
      }
    }
  }

  @include e((header, body, footer)) {
    table-layout: fixed;
    border-collapse: separate;
    will-change: auto;
  }

  @include e((header-wrapper, footer-wrapper)) {
    overflow: hidden;

    & tbody td.el-table__column {
      background-color: $--table-header-background-color;
      color: $--table-font-color;
    }
  }

  @include e(body-wrapper) {
    overflow: hidden;
    position: relative;

    @include when(scrolling-none) {
      ~ .el-table__fixed,
      ~ .el-table__fixed-right {
        box-shadow: none;
      }
    }

    @include when(scrolling-left) {
      ~ .el-table__fixed {
        box-shadow: none;
      }
    }

    @include when(scrolling-right) {
      ~ .el-table__fixed-right {
        box-shadow: none;
      }
    }
  }

  // 粘性固定列样式
  @include when(scrolling-left) {
    td.el-table__column-fixed-right-first,
    th.el-table__column-fixed-right-first {
      box-shadow: -3px 5px 10px rgba(0, 0, 0, 0.12);
    }
  }

  @include when(scrolling-middle) {
    td.el-table__column-fixed-right-first,
    th.el-table__column-fixed-right-first {
      box-shadow: -3px 5px 10px rgba(0, 0, 0, 0.12);
    }

    td.el-table__column-fixed-left-last,
    th.el-table__column-fixed-left-last {
      box-shadow: 3px 5px 10px rgba(0, 0, 0, 0.12);
    }
  }

  @include when(scrolling-right) {
    td.el-table__column-fixed-left-last,
    th.el-table__column-fixed-left-last {
      box-shadow: 3px 5px 10px rgba(0, 0, 0, 0.12);
    }
  }

  .caret-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    height: 21px;
    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: $--color-text-placeholder;
      top: -2px;
    }

    &.descending {
      border-top-color: $--color-text-placeholder;
      bottom: 1px;
    }
  }

  .ascending .sort-caret.ascending {
    border-bottom-color: $--color-primary;
  }

  .descending .sort-caret.descending {
    border-top-color: $--color-primary;
  }

  .hidden-columns {
    visibility: hidden;
    position: absolute;
    z-index: -1;
  }

  @include m(striped) {
    & .el-table__body {
      & tr.el-table__row--striped {
        td {
          background: $--table-row-striped-background-color;
        }
        td.el-table__column {
          &.el-table__cell-row-hover, &.el-table__cell-column-hover {
            background-color: $--table-row-hover-background-color;
          }
        }
        &.current-row td.el-table__column, &.selection-row td.el-table__column{
          background-color: $--table-current-row-background-color;
        }
      }
    }
  }

  @include e(body) {
    // tr.hover-row {
    //   &, &.el-table__row--striped {
    //     &, &.current-row, &.selection-row {
    //       > td.el-table__column {
    //         background-color: $--table-row-hover-background-color;
    //       }
    //     }
    //   }
    // }

    tr.current-row > td.el-table__column, tr.selection-row > td.el-table__column {
      background-color: $--table-current-row-background-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: 21px;
    cursor: pointer;
    margin-left: 5px;
    & i {
      color: $--color-info;
      font-size: 15px;
    }
  }

  @include m(enable-row-transition) {
    .el-table__body td.el-table__column {
      transition: background-color .25s ease;
    }
  }

  @include m(enable-row-hover) {
    td.el-table__column {
      &.el-table__cell-row-hover, &.el-table__cell-column-hover {
        background-color: $--table-row-hover-background-color;
      }
    }
  }

  td.el-table__column {
    &.el-table__cell-column-hover {
      background-color: $--table-row-hover-background-color;
    }
  }

  @include m(fluid-height) {
    .el-table__fixed,
    .el-table__fixed-right {
      bottom: 0;
      overflow: hidden;
    }
  }

  [class*=el-table__row--level] {
    .el-table__expand-icon {
      display: inline-block;
      width: 20px;
      line-height: 20px;
      height: 20px;
      text-align: center;
      margin-right: 3px;
    }
  }

  @include m(card) {
    background-color: transparent;
    &.el-table{
      @include m(medium) {
        th.el-table__column.el-table--card__cell, 
        td.el-table__column.el-table--card__cell {
          padding: 5px 0;
        }
      }
    
      @include m(small) {
        th.el-table__column.el-table--card__cell, 
        td.el-table__column.el-table--card__cell {
          padding: 3px 0;
        }
      }
    
      @include m(mini) {
        th.el-table__column.el-table--card__cell, 
        td.el-table__column.el-table--card__cell {
          padding: 1px 0;
        }
      }
      td.el-table__column.el-table--card__cell,
      th.el-table__column.el-table--card__cell,
      td.el-table__expanded-cell{
        border-bottom: none;
        background-color: transparent;
      }
      td.el-table__expanded-cell{
        padding: 0 10px;
      }
      &::before{
        display: none;
      }
      th.el-table__column.el-table--card__cell{
        color: $--table-font-color;
      }
    }
    .el-table__header.el-table__header-card,
    .el-table__footer.el-table__footer-card{
      // border-right: $--table-border;
      border-radius:0 2px 2px 0;
      &.el-table__header-gutter{
        border-right: none;
      }
      th.el-table__column.el-table--card__cell,
      td.el-table__column.el-table--card__cell{
        background-color: $--color-white;
        border-top:$--table-border;
        border-bottom:$--table-border;
      }
      th.el-table__column.el-table--card__cell:first-child{
        border-left: $--table-border;
        border-radius:2px 0px 0px 2px;
        padding-left: 3px;
      }
      td.el-table__column.el-table--card__cell:first-child{
        border-left: $--table-border;
        border-radius:2px 0px 0px 2px;
      }
      th.el-table__column.el-table--card__cell:last-child,
      td.el-table__column.el-table--card__cell:last-child{
        border-right: $--table-border;
        border-radius:0 2px 2px 0;
      }
    }
    // &.el-table--enable-row-hover {
    //   .el-table__body tr:hover {
    //     td.el-table__column{
    //       background-color: $--color-white;
    //       border-color: $--color-primary-light-5;
    //     }
    //     td.el-table__column:first-child,td.el-table__column:last-child{
    //       border-color: $--color-primary-light-5;
    //     }
    //   }
    // }
    .el-table__body-wrapper,
    .el-table__fixed-body-wrapper{
      table.el-table__body-card{
        border-collapse:separate;
        border-spacing:0px 10px;
      }
      td.el-table__column.el-table--card__cell,
      th.el-table__column.el-table--card__cell{
        border-spacing:0px 10px;
      }
      .el-table__row{
        td.el-table__column.el-table--card__cell{
          background-color: $--color-white;
          border-top:$--table-border;
          border-bottom:$--table-border;
        }
        td.el-table__column.el-table--card__cell:first-child{
          border-left: $--table-border;
          border-radius: 2px 0px 0px 2px;
          padding-left: 3px;
          border-left: 4px solid $--color-primary-light-5;
        }
        td.el-table__column.el-table--card__cell:last-child{
          border-right:$--table-border;
          border-radius:0 2px 2px 0;
        }
        td.el-table__column.el-table--card__cell.el-table__cell-row-hover{
          background-color: $--color-white;
          border-color: $--color-primary-light-5;
        }
        td.el-table__column.el-table--card__cell.el-table__cell-row-hover:first-child,
        td.el-table__column.el-table--card__cell.el-table__cell-row-hover:last-child{
          border-color: $--color-primary-light-5;
        }
        &.current-row, &.selection-row{
          td.el-table__column.el-table--card__cell,td.el-table__column.el-table--card__cell.el-table__cell-row-hover{
            background-color: $--table-current-row-background-color;
            border-color: $--color-primary;
          }
        }
      }
      // 左侧固定列最后一个单元格不要右边线
      .el-table__fixed-left{
        td.el-table__column.el-table--card__cell:last-child{
          border-right:none;
          border-radius:0;
        }
      }
      .el-table__fixed-right{
        td.el-table__column.el-table--card__cell:first-child{
          border-left:none;
          border-radius:0;
        }
      }
      tr{
        background-color: transparent;
      }
      tr[class*="el-table__row--level"]:not(.el-table__row--level_0){
        td.el-table__column.el-table--card__cell.el-table__cell-row-hover:first-child,
        td.el-table__column.el-table--card__cell.el-table__cell-row-hover:last-child{
          border-color: $--border-color-base;
        }
      }
      tr[class*="el-table__row--level"]:not(.el-table__row--level_0){
        &:hover{
          td.el-table__column.el-table--card__cell{
            border-color: $--border-color-base;
          }
        }
        td.el-table__column.el-table--card__cell{
          background-color: $--color-white;
          border: none;
          padding: 0;
          .cell::before{
            display: none;
          }
        }
      }
      tr[class*="el-table__row--level"] + tr[class*="el-table__row--level"]{
        td.el-table__column.el-table--card__cell{
          padding-top: 10px;
          border-top: 1px solid $--border-color-base;
        }
      }
      tr.el-table__row--level_0+ tr[class*="el-table__row--level"]{
        td.el-table__column.el-table--card__cell{
          padding-top: 0;
          border-top:none;
        }
      }
    }
    .el-table__fixed-header-wrapper{
      th.el-table__column:last-child{
        // border-right: none;
        // border-radius: 0;
      }
    }
    .cell{
      line-height: 24px;
    }
  }
}

.table-tooltip{
  .el-tooltip__content{
    max-width: 800px;
  }
}