@import '~rc-table/assets/index.css';

.rc-table.ebs-table {
  box-shadow: $table-box-shadow;

  // FIXME: Fix table on mobile
  // @include mq($until: desktop) {
  //   display: none;
  // }

  &--small td {
    padding: rem($base-size $gutter-size);
  }

  &__th--filtered {
    cursor: pointer;
    transition: $transition-time;

    &-desc .ebs-icon {
      transform: rotate(180deg);
    }

    &:hover,
    &-asc,
    &-desc {
      color: $table-filter-active-color;

      .ebs-icon {
        color: $table-filter-active-color;
      }
    }

    .ebs-icon {
      position: relative;
      top: 0;
      color: currentColor;
      font-size: rem($table-body-font-size);
      transition: $transition-time;
      margin-left: rem(6px);
    }
  }

  .is-action {
    width: rem(80px);

    .ebs-action__wrapper {
      float: right;
    }
  }

  .rc-table-thead tr:first-child th.rc-table-cell {
    border-top: none;
  }

  .rc-table-thead tr:not(:first-child) th.rc-table-cell {
    border: $table-border;
    border-top: none;
    border-right: none;
    border-bottom: $table-head-cell-bottom-border;
  }

  .rc-table-tbody tr.rc-table-row {
    td.rc-table-cell {
      word-break: normal;
      border: $table-body-cell-border;
      transition: $transition-time;
      text-align: $table-body-cell-text-align;
      font-size: rem($table-body-font-size);
      white-space: nowrap;

      &:not(:last-child) {
        border-right: none;
      }
    }

    &:nth-child(odd) td.rc-table-cell {
      background-color: $table-body-cell-odd-background;
    }

    &:hover:nth-child(odd) td.rc-table-cell,
    &:hover:nth-child(even) td.rc-table-cell {
      background-color: $table-body-cell-hover-background;
    }

    &:last-child td {
      border-bottom: $table-border;
    }
  }

  &-mobile {
    display: none;

    @include mq($until: desktop) {
      display: block;
    }

    &__item {
      @include elevation-2;
      position: relative;
      border: $table-body-mobile-cell-border;
      border-radius: rem($border-radius);
      background-color: $table-head-background;
      display: flex;
      flex-wrap: wrap;

      &-key {
        font-size: rem($gutter-size);
        position: absolute;
        top: rem($gutter-size);
        right: rem($gutter-size);
        color: $grey-400;
      }

      &-title {
        padding: rem($gutter-size $gutter-size) calc(#{rem($gutter-size)} / 2);
        font-size: rem($table-body-font-size);
        width: 100%;
      }

      &-desc {
        padding: rem(0 $gutter-size $gutter-size);
        width: 100%;
      }

      &-desc:not(:last-child) {
        border-bottom: $table-body-mobile-cell-border;
      }

      &-child {
        padding: rem($gutter-size);
        width: 50%;

        &-title {
          display: block;
          font-size: rem($table-body-font-size);
          margin-bottom: rem(5px);
          color: $grey-400;
        }

        &:nth-child(even) {
          border-right: $table-body-mobile-cell-border;
        }

        &:last-child {
          border-right: unset;
          width: 100%;
        }
      }

      &-action {
        width: 100%;
        border-top: $table-body-mobile-cell-border;
        border-bottom-left-radius: $border-radius;
        border-bottom-right-radius: $border-radius;
        color: $white;
        display: flex;
        align-items: center;
        text-align: center;
        padding: rem($gutter-size 5px);

        > * {
          width: 100%;
          display: block;
        }

        > .flex {
          display: flex;
          width: 100%;
          align-items: center;
          justify-content: center;
        }
      }

      &:not(:last-child) {
        margin-bottom: rem($gutter-size);
      }
    }

    .ebs-button__wrapper {
      width: 100%;
      border-top-left-radius: 0;
      border-top-right-radius: 0;
    }

    .ebs-action__wrapper {
      @include flex-center;
      position: relative;
    }
  }

  .rc-table-content {
    border: 1px solid $border-color;
    overflow: auto hidden;
  }

  .rc-table-expanded-row {
    .rc-table-cell {
      box-shadow: none;
      padding: 0;

      .flex-item {
        border-bottom: none;
      }
    }
  }

  th,
  td {
    border-color: $border-color;
    border-right: none;
    padding: rem(22px 16px);
  }

  td {
    @include fontMedium;
    color: $text-color;

    a {
      color: var(--primary-color);
    }

    b,
    strong {
      @include fontBold;
    }

    .ebs-time__period-cell > div > .ebs-info {
      display: inline-block;
    }

    .ebs-time__period-cell > div > .ebs-info:not(:first-child) {
      padding-left: rem($table-body-font-size);

      .ebs-info__icon {
        display: none;
      }
    }

    .ebs-time__period-cell > div > .ebs-info:not(:last-child) {
      margin-right: rem($table-body-font-size);
    }
  }

  .rc-table-thead tr {
    &.rc-table-row-expand-icon-cell + th.rc-table-cell {
      padding-left: 0;
    }

    th.rc-table-cell {
      text-transform: uppercase;
      border: $table-head-cell-border;
      border-bottom: $table-head-cell-bottom-border;
      border-top: $table-border;
      position: relative;
      font-weight: $table-head-font-weight;
      text-align: $table-head-cell-text-align;
      background-color: $table-head-background;
      font-size: rem($table-head-font-size);
      color: $heading-color;
      word-break: normal;

      &.has-children {
        border: $table-border;
        border-right: none;
        border-top: none;

        + *:not(.has-children) {
          border-left: $table-border;
        }
      }
    }

    &:not(:last-child) th.rc-table-cell {
      border-right: none;
    }

    &:not(:last-child) th.rc-table-cell {
      border-right: none;
    }

    &:not(:first-child) th.rc-table-cell {
      border-left: $table-border;
    }
  }
}

.table-no-border {
  .rc-table-header,
  .rc-table-body,
  .rc-table-content {
    border: 0 !important;
  }

  .rc-table-tbody tr.rc-table-row:last-child td {
    border-bottom: 0 !important;
  }
}
