const PARTIDA_NOTICE_LAYER_SELECTOR = '[data-partida-notice-layer]';

/**
 * Composes bits-ui `onInteractOutside` so clicks on the portaled invoice-items
 * {@link ErrorPanelNotice} are not treated as “outside” the Sheet/Dialog.
 */
export function withPartidaNoticeInteractOutside(
	userOnInteractOutside?: (e: PointerEvent) => void
): (e: PointerEvent) => void {
	return (e: PointerEvent) => {
		const t = e.target;
		if (t instanceof Element && t.closest(PARTIDA_NOTICE_LAYER_SELECTOR)) {
			e.preventDefault();
		}
		userOnInteractOutside?.(e);
	};
}
