@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, primary);
  $background: map.get($config, background);
  $foreground: map.get($config, foreground);

  rds-c-api-snippets-dialog {
    // Give the active tab the same styles as a focused tab
    .mat-tab-group {
      &.mat-primary {
        @include _rds-c-api-snippets-active-tab($primary);
      }
      &.mat-accent {
        @include _rds-c-api-snippets-active-tab($accent);
      }
    }

    .rds-c-snippets-link-button {
      @include _rds-c-api-snippets-outline-button($foreground);
    }
  }

  rds-c-code-snippet {
    .rds-c-code-snippet-container,
    .rds-c-code-snippet-copy-button {
      background-color: mat.get-color-from-palette($background, background);
      color: mat.get-color-from-palette($foreground, base);
    }

    .rds-c-code-snippet-copy-button {
      @include _rds-c-api-snippets-outline-button($foreground);
    }

    .rds-c-snippet-secondary-color {
      color: mat.get-color-from-palette($foreground, secondary-text);
    }
  }

  rds-c-versioned-code-snippets {
    .mat-action-list {
      .mat-list-item.active {
        background-color: mat.get-color-from-palette($background, app-bar, 0.8);
        border-right-color: mat.get-color-from-palette($primary);
      }
      .mat-list-item:focus,
      .mat-list-item:hover {
        background-color: mat.get-color-from-palette($background, app-bar, 0.6);
      }
    }
  }
}

@mixin typography($theme) {
}

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

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

@mixin _rds-c-api-snippets-active-tab($color) {
  .mat-tab-label-active {
    opacity: 1;
    background-color: mat.get-color-from-palette($color, lighter, 0.3);
  }
}

@mixin _rds-c-api-snippets-outline-button($foreground) {
  border-color: mat.get-color-from-palette($foreground, divider);
  transition: border-color 300ms cubic-bezier(0, 0, 0.2, 1);
  &:hover {
    border-color: mat.get-color-from-palette($foreground, secondary-text);
  }
}
