@import '../../style/themes/index';
@import '../../style/mixins/index';
@import './size';
@import './bordered';

// Table
// --
@font-size-sm: 3 * @P;
@heading-color: fade(#000, 85%);
@shadow-color: rgba(0, 0, 0, 0.15);
@box-shadow-base: @shadow-2;
@table-bg: @component-background;
@table-header-bg: @background-color-light;
@table-header-color: @heading-color;
@table-header-sort-bg: @background-color-base;
@table-body-sort-bg: #fafafa;
@table-row-hover-bg: @background-color-light;
@table-selected-row-color: inherit;
@table-selected-row-bg: @primary-1;
@table-body-selected-sort-bg: @table-selected-row-bg;
@table-selected-row-hover-bg: darken(@table-selected-row-bg, 2%);
@table-expanded-row-bg: #fbfbfb;

// size
@table-padding-vertical: 10px;
@table-padding-horizontal: 12px;
@table-padding-vertical-lg: 20px;
@table-padding-horizontal-lg: 12px;
@table-padding-vertical-sm: 6px;
@table-padding-horizontal-sm: 12px;
@table-font-size: @T2;
@table-font-size-lg: @T2;
@table-font-size-sm: @T2;
@table-tbody-td-height: 40px;
@table-tbody-td-height-lg: 60px;
@table-tbody-td-height-sm: 32px;

@table-border-color: @border-color-split;
@table-border-radius-base: @border-radius-base;
@table-footer-bg: @background-color-light;
@table-footer-color: @heading-color;
@table-header-bg-sm: @table-header-bg;

@table-header-cell-split-color: #fff;
// Sorter
// Legacy: `table-header-sort-active-bg` is used for hover not real active
@table-header-sort-active-bg: rgba(0, 0, 0, 0.04);
@table-fixed-header-sort-active-bg: hsv(0, 0, 96%);

// Filter
@table-header-filter-active-bg: rgba(0, 0, 0, 0.04);
@table-filter-btns-bg: inherit;
@table-filter-dropdown-bg: @component-background;
@table-expand-icon-bg: @component-background;
@table-selection-column-width: 28px;
// Sticky
@table-sticky-scroll-bar-bg: fade(#000, 35%);
@table-sticky-scroll-bar-radius: 4px;

@table-prefix-cls: ~'@{acud-prefix}-table';
@tree-prefix-cls: ~'@{acud-prefix}-tree';
@dropdown-prefix-cls: ~'@{acud-prefix}-dropdown';
@descriptions-prefix-cls: ~'@{acud-prefix}-descriptions';
@table-header-icon-color: #bfbfbf;
@table-header-icon-color-hover: darken(@table-header-icon-color, 10%);
@table-sticky-zindex: calc(@zindex-table-fixed + 1);
@table-sticky-scroll-bar-active-bg: fade(@table-sticky-scroll-bar-bg, 80%);
@table-filter-dropdown-max-height: 264px;
@background-color-light: hsv(0, 0, 98%);
@background-color-base: hsv(0, 0, 96%);
@primary-1: @B6;
@zindex-table-fixed: 2;
@tree-node-hover-bg: @p6-hover-background-color;
@tree-node-selected-bg: @p6-click-background-color;

.operation-unit() {
  color: @B6;
  text-decoration: none;
  outline: none;
  cursor: pointer;
  transition: color 0.3s;

  &:focus,
  &:hover {
    color: @B6;
  }

  &:active {
    color: @B6;
  }
}

.@{table-prefix-cls}-wrapper {
  clear: both;
  max-width: 100%;
  // .clearfix();
}

.@{table-prefix-cls} {
  .reset-component();
  position: relative;
  font-size: @table-font-size;
  background: @table-bg;
  border-radius: @table-border-radius-base;

  // https://github.com/ant-design/ant-design/issues/17611
  table {
    width: 100%;
    text-align: left;
    border-radius: @table-border-radius-base @table-border-radius-base 0 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  // ============================= Cell =============================
  &-thead > tr > th,
  &-tbody > tr > td,
  tfoot > tr > th,
  tfoot > tr > td {
    position: relative;
    padding: @table-padding-vertical @table-padding-horizontal;
    overflow-wrap: break-word;
  }

  &-cell-ellipsis {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    word-break: keep-all;

    // Fixed first or last should special process
    &.@{table-prefix-cls}-cell-fix-left-last,
    &.@{table-prefix-cls}-cell-fix-right-first {
      overflow: visible;

      .@{table-prefix-cls}-cell-content {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }

    .@{table-prefix-cls}-column-title {
      overflow: hidden;
      text-overflow: ellipsis;
      word-break: keep-all;
    }
  }

  // ============================ Title =============================
  &-title {
    padding: @table-padding-vertical @table-padding-horizontal;
  }

  // ============================ Footer ============================
  &-footer {
    padding: @table-padding-vertical @table-padding-horizontal;
    color: @table-footer-color;
    background: @table-footer-bg;
  }

  // ============================ Header ============================
  &-thead {
    > tr {
      > th {
        position: relative;
        color: @table-header-color;
        font-weight: 500;
        text-align: left;
        background: @table-header-bg;
        // border-bottom: @border-width-base @border-style-base @table-border-color;
        transition: background 0.3s ease;

        &[colspan]:not([colspan='1']) {
          text-align: center;
        }

        &:not(:last-child):not(.@{table-prefix-cls}-selection-column):not(.@{table-prefix-cls}-row-expand-icon-cell):not([colspan])::before {
          position: absolute;
          top: 50%;
          right: 0;
          // width: 1px;
          width: 0;
          height: 1.6em;
          background-color: @table-header-cell-split-color;
          transform: translateY(-50%);
          transition: background-color 0.3s;
          content: '';
        }
      }
    }

    > tr:not(:last-child) > th {
      &[colspan] {
        border-bottom: 0;
      }
    }
  }

  // ============================= Body =============================
  &-tbody {
    > tr {
      > td {
        border-bottom: @border-width-base @border-style-base @table-border-color;
        transition: background 0.3s;
        border-right: 1px solid transparent;

        // ========================= Nest Table ===========================
        > .@{table-prefix-cls}-wrapper:only-child,
        > .@{table-prefix-cls}-expanded-row-fixed > .@{table-prefix-cls}-wrapper:only-child {
          .@{table-prefix-cls} {
            margin: @P * 6 - @table-padding-vertical @P * 10 - @table-padding-horizontal;
            min-height: unset;

            &-thead tr th {
              // background-color: @G9;
              background-color: #edeef0;
            }

            &-tbody > tr:last-child > td {
              border-bottom: 0;

              &:first-child,
              &:last-child {
                border-radius: 0;
              }
            }
          }
        }
      }

      &.@{table-prefix-cls}-row:hover > td,
      > td.@{table-prefix-cls}-cell-row-hover {
        // background: @table-row-hover-bg;
        background-color: ~'@{@{table-tbody-p}-hover-background-color}';
      }

      &.@{table-prefix-cls}-row-selected {
        > td {
          background: @B1;
          // border-color: rgba(0, 0, 0, 0.03);
        }

        &:hover {
          > td {
            background: @B2;
          }
        }
      }
    }
  }

  // =========================== Summary ============================
  &-summary {
    position: relative;
    z-index: @zindex-table-fixed;
    td {
      background-color: #fafafa;
    }

    div& {
      box-shadow: 0 -@border-width-base 0 @table-border-color;
    }

    > tr {
      > th,
      > td {
        border-bottom: @border-width-base @border-style-base @table-border-color;
      }
    }
  }

  // ========================== Pagination ==========================
  &-pagination.@{acud-prefix}-pagination {
    margin: 16px 0;
  }

  &-pagination {
    display: flex;
    flex-wrap: wrap;
    row-gap: @padding-xs;

    > * {
      flex: none;
    }

    &-left {
      justify-content: flex-start;
    }

    &-center {
      justify-content: center;
    }

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

  // ================================================================
  // =                           Function                           =
  // ================================================================

  // ============================ Sorter ============================
  &-thead th.@{table-prefix-cls}-column-has-sorters {
    // cursor: pointer;
    // transition: all 0.3s;

    &:hover {
      // background: @table-header-sort-active-bg;

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

    // https://github.com/ant-design/ant-design/issues/30969
    &.@{table-prefix-cls}-cell-fix-left:hover,
    &.@{table-prefix-cls}-cell-fix-right:hover {
      background: @table-fixed-header-sort-active-bg;
    }
  }

  &-thead th.@{table-prefix-cls}-column-sort {
    // background: @table-header-sort-bg;

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

  td&-column-sort {
    // background: @table-body-sort-bg;
  }

  &-column-title {
    position: relative;
    z-index: 1;
    // flex: 0;
  }

  &-column-sorters {
    display: flex;
    flex: auto;
    align-items: center;
    justify-content: flex-start;
  }

  &-column-sorter {
    margin-left: 4px;
    color: @G5;
    font-size: 0;
    transition: color 0.3s;

    &-inner {
      display: inline-flex;
      flex-direction: column;
      align-items: center;
    }

    & &-icon {
      // display: none;
    }

    &-default,
    &-up,
    &-down {
      // font-size: 16px;

      &.active {
        display: inherit;
        color: @B6;
      }
    }
  }
  &-column-sorter:hover .@{table-prefix-cls}-column-sorter {
    &-up,
    &-down {
      &.active {
        color: @B5;
      }
    }
  }
  &-column-sorter:active .@{table-prefix-cls}-column-sorter {
    &-up,
    &-down {
      &.active {
        color: @B7;
      }
    }
  }
  &-column-sorter-default:hover .@{table-prefix-cls}-column-sorter {
    &-up,
    &-down {
      color: @B5;
    }
  }
  &-column-sorter-default:active .@{table-prefix-cls}-column-sorter {
    &-up,
    &-down {
      color: @B7;
    }
  }

  // ============================ Filter ============================
  &-filter-column {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .@{dropdown-prefix-cls}-trigger {
      display: flex;
      .@{iconfont-css-prefix}-outlined-funnel {
        display: flex;
        height: 4 * @P;
      }
    }
  }

  &-filter-trigger {
    position: relative;
    display: flex;
    align-items: center;
    margin-left: @P;
    padding: 0 4px;
    color: @table-header-icon-color;
    font-size: 16px;
    border-radius: @border-radius-base;
    cursor: pointer;
    transition: all 0.3s;

    &.active {
      color: @primary-color;
    }
  }

  // Dropdown
  &-filter-dropdown {
    .reset-component();

    min-width: 120px;
    background-color: @table-filter-dropdown-bg;
    border-radius: @border-radius-base;
    box-shadow: @box-shadow-base;

    .@{acud-prefix}-dropdown-menu-item-multiple {
        .@{acud-prefix}-checkbox + span {
            white-space: nowrap;
        }
    }

    // Reset menu
    .@{dropdown-prefix-cls}-menu {
      // https://github.com/ant-design/ant-design/issues/4916
      // https://github.com/ant-design/ant-design/issues/19542
      max-height: @table-filter-dropdown-max-height;
      overflow-x: hidden;
      border: 0;
      box-shadow: none;

      &:empty::after {
        display: block;
        padding: 8px 0;
        color: @disabled-color;
        font-size: @font-size-sm;
        text-align: center;
        content: 'Not Found';
      }
    }

    &-tree {
      padding: @P * 2 @P * 3;
      max-height: 216px;
      overflow-y: auto;
    }

    &-search {
      padding: @P * 2 @P * 3;

      &-input {
        input {
          min-width: 140px;
        }
        .@{iconfont-css-prefix} {
          color: @disabled-color;
        }
      }
      &-highlight {
        color: @B6;
      }
    }

    &-checkall {
      width: 100%;
      margin-bottom: 4px;
      // margin-left: 4px;
    }

    &-submenu > ul {
      max-height: calc(100vh - 130px);
      overflow-x: hidden;
      overflow-y: auto;
    }

    // Checkbox
    &,
    &-submenu {
      .@{acud-prefix}-checkbox-wrapper + span {
        padding-left: 8px;
      }
    }

    // Operation
    &-btns {
      display: flex;
      justify-content: flex-end;
      padding: @P * 2 @P * 3;
      overflow: hidden;
      background-color: @table-filter-btns-bg;
      border-top: @border-width-base @border-style-base @table-border-color;
      &-reset {
        margin-left: @P * 2;
      }
    }
  }

  // ========================== Selections ==========================
  &-selection-col {
    width: @table-selection-column-width;
  }

  &-bordered &-selection-col {
    width: @table-selection-column-width + 18px;
  }

  table tr th&-selection-column,
  table tr td&-selection-column {
    padding-right: 0;
    // padding-left: @P * 3;
    // text-align: left;

    .@{acud-prefix}-radio-wrapper,
    .@{acud-prefix}-radio {
      margin-right: 0;
      &-outline {
        margin-right: 0;
      }
    }
  }

  table tr th&-selection-column&-cell-fix-left {
    z-index: 3;
  }

  table tr th&-selection-column::after {
    background-color: transparent !important;
  }

  &-selection {
    position: relative;
    display: flex;
    // flex-direction: column;
    flex-direction: row;

    &-extra {
      // position: absolute;
      // top: 0;
      // z-index: 1;
      cursor: pointer;
      transition: all 0.3s;
      margin-inline-start: 100%;
      padding-inline-start: @padding-xss;
      margin-left: 0;
      display: flex;
      align-items: center;

      .@{acud-prefix}-dropdown-trigger {
        display: flex;
        height: 4 * @P;
      }

      .@{iconfont-css-prefix} {
        color: @G5;
        font-size: @P * 4;
        display: flex;

        &:hover {
          color: @G5;
        }
      }
    }
  }

  // ========================== Expandable ==========================
  &-expand-icon-col {
    width: 28px;
  }

  &-row-expand-icon-cell {
    text-align: center;
  }

  &-row-indent {
    float: left;
    height: 1px;
  }

  &-row-expand-icon {
    .basic-tp-config(@table-row-expand-icon-tp);
    cursor: pointer;
    font-size: @P * 4;
    line-height: 0;
    float: left;
    margin: auto;

    &-spaced {
      cursor: not-allowed;
    }

    .@{table-prefix-cls}-row-indent + & {
      margin-top: ((@font-size-base * @line-height-base - @border-width-base * 3) / 2) -
        ceil(((@font-size-sm * 1.4 - @border-width-base * 3) / 2));
      margin-right: @padding-xs;
    }
  }

  tr&-expanded-row {
    &,
    &:hover {
      > td {
        background: @G10;
      }
    }

    // https://github.com/ant-design/ant-design/issues/25573
    .@{descriptions-prefix-cls}-view {
      display: flex;

      table {
        flex: auto;
        width: auto;
      }
    }
  }

  // With fixed
  .@{table-prefix-cls}-expanded-row-fixed {
    position: relative;
    margin: -@table-padding-vertical -@table-padding-horizontal;
    padding: @table-padding-vertical @table-padding-horizontal;
  }

  // ========================= Placeholder ==========================
  &-tbody > tr&-placeholder {
    text-align: center;
    .@{table-prefix-cls}-empty & {
      color: @disabled-color;
    }

    &:hover {
      > td {
        background: @component-background;
      }
    }
  }

  // ============================ Fixed =============================
  &-cell-fix-left,
  &-cell-fix-right {
    position: sticky !important;
    z-index: @zindex-table-fixed;
    background: @table-bg;
  }

  &-cell-fix-left-first::after,
  &-cell-fix-left-last::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: -1px;
    width: 30px;
    transform: translateX(100%);
    transition: box-shadow 0.3s;
    content: '';
    pointer-events: none;
  }

  &-cell-fix-right-first::after,
  &-cell-fix-right-last::after {
    position: absolute;
    top: 0;
    bottom: -1px;
    left: 0;
    width: 30px;
    transform: translateX(-100%);
    transition: box-shadow 0.3s;
    content: '';
    pointer-events: none;
  }

  .@{table-prefix-cls}-container {
    &::before,
    &::after {
      position: absolute;
      top: 0;
      bottom: 0;
      z-index: 1;
      width: 30px;
      transition: box-shadow 0.3s;
      content: '';
      pointer-events: none;
    }

    &::before {
      left: 0;
    }

    &::after {
      right: 0;
    }
  }

  &-ping-left {
    &:not(.@{table-prefix-cls}-has-fix-left) .@{table-prefix-cls}-container {
      position: relative;

      &::before {
        box-shadow: inset 10px 0 8px -8px darken(@shadow-color, 5%);
      }
    }

    .@{table-prefix-cls}-cell-fix-left-first::after,
    .@{table-prefix-cls}-cell-fix-left-last::after {
      box-shadow: inset 10px 0 8px -8px darken(@shadow-color, 5%);
    }

    .@{table-prefix-cls}-cell-fix-left-last::before {
      background-color: transparent !important;
    }
  }

  &-ping-right {
    &:not(.@{table-prefix-cls}-has-fix-right) .@{table-prefix-cls}-container {
      position: relative;

      &::after {
        box-shadow: inset -10px 0 8px -8px darken(@shadow-color, 5%);
      }
    }

    .@{table-prefix-cls}-cell-fix-right-first::after,
    .@{table-prefix-cls}-cell-fix-right-last::after {
      box-shadow: inset -10px 0 8px -8px darken(@shadow-color, 5%);
    }
  }

  &-sticky {
    &-holder {
      position: sticky;
      z-index: @table-sticky-zindex;
      background: @component-background;
    }

    &-scroll {
      position: sticky;
      bottom: 0;
      z-index: @table-sticky-zindex;
      display: flex;
      align-items: center;
      background: lighten(@table-border-color, 80%);
      border-top: 1px solid @table-border-color;
      opacity: 0.6;

      &:hover {
        transform-origin: center bottom;
      }

      &-bar {
        height: 8px;
        background-color: @table-sticky-scroll-bar-bg;
        border-radius: @table-sticky-scroll-bar-radius;

        &:hover {
          background-color: @table-sticky-scroll-bar-active-bg;
        }

        &-active {
          background-color: @table-sticky-scroll-bar-active-bg;
        }
      }
    }
  }
  &-filter-dropdown-empty {
    margin: @P * 2 0;
  }
}

@media all and (-ms-high-contrast: none) {
  .@{table-prefix-cls} {
    &-ping-left {
      .@{table-prefix-cls}-cell-fix-left-last::after {
        box-shadow: none !important;
      }
    }

    &-ping-right {
      .@{table-prefix-cls}-cell-fix-right-first::after {
        box-shadow: none !important;
      }
    }
  }
}

@import './radius';
@import './rtl';
@import './base.less';
@import './space.less';
