@import url(../var.less);
@import url(checkbox.less);
@import url(tag.less);
@import url(tooltip.less);

@table-prefix: ~"@{prefix}table";
@shared: ~"%shared";

.@{table-prefix}{
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  flex: 1;
  width: 100%;
  max-width: 100%;
  background-color: @color-white;
  font-size: @font-size-base;
  color: @table-font-color;

  &__empty-block {
    min-height: 60px;
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  &__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: @secondary-text-color;
  }

  // 展开行
  &__expand-column {
    .cell {
      padding: 0;
      text-align: center;
    }
  }

  &__expand-icon {
    position: relative;
    cursor: pointer;
    color: #666;
    font-size: 12px;
    transition: transform 0.2s ease-in-out;
    height: 20px;

    &--expanded {
      transform: rotate(90deg);
    }

    > .w-icon {
      position: absolute;
      left: 50%;
      top: 50%;
      margin-left: -5px;
      margin-top: -5px;
    }
  }

  &__expanded-cell {
    background-color: @table-header-background-color;

    // 纯属为了增加权重
    &[class*=cell] {
      padding: 20px 50px;
    }
  }

  &__placeholder {
    display: inline-block;
    width: 20px;
  }

  &__append-wrapper {
    overflow: hidden;
  }

  &--fit {
    border-right: 0;
    border-bottom: 0;

    th.gutter, td.gutter {
      border-right-width: 1px;
    }
  }

  &--scrollable-x {
    .w-table__body-wrapper {
      overflow-x: auto;
    }
  }

  &--scrollable-y {
    .w-table__body-wrapper {
      overflow-y: auto;
    }
  }

  thead {
    color: @table-header-font-color;
    height: 54px;
    font-weight: 500;

    tr {
      background-color: @table-header-background-color;
    }

    &.is-group {
      th {
        background: @background-color-base;
      }
    }
  }

  th, td {
    padding: 16px 0;
    min-width: 0;
    box-sizing: border-box;
    text-overflow: ellipsis;
    vertical-align: middle;
    position: relative;
    text-align: left;

    &.is-center {
      text-align: center;
    }

    &.is-right {
      text-align: right;
    }

    &.gutter {
      width: 15px;
      border-right-width: 0;
      border-bottom-width: 0;
      padding: 0;
    }

    &.is-hidden {
      > * {
        visibility: hidden;
      }
    }
  }

  &--medium {
    thead {
      height: 47px;
    }
    th, td {
      padding: 13px 0;
    }
  }

  &--small {
    thead {
      height: 32px;
    }
    th, td {
      padding: 6px 0;
    }
  }

  tr {
    background-color: @color-white;

    input[type="checkbox"] {
      margin: 0;
    }
  }

  th.is-leaf, td {
    border-bottom: @table-border;
  }

  th.is-sortable {
    cursor: pointer;
  }

  th {
    overflow: hidden;
    user-select: none;
    background-color: @table-header-background-color;

    > .cell {
      display: inline-block;
      box-sizing: border-box;
      position: relative;
      vertical-align: middle;
      padding-left: 16px;
      padding-right: 16px;
      width: 100%;
      border-left: @table-header-cell-border;
      // height: 22px;
      // line-height: 22px;
      // display: flex;
      // align-items: center;
      &.highlight {
        color: @primary-color;
      }
    }

    &.required > div::before {
      display: inline-block;
      content: "";
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #ff4d51;
      margin-right: 5px;
      vertical-align: middle;
    }
  }

  th {
    &:first-child {
      > .cell {
        border-left: 0;
      }
    }
  }

  td {
    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: 20px;
    padding-left: 16px;
    padding-right: 16px;

    &.w-tooltip {
      white-space: nowrap;
      min-width: 50px;
    }
  }

  &--group, &--border {
    border: @table-bordered;

    .@{shared}-border-pseudo {
      content: '';
      position: absolute;
      background-color: @table-border-color;
      z-index: 1;
    }

    // 表格右部伪 border
    &::after {
      .@{shared}-border-pseudo {
        top: 0;
        right: 0;
        width: 1px;
        height: 100%;
      }
    }
  }

  // 表格底部伪 border，总是有的
  &::before {
    .@{shared}-border-pseudo {
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1px;
    }
  }

  // table--border
  &--border {
    &.w-loading-parent--relative {
      border-color: transparent;
    }

    th {
      > .cell {
        border-left: none;
      }
    }

    tr {
      td:last-child {
        border-right: none;
      }
    }

    th, td {
      border-right: @table-border;

      &:first-child .cell {
        padding-left: 10px;
      }
    }

    th.gutter:last-of-type {
      border-bottom: @table-border;
      border-bottom-width: 1px;
    }

    & th {
      border-bottom: @table-border;
    }

    tr:last-child {
      td {
        border-bottom: none;
      }
    }
  }

  &--hidden {
    visibility: hidden;
  }

  &__fixed, &__fixed-right {
    position: absolute;
    top: 0;
    left: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    box-shadow: @table-fixed-box-shadow;
    background-color: @color-white;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1px;
      background-color: @border-lighter-color;
      z-index: 4;
    }
  }

  &__fixed-right-patch {
    position: absolute;
    top: -1px;
    right: 0;
    background-color: @color-white;
    border-bottom: @table-border;
  }

  &__fixed-right {
    top: 0;
    left: auto;
    right: 0;

    .w-table__fixed-header-wrapper,
    .w-table__fixed-body-wrapper,
    .w-table__fixed-footer-wrapper {
      left: auto;
      right: 0;
    }
  }

  &__fixed-header-wrapper {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 3;
  }

  &__fixed-footer-wrapper {
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 3;

    & tbody td {
      border-top: @table-border;
      background-color: @table-row-hover-background-color;
      color: @table-font-color;
    }
  }

  &__fixed-body-wrapper {
    position: absolute;
    left: 0;
    top: 37px;
    overflow: hidden;
    z-index: 3;
  }

  &__header-wrapper, &__body-wrapper, &__footer-wrapper {
    width: 100%;
  }

  &__footer-wrapper {
    margin-top: -1px;
    td {
      border-top: @table-border;
    }
  }

  &__header, &__body, &__footer {
    table-layout: fixed;
    border-collapse: separate;
  }

  &__header-wrapper, &__footer-wrapper {
    overflow: hidden;

    & tbody td {
      background-color: @table-row-hover-background-color;
      color: @table-font-color;
    }
  }

  &__body-wrapper {
    overflow: hidden;
    position: relative;

    &.is-scrolling-none {
      ~ .w-table__fixed,
      ~ .w-table__fixed-right {
        box-shadow: none;
      }
    }

    &.is-scrolling-left {
      ~ .w-table__fixed-right {
        box-shadow: none;
      }
    }

    .wl-table--border {
      &.is-scrolling-right {
        ~ .w-table__fixed-right {
          border-left: @table-border;
        }
      }

      &.is-scrolling-left {
        ~ .w-table__fixed {
          border-right: @table-border;
        }
      }
    }
  }

  .caret-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    height: 34px;
    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: @placeholder-text-color;
      top: 5px;
    }

    &.descending {
      border-top-color: @placeholder-text-color;
      bottom: 7px;
    }
  }

  .ascending .sort-caret.ascending {
    border-bottom-color: @primary-color;
  }

  .descending .sort-caret.descending {
    border-top-color: @primary-color;
  }

  .hidden-columns {
    visibility: hidden;
    position: absolute;
    z-index: -1;
  }

  &--striped {
    & .w-table__body {
      & tr.w-table__row--striped {
        td {
          background: #FAFAFA;
        }

        &.current-row td {
          background-color: @table-current-row-background-color;
        }
      }
    }
  }

  &__body {
    tr.hover-row {
      &, &.w-table__row--striped {
        &, &.current-row {
          > td {
            background-color: @table-row-hover-background-color;
          }
        }
      }
    }

    tr.current-row > td {
      background-color: @table-current-row-background-color;
    }
  }

  &__column-resize-proxy {
    position: absolute;
    left: 200px;
    top: 0;
    bottom: 0;
    width: 0;
    border-left: @table-border;
    z-index: 10;
  }

  &__column-filter-trigger {
    display: inline-block;
    cursor: pointer;
    & i {
      color: @info-color;
      font-size: 14px;
      transform: scale(.75);
    }
  }

  &--enable-row-transition {
    .w-table__body td {
      transition: background-color .25s ease;
    }
  }

  &--enable-row-hover {
    .w-table__body tr:hover > td {
      background-color: @table-row-hover-background-color;
    }
  }

  &--fluid-height {
    .w-table__fixed,
    .w-table__fixed-right {
      bottom: 0;
      overflow: hidden;
    }
  }

  [class*=w-table__row--level] {
    .w-table__expand-icon {
      display: inline-block;
      width: 20px;
      line-height: 20px;
      height: 20px;
      text-align: center;
      margin-right: 3px;
    }
  }
}