'use strict';

exports.__esModule = true;

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; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _Bridge2 = _interopRequireDefault(_Bridge);

var _ShareChoose = require('./ShareChoose');

var _ShareChoose2 = _interopRequireDefault(_ShareChoose);

var _ShareTip = require('./ShareTip');

var _ShareTip2 = _interopRequireDefault(_ShareTip);

var _ShareType = require('./ShareType');

var _ShareType2 = _interopRequireDefault(_ShareType);

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

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; }

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

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


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

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