@import '../animation/variables.scss';

$name: 'ivue-table';

:root {
  // color
  --#{$name}-placeholder-color: #9ab0c6;
  --#{$name}-row-hover-cell-bg: #eeeeee;
  --#{$name}-stripe-body-cell-bg: #fafafa;
  --#{$name}-group-cell-bg: #f5f7fa;
}

.#{$name} {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  height: fit-content;
  width: 100%;
  max-width: 100%;
  background-color: var(--ivue-white-color);
  font-size: var(--ivue-font-base-size);
  color: var(--ivue-text-color);

  thead {
    font-weight: 500;
  }

  // 行
  .cell {
    box-sizing: border-box;
    text-overflow: ellipsis;
    white-space: normal;
    word-break: break-all;
    line-height: 23px;
    padding: 0 12px;
    transition: var(--ivue-all-transition);

    &-content {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
    }
  }

  .highlight {
    color: var(--ivue-primary-color);
  }

  // 没有border
  &:not(.ivue-table-border) {
    .#{$name}-cell {
      border-right: none;
    }
  }

  &-hidden {
    position: absolute;
    z-index: -1;
    visibility: hidden;
  }

  // 100%宽度
  &-fullWidth {
    border-right: 0;
    border-bottom: 0;
  }

  // 内容
  &-content {
    position: relative;
    display: flex;
    flex-direction: column;

    // 滚动条
    .ivue-scrollbar-bar {
      z-index: 2;
    }

    &::before {
      content: '';
      position: absolute;
      background-color: var(--ivue-border-color);
      left: 0;
      bottom: 0;
      width: 100%;
      height: 1px;
      z-index: 3;
    }

    &::after {
      left: 0;
      top: 0;
      width: 100%;
      height: 1px;
      z-index: 3;
    }

    tr:first-child th:first-child {
      border-left: none;
    }
  }

  // 行
  &-cell {
    padding: 8px 0;
    min-width: 0;
    box-sizing: border-box;
    text-overflow: ellipsis;
    vertical-align: middle;
    position: relative;
    text-align: left;
    z-index: 1;

    .ivue-table--expand-icon {
      width: 20px;
      height: 20px;
      align-items: center;

      .ivue-icon {
        line-height: 20px;
      }
    }
  }

  // 行居中
  &-cell.is-center {
    .cell {
      justify-content: center;
    }
  }

  // 行右对齐
  &-cell.is-right {
    .cell {
      justify-content: right;
    }
  }

  // 行左对齐
  &-cell.is-left {
    .cell {
      justify-content: left;
    }
  }

  th.#{$name}-cell {
    user-select: none;

    & > .cell {
      display: flex;
      box-sizing: border-box;
      position: relative;
      width: 100%;
      vertical-align: middle;
    }
  }

  th.#{$name}-cell.is-leaf {
    border-bottom: 1px solid var(--ivue-border-color);
  }

  td.#{$name}-cell {
    border-bottom: 1px solid var(--ivue-border-color);
  }

  // 排序
  .is-sortable {
    cursor: pointer;
  }

  // 过滤
  .is-filterable {
    cursor: inherit;
  }

  // 升序
  .ascending {
    .#{$name}-header--ascending {
      color: var(--ivue-primary-color);
    }
  }

  // 降序
  .descending {
    .#{$name}-header--descending {
      color: var(--ivue-primary-color);
    }
  }

  // 头部
  &-header {
    table-layout: fixed;
    border-collapse: separate;

    &--wrapper {
      overflow: hidden;
      width: 100%;
      flex-shrink: 0;
    }

    &--sortable {
      position: relative;
      display: inline-flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 24px;
      padding-left: 2px;
      cursor: pointer;

      .ivue-icon {
        width: auto;
        min-width: auto;
        height: auto;
        line-height: 1;
        font-size: 24px;
        color: var(--ivue-arrow-color);
        margin: initial;
        height: 8px;
        overflow: hidden;
      }
    }
  }

  // 边框
  &-border {
    .#{$name}-content {
      &::after {
        content: '';
        position: absolute;
        background-color: var(--ivue-border-color);
      }
    }

    .#{$name}-cell {
      border-right: 1px solid var(--ivue-border-color);
      border-bottom: 1px solid var(--ivue-border-color);
    }

    .#{$name}-footer--wrapper {
      position: relative;
      flex-shrink: 0;
      margin-top: -2px;
    }

    &::before {
      content: '';
      position: absolute;
      top: -1px;
      left: 0;
      width: 1px;
      height: 100%;
      background-color: var(--ivue-border-color);
      z-index: 3;
    }

    &::after {
      content: '';
      position: absolute;
      top: -1px;
      right: 0;
      width: 1px;
      height: 100%;
      background-color: var(--ivue-border-color);
      z-index: 3;
    }
  }

  // 列
  &-column {
    // 拖拽时的虚线
    &-resize-proxy {
      position: absolute;
      left: 200px;
      top: 0;
      bottom: 0;
      width: 0;
      border-left: 1px solid var(--ivue-border-color);
      z-index: 10;
    }
  }

  // body
  &-body-wrapper {
    position: relative;
    overflow: hidden;
    width: 100%;
  }

  &-body {
    border-collapse: separate;

    .highlight-current-row > .ivue-table-cell {
      background-color: rgba(91, 142, 255, 0.3);
    }
  }

  // 提示
  &-placeholder {
    position: sticky;
    left: 0;
    right: 0;
    min-height: 60px;
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;

    &--text {
      line-height: 60px;
      width: 50%;
      color: var(--#{$name}-placeholder-color);
    }
  }

  // 行 hover 有固定列的时候触发
  &-row.hover-row {
    .#{$name}-cell {
      background-color: var(--#{$name}-row-hover-cell-bg);
    }
  }

  // 斑马纹
  &-stripe {
    .#{$name}-body {
      tr.#{$name}-row--stripe td.#{$name}-cell {
        background: var(--#{$name}-stripe-body-cell-bg);
      }
    }
  }

  // 行hover
  &-nofixed-row-hover {
    .#{$name}-body tr:hover > td.#{$name}-cell {
      background-color: var(--#{$name}-row-hover-cell-bg);
    }
  }

  &-nofixed-row-transition {
    .#{$name}-body td.#{$name}-cell {
      transition: background-color 0.25s ease;
    }
  }

  // 固定列右边, 固定列左边
  &-fixed-column--right,
  &-fixed-column--left {
    position: sticky !important;
    z-index: 2;
    background-color: var(--ivue-white-color);
  }

  // 固定列右边
  &-fixed-column--right.is-first-column::before {
    left: -10px;
  }

  // 固定列左边
  &-fixed-column--left.is-last-column::before {
    right: -10px;
  }

  // 多行表头
  &-group {
    .is-group {
      th.ivue-table-cell {
        background: var(--#{$name}-group-cell-bg);
      }
    }
  }

  .cell.#{$name}-tooltip {
    white-space: nowrap;
    min-width: 50px;
    overflow: hidden;
  }

  .ivue-tooltip {
    display: flex;
  }

  .ivue-tooltip-arrow {
    &::after {
      display: none;
    }
  }

  // 过滤弹窗
  &-filter-panel {
    cursor: pointer;
    padding: 0 !important;

    &-icon {
      display: flex;
      overflow: hidden;
      width: auto;
      min-width: auto;
      height: auto;
      font-weight: initial;
      transition: all 0.2s ease-in-out;
      transform-origin: center center;
      color: var(--ivue-arrow-color);
    }

    &-visible {
      transform: rotate(180deg);
    }

    &-content {
      min-width: 100px;
    }

    &-checkbox-group {
      padding: 10px;

      .ivue-checkbox-group--item {
        display: flex;
        align-items: center;
        margin-right: 5px;
        margin-bottom: 12px;
        margin-left: 5px;
        height: unset;

        &:last-child {
          margin-bottom: 0;
        }
      }

      .ivue-checkbox-label-text {
        padding-left: 6px;
      }
    }

    // 底部
    &-bottom {
      border-top: 1px solid var(--ivue-border-color);
      padding: 8px;

      button {
        background: 0 0;
        border: none;
        color: var(--ivue-text-color);
        cursor: pointer;
        font-size: 13px;
        padding: 0 3px;
        transition: var(--ivue-all-transition);

        &:hover {
          color: var(--ivue-primary-color);
        }
      }

      .is-disabled {
        color: var(--ivue-disabled-color) !important;
        cursor: not-allowed;
      }
    }

    // 筛选单选列表
    &-list {
      padding: 5px 0;
      margin: 0;
      list-style: none;
      min-width: 100px;

      &--item {
        line-height: 36px;
        padding: 0 10px;
        cursor: pointer;
        font-size: 14px;
        transition: all $ivue-transition-default;

        &:hover {
          color: var(--ivue-primary-color);
          background: rgba(91, 142, 255, 0.1);
        }
      }

      // 激活
      &--active {
        color: var(--ivue-white-color) !important;
        background: var(--ivue-primary-color) !important;
      }
    }

    .ivue-scrollbar-wrapper {
      max-height: 280px;
    }

    .ivue-tooltip-inner {
      padding: 0;
      border: 1px solid var(--ivue-border-color);
    }
  }

  // 展开
  &--expand {
    // icon
    &-icon {
      position: relative;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      color: var(--ivue-arrow-color);
      font-size: 12px;
      transition: all $ivue-transition-default;
      height: 20px;
      cursor: pointer;
      vertical-align: middle;

      .ivue-icon {
        display: inline-block;
        width: auto;
        height: auto;
        min-width: auto;
        font-size: 20px;
        vertical-align: initial;
      }

      // 展开完成
      &__expandend {
        transform: rotate(90deg);
      }
    }

    // 单元格
    &-cell {
      transition: all $ivue-transition-default;

      &:hover {
        background-color: transparent !important;
      }
    }
  }

  // 树节点缩进
  &-indent {
    &--placeholder {
      display: inline-block;
      width: 20px;
    }
  }

  &-circular {
    width: 15px;
    height: 15px;
    animation: loading-rotate 2s linear infinite;

    .path {
      animation: loading-dash 1.5s ease-in-out infinite;
      stroke-dasharray: 90, 150;
      stroke-dashoffset: 0;
      stroke-width: 3;
      stroke: var(--ivue-arrow-color);
      stroke-linecap: round;
    }
  }

  // 底部
  &-footer {
    table-layout: fixed;
    border-collapse: separate;

    &--wrapper {
      overflow: hidden;
      width: 100%;

      tbody td.#{$name}-cell {
        background-color: var(--#{$name}-row-hover-cell-bg);
        color: var(--ivue-text-color);
      }
    }
  }
}

