import { rpx2vw4style as __rpx2vw__ } from "babel-runtime-jsx-style-transform";
import React, { createElement } from "react";
import navigate from '@uni/navigate';
import { setClipboard } from '@uni/clipboard';
import Message from '../message';
import { isStrictByteDanceMicroApp, isStrictMiniApp, scrollToId } from '../utils';
var MINIAPP_PAGE_REG = /^\/pages\/(.+)\/index/;
var SIMPLE_URL_REG = /[a-zA-z]+:\/\/[^\s]*/;

var RichTextLink = function RichTextLink(props) {
  var style = props.style,
      href = props.href,
      className = props.className,
      children = props.children;

  var handleClick = function handleClick() {
    if (href[0] === '#') {
      var id = href.substring(1);
      scrollToId(id);
    } else if (SIMPLE_URL_REG.test(href)) {
      setClipboard({
        text: href
      }).then(function () {
        if (isStrictMiniApp || isStrictByteDanceMicroApp) {
          Message.show({
            content: '链接已复制到粘贴板'
          });
        }
      });
    } else if (MINIAPP_PAGE_REG.test(href)) {
      navigate.push({
        url: href
      }).then(function (res) {});
    }
  };

  return /*#__PURE__*/React.createElement("view", {
    className: className,
    onClick: handleClick,
    style: __rpx2vw__(style)
  }, children);
};

export default RichTextLink;