import * as React from 'react';
import Link from 'next/link';

interface ILinkWrapperProps {
  children?: React.ReactNode;
  href: any;
  target?: string;
  className?: string;
  newTab?: boolean;
  style?: any;
}

/*
  This wrapper wrappes link so it can be passed down to
  nova ui components like Button
*/

export default class LinkWrapper extends React.Component<ILinkWrapperProps> {
  render() {
    const { href, children, className, newTab, target, ...rest } = this.props;
    const hrefTarget = newTab ? '_blank' : target;

    return (
      <Link
        href={href}
        className={className}
        target={hrefTarget}
        rel="noopener noreferrer"
        {...rest}
      >
        {children}
      </Link>
    );
  }
}
