"use strict";

require("core-js/modules/es.object.define-property.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.copyText = copyText;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _safelyRemoveChild = require("agora-foundation/lib/utilities/safely-remove-child");
function copyText(_x) {
  return _copyText.apply(this, arguments);
}
function _copyText() {
  _copyText = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(text) {
    var textarea, _t;
    return _regenerator["default"].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');
          (0, _safelyRemoveChild.safelyRemoveChild)(document.body, textarea);
        case 5:
        case "end":
          return _context.stop();
      }
    }, _callee, null, [[1, 3]]);
  }));
  return _copyText.apply(this, arguments);
}