@import '~@gmfe/react/src/var.less';
@import './variables.less';

@gm-table-x-header-bg: #e8eaf0;
@gm-table-x-border-color: rgba(216, 222, 231, 0.5);
@gm-table-x-sort-color: #ccc;
@gm-table-x-sort-active-color: #999;
@gm-table-x-select-color: rgba(36, 51, 81, 0.8);
@gm-table-x-select-action-bar-height: 50px;

.gm-table-x {
  border-bottom: 1px solid @gm-table-x-border-color;
  overflow: auto;
  position: relative;

  .gm-table-x-table {
    // 性能考虑
    z-index: 1;
    transform: translateZ(0);
    display: block; // 覆盖table 默认display

    .gm-table-x-tr {
      display: flex;
      min-height: 60px;

      .gm-table-x-th {
        background: @gm-table-x-header-bg;
        display: flex;
        flex-direction: column;
        justify-content: center;
        color: @gm-color-first;
        font-weight: bold;
      }

      .gm-table-x-td {
        display: flex;
        flex-direction: column;
        justify-content: center;
      }

      .gm-table-x-th,
      .gm-table-x-td {
        flex: 1 0;
        padding: 8px;
        white-space: normal;
        word-wrap: break-word;
        word-break: break-all;

        &.gm-table-x-icon-column {
          padding-right: 5px;
          padding-left: 5px;
          .gm-table-x-icon.gm-popover-active {
            color: @brand-primary;
          }
        }

        &:first-child {
          padding-left: 20px;
        }

        &:last-child {
          padding-right: 20px;
        }

        .gm-table-x-expand {
          font-size: 14px;
          padding-top: 2px;
        }
      }
    }

    .gm-table-x-thead {
      position: sticky;
      top: 0;
      z-index: 10;
      display: block; // 覆盖thead 默认display

      .gm-table-x-tr {
        min-height: 46px;
      }
    }

    .gm-table-x-tbody {
      display: block; // 覆盖tbody 默认display

      .gm-table-x-tr {
        &.gm-table-x-tr-even {
          .gm-table-x-td {
            background: @gm-back-body-bg;
          }
        }

        &.gm-table-x-tr-odd {
          .gm-table-x-td {
            background: white;
          }
        }

        &.sortable-chosen {
          .gm-table-x-tr {
            .gm-table-x-td {
              background-color: @table-bg-hover;
            }
          }
        }
      }

      // disable
      .gm-table-x-tr-disable.gm-table-x-tr {
        .gm-table-x-td {
          background-color: @gm-bg-disabled !important;
        }
      }

      // 高亮
      .gm-table-x-tr-highlight.gm-table-x-tr {
        .gm-table-x-td {
          background-color: @table-bg-hover !important;
        }
      }

      // 拖拽的时候没有hover效果
      &:not(.gm-table-x-sortable-active) {
        .gm-table-x-tr {
          &:hover {
            .gm-table-x-td {
              background-color: @table-bg-hover;
            }
          }
        }
      }
    }

    /* sort */
    // 排序样式
    .gm-table-x-sort-header {
      position: relative;
      padding: 0 8px;

      &::before {
        content: '';
        position: absolute;
        right: 4px;
        bottom: 8px;
        width: 0;
        height: 0;
        border-top: 4px solid transparent;
        border-right: 4px solid transparent;
        border-bottom: 6px solid @gm-table-x-sort-color;
        border-left: 4px solid transparent;
      }

      &::after {
        content: '';
        position: absolute;
        right: 4px;
        bottom: -3px;
        width: 0;
        height: 0;
        border-top: 6px solid @gm-table-x-sort-color;
        border-right: 4px solid transparent;
        border-bottom: 4px solid transparent;
        border-left: 4px solid transparent;
      }

      &.gm-table-x-sort-header-asc {
        &::before {
          border-bottom: 5px solid @gm-table-x-sort-active-color;
        }
      }

      &.gm-table-x-sort-header-desc {
        &::after {
          border-top: 5px solid @gm-table-x-sort-active-color;
        }
      }
    }

    /* sort end */

    /* resizer */

    .gm-table-x-resizer {
      position: absolute;
      width: 10px;
      right: -5px;
      top: 0;
      bottom: 0;
      z-index: 1;
    }

    // 最后一个需要去掉
    // stylelint-disable-next-line
    .gm-table-x-th {
      // stylelint-disable-next-line
      &:last-child {
        .gm-table-x-resizer {
          display: none;
        }
      }
    }

    /* resizer end */

    /* fixed */

    .gm-table-x-th,
    .gm-table-x-td {
      &.gm-table-x-fixed-left,
      &.gm-table-x-fixed-right {
        position: sticky !important;
        z-index: 1;
      }

      &.gm-table-x-fixed-left {
        border-right: 1px solid @gm-table-x-border-color !important;
      }

      &.gm-table-x-fixed-right {
        border-left: 1px solid @gm-table-x-border-color !important;
      }
    }
  }

  &.gm-table-x-empty {
    min-height: 166px;
  }

  &.gm-table-x-tiled {
    border-left: 1px solid @gm-table-x-border-color;
    border-right: 1px solid @gm-table-x-border-color;
  }

  // edit button 和 gm-table-x-edit 没有关系，只是名字相近
  .gm-table-x-edit-button {
    visibility: hidden;
    font-size: 14px;
    display: inline-block;
    cursor: pointer;
    width: 20px;

    &[disabled] {
      cursor: not-allowed;
    }

    &:hover {
      color: @brand-primary;
    }

    &.gm-popover-active {
      visibility: visible;
      color: @brand-primary;
    }
  }

  .gm-table-x-tr:hover {
    .gm-table-x-edit-button {
      visibility: visible;
    }
  }
}

