@import '../../styles/common';

$accent-height: 3px;
$heading-offset: rem(2px);
$intermediate-spacing: spacing(base-tight);
$ribbon-flex-basis: rem(32px);
$secondary-action-vertical-padding: 0.5 * (control-height() - line-height(body));
$secondary-action-horizontal-padding: 1.5 * spacing(tight);

@mixin banner-attributes($highlight, $background, $in-page, $tint) {
  transition: box-shadow duration() easing();
  transition-delay: duration(fast);

  @media (-ms-high-contrast: active) {
    box-shadow: inset 0 $accent-height 0 0 ms-high-contrast-color('text'),
      inset 0 0 border-width(base) border-width(base)
        ms-high-contrast-color('text');
  }

  @if $in-page {
    box-shadow: inset 0 $accent-height 0 0 $highlight, inset shadow(transparent),
      shadow();
  }

  @if $tint {
    background-color: mix(white, $background, 44%);
  } @else {
    background-color: $background;
  }

  &:focus {
    outline: none;
    box-shadow: inset 0 $accent-height 0 0 $highlight,
      inset 0 0 0 $accent-height $highlight, shadow();
    @media (-ms-high-contrast: active) {
      box-shadow: inset 0 0 0 $accent-height ms-high-contrast-color('text');
    }
  }
}

@mixin banner-variants($in-page: false) {
  @include banner-attributes(
    color('ink', 'lighter'),
    color('sky', 'light'),
    $in-page,
    false
  );

  &.statusSuccess {
    @include banner-attributes(
      color('green'),
      color('green', 'lighter'),
      $in-page,
      true
    );
  }

  &.statusInfo {
    @include banner-attributes(
      color('teal'),
      color('teal', 'lighter'),
      $in-page,
      true
    );
  }

  &.statusWarning {
    @include banner-attributes(
      color('yellow'),
      color('yellow', 'lighter'),
      $in-page,
      true
    );
  }

  &.statusCritical {
    @include banner-attributes(
      color('red'),
      color('red', 'lighter'),
      $in-page,
      true
    );
  }
}

.Banner {
  position: relative;
  display: flex;
}

.withinContentContainer {
  border-radius: border-radius();
  padding: spacing(tight) $intermediate-spacing;

  @include banner-variants;

  + .Banner {
    margin-top: spacing(tight);
  }

  .Ribbon {
    padding-right: $intermediate-spacing;
  }

  .Actions {
    padding: $intermediate-spacing 0 spacing(extra-tight) 0;
  }

  .Dismiss {
    right: $intermediate-spacing;
    top: $intermediate-spacing;
    position: absolute;
  }
}

.withinPage {
  border-radius: 0 0 border-radius() border-radius();
  padding: spacing();

  @include banner-variants(true);

  + .Banner {
    margin-top: spacing(loose);
  }

  .Ribbon {
    padding-right: spacing();
  }

  .Actions {
    padding-top: spacing();
  }

  .Dismiss {
    right: spacing();
    top: spacing(loose);
    position: absolute;
  }
}

.hasDismiss {
  padding-right: spacing() + spacing(extra-tight) + control-height();
}

.Heading {
  padding-top: $heading-offset;
  word-break: break-word;
}

.Content {
  @include text-breakword;
  padding: spacing(extra-tight) 0;
}

.Ribbon {
  flex: 0 0 $ribbon-flex-basis;
}

.PrimaryAction {
  margin-right: rem(6px);
}

// We need pretty high specificity to do the descendant selectors
// onto the text, which needs to be the relative positioned wrapper
// so that the borders/ backgrounds do not extend outside of it.
// stylelint-disable selector-max-specificity

.SecondaryAction {
  @include unstyled-button;
  @include unstyled-link;
  display: inline-block;
  margin: (-1 * $secondary-action-vertical-padding)
    (-0.5 * $secondary-action-horizontal-padding);
  padding: $secondary-action-vertical-padding
    $secondary-action-horizontal-padding;
  color: color('ink');
  padding-left: rem(6px);

  &:hover > .Text::after {
    opacity: 0.75;
  }

  &:active > .Text::after {
    opacity: 0;
  }

  &:focus > .Text {
    @include plain-button-backdrop;
    @include high-contrast-button-outline;

    &::after {
      opacity: 0;
    }
  }
}

// stylelint-enable selector-max-specificity
.Text {
  position: relative;

  &::after,
  &::before {
    content: '';
    position: absolute;
  }

  &::after {
    bottom: 0;
    left: 0;
    right: 0;
    display: block;
    border: border-width() solid currentColor;
    opacity: 0.25;
    will-change: opacity;
    transition: opacity duration() easing();
  }
}
