Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
require("../chunk-BN4qSVkS.cjs");
let react = require("react");
//#region src/hooks/useClipboard.tsx
function useClipboard(clipboardArgs) {
	const { onWriteEmptyText, onWriteError, onWrite, onReadError } = (0, react.useMemo)(() => ({
		onWriteEmptyText: clipboardArgs?.onWriteEmptyText,
		onWriteError: clipboardArgs?.onWriteError,
		onWrite: clipboardArgs?.onWrite,
		onReadError: clipboardArgs?.onReadError
	}), [clipboardArgs]);
	const [canReadFromClipboard, setCanReadFromClipboard] = (0, react.useState)(typeof navigator.clipboard?.readText !== "undefined");
	const [canWriteToClipboard, setCanWriteToClipboard] = (0, react.useState)(typeof navigator.clipboard?.writeText !== "undefined");
	const writeTextToClipboard = (0, react.useCallback)(async (text) => {
		try {
			if (!text.trim()) {
				if (onWriteEmptyText) onWriteEmptyText();
			} else {
				await navigator.clipboard.writeText(text);
				if (onWrite) onWrite();
			}
		} catch {
			if (onWriteError) onWriteError();
			setCanWriteToClipboard(false);
		}
	}, [
		onWrite,
		onWriteEmptyText,
		onWriteError
	]);
	const readTextFromClipboard = (0, react.useCallback)(async () => {
		try {
			return await navigator.clipboard.readText();
		} catch {
			if (onReadError) onReadError();
			setCanReadFromClipboard(false);
			return null;
		}
	}, [onReadError]);
	return (0, react.useMemo)(() => ({
		canReadFromClipboard,
		canWriteToClipboard,
		readTextFromClipboard,
		writeTextToClipboard
	}), [
		canReadFromClipboard,
		canWriteToClipboard,
		readTextFromClipboard,
		writeTextToClipboard
	]);
}
//#endregion
exports.useClipboard = useClipboard;
