@use 'sass:map';
@use 'sass:meta';
@use '@angular/material' as mat;
@use '../core/tokens/m2-utils';
@use '../core/tokens/m3-utils';

@function get-tokens($theme) {
  $system: m2-utils.get-system($theme);

  $is-dark: false;
  @if meta.type-of($theme) == 'map' {
    $is-dark: mat.get-theme-type($theme) == dark;
  }

  $density-scale: mat.private-clamp-density(map.get($system, density-scale), -4);

  $row-striped-background-color: #f5f5f5;
  @if $is-dark {
    $row-striped-background-color: #3a3a3a;
  }

  $row-hover-background-color: #eee;
  @if $is-dark {
    $row-hover-background-color: #2a2a2a;
  }

  $row-selected-background-color: #eee;
  @if $is-dark {
    $row-selected-background-color: #2a2a2a;
  }

  $row-selected-hover-background-color: #e0e0e0;
  @if $is-dark {
    $row-selected-hover-background-color: #1a1a1a;
  }

  @return (
    base: (
      grid-container-shape: 0,
      grid-table-cell-min-width: 80px,
    ),
    color: (
      grid-outline-color: m3-utils.color-with-opacity(map.get($system, on-surface), 20%),
      grid-column-menu-text-color: map.get($system, on-surface),
      grid-column-menu-divider-color: map.get($system, outline),
      grid-table-footer-background-color: map.get($system, surface),
      grid-table-row-striped-background-color: $row-striped-background-color,
      grid-table-row-hover-background-color: $row-hover-background-color,
      grid-table-row-selected-background-color: $row-selected-background-color,
      grid-table-row-selected-hover-background-color: $row-selected-hover-background-color,
      grid-table-cell-selected-outline-color: map.get($system, secondary),
      grid-resizable-handle-active-background-color: map.get($system, primary),
      grid-resizable-handle-hover-background-color: map.get($system, primary),
      grid-resizable-handle-disabled-background-color: map.get($system, outline),
    ),
    typography: (),
    density: (
      grid-row-expand-button-size: map.get((
        0: 48px,
        -1: 44px,
        -2: 40px,
        -3: 36px,
        -4: 28px
      ), $density-scale),
    )
  );
}
