@import "datatables.net-bs4/css/dataTables.bootstrap4";
@import "datatables.net-responsive-bs4/css/responsive.bootstrap4";

.table > thead > tr {
  &.hide-header {
    display: none;
  }

  > th {
    border-bottom: 0;
    color: $color-gray-15;
    font-weight: $font-weight-bold;
    line-height: 32px;

    &:focus {
      box-shadow: $outline-box-shadow rgba($default-border-color, $outline-border-opacity);
    }
  }
}

.table > tbody > tr > td {
  line-height: 31px; //31px + 1px border = 32px
}

.embla-table-wrapper {
  table.dataTable {
    margin-bottom: 0 !important;
    margin-top: 0 !important;

    tbody tr.selected {
      background-color: $color-gray-95;
    }

    td.dataTables_empty {
      padding-bottom: $padding-l;
      padding-top: $padding-l;
    }
  }

  &.no-border-top {
    border-top: 0;
  }

  .embla-pagination-wrapper {
    &.hide-pagination {
      display: none;
    }
  }

  &.hide-overflow {
    overflow: hidden;
  }
}

.dataTables_wrapper h3.datatables-title {
  margin-bottom: 0;
  margin-top: 6px;
}

table.dataTable thead {
  th {
    &.sorting::after,
    &.sorting_asc::after,
    &.sorting_desc::after {
      display: inline-block;
      font-size: 18px;
      margin-left: 8px;
      opacity: 0.7;
      right: initial;
    }

    &.sorting::after {
      @include embla-icon("sort-unset", "\21F5");
      top: 12px;
    }

    &.sorting_asc::after {
      @include embla-icon("sort-asc", "\2913");
      opacity: 1;
      top: 12px;
    }

    &.sorting_desc::after {
      @include embla-icon("sort-desc", "\2912");
      opacity: 1;
      top: 12px;
    }
  }
}

table.dataTable thead .sorting::before,
table.dataTable thead .sorting_asc::before,
table.dataTable thead .sorting_desc::before,
table.dataTable thead .sorting_asc_disabled::before,
table.dataTable thead .sorting_desc_disabled::before {
  content: "";
}

div.dataTables_wrapper {

  @include media-breakpoint-down("xs") {
    .card-body.filters-in-modal {
      .filter-button-wrapper {
        padding-right: $padding-s;

        .filter-modal-show {
          width: 100%;
        }
      }

      .search-column {
        flex-basis: 0;
        flex-grow: 1;
        padding-left: $padding-s;
      }

    }
  }

  .default-filter {
    display: inline-block;
    margin-right: 16px;
    width: 150px;
  }

  .title-row {
    .title-column {
      h3 {
        margin-top: 24px;
      }

      &.no-search-column {
        h3 {
          margin-top: 0;
        }
      }
    }
  }

  .action-column {
    padding-top: 4px;
  }

  .search-column {
    div.dataTables_filter {
      label {
        font-weight: $font-weight-bold;
        margin-bottom: 0;
      }

      input {
        display: block;
        font-size: $font-size-medium;
        font-weight: $font-weight-normal;
        margin-left: 0;
        margin-top: $margin-xxs;
        width: 100%;
      }
    }
  }

  .page-length .dataTables_length label {
    > * {
      font-size: $font-size-medium;
    }
  }

  .filter-column {
    label {
      display: block;
    }

    .form-group {
      width: 100%;
    }

    .form-control {
      width: 100%;
    }
  }


}

div.dataTables_wrapper .page-length {
  display: flex;
  flex-direction: row;

  .dataTables_length {
    margin-right: 16px;

    label {
      display: flex;
      flex-direction: column;
      font-weight: $font-weight-bold;
      margin-bottom: 0;

      span.select2.select2-container {
        margin-top: 2px;
      }
    }
  }
}

div.dataTables_wrapper div.dataTables_paginate ul.pagination {
  justify-content: center;
  margin: 0;

}

.embla-pagination-wrapper {
  background-color: $color-white;
  border-top: $default-border;
  padding-bottom: $padding-m;

  padding-top: $padding-m;

  .dataTables_paginate.paging_simple_numbers {
    line-height: 1;
  }

  .pagination {
    > li.paginate_button {
      > a {
        border-radius: 0;
      }

      &.previous {
        > a {
          border-bottom-right-radius: 0;
          border-top-right-radius: 0;
        }
      }

      &.next {
        > a {
          border-bottom-left-radius: 0;
          border-top-left-radius: 0;
        }
      }

      &.previous,
      &.next {
        > a {

          height: 32px;
          padding: 3px;
          width: 32px;

          > svg.table-pagination-icon {
            margin-bottom: -4px;
          }
        }
      }

      > a,
      > span {
        @include button-size(7px, 11px, 12px, 16px, 0);
        @include embla-button-variant($btn-default-color, $btn-default-bg, $btn-default-border, $btn-default-color, $btn-hover-default-bg, $btn-hover-default-border, $btn-active-default-color, $btn-active-default-bg, $btn-active-default-border);
        font-weight: $btn-font-weight;

        letter-spacing: $btn-letter-spacing;
      }

      &.active {
        > a,
        > span {
          @include embla-button-variant($btn-primary-color, $btn-primary-bg, $btn-primary-border, $btn-primary-color, $btn-hover-primary-bg, $btn-hover-primary-border, $btn-active-primary-color, $btn-active-primary-bg, $btn-active-primary-border);
        }
      }

      &.disabled {
        > a,
        > span {
          @include embla-button-variant(rgba($btn-default-color, $disabled-text-opacity), $btn-default-bg, rgba($btn-default-border, $disabled-opacity), rgba($btn-default-color, $disabled-text-opacity), $btn-default-bg, rgba($btn-default-border, $disabled-opacity), rgba($btn-default-color, $disabled-text-opacity), $btn-default-bg, rgba($btn-default-border, $disabled-opacity));
        }
      }

      &:first-child {
        > a,
        > span {
          border-bottom-left-radius: 50%;
          border-top-left-radius: 50%;
        }
      }

      &:last-child {
        > a,
        > span {
          border-bottom-right-radius: 50%;
          border-top-right-radius: 50%;
        }
      }
    }
  }
}

