@import './theme/default';
@import './theme/font';

$fixed-right-column-box-shadow: -4px 0 8px -4px rgba($shadow-color, 0.1);
$fixed-left-column-box-shadow: 4px 0 8px -4px rgba($shadow-color, 0.1);

.zent-grid {
  @include theme-color(color, stroke, 1);
  font-size: $font-size-normal;
  position: relative;
  line-height: 1.5;
  overflow: hidden;

  &.zent-grid-scroll-position-left {
    .zent-grid-fixed-left {
      box-shadow: none;
    }
  }

  &.zent-grid-scroll-position-right {
    .zent-grid-fixed-right {
      box-shadow: none;
    }
  }

  &-fixed-layout table {
    table-layout: fixed;
  }

  &-table {
    width: 100%;
    text-align: left;
    border-collapse: collapse;
    border-spacing: 0;

    &-ellipsis {
      table-layout: fixed;

      .zent-grid-nowrap {
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }

    &-small {
      .zent-grid-td {
        padding: 4px 12px;
      }
    }

    &-medium {
      .zent-grid-td {
        padding: 8px 12px;
      }
    }

    &-large {
      .zent-grid-td {
        padding: 16px 12px;
      }
    }
  }

  &-bordered {
    table {
      border-collapse: collapse;
    }

    th,
    td {
      @include theme-color(border-color, stroke, 6);
      border-width: 1px;
      border-style: solid;
      border-top: 0;

      &:first-child {
        border-left: 0;
      }

      &:last-child {
        border-right: 0;
      }
    }
  }

  &-without-size {
    tr {
      height: 56px;
    }
  }

  &-text-align-left {
    text-align: left;
  }

  &-text-align-right {
    text-align: right;

    .zent-grid-thead-sort {
      margin-right: 16px;
    }
  }

  &-text-align-center {
    text-align: center;
  }

  &-thead {
    .caret-up,
    .caret-down {
      position: absolute;
      left: 6px;
      font-size: 12px;
      @include theme-color(color, stroke, 3);
    }

    .caret-up {
      top: 0;
    }

    .caret-down {
      bottom: 0;
    }

    &-sort {
      position: relative;

      &-btn {
        position: relative;
        display: flex;
      }
    }

    &-sort-desc,
    &-sort-asc {
      cursor: pointer;
    }

    &-sort-desc {
      .caret-down {
        @include theme-color(color, primary, 4);
      }
    }

    &-sort-asc {
      .caret-up {
        @include theme-color(color, primary, 4);
      }
    }
  }

  &-thead > tr > th {
    &[colspan] {
      text-align: center;
    }
  }

  &-fixed {
    width: auto;
  }

  &-fixed-left,
  &-fixed-right {
    position: absolute;
    top: 0;
    overflow: hidden;

    .zent-grid-fixed {
      border-left: 0;
      border-right: 0;
    }

    table {
      width: auto;
    }
  }

  &-fixed-left {
    left: 0;
    // FIXME: 为了让fix住的部分底部阴影去除
    box-shadow: $fixed-left-column-box-shadow;

    .zent-grid-header .zent-grid-table {
      border-right: 0;
    }

    .zent-grid-body {
      margin-right: -20px;
      box-sizing: border-box;
      margin-bottom: -15px;
      overflow: scroll;
    }
  }

  &-fixed-right {
    right: 0;
    // FIXME: 为了让fix住的部分底部阴影去除
    box-shadow: $fixed-right-column-box-shadow;

    .zent-grid-header .zent-grid-table {
      border-left: 0;
    }

    .zent-grid-body .zent-grid-table {
      border-left: 0;
    }

    .zent-grid-body {
      box-sizing: border-box;
      margin-bottom: -15px;
      overflow: scroll;
    }
  }

  &-scroll {
    overflow: auto;

    table {
      width: auto;
      min-width: 100%;
    }

    .zent-grid-header {
      overflow-x: scroll;
      margin-bottom: -15px;
      padding-bottom: 15px;
    }

    .zent-grid-body {
      position: relative;
    }
  }

  &-empty {
    @include theme-color(border-bottom-color, stroke, 6);
    text-align: center;
    height: 50px;
    line-height: 50px;
    border-bottom-width: 1px;
    border-bottom-style: solid;
  }

  &-tr {
    @include theme-color(background-color, stroke, 9);
    display: table-row;

    &:hover,
    &__mouseover {
      @include theme-color(background-color, primary, 8);
    }

    &__expanded {
      td {
        @include theme-color(background-color, stroke, 8);
        padding: 10px 12px;
        word-break: break-all;
      }
    }
  }

  &-tr__disable-highlight {
    &:hover {
      @include theme-color(background-color, stroke, 9);
    }
  }

  &-th,
  &-td {
    @include theme-color(border-bottom-color, stroke, 6);
    font-size: $font-size-normal;
    display: table-cell;
    box-sizing: border-box;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    vertical-align: middle;
    overflow-wrap: break-word;
  }

  &-th {
    @include theme-color(background-color, stroke, 8);
    line-height: 20px;
    padding: 8px 12px;
    font-weight: 500;

    &:first-child {
      padding: 8px 12px;
    }

    &:last-child {
      padding: 8px 12px;
    }

    &-break-word {
      word-break: break-word;
    }

    &.zent-grid-nowrap {
      white-space: nowrap;
      word-break: keep-all;
    }
  }

  &-th.zent-grid-th-sortable {
    position: relative;
    cursor: pointer;

    &:hover {
      &::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.05);
      }
    }
  }

  &-th.zent-grid-th-selection,
  &-td.zent-grid-td-selection,
  &-th.zent-grid-th-expand,
  &-td.zent-grid-td-expand {
    padding-right: 0;
  }

  &-td {
    line-height: 20px;
    position: relative;

    .zent-grid-expandable-btn {
      cursor: pointer;
      display: inline-block;
      width: 16px;
      height: 16px;
      font-size: 16px;
      text-align: center;
      user-select: none;
    }

    &-multiple-row {
      @include theme-color(border-color, stroke, 6);
      border-left-width: 1px;
      border-right-width: 1px;
      border-style: solid;
    }
  }

  &-tfoot {
    margin-top: 16px;
    overflow: hidden;

    .zent-grid-tfoot-page {
      margin-top: 0;
    }

    .zent-grid-batch.zent-grid-batch--fixed {
      @include theme-color(background-color, stroke, 9);
      @include theme-color(border-color, stroke, 6);
      position: fixed;
      left: unset;
      z-index: 1;
      bottom: 0;
      padding-top: 12px;
      box-sizing: border-box;
      border-top-width: 1px;
      border-top-style: solid;
    }
  }

  &-tfoot-page {
    margin-top: 10px;
    float: right;
  }

  a {
    @include theme-color(color, primary, 4);
    cursor: pointer;
  }

  .zent-grid-batch {
    padding-left: 12px;
    padding-bottom: 12px;
    display: flex;
    align-items: center;

    .batch-component {
      line-height: 20px;
      margin-right: 8px;

      &:last-child {
        margin-right: 0;
      }
    }
  }

  .zent-grid-batch__foot {
    float: left;
  }

  &-selection-checkbox {
    position: absolute;
    top: 50%;
    transform: translate(0, -50%);
    line-height: 1;
    font-size: 0;
    display: inline-block;
    margin-top: -1px;
  }

  .zent-grid-sticky-header {
    overflow-x: scroll;
  }

  .zent-grid-sticky-header-warp {
    position: absolute;
  }
}
