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

.@{data-table-prefix} {
  .extendBaseEnhanced();
  display: flex;
  flex-direction: column;
  width: 100%;
  .setFontSize(@icecream-font-size-main);
  text-align: left;

  table {
    width: 100%;
    // 不用 collapse 是因为
    // https://stackoverflow.com/questions/50361698/border-style-do-not-work-with-sticky-position-element
    border-collapse: separate;
    border-spacing: 0;
  }

  &-head {
    flex: 0 0 auto;

    // fixHead: true 时，head 跟 body 内部会各自包一个 table，这里针对控制 head 里的 table
    table {
      table-layout: fixed;
    }

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

    &-th {
      .td();

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

    &-sort {
      display: inline-flex;
      flex-direction: column;
      margin-left: 4px;
      font-size: 10px; // 调整 icon 的大小
      // 如果表现不好用 inline-flex
      vertical-align: text-bottom;
      cursor: pointer;

      &-asc svg:first-child {
        color: @icecream-primary-color;
      }
    
      &-desc svg:last-child {
        color: @icecream-primary-color;
      }
    }

    &-filter {
      display: inline-flex;
      flex-direction: column;
      margin-left: 4px;
      font-size: @icecream-font-size-1;
      vertical-align: -0.125em;
      cursor: pointer;

      .@{dropdown-class} {
        border: none;
      }
    
      &-active {
        color: @icecream-primary-color;
      }
    }

  }

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

    &-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
  &-cell-left-shadow::after,
  &-cell-right-shadow::after {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    transition: box-shadow @icecream-transitions;
    content: "";
    pointer-events: none;
  }

  &-cell-right-shadow::after {
    right: 0;
    transform: translate(100%);
    box-shadow: inset 8px 0 8px -8px #00000026;
  }

  &-cell-left-shadow::after {
    left: 0;
    transform: translate(-100%);
    box-shadow: inset -8px 0 8px -8px #00000026;
  }

  &-measure-row {
    height: 0;
    font-size: 0;
  }

  &-measure-cell {
    padding: 0 !important;
    height: 0 !important;
    border: none !important;
  }
}

// 边框
.@{data-table-prefix}-border {
  &-row {
    .@{data-table-head-prefix} {
      th {
        border-bottom: 1px solid @icecream-color-grey-5;
      }
    }
    .@{data-table-body-prefix} {
      td {
        border-bottom: 1px solid @icecream-color-grey-5;
      }
    }
  }
  &-full {
    border-left: 1px solid @icecream-color-grey-5;
    .@{data-table-head-prefix} {
      th {
        border: 1px solid @icecream-color-grey-5;
        border-left: none;
      }
    }
    .@{data-table-body-prefix} {
      td {
        border-bottom: 1px solid @icecream-color-grey-5;
        border-right: 1px solid @icecream-color-grey-5;
      }
    }

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

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

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

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

.@{data-table-prefix}-fix-head {
  > .@{icecream-prefix}-loading-content {
    display: flex;
    flex-direction: column;
  }
  .@{data-table-prefix}-content-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
}

.@{data-table-prefix}-fix-column {
  .@{data-table-prefix}-content-wrapper {
    overflow-x: auto;
  }
}

.@{data-table-prefix}-fix-head.@{data-table-prefix}-fix-column {
  // 这里对 head & body 处理的差异，详见 HorizontalScrollProvider
  .@{data-table-head-prefix} {
    overflow-x: hidden;
  }
  .@{data-table-body-prefix} {
    overflow-x: auto;
  }
}

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

.@{data-table-placeholder} {
  td {
    padding: 48px 0
  }
}

.@{data-table-head-prefix}-filter-select {
  @item-height: 36px;
  @item-padding-horizontal: @icecream-gap-sm;

  .extendBaseEnhanced();
  min-width: 120px;
  .setFontSize(@icecream-font-size-main);
  font-weight: 400;

  &-option {
    .extendBaseEnhanced();
    width: 100%;
    height: @item-height;
    line-height: @item-height;
    padding: 0 @item-padding-horizontal;
    list-style: none;

    &&-checked {
      background: fade(@icecream-primary-color, 10);

      &:hover {
        background: fade(@icecream-primary-color, 10);
      }
    }

    &:hover {
      background: fade(@icecream-primary-color, 5);
    }

    &-checkbox {
      width: 100%;
      height: 100%;
      line-height: @item-height !important;
      vertical-align: top;
    }
  }

  &-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: @item-height;
    padding: 0 @item-padding-horizontal;
    border-top: 1px solid @icecream-color-grey-5;
  }
}
