/** @license MIT | @cube-dev/ui-kit v0.123.0 | Cube Dev Team */
import { createSharedStore } from "./sharedStore.js";
import { useEffect } from "react";
import { useFocusVisible } from "react-aria";

//#region src/utils/react/useControlledFocusVisible.ts
const useControlledFocusVisibleStore = createSharedStore("controlledFocusVisible", { isManuallyActivated: false });
/**
* A hook that shares its state using sharedStore and works like useFocusVisible from react-aria,
* but also returns activateFocusVisible function that manually switches the state to true
* until the original flag is switched to false.
*/
function useControlledFocusVisible() {
	const { isFocusVisible: originalIsFocusVisible } = useFocusVisible({});
	const [{ isManuallyActivated }, setStore] = useControlledFocusVisibleStore();
	useEffect(() => {
		if (!originalIsFocusVisible && isManuallyActivated) setStore({ isManuallyActivated: false });
	}, [
		originalIsFocusVisible,
		isManuallyActivated,
		setStore
	]);
	const activateFocusVisible = () => {
		setStore({ isManuallyActivated: true });
	};
	return {
		isFocusVisible: originalIsFocusVisible || isManuallyActivated,
		activateFocusVisible
	};
}

//#endregion
export { useControlledFocusVisible };
//# sourceMappingURL=useControlledFocusVisible.js.map