@use '@angular/material' as mat;

@mixin _unelevated-button-variant($theme, $palette) {
  --mdc-filled-button-label-text-color: #{mat.get-theme-color($theme, $palette, default-contrast)};
  --mat-filled-button-ripple-color: #{rgba(
      mat.get-theme-color($theme, $palette, default-contrast),
      0.1
    )};
  --mat-filled-button-state-layer-color: #{mat.get-theme-color($theme, $palette, default-contrast)};
}

@mixin _raised-button-variant($theme, $palette) {
  --mdc-protected-button-label-text-color: #{mat.get-theme-color($theme, $palette, default-contrast)};
  --mat-protected-button-ripple-color: #{rgba(
      mat.get-theme-color($theme, $palette, default-contrast),
      0.1
    )};
  --mat-protected-button-state-layer-color: #{mat.get-theme-color(
      $theme,
      $palette,
      default-contrast
    )};
}

@mixin _fab-color($theme, $palette) {
  --mat-fab-foreground-color: #{mat.get-theme-color($theme, $palette, default-contrast)};
  --mat-fab-ripple-color: #{rgba(mat.get-theme-color($theme, $palette, default-contrast), 0.1)};
  --mat-fab-state-layer-color: #{mat.get-theme-color($theme, $palette, default-contrast)};
}

@mixin _fab-colors($theme) {
  .mat-mdc-fab,
  .mat-mdc-mini-fab {
    &.mat-primary {
      @include _fab-color($theme, primary);
    }

    &.mat-accent {
      @include _fab-color($theme, accent);
    }

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

@mixin button-theme($theme) {
  .mat-mdc-unelevated-button {
    &.mat-primary {
      @include _unelevated-button-variant($theme, primary);
    }

    &.mat-accent {
      @include _unelevated-button-variant($theme, accent);
    }

    &.mat-warn {
      @include _unelevated-button-variant($theme, warn);
    }
  }

  .mat-mdc-raised-button {
    &.mat-primary {
      @include _raised-button-variant($theme, primary);
    }

    &.mat-accent {
      @include _raised-button-variant($theme, accent);
    }

    &.mat-warn {
      @include _raised-button-variant($theme, warn);
    }
  }

  @include _fab-colors($theme);
  // Unsure why but the material fab styles target html, if anyone knows, let me know!
  html {
    @include _fab-colors($theme);
  }
}
