// NOTICE
// A list of notices, e.g. notifications/messages, in a utility panel under a sub-nav trigger
// (.sub-nav__content--utility, see _utility-panel.scss).
//
// Parts:
// .notice-feed        the title (.sub-nav__header) and the scrolling list, in the panel
// .notice-list        the list itself, with .notice-list__item for each row
// .notice-feed__footer  "clear all" and, on mobile, the sticky .notice-feed__scroll-to-top button
// .notice             one notice: source, time, text and an optional link
// .sub-nav__badge     the unread count on the trigger

$notice-dot-size: 10px;
$notice-separator-size: 2px;
$notice-fade-transition: 0.15s;
$notice-footer-fade-height: spacing(2); // on mobile, the fade above the sticky footer
$notice-footer-transition: 0.2s;

// The height of a small button: two vertical paddings and one line. The feed's fade is this tall
// plus spacing(0), so it covers a floating button (e.g. "clear all") whether or not it is shown.
$notice-button-height: spacing($button-padding-vertical-small, $times: 2, $add: "#{line-height("single", $include-calc: false)}");
$notice-fade-height: spacing(0, $add: $notice-button-height);

// UNREAD COUNT ON THE TRIGGER
// A round dot. Its size, its digits and its position follow the size of the bell icon, so the dot keeps
// the same proportion to the icon at every breakpoint. The numbers come from the design, for the
// smallest breakpoint, where the glyph of the bell is 19.2px:
// - the dot is 16px and the digits are 10px;
// - the left edge of the dot is at the middle of the bell;
// - the top edge of the dot is level with the top edge of the icon box, which is 22px high.
// The count is never wider than "9+", so the digits fit in the dot and the dot does not need to grow.
$notice-badge-size: 0.8333; // 16px, of the glyph size of the bell
$notice-badge-font-size: 0.5208; // 10px, of the glyph size of the bell
$notice-badge-top-offset: 0.5729; // 11px, of the glyph size of the bell: half the height of the icon box
.sub-nav__badge {
  --notice-badge-icon-size: var(--font-size-p1); // the size of the bell glyph

  position: absolute;
  top: calc(50% - var(--notice-badge-icon-size) * #{$notice-badge-top-offset});
  left: 50%;
  width: calc(var(--notice-badge-icon-size) * #{$notice-badge-size});
  height: calc(var(--notice-badge-icon-size) * #{$notice-badge-size});
  padding: 0;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background-color: color("utility-attention");
  color: color("utility-foreground");
  font-size: calc(var(--notice-badge-icon-size) * #{$notice-badge-font-size});
  font-weight: $font-weight-normal;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  pointer-events: none;
}

// FEED
// The title and the list scroll together. The feed is the scroll area of the panel, so the scroll
// bar is at the outer edge of the panel. The padding is on __content, inside the element that
// scrolls, so it does not move the scroll bar inward.
.notice-feed {
  @include utility-panel-scroll-area($from-top: true);

  display: flex;
  flex-direction: column;
  box-sizing: border-box;

  &__content {
    padding: var(--sub-nav-padding) var(--sub-nav-padding) spacing(1);
  }

  &__scroll {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;

    // Fade over the last rows; visible only while there is more to scroll to. It stops short of the
    // scroll bar (the app sets --notice-scrollbar-width to the width of the scroll bar).
    &::after {
      content: "";
      position: absolute;
      right: var(--notice-scrollbar-width, 0px);
      bottom: 0;
      left: 0;
      height: $notice-fade-height;
      background: linear-gradient(to bottom, transparent, color("background"));
      opacity: 0;
      pointer-events: none;
      transition: opacity $notice-fade-transition;
    }

    &--more::after {
      opacity: 1;
    }

    // Lets the last notice scroll clear of a floating button.
    &--with-footer .notice-feed__inner {
      padding-bottom: spacing(1);
    }
  }

  // The scrolling part. It has the scroll bar of the browser, the same as the body of a modal.
  &__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }

  // A button floating over the bottom right of the list, above the fade and clear of the scroll bar.
  // On mobile it is a sticky bar, see below.
  &__footer {
    position: absolute;
    right: calc(var(--sub-nav-padding) + var(--notice-scrollbar-width, 0px));
    bottom: spacing(1);
    z-index: 1;
  }

  // The "jump up" button. It is only for mobile, where the page scrolls and not the list.
  // It fades in when the page is scrolled down, see .notice-feed__scroll-to-top--visible.
  &__scroll-to-top {
    display: none;
  }

  // The layer fills the page, so the list fills the layer. On mobile --sub-nav-padding is the
  // page's side padding, which keeps the text in line with the page content.
  @include breakpoint("medium", $mobile-last: true) {
    &__content {
      padding-bottom: spacing(0);
    }

    .notice {
      padding-right: spacing(-1);
    }

    // The page scrolls, not the list. The footer is a sticky bar after the list with "clear all" on
    // the left and the jump-up button on the right. At the end of the list it rests below the last
    // notice, so it does not cover any text. While more of the list is below, it stays at the bottom
    // of the screen, and a fade above it (the footer's own ::before) softens the notices behind it.
    &__scroll::after {
      display: none;
    }

    // Also beats the padding that --with-footer sets for the floating button on desktop.
    &__scroll &__inner {
      padding-bottom: $notice-footer-fade-height;
    }

    &__footer {
      position: sticky;
      right: auto;
      bottom: 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: spacing(-1);
      padding: 0 var(--sub-nav-padding) spacing(0);
      box-sizing: border-box;

      // Behind the buttons (z-index -1 inside the footer's own stacking context). It does not take clicks.
      // The gradient runs up from the bottom of the footer to $notice-footer-fade-height above it:
      // solid up to 60% of the height, 80% at 90%, and transparent at the top.
      &::before {
        content: "";
        position: absolute;
        top: calc(-1 * #{$notice-footer-fade-height});
        right: 0;
        bottom: 0;
        left: 0;
        z-index: -1;
        background: linear-gradient(
          to top,
          color("background") 40%,
          color-mix(in srgb, #{color("background")} 80%, transparent) 70%,
          var(--transparent-background) 100%
        );
        pointer-events: none;
      }

      .button {
        box-shadow: 0 0.1rem 0.5rem 0 var(--color-shadow);
      }
    }

    &__scroll-to-top {
      display: inline-flex;
      margin-left: auto; // stays on the right when "clear all" is not shown
      flex: none; // stays round: a flex row must not squeeze it
      opacity: 0;
      visibility: hidden;
      transition: opacity $notice-footer-transition ease-in-out, visibility 0s linear $notice-footer-transition;

      // The icon font has no up arrow, so the right arrow (.icon-next) is turned to point up.
      &::before {
        transform: rotate(-90deg);
      }

      &--visible {
        opacity: 1;
        visibility: visible;
        transition-delay: 0s;
      }
    }
  }
}

// LIST
// The rule at the top belongs to the list, so a heading above the list (the panel title, or the
// name of a source such as Outlook) is above the rule. Without a list there is no rule.
.notice-list {
  display: flex;
  flex-direction: column;
  list-style: none;
  padding: 0;
  margin: 0;
  border-top: $width-border solid color("border");

  &__item {
    list-style: none;
    padding: 0;
    margin: 0;

    &:not(:first-child) {
      border-top: $width-border solid color("border");
    }
  }
}

// NOTICE
// The unread dot sits in the left padding, level with the middle of the first line.
.notice {
  $notice-padding: -2;
  $notice-gap: -2;
  $notice-gap-inline: -5;
  $notice-line-height: line-height("single", $include-calc: false);

  position: relative;
  display: flex;
  flex-direction: column;
  gap: spacing($notice-gap);
  padding: spacing($notice-padding);
  color: color("foreground");
  // Only the size: each part sets its own line-height, because a calc() line-height is inherited as a fixed length.
  font-size: font-size(-1);

  // The row never wraps: the source and the link wrap inside their own columns, while the time
  // stays on the first line. The link starts at zero width and grows into the free space, so the
  // source column only shrinks once the link is down to its longest word.
  &__top {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: spacing($notice-gap-inline);
    @include set-font(-1, "single");
  }

  &__meta {
    display: flex;
    align-items: flex-start;
    gap: spacing($notice-gap-inline);
    min-width: 0;
    margin-right: auto;
  }

  &__badge {
    position: absolute;
    top: calc(#{spacing($notice-padding)} + (#{$notice-line-height} - #{$notice-dot-size}) / 2);
    left: 0;
    display: inline-block;
    width: $notice-dot-size;
    height: $notice-dot-size;
    border-radius: 50%;
    background-color: color("utility-attention");
    flex-shrink: 0;
  }

  &__badge-label {
    @include screenreader-only;
  }

  &__source {
    min-width: 0;
    overflow-wrap: break-word;
    font-weight: $font-weight-bold;
  }

  &__separator {
    flex: none;
    width: $notice-separator-size;
    height: $notice-separator-size;
    margin-top: calc((#{$notice-line-height} - #{$notice-separator-size}) / 2);
    border-radius: 50%;
    background-color: color("foreground-secondary");
  }

  &__time {
    flex: none;
    white-space: nowrap;
    color: color("foreground-secondary");
  }

  // A ghost button (.button--text). The extra .notice__top beats the padding from
  // .button--text.button--small, so the link text lines up with the text beside it.
  &__top &__external-link {
    flex: 1 1 0;
    max-width: max-content;
    padding-top: 0;
    padding-bottom: 0;
    overflow-wrap: break-word;
    text-align: right; // a long text wraps onto several lines, which line up on the right
    @include set-font(-1, "single");

    &::before {
      font-size: 1.25em;
      line-height: 1;
    }
  }

  &__content {
    display: flex;
    flex-direction: column;
    gap: spacing($notice-gap);
  }

  &__header {
    @include set-font(0, "single");
  }

  &__subheader {
    @include set-font(-1, "single");
    color: color("foreground-secondary");
  }

  &__internal-link {
    @include set-font(-1, "single");
  }
}
