/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
@use 'sass:map';
@use '@material/theme/color-palette' as mdc-color-palette;
@use '@material/theme/theme-color' as mdc-theme-color;
@use '@material/elevation/elevation-theme' as mdc-elevation-theme;
@use './keys';

/// MDC theme variable overrides
$primary: mdc-color-palette.$indigo-500 !default;
$on-primary: #ffffff !default;
$secondary: mdc-color-palette.$amber-500 !default;
$on-secondary: #000000 !default;
$accent: $secondary !default;
$on-accent: $on-secondary !default;
$background: mdc-color-palette.$grey-50 !default;
$surface: #ffffff !default;
$on-surface: #000000 !default;
$error: #b00020 !default;
$on-error: #ffffff !default;
$text-disabled-on-background: rgba(0, 0, 0, 0.12) !default;

// Tyler theme variables
$success: #2e7d32 !default;
$success-muted: #a5d6a7 !default;
$success-text-muted: #1b5e20 !default;
$warning: #d14900 !default;
$warning-muted: #ffdba6 !default;
$warning-text-muted: #a03a03 !default;
$danger: $error !default;
$danger-hover: #db8a98; //350 37 86
$danger-muted: #ffcdd2 !default;
$danger-text-muted: #a22d0e !default;
$info-primary: #1a237e !default;
$info-primary-muted: #bbdefb !default;
$info-primary-text-muted: #1a237e !default;
$info-secondary: #000000 !default;
$info-secondary-muted: #e0e0e0 !default;
$info-secondary-text-muted: #000000 !default;
$info: mdc-color-palette.$grey-800 !default;
$label-color: mdc-color-palette.$grey-700 !default;
$icon-color: mdc-color-palette.$grey-600 !default;
$disabled-color: mdc-color-palette.$grey-500 !default;
$border-color: mdc-color-palette.$grey-300 !default;
$disabled-background: #f0f0f0 !default;
$border: 1px solid $border-color !default;
$text-primary-color: rgba(0, 0, 0, 0.87) !default;
$text-secondary-color: rgba(0, 0, 0, 0.54) !default;
$tertiary: mdc-color-palette.$indigo-a400 !default;
$on-tertiary: #ffffff !default;
$danger: $theme-danger !default;
$warning: $theme-warning !default;
$success: $theme-success !default;
$info: $theme-info !default;
$form-field-icon-disabled-on-background: rgba(0, 0, 0, 0.26) !default;
$form-field-text-disabled-on-background: rgba(0, 0, 0, 0.6) !default;
$form-field-disabled-on-background: mdc-color-palette.$grey-100 !default;
$form-field-label-on-background: rgba(0, 0, 0, 0.65) !default;
$label-disabled-on-background: rgba(0, 0, 0, 0.38) !default;
$elevated-surface: $surface !default;
$on-elevated-surface: rgba(0, 0, 0, 0.87) !default;
$popup-elevation: mdc-elevation-theme.elevation-box-shadow(2) !default;
$scrollbar-width: 16px !default;
$scrollbar-height: 16px !default;
$scrollbar-thumb-min-height: 32px !default;
$scrollbar-thumb-min-width: 32px !default;
$scrollbar-thumb: mdc-color-palette.$grey-400 !default;
$scrollbar-thumb-hover: mdc-color-palette.$grey-500 !default;
$scrollbar-track: #f0f0f0 !default;
$scrollbar-track-hover: #ececec !default;

$z-index-surface: 1 !default;
$z-index-header: 4 !default;
$z-index-backdrop: 7 !default;
$z-index-dialog: 8 !default;
$z-index-notification: 9 !default;
$z-index-popup: 10 !default;
$z-index-tooltip: 11 !default;

$z-index-values: (
  surface: $z-index-surface,
  header: $z-index-header,
  backdrop: $z-index-backdrop,
  dialog: $z-index-dialog,
  notification: $z-index-notification,
  popup: $z-index-popup,
  tooltip: $z-index-tooltip
) !default;

/// Colors to display in light and dark contrast contexts
$text-colors: (
  dark: (
    primary: rgba(0, 0, 0, 0.87),
    secondary: rgba(0, 0, 0, 0.54),
    hint: rgba(0, 0, 0, 0.38),
    disabled: rgba(0, 0, 0, 0.38),
    disabled-secondary: rgba(0, 0, 0, 0.12),
    icon: rgba(0, 0, 0, 0.38)
  ),
  light: (
    primary: rgba(255, 255, 255, 0.87),
    secondary: rgba(255, 255, 255, 0.7),
    secondary-alternative: rgba(255, 255, 255, 0.54),
    hint: rgba(255, 255, 255, 0.5),
    disabled: rgba(255, 255, 255, 0.5),
    disabled-secondary: rgba(255, 255, 255, 0.12),
    icon: rgba(255, 255, 255, 0.5)
  ),
) !default;

/// A map of text emphasis opacities by name
$text-emphasis: (
  high: 0.87,
  medium: 0.6,
  disabled: 0.38,
) !default;

