@use './tokens' as kt;

@include kt.block {
  &__body {
    --kt-table-scroll-y: 260px;

    position: relative;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    border: 1px solid hsl(var(--border));
    border-radius: 6px;
  }

  &__ant,
  &__ant .ant-spin-nested-loading,
  &__ant .ant-spin-container {
    height: 100%;
    min-height: 0;
  }

  &__ant {
    .ant-table,
    .ant-table-container,
    .ant-table-content,
    .ant-table-header,
    .ant-table-body {
      overscroll-behavior: contain;
    }

    .ant-table table {
      table-layout: fixed !important;
    }

    .ant-spin-container,
    .ant-table {
      display: flex;
      flex: 1 1 0;
      flex-direction: column;
      min-height: 0;
    }

    .ant-table-container {
      display: flex;
      flex: 1 1 0;
      flex-direction: column;
      min-height: 0;
    }

    .ant-table-header {
      position: relative;
      z-index: 5;
      flex: 0 0 auto;
      contain: paint;
      background: hsl(var(--card));
    }

    .ant-table-body {
      position: relative;
      z-index: 1;
      min-height: 0;
      max-height: var(--kt-table-scroll-y) !important;
      contain: paint;
      overflow: auto !important;
      scrollbar-gutter: stable;
      will-change: scroll-position;
    }

    .ant-table-summary {
      flex-shrink: 0;
      margin-top: auto;
    }

    .ant-table-cell {
      border-bottom-color: hsl(var(--border)) !important;
    }

    .ant-table-cell-fix-left,
    .ant-table-cell-fix-right,
    .ant-table-cell-fix-start,
    .ant-table-cell-fix-end {
      background: hsl(var(--card)) !important;
    }

    .ant-table-thead > tr > th.ant-table-cell-fix-left,
    .ant-table-thead > tr > th.ant-table-cell-fix-right,
    .ant-table-thead > tr > th.ant-table-cell-fix-start,
    .ant-table-thead > tr > th.ant-table-cell-fix-end {
      z-index: 6;
      background: hsl(var(--card)) !important;
    }

    .ant-table-tbody > tr:hover > td.ant-table-cell-fix-left,
    .ant-table-tbody > tr:hover > td.ant-table-cell-fix-right,
    .ant-table-tbody > tr:hover > td.ant-table-cell-fix-start,
    .ant-table-tbody > tr:hover > td.ant-table-cell-fix-end {
      background: hsl(var(--accent)) !important;
    }

    .ant-table-tbody > tr#{kt.$block}__row--clickable {
      cursor: pointer;
    }

    .ant-table-tbody > tr#{kt.$block}__row--active > td,
    .ant-table-tbody > tr#{kt.$block}__row--active > td.ant-table-cell-fix-left,
    .ant-table-tbody
      > tr#{kt.$block}__row--active
      > td.ant-table-cell-fix-right,
    .ant-table-tbody
      > tr#{kt.$block}__row--active
      > td.ant-table-cell-fix-start,
    .ant-table-tbody > tr#{kt.$block}__row--active > td.ant-table-cell-fix-end {
      background: hsl(var(--accent)) !important;
    }

    .ant-table-summary .ant-table-cell-fix-left,
    .ant-table-summary .ant-table-cell-fix-right,
    .ant-table-summary .ant-table-cell-fix-start,
    .ant-table-summary .ant-table-cell-fix-end {
      background: hsl(var(--card)) !important;
    }

    // Fixed column shadows repaint while Antdv toggles shadow classes during horizontal scroll.
    .ant-table-cell-fix-start-shadow::after,
    .ant-table-cell-fix-end-shadow::after,
    .ant-table-cell-fix-left-last::after,
    .ant-table-cell-fix-right-first::after {
      box-shadow: none !important;
    }

    .ant-table-thead > tr > th {
      position: relative;
      top: 0;
      z-index: 5;
      background: hsl(var(--card)) !important;
    }

    tfoot.ant-table-summary .ant-table-cell,
    tfoot.ant-table-summary > tr > td {
      height: 44px;
      padding: 0 16px;
      overflow: hidden;
      text-overflow: ellipsis;
      font-size: 13px;
      line-height: 20px;
      color: hsl(var(--foreground));
      white-space: nowrap;
      border-bottom: 0 !important;
    }

    .ant-table-tbody > tr#{kt.$block}__row--resizable > td {
      height: var(--kt-table-row-height);
    }

    .ant-table-tbody
      > tr#{kt.$block}__row--resizable
      > td#{kt.$block}__index-column {
      position: sticky;
      z-index: 16;
    }
  }

  &__index-cell {
    position: static;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
  }

  &__index-column {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    padding-inline: 4px !important;
    overflow: visible !important;
    text-overflow: clip !important;
    text-align: center;
    white-space: nowrap;
  }

  &__index-column .ant-table-cell-content,
  &__index-column .ant-table-column-title {
    min-width: 0;
    overflow: visible;
    text-overflow: clip;
  }

  &__action-column {
    width: 112px;
    min-width: 112px;
    max-width: 112px;
  }
}
