@use 'sass:map';
@use '../core/theming/theming';

@mixin color($config-or-theme) {
  $config: theming.get-color-config($config-or-theme);
  $primary: map.get($config, primary);
  $accent: map.get($config, accent);
  $warn: map.get($config, warn);
  $background: map.get($config, background);
  $foreground: map.get($config, foreground);
  $is-dark-theme: map.get($config, is-dark);

  .mtx-form-group {
    .mtx-form-label {
      &.mtx-form-label-marker::after {
        color: theming.get-color-from-palette($warn);
      }
    }
  }

  .mtx-form-field-appearance-fluent {
    .mat-form-field-flex {
      border: 1px solid rgba(theming.get-color-from-palette($foreground, divider), .54);

      &:hover {
        border: 1px solid rgba(theming.get-color-from-palette($foreground, divider), .78);
      }
    }

    .mat-focused {
      .mat-form-field-flex {
        border-color: theming.get-color-from-palette($primary);
        box-shadow: inset 0 0 0 1px theming.get-color-from-palette($primary);
      }

      &.mat-accent {
        .mat-form-field-flex {
          border-color: theming.get-color-from-palette($accent);
          box-shadow: inset 0 0 0 1px theming.get-color-from-palette($accent);
        }
      }

      &.mat-warn {
        .mat-form-field-flex {
          border-color: theming.get-color-from-palette($warn);
          box-shadow: inset 0 0 0 1px theming.get-color-from-palette($warn);
        }
      }
    }

    .mat-form-field-invalid {
      .mat-form-field-flex,
      &.mat-accent .mat-form-field-flex,
      &.mat-warn .mat-form-field-flex {
        border-color: theming.get-color-from-palette($warn);
        box-shadow: inset 0 0 0 1px theming.get-color-from-palette($warn);
      }
    }

    .mat-form-field-disabled {
      .mat-form-field-flex {
        background-color: theming.get-color-from-palette($background, disabled-button);
        border-color: theming.get-color-from-palette($foreground, divider);
      }
    }

    .mat-form-field-label,
    .mat-hint {
      color: theming.get-color-from-palette($foreground, secondary-text);
    }
  }
}

@mixin typography($config-or-theme) {}

@mixin _density($config-or-theme) {}

@mixin theme($theme-or-color-config) {
  $theme: theming.private-legacy-get-theme($theme-or-color-config);
  @include theming.private-check-duplicate-theme-styles($theme, 'mtx-form-group') {
    $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);
    }
  }
}
