@use 'sass:map';
@use 'sass:meta';
@use '@material/density' as mdc-density;
@use '@material/typography' as mdc-typography;

@use '../core/typography/typography';
@use '../core/typography/typography-utils';
@use '../core/mdc-helpers/mdc-helpers';
@use '../core/theming/theming';
@use '../form-field/form-field-density';
@use './paginator-variables';

@mixin color($config-or-theme) {
  $config: theming.get-color-config($config-or-theme);
  $background: map.get($config, background);
  $foreground: map.get($config, foreground);
  $icon-color: rgba(theming.get-color-from-palette($foreground, base), 0.54);
  $disabled-color: rgba(theming.get-color-from-palette($foreground, base), 0.12);

  .mat-mdc-paginator {
    background: theming.get-color-from-palette($background, card);
    color: rgba(theming.get-color-from-palette($foreground, base), 0.87);
  }

  .mat-mdc-paginator-icon {
    fill: $icon-color;
  }

  .mat-mdc-paginator-decrement,
  .mat-mdc-paginator-increment {
    border-top: 2px solid $icon-color;
    border-right: 2px solid $icon-color;
  }

  .mat-mdc-paginator-first,
  .mat-mdc-paginator-last {
    border-top: 2px solid $icon-color;
  }

  .mat-mdc-icon-button[disabled] {
    .mat-mdc-paginator-decrement,
    .mat-mdc-paginator-increment,
    .mat-mdc-paginator-first,
    .mat-mdc-paginator-last {
      border-color: $disabled-color;
    }

    .mat-mdc-paginator-icon {
      fill: $disabled-color;
    }
  }
}

@mixin typography($config-or-theme) {
  $config: typography.private-typography-to-2018-config(
      theming.get-typography-config($config-or-theme));

  @include mdc-helpers.using-mdc-typography($config) {
    .mat-mdc-paginator {
      @include mdc-typography.typography(caption, $query: mdc-helpers.$mdc-typography-styles-query);
    }

    .mat-mdc-paginator .mat-mdc-select-value {
      font-size: typography-utils.font-size($config, caption);
    }
  }
}

@mixin density($config-or-theme) {
  $density-scale: theming.get-density-config($config-or-theme);
  $height: mdc-density.prop-value(
      paginator-variables.$density-config, $density-scale, height);

  .mat-mdc-paginator {
    // We need the form field to be narrower in order to fit into the paginator,
    // so we set its density to be -4 or denser.
    @if ((meta.type-of($density-scale) == 'number' and $density-scale >= -4) or
         $density-scale == maximum) {
      @include form-field-density.private-form-field-density(-4);
    }
    @else {
      @include form-field-density.private-form-field-density($density-scale);
    }
  }

  .mat-mdc-paginator-container {
    min-height: $height;
  }
}

@mixin theme($theme-or-color-config) {
  $theme: theming.private-legacy-get-theme($theme-or-color-config);
  @include theming.private-check-duplicate-theme-styles($theme, 'mat-paginator') {
    $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);
    }
  }
}
