/*
* Table component
*
*/

@import './table-header-buttons.scss';

.dnb-table {
  // table border
  &--border {
    tbody {
      .dnb-table__td,
      .dnb-table__th {
        @include tableBorder() {
          border: var(--table-border);
          border-bottom: none;
        }
        &:first-child::after {
          border-left: none;
        }
        &:last-child::after {
          border-right: none;
        }
      }

      .dnb-table__tr:first-child {
        .dnb-table__td,
        .dnb-table__th {
          &::after {
            border-top: none;
          }
        }
      }
    }

    // Header underline
    thead + tbody {
      .dnb-table__tr:first-child {
        .dnb-table__td,
        .dnb-table__th {
          &::after {
            border-top: var(--table-border);
          }
        }
      }
    }
  }

  /* stylelint-disable */
  &--outline {
    // first row must be rounded
    thead:first-of-type,
    tbody:first-child,
    caption:first-child + tbody {
      .dnb-table__tr:first-of-type {
        .dnb-table__th,
        .dnb-table__td {
          &:first-child,
          &:first-child::before,
          &:first-child::after {
            border-top-left-radius: var(--table-outline-radius);
          }
          &:last-child,
          &:last-child::before,
          &:last-child::after {
            border-top-right-radius: var(--table-outline-radius);
          }
        }
      }
    }
  }

  // last row must be rounded
  &--outline tbody:last-child {
    .dnb-table__tr:last-child,
    .dnb-table__tr--clickable:not(
        .dnb-table__tr--expanded
      ).dnb-table__tr--last {
      // Use "clip-path" instead of "overflow" because display=table-row does not give the expected/same result like display=block would.
      clip-path: inset(
        0 round 0 0 var(--table-outline-radius) var(--table-outline-radius)
      );

      .dnb-table__th,
      .dnb-table__td {
        &:first-child {
          &,
          &::before,
          &::after {
            border-bottom-left-radius: var(--table-outline-radius);
          }
        }
        &:last-child {
          &,
          &::before,
          &::after {
            border-bottom-right-radius: var(--table-outline-radius);
          }
        }
      }
    }
  }

  /* stylelint-enable */

  // spacing
  &__td--no-spacing,
  td#{&}__td--no-spacing {
    padding: 0;
  }
  &__td--spacing-horizontal,
  td#{&}__td--spacing-horizontal {
    padding-top: 0;
    padding-bottom: 0;
  }
}
