import { useEffect } from 'react';
import { useGestureContext } from '../context/GestureContext';
import type { GestureLayerDefinition, PageGestureState } from '../types';

export function useGesturePageState(pageState: PageGestureState) {
  const { setPageState } = useGestureContext();

  useEffect(() => {
    setPageState(pageState);
  }, [pageState, setPageState]);
}

export function useGestureLayer(layer: GestureLayerDefinition) {
  const { registerLayer, unregisterLayer } = useGestureContext();

  useEffect(() => {
    registerLayer(layer);

    return () => {
      unregisterLayer(layer.id);
    };
  }, [layer, registerLayer, unregisterLayer]);
}
