import React from 'react';
import { getHapticsPreference, setHapticsPreference, supportsHaptics } from '../lib/haptics';

export function useHapticsPreference() {
  const [enabled, setEnabledState] = React.useState(() => getHapticsPreference());
  const [supported, setSupported] = React.useState(() => supportsHaptics());

  React.useEffect(() => {
    setEnabledState(getHapticsPreference());
    setSupported(supportsHaptics());
  }, []);

  const setEnabled = React.useCallback((value: boolean) => {
    setHapticsPreference(value);
    setEnabledState(value);
  }, []);

  return { enabled, setEnabled, supported };
}
