"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.unlinkPayload = exports.buildVisitedNonHyperLinkPayload = exports.buildVisitedLinkPayload = exports.buildOpenedSettingsPayload = exports.buildEditLinkPayload = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _enums = require("./types/enums");
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) { (0, _defineProperty2.default)(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; }
var buildEditLinkPayload = exports.buildEditLinkPayload = function buildEditLinkPayload(type) {
  return {
    action: _enums.ACTION.CLICKED,
    actionSubject: type === _enums.ACTION_SUBJECT_ID.HYPERLINK ? _enums.ACTION_SUBJECT.HYPERLINK : _enums.ACTION_SUBJECT.SMART_LINK,
    actionSubjectId: _enums.ACTION_SUBJECT_ID.EDIT_LINK,
    attributes: type !== _enums.ACTION_SUBJECT_ID.HYPERLINK ? {
      // @ts-ignore
      display: type
    } : {},
    eventType: _enums.EVENT_TYPE.UI
  };
};
var mapLinkTypeToCardAppearance = function mapLinkTypeToCardAppearance(type) {
  switch (type) {
    case _enums.ACTION_SUBJECT_ID.CARD_INLINE:
      {
        return 'inline';
      }
    case _enums.ACTION_SUBJECT_ID.CARD_BLOCK:
      {
        return 'block';
      }
    case _enums.ACTION_SUBJECT_ID.EMBEDS:
      {
        return 'embed';
      }
    default:
      {
        return 'url';
      }
  }
};
var buildVisitedLinkPayload = exports.buildVisitedLinkPayload = function buildVisitedLinkPayload(type) {
  return type === _enums.ACTION_SUBJECT_ID.HYPERLINK ? buildVisitedHyperLinkPayload() : buildVisitedNonHyperLinkPayload(type, _enums.INPUT_METHOD.TOOLBAR);
};
var buildVisitedHyperLinkPayload = function buildVisitedHyperLinkPayload() {
  return {
    action: _enums.ACTION.VISITED,
    actionSubject: _enums.ACTION_SUBJECT.HYPERLINK,
    actionSubjectId: undefined,
    attributes: {
      inputMethod: _enums.INPUT_METHOD.TOOLBAR
    },
    eventType: _enums.EVENT_TYPE.TRACK
  };
};
var buildVisitedNonHyperLinkPayload = exports.buildVisitedNonHyperLinkPayload = function buildVisitedNonHyperLinkPayload(type, inputMethod, resolvedAttributes) {
  return {
    action: _enums.ACTION.VISITED,
    actionSubject: _enums.ACTION_SUBJECT.SMART_LINK,
    actionSubjectId: type,
    attributes: _objectSpread({
      inputMethod: inputMethod
    }, resolvedAttributes && {
      displayCategory: resolvedAttributes.displayCategory,
      extensionKey: resolvedAttributes.extensionKey,
      status: resolvedAttributes.status,
      statusDetails: resolvedAttributes.statusDetails
    }),
    eventType: _enums.EVENT_TYPE.TRACK
  };
};
var buildOpenedSettingsPayload = exports.buildOpenedSettingsPayload = function buildOpenedSettingsPayload(type) {
  return {
    action: _enums.ACTION.CLICKED,
    actionSubject: _enums.ACTION_SUBJECT.BUTTON,
    actionSubjectId: _enums.ACTION_SUBJECT_ID.GOTO_SMART_LINK_SETTINGS,
    attributes: {
      // @ts-ignore
      inputMethod: _enums.INPUT_METHOD.TOOLBAR,
      display: mapLinkTypeToCardAppearance(type)
    },
    eventType: _enums.EVENT_TYPE.UI
  };
};
var unlinkPayload = exports.unlinkPayload = function unlinkPayload(type) {
  return {
    action: _enums.ACTION.UNLINK,
    actionSubject: type === _enums.ACTION_SUBJECT_ID.HYPERLINK ? _enums.ACTION_SUBJECT.HYPERLINK : _enums.ACTION_SUBJECT.SMART_LINK,
    actionSubjectId: type === _enums.ACTION_SUBJECT_ID.HYPERLINK ? undefined : type,
    attributes: {
      inputMethod: _enums.INPUT_METHOD.TOOLBAR
    },
    eventType: _enums.EVENT_TYPE.TRACK
  };
};