@import "./menu_common";

//-- Mixin ---------------------------------------------------------------------
// Components
$_layoutCommonMenus: (
  $_iconMenuPopupMenus,
  $_libraryMenuitem,
  $_libraryMenu,
  $_otherPopupMenuitem,
  $_otherIconMenu,
  "#context_openANewTab.tabmix-newtab-menu-icon"
);
@mixin _layoutInitIconMenus() {
  #{$_globalMenus},
  #{$_nestedPopupIconMenus},
  #{$_layoutCommonMenus} {
    @content;
  }
}
@mixin _layoutInitPaddingMenus() {
  #{selector.nest($_nestedPopupPadding, "menuitem:not(.menuitem-iconic), menu:not(.menu-iconic)")},
  #{$_nestedPopupPaddingMenus},
  #{$_layoutCommonMenus} {
    @content;
  }
}
@mixin _layoutIconMenus() {
  #{$_nestedPopupPaddingMenus},
  #{$_layoutCommonMenus} {
    @content;
  }
}

//------------------------------------------------------------------------------

#{$_initialMenus},
#{$_globalMenus} {
  @include _initial_menus;
}

/* Icon */
@include _layoutInitIconMenus {
  @include _layout_icon_menus;
}
#tabContextMenu > .tabmix-newtab-menu-icon {
  -moz-context-properties: fill, fill-opacity, stroke !important;
  fill: currentColor !important;
}

/* For native context menus */
#{$_nestedPopupIconMenus} {
  @include _layout_icon_native_menus;
}

/* Padding */
@include _layout_root_padding;
@include _layoutInitPaddingMenus {
  @include _layout_init_padding;
}
#sidebarMenu-popup:is(menupopup):not(panel) {
  --context-menu-background-padding: var(--context-menu-background-padding-default);
  padding-inline-start: 0 !important;

  :not(menu, #ContentSelectDropdown, #context-navigation) > & > #{$_iconMenuitem} {
    padding-inline-start: 28px !important;
    margin-inline-start: var(--arrowpanel-menuitem-margin-inline) !important;
  }
}

/* Menubar */
@include Option("userChrome.icon.global_menubar") {
  #{$_globalMenus} {
    background-position: var(--uc-menu-background-position) var(--context-menu-background-padding-default) center !important;
    padding-inline-start: calc(16px + var(--context-menu-background-padding-default)) !important;
    padding-inline-end: 3px;

    &:first-child {
      background-position: var(--uc-menu-background-position) calc(3px + var(--context-menu-background-padding-default)) center !important;
      padding-inline-start: calc(19px + var(--context-menu-background-padding-default)) !important;
    }
    menupopup {
      --menuitem-image: none; /* Prevent Image Inheritance */
    }
    & > :is(.menubar-text, .menu-text) {
      @include OS($win) {
        transform: translateY(-1px) !important; /* Fix menu top padding position */
        padding-inline-start: 0.3em !important;
      }
      @include OS($linux) {
        @include _layout_init_linux;
      }
    }
    @include NotOption("userChrome.padding.global_menubar") {
      padding-block: 2px !important;
    }
  }
}

/* Padding - Non Native */
@include OS($win, $linux) {
  @include NonNativeMenu {
    @include _layout_root_non_native;
    @include _layoutIconMenus {
      @include _layout_init_non_native();
    }

    // FF v121
    .menupopup-arrowscrollbox {
      padding-inline: 0 !important; /* Original: padding: var(--panel-padding); --panel-padding-block: 4px; */
    }

    // FF v141 #1128
    menupopup[needsgutter] > :is(menu, menuitem) > .menu-icon {
      display: none !important;
    }
  }
}

/* Padding - Windows */
@include _layout_root_win;
@include OS($win) {
  @include _layoutIconMenus {
    @include _layout_init_win();
  }
}

/* Padding - Linux */
@include OS($linux) {
  @include _layout_root_linux;
}

/* Padding - Mac */
@include OS($mac) {
  @include _layout_root_mac;

  /* context menu width */
  #{$_nestedPopupPaddingMenus},
  #blockedPopupDontShowMessage {
    @include _layout_init_mac_width;
  }

  /* text position */
  #{selector.nest($_nestedPopupPadding, "menuitem > .menu-text, menu > .menu-text")} {
    @include _layout_init_mac_text;
  }

  /* Checkbox menuitem, None iconic menu */
  #{selector.nest($_nestedPopupPadding, "menuitem[type=\"checkbox\"]")} {
    // "menuitem[checked=\"true\"], menu:not(.menu-iconic)"
    @include _layout_init_mac_others;
  }

  /* Global Menu */
  @include Option("userChrome.icon.global_menu.mac") {
    #{selector.nest($_iconMenuPopup, "menuitem:not(.menuitem-iconic, .bookmark-item), menu:not(.menu-iconic)")} {
      list-style-image: var(--menuitem-image, url("../icons/blank.svg")) !important;
    }
  }

  /* Exeptions */
  // Mac unified extenstions #847
  #unified-extensions-context-menu > menuitem::before {
    padding-inline: 0 !important;
  }

  :not(menu, #ContentSelectDropdown, #context-navigation) > menupopup:not(.in-menulist) > menuitem {
    &:not(.menuitem-iconic, .bookmark-item, .in-menulist, [checked="true"]) {
      padding-inline-start: 0 !important;
    }

    &:not(.menuitem-iconic):has(.menu-iconic-left) {
      &[checked] {
        padding-left: 4px !important;
        background-image: none !important;
      }
      &[checked="true"] {
        padding-left: calc(var(--context-menu-mac-padding) - 8px) !important;
        .menu-iconic-text {
          padding-left: 8px !important;
        }
      }
    }
  }
}
