@use './../variables/color';
@use './../variables/commons';

@use './../functions/tokens';
@use './../tokens/utilities';

tokens.$default-map: utilities.$post-spacing;

// These styles have been temporarily copied from bootstrap as to not break the table designs in the documentation

.table {
  --table-color-type: initial;
  --table-bg-type: initial;
  --table-color-state: initial;
  --table-bg-state: initial;
  --table-color: var(--post-current-fg);
  --table-border-color: color-mix(in srgb, var(--post-current-fg), transparent 80%);
  --table-accent-bg: transparent;
  --table-striped-color: var(--post-current-fg);
  --table-striped-bg: color-mix(in srgb, var(--post-current-fg), transparent 90%);
  --table-active-color: var(--post-current-fg);
  --table-active-bg: #{color.$yellow};
  --table-hover-color: var(--post-current-fg);
  --table-hover-bg: color-mix(in srgb, var(--post-current-fg), transparent 80%);

  width: 100%;
  margin-bottom: 1rem;
  vertical-align: top;
  border-color: var(--table-border-color);
  caption-side: bottom;

  > :not(:first-child) {
    border-width: 0;
  }
}

.table > :not(caption) > * > * {
  padding: tokens.get('utility-margin-12') tokens.get('utility-margin-4');
  color: var(--post-current-fg);
  background-color: transparent;
  border-bottom-width: 1px;
  box-shadow: inset 0 0 0 9999px var(--table-bg-state, var(--table-bg-type, var(--table-accent-bg)));
}

.table > tbody {
  vertical-align: inherit;
  text-align: left;
}

.table > thead {
  vertical-align: bottom;
  text-align: left;
}

.table > caption {
  text-align: left;
}

.table-group-divider {
  border-top: calc(1px * 2) solid color-mix(in srgb, var(--post-current-fg), transparent 80%);
}

.table-sm > :not(caption) > * > * {
  padding: tokens.get('utility-margin-8') tokens.get('utility-margin-4');
}

.table-bordered > :not(caption) > * {
  border-width: 1px 0;
}

.table-bordered > :not(caption) > * > * {
  border-width: 0 1px;
}

.table-borderless > :not(caption) > * > * {
  border-bottom-width: 0;
}

.table-borderless > :not(:first-child) {
  border-top-width: 0;
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
  --table-color-type: var(--table-striped-color);
  --table-bg-type: var(--table-striped-bg);
}

.table-striped-columns > :not(caption) > tr > :nth-child(even) {
  --table-color-type: var(--table-striped-color);
  --table-bg-type: var(--table-striped-bg);
}

.table-active {
  --table-color-state: var(--table-active-color);
  --table-bg-state: var(--table-active-bg);
}

.table-hover > tbody > tr:hover > * {
  --table-color-state: var(--table-hover-color);
  --table-bg-state: var(--table-hover-bg);
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-mono {
  // Set all border color
  > thead,
  > tbody,
  > tfoot,
  > :is(thead, tbody, tfoot) > tr,
  > :is(thead, tbody, tfoot) > tr > :is(td, th) {
    border-color: var(--post-current-fg);
    border-width: commons.$border-thick;
  }

  // Remove striped background, but only if not associated with table-hover and hover
  &.table-striped:not(.table-hover) > tbody > tr > :is(th, td),
  &.table-striped.table-hover > tbody > tr:not(:hover) > :is(th, td) {
    box-shadow: none;
  }

  // Hide border between cells on tbody when hovered, but not bordered
  &.table-hover:not(.table-bordered) {
    > tbody > tr > :is(td, th) {
      border: 0;
    }
  }

  // Underline by default (Hide cells border)
  &:not(.table-bordered) {
    > :is(thead, tbody, tfoot) > tr > :is(td, th) {
      border: 0;
    }
  }

  // Remove border when borderless
  &.table-borderless {
    > thead,
    > tbody,
    > tfoot,
    > :is(thead, tbody, tfoot) > tr,
    > :is(thead, tbody, tfoot) > tr > :is(td, th) {
      border: 0;
    }
  }

  > tbody > tr {
    background-color: color-mix(in srgb, var(--post-current-fg), transparent 90%);
  }
}
