import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { extractSmartLinkUrl } from '@atlaskit/link-extractors';
import { ActionName, CardAction } from '../../index';
import { getDefinitionId, getExtensionKey, getResourceType } from '../../state/helpers';
import { canShowAction } from '../../utils/actions/can-show-action';
export var extractInvokeCopyLinkAction = function extractInvokeCopyLinkAction(_ref) {
  var actionOptions = _ref.actionOptions,
    appearance = _ref.appearance,
    id = _ref.id,
    response = _ref.response;
  if (!canShowAction(CardAction.CopyLinkAction, actionOptions)) {
    return;
  }
  var url = extractSmartLinkUrl(response);
  if (!url) {
    return;
  }
  return {
    actionFn: function () {
      var _actionFn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        return _regeneratorRuntime.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: ActionName.CopyLinkAction,
    definitionId: getDefinitionId(response),
    display: appearance,
    extensionKey: getExtensionKey(response),
    id: id,
    resourceType: getResourceType(response)
  };
};