"use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunkZ6EUSUADcjs = require('./chunk-Z6EUSUAD.cjs');

// src/hooks/useClipboard.tsx
var _react = require('react');
function useClipboard(clipboardArgs) {
  var _a, _b;
  const { onWriteEmptyText, onWriteError, onWrite, onReadError } = _react.useMemo.call(void 0, 
    () => ({
      onWriteEmptyText: clipboardArgs == null ? void 0 : clipboardArgs.onWriteEmptyText,
      onWriteError: clipboardArgs == null ? void 0 : clipboardArgs.onWriteError,
      onWrite: clipboardArgs == null ? void 0 : clipboardArgs.onWrite,
      onReadError: clipboardArgs == null ? void 0 : clipboardArgs.onReadError
    }),
    [clipboardArgs]
  );
  const [canReadFromClipboard, setCanReadFromClipboard] = _react.useState.call(void 0, 
    typeof ((_a = navigator.clipboard) == null ? void 0 : _a.readText) !== "undefined"
  );
  const [canWriteToClipboard, setCanWriteToClipboard] = _react.useState.call(void 0, 
    typeof ((_b = navigator.clipboard) == null ? void 0 : _b.writeText) !== "undefined"
  );
  const writeTextToClipboard = _react.useCallback.call(void 0, 
    (text) => _chunkZ6EUSUADcjs.__async.call(void 0, this, null, function* () {
      try {
        if (!text.trim()) {
          if (onWriteEmptyText) {
            onWriteEmptyText();
          }
        } else {
          yield navigator.clipboard.writeText(text);
          if (onWrite) {
            onWrite();
          }
        }
      } catch (error) {
        if (onWriteError) {
          onWriteError();
        }
        setCanWriteToClipboard(false);
      }
    }),
    [onWrite, onWriteEmptyText, onWriteError]
  );
  const readTextFromClipboard = _react.useCallback.call(void 0, () => _chunkZ6EUSUADcjs.__async.call(void 0, this, null, function* () {
    try {
      const text = yield navigator.clipboard.readText();
      return text;
    } catch (error) {
      if (onReadError) {
        onReadError();
      }
      setCanReadFromClipboard(false);
      return null;
    }
  }), [onReadError]);
  const clipboard = _react.useMemo.call(void 0, 
    () => ({
      canReadFromClipboard,
      canWriteToClipboard,
      readTextFromClipboard,
      writeTextToClipboard
    }),
    [
      canReadFromClipboard,
      canWriteToClipboard,
      readTextFromClipboard,
      writeTextToClipboard
    ]
  );
  return clipboard;
}



exports.useClipboard = useClipboard;
