/* Popovers/Menus */

@use "../../../../theme";
@use "../../../../theme-color";
@use "../../../../shadow";
@use "../../gnome-shell";

// 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: theme.$corner-radius;
  box-shadow: shadow.$z4;
  background-color: theme-color.$surface-z8;
  color: theme-color.$on-surface;
}

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

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

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

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

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

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

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

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

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

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

  .toggle-switch {
    width: 20px;
    height: 20px;
    background-image: url("assets/menu-item-toggle-off.svg");

    &:checked {
      background-image: url("assets/menu-item-toggle-on.svg");
    }
  }
}

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

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

// symbolic icons in popover

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

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

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

// popover submenus
.popup-sub-menu {
  border-top: 0;
  border-bottom: 0;
  padding-bottom: 0;
  box-shadow: none;
  background-color: theme-color.entry-fill(theme-color.$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 gnome-shell.$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: theme-color.divider(theme-color.$on-surface);

      // submenu separators
      .popup-sub-menu & {
        margin: 8px 0;
        background-color: theme-color.divider(theme-color.$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: theme-color.divider(theme-color.$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 gnome-shell.$version == 3.32 {
  .system-switch-user-submenu-icon {
    icon-size: 16px;
    padding: 0 4px;
  }
} @else if gnome-shell.$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 gnome-shell.$version < 3.36 {
  .system-menu-action {
    -st-icon-style: symbolic; // >= 3.30
    padding: (theme.$large-size - 16px) / 2;
    border: 0;
    border-radius: theme.$large-size / 2; // wish we could do 50%
    color: theme-color.hint(theme-color.$on-surface);
    transition-duration: theme.$state-duration;

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

    &:focus {
      background-color: theme-color.focus-overlay(theme-color.$on-surface);
    }

    &:hover {
      background-color: theme-color.hover-overlay(theme-color.$on-surface);
    }

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

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