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 const extractInvokeCopyLinkAction = ({
  actionOptions,
  appearance,
  id,
  response
}) => {
  if (!canShowAction(CardAction.CopyLinkAction, actionOptions)) {
    return;
  }
  const url = extractSmartLinkUrl(response);
  if (!url) {
    return;
  }
  return {
    actionFn: async () => navigator.clipboard.writeText(url),
    actionSubjectId: 'copyLink',
    actionType: ActionName.CopyLinkAction,
    definitionId: getDefinitionId(response),
    display: appearance,
    extensionKey: getExtensionKey(response),
    id,
    resourceType: getResourceType(response)
  };
};