@use 'mixins/mixins' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

@mixin center-flex() {
  display: flex;
  align-items: center;
}

@mixin cell-padding() {
  padding: 0 8px;
}

@mixin safe-padding() {
  padding-inline-end: getCssVar('table-scrollbar-size');
}

@mixin cell-alignment() {
  @include when('align-center') {
    justify-content: center;
    text-align: center;
  }

  @include when('align-right') {
    justify-content: flex-end;
    text-align: right;
  }
}

@mixin table-root() {
  display: flex;
  flex-direction: column-reverse;
  position: absolute;
  overflow: hidden;
  top: 0;
  background-color: getCssVar('bg', 'color');
}

@mixin hidden-scrollbar {
  .#{$namespace}-virtual-scrollbar {
    opacity: 0;
  }

  .#{$namespace}-vl__vertical,
  .#{$namespace}-vl__horizontal {
    z-index: -1;
  }
}

@include b('table-v3') {
  @include set-component-css-var('table', $table);
}

@include b('table-v3') {
  font-size: getCssVar('font-size', 'base');
  overflow: hidden;
  width: fit-content;
  &__table {
    scrollbar-width: none;
    border: getCssVar('table', 'border');
    background: #fff;
    &::-webkit-scrollbar {
      display: none;
    }
  }
  .qd-scrollbar__bar.is-vertical {
    top: var(--vertical-bar-top) !important;
  }
  .vue-recycle-scroller__slot {
    position:sticky;
    top: 0;
    z-index: 100;
  }
  .vue-recycle-scroller__item-wrapper {
    width: var(--row-total-width) !important;
    overflow: visible!important;
  }
  .vue-recycle-scroller__item-view {
    width: var(--row-total-width) !important;
  }
  
  * {
    box-sizing: border-box;
  }

  @include e('header-row') {
    display: flex;
    height: 60px;

    @include e('header-cell') {
      border-bottom: getCssVar('table', 'border');
      height: 100%;
      user-select: none;
      overflow: hidden;
      background-color: getCssVar('table-header', 'bg-color');
      color: getCssVar('table-header', 'text-color');
      font-weight: bold;
      @include center-flex;
      @include cell-padding;
      @include cell-alignment;

      @include when(sortable) {
        cursor: pointer;
      }

      &:hover {
        .#{$namespace}-icon {
          display: block;
        }
      }
    }

    @include e('sort-icon') {
      transition: opacity, display getCssVar('transition-duration', '');
      opacity: 0.6;
      display: none;

      @include when(sorting) {
        display: block;
        opacity: 1;
      }
    }
  }

  @include e('row') {
    // border-bottom: getCssVar('table', 'border');

    @include center-flex;
    transition: background-color getCssVar('transition-duration', '');

    @include when('hovered') {
      @include e('row-cell') {
        background-color: var(--qd-table-row-hover-bg-color);
      }
    }

    &:hover {
      @include e('row-cell') {
        background-color: var(--qd-table-row-hover-bg-color);
      }
    }

    @include e('row-cell') {
      height: 100%;
      overflow: hidden;
      @include center-flex;
      @include cell-padding;
      @include cell-alignment;

      &--fixed {
        position: sticky;
        left: 0;
        height: 100%;
        box-shadow: 2px 0 4px rgba(0,0,0,.06);
        background: #fff;
        z-index: 100;
      }
    }

    @include e('expand-icon') {
      margin: 0 4px;
      cursor: pointer;
      user-select: none;

      svg {
        transition: transform getCssVar('transition-duration', '');
      }

      @include when(expanded) {
        svg {
          transform: rotate(90deg);
        }
      }
    }
  }

  &:not(.is-dynamic) {
    @include e('cell-text') {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  @include when(dynamic) {
    @include e('row') {
      overflow: hidden;
      align-items: stretch;

      @include e('row-cell') {
        overflow-wrap: break-word;
      }
    }
  }

  @include e('border') {
    box-sizing: content-box;
    border: getCssVar('table', 'border');
    
    @include e('main') {
        box-shadow: 0 0 0 1px var(--qd-table-border-color);
    }

    @include e('header-row') {
      background-color: var(--qd-table-header-bg-color);
      @include e('header-cell') {
        border-right: getCssVar('table', 'border');
        &:last-child {
          border-right: none;
        }
      }
    }

    @include e('row') {
      @include e('row-cell') {
        border-right: getCssVar('table', 'border');
        border-bottom: getCssVar('table', 'border');
        &:last-child {
          border-right: unset;
        }
      }
    }
  }
  .caret-wrapper {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    height: 14px;
    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: getCssVar('text-color', 'placeholder');
      top: -5px;
    }

    &.descending {
      border-top-color: getCssVar('text-color', 'placeholder');
      bottom: -3px;
    }
  }

  .ascending .sort-caret.ascending {
    border-bottom-color: getCssVar('color-primary');
  }

  .descending .sort-caret.descending {
    border-top-color: getCssVar('color-primary');
  }
}
.vue-recycle-scroller{position:relative}.vue-recycle-scroller.direction-vertical:not(.page-mode){overflow-y:auto}.vue-recycle-scroller.direction-horizontal:not(.page-mode){overflow-x:auto}.vue-recycle-scroller.direction-horizontal{display:flex}.vue-recycle-scroller__slot{flex:auto 0 0}.vue-recycle-scroller__item-wrapper{flex:1;box-sizing:border-box;overflow:hidden;position:relative}.vue-recycle-scroller.ready .vue-recycle-scroller__item-view{position:absolute;top:0;left:0;will-change:transform}.vue-recycle-scroller.direction-vertical .vue-recycle-scroller__item-wrapper{width:100%}.vue-recycle-scroller.direction-horizontal .vue-recycle-scroller__item-wrapper{height:100%}.vue-recycle-scroller.ready.direction-vertical .vue-recycle-scroller__item-view{width:100%}.vue-recycle-scroller.ready.direction-horizontal .vue-recycle-scroller__item-view{height:100%}.resize-observer[data-v-b329ee4c]{position:absolute;top:0;left:0;z-index:-1;width:100%;height:100%;border:none;background-color:transparent;pointer-events:none;display:block;overflow:hidden;opacity:0}.resize-observer[data-v-b329ee4c] object{display:block;position:absolute;top:0;left:0;height:100%;width:100%;overflow:hidden;pointer-events:none;z-index:-1}
