/**
 * Table print
 * @define table
 */

@use 'sass:map';

// Exposed variables
$theme: null !default;
$table: null !default;

.ecl-table,
%ecl-table {
  border-collapse: collapse;
  color: map.get($table, 'table-color');
  font: map.get($theme, 'font-print', 'm');
  margin: 0;
  break-inside: avoid;
  width: 100%;
}

.ecl-table__header,
%ecl-table__header {
  border-inline-end: map.get($table, 'header', 'separator-desktop');
  border-inline-start: map.get($table, 'header', 'separator-desktop');
  font-weight: map.get($table, 'header', 'font-weight');
  padding: map.get($theme, 'spacing-print', 's')
    map.get($theme, 'spacing-print', 'xl') map.get($theme, 'spacing-print', 's')
    map.get($theme, 'spacing-print', 'm');
  text-align: start;
  vertical-align: baseline;

  &:first-child {
    border-inline-start-color: map.get($table, 'head', 'border-inline-color');
  }

  &:last-child {
    border-inline-end-color: map.get($table, 'head', 'border-inline-color');
  }
}

.ecl-table__row,
%ecl-table__row {
  border-bottom: map.get($table, 'row-border');
}

.ecl-table__head,
%ecl-table__head {
  background-color: map.get($table, 'head', 'background');
  border-bottom: map.get($table, 'row-border');
  border-top: map.get($table, 'row-border');

  .ecl-table__row {
    border-bottom: none;
  }

  .ecl-table__row:not(:first-child) .ecl-table__header:not(:empty) {
    border-top: map.get($table, 'row-border');
  }
}

.ecl-table__cell,
%ecl-table__cell {
  border-inline-start: map.get($table, 'cell', 'separator');
  padding: map.get($theme, 'spacing-print', 's')
    map.get($theme, 'spacing-print', 'm');

  &:last-child {
    border-inline-end: map.get($table, 'cell-separator');
  }
}

.ecl-table__caption {
  caption-side: bottom;
  color: map.get($table, 'caption', 'color');
  font: map.get($theme, 'font-print', 's');
  margin-top: map.get($theme, 'spacing-print', 'xs');
  text-align: start;
}

.ecl-table--zebra {
  .ecl-table__row:nth-of-type(even) {
    background-color: map.get($table, 'zebra-background');
  }
}

.ecl-table__arrow,
.ecl-table__filter-label {
  display: none;
}
