"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.extractInvokeCopyLinkAction = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _linkExtractors = require("@atlaskit/link-extractors");
var _index = require("../../index");
var _helpers = require("../../state/helpers");
var _canShowAction = require("../../utils/actions/can-show-action");
var extractInvokeCopyLinkAction = exports.extractInvokeCopyLinkAction = function extractInvokeCopyLinkAction(_ref) {
  var actionOptions = _ref.actionOptions,
    appearance = _ref.appearance,
    id = _ref.id,
    response = _ref.response;
  if (!(0, _canShowAction.canShowAction)(_index.CardAction.CopyLinkAction, actionOptions)) {
    return;
  }
  var url = (0, _linkExtractors.extractSmartLinkUrl)(response);
  if (!url) {
    return;
  }
  return {
    actionFn: function () {
      var _actionFn = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
        return _regenerator.default.wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              return _context.abrupt("return", navigator.clipboard.writeText(url));
            case 1:
            case "end":
              return _context.stop();
          }
        }, _callee);
      }));
      function actionFn() {
        return _actionFn.apply(this, arguments);
      }
      return actionFn;
    }(),
    actionSubjectId: 'copyLink',
    actionType: _index.ActionName.CopyLinkAction,
    definitionId: (0, _helpers.getDefinitionId)(response),
    display: appearance,
    extensionKey: (0, _helpers.getExtensionKey)(response),
    id: id,
    resourceType: (0, _helpers.getResourceType)(response)
  };
};