/* hoc 相关 */
.gm-table-x-select-batch-action-bar-container {
  position: relative;

  .gm-table-x-select-batch-action-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 10;
    padding-left: 20px;
    background: @gm-back-body-bg;
    height: @gm-table-x-select-action-bar-height;
  }
}

.gm-table-x-sub-table {
  border: 1px solid @brand-primary;
  background: @gm-back-body-bg;

  .gm-table-x-th {
    background: @gm-back-body-bg !important;
    border-bottom: 1px solid @gm-table-x-border-color;

    &:first-child {
      border-bottom: transparent !important;
    }
  }

  .gm-table-x-td {
    border-bottom: 1px solid @gm-table-x-border-color;
    background: transparent !important;

    &:first-child {
      border-bottom: transparent !important;
    }
  }
}

.gm-table-x-edit-table {
  // action
  .gm-table-x-edit-action-add {
    display: inline-block;
    margin-right: 18px;
    cursor: pointer;
    color: @brand-primary;

    svg {
      width: 20px;
      height: 20px;
    }

    &.disabled {
      color: fadeout(@brand-primary, 50%);
      cursor: not-allowed;
    }
  }

  .gm-table-x-edit-action-delete {
    display: inline-block;
    color: @brand-danger;
    cursor: pointer;

    svg {
      width: 20px;
      height: 20px;
    }

    &.disabled {
      color: fadeout(@brand-danger, 50%);
      cursor: not-allowed;
    }
  }

  // 耦合其他组件
  .gm-table-x-td {
    .gm-input {
      .gm-table-x-edit-table-common-input();
    }

    .gm-input-number {
      .gm-table-x-edit-table-common-input();
    }

    .gm-more-select {
      .gm-more-select-selected {
        .gm-table-x-edit-table-common-input();

        padding-top: 0;
        padding-bottom: 0;

        .gm-more-select-clear-btn {
          padding: 0;
          right: 5px;
        }
      }
    }

    .gm-select {
      display: block;

      .gm-selection-selected {
        .gm-table-x-edit-table-common-input();

        line-height: 22px;
        padding-right: 20px;
      }
    }

    .gm-selected {
      input {
        .gm-table-x-edit-table-common-input();

        padding-right: 20px;
      }
    }

    .gm-selection {
      input {
        .gm-table-x-edit-table-common-input();

        padding-right: 20px;
      }
    }
  }

  // action
  .gm-react-edit-table-action-add {
    width: 20px;
    height: 20px;
    color: @brand-primary;
    margin-right: 18px;
    cursor: pointer;

    &.disabled {
      color: fadeout(@brand-primary, 50%);
      cursor: not-allowed;
    }
  }

  .gm-react-edit-table-action-delete {
    width: 20px;
    height: 20px;
    color: @brand-danger;
    cursor: pointer;

    &.disabled {
      color: fadeout(@brand-danger, 50%);
      cursor: not-allowed;
    }
  }
}

.gm-react-table-x-diy-modal {
  width: 900px;

  .gm-react-table-x-diy-modal-header {
    .gm-react-table-x-diy-modal-header-title {
      font-size: 14px;
      border-left: 3px solid @brand-primary;
    }

    .gm-react-table-x-diy-modal-header-close {
      font-size: 16px;
      color: #000923;
      text-shadow: 0 1px 0 #fff;
      font-weight: bold;
      transition: color 0.5s;
      border: none;
    }
  }

  .gm-react-table-x-diy-modal-content{
    border-top: 1px solid @gm-table-x-border-color;
    border-bottom: 1px solid @gm-table-x-border-color;
  }

  .gm-react-table-x-diy-modal-title {
    background-color: @gm-back-body-bg;
    border-bottom: 1px solid @gm-table-x-border-color;
  }

  .gm-react-table-x-diy-modal-selector {
    & > div {
      padding: 10px;
    }

    width: 80%;
    border-right: 1px solid @gm-table-x-border-color;
  }

  .gm-react-table-x-diy-modal-list {
    & > div {
      padding: 10px;
    }

    width: 20%;

    .gm-react-table-x-diy-modal-list-ul {
      list-style-type: none;
      padding: 0;
      margin: 30px 0;
      max-height: 400px;
      overflow: auto;

      .gm-react-table-x-diy-modal-list-li {
        position: relative;
        user-select: none;
        padding: 5px 10px;

        &::before {
          content: '\2022'; //圆点
          font-size: 16px;
          margin-right: 2px;
        }

        .gm-react-table-x-diy-modal-list-li-remove {
          position: absolute;
          top: 10px;
          right: 0px;
          width: 14px;
          height: 14px;
        }
      }

      .gm-react-table-x-diy-modal-list-li.active {
        background: #d7e8fc;
      }

      .gm-react-table-x-diy-modal-list-li:hover {
        background: #d7e8fc;
      }
    }
  }
}

@media (max-width: 768px) {
  .gm-react-table-x-diy-modal {
    width: 600px;
  }
}

/* 耦合其他组件 */

// stylelint-disable-next-line
.gm-table-x {
  // select 样式
  .gm-table-x-select:not(.disabled) {
    input:not(:checked) + span {
      border-color: @gm-table-x-select-color;
    }
  }
}
