"use strict";

exports.__esModule = true;
exports.Share = void 0;

var _react = _interopRequireDefault(require("react"));

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

var shareSettings = 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=550,height=431';
var mediumSet = ['twitter', 'telegram', 'facebook', 'linkedin'];

var handleSocialShare = function handleSocialShare(url) {
  return window.open(url, '', shareSettings);
};

var socialLink = function socialLink(medium, url) {
  return /*#__PURE__*/_react.default.createElement("button", {
    type: "button",
    onClick: function onClick() {
      return handleSocialShare(url);
    },
    className: "blog-" + medium
  }, medium);
};

var LinkToSocial = function LinkToSocial(_ref) {
  var medium = _ref.medium,
      url = _ref.url;
  var link;

  switch (medium) {
    case 'twitter':
      link = "https://twitter.com/intent/tweet?url=" + encodeURI(url);
      return socialLink(medium, link);

    case 'facebook':
      link = "https://www.facebook.com/sharer/sharer.php?u=" + encodeURI(url);
      return socialLink(medium, link);

    case 'linkedin':
      link = "https://www.linkedin.com/shareArticle?url=" + encodeURI(url) + "&mini=true";
      return socialLink(medium, link);

    case 'telegram':
      link = "https://telegram.me/share/url?url=" + encodeURI(url);
      return socialLink(medium, link);

    case 'article-quote':
      return '';

    default:
      return null;
  }
};

var Share = function Share() {
  var url = '/';
  if (typeof window !== "undefined") url = window.location;
  return /*#__PURE__*/_react.default.createElement("div", {
    className: "share"
  }, /*#__PURE__*/_react.default.createElement("ul", null, mediumSet.map(function (medium) {
    return /*#__PURE__*/_react.default.createElement("li", {
      key: medium
    }, /*#__PURE__*/_react.default.createElement(LinkToSocial, {
      medium: medium,
      url: url
    }));
  })));
};

Share.displayName = 'Share';
var ShareDoc;

if (process.env.NODE_ENV !== 'production') {
  // eslint-disable-next-line global-require
  ShareDoc = require('./doc').doc(Share);
}

var ShareWrapper = ShareDoc || Share;
exports.Share = ShareWrapper;