@use 'sass:map';
@use '../../../theming/theming';
@use '../../../typography/typography-utils';
@use '../../../mdc-helpers/mdc-helpers';
@use '../../../style/sass-utils';
@use '../../token-utils';

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

// Tokens that can't be configured through Angular Material's current theming API,
// but may be in a future version of the theming API.
//
// Tokens that are available in MDC, but not used in Angular Material should be mapped to `null`.
// `null` indicates that we are intentionally choosing not to emit a slot or value for the token in
// our CSS.
@function get-unthemable-tokens() {
  @return (
    // Height of the container's elevation.
    container-elevation: 24,
    // Color of the elevation shadow.
    container-shadow-color: #000,
    // Border radius of the container.
    container-shape: 4px,
    // =============================================================================================
    // = TOKENS NOT USED IN ANGULAR MATERIAL                                                       =
    // =============================================================================================
    with-divider-divider-height: null,
    with-divider-divider-color: null,
    with-icon-icon-size: null,
    with-icon-icon-color: null,
    action-label-text-font: null,
    action-label-text-line-height: null,
    action-label-text-size: null,
    action-label-text-weight: null,
    action-label-text-tracking: null,
    action-label-text-color: null,
    action-hover-state-layer-color: null,
    action-hover-state-layer-opacity: null,
    action-hover-label-text-color: null,
    action-focus-state-layer-color: null,
    action-focus-state-layer-opacity: null,
    action-focus-label-text-color: null,
    action-pressed-state-layer-color: null,
    action-pressed-state-layer-opacity: null,
    action-pressed-label-text-color: null,
    headline-color: null,
    headline-font: null,
    headline-line-height: null,
    headline-size: null,
    headline-tracking: null,
    headline-weight: null,
    z-index: null,
    container-surface-tint-layer-color: null,
  );
}

// Tokens that can be configured through Angular Material's color theming API.
@function get-color-tokens($config) {
  $is-dark: map.get($config, 'is-dark');
  $background: map.get($config, background);
  $on-surface: if($is-dark, #fff, #000);

  @return (
    // Background color of the container.
    container-color: theming.get-color-from-palette($background, dialog),
    // Color of the dialog header.
    subhead-color: rgba($on-surface, 0.87),
    // Color of the dialog body text.
    supporting-text-color: rgba($on-surface, 0.6),
  );
}

// Tokens that can be configured through Angular Material's typography theming API.
@function get-typography-tokens($config) {
  // TODO(crisbeto): The earlier implementation of the dialog used MDC's APIs to create the
  // typography tokens. As a result, we unintentionally allowed `null` typography configs to be
  // passed in. Since there a lot of apps that now depend on this pattern, we need this temporary
  // fallback.
  @if ($config == null) {
    $config: mdc-helpers.private-fallback-typography-from-mdc();
  }

  @return (
    // Typography of the dialog header.
    subhead-font: typography-utils.font-family($config, headline-6)
      or typography-utils.font-family($config),
    subhead-line-height: typography-utils.line-height($config, headline-6),
    subhead-size: typography-utils.font-size($config, headline-6),
    subhead-weight: typography-utils.font-weight($config, headline-6),
    subhead-tracking: typography-utils.letter-spacing($config, headline-6),
    // Typography of the dialog body text.
    supporting-text-font: typography-utils.font-family($config, body-1)
      or typography-utils.font-family($config),
    supporting-text-line-height: typography-utils.line-height($config, body-1),
    supporting-text-size: typography-utils.font-size($config, body-1),
    supporting-text-weight: typography-utils.font-weight($config, body-1),
    supporting-text-tracking: typography-utils.letter-spacing($config, body-1),
  );
}

// Tokens that can be configured through Angular Material's density theming API.
@function get-density-tokens($config) {
  @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 sass-utils.deep-merge-all(
      get-unthemable-tokens(),
      get-color-tokens(token-utils.$placeholder-color-config),
      get-typography-tokens(token-utils.$placeholder-typography-config),
      get-density-tokens(token-utils.$placeholder-density-config)
  );
}
