---
import type { HTMLAttributes } from 'astro/types';

interface Link extends HTMLAttributes<'a'> {
    text?: string;
}

export interface Props extends Link {
    active?: Link;
}

const {
    text,
    active,
    class: _class,
    ...attrs
} = Astro.props as Props
---

{() => {
    if (Astro.url.pathname === attrs.href) {
        if (Astro.slots.has('active')) return <Fragment set:html={Astro.slots.render('active')}/>
        if (active) return <a class:list={[_class, active.class]} {...{...attrs, ...active}}>{active.text||text}<Fragment set:html={Astro.slots.render('default')}/></a>
    }
    return <a class:list={_class} {...attrs}>{text}<Fragment set:html={Astro.slots.render('default')}/></a>
}}