/**Variable**/
@import './helpers/mixin.scss';
@import './base/checked.scss';
@import './base/common.scss';
@import './base/loading.scss';

%DefaultColumnHeight {
  height: $s-table-row-height-default;
}

%MediumColumnHeight {
  height: $s-table-row-height-medium;
}

%SmallColumnHeight {
  height: $s-table-row-height-small;
}

%MiniColumnHeight {
  height: $s-table-row-height-mini;
}

%CellEllipsis {
  &:not(.col--actived) {
    .s-cell {
      @extend %TextEllipsis;
    }
  }
}

// 24 栅格布局
.s-row {
  $spans: 4.16667%, 8.33333%, 12.5%, 16.66667%, 20.83333%, 25%, 29.16667%, 33.33333%,
          37.5%, 41.66667%, 45.83333%, 50%, 54.16667%, 58.33333%, 62.5%, 66.66667%,
          70.83333%, 75%, 79.16667%, 83.33333%, 87.5%, 91.66667%, 95.83333%, 100%;
  @for $index from 0 to length($spans) {
    & > .s-col--#{$index + 1} {
      width: nth($spans, $index + 1);
    }
  }
}

.s-table-slots,
.s-table--file-form {
  display: none;
}

.s-table--print-frame {
  position: fixed;
  bottom: -100%;
  left: -100%;
  height: 0;
  width: 0;
  border: 0;
}

.s-table--body-wrapper,
.s-table--fixed-left-body-wrapper,
.s-table--fixed-right-body-wrapper {
  overflow-y: auto;
  overflow-x: auto;
}

/*默认的渲染*/
.s-cell,
.s-table--filter-wrapper {
  .s-default-input,
  .s-default-textarea,
  .s-default-select {
    outline: 0;
    padding: 0 2px;
    width: 100%;
    color: $s-font-color;
    border-radius: 4px;
    border: 1px solid $s-input-border-color;
    &:focus {
      border: 1px solid $s-primary-color;
    }
    &[disabled] {
      cursor: not-allowed;
      background-color: #f3f3f3;
    }
  }
  .s-default-input,
  .s-default-textarea,
  .s-default-select,
  .s-input {
    height: floor($s-table-row-height-default - 6);
  }
  .s-default-input {
    &[type="date"]::-webkit-inner-spin-button {
      margin-top: 6px;
    }
    &[type="date"]::-webkit-inner-spin-button,
    &[type="number"]::-webkit-inner-spin-button {
      height: 24px;
    }
    &::placeholder {
      color: $s-input-placeholder-color;
    }
  }
  .s-default-textarea {
    resize: none;
    vertical-align: middle;
  }
  .s-input,
  .s-textarea,
  .s-select {
    width: 100%;
    display: block;
  }
  .s-input > .s-input--inner,
  .s-textarea > .s-textarea--inner {
    padding: 0 2px;
  }
  .s-textarea--inner,
  .s-default-textarea {
    resize: none;
  }
}
.s-table--filter-wrapper {
  .s-default-input,
  .s-default-textarea {
    padding: 0 10px;
  }
}

/*复选框-范围选择*/
.s-table--checkbox-range {
  display: none;
  position: absolute;
  background-color: $s-table-checkbox-range-background-color;
  border: 1px solid $s-table-checkbox-range-border-color;
  border-radius: 2px;
  pointer-events: none;
}

