"use client";
import { useEffect, useState } from "react";
//#region src/hooks/useKeyboardOffset.tsx
/**
* Hook to handle iOS keyboard viewport changes.
* Returns the offset needed to keep elements above the keyboard.
*/
function useKeyboardOffset() {
	const [keyboardOffset, setKeyboardOffset] = useState(0);
	useEffect(() => {
		const viewport = window.visualViewport;
		if (!viewport) return;
		const handleResize = () => {
			const offset = window.innerHeight - viewport.height;
			setKeyboardOffset(Math.max(0, offset));
		};
		handleResize();
		viewport.addEventListener("resize", handleResize);
		viewport.addEventListener("scroll", handleResize);
		return () => {
			viewport.removeEventListener("resize", handleResize);
			viewport.removeEventListener("scroll", handleResize);
		};
	}, []);
	return keyboardOffset;
}
//#endregion
export { useKeyboardOffset };
