@use 'mixins/mixins' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

@include b(table) {
  @include set-component-css-var('table', $table);
}

@include b(table) {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  height: fit-content;
  width: 100%;
  max-width: 100%;
  background-color: var(--el-table-bg-color);
  font-size: 14px;
  color: var(--el-table-text-color);

  // when data is empty
  @include e(empty-block) {
    min-height: 60px;
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  @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: var(--el-text-color-secondary);
  }

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

  @include e(expand-icon) {
    position: relative;
    cursor: pointer;
    color: var(--el-text-color-regular);
    font-size: 12px;
    transition: transform var(--el-transition-duration-fast) ease-in-out;
    height: 20px;

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

    > .#{$namespace}-icon {
      font-size: 12px;
    }
  }

  @include e(expanded-cell) {
    background-color: var(--el-table-expanded-cell-bg-color);

    // increase the weight purely
    &[class*='cell'] {
      padding: 20px 50px;
    }

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

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

  @include e(append-wrapper) {
    // avoid overlapping margin 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;

    .#{$namespace}-table__cell.gutter {
      border-right-width: 1px;
    }
  }

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

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

  thead {
    color: var(--el-table-header-text-color);
    font-weight: 500;

    &.is-group {
      th.#{$namespace}-table__cell {
        background: var(--el-bg-color-base);
      }
    }
  }

  .#{$namespace}-table__cell {
    padding: 12px 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;
      }
    }
  }

  @include m(medium) {
    .#{$namespace}-table__cell {
      padding: 10px 0;
    }
  }

  @include m(small) {
    font-size: 12px;
    .#{$namespace}-table__cell {
      padding: 8px 0;
    }
  }

  tr {
    background-color: var(--el-table-tr-bg-color);

    input[type='checkbox'] {
      margin: 0;
    }
  }

  th.#{$namespace}-table__cell.is-leaf,
  td.#{$namespace}-table__cell {
    border-bottom: var(--el-table-border);
  }

  th.#{$namespace}-table__cell.is-sortable {
    cursor: pointer;
  }

  th.#{$namespace}-table__cell {
    overflow: hidden;
    user-select: none;
    background-color: var(--el-table-header-bg-color);

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

      &.highlight {
        color: var(--el-color-primary);
      }
    }

    &.required > div::before {
      display: inline-block;
      content: '';
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #ff4d51;
      margin-right: 5px;
      vertical-align: middle;
    }
  }

  td.#{$namespace}-table__cell {
    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;

    &.#{$namespace}-tooltip {
      white-space: nowrap;
      min-width: 50px;
    }
  }

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

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

    // 表格右部伪 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;

    // fix: #1013
    // &.#{$namespace}-loading-parent--relative {
    //   border-color: transparent;
    // }

    .#{$namespace}-table__cell {
      border-right: var(--el-table-border);

      &:first-child .cell {
        padding-left: 10px;
      }
    }

    th.#{$namespace}-table__cell.gutter:last-of-type {
      border-bottom: var(--el-table-border);
      border-bottom-width: 1px;
    }

    & th.#{$namespace}-table__cell {
      border-bottom: var(--el-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: var(--el-table-fixed-box-shadow);

    &::before {
      content: '';
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1px;
      background-color: var(--el-border-color-light);
      z-index: 4;
    }
  }

  @include e(fixed-right-patch) {
    position: absolute;
    top: -1px;
    right: 0;
    background-color: var(--el-table-header-bg-color);
    border-bottom: var(--el-table-border);
  }

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

    .#{$namespace}-table__fixed-header-wrapper,
    .#{$namespace}-table__fixed-body-wrapper,
    .#{$namespace}-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.#{$namespace}-table__cell {
      border-top: var(--el-table-border);
      background-color: var(--el-table-row-hover-bg-color);
      color: var(--el-table-text-color);
    }
  }

  @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.#{$namespace}-table__cell {
      border-top: var(--el-table-border);
    }
  }

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

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

    & tbody td.#{$namespace}-table__cell {
      background-color: var(--el-table-row-hover-bg-color);
      color: var(--el-table-text-color);
    }
  }

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

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

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

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

    .#{$namespace}-table--border {
      @include when(scrolling-right) {
        ~ .#{$namespace}-table__fixed-right {
          border-left: var(--el-table-border);
        }
      }

      @include when(scrolling-left) {
        ~ .#{$namespace}-table__fixed {
          border-right: var(--el-table-border);
        }
      }
    }
  }

  .caret-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    height: 14px;
    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: var(--el-text-color-placeholder);
      top: -5px;
    }

    &.descending {
      border-top-color: var(--el-text-color-placeholder);
      bottom: -3px;
    }
  }

  .ascending .sort-caret.ascending {
    border-bottom-color: var(--el-color-primary);
  }

  .descending .sort-caret.descending {
    border-top-color: var(--el-color-primary);
  }

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

  @include m(striped) {
    & .#{$namespace}-table__body {
      & tr.#{$namespace}-table__row--striped {
        td.#{$namespace}-table__cell {
          background: #fafafa;
        }

        &.current-row td.#{$namespace}-table__cell {
          background-color: var(--el-table-current-row-bg-color);
        }
      }
    }
  }

  @include e(body) {
    tr.hover-row {
      &,
      &.#{$namespace}-table__row--striped {
        &,
        &.current-row {
          > td.#{$namespace}-table__cell {
            background-color: var(--el-table-row-hover-bg-color);
          }
        }
      }
    }

    tr.current-row > td.#{$namespace}-table__cell {
      background-color: var(--el-table-current-row-bg-color);
    }
  }

  @include e(column-resize-proxy) {
    position: absolute;
    left: 200px;
    top: 0;
    bottom: 0;
    width: 0;
    border-left: var(--el-table-border);
    z-index: 10;
  }

  @include e(column-filter-trigger) {
    display: inline-block;
    cursor: pointer;

    & i {
      color: var(--el-text-color-secondary);
      font-size: 12px;
      vertical-align: middle;
      transform: scale(0.75);
    }
  }

  @include m(enable-row-transition) {
    .#{$namespace}-table__body td.#{$namespace}-table__cell {
      transition: background-color 0.25s ease;
    }
  }

  @include m(enable-row-hover) {
    .#{$namespace}-table__body tr:hover > td.#{$namespace}-table__cell {
      background-color: var(--el-table-row-hover-bg-color);
    }
  }

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

  [class*='#{$namespace}-table__row--level'] {
    .#{$namespace}-table__expand-icon {
      display: inline-block;
      width: 12px;
      line-height: 12px;
      height: 12px;
      text-align: center;
      margin-right: 8px;
    }
  }
}
