// This is a heavily customized version of Bulma's message component
// Original copyright (c) 2019 Jeremy Thomas, The MIT License (MIT)
$admonition-colors: (
  'default': $admonition-default, 'info': $info, 'success': $success, 'warning': $warning,
  'danger': $danger, 'compat': $compat, 'todo': $todo,
) !default;

$admonition-background: () !default;
$admonition-body-color: () !default;
$admonition-header-background: () !default;
$admonition-header-color: () !default;
$admonition-border-color: () !default;
@each $name, $color in $admonition-colors {
  // $bg: lighten-color($color, 5);
  @if not map-has-key($admonition-header-background, $name) {
    $admonition-header-background: map-merge($admonition-header-background, ($name: transparent)) !global;
  }
  @if not map-has-key($admonition-header-color, $name) {
    $admonition-header-color: map-merge($admonition-header-color, ($name: $color)) !global;
  }
  @if not map-has-key($admonition-border-color, $name) {
    $admonition-border-color: map-merge($admonition-border-color, ($name: $color)) !global;
  }
  @if not map-has-key($admonition-background, $name) {
    $admonition-background: map-merge($admonition-background, ($name: $background)) !global;
  }
  @if not map-has-key($admonition-body-color, $name) {
    $admonition-body-color: map-merge($admonition-body-color, ($name: findColorInvert($background))) !global;
  }
}

.admonition {
  @extend %block;

  background-color: map-get($admonition-background, 'default');
  border-style: solid;
  border-width: $documenter-admonition-border-width;
  border-color: map-get($admonition-border-color, 'default');
  border-radius: $documenter-admonition-border-radius;
  font-size: $size-normal;

  strong {
    color: currentColor;
  }

  // Sizes
  &.is-small {
    font-size: $size-small;
  }

  &.is-medium {
    font-size: $size-medium;
  }

  &.is-large {
    font-size: $size-large;
  }

  // Colors
  @each $name, $pair in $admonition-colors {
    // $text-color: desaturate(darken($color, $darken-percentage), $desaturate-percentage);
    // $color-lightning: max(100% - lightness($color) - 5%, 0%);
    // $background: lighten($color, $color-lightning);

    &.is-#{$name} {
      background-color: map-get($admonition-background, $name);
      border-color: map-get($admonition-border-color, $name);

      > .admonition-header {
        background-color: map-get($admonition-header-background, $name);
        color: map-get($admonition-header-color, $name);
      }

      > .admonition-body {
        color: map-get($admonition-body-color, $name);
      }
    }
  }
}

.admonition-header {
  color: map-get($admonition-header-color, 'default');
  background-color: map-get($admonition-header-background, 'default');
  align-items: center;
  font-weight: $message-header-weight;
  justify-content: space-between;
  line-height: 1.25;
  padding: $documenter-admonition-header-padding;
  position: relative;

  &:before {
    @include font-awesome;
    margin-right: $documenter-container-left-padding;
    // fa-circle-exclamation
    content: "\f06a";
  }

  .admonition-anchor {
    opacity: 0;
    margin-left: 0.5em;
    font-size: 0.75em;
    color: inherit;
    text-decoration: none;
    transition: opacity 0.2s ease-in-out;
    
    &:before {
      @include font-awesome;
      // fa-link
      content: "\f0c1";
    }
    
    &:hover {
      opacity: 1 !important;
      text-decoration: none;
    }
  }
  
  &:hover .admonition-anchor {
    opacity: 0.8;
  }
}

details.admonition.is-details > .admonition-header {
    list-style: none;
    &:before {
        @include font-awesome;
        // fa-circle-plus
        content: "\f055";
    }
}

details[open].admonition.is-details > .admonition-header:before {
    @include font-awesome;
    // fa-circle-minus
    content: "\f056";
}

.admonition-body {
  color: $message-body-color;
  padding: $documenter-admonition-body-padding;

  pre {
    background-color: $pre-background;
  }

  code {
    background-color: $code-background;
  }
}