/// A map of background colors and their contrast color to use on that background
$background-colors: (
  primary: $primary,
  danger: $danger,
  warning: $warning,
  success: $success,
  info-primary: $info-primary,
  info-secondary: $info-secondary,
  contrast: (
    primary: #ffffff,
    danger: #ffffff,
    warning: #ffffff,
    success: #ffffff,
    info-primary: #ffffff,
    info-secondary: #ffffff
  )
);

/// Returns the original property values map
@function original-property-values() {
  @return map.merge((), $_property-values-copy);
}

/// Calculare color contrast on specific fill colors
@function color-on-background($text-style, $fill-color) {
  $contrast-tone: mdc-theme-color.contrast-tone($fill-color);
  @return map.get(map.get($text-colors, $contrast-tone), $text-style);
}

/// A map of theme/custom property names and corresponding values
$property-values: (
  tertiary: $tertiary,
  on-tertiary: $on-tertiary,
  border-color: $border-color,
  danger: $danger,
  error-hover: $danger-hover,
  warning: $warning,
  success: $success,
  info: $info,
  icon-color: $icon-color,
  form-field-label-on-background: $form-field-label-on-background,
  form-field-icon-disabled-on-background: $form-field-icon-disabled-on-background,
  form-field-text-disabled-on-background: $form-field-text-disabled-on-background,
  form-field-disabled-on-background: $form-field-disabled-on-background,
  label-disabled-on-background: $label-disabled-on-background,
  elevated-surface: $elevated-surface,
  on-elevated-surface: $on-elevated-surface,
  popup-elevation: $popup-elevation,
  scrollbar-thumb: $scrollbar-thumb,
  scrollbar-thumb-hover: $scrollbar-thumb-hover,
  scrollbar-track: $scrollbar-track,
  scrollbar-track-hover: $scrollbar-track-hover
) !default;

// Add our theme property values to the theme key store
@include keys.set-values($property-values, $options: (custom-property-prefix: theme));

/// Keep track of the original values for comparison in case they are customized later
$_property-values-copy: $property-values;

/// MDC theme property map
$mdc-property-values: (
  primary: $primary,
  secondary: $secondary,
  background: $background,
  error: $error,
  on-primary: $on-primary,
  on-secondary: $on-secondary,
  surface: $surface,
  on-surface: $on-surface,
  on-error: $on-error,
  text-primary-on-background: color-on-background(primary, $background),
  text-secondary-on-background: color-on-background(secondary, $background),
  text-hint-on-background: color-on-background(hint, $background),
  text-disabled-on-background: color-on-background(disabled-secondary, $background),
  text-icon-on-background: color-on-background(icon, $background),
  text-primary-on-light: color-on-background(primary, light),
  text-secondary-on-light: color-on-background(secondary, light),
  text-hint-on-light: color-on-background(hint, light),
  text-disabled-on-light: color-on-background(disabled, light),
  text-icon-on-light: color-on-background(icon, light),
  text-primary-on-dark: color-on-background(primary, dark),
  text-secondary-on-dark: color-on-background(secondary, dark),
  text-hint-on-dark: color-on-background(hint, dark),
  text-disabled-on-dark: color-on-background(disabled, dark),
  text-icon-on-dark: color-on-background(icon, dark)
) !default;

$property-values-dark: (
  // Core theme variables from MDC
  primary: #{mdc-color-palette.$indigo-a100},
  secondary: #{mdc-color-palette.$amber-200},
  background: #{mdc-color-palette.$grey-900},
  surface: #2c2c2c,
  error: #cf6679,
  on-primary: #000000,
  on-secondary: #000000,
  on-surface: #ffffff,
  on-error: #000000,
  text-primary-on-dark: #000000,
  text-primary-on-background: rgba(255, 255, 255, 0.87),
  text-secondary-on-background: rgba(255, 255, 255, 0.54),
  text-hint-on-background: rgba(255, 255, 255, 0.38),
  text-icon-on-background: rgba(255, 255, 255, 0.38),
  text-disabled-on-background: rgba(255, 255, 255, 0.12),
  text-disabled-on-light: rgba(255, 255, 255, 0.38),
  text-secondary-on-light: rgba(255, 255, 255, 0.54),

  // forge-specific theme properties
  tertiary: #{mdc-color-palette.$amber-200},
  border-color: #464646,
  form-field-icon-disabled-on-background: rgba(255, 255, 255, 0.26),
  form-field-disabled-on-background: #353535,
  form-field-text-disabled-on-background: rgba(255, 255, 255, 0.6),
  form-field-label-on-background: rgba(255, 255, 255, 0.65),
  label-disabled-on-background: rgba(255, 255, 255, 0.38),
  scrollbar-thumb: #{mdc-color-palette.$grey-600},
  scrollbar-thumb-hover: #{mdc-color-palette.$grey-500},
  scrollbar-track: #3a3a3a,
  scrollbar-track-hover: #{mdc-color-palette.$grey-800},
  elevated-surface: #363636,
  on-elevated-surface: rgba(255, 255, 255, 0.87),
  popup-elevation: #{mdc-elevation-theme.elevation-box-shadow(16)}
) !default;
