@use 'sass:map';
@use '~@angular/material' as mat;

@mixin color($theme) {
  $config: mat.get-color-config($theme);
  $primary: map.get($config, primary);
  $accent: map.get($config, accent);
  $background: map.get($config, background);
  $foreground: map.get($config, foreground);
  $is-dark-theme: map-get($config, is-dark);
  $disabled-search: if($is-dark-theme, map-get(mat.$grey-palette, 500), map-get(mat.$grey-palette, 300));

  mtna-search-box {
    &.mat-primary {
      @include _mtna-search-box-palette($primary);
    }
    &.mat-accent {
      @include _mtna-search-box-palette($accent);
    }
    .search-container {
      background-color: mat.get-color-from-palette($background, card);
      border: 1px solid mat.get-color-from-palette($foreground, divider);
      .close-button,
      input {
        color: mat.get-color-from-palette($foreground, text);
      }
      &.disabled {
        background-color: $disabled-search;
        .close-button,
        input {
          color: mat.get-color-from-palette($foreground, disabled-text);
        }
        .search-button {
          background-image: none;
          background-color: mat.get-color-from-palette($background, disabled-button);
          box-shadow: none;
          .mat-icon {
            color: mat.get-color-from-palette($foreground, disabled-text);
          }
        }
      }
      & > input::-webkit-input-placeholder,
      & > input:-moz-placeholder,
      & > input::-moz-placeholder,
      & > input:-ms-input-placeholder {
        color: mat.get-color-from-palette($foreground, disabled-text);
      }
    }
  }
}

@mixin typography($theme) {
  mtna-search-box {
    .search-container input {
      font-size: 20px;
    }
  }
}

@mixin theme($theme) {
  $config: mat.get-color-config($theme);
  @if $config != null {
    @include color($theme);
  }

  @include typography($theme);
}

@mixin _mtna-search-box-palette($palette) {
  .search-container:not(.disabled) {
    .search-button {
      background-image: none;
      background-color: mat.get-color-from-palette($palette);
      .mat-icon {
        color: mat.get-color-from-palette($palette, default-contrast);
      }
    }
  }
}
