@use 'sass:map';
@use '../../../mx-core/src/base/colors';
@use '../../../mx-core/src/base/typography';
@use '../../../mx-core/src/base/opacity';

@mixin mx-table-theme($theme) {
  $is-dark: map.get($theme, is-dark);
  $color-theme: colors.$mx-light;

  @if $is-dark {
    $color-theme: colors.$mx-dark;
  }

  .mx-table {
    &__body {
      &--loading {
        background-color: rgba(map.get($color-theme, scrim), opacity.$opacity-16);
      }
    }

    &__toolbar {
      border-bottom: 1px solid map.get($color-theme, outlineVariant);
      &-selection {
        span.subtitle {
          color: map.get($color-theme, onSurfaceVariant);
        }
        &::after {
          background-color: map.get($color-theme, outlineVariant);
        }
      }
    }

    &__footer {
      border-top: 1px solid map.get($color-theme, outlineVariant);
    }
  }

  table.mat-mdc-table {
    background-color: transparent;
    .mat-mdc-table-sticky {
      background-color: map.get($color-theme, surface);

      &-border-elem-left {
        border-right: 1px solid map.get($color-theme, outlineVariant);
      }

      &-border-elem-right {
        border-left: 1px solid map.get($color-theme, outlineVariant);
      }
    }

    .mat-mdc-cell:not(.mat-mdc-table-sticky) {
      background: none;
    }

    .mat-mdc-row {
      &:hover {
        &:not(.selected) {
          .mat-mdc-cell {
            background-color: rgba(map.get($color-theme, onSurface), 0.08);
          }

          .mat-mdc-table-sticky {
            background-color: map.get($color-theme, surface);
            &::before {
              background: rgba(map.get($color-theme, onSurface), 0.08);
            }
          }
        }
      }
      &.selected {
        .mat-mdc-cell {
          background-color: rgba(map.get($color-theme, primary), 0.08);
        }

        .mat-mdc-table-sticky {
          background-color: map.get($color-theme, surface);
          &::before {
            background: rgba(map.get($color-theme, primary), 0.08);
          }
        }
      }
      &:has(.mx-table__td--checkbox):has(.mdc-checkbox--selected) {
        .mat-mdc-cell:not(.mat-mdc-table-sticky) {
          background-color: rgba(map.get($color-theme, primary), 0.08);
        }
      }
    }

    .mat-sort-header-arrow {
      color: map.get($color-theme, onSurfaceVariant);
    }

    .mdc-data-table__header-cell {
      color: map.get($color-theme, onSurfaceVariant);
      border-bottom: 1px solid map.get($color-theme, outlineVariant);
    }
    .mdc-data-table__cell {
      color: map.get($color-theme, onSurface);
      border-bottom: 1px solid map.get($color-theme, outlineVariant);
    }
    .mat-mdc-row:has(+ .mx-expandable-row) {
      .mdc-data-table__cell {
        border-bottom: 0px solid map.get($color-theme, outlineVariant);
      }
    }
    .mx-expandable-row + .mat-mdc-row {
      .mdc-data-table__cell {
        border-top: 1px solid map.get($color-theme, outlineVariant);
      }
    }
  }
}
