import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from './types/enums';
export var buildEditLinkPayload = function buildEditLinkPayload(type) {
  return {
    action: ACTION.CLICKED,
    actionSubject: type === ACTION_SUBJECT_ID.HYPERLINK ? ACTION_SUBJECT.HYPERLINK : ACTION_SUBJECT.SMART_LINK,
    actionSubjectId: ACTION_SUBJECT_ID.EDIT_LINK,
    attributes: type !== ACTION_SUBJECT_ID.HYPERLINK ? {
      // @ts-ignore
      display: type
    } : {},
    eventType: EVENT_TYPE.UI
  };
};
var mapLinkTypeToCardAppearance = function mapLinkTypeToCardAppearance(type) {
  switch (type) {
    case ACTION_SUBJECT_ID.CARD_INLINE:
      {
        return 'inline';
      }
    case ACTION_SUBJECT_ID.CARD_BLOCK:
      {
        return 'block';
      }
    case ACTION_SUBJECT_ID.EMBEDS:
      {
        return 'embed';
      }
    default:
      {
        return 'url';
      }
  }
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export var buildVisitedLinkPayload = function buildVisitedLinkPayload(type) {
  return type === ACTION_SUBJECT_ID.HYPERLINK ? buildVisitedHyperLinkPayload() : buildVisitedNonHyperLinkPayload(type, INPUT_METHOD.TOOLBAR);
};
var buildVisitedHyperLinkPayload = function buildVisitedHyperLinkPayload() {
  return {
    action: ACTION.VISITED,
    actionSubject: ACTION_SUBJECT.HYPERLINK,
    actionSubjectId: undefined,
    attributes: {
      inputMethod: INPUT_METHOD.TOOLBAR
    },
    eventType: EVENT_TYPE.TRACK
  };
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export var buildVisitedNonHyperLinkPayload = function buildVisitedNonHyperLinkPayload(type, inputMethod, resolvedAttributes) {
  return {
    action: ACTION.VISITED,
    actionSubject: ACTION_SUBJECT.SMART_LINK,
    actionSubjectId: type,
    attributes: _objectSpread({
      inputMethod: inputMethod
    }, resolvedAttributes && {
      displayCategory: resolvedAttributes.displayCategory,
      extensionKey: resolvedAttributes.extensionKey,
      status: resolvedAttributes.status,
      statusDetails: resolvedAttributes.statusDetails
    }),
    eventType: EVENT_TYPE.TRACK
  };
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export var buildOpenedSettingsPayload = function buildOpenedSettingsPayload(type) {
  return {
    action: ACTION.CLICKED,
    actionSubject: ACTION_SUBJECT.BUTTON,
    actionSubjectId: ACTION_SUBJECT_ID.GOTO_SMART_LINK_SETTINGS,
    attributes: {
      // @ts-ignore
      inputMethod: INPUT_METHOD.TOOLBAR,
      display: mapLinkTypeToCardAppearance(type)
    },
    eventType: EVENT_TYPE.UI
  };
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export var unlinkPayload = function unlinkPayload(type) {
  return {
    action: ACTION.UNLINK,
    actionSubject: type === ACTION_SUBJECT_ID.HYPERLINK ? ACTION_SUBJECT.HYPERLINK : ACTION_SUBJECT.SMART_LINK,
    actionSubjectId: type === ACTION_SUBJECT_ID.HYPERLINK ? undefined : type,
    attributes: {
      inputMethod: INPUT_METHOD.TOOLBAR
    },
    eventType: EVENT_TYPE.TRACK
  };
};