// 滚动
@keyframes loading-rotate {
  100% {
    transform: rotate(360deg);
  }
}

// 圆形滚动样式
@keyframes loading-dash {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }

  50% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -40px;
  }

  100% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -120px;
  }
}

// 固定列右边
.#{$name}.is-scrolling-left,
.#{$name}.is-scrolling-middle {
  .#{$name}-fixed-column--right.ivue-table-cell {
    border-left: none;
  }

  .#{$name}-fixed-column--right.is-first-column {
    &::before {
      content: '';
      position: absolute;
      top: 0;
      width: 10px;
      bottom: -1px;
      overflow-x: hidden;
      overflow-y: hidden;
      box-shadow: none;
      touch-action: none;
      pointer-events: none;
      box-shadow: inset -10px 0 10px -10px rgba(0, 0, 0, 0.15);
    }
  }
}

// 固定列左边
.#{$name}.is-scrolling-right,
.#{$name}.is-scrolling-middle {
  .#{$name}-fixed-column--left.ivue-table-cell {
    border-right: none;
  }

  .#{$name}-fixed-column--left.is-last-column {
    &::before {
      content: '';
      position: absolute;
      top: 0;
      width: 10px;
      bottom: -1px;
      overflow-x: hidden;
      overflow-y: hidden;
      box-shadow: none;
      touch-action: none;
      pointer-events: none;
      box-shadow: inset 10px 0 10px -10px rgba(0, 0, 0, 0.15);
    }
  }
}
