
import React from 'react';
import { Link } from 'react-router';

export default function AutoLink(props) {
  const url = props.href || props.to;
  if (!url)
    return <span {...props} />;

  const is_link = ["http://", "https://", "//"].findIndex(test => url.indexOf(test) !== -1) !== -1;

  return is_link ? <a href={url} {...props} to={undefined}/> : <Link to={url} {...props} href={undefined}/>;
}
