---

import Icon from '../Icon.astro'

interface Props {
	href: string
	class: string
}

const p = Astro.props as Props;

let external = false;

if (p.href.includes('https://') || p.href.includes('http://')) {
	external = true;
}

---

<a href={p.href} class={p.class} target={external ? '_blank' : '_self'}>
	<slot/>
	{external ? (
		<>
		<Icon icon="FaExternalLink" class='w-2.5 inline-block align-super fill-crusta-800 dark:fill-night-400' aria-hidden="true"/>
		<span class="hidden">opens in a new tab</span>
		</>
	) : ''}
</a>