@use '@angular/material' as mat;
@use "@material/data-table/data-table-theme" as mdc-data-table;
@use "sass:map";
@import '../themes/material-typography';
@import '../variables';

@mixin apply-table-styles($palette) {
  $bg-color: mat.get-color-from-palette($palette, "background");
  @include mdc-data-table.header-row-fill-color($bg-color);
  $select-color: mat.get-color-from-palette($palette, "selected-button");
  @include mdc-data-table.selected-row-fill-color($select-color);
  $hover-color: mat.get-color-from-palette($palette, "hover");
  @include mdc-data-table.row-hover-fill-color($hover-color);
  $table-border-color: mat.get-color-from-palette($palette, "table-border");
  $text-secondary-color: mat.get-color-from-palette($palette, "secondary-text");

  .mat-mdc-table {
    background: $bg-color;
  }
  .mdc-data-table__header-cell, .mdc-data-table__cell {
    color: unset;
  }
  .mdc-data-table__row--selected:hover {
    background-color: $select-color !important; /*light theme doesn't work without important flag. I don't know why*/
  }
  .mat-mdc-row {
    cursor: default;

    &.readonly .mat-mdc-cell {
      color: $text-secondary-color;
    }

    &.has-changes {
      font-style: italic;
    }
  }

  .mat-mdc-header-cell {
    width: 0;
    border-left: 1px solid $table-border-color;

    &:nth-of-type(1) {
      border-left: none;
    }
  }

  .mat-mdc-header-cell, .mat-mdc-cell {
    white-space: nowrap;
    padding: $plt-padding-sm $plt-padding-base;
    border-bottom-color: $table-border-color;
  }

  .mat-mdc-cell,
  .mat-mdc-cell * {
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: mat.font-size($custom-typography-config, 'body-1');

    &.right {
       text-align: center;
     }

    &.vertical-align-center {
      vertical-align: center;
    }

    &.vertical-align-top {
      vertical-align: top;
    }

    small {
      font-size: mat.font-size($custom-typography-config, 'body-2');
      color: $text-secondary-color;
    }

    .mat-mdc-checkbox {
      padding: 1px 0 0 1px;
    }
  }

  th:last-of-type {
    width: auto;
  }
}
