import { c } from "react-compiler-runtime";
import React, { cloneElement } from "react";
import { Menu } from "@material-ui/core";
import { bindMenu, bindTrigger, usePopupState } from "material-ui-popup-state/hooks";
//#region src/shell/ui/profile/MenuOpener.jsx
/**
* Helper to handle open a menu when a button is clicked
*/
const MenuOpener = (t0) => {
	const $ = c(17);
	const { MenuComponent: t1, button, menuProps, children } = t0;
	const MenuComponent = t1 === void 0 ? Menu : t1;
	let t2;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t2 = {
			variant: "popover",
			popupId: "useId(name)"
		};
		$[0] = t2;
	} else t2 = $[0];
	const popupState = usePopupState(t2);
	const { close } = popupState;
	let t3;
	if ($[1] !== close) {
		t3 = (e) => {
			const isButton = e.target.matches("a, button, input[type=\"button\"], input[type=\"image\"], [role=\"button\"], [role=\"link\"], a *, button *, [role=\"button\"] *, [role=\"link\"] *");
			const isDropdownButton = e.target.matches(".MuiAutocomplete-endAdornment *");
			if (isButton && !isDropdownButton) close();
		};
		$[1] = close;
		$[2] = t3;
	} else t3 = $[2];
	const click = t3;
	let t4;
	if ($[3] !== button || $[4] !== popupState) {
		t4 = cloneElement(button, bindTrigger(popupState));
		$[3] = button;
		$[4] = popupState;
		$[5] = t4;
	} else t4 = $[5];
	let t5;
	if ($[6] !== popupState) {
		t5 = bindMenu(popupState);
		$[6] = popupState;
		$[7] = t5;
	} else t5 = $[7];
	let t6;
	if ($[8] !== MenuComponent || $[9] !== children || $[10] !== click || $[11] !== menuProps || $[12] !== t5) {
		t6 = /* @__PURE__ */ React.createElement(MenuComponent, {
			...menuProps,
			...t5,
			onClick: click
		}, children);
		$[8] = MenuComponent;
		$[9] = children;
		$[10] = click;
		$[11] = menuProps;
		$[12] = t5;
		$[13] = t6;
	} else t6 = $[13];
	let t7;
	if ($[14] !== t4 || $[15] !== t6) {
		t7 = /* @__PURE__ */ React.createElement(React.Fragment, null, t4, t6);
		$[14] = t4;
		$[15] = t6;
		$[16] = t7;
	} else t7 = $[16];
	return t7;
};
//#endregion
export { MenuOpener as default };

//# sourceMappingURL=MenuOpener.mjs.map