@use "sass:map";
@use "@angular/material" as mat;
@use "../global";
@use "../themes";

$radius: 16px !default;
$icon-spacing: global.$spacing !default;

@mixin override-color($theme) {
  $color-config: mat.get-color-config($theme);
  $primary-palette: map.get($color-config, "primary");
  $accent-palette: map.get($color-config, "accent");
  $warn-palette: map.get($color-config, "warn");

  .mat-mdc-button-base {
    /* TODO(mdc-migration): The following rule targets internal classes of button that may no longer apply for the MDC version. */
    &.mat-mdc-outlined-button:not([color]):not(.mat-button-disabled) {
      border-color: map.get(map.get($color-config, "foreground"), text);
    }
    &.mat-mdc-outlined-button.mat-primary {
      border-color: mat.get-color-from-palette($primary-palette);
    }
    &.mat-mdc-outlined-button.mat-accent {
      border-color: mat.get-color-from-palette($accent-palette);
    }
    &.mat-mdc-outlined-button.mat-warn {
      border-color: mat.get-color-from-palette($warn-palette);
    }
  }
}

@mixin override-theme($theme) {
  $color-config: mat.get-color-config($theme);

  // Temporary for typo.
  --mdc-typography-button-letter-spacing: normal;

  @if $color-config != null {
    @include override-color($theme);
  }

  .mat-mdc-button-base {
    &.mdc-button,
    &.mat-mdc-unelevated-button,
    &.mat-mdc-outlined-button,
    &.mat-mdc-raised-button {
      text-transform: uppercase;
      border-radius: $radius;
    }

    .mat-icon {
      height: 24px;
      width: 24px;
      font-size: 24px;
    }
  }

  .mat-mdc-button,
  .mat-mdc-unelevated-button,
  .mat-mdc-raised-button,
  .mat-mdc-outlined-button {
    white-space: nowrap;
    .mdc-button__label {
      z-index: 0;
    }
  }

  .mdc-button {
    //For responsive behavior
    min-width: unset;
  }
}
