// 内库使用-start
import LocaleUtil from "./../../../utils/LocaleUtil";
import Bridge from "./../../../utils/Bridge";
// 内库使用-end

/* 测试使用-start
import { LocaleUtil, Bridge } from 'seedsui-react'
测试使用-end */

// 分享至
function share(params) {
  var _ref = params || {},
    title = _ref.title,
    description = _ref.description,
    url = _ref.url,
    imageUrl = _ref.imageUrl,
    _onSuccess = _ref.onSuccess,
    _onFail = _ref.onFail;
  if (Bridge.platform === 'lark') {
    window.top.tt.share({
      channelType: ['wx', 'wx_timeline', 'system'],
      contentType: 'url',
      title: title,
      content: description,
      url: url,
      image: imageUrl,
      success: function success() {
        _onSuccess && _onSuccess();
      },
      fail: function fail(err) {
        console.log('Lark Share fail:', err);
        _onFail && _onFail({
          errMsg: (err === null || err === void 0 ? void 0 : err.errMsg) || LocaleUtil.locale('分享失败', 'SeedsUI_share_failed')
        });
      }
    });
  } else if (Bridge.platform === 'dingtalk') {
    window.top.dd.biz.util.share({
      type: 0,
      // 分享类型，0:全部组件 默认；1:只能分享到钉钉；2:不能分享，只有刷新按钮
      url: url,
      title: title,
      content: description,
      image: imageUrl,
      onSuccess: function onSuccess() {
        _onSuccess && _onSuccess();
      },
      onFail: function onFail(err) {
        console.log('DingTalk Share fail:', err);
        _onFail && _onFail({
          errMsg: (err === null || err === void 0 ? void 0 : err.errMsg) || LocaleUtil.locale('分享失败', 'SeedsUI_share_failed')
        });
      }
    });
  }
}
export default share;