require("../../../../_virtual/_rolldown/runtime.js");
const require_IsActiveContext = require("../../context/IsActiveContext.js");
let react = require("react");
let ahooks = require("ahooks");
//#region src/components/ticketBooking/hooks/pisellos/useActiveExecute.ts
/**
* useActiveExecute Hook
* 返回一个函数，该函数接收一个回调函数，并返回一个包装后的函数
* 包装后的函数只在 isActive 为 true 时执行原始回调
*
* @example
* ```tsx
* const { executeIfActive } = useActiveExecute();
*
* // 创建一个包装函数用于事件监听
* const handleChange = (data) => {
*   console.log('data:', data);
* };
*
* // 返回的函数会在被调用时检查 isActive
* pisellos.effects.on('event', executeIfActive(handleChange));
* ```
*/
const useActiveExecute = () => {
	const isActive = require_IsActiveContext.useIsActive();
	const isActiveRef = (0, react.useRef)(isActive);
	(0, react.useEffect)(() => {
		isActiveRef.current = isActive;
	}, [isActive]);
	return { executeIfActive: (0, ahooks.useMemoizedFn)((fn) => {
		return ((...args) => {
			if (!isActiveRef.current) return;
			return fn === null || fn === void 0 ? void 0 : fn(...args);
		});
	}) };
};
//#endregion
exports.useActiveExecute = useActiveExecute;
