// `next/link` stand-in for the design-system bundle.
//
// Header, Hero and Footer navigate with next/link. The real one reads Next's
// AppRouterContext, which doesn't exist outside a Next app — pulling it into the
// bundle would drag the router runtime in and throw on mount in every preview
// and every design the agent builds.
//
// Routed here by compilerOptions.paths in .design-sync/tsconfig.ds.json, which
// the converter feeds to esbuild. Renders the plain anchor Next renders anyway,
// and drops the router-only props so React doesn't warn about unknown DOM
// attributes.

import * as React from 'react';

type UrlObject = { pathname?: string; query?: unknown; hash?: string };

export type LinkProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {
  href: string | UrlObject;
  prefetch?: boolean | null;
  replace?: boolean;
  scroll?: boolean;
  shallow?: boolean;
  passHref?: boolean;
  legacyBehavior?: boolean;
  locale?: string | false;
};

const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(
  { href, prefetch, replace, scroll, shallow, passHref, legacyBehavior, locale, ...rest },
  ref,
) {
  const resolved =
    typeof href === 'string' ? href : `${href?.pathname ?? ''}${href?.hash ?? ''}` || '#';
  return <a ref={ref} href={resolved} {...rest} />;
});

export default Link;
