@use '@material/radio/radio' as mdc-radio;
@use '@material/radio/radio-theme' as mdc-radio-theme;
@use '@material/form-field' as mdc-form-field;
@use '../core/mdc-helpers/mdc-helpers';
@use '../core/theming/theming';
@use '../core/typography/typography';
@use './radio-private';
@use 'sass:map';

@mixin color($config-or-theme) {
  $config: theming.get-color-config($config-or-theme);
  $primary: theming.get-color-from-palette(map.get($config, primary));
  $accent: theming.get-color-from-palette(map.get($config, accent));
  $warn: theming.get-color-from-palette(map.get($config, warn));

  @include mdc-helpers.using-mdc-theme($config) {
    .mat-mdc-radio-button {
      @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-theme-styles-query);

      &.mat-primary {
        @include radio-private.private-radio-color($config, $primary);
      }

      &.mat-accent {
        @include radio-private.private-radio-color($config, $accent);
      }

      &.mat-warn {
        @include radio-private.private-radio-color($config, $warn);
      }
    }
  }
}

@mixin typography($config-or-theme) {
  $config: typography.private-typography-to-2018-config(
      theming.get-typography-config($config-or-theme));
  @include mdc-helpers.using-mdc-typography($config) {
    @include mdc-radio.without-ripple($query: mdc-helpers.$mdc-typography-styles-query);
    @include mdc-form-field.core-styles($query: mdc-helpers.$mdc-typography-styles-query);
  }
}

@mixin density($config-or-theme) {
  $density-scale: theming.get-density-config($config-or-theme);
  .mat-mdc-radio-button .mdc-radio {
    @include mdc-radio-theme.density($density-scale, $query: mdc-helpers.$mdc-base-styles-query);
  }

  @include mdc-helpers.if-touch-targets-unsupported($density-scale) {
    .mat-mdc-radio-touch-target {
      display: none;
    }
  }
}

@mixin theme($theme-or-color-config) {
  $theme: theming.private-legacy-get-theme($theme-or-color-config);
  @include theming.private-check-duplicate-theme-styles($theme, 'mat-radio') {
    $color: theming.get-color-config($theme);
    $density: theming.get-density-config($theme);
    $typography: theming.get-typography-config($theme);

    @if $color != null {
      @include color($color);
    }
    @if $density != null {
      @include density($density);
    }
    @if $typography != null {
      @include typography($typography);
    }
  }
}
