@import "../_colors";
@import "../_queries";

$table-background: $default-color !default;
$table-expanded-row-color: #f5f5f5 !default;
$table-selected-color: #f0f0f0 !default;
$table-hover-color: #ebebeb !default;
$table-border-color: $default-secondary-color !default;
$table-shadow-color: $default-primary-color !default;
$table-text-color: $primary-dark-text-color !default;
$table-expand-icon-color: $primary-dark-text-color !default;
$table-collapse-icon-color: $primary-dark-text-color !default;
$table-sort-icon-color: $default-primary-color !default;
$table-sort-icon-active-color: $primary-dark-text-color !default;
$shadow-color: rgba(0, 0, 0, 0.18) !default;

%frozen-column-base {
  z-index: 1 !important;
  background-color: $table-background !important;
  border-right: 1px solid $table-border-color;
}

body .p-datatable {
  &-header {
    margin: 12px 0;
    border-style: none;
    .p-multiselect {
      width: auto;
    }
  }

  &-table {
    table-layout: fixed;
  }
  .p-datepicker-input {
    min-width: 7em;
  }
  &-table-container {
    margin-bottom: 2em;
  }

  s-table-header-checkbox s-checkbox {
    .checkbox,
    label {
      margin-bottom: 0;
    }
  }
  &-scrollable-table .p-datatable-thead {
    z-index: 1 !important;
    background: $table-background !important;
  }

  .p-paginator {
    min-width: auto;
    &-last {
      margin-right: 16px;
    }
    .p-select-label {
      min-width: auto;
    }
  }
}

body .p-datatable .p-datatable-table-container {
  .p-datatable-tfoot > tr > td,
  .p-datatable-tbody > tr > td,
  .p-datatable-thead > tr > th {
    overflow: hidden;
    padding: 15px;
    word-wrap: break-word;
    color: $table-text-color;
    border-bottom: 1px solid $table-border-color;
    background-color: transparent;
    text-align: left;
    white-space: normal;
  }

  .p-datatable-thead > tr > th {
    font-weight: bold !important;
    &:not(:last-child) {
      border-right: 1px solid $table-border-color;
    }
  }

  .p-datatable-thead,
  .p-datatable-frozen-tbody {
    z-index: 0;
  }
  .p-datatable-tbody > tr.p-datatable-row-selected {
    background-color: transparent;
  }

  .p-datatable-tbody > tr.p-datatable-row-selected > td {
    background-color: $table-selected-color;
  }

  .p-datatable-tbody > tr:focus,
  .p-datatable-thead > tr > th:focus {
    outline: none;
  }

  .p-datatable-tbody > tr:focus > td,
  .p-datatable-tbody > tr:hover > td,
  .p-datatable-thead > tr > th:focus {
    background-color: $table-hover-color !important;
  }

  .p-datatable-thead > tr > th .p-sortable-column-icon {
    color: $table-sort-icon-active-color;
  }

  .p-datatable-thead
    > tr
    > th:not(.p-datatable-row-selected)
    .p-sortable-column-icon {
    color: $table-sort-icon-color;
  }

  .p-widget-header {
    border: none;
  }

  .p-datatable-table-caption,
  .p-datatable-table-summary {
    padding: 10px 0;
    font-weight: normal;
  }

  p-tableheadercheckbox:only-child .p-chkbox,
  p-tablecheckbox:only-child .p-chkbox {
    display: block;
  }

  p-sorticon {
    vertical-align: baseline;
  }

  tr {
    > :is(td, th).p-datatable-frozen-column.p-datatable-frozen-column-left {
      @extend %frozen-column-base;

      &:has(+ :is(td, th):not(.p-datatable-frozen-column)) {
        box-shadow: 4px 0 8px $shadow-color !important;
      }
    }

    > :is(td, th).p-datatable-frozen-column:not(
        .p-datatable-frozen-column-left
      ) {
      @extend %frozen-column-base;
    }

    > :is(td, th):not(.p-datatable-frozen-column)
      + :is(td, th).p-datatable-frozen-column:not(
        .p-datatable-frozen-column-left
      ) {
      box-shadow: -4px 0 8px $shadow-color !important;
    }
  }

  tbody > tr.sds-expanded-row {
    box-shadow: inset 0px 5px 5px -3px $table-shadow-color;
  }

  tbody > tr.sds-expanded-row > td {
    padding: 20px 20px 20px 56px;
    background: #d5e8ec !important;
    &:hover {
      background: #d5e8ec !important;
    }
    .p-datatable-thead {
      background-color: transparent !important;
    }
  }

  tbody > tr.sds-expanded-row > td,
  tbody > tr.sds-expanded-row:hover > td {
    background-color: $table-expanded-row-color;
  }

  tbody td .fa.fa-plus,
  tbody td .fa.fa-minus {
    cursor: pointer;
    width: 100%;
    text-align: center;
  }

  tbody td .fa.fa-plus.disabled {
    color: $default-primary-color;
    cursor: default;
  }

  tbody td .fa.fa-minus.disabled {
    color: $default-primary-color;
    cursor: default;
  }

  tr:hover > td.p-editable-column:not(.p-editing-cell) {
    cursor: text;
  }

  .p-datatable-tbody > tr > td.p-editing-cell {
    padding: 7.5px;
  }

  .p-datatable-table-dragpoint-bottom {
    -webkit-box-shadow: inset 0 -2px 0 0 $primary-color;
    -moz-box-shadow: inset 0 -2px 0 0 $primary-color;
    box-shadow: inset 0 -2px 0 0 $primary-color;
  }

  th.p-datatable-column-sorted {
    font-weight: bold !important;
  }
}

body .sds-table-scrollable .p-datatable-table-container {
  max-height: 60vh;
  overflow: auto;
}
