@use 'sass:map';
@use '@angular/material' as mat;
@use '../../token-definition';

// The prefix used to generate the fully qualified name for tokens in this file.
$prefix: (mtx, grid);

// Tokens that can't be configured through Angular Material's current theming API,
// but may be in a future version of the theming API.
@function get-unthemable-tokens() {
  @return (
    container-shape: 0,
    table-cell-min-width: 80px,
  );
}

// Tokens that can be configured through Angular Material's color theming API.
@function get-color-tokens($theme) {
  $is-dark: mat.get-theme-type($theme) == dark;
  $text-color: mat.get-theme-color($theme, foreground, text);
  $divider-color: mat.get-theme-color($theme, foreground, divider);

  @return (
    outline-color: mat.private-safe-color-change($text-color, $alpha: .2),
    column-menu-text-color: $text-color,
    column-menu-divider-color: $divider-color,
    table-footer-background-color: mat.get-theme-color($theme, background, app-bar),
    table-row-striped-background-color: if($is-dark, #3a3a3a, #f5f5f5),
    table-row-hover-background-color: if($is-dark, #2a2a2a, #eee),
    table-row-selected-background-color: if($is-dark, #2a2a2a, #eee),
    table-row-selected-hover-background-color: if($is-dark, #1a1a1a, #e0e0e0),
    table-cell-selected-outline-color: mat.get-theme-color($theme, accent),
    resizable-handle-active-background-color: mat.get-theme-color($theme, primary),
    resizable-handle-hover-background-color: mat.get-theme-color($theme, primary),
    resizable-handle-disabled-background-color: $divider-color,
  );
}

// Tokens that can be configured through Angular Material's typography theming API.
@function get-typography-tokens($theme) {
  @return ();
}

// Tokens that can be configured through Angular Material's density theming API.
@function get-density-tokens($theme) {
  $scale: mat.private-clamp-density(mat.get-theme-density($theme), -4);
  $expand-button-scale: (
    0: 48px,
    -1: 44px,
    -2: 40px,
    -3: 36px,
    -4: 28px
  );

  @return (
    row-expand-button-size: map.get($expand-button-scale, $scale),
  );
}

// Combines the tokens generated by the above functions into a single map with placeholder values.
// This is used to create token slots.
@function get-token-slots() {
  @return mat.private-deep-merge-all(
    get-unthemable-tokens(),
    get-color-tokens(token-definition.$placeholder-color-config),
    get-typography-tokens(token-definition.$placeholder-typography-config),
    get-density-tokens(token-definition.$placeholder-density-config)
  );
}
