@use '@angular/material' as mat;
@mixin mw-mat-button-override($theme) {
  $primary: map-get($theme, primary);
  $accent: map-get($theme, accent);
  $warn: map-get($theme, warn);

  $background: (
    mat-button-overlay-hover-opacity: 0.04,
    mat-button-overlay-focus-opacity: 0.12,
    mat-button-overlay-pressed-opacity: 0.1,
    outline-warn-button-border-color: mat.get-color-from-palette($warn),
  );

  $foreground: ();

  $theme-background: map-get($theme, background);
  $theme-foreground: map-get($theme, foreground);

  $background: map-merge($background, $theme-background);
  $foreground: map-merge($foreground, $theme-foreground);

  button.mat-button,
  .mat-raised-button,
  .mat-flat-button,
  .mat-stroked-button {
    border-radius: 2px;
    &.mw-density {
      &-1 {
        line-height: 32px;
      }
      &-3 {
        line-height: 24px;
      }
    }

    .mat-button-wrapper {
      mat-icon {
        width: 18px;
        height: 18px;
        font-size: 18px;
        line-height: 18px;
        position: relative;
        top: -1px;
        &:first-child {
          left: -4px;
        }
        &:last-child:not(:first-child) {
          right: -4px;
        }
      }
      div {
        display: contents;
      }
    }

    &.mat-primary:not([disabled])
      mat-icon.mat-icon-no-color:not(.mw-button-icon-custom-color) {
      color: mat.get-color-from-palette(map-get($theme, accent));
    }

    &.mat-button-disabled {
      color: var(--mw-disabled-text) !important;
    }
  }

  .mat-icon-button {
    &.mat-button-disabled {
      color: var(--mw-disabled-text) !important;
    }
  }

  button.mat-button-base {
    &:not([disabled]) {
      .mat-button-focus-overlay,
      .mat-ripple-element {
        background-color: currentColor;
      }
    }
    &.cdk-keyboard-focused .mat-button-focus-overlay {
      opacity: map-get($background, mat-button-overlay-focus-opacity);
    }
    .mat-ripple-element {
      opacity: map-get($background, mat-button-overlay-pressed-opacity);
    }
  }

  button.mat-stroked-button:not([disabled]) {
    border-color: var(--mw-divider);
  }

  button.mat-stroked-button:not([disabled]).mat-warn {
    border-color: map-get($background, outline-warn-button-border-color);
  }

  button.mat-primary:not([disabled]) {
    &.mat-button,
    &.mat-stroked-button {
      .mat-button-wrapper {
        color: var(--mw-text);
      }
    }
  }
}
