import { useState, useCallback, useEffect } from 'react';
/**
 * Hook to use copy to clipboard functionality.
 * @returns object with values:
 * - isCopied - boolean with status of clipboard action
 * - copyToClipboard - a return function that allows to initiate copying
 * - reset - an optional return function
 */
export function useCopyClipboard({ value, onCopy, resetTimeout, }) {
    const [isCopied, setIsCopied] = useState(false);
    const copyToClipboard = useCallback(() => {
        navigator.clipboard.writeText(value).then(() => {
            setIsCopied(true);
            onCopy?.();
        });
    }, [value, onCopy]);
    const reset = useCallback(() => {
        setIsCopied(false);
    }, [setIsCopied]);
    useEffect(() => {
        let timeout;
        if (isCopied && resetTimeout) {
            timeout = setTimeout(reset, resetTimeout);
        }
        return () => {
            clearTimeout(timeout);
        };
    }, [isCopied, reset, resetTimeout]);
    useEffect(reset, [value, reset]);
    return { isCopied, copyToClipboard, reset };
}
//# sourceMappingURL=useCopyClipboard.js.map