@import '../../styles/common';

.DataTable {
  --pc-data-table-first-column-width: 145px;
  position: relative;
  max-width: 100vw;
}

.condensed {
  .Navigation {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: var(--p-space-4) var(--p-space-2);

    @media #{$p-breakpoints-md-up} {
      justify-content: flex-end;
    }
  }
}

.Navigation {
  display: none;

  .IncreasedTableDensity & {
    padding: var(--p-space-2) var(--p-space-2) 0 var(--p-space-2);
  }
}

.Pip {
  height: 6px;
  width: 6px;
  background: var(--p-text-subdued);
  border-radius: var(--p-border-radius-1);

  &:not(:last-of-type) {
    margin-right: var(--p-space-1);
  }
}

.Pip-visible {
  background: var(--p-text);
}

.ScrollContainer {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.Table {
  width: 100%;
  border-spacing: 0;
}

// stylelint-disable selector-max-class, selector-max-combinators, selector-max-specificity, selector-max-compound-selectors
.TableRow + .TableRow {
  .Cell {
    border-top: var(--p-border-divider);
  }
}

.Cell {
  padding: var(--p-space-4);
  white-space: nowrap;
  text-align: left;
  transition: background-color var(--p-duration-200) var(--p-ease-in-out);

  .IncreasedTableDensity & {
    padding: var(--p-space-2) var(--p-space-4);
  }
}

.ZebraStripingOnData {
  .TableRow:nth-child(2n + 1) .Cell,
  &.RowCountIsEven .TableRow:nth-child(2n) .Cell,
  &.ShowTotalsInFooter .TableRow:nth-child(2n) .Cell,
  &.ShowTotalsInFooter.RowCountIsEven .TableRow:nth-child(2n + 1) .Cell {
    background: none;
  }

  .TableRow:nth-child(2n) .Cell,
  &.RowCountIsEven .TableRow:nth-child(2n + 1) .Cell,
  &.ShowTotalsInFooter .TableRow:nth-child(2n + 1) .Cell,
  &.ShowTotalsInFooter.RowCountIsEven .TableRow:nth-child(2n) .Cell {
    background: var(--p-surface-subdued);
  }
}

.Cell-firstColumn {
  @include text-emphasis-normal;
  text-align: left;
  white-space: normal;
}

.Cell-numeric {
  text-align: right;
}

.Cell-truncated {
  white-space: nowrap;
  overflow-x: hidden;
  text-overflow: ellipsis;
  max-width: var(--pc-data-table-first-column-width);
}

.Cell-header {
  @include text-emphasis-normal;
  border-bottom: var(--p-border-divider);
  border-top: 0;

  .IncreasedTableDensity & {
    font-weight: var(--p-font-weight-medium);
    font-size: var(--p-font-size-1);
  }
}

.Cell-sortable {
  padding: 0;

  .IncreasedTableDensity & {
    padding: var(--p-space-2) var(--p-space-3);

    &:first-child {
      padding-left: var(--p-space-3);
    }

    &:last-child {
      padding-right: var(--p-space-3);
    }
  }

  .IncreasedTableDensity & .Heading-left {
    padding-right: 0;
    padding-left: var(--p-space-1);
  }
}

.Cell-verticalAlignTop {
  vertical-align: top;
}

.Cell-verticalAlignBottom {
  vertical-align: bottom;
}

.Cell-verticalAlignMiddle {
  vertical-align: middle;
}

.Cell-verticalAlignBaseline {
  vertical-align: baseline;
}

.hoverable {
  .Cell-hovered {
    @media #{$p-breakpoints-md-up} {
      background: var(--p-surface-hovered);
    }
  }
}

.Icon {
  display: flex;
  align-self: flex-end;
  opacity: 0;
  transition: opacity var(--p-duration-200) var(--p-ease),
    fill var(--p-duration-200) var(--p-ease);
}