.table > thead > tr > th,
.table > thead > tr > td,
.table > tbody > tr > th,
.table > tbody > tr > td,
.table > tfoot > tr > th,
.table > tfoot > tr > td {
  border-top: $default-border;
}

.embla-responsive-child-table {
  margin-bottom: $margin-m;
  margin-left: $margin-l;
  margin-top: $margin-s;
  width: calc(100% - 64px); //64 = 2x $margin-l

  .embla-responsive-tr-border {
    border-bottom: $default-border;
  }

  tr td:first-child {
    font-weight: $font-weight-bold;
    padding-right: 16px;
  }
}


/* Responsive table */
table.responsive-table {
  white-space: nowrap;
}


table.responsive-state:not(.embla-responsive-child-table) thead tr th {
  &.details-button {
    &.actions-enabled {
      width: 60px;

      .datatable-select-all-label {
        margin-left: 38px;
      }
    }
  }
}

table.responsive-table {
  .expand-arrow {
    background: none;
    border: 0;
    margin: none;
    padding: none;

    &:focus {
      outline: none;

      &::before {
        box-shadow: $outline-box-shadow rgba($btn-default-border, $outline-border-opacity);
      }
    }
  }

  .expand-arrow.hide-arrow {
    left: -9999px;
    position: absolute;
  }
}

table.responsive-state:not(.embla-responsive-child-table) tr {
  td.details-button .expand-arrow {
    &::before {
      background: url($base-icon-path + "arrow-right.svg") no-repeat center center;
      content: "";
      cursor: pointer;
      display: inline-block;
      height: 20px;
      margin-bottom: -5px;
      margin-right: 6px;
      width: 20px;
    }
  }

  &.parent td.details-button .expand-arrow::before {
    background: url($base-icon-path + "arrow-down.svg") no-repeat center center;
  }
}


// table actions
.dataTables_wrapper {
  table:not(.embla-responsive-child-table) {
    width: 100%;
  }

  .checkbox-header-th {
    width: 28px;
  }

  td,
  th {
    &:first-child {
      padding-left: $padding-m;
    }

    &:last-child {
      padding-right: $padding-m;
    }

    &:focus {
      outline: none;
    }
  }

  .card {
    .card-body.card-body-actions-row {
      align-items: center;
      background-color: $color-gray-95;
      display: flex;
      height: 0;
      overflow: hidden;
      padding: 0;
      transition: all $default-transition;
      visibility: hidden;

      &.visible {
        height: 65px;
        visibility: visible;
      }

      .actions-row {
        padding: $padding-m;

        .selected-rows-text {
          color: $text-heading-color-subtle;
          display: inline-block;
          font-family: $font-family-headings;
          font-size: $font-size-h4;
          font-weight: $font-weight-bold;
          line-height: $line-height-h4;
          margin-left: $margin-s;
          margin-right: $margin-m;
        }

        .selected-rows-actions {
          display: inline-block;
        }
      }
    }
  }
}

.modal-filter-container {
  display: flex;

  > .filter-modal {
    .modal-filters {
      .page-length .dataTables_length > label,
      .filter-column .default-filter,
      .search-column .dataTables_filter > label {
        margin-bottom: $margin-s;
      }

      .page-length,
      > .filter-column {
        flex: inherit;
        flex-direction: column;
        max-width: inherit;
        width: 100%;

        .dataTables_length {
          margin-right: 0;
        }

        .default-filter {
          margin-right: 0;
          width: 100%;
        }

        span.select2 {
          width: 100% !important;
        }
      }

      .search-column {
        label {
          width: 100%;
        }
      }
    }
  }
}

.filter-row .search-column.table-search-filter-no-label div.dataTables_filter {
  label {
    display: flex;
    font-size: 0; // Hides "søg" label text
    margin-bottom: 0;

    input {
      margin-left: 0;
      margin-top: 0;
    }
  }
}

.card {
  > .table {
    margin-bottom: 0;

    > thead:first-child,
    > tbody:first-child {
      > tr:first-child {
        > th,
        > td {
          border-top: 0;
        }
      }
    }

    > tr:first-child {
      > td {
        border-top: 0;
      }
    }
  }
}

@media screen and (max-width: 575px) {
  div.dataTables_wrapper div.dataTables_filter {
    text-align: left;
  }
}

@media screen and (max-width: 767px) {
  div.dataTables_wrapper div.dataTables_filter {
    text-align: right;
  }
}
