var _excluded = ["className", "style", "shareTo"];
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useRef, forwardRef, useImperativeHandle } from 'react';
import _support from "./../utils/support";
import WeChat from "./WeChat";
import WeCom from "./WeCom";
import Lark from "./Lark";
import DingTalk from "./DingTalk";

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

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

// 分享, shareTo: {extensions: [{isVisible: ({ shareTo }) => ture|false, render: ({ shareTo }) => Node, }]}
function Main(_ref, ref) {
  var className = _ref.className,
    style = _ref.style,
    shareTo = _ref.shareTo,
    props = _objectWithoutProperties(_ref, _excluded);
  var mainRef = useRef(null);

  // Expose
  useImperativeHandle(ref, function () {
    return {
      mainDOM: mainRef.current,
      getMainDOM: function getMainDOM() {
        return mainRef.current;
      },
      support: function support(externalShareTo) {
        return _support(externalShareTo || shareTo);
      }
    };
  });
  function getShareNodes() {
    if (Bridge.platform === 'wechat') {
      return /*#__PURE__*/React.createElement(WeChat, _extends({}, props, {
        shareTo: shareTo
      }));
    }
    if (Bridge.platform === 'wework') {
      return /*#__PURE__*/React.createElement(WeCom, _extends({}, props, {
        shareTo: shareTo
      }));
    }
    if (Bridge.platform === 'lark') {
      return /*#__PURE__*/React.createElement(Lark, _extends({}, props, {
        shareTo: shareTo
      }));
    }
    if (Bridge.platform === 'dingtalk') {
      return /*#__PURE__*/React.createElement(DingTalk, _extends({}, props, {
        shareTo: shareTo
      }));
    }

    // Custom Extension Items
    if (Array.isArray(shareTo === null || shareTo === void 0 ? void 0 : shareTo.extensions) && shareTo !== null && shareTo !== void 0 && shareTo.extensions.length) {
      var _iterator = _createForOfIteratorHelper(shareTo.extensions),
        _step;
      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          var extension = _step.value;
          if (typeof (extension === null || extension === void 0 ? void 0 : extension.render) === 'function') {
            var ExtensionNode = extension.render({
              shareTo: shareTo
            });
            if (ExtensionNode) return ExtensionNode;
          }
        }
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }
    }
    return null;
  }
  var isSupport = _support(shareTo);
  return /*#__PURE__*/React.createElement("div", {
    className: "share".concat(className ? ' ' + className : '').concat(isSupport ? '' : ' error'),
    style: style,
    ref: mainRef
  }, isSupport ? getShareNodes() : /*#__PURE__*/React.createElement(Result, {
    className: "share-main-result",
    status: "empty",
    title: LocaleUtil.locale('此平台暂不支持分享', 'SeedsUI_share_no_support')
  }));
}
export default /*#__PURE__*/forwardRef(Main);