import React from 'react';
import Type from "./../Type";

// 企业微信只支持分享到企业微信
function WeCom(_ref) {
  var shareTo = _ref.shareTo;
  if (shareTo !== null && shareTo !== void 0 && shareTo.wecom) {
    var _ref2 = (shareTo === null || shareTo === void 0 ? void 0 : shareTo.wecom) || {},
      title = _ref2.title,
      description = _ref2.description,
      url = _ref2.url,
      imageUrl = _ref2.imageUrl,
      onSuccess = _ref2.onSuccess,
      onFail = _ref2.onFail;
    return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Type, {
      type: "wecom",
      onClick: function onClick() {
        window.top.wx.invoke('shareAppMessage', {
          title: title || '',
          desc: description || '',
          link: url || '',
          imgUrl: imageUrl || ''
        }, function (res) {
          console.log('WeCom Share result:', res);
          if (res.err_msg === 'shareAppMessage:ok') {
            onSuccess && onSuccess();
          } else {
            onFail && onFail({
              errMsg: (res === null || res === void 0 ? void 0 : res.errMsg) || '分享失败'
            });
          }
        });
      }
    }));
  }
  return null;
}
export default WeCom;