var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

import React, { useState } from 'react';
import Bridge from './../Bridge';
import ShareChoose from './ShareChoose';
import ShareTip from './ShareTip';
import ShareType from './ShareType';

function Share(_ref) {
  var children = _ref.children,
      type = _ref.type,
      _ref$shareTo = _ref.shareTo,
      shareTo = _ref$shareTo === undefined ? ['wechat', 'wework', 'moments'] : _ref$shareTo,
      _ref$config = _ref.config,
      config = _ref$config === undefined ? {
    title: '', // 分享标题
    desc: '', // 分享描述
    link: '', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
    imgUrl: '' // 分享图标
  } : _ref$config,
      originConfig = _ref.originConfig,
      others = _objectWithoutProperties(_ref, ['children', 'type', 'shareTo', 'config', 'originConfig']);

  if (Bridge.platform !== 'wework' && Bridge.platform !== 'wechat' && Bridge.platform !== 'wq' && Bridge.platform !== 'dinghuo' && Bridge.platform !== 'waiqin') {
    console.log('Share: 此平台无法使用分享功能');
    return null;
  }
  if (!config || !config.link) {
    console.log('Share: 没有设置config');
    return null;
  }
  // 定义state

  var _useState = useState(false),
      show = _useState[0],
      setShow = _useState[1];
  // 显隐弹窗


  var handlerClick = function handlerClick() {
    if (Bridge.platform === 'dinghuo' || Bridge.platform === 'waiqin') {
      Bridge.shareText({
        title: config.title,
        desc: config.desc,
        link: config.link,
        text: '' + config.link
      });
    } else {
      setShow(true);
    }
  };
  return React.createElement(
    'div',
    _extends({}, others, { onClick: handlerClick }),
    children,
    Bridge.platform === 'wechat' && React.createElement(ShareTip, {
      show: show,
      config: config,
      originConfig: originConfig,
      onHide: function onHide() {
        return setShow(false);
      }
    }),
    (Bridge.platform === 'wework' || Bridge.platform === 'wq') && !type && React.createElement(ShareChoose, {
      show: show,
      config: config,
      shareTo: shareTo,
      onHide: function onHide() {
        return setShow(false);
      }
    }),
    (Bridge.platform === 'wework' || Bridge.platform === 'wq') && type && React.createElement(ShareType, {
      type: type,
      config: config
    })
  );
}

export default Share;