/*table*/
.s-table {
  position: relative;
  font-size: $s-font-size;
  color: $s-font-color;
  font-family: $s-font-family;
  background-color: $s-table-background-color;
  &:before,
  &:after {
    content: "";
    position: absolute;
    left: 0;
    width: 100%;
    height: 1px;
    z-index: 2;
  }
  &:before {
    top: 0;
    border-top: 1px solid $s-table-border-color;
  }
  &:after {
    bottom: 0;
    border-bottom: 1px solid $s-table-border-color;
  }
  &[x-cloak] {
    .s-table--main-wrapper,
    .s-table--fixed-left-wrapper,
    .s-table--fixed-right-wrapper {
      visibility: hidden;
    }
  }
  .s-table--header,
  .s-table--body,
  .s-table--footer {
    border: 0;
    border-spacing: 0;
    border-collapse: separate;
    table-layout: fixed;
  }
  .s-table--header-wrapper,
  .s-table--footer-wrapper {
    overflow-x: hidden;
    overflow-y: hidden;
  }
  &:not(.is--empty) {
    &.show--foot {
      &.scroll--x {
        .s-table--body-wrapper {
          overflow-x: scroll;
        }
      }
    }
  }
  .s-body--row {
    background-color: $s-table-background-color;
    &.row--stripe {
      background-color: $s-table-row-striped-background-color;
      .s-tree--btn-wrapper {
        background-color: $s-table-row-striped-background-color;
      }
    }
    &.row--radio {
      background-color: $s-table-row-radio-background-color;
      .s-tree--btn-wrapper {
        background-color: $s-table-row-radio-background-color;
      }
    }
    &.row--cheched {
      background-color: $s-table-row-cheched-background-color;
      .s-tree--btn-wrapper {
        background-color: $s-table-row-cheched-background-color;
      }
    }
    &.row--current {
      background-color: $s-table-row-current-background-color;
      .s-tree--btn-wrapper {
        background-color: $s-table-row-current-background-color;
      }
    }
    &.row--hover {
      background-color: $s-table-row-hover-background-color;
      .s-tree--btn-wrapper {
        background-color: $s-table-row-hover-background-color;
      }
      &.row--stripe {
        background-color: $s-table-row-hover-striped-background-color;
        .s-tree--btn-wrapper {
          background-color: $s-table-row-hover-striped-background-color;
        }
      }
      &.row--radio {
        background-color: $s-table-row-hover-radio-background-color;
        .s-tree--btn-wrapper {
          background-color: $s-table-row-hover-radio-background-color;
        }
      }
      &.row--cheched {
        background-color: $s-table-row-hover-cheched-background-color;
        .s-tree--btn-wrapper {
          background-color: $s-table-row-hover-cheched-background-color;
        }
      }
      &.row--current {
        background-color: $s-table-row-hover-current-background-color;
        .s-tree--btn-wrapper {
          background-color: $s-table-row-hover-current-background-color;
        }
      }
    }
  }
  &.c--resize {
    * {
      cursor: col-resize;
    }
  }
  &.column--highlight {
    .s-header--column {
      &:not(.col--seq) {
        &:hover {
          background-color: $s-table-column-hover-background-color;
        }
      }
    }
  }
  .s-header--column,
  .s-body--column,
  .s-footer--column {
    position: relative;
    line-height: $s-table-row-line-height;
    text-align: left;
    &:not(.col--ellipsis) {
      padding: #{floor(($s-table-row-height-default - $s-table-row-line-height) / 2)} 0;
    }
    &.col--current {
      background-color: $s-table-column-current-background-color;
      .s-tree--btn-wrapper {
        background-color: $s-table-column-current-background-color;
      }
    }
    &.col--center {
      text-align: center;
    }
    &.col--right {
      text-align: right;
    }
  }
  .s-header--column {
    &.col--ellipsis {
      &.col--center {
        .s-cell{
          justify-content: center;
        }
      }
      &.col--right {
        .s-cell{
          justify-content: flex-end;
        }
      }
    }
  }
  .s-body--column {
    &.col--checkbox {
      user-select: none;
    }
  }
  .s-table--footer-wrapper {
    border-top: 1px solid $s-table-border-color;
  }
  &.border--default,
  &.border--full,
  &.border--outer {
    .s-table--header-wrapper {
      background-color: $s-table-header-background-color;
    }
  }
  &.border--default,
  &.border--inner {
    .s-header--column,
    .s-body--column,
    .s-footer--column {
      background-image: linear-gradient($s-table-border-color, $s-table-border-color);
      background-repeat: no-repeat;
      background-size: 100% 1px;
      background-position: right bottom;
    }
  }
  &.border--full {
    .s-header--column,
    .s-body--column,
    .s-footer--column {
      background-image: linear-gradient($s-table-border-color, $s-table-border-color), linear-gradient($s-table-border-color, $s-table-border-color);
      background-repeat: no-repeat;
      background-size: 1px 100%, 100% 1px;
      background-position: right top, right bottom;
    }
    .s-table--fixed-left-wrapper {
      border-right: 1px solid $s-table-border-color;
      .s-body--column{
        border-right-color: $s-table-border-color;
      }
    }
  }
  &.border--inner,
  &.border--none {
    &:before,
    .s-table--border-line {
      display: none;
    }
    .s-table--fixed-left-wrapper {
      border-right: 0;
    }
  }
  &.border--none {
    &:after,
    .s-table--header-border-line {
      display: none;
    }
  }
  &.t--selected {
    user-select: none;
  }
  &.size--medium {
    font-size: $s-font-size-medium;
    .s-header--column,
    .s-body--column,
    .s-footer--column {
      &:not(.col--ellipsis) {
        padding: #{floor(($s-table-row-height-medium - $s-table-row-line-height) / 2)} 0;
      }
    }
    .s-cell {
      .s-default-input,
      .s-default-textarea,
      .s-default-select,
      .s-input {
        height: floor($s-table-row-height-medium - 6);
      }
      .s-default-input {
        &[type="date"]::-webkit-inner-spin-button {
          margin-top: 4px;
        }
      }
    }
  }
  &.size--small {
    font-size: $s-font-size-small;
    .s-header--column,
    .s-body--column,
    .s-footer--column {
      &:not(.col--ellipsis) {
        padding: #{floor(($s-table-row-height-small - $s-table-row-line-height) / 2)} 0;
      }
    }
    .s-cell {
      .s-default-input,
      .s-default-textarea,
      .s-default-select,
      .s-input {
        height: floor($s-table-row-height-small - 6);
      }
      .s-default-input {
        &[type="date"]::-webkit-inner-spin-button {
          margin-top: 2px;
        }
      }
    }
  }
  &.size--mini {
    font-size: $s-font-size-mini;
    .s-header--column,
    .s-body--column,
    .s-footer--column {
      &:not(.col--ellipsis) {
        padding: #{floor(($s-table-row-height-mini - $s-table-row-line-height) / 2)} 0;
      }
    }
    .s-cell {
      .s-default-input,
      .s-default-textarea,
      .s-default-select,
      .s-input {
        height: floor($s-table-row-height-mini - 6);
      }
      .s-default-input {
        &[type="date"]::-webkit-inner-spin-button {
          margin-top: 0;
        }
      }
    }
  }
  .s-cell {
    white-space: normal;
    word-break: break-all;
    padding: 0 10px;
  }

  // 单选框和复选框
  .s-cell--radio {
    @extend %XERadio;
  }
  .s-cell--checkbox {
    @extend %XECheckbox;
  }
  .s-cell--radio .s-radio--icon,
  .s-cell--checkbox .s-checkbox--icon {
    left: 0;
    top: 0.1em;
  }
  .s-cell--radio .s-radio--label,
  .s-cell--checkbox .s-checkbox--label {
    padding-left: 0.5em;
  }
  .s-cell--radio,
  .s-cell--checkbox {
    padding-left: 1.2em;
  }

  .fixed--hidden {
    visibility: hidden;
  }
  .s-table--fixed-left-wrapper,
  .s-table--fixed-right-wrapper {
    width: 100%;
    position: absolute;
    top: 0;
    z-index: 1;
    overflow: hidden;
    background-color: $s-table-background-color;
    .s-table--body-wrapper {
      overflow-x: hidden;
    }
  }
  &.show--head {
    .s-table--fixed-left-wrapper,
    .s-table--fixed-right-wrapper {
      .s-table--body-wrapper {
        &:before {
          display: none;
        }
      }
   }
  }
  .s-table--fixed-left-wrapper {
    left: 0;
    width: 200px;
    &.scrolling--middle {
      box-shadow: 4px 3px 4px 0px rgba(0, 0, 0, 0.12);
    }
  }
  .s-table--fixed-right-wrapper {
    right: 0;
    &.scrolling--middle {
      box-shadow: -4px 3px 4px 0px rgba(0, 0, 0, 0.12);
    }
  }
  .s-table--header-wrapper,
  .s-table--body-wrapper,
  .s-table--footer-wrapper {
    position: relative;
    &.fixed-left--wrapper,
    &.fixed-right--wrapper {
      position: absolute;
      top: 0;
    }
    &.fixed-left--wrapper {
      left: 0;
      overflow-y: hidden;
    }
    &.fixed-right--wrapper {
      right: 0;
      overflow-y: auto;
    }
  }
  .s-body--x-space {
    width: 100%;
    height: 1px;
    margin-bottom: -1px;
  }
  .s-body--y-space {
    width: 0;
    float: left;
  }

  /*列宽线*/
  .s-table--resizable-bar {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 100%;
    z-index: 4;
    &:before {
      content: "";
      display: block;
      height: 100%;
      background-color: $s-table-resizable-color;
    }
  }

  /*边框线*/
  .s-table--border-line {
    &:before,
    &:after {
      content: "";
      position: absolute;
      top: 0;
      width: 0;
      height: 100%;
      z-index: 1;
    }
    &:before {
      left: 0;
      border-left: 1px solid $s-table-border-color;
    }
    &:after {
      right: 0;
      border-right: 1px solid $s-table-border-color;
    }
  }

  /*树形节点*/
  &.has--tree-line {
    .s-body--row {
      &:first-child {
        .s-tree--line {
          border-width: 0 0 1px 0;
        }
      }
    }
    .s-body--row {
      .s-body--column {
        background-image: none;
      }
    }
  }
  .s-tree--line-wrapper {
    position: relative;
    display: block;
    height: 0;
  }
  .s-tree--line {
    content: "";
    position: absolute;
    bottom: -0.9em;
    width: 0.8em;
    border-width: 0 0 1px 1px;
    border-style: dotted;
    border-color: $s-table-tree-node-line-color;
    pointer-events: none;
  }
  .s-cell--tree-node {
    position: relative;
  }
  .s-tree--btn-wrapper {
    position: absolute;
    top: 50%;
    width: 1em;
    height: 1em;
    text-align: center;
    transform: translateY(-50%);
    z-index: 1;
    background-color: $s-table-background-color;
    user-select: none;
    cursor: pointer;
  }
  .s-tree--node-btn {
    display: block;
    color: lighten($s-font-color, 20%);
    &:hover {
      color: $s-font-color;
    }
  }
  .s-tree-cell {
    display: block;
    padding-left: 1.5em;
  }
  .s-body--column {
    &.col--ellipsis {
      & > .s-cell {
        .s-tree-cell {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
  }

  /*展开行*/
  .s-table--expanded {
    padding-right: 0.5em;
    cursor: pointer;
    .s-table--expand-btn {
      width: 1em;
      height: 1em;
      text-align: center;
      user-select: none;
      color: lighten($s-font-color, 20%);
      &:hover {
        color: $s-font-color;
      }
    }
  }
  .s-body--expanded-column {
    border-bottom: 1px solid $s-table-border-color;
    &.col--ellipsis {
      & > .s-body--expanded-cell {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
  .s-body--expanded-cell {
    padding: 20px;
  }

  /*设置列高度*/
  &.s-editable {
    .s-body--column {
      @extend %DefaultColumnHeight;
    }
    &.size--medium {
      .s-body--column {
        @extend %MediumColumnHeight;
      }
    }
    &.size--small {
      .s-body--column {
        @extend %SmallColumnHeight;
      }
    }
    &.size--mini {
      .s-body--column {
        @extend %MiniColumnHeight;
      }
    }
  }

  /*溢出列*/
  .s-header--column,
  .s-body--column,
  .s-footer--column {
    &.col--ellipsis {
      @extend %DefaultColumnHeight;
    }
  }
  .s-body--column,
  .s-footer--column {
    &.col--ellipsis {
      @extend %CellEllipsis;
    }
  }
  &.virtual--x,
  &.virtual--y {
    .col--ellipsis {
      .s-cell {
        max-height: $s-table-row-height-default;
      }
    }
  }
  &.size--medium {
    .s-header--column,
    .s-body--column,
    .s-footer--column {
      &.col--ellipsis {
        @extend %MediumColumnHeight;
      }
    }
    &.virtual--x,
    &.virtual--y {
      .col--ellipsis {
        .s-cell {
          max-height: $s-table-row-height-medium;
        }
      }
    }
    .s-cell--checkbox .s-checkbox--icon,
    .s-cell--radio .s-radio--icon {
      font-size: $s-radio-font-size-medium;
    }
  }
  &.size--small {
    .s-header--column,
    .s-body--column,
    .s-footer--column {
      &.col--ellipsis {
        @extend %SmallColumnHeight;
        .s-cell {
          max-height: $s-table-row-height-small;
        }
      }
    }
    &.virtual--x,
    &.virtual--y {
      .col--ellipsis {
        .s-cell {
          max-height: $s-table-row-height-small;
        }
      }
    }
    .s-cell--checkbox .s-checkbox--icon,
    .s-cell--radio .s-radio--icon {
      font-size: $s-radio-font-size-small;
    }
  }
  &.size--mini {
    .s-header--column,
    .s-body--column,
    .s-footer--column {
      &.col--ellipsis {
        @extend %MiniColumnHeight;
        .s-cell {
          max-height: $s-table-row-height-mini;
        }
      }
    }
    &.virtual--x,
    &.virtual--y {
      .col--ellipsis {
        .s-cell {
          max-height: $s-table-row-height-mini;
        }
      }
    }
    .s-cell--checkbox .s-checkbox--icon,
    .s-cell--radio .s-radio--icon {
      font-size: $s-radio-font-size-mini;
    }
  }

  /*暂无数据*/
  .s-table--empty-placeholder,
  .s-table--empty-block {
    min-height: 60px;
    justify-content: center;
    align-items: center;
    text-align: center;
    overflow: hidden;
    width: 100%;
    pointer-events: none;
  }
  .s-table--empty-block {
    display: none;
    visibility: hidden;
  }
  .s-table--empty-placeholder {
    display: none;
    position: absolute;
    top: 0;
    z-index: 8;
  }
  .s-table--empty-content {
    display: block;
    width: 50%;
    pointer-events: auto;
  }
  &.is--empty {
    .s-table--empty-block,
    .s-table--empty-placeholder {
      display: flex;
    }
  }

  .s-body--column {
    &.col--selected {
      box-shadow: inset 0px 0px 0px 2px $s-primary-color;
    }
  }

  /*校验不通过*/
  .s-body--column {
    &.col--actived,
    &.col--selected,
    &.col--dirty {
      position: relative;
    }
    &.col--valid-error {
      .s-cell--valid {
        width: 320px;
        position: absolute;
        bottom: calc(100% + 4px);
        left: 50%;
        transform: translateX(-50%);
        text-align: center;
        pointer-events: none;
        z-index: 1;
        .s-cell--valid-msg {
          display: inline-block;
          border-radius: 4px;
          padding: 8px 12px;
          color: #fff;
          background-color: $s-table-validate-error-background-color;
          pointer-events: auto;
        }
      }
      .s-default-input,
      .s-default-textarea,
      .s-default-select {
        border-color: $s-table-validate-error-color;
      }
      .s-input {
        > .s-input--inner {
          border-color: $s-table-validate-error-color;
        }
      }

    }
  }
  .s-body--row {
    &:first-child {
      .s-cell--valid {
        bottom: auto;
        top: calc(100% + 4px);
      }
    }
  }

  /*可编辑*/
  &.s-editable {
    &.c--highlight {
      .s-body--column {
        &.col--actived {
          box-shadow: inset 0px 0px 0px 2px $s-primary-color;
          &.col--valid-error {
            box-shadow: inset 0px 0px 0px 2px $s-table-validate-error-color;
          }
          .s-cell {
            .s-default-input,
            .s-default-textarea {
              border: 0;
              padding: 0;
            }
            .s-default-input {
              height: $s-table-row-line-height;
            }
            .s-input {
              height: $s-table-row-line-height - 1;
              .s-input--inner {
                border: 0;
                padding-left: 0;
              }
            }
            .s-textarea {
              height: $s-table-row-line-height - 1;
              .s-textarea--inner {
                border: 0;
              }
            }
          }
        }
      }
    }
    // &.is--change {
    //   .s-header--row {
    //     &:first-child {
    //       .s-header--column {
    //         &:first-child {
    //           &:before {
    //             content: "";
    //             top: 2px;
    //             left: 2px;
    //             position: absolute;
    //             border-radius: 50%;
    //             width: 6px;
    //             height: 6px;
    //             background-color: $s-primary-color;
    //           }
    //         }
    //       }
    //     }
    //   }
    // }
    .s-body--column {
      padding: 0;
      &.col--actived {
        padding: 0;
      }
      &.col--dirty {
        &:before {
          content: "";
          top: -$s-table-cell-dirty-width;
          left: -$s-table-cell-dirty-width;
          position: absolute;
          border-width: $s-table-cell-dirty-width;
          border-style: solid;
          border-color: transparent $s-table-cell-dirty-color transparent transparent;
          transform: rotate(45deg);
        }
      }
    }
  }
  &.s-table-element .s-cell > .el {
    &-input, &-input-number, &-select, &-cascader, &-date-editor {
      width: 100%;
    }
  }
}
