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

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

// Generates the tokens used to theme the option based on a palette.
@function private-get-color-palette-color-tokens($theme, $palette-name) {
  @return (
    option-selected-state-text-color: mat.get-theme-color($theme, $palette-name),
  );
}

// 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: 4px,
    container-elevation-shadow: elevation.get-box-shadow(8),
  );
}

// Tokens that can be configured through Angular Material's color theming API.
@function get-color-tokens($theme) {
  $text-color: mat.get-theme-color($theme, foreground, text);
  $hint-text-color: mat.get-theme-color($theme, foreground, hint-text);
  $secondary-text-color: mat.get-theme-color($theme, foreground, secondary-text);
  $disabled-text-color: mat.get-theme-color($theme, foreground, disabled-text);
  $divider-color: mat.get-theme-color($theme, foreground, divider);
  $hover-color: mat.get-theme-color($theme, background, hover);
  $palette-tokens: private-get-color-palette-color-tokens($theme, primary);

  @return map.merge($palette-tokens, (
    container-text-color: $text-color,
    placeholder-text-color: $hint-text-color,
    disabled-text-color: $hint-text-color,

    multiple-value-background-color: mat.get-theme-color($theme, background, unselected-chip),
    multiple-value-outline-color: $divider-color,
    multiple-value-icon-hover-background-color: $divider-color,

    clear-icon-color: $secondary-text-color,
    clear-icon-hover-color: mat.get-theme-color($theme, warn),

    enabled-arrow-color: $secondary-text-color,
    disabled-arrow-color: $disabled-text-color,
    invalid-arrow-color: mat.get-theme-color($theme, warn),

    panel-background-color: mat.get-theme-color($theme, background, card),
    panel-divider-color: $divider-color,
    optgroup-label-text-color: $secondary-text-color,
    option-label-text-color: $text-color,
    option-selected-state-background-color: $hover-color,
    option-hover-state-background-color: $hover-color,
    option-disabled-state-text-color: $hint-text-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) {
  @return ();
}

// 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)
  );
}
