@import "./SortIcon/style.less";
@import "./filter/style.less";
@import "./plugins/style.less";
@import "./rows/Placeholder/style.less";
@import "./rows/Measure/style.less";

@table-prefix: ~"@{icecream-prefix}-table";
@table-bordered-cls: ~"@{table-prefix}-bordered";
@table-header-prefix: ~"@{table-prefix}-header";
@table-body-prefix: ~"@{table-prefix}-body";
@table-header-th: ~"@{table-header-prefix}-th";
@table-header-tr: ~"@{table-header-prefix}-tr";
@table-body-tr: ~"@{table-body-prefix}-tr";
@table-body-td: ~"@{table-body-prefix}-td";
@table-row-height: 52px;
@table-small-row-height: 44px;

.@{table-prefix} {
  .extendBaseEnhanced();
  width: 100%;
  .setFontSize(@icecream-font-size-main);
  text-align: left;
  // 不用 collapse 是因为
  // https://stackoverflow.com/questions/50361698/border-style-do-not-work-with-sticky-position-element
  border-collapse: separate;
  border-spacing: 0;

  &-wrap {
    display: flex;
    width: 100%;
  }

  &-loading {
    width: 100%;

    .@{icecream-prefix}-loading-content {
      display: flex;
      flex-direction: column;

      .@{table-prefix}-loading-inner {
        display: flex;
        flex-direction: column;
        min-height: 0;
  
        &.@{table-prefix}-loading-inner-fixed-column {
          overflow-x: auto;
        }
      }
    }
  }

  &-header {
    > table {
      width: 100%;
      table-layout: fixed;
      border-collapse: separate;
      border-spacing: 0;
    }

    &-tr {
      background: @icecream-color-grey-3;
    }

    &-th {
      .td();

      &-title {
        font-weight: @icecream-bold;
      }
    }
  }

  &-body {
    flex: 1;
    overflow-y: auto;
    // 避免滚动条从无到有导致一瞬间出现滚动条的问题
    overflow-x: hidden;

    > table {
      width: 100%;
      table-layout: fixed;
      border-collapse: separate;
      border-spacing: 0;
    }

    &-tr {
      background-color: @icecream-color-grey-1;

      &:hover {
        // important 覆盖斑马纹的灰色底色
        background: #F2FBFE !important;
      }
    }
    &-td {
      .td();
    }
  }

  &-pagination {
    display: flex;
    justify-content: flex-end;
    margin-top: @icecream-gap-md;

    &-align-right {
      justify-content: flex-end;
    }
    &-align-center {
      justify-content: center;
    }
  }

  // fixColumn box shadow
  .@{table-header-th}-left-last::after, .@{table-body-td}-left-last::after, .@{table-header-th}-right-first::after, .@{table-body-td}-right-first::after {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    transition: box-shadow @icecream-transitions;
    content: "";
    pointer-events: none;
  }

  .@{table-header-th}-left-last::after, .@{table-body-td}-left-last::after {
    right: 0;
    transform: translate(100%);
    box-shadow: inset 8px 0 8px -8px #00000026;
  }

  .@{table-header-th}-right-first::after, .@{table-body-td}-right-first::after {
    left: 0;
    transform: translate(-100%);
    box-shadow: inset -8px 0 8px -8px #00000026;
  }
}

// 边框
.@{table-prefix}-border {
  &-row {
    .@{table-header-prefix} {
      th {
        border-bottom: 1px solid @icecream-color-grey-5;
      }
    }
    .@{table-body-prefix} {
      tr:not(.@{table-measure-row}) td {
        border-bottom: 1px solid @icecream-color-grey-5;
      }
    }
  }
  &-full {
    border-left: 1px solid @icecream-color-grey-5;
    .@{table-header-prefix} {
      th {
        border: 1px solid @icecream-color-grey-5;
        border-left: none;
      }
    }
    .@{table-body-prefix} {
      tr:not(.@{table-measure-row}) td {
        border-bottom: 1px solid @icecream-color-grey-5;
        border-right: 1px solid @icecream-color-grey-5;
      }
    }

    .@{table-header-prefix}-selection,
    .@{table-body-prefix}-selection {
      padding: 0 @icecream-gap-md-x;
    }
  }
}

// 斑马纹
.@{table-prefix}-zebra {
  .@{table-body-tr}:nth-child(2n) {
    background: @icecream-color-grey-2;
  }
}

// 尺寸
.@{table-prefix}-size-small {
  .setFontSize(@icecream-font-size-sm);

  .@{table-header-th},
  .@{table-body-td} {
    padding: @icecream-gap-sm @icecream-gap-md-x;
  }
}

// fixHead
.@{table-prefix}-fixed-header {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  // 防止被子组件撑开
  min-height: 0;
  text-align: left;
}

// fixHead and fixColumn
.@{table-prefix}-fixed-header.@{table-prefix}-fixed-column {
  .@{table-header-prefix} {
    overflow: hidden;
  }

  .@{table-body-prefix} {
    overflow-x: auto;
  }
}

.td() {
  // 需要和 getPaddingBySize 保持同步
  padding: @icecream-gap-md @icecream-gap-md-x;
  vertical-align: middle;
}
