'use strict';

var NextLink = require('next/link');
var link = require('@keystar/ui/link');
var jsxRuntime = require('react/jsx-runtime');

function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }

var NextLink__default = /*#__PURE__*/_interopDefault(NextLink);

const UniversalNextLink = link.makeLinkComponent((_ref, ref) => {
  let {
    href,
    onClick,
    rel,
    ...props
  } = _ref;
  const shouldUseNext = href[0] === '/' && href[1] !== '/';
  return shouldUseNext ? /*#__PURE__*/jsxRuntime.jsx(NextLink__default["default"], {
    href: href,
    ref: ref,
    ...props
  }) : /*#__PURE__*/jsxRuntime.jsx("a", {
    ref: ref,
    href: href,
    rel: rel || 'noreferrer noopener',
    onClick: event => {
      if (href === '' || href === '#') {
        event.preventDefault();
      }
      if (typeof onClick === 'function') {
        onClick(event);
      }
    },
    ...props
  });
});

exports.UniversalNextLink = UniversalNextLink;
