import { useEffect } from 'react';
import { isBrowser, noop } from '../util/const.js';
export const useVibrate = !isBrowser || navigator.vibrate === undefined
    ? noop
    : (enabled, pattern, loop) => {
        useEffect(() => {
            let interval;
            if (enabled) {
                navigator.vibrate(pattern);
                if (loop) {
                    interval = setInterval(() => {
                        navigator.vibrate(pattern);
                    }, Array.isArray(pattern) ? pattern.reduce((a, n) => a + n, 0) : pattern);
                }
                return () => {
                    navigator.vibrate(0);
                    if (interval) {
                        clearInterval(interval);
                    }
                };
            }
        }, [loop, pattern, enabled]);
    };
