---
import type { HTMLAttributes } from 'astro/types';
import { isValidFramework } from '@/types/docs';
import { resolveDocsLinkUrl } from '@/utils/docs/routing';
import A from '../typography/A.astro';

interface Props extends Omit<HTMLAttributes<'a'>, 'href'> {
  slug: string;
}
const { slug, class: className } = Astro.props;

const { framework: paramFramework } = Astro.params;
if (!paramFramework || !isValidFramework(paramFramework)) {
  throw new Error(`Invalid or missing framework param "${paramFramework ?? 'undefined'}".`);
}

const { url: href } = resolveDocsLinkUrl({
  targetSlug: slug,
  contextFramework: paramFramework,
});
---

<A href={href} class={className ?? undefined}><slot /></A>
