/* Popovers/Menus */

// the popover itself
.popup-menu-boxpointer {
  -arrow-base: 0;
  -arrow-rise: 0;
  -arrow-border-width: 0;
  -arrow-border-color: transparent;
  -arrow-border-radius: 20px; // This is necessary for the weird bug: materia-theme#296
  -arrow-box-shadow: none; // dreaming bugzilla #689995
  -arrow-background-color: transparent;
}

// container of the popover menu
.popup-menu {
  min-width: 15em;
  border-color: transparent;
  color: inherit;

  // dunno what that is
  .popup-status-menu-item {
    // font-weight: normal;
    // color: pink;
  }

  &.panel-menu {
    -boxpointer-gap: 0; // distance from the panel
    margin-bottom: 1.75em;
  }
}

.popup-menu-content {
  margin: 8px;
  padding: 8px 0;
  border-radius: $corner-radius;
  box-shadow: $shadow-z4;
  background-color: $surface-z8;
  color: $on-surface;
}

// menu items
.popup-menu-item {
  // min-height: $menuitem-size - 4px * 2;
  spacing: 8px;
  padding: 0;
  transition-duration: $duration;

  &:ltr {
    padding: 0.4em;
    padding-right: 24px;
    padding-left: 0;
  }

  &:rtl {
    padding: 0.4em;
    padding-right: 0;
    padding-left: 24px;
  }

  &.selected {
    background-color: overlay("hover", $on-surface);
    transition-duration: 0ms;

    &,
    &:active {
      color: $on-surface;
    }
  }

  &:active {
    background-color: overlay("pressed", $on-surface);
    color: $on-surface;
    transition-duration: $duration-ripple;
  }

  &:checked {
    box-shadow: none;
    background-color: $overlay-selected;
    font-weight: normal;

    &.selected {
      background-color: overlay("hover", $primary, $on: $overlay-selected);
    }

    &:active {
      background-color: overlay("pressed", $primary, $on: $overlay-selected);
    }
  }

  &:insensitive {
    color: disabled($on-surface);
  }
}

// all icons and other graphical elements
.popup-inactive-menu-item {
  color: $on-surface;

  &:insensitive {
    color: disabled($on-surface);
  }
}

// symbolic icons in popover

.popup-menu-arrow {
  @if $version >= 3.32 {
    icon-size: 16px;
  } @else {
    width: 16px;
    height: 16px;
  }

  .popup-menu-content & {
    color: hint($on-surface);
  }
}

.popup-menu-icon {
  icon-size: 16px;
  color: hint($on-surface);
}

// popover submenus
.popup-sub-menu {
  border-top: 0;
  border-bottom: 0;
  padding-bottom: 0;
  box-shadow: none;
  background-color: entry-fill($on-surface);
}

// container for radio and check boxes
.popup-menu-ornament {
  text-align: right;
  width: 16px;
  height: 16px;

  &:ltr {
    text-align: right;
  }

  &:rtl {
    text-align: left;
  }
}

// separator
@if $version >= 3.36 {
  .popup-separator-menu-item {
    padding: 0;

    .popup-separator-menu-item-separator {
      // -margin-horizontal: 24px;
      height: 1px; // not really the whole box
      margin: 8px 0;
      background-color: divider($on-surface);

      // submenu separators
      .popup-sub-menu & {
        margin: 8px 0;
        background-color: divider($on-surface);

        &:ltr {
          margin-right: 32px;
        }

        &:rtl {
          margin-left: 32px;
        }
      }
    }
  }
} @else {
  .popup-separator-menu-item {
    // -margin-horizontal: 24px;
    height: 1px; // not really the whole box
    margin: 8px 64px - 24px;
    border: 0;
    background-color: divider($on-surface);
  }
}

// desktop background menu
.background-menu {
  -boxpointer-gap: 4px;
  -arrow-rise: 0; // hide the beak on the menu
}

// system status menu
.aggregate-menu {
  min-width: 21em;

  // lock screen, shutdown, etc. buttons
  .popup-menu-icon {
    padding: 0;
    margin: 0 4px;
    -st-icon-style: symbolic; // >= 3.36
  }

  .popup-sub-menu .popup-menu-item > :first-child {
    // account for icons in submenus with padding
    &:ltr {
      padding-left: 16px; 
      margin-left: 16px;
    }

    &:rtl {
      padding-right: 16px;
      margin-right: 16px;
    }
  }
}

@if $version == 3.32 {
  .system-switch-user-submenu-icon {
    icon-size: 16px;
    padding: 0 4px;
  }
} @else if $version < 3.32 {
  .system-switch-user-submenu-icon.user-icon {
    icon-size: 20px;
    padding: 0 2px;
  }

  .system-switch-user-submenu-icon.default-icon {
    icon-size: 16px;
    padding: 0 4px;
  }
}

@if $version < 3.36 {
  .system-menu-action {
    -st-icon-style: symbolic; // >= 3.30
    padding: ($large-size - 16px) / 2;
    border: 0;
    border-radius: $large-size / 2; // wish we could do 50%
    color: hint($on-surface);
    transition-duration: $duration;

    &:hover,
    &:focus {
      padding: ($large-size - 16px) / 2;
      border: 0;
      color: hint($on-surface);
    }

    &:focus {
      background-color: overlay("focus", $on-surface);
    }

    &:hover {
      background-color: overlay("hover", $on-surface);
    }

    &:active {
      background-color: overlay("pressed", $on-surface);
      color: hint($on-surface);
      transition-duration: $duration-ripple;
    }

    > StIcon {
      icon-size: 16px;
    }
  }
}
