import React, { Fragment } from 'react';
import Bridge from './../Bridge';

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')) {
      // 微信
      Bridge.invoke('shareWechatMessage', config, function (res) {
        if (res.err_msg === 'shareWechatMessage:ok') {
          console.log('分享成功');
        }
      });
    } else if (target.classList.contains('wework')) {
      // 企业微信
      Bridge.invoke('shareAppMessage', config, function (res) {
        if (res.err_msg === 'shareAppMessage:ok') {
          console.log('分享成功');
        }
      });
    } else if (target.classList.contains('moments')) {
      // 朋友圈
      Bridge.invoke('shareTimeline', config, function (res) {
        if (res.err_msg === 'shareTimeline:ok') {
          console.log('分享成功');
        }
      });
    }
  };
  return React.createElement(
    Fragment,
    null,
    React.createElement('i', { className: 'share-icon ' + type, onClick: handlerClick }),
    React.createElement(
      'p',
      { className: 'share-caption' },
      type === 'wechat' && '微信好友',
      type === 'wework' && '企业微信好友',
      type === 'moments' && '微信朋友圈'
    )
  );
}

export default ShareType;