"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vue = require("vue");

var _vueRouter = require("vue-router");

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

var _lodashEs = require("lodash-es");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * 外链正则表达式
 */
var externalReg = /(http|https|ftp):\/\/([\w.]+\/?)\S*/;

var AppLink = function AppLink(props, _ref) {
  var _slots$default3;

  var attrs = _ref.attrs,
      slots = _ref.slots,
      emit = _ref.emit;
  var external = props.external,
      target = props.target,
      to = props.to,
      customClickEvent = props.customClickEvent,
      registered = props.registered;
  var isExternal = (0, _vue.computed)(function () {
    return external || typeof to === 'string' && externalReg.test(to);
  });

  if (isExternal.value) {
    var _slots$default;

    return (0, _vue.createVNode)("a", {
      "href": to,
      "target": target
    }, [(_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)]);
  }
  /* 路由未注册则直接返回 */
  // if (!registered) {
  //   return slots.default?.();
  // }

  /* 如果跳转链接不存在或存在自定义点击事件，则直接返回插槽内容 */


  if (!to || customClickEvent) {
    var _slots$default2;

    return (_slots$default2 = slots.default) === null || _slots$default2 === void 0 ? void 0 : _slots$default2.call(slots);
  }

  return (0, _vue.createVNode)(_vueRouter.RouterLink, _objectSpread(_objectSpread({}, (0, _lodashEs.omit)(props, 'external', 'target', 'registered', 'customClickEvent')), {}, {
    "target": "_self",
    "to": to,
    "replace": true
  }), {
    default: function _default() {
      return [(_slots$default3 = slots.default) === null || _slots$default3 === void 0 ? void 0 : _slots$default3.call(slots)];
    }
  });
};

AppLink.displayName = 'AppLink';
AppLink.props = {
  external: _utils.PropTypes.bool.def(false),
  target: _utils.PropTypes.string.def('_blank'),
  registered: _utils.PropTypes.bool.def(false),
  to: {
    type: [String, Object]
  },
  customClickEvent: _utils.PropTypes.bool.def(false)
};
AppLink.inheritAttrs = false;

var _default2 = (0, _utils.withInstall)(AppLink);

exports.default = _default2;