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

@mixin _calendar-color($theme, $palette-name) {
  $palette-color: mat.get-theme-color($theme, $palette-name);
  $calendar-tokens: m2-datetimepicker.private-get-calendar-color-palette-color-tokens($theme, $palette-name);

  @include token-utils.create-token-values-mixed($calendar-tokens);
}

@mixin base($theme) {
  @if mat.get-theme-version($theme) == 1 {
    @include token-utils.create-token-values(map.get(m3-datetimepicker.get-tokens($theme), base));
  }
  @else {
    @include mat.private-current-selector-or-root() {
      @include token-utils.create-token-values-mixed(m2-datetimepicker.get-unthemable-tokens());
    }
  }
}

@mixin color($theme, $color-variant: null) {
  @if mat.get-theme-version($theme) == 1 {
    @include token-utils.create-token-values(map.get(m3-datetimepicker.get-tokens($theme, $color-variant), color));
  }
  @else {
    @include mat.private-current-selector-or-root() {
      @include token-utils.create-token-values-mixed(m2-datetimepicker.get-color-tokens($theme));
    }

    .mtx-datetimepicker-content {
      &.mat-accent {
        @include _calendar-color($theme, accent);
      }

      &.mat-warn {
        @include _calendar-color($theme, warn);
      }
    }

    .mtx-datetimepicker-toggle-active {
      &.mat-accent {
        $accent-tokens: m2-datetimepicker.private-get-toggle-color-palette-color-tokens($theme, accent);
        @include token-utils.create-token-values-mixed($accent-tokens);
      }

      &.mat-warn {
        $warn-tokens: m2-datetimepicker.private-get-toggle-color-palette-color-tokens($theme, warn);
        @include token-utils.create-token-values-mixed($warn-tokens);
      }
    }
  }
}

@mixin typography($theme) {
  @if mat.get-theme-version($theme) == 1 {
    @include token-utils.create-token-values(map.get(m3-datetimepicker.get-tokens($theme), typography));
  }
  @else {
    @include mat.private-current-selector-or-root() {
      @include token-utils.create-token-values-mixed(m2-datetimepicker.get-typography-tokens($theme));
    }
  }
}

@mixin density($theme) {
  @if mat.get-theme-version($theme) == 1 {
    @include token-utils.create-token-values(map.get(m3-datetimepicker.get-tokens($theme), density));
  }
  @else {
    @include mat.private-current-selector-or-root() {
      @include token-utils.create-token-values-mixed(m2-datetimepicker.get-density-tokens($theme));
    }
  }
}

/// Defines the tokens that will be available in the `overrides` mixin and for docs extraction.
@function _define-overrides() {
  @return (
    (
      namespace: datetimepicker,
      tokens: token-utils.get-overrides(m3-datetimepicker.get-tokens(), datetimepicker),
    ),
  );
}

@mixin overrides($tokens: ()) {
  @include token-utils.batch-create-token-values($tokens, _define-overrides());
}

@mixin theme($theme, $color-variant: null) {
  @include mat.private-check-duplicate-theme-styles($theme, 'mtx-datetimepicker') {
    @if mat.get-theme-version($theme) == 1 {
      @include base($theme);
      @include color($theme, $color-variant);
      @include density($theme);
      @include typography($theme);
    }
    @else {
      @include base($theme);
      @if mat.theme-has($theme, color) {
        @include color($theme);
      }
      @if mat.theme-has($theme, density) {
        @include density($theme);
      }
      @if mat.theme-has($theme, typography) {
        @include typography($theme);
      }
    }
  }
}