.Heading {
  @include unstyled-button;
  @include focus-ring;
  position: relative;
  display: inline-flex;
  justify-content: flex-end;
  align-items: baseline;
  @include recolor-icon(var(--p-icon));
  color: var(--p-text);
  transition: color var(--p-duration-200) var(--p-ease);
  cursor: pointer;
  padding: var(--p-space-2);
  margin: var(--p-space-2);

  .StickyHeaderEnabled [data-sticky-active] & {
    visibility: hidden;
  }

  .StickyHeaderEnabled [data-sticky-active] .StickyTable & {
    visibility: visible;
  }

  .IncreasedTableDensity & {
    font-weight: var(--p-font-weight-medium);
    font-size: var(--p-font-size-1);
    padding: 0;
    padding-right: var(--p-space-1);
    margin: 0;
  }

  &:hover {
    @include recolor-icon(var(--p-interactive-hovered));
    color: var(--p-interactive-hovered);

    .Icon {
      opacity: 1;

      svg {
        fill: var(--p-icon-disabled);
      }
    }
  }

  &:focus:not(:active) {
    @include focus-ring($style: 'focused');

    .Icon {
      opacity: 1;

      svg {
        fill: var(--p-icon-disabled);
      }
    }
  }
}

.Heading-left {
  justify-content: flex-start;
  flex-direction: row-reverse;
}

.Cell-sorted {
  .Icon {
    opacity: 1;
  }

  .Heading:focus:not(:active) {
    svg {
      fill: var(--p-icon);
    }
  }
}

.Cell-total {
  @include text-emphasis-strong;
  background: var(--p-surface-subdued);
  border-bottom: var(--p-border-divider);

  .ZebraStripingOnData.ShowTotals & {
    background: var(--p-surface-subdued);
  }

  .ZebraStripingOnData.ShowTotals.RowCountIsEven &,
  .ZebraStripingOnData.ShowTotalsInFooter & {
    background: none;
  }
}

.Cell-total-footer {
  border-top: var(--p-border-divider);
  border-bottom: none;

  &:first-child {
    border-bottom-left-radius: var(--p-border-radius-2);
  }

  &:last-child {
    border-bottom-right-radius: var(--p-border-radius-2);
  }
}

.Footer {
  padding: var(--p-space-4);
  background: var(--p-surface-subdued);
  color: var(--p-text-subdued);
  text-align: center;
  border-top: var(--p-border-divider);
  border-bottom-left-radius: var(--p-border-radius-2);
  border-bottom-right-radius: var(--p-border-radius-2);

  .ZebraStripingOnData & {
    background: none;
  }
}

.StickyHeaderEnabled {
  .StickyTable {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    visibility: hidden;
    z-index: var(--p-z-1);
  }

  .StickyTableHeader {
    position: absolute;
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow: hidden;
    border-spacing: 0;

    &:not(.StickyTableHeader-isSticky) {
      top: -9999px;
      left: -9999px;
    }
  }

  .StickyTableColumnHeader-isScrolling {
    box-shadow: 1px 1px 0 0 var(--p-border-divider),
      1px 0 1px 1px rgba(63, 63, 68, 0.05), 1px 0 3px 0 rgba(63, 63, 68, 0.15);
  }

  .StickyTableHeadingsRow {
    overflow-x: auto;
    background-color: var(--p-surface);
    scrollbar-width: none;

    &::-webkit-scrollbar {
      appearance: none;
      height: 0;
      width: 0;
    }
  }

  .StickyTableHeader-isSticky {
    visibility: visible;
    background-color: var(--p-surface);
    box-shadow: var(--p-shadow-base);
  }
}

.FixedFirstColumn {
  position: absolute;
  background: var(--p-surface);
  z-index: 3;
  border-spacing: 0;
  @media #{$p-breakpoints-md-down} {
    z-index: 1;
  }

  &.separate th {
    border-right: var(--p-border-divider);
  }
}

.TooltipContent {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
