"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.LinkEvent = undefined;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.trackEvent = trackEvent;
exports.trackButtonEvent = trackButtonEvent;

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

function _trackEvent(eventName, isButton, props) {
  var properties = Object.assign({}, props || {}, {
    category: isButton ? "button" : "link",
    label: eventName
  });

  if (typeof window !== 'undefined' && window.analytics) {
    try {
      window.analytics.track("click", properties);
    } catch (err) {}
  }
  return;
}

function trackEvent(eventName, props) {
  return _trackEvent(eventName, false, props);
}

function trackButtonEvent(eventName, props) {
  return _trackEvent(eventName, true, props);
}

var LinkEvent = function LinkEvent(props) {
  var href = props.href,
      target = props.target,
      download = props.download,
      rel = props.rel,
      children = props.children,
      event = props.event,
      eventProps = props.eventProps,
      rest = _objectWithoutProperties(props, ["href", "target", "download", "rel", "children", "event", "eventProps"]);

  return _react2.default.createElement(
    "a",
    _extends({
      href: href,
      target: target,
      download: download,
      rel: rel,
      onClick: function onClick() {
        if (event) {
          trackEvent(event, eventProps);
        }
      }
    }, rest),
    children
  );
};

exports.LinkEvent = LinkEvent;
exports.default = undefined;