@import "../../styles/variables.scss";
@import "../../styles/reset";

$table-bg-accent: var(--background-bright, $off-white);
$novo-row-horizontal-padding: 20px;
$table-header-font-weight: 400;
$breakpoint: 1000px;

cdk-table {
  display: block;
  flex: 1;
  &.expandable {
    width: fit-content;
    min-width: 100%;
  }
  &.empty {
    min-height: 62px;
    max-height: 62px;
  }
  > .novo-data-table-row:nth-of-type(odd) {
    .novo-data-table-cell,
    .novo-data-table-button-cell,
    .novo-data-table-dropdown-cell,
    .novo-data-table-expand-cell,
    .novo-data-table-checkbox-cell {
      background-color: var(--background-muted, $sand);
    }
    &.active {
      .novo-data-table-cell,
      .novo-data-table-button-cell,
      .novo-data-table-dropdown-cell,
      .novo-data-table-expand-cell,
      .novo-data-table-checkbox-cell {
        background-color: rgba($ocean, 0.15);
      }
      + .novo-data-table-detail-row {
        background-color: rgba($ocean, 0.15);
      }
    }
    + .novo-data-table-detail-row {
      background-color: var(--background-muted, $sand);
    }
  }
  > .novo-data-table-row:nth-of-type(even) {
    .novo-data-table-cell,
    .novo-data-table-button-cell,
    .novo-data-table-dropdown-cell,
    .novo-data-table-expand-cell,
    .novo-data-table-checkbox-cell {
      background-color: var(--background-body, $white);
    }
    &.active {
      .novo-data-table-cell,
      .novo-data-table-button-cell,
      .novo-data-table-dropdown-cell,
      .novo-data-table-expand-cell,
      .novo-data-table-checkbox-cell {
        background-color: rgba($ocean, 0.15);
      }
      + .novo-data-table-detail-row {
        background-color: rgba($ocean, 0.15);
      }
    }
    + .novo-data-table-detail-row {
      background-color: var(--background-body, $white);
    }
  }
}

.novo-data-table-cell-align-right {
  text-align: right;
  justify-content: flex-end;
  overflow: hidden;
  text-overflow: clip;
}

.novo-data-table-header-row,
.novo-data-table-header-cell {
  position: relative;
  z-index: z(default);
}

.novo-data-table-header-row.fixed-header,
.novo-data-table-header-cell.fixed-header {
  position: sticky;
  top: 0;
}

.novo-data-table-row,
.novo-data-table-header-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  background-color: var(--background-body, $white);
  .novo-data-table-header-cell,
  .novo-data-table-checkbox-header-cell {
    background-color: var(--background-body, $white);
  }
  &.expanded {
    i.bhi-next.data-table-icon {
      cursor: pointer;
      transition: all 0.1s;
      &.expanded {
        transform: rotate(90deg);
      }
    }
  }
}

.novo-data-table-header-cell {
  &.resizable {
    padding-right: 0;
    &:hover {
      background-color: var(--background-muted, $neutral);
    }
    .data-table-header-resizable {
      height: 100%;

      span {
        cursor: ew-resize;
        background-color: var(--border, $neutral);
        width: 1px;
        margin: 0 4px;
        display: block;
      }
    }
  }
  > div {
    > button {
      margin-right: 2px;
    }
    &.spacer {
      flex-grow: 100;
    }
  }
  &[draggable=true] label {
    cursor: grab;
    user-select: none;
  }
}

.novo-data-table-clear-button {
  button {
    min-width: 80px !important;
  }
}

.novo-data-table-cell,
.novo-data-table-header-cell {
  min-width: 200px;
  padding: 9px;
  flex: 1;
  line-height: 1.1em;
  > i.label-icon {
    margin-right: 0.5em;
  }
  > span {
    display: block;
    min-width: 180px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  novo-dropdown {
    display: inline-block;
  }
  .filter-button {
    color: var(--text-muted);
    background: transparent;
    pointer-events: all;
    margin-left: 0.5rem;
    line-height: 1em;
    outline: none;
    &:hover {
      color: var(--text-main);
    }
    &.filter-active {
      color: var(--selection);
    }
  }

  button.active {
    color: $white;
    background: $positive;
    &:hover,
    &:active,
    &:focus,
    &:visited {
      background: $positive !important;
    }
  }
  &.clickable {
    cursor: pointer;
    color: $company;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.novo-data-table-cell {
  display: flex;
  flex-direction: row;
  align-items: center;
  &.dropdown-cell,
  &.button-cell {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    flex-direction: column;
    padding: 0 5px;
    novo-dropdown {
      button {
        padding: 0;
        padding-left: 5px;
        &:hover,
        &:active,
        &:focus {
          background: rgba(0, 0, 0, 0.1) !important;
        }
      }
    }
  }
  &.button-cell {
    min-width: 40px;
    max-width: 40px;
  }
  &.dropdown-cell {
    min-width: 98px;
    max-width: 98px;
    &.empty {
      min-width: 39px;
      max-width: 39px;
    }
  }
  i.data-table-icon {
    cursor: pointer;
    font-size: 1.2em;
    padding: 0.5em;
    border-radius: 3px;
    &.disabled {
      pointer-events: none;
      opacity: 0.7;
    }
    &:hover {
      background: rgba(0, 0, 0, 0.1);
    }
    &:active {
      background: rgba(0, 0, 0, 0.25);
    }
  }
}

.novo-data-table-header-cell {
  white-space: normal;
  overflow-wrap: break-word;
  display: flex;
  align-items: center;
  + .button-header-cell,
  + .dropdown-header-cell {
    border-left: none;
  }
  > label {
    display: inline-block;
    padding-right: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    &.sort-disabled {
      cursor: default;
    }
  }
  > div {
    width: 55px;
    display: flex;
    align-items: center;
    flex: 0;
  }
  novo-dropdown[side="right"] {
    display: inline-block;
    &:focus {
      outline: none;
    }
  }
  &.button-header-cell {
    min-width: 40px;
    max-width: 40px;
  }
  &.dropdown-header-cell {
    min-width: 98px;
    max-width: 98px;
    &.empty {
      min-width: 39px;
      max-width: 39px;
    }
  }
}

.novo-data-table-expand-header-cell,
.novo-data-table-expand-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  i {
    cursor: pointer;
    transition: all 0.1s;
    &.expanded {
      transform: rotate(90deg);
    }
  }
}

.novo-data-table-checkbox-header-cell,
.novo-data-table-checkbox-cell {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex-direction: column;
  max-width: 40px;
  padding: 0 10px;
  div.data-table-checkbox {
    display: flex;
    cursor: pointer;
    i {
      cursor: pointer;
      &.bhi-box-empty,
      &.bhi-checkbox-disabled {
        cursor: not-allowed !important;
      }
      &.bhi-checkbox-empty {
        color: #d2d2d2;
      }
      &.bhi-box-yes,
      &.bhi-checkbox-filled {
        color: $positive;
      }
    }
  }
  input {
    appearance: none !important;
    height: 0 !important;
    border: none !important;
  }
}

novo-data-table {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
  &.loading {
    min-height: 300px;
  }
  header {
    padding: 5px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border, $off-white);
    &.pagination-footer {
      justify-content: space-between;
    }
    &.empty {
      padding: 0;
    }
    > [novo-data-table-custom-header] {
      flex: 1;
    }
    > novo-search {
      padding-right: 10px;
      display: none;
      @media (min-width: $breakpoint) {
        display: flex;
      }
      > input {
        padding: 8.5px;
        font-size: 1.1em;
        height: 35px;
      }
      &.active > button[theme="fab"] {
        height: 35px;
        min-height: 35px;
      }
    }
    > div.novo-data-table-actions {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      > * {
        margin-right: 0.2em;
        &:last-child {
          margin-right: 0;
        }
      }
      > div,
      > section {
        display: flex;
        align-items: center;
        button {
          margin-left: 3px;
          margin-bottom: 0px;
        }
        button[theme][theme="icon"] {
          height: 35px;
          width: 35px;
          font-size: 1.4em;
        }
        novo-dropdown {
          button[theme] {
            white-space: nowrap;
            padding: 6px 5px 6px 15px !important;
          }
        }
      }
    }
  }
  button[theme][theme="icon"] {
    height: 30px;
    width: 30px;
    padding: 5px;
  }
  .novo-data-table-loading-mask {
    position: absolute;
    display: flex;
    padding-top: 10%;
    justify-content: center;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.07);
    z-index: z(above);
  }
  .clickable {
    @extend a;
  }
  .novo-data-table-detail-row {
    padding: 1em;
  }
  .novo-data-table-empty-container {
    padding-top: 0;
  }
  .novo-data-table-no-results-container,
  .novo-data-table-no-more-results-container{
    position: absolute;
    top: 48%;
    left: 0;
    right: 0;
    width: 100%;
  }
  .novo-data-table-empty-container,
  .novo-data-table-no-results-container,
  .novo-data-table-no-more-results-container{
    padding: 2em;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: $grey;
    z-index: 5;
  }
  .novo-data-table-outside-container {
    display: flex;
    flex: 1;
    .novo-data-table-custom-filter {
      border-right: 1px solid var(--border, $off-white);
      novo-date-picker {
        .calendar {
          box-shadow: none;
          .date-range-tabs {
            height: 51px;
          }
          .calendar-footer {
            display: none;
          }
        }
      }
      div.period-selector {
        padding: 1em;
        .novo-form-control-label {
          display: block;
          max-width: 100%;
          margin-bottom: 1em;
        }
      }
    }
    .novo-data-table-container {
      flex: 1;
      overflow: auto;
      position: relative;
      &.empty {
        display: flex;
        flex: 0;
      }
      &.empty-user-filtered {
        display: flex;
        flex-flow: column nowrap;
        min-height: 250px;
      }
    }
  }
  .novo-data-table-outside-container-fixed {
    overflow: hidden;
    position: relative;
    .novo-data-table-container-fixed {
      position: absolute;
      width: 100%;
      height: 100%;
    }
  }
  .novo-data-table-footer {
    display: flex;
    align-items: center;
    > div,
    div.novo-data-table-footer-cell {
      border-top: 1px solid var(--border, $off-white);
      flex: 1;
      min-width: 200px;
      display: flex;
      align-items: center;
      &:not(.button-cell):not(.dropdown-cell) {
        padding: 10px;
      }
    }
  }
}

.dropdown-container.data-table-dropdown {
  min-width: 220px;
  max-width: 280px;
  max-height: 500px;
  overflow-x: hidden;
  overflow-y: hidden;
  &.right {
    margin-left: -150px !important;
  }
  .header {
    padding: 5px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .optgroup-container {
    max-height: 346px;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .dropdown-list-options {
    max-height: 346px;
    overflow-y: auto;
    overflow-x: hidden;
  }
  .footer {
    border-top: 1px solid var(--border, $off-white);
    padding: 5px 10px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    button {
      icon {
        font-size: 0.8em;
      }
    }
  }
  list item.active {
    background: transparent;
    font-weight: 500;
  }
  button[theme][theme="dialogue"][icon] i {
    padding: inherit;
    padding-left: 5px;
    height: inherit;
    width: inherit;
    display: inline-block;
    line-height: inherit;
  }

  .calendar-container {
    height: 100%;
    min-height: 200px;
    width: 100%;
    background: #fff;
    padding: 0 !important;
    .back-link {
      color: $positive;
      line-height: 3em;
      font-size: 0.9em;
      padding-left: 5px;
      cursor: pointer;
    }
    novo-date-picker {
      .calendar {
        width: 100%;
        height: 100%;
        box-shadow: none;
        padding: 0 5px 10px;
        .calendar-top {
          display: none;
        }
      }
    }
  }
  span.error-text {
    color: $negative;
    position: relative;
    left: 10px;
    top: -17px;
    font-size: x-small;
  }
  .filter-null-results {
    background-color: $white;
    text-align: center;
    color: darken($light, 15%);
    background: transparent;
    font-weight: 500;
  }
}
