'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _Bridge = require('./../Bridge');

var _Bridge2 = _interopRequireDefault(_Bridge);

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

function ShareType(_ref) {
  var _ref$config = _ref.config,
      config = _ref$config === undefined ? {} : _ref$config,
      type = _ref.type;

  // 点击
  var handlerClick = function handlerClick(e) {
    var target = e.target;
    e.stopPropagation();
    if (target.classList.contains('wechat')) {
      // 微信
      _Bridge2.default.invoke('shareWechatMessage', config, function (res) {
        if (res.err_msg === 'shareWechatMessage:ok') {
          console.log('分享成功');
        }
      });
    } else if (target.classList.contains('wework')) {
      // 企业微信
      _Bridge2.default.invoke('shareAppMessage', config, function (res) {
        if (res.err_msg === 'shareAppMessage:ok') {
          console.log('分享成功');
        }
      });
    } else if (target.classList.contains('moments')) {
      // 朋友圈
      _Bridge2.default.invoke('shareTimeline', config, function (res) {
        if (res.err_msg === 'shareTimeline:ok') {
          console.log('分享成功');
        }
      });
    }
  };
  return _react2.default.createElement(
    _react.Fragment,
    null,
    _react2.default.createElement('i', { className: 'share-icon ' + type, onClick: handlerClick }),
    _react2.default.createElement(
      'p',
      { className: 'share-caption' },
      type === 'wechat' && '微信好友',
      type === 'wework' && '企业微信好友',
      type === 'moments' && '微信朋友圈'
    )
  );
}

exports.default = ShareType;
module.exports = exports['default'];