import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { safelyRemoveChild } from 'agora-foundation/lib/utilities/safely-remove-child';
export function copyText(_x) {
  return _copyText.apply(this, arguments);
}
function _copyText() {
  _copyText = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) {
    var textarea, _t;
    return _regeneratorRuntime.wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          if (!('clipboard' in navigator)) {
            _context.next = 4;
            break;
          }
          _context.prev = 1;
          _context.next = 2;
          return navigator.clipboard.writeText(text);
        case 2:
          return _context.abrupt("return");
        case 3:
          _context.prev = 3;
          _t = _context["catch"](1);
          console.error('navigator.clipboard.writeText catch error:', _t);
        case 4:
          textarea = document.createElement('textarea');
          textarea.setAttribute('readonly', 'readonly');
          textarea.value = text;
          document.body.appendChild(textarea);
          textarea.select();
          document.execCommand('copy');
          safelyRemoveChild(document.body, textarea);
        case 5:
        case "end":
          return _context.stop();
      }
    }, _callee, null, [[1, 3]]);
  }));
  return _copyText.apply(this, arguments);
}