import React, { CSSProperties } from 'react';
import { classnames } from '..';

interface Props {
	handling: () => void;
	children: React.ReactNode;
	className?: string[] | string;
	style?: CSSProperties;
	title?: string;
}

export function Lenke(props: Props) {
	const { handling, children, className, ...rest } = props;

	const keyhandler = (event) => {
		if (event.keyCode === 13 || event.keyCode === 32) {
			event.preventDefault();
			handling();
		}
	};

	return (
		<a
			{...rest}
			className={classnames('lenke-med-handling', className)}
			tabIndex={0}
			role={'button'}
			onClick={() => handling()}
			onKeyDown={keyhandler}
		>
			{children}
		</a>
	);
}
