---
import type { HTMLAttributes } from 'astro/types';
import Link from './Link.astro';

interface LinkProps extends HTMLAttributes<'a'> {
    text?: string;
    active?: LinkProps;
}

export interface Props {
    links: LinkProps[];
    defaults?: LinkProps;
    active?: LinkProps;
}

const {
    links,
    defaults,
    active
} = Astro.props
---

{ links.map(link => {
    const attrs = { active, ...defaults, ...link };
    if (!!Object.keys(Astro.slots).length) {
        if (Astro.url.pathname === link.href && Astro.slots.has('active')) return <Fragment set:html={Astro.slots.render('active', [attrs])}/>
        return <Fragment set:html={Astro.slots.render('default', [attrs])}/>
    }
    return <Link {...attrs}/>
})}