@import '../core/theming/theming';


@mixin md-checkbox-theme($theme) {
  $is-dark-theme: map-get($theme, is-dark);
  $primary: map-get($theme, primary);
  $accent: map-get($theme, accent);
  $warn: map-get($theme, warn);
  $background: map-get($theme, background);


  // The color of the checkbox border.
  $checkbox-border-color: if($is-dark-theme, rgba(white, 0.7), rgba(black, 0.54)) !default;

  // The color of the checkbox's checkmark / mixedmark.
  $checkbox-mark-color: md-color($background, background);

  // NOTE(traviskaufman): While the spec calls for translucent blacks/whites for disabled colors,
  // this does not work well with elements layered on top of one another. To get around this we
  // blend the colors together based on the base color and the theme background.
  $white-30pct-opacity-on-dark: #686868;
  $black-26pct-opacity-on-light: #b0b0b0;
  $disabled-color: if($is-dark-theme, $white-30pct-opacity-on-dark, $black-26pct-opacity-on-light);

  .md-checkbox-frame {
    border-color: $checkbox-border-color;
  }

  .md-checkbox-checkmark {
    fill: $checkbox-mark-color;
  }

  .md-checkbox-checkmark-path {
    // !important is needed here because a stroke must be set as an attribute on the SVG in order
    // for line animation to work properly.
    stroke: $checkbox-mark-color !important;
  }

  .md-checkbox-mixedmark {
    background-color: $checkbox-mark-color;
  }

  .md-checkbox-indeterminate, .md-checkbox-checked {
    &.md-primary .md-checkbox-background {
      background-color: md-color($primary, 500);
    }

    &.md-accent .md-checkbox-background {
      background-color: md-color($accent, 500);
    }

    &.md-warn .md-checkbox-background {
      background-color: md-color($warn, 500);
    }
  }

  .md-checkbox-disabled {
    &.md-checkbox-checked, &.md-checkbox-indeterminate {
      .md-checkbox-background {
        background-color: $disabled-color;
      }
    }

    &:not(.md-checkbox-checked) {
      .md-checkbox-frame {
        border-color: $disabled-color;
      }
    }
  }

  .md-checkbox:not(.md-checkbox-disabled) {
    &.md-primary .md-checkbox-ripple .md-ripple-foreground {
      background-color: md-color($primary, 0.26);
    }

    &.md-accent .md-checkbox-ripple .md-ripple-foreground {
      background-color: md-color($accent, 0.26);
    }

    &.md-warn .md-checkbox-ripple .md-ripple-foreground {
      background-color: md-color($warn, 0.26);
    }
  }
}
