@import '../../style/themes/default';
@import '../../style/mixins/index';

@table-prefix-cls: ~'@{c7n-prefix}-table';
@select-prefix-cls: ~'@{c7n-prefix}-select';
@checkbox-prefix-cls: ~'@{c7n-prefix}-checkbox';
@table-header-icon-color: @text-color-secondary;

.@{table-prefix-cls}-wrapper {
  .clearfix;
  position: relative;
}

.@{table-prefix-cls} {
  .reset-component;
  position: relative;
  clear: both;

  &-body {
    transition: opacity @animation-duration-slow;
  }

  &.resizable-table&-empty .react-resizable {
    .column-resizable-handle {
      display: none;
    }
  }

  &.resizable-table .react-resizable {
    position: relative;

    .column-resizable-handle {
      position: absolute;
      top: 0;
      right: -0.01rem;
      bottom: 0;
      z-index: 100;
      width: 0.06rem;
      cursor: col-resize;

      &:hover, &.react-draggable-dragging {
        background-color: #ccc;
      }
    }
  }

  &.resizable-table &-thead th,
  &.resizable-table &-tbody td {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  table {
    width: 100%;
    text-align: left;
    border-radius: @border-radius-base @border-radius-base 0 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  &-thead > tr > th {
    color: @heading-color;
    font-weight: 500;
    text-align: left;
    background-color: @table-header-bg;
    border-bottom: @border-width-base @border-style-base @border-color-split;
    transition: background @animation-duration-slow ease;

    &[colspan] {
      text-align: center;
      border-bottom: 0;
    }

    &:hover {
      .@{table-prefix-cls}-sort-icon {
        opacity: 1;
      }
    }

    .@{table-prefix-cls}-sort-icon {
      position: relative;
      width: 0.14rem;
      margin-left: 0.08rem;
      color: @table-header-icon-color;
      font-weight: normal;
      font-size: calc(@font-size-base + 0.02rem);
      vertical-align: text-bottom;
      cursor: pointer;
      opacity: 0;
      transition: all @animation-duration-slow;
    }

    &.@{table-prefix-cls}-sort-ascend,
    &.@{table-prefix-cls}-sort-descend {
      .@{table-prefix-cls}-sort-icon {
        color: @text-color;
        opacity: 1;
      }
    }

    &.@{table-prefix-cls}-sort-descend .@{table-prefix-cls}-sort-icon {
      transform: rotate(180deg);
    }

    &.@{table-prefix-cls}-column-has-filters {
      overflow: hidden;
      cursor: pointer;
    }
  }

  &-thead > tr:first-child > th {
    &:first-child {
      border-top-left-radius: @border-radius-base;
    }

    &:last-child {
      border-top-right-radius: @border-radius-base;
    }
  }

  &-tbody > tr > td {
    border-bottom: @border-width-base @border-style-base @border-color-split;
    transition: all @animation-duration-slow;
  }

  &-thead > tr,
  &-tbody > tr {
    transition: all @animation-duration-slow;

    &.@{table-prefix-cls}-row-hover,
    &:hover {
      & > td {
        background-color: @table-row-hover-bg;
      }
    }
  }

  &-thead > tr:hover {
    background: none;
  }

  &-footer {
    position: relative;
    padding: @table-padding-vertical @table-padding-horizontal;
    background-color: @table-header-bg;
    border-top: @border-width-base @border-style-base @border-color-split;
    border-radius: 0 0 @border-radius-base @border-radius-base;

    &::before {
      position: absolute;
      top: -0.01rem;
      left: 0;
      width: 100%;
      height: 0.01rem;
      background-color: @table-header-bg;
      content: '';
    }
  }

  &.@{table-prefix-cls}-bordered &-footer {
    border: @border-width-base @border-style-base @border-color-split;
  }

  &-title {
    position: relative;
    top: 0.01rem;
    padding: @table-padding-vertical 0;
    border-radius: @border-radius-base @border-radius-base 0 0;
  }

  &.@{table-prefix-cls}-bordered &-title {
    padding-right: @table-padding-horizontal;
    padding-left: @table-padding-horizontal;
    border: @border-width-base @border-style-base @border-color-split;
  }

  &-title + &-content {
    position: relative;
    overflow: hidden;
    border-radius: @border-radius-base @border-radius-base 0 0;

    .@{table-prefix-cls}-bordered & {
      &,
      table,
      .@{table-prefix-cls}-thead > tr:first-child > th {
        border-radius: 0;
      }
    }
  }

  &-without-column-header &-title + &-content,
  &-without-column-header table {
    border-radius: 0;
  }

  &-tbody > tr.@{table-prefix-cls}-row-selected td {
    background-color: @table-selected-row-bg;
  }

  &-thead > tr > th,
  &-tbody > tr > td {
    padding: @table-padding-vertical @table-padding-horizontal;
    word-break: break-all;

    &:focus {
      background-color: @table-cell-focus-bg;
    }
  }

  &-thead > tr > th.@{table-prefix-cls}-selection-column-custom {
    width: 0.62rem !important;
    min-width: 0.62rem !important;
    padding-right: 0;
    padding-left: 0.16rem;
  }

  &-thead > tr > th.@{table-prefix-cls}-selection-column,
  &-tbody > tr > td.@{table-prefix-cls}-selection-column {
    width: 0.2rem;
    min-width: 0.2rem;
    text-align: center;

    .@{c7n-prefix}-radio-wrapper {
      margin-right: 0;
    }
  }

  &-expand-icon-th,
  &-row-expand-icon-cell {
    width: 0.5rem;
    min-width: 0.5rem;
    text-align: center;
  }

  &-header {
    overflow: hidden;
  }

  &-header table {
    border-radius: @border-radius-base @border-radius-base 0 0;
  }

  &-loading {
    position: relative;

    .@{table-prefix-cls}-body {
      background-color: @component-background;
      opacity: 0.5;
    }

    .@{table-prefix-cls}-spin-holder {
      position: absolute;
      top: 50%;
      left: 50%;
      height: 0.2rem;
      margin-left: -0.3rem;
      line-height: 0.2rem;
    }

    .@{table-prefix-cls}-with-pagination {
      margin-top: -0.2rem;
    }

    .@{table-prefix-cls}-without-pagination {
      margin-top: 0.1rem;
    }
  }

  &-column-sorter {
    position: relative;
    display: inline-block;
    width: 0.14rem;
    height: 0.14rem;
    margin-left: 0.08rem;
    color: @table-header-icon-color;
    font-weight: normal;
    text-align: center;
    vertical-align: middle;

    &-up,
    &-down {
      position: relative;
      display: block;
      width: 0.14rem;
      height: 0.06rem;
      line-height: 0.06rem;
      cursor: pointer;

      &:hover .@{iconfont-css-prefix} {
        color: @primary-4;
      }

      &.on {
        .@{iconfont-css-prefix}-caret-up,
        .@{iconfont-css-prefix}-caret-down {
          color: @primary-color;
        }
      }

      &::after {
        position: absolute;
        left: 0;
        width: 0.14rem;
        height: 0.3rem;
        content: '';
      }
    }

    &-up::after {
      bottom: 0;
    }

    &-down::after {
      top: 0;
    }

    .@{iconfont-css-prefix}-caret-up,
    .@{iconfont-css-prefix}-caret-down {
      .iconfont-size-under-12px(0.08rem);
      height: 0.04rem;
      line-height: 0.04rem;
      transition: all @animation-duration-slow;
    }
  }

  &-bordered {
    .@{table-prefix-cls}-header > table,
    .@{table-prefix-cls}-body > table,
    .@{table-prefix-cls}-fixed-left table,
    .@{table-prefix-cls}-fixed-right table {
      border: @border-width-base @border-style-base @border-color-split;
      border-right: 0;
      border-bottom: 0;
    }

    &.@{table-prefix-cls}-empty {
      .@{table-prefix-cls}-placeholder {
        border-right: @border-width-base @border-style-base @border-color-split;
        border-left: @border-width-base @border-style-base @border-color-split;
      }
    }

    &.@{table-prefix-cls}-fixed-header {
      .@{table-prefix-cls}-header > table {
        border-bottom: 0;
      }

      .@{table-prefix-cls}-body > table {
        border-top: 0;
        border-top-left-radius: 0;
        border-top-right-radius: 0;
      }

      .@{table-prefix-cls}-body-inner > table {
        border-top: 0;
      }

      .@{table-prefix-cls}-placeholder {
        border: 0;
      }
    }

    .@{table-prefix-cls}-thead > tr > th {
      border-bottom: @border-width-base @border-style-base @border-color-split;
    }

    .@{table-prefix-cls}-thead > tr > th,
    .@{table-prefix-cls}-tbody > tr > td {
      border-right: @border-width-base @border-style-base @border-color-split;
    }
  }

  &-placeholder {
    position: relative;
    z-index: 1;
    padding: @table-padding-vertical @table-padding-horizontal;
    color: @text-color-secondary;
    font-size: @font-size-base;
    text-align: center;
    background-color: @component-background;
    border-bottom: @border-width-base @border-style-base @border-color-split;

    .@{iconfont-css-prefix} {
      margin-right: 0.04rem;
    }
  }

  &-pagination.@{c7n-prefix}-pagination {
    float: right;
    margin-top: 0.16rem;
    line-height: 0.32rem;
  }

  &-filter-dropdown {
    min-width: 0.96rem;
    margin-left: -0.08rem;
    background-color: @component-background;
    border-radius: @border-radius-base;
    box-shadow: @box-shadow-base;

    .@{c7n-prefix}-dropdown-menu {
      border: 0;
      border-radius: @border-radius-base @border-radius-base 0 0;
      box-shadow: none;

      &-without-submenu {
        max-height: 4rem;
        overflow-x: hidden;
      }

      &-item > label + span {
        padding-right: 0;
      }

      &-sub {
        border-radius: @border-radius-base;
        box-shadow: @box-shadow-base;
      }

      .@{c7n-prefix}-dropdown-submenu-contain-selected {
        .@{c7n-prefix}-dropdown-menu-submenu-title::after {
          color: @primary-color;
          font-weight: bold;
          text-shadow: 0 0 0.02rem @primary-2;
        }
      }
    }

    .@{c7n-prefix}-dropdown-menu-item {
      overflow: hidden;
    }

    > .@{c7n-prefix}-dropdown-menu > .@{c7n-prefix}-dropdown-menu-item:last-child,
    > .@{c7n-prefix}-dropdown-menu
    > .@{c7n-prefix}-dropdown-menu-submenu:last-child
    .@{c7n-prefix}-dropdown-menu-submenu-title {
      border-radius: 0;
    }

    &-btns {
      padding: 0.07rem 0.08rem;
      overflow: hidden;
      border-top: @border-width-base @border-style-base @border-color-split;
    }

    &-link {
      color: @link-color;

      &:hover {
        color: @link-hover-color;
      }

      &:active {
        color: @link-active-color;
      }

      &.confirm {
        float: left;
      }

      &.clear {
        float: right;
      }
    }
  }

  &-filter-bar {
    position: relative;
    padding: 0 0.57rem 0 0;
    border-top: @border-width-base @border-style-base @border-color-base;
    border-bottom: @border-width-base @border-style-base @border-color-base;
  }

  &-filter-select {
    padding-left: 0.41rem;
    vertical-align: middle;

    &-icon {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0.16rem;
      height: 0.18rem;
      margin: auto 0;
      color: @text-color;

      & i {
        vertical-align: top;
      }
    }

    &-dropdown {
      .@{checkbox-prefix-cls}-wrapper {
        display: none;

        &.multiple {
          display: inline-block;
        }
      }
    }

    &-ok-btn {
      position: absolute !important;
      right: 0;
      bottom: 0;
      width: 100%;
      padding: 0.1rem 0.2rem !important;
      text-align: right;
      background-color: #fff;

      &:hover {
        background-color: #f5f5f5 !important;
      }
    }

    &-columns {
      display: none;
    }

    .@{select-prefix-cls} {
      width: 100%;

      &-selection {
        padding-top: 0;
      }

      &-underline {
        display: none;
      }
    }
  }

  &-columns-chooser {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 0.56rem;
    height: 0.24rem;
    margin: auto 0;
    line-height: 1;
    text-align: center;
    border-left: @border-width-base @border-style-base @border-color-base;
  }

  &-selection {
    &-select-all-custom {
      margin-right: 0.04rem !important;
    }

    .@{iconfont-css-prefix}-down {
      color: @table-header-icon-color;
      transition: all @animation-duration-slow;
    }

    &-menu {
      min-width: 0.96rem;
      margin-top: 0.05rem;
      margin-left: -0.3rem;
      background-color: @component-background;
      border-radius: @border-radius-base;
      box-shadow: @box-shadow-base;

      .@{c7n-prefix}-action-down {
        color: @table-header-icon-color;
      }
    }

    &-down {
      display: inline-block;
      padding: 0;
      line-height: 1;
      cursor: pointer;

      &:hover .@{iconfont-css-prefix}-down {
        color: #666;
      }
    }
  }

  &-row {
    &-expand-icon {
      .iconfont-font('\e5c5', 0.2rem);
      width: 0.2rem;
      height: 0.2rem;
      line-height: 1;
      transform: rotate(-90deg);
      cursor: pointer;
    }

    &-expanded {
      transform: rotate(0);
    }

    &-spaced {
      visibility: hidden;

      &::after {
        content: '.';
      }
    }

    &[class*='@{table-prefix-cls}-row-level-0'] .@{table-prefix-cls}-selection-column > span {
      display: inline-block;
    }
  }

  tr&-expanded-row {
    &,
    &:hover {
      background-color: @table-expanded-row-bg;
    }
  }

  .@{table-prefix-cls}-row-indent + .@{table-prefix-cls}-row-expand-icon {
    margin-right: 0.08rem;
    vertical-align: top;
  }

  &-scroll {
    overflow: auto;
    overflow-x: hidden;

    table {
      min-width: 100%;
    }
  }

  &-body-inner {
    height: 100%;
  }

  &-fixed-header > &-content > &-scroll > &-body {
    position: relative;
    background-color: @component-background;
  }

  &-fixed-header &-body-inner {
    overflow: scroll;
  }

  &-fixed-header &-scroll &-header {
    margin-bottom: -0.2rem;
    padding-bottom: 0.2rem;
    overflow: scroll;
  }

  &-fixed-left,
  &-fixed-right {
    position: absolute;
    top: 0;
    overflow: hidden;
    border-radius: 0;
    transition: box-shadow @animation-duration-slow ease;

    table {
      width: auto;
      background-color: @component-background;
    }
  }

  &-fixed-header &-fixed-left &-body-outer &-fixed,
  &-fixed-header &-fixed-right &-body-outer &-fixed {
    border-radius: 0;
  }

  &-fixed-left {
    left: 0;
    box-shadow: 0.06rem 0 0.06rem -0.04rem @shadow-color;

    .@{table-prefix-cls}-header {
      overflow-y: hidden;
    }

    // hide scrollbar in left fixed columns
    .@{table-prefix-cls}-body-inner {
      margin-right: -0.2rem;
      padding-right: 0.2rem;
    }

    .@{table-prefix-cls}-fixed-header & .@{table-prefix-cls}-body-inner {
      padding-right: 0;
    }

    &,
    table {
      border-radius: @border-radius-base 0 0 0;
    }

    .c7n-table-thead > tr > th:last-child {
      border-top-right-radius: 0;
    }
  }

  &-fixed-right {
    right: 0;
    box-shadow: -0.06rem 0 0.06rem -0.04rem @shadow-color;

    &,
    table {
      border-radius: 0 @border-radius-base 0 0;
    }

    // hide expand row content in right-fixed Table
    .@{table-prefix-cls}-expanded-row {
      color: transparent;
      pointer-events: none;
    }

    .c7n-table-thead > tr > th:first-child {
      border-top-left-radius: 0;
    }
  }

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

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

  &-sticky-column {
    position: sticky !important;
    z-index: 2;
    background-color: #fff;
    background-image: -webkit-gradient(linear, left top, right top, from(#fff), to(#fff));
    background-image: linear-gradient(to right, #fff 0%, #fff 100%);
    background-blend-mode: multiply;
  }

  &-thead &-sticky-column {
    background-color: @table-header-bg;
  }

  &-sticky-shadow {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 2;
    width: .1rem;
    border-color: transparent;
    transition: all @animation-duration-slow;
    pointer-events: none;
  }

  &-sticky-left&-sticky-shadow {
    border-left: @border-width-base @border-style-base @border-color-split;
    box-shadow: inset 0.06rem 0 0.06rem -0.04rem @shadow-color;
  }

  &-sticky-right&-sticky-shadow {
    border-right: @border-width-base @border-style-base @border-color-split;
    box-shadow: inset -0.06rem 0 0.06rem -0.04rem @shadow-color;
  }

  &&-scroll-position-left &-sticky-left&-sticky-shadow,
  &&-scroll-position-right &-sticky-right&-sticky-shadow {
    display: none;
  }
}

@import './size';