"use client";
import { useEffect, useRef, useState } from "react";
//#region packages/@mantine/hooks/src/use-clipboard/use-clipboard.ts
function useClipboard(options = {}) {
	const timeout = options.timeout ?? 2e3;
	const [error, setError] = useState(null);
	const [copied, setCopied] = useState(false);
	const timeoutRef = useRef(null);
	useEffect(() => () => {
		window.clearTimeout(timeoutRef.current);
	}, []);
	const handleCopyResult = (value) => {
		window.clearTimeout(timeoutRef.current);
		timeoutRef.current = window.setTimeout(() => setCopied(false), timeout);
		setCopied(value);
	};
	const copy = (value) => {
		if ("clipboard" in navigator) navigator.clipboard.writeText(value).then(() => {
			setError(null);
			handleCopyResult(true);
		}).catch((err) => setError(err));
		else setError(/* @__PURE__ */ new Error("useClipboard: navigator.clipboard is not supported"));
	};
	const reset = () => {
		setCopied(false);
		setError(null);
		window.clearTimeout(timeoutRef.current);
	};
	return {
		copy,
		reset,
		error,
		copied
	};
}
//#endregion
export { useClipboard };

//# sourceMappingURL=use-clipboard.mjs.map