"use strict";

exports.__esModule = true;
exports.default = void 0;

var _babelRuntimeJsxStyleTransform = require("babel-runtime-jsx-style-transform");

var _react = _interopRequireWildcard(require("react"));

var _navigate = _interopRequireDefault(require("@uni/navigate"));

var _clipboard = require("@uni/clipboard");

var _message = _interopRequireDefault(require("../message"));

var _utils = require("../utils");

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var MINIAPP_PAGE_REG = /^\/pages\/(.+)\/index/;
var SIMPLE_URL_REG = /[a-zA-z]+:\/\/[^\s]*/;

var RichTextLink = function (props) {
  var style = props.style,
      href = props.href,
      className = props.className,
      children = props.children;
  return /*#__PURE__*/(0, _react.createElement)("view", {
    className: className,
    onClick: function handleClick() {
      if (href[0] === '#') {
        var id = href.substring(1);
        (0, _utils.scrollToId)(id);
      } else if (SIMPLE_URL_REG.test(href)) {
        (0, _clipboard.setClipboard)({
          text: href
        }).then(function () {
          if (_utils.isStrictMiniApp || _utils.isStrictByteDanceMicroApp) {
            _message.default.show({
              content: '链接已复制到粘贴板'
            });
          }
        });
      } else if (MINIAPP_PAGE_REG.test(href)) {
        _navigate.default.push({
          url: href
        }).then(function () {});
      }
    },
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)(style)
  }, children);
};

var _default = RichTextLink;
exports.default = _default;