'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 _reactDom = require('react-dom');

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

var _Bridge2 = _interopRequireDefault(_Bridge);

var _instance = require('../Context/instance.js');

var _instance2 = _interopRequireDefault(_instance);

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

function ShareTip(_ref) {
  var portal = _ref.portal,
      show = _ref.show,
      _ref$config = _ref.config,
      config = _ref$config === undefined ? {} : _ref$config,
      originConfig = _ref.originConfig,
      _ref$maskAttribute = _ref.maskAttribute,
      maskAttribute = _ref$maskAttribute === undefined ? {} : _ref$maskAttribute,
      onHide = _ref.onHide;

  // 生命周期
  (0, _react.useEffect)(function () {
    // componentDidMount和componentDidUpdate
    return function () {
      // componentWillUnmount
      // 更新分享
      if (originConfig) {
        wx.updateAppMessageShareData(_extends({}, originConfig, {
          success: function success() {
            console.log('还原好友分享成功');
          },
          fail: function fail() {
            var res = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

            console.log(res.errMsg || '还原好友分享失败, 请稍后再试', { mask: false });
          }
        }));
        wx.updateTimelineShareData(_extends({}, originConfig, {
          success: function success() {
            console.log('还原朋友圈分享成功');
          },
          fail: function fail() {
            var res = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

            console.log(res.errMsg || '还原朋友圈分享失败, 请稍后再试', { mask: false });
          }
        }));
      }
    };
  });

  // useEffect(() => {
  //   // componentDidUpdate: 更新usernmae
  // }, [state.username]);

  // 更新分享
  wx.updateAppMessageShareData(_extends({}, config, {
    success: function success() {
      console.log('更新好友分享成功');
    },
    fail: function fail() {
      var res = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      _Bridge2.default.showToast(res.errMsg || '更新好友分享失败, 请稍后再试', { mask: false });
    }
  }));
  wx.updateTimelineShareData(_extends({}, config, {
    success: function success() {
      console.log('更新朋友圈分享成功');
    },
    fail: function fail() {
      var res = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      _Bridge2.default.showToast(res.errMsg || '更新朋友圈分享失败, 请稍后再试', { mask: false });
    }
  }));
  // 点击
  var handlerClick = function handlerClick(e) {
    var target = e.target;
    e.stopPropagation();
    if (target.classList.contains('share-mask')) {
      if (onHide) onHide(e);
    }
  };
  // context
  var context = (0, _react.useContext)(_instance2.default) || {};
  var locale = context.locale || {};
  return (0, _reactDom.createPortal)(_react2.default.createElement(
    'div',
    _extends({ className: 'mask share-mask' + (maskAttribute.className ? ' ' + maskAttribute.className : '') + (show ? ' active' : '') }, maskAttribute, { onClick: handlerClick }),
    _react2.default.createElement('div', { className: 'share-tip-arrow' }),
    _react2.default.createElement(
      'div',
      { className: 'share-tip' },
      _react2.default.createElement(
        'p',
        null,
        '1.',
        locale['sharetip_click_on_the_top_right'] || '点击右上角'
      ),
      _react2.default.createElement(
        'p',
        null,
        '2.',
        locale['sharetip_click'] || '点击',
        _react2.default.createElement('img', { alt: '', src: '//res.waiqin365.com/d/seedsui/share/tip_friend.png' }),
        locale['sharetip_sent_to_friend_or'] || '发送给朋友或',
        _react2.default.createElement('img', { alt: '', src: '//res.waiqin365.com/d/seedsui/share/tip_moments.png' }),
        locale['sharetip_share_to_moments'] || '分享给朋友圈'
      )
    )
  ), portal || context.portal || document.getElementById('root') || document.body);
}

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