"use client";

import Link from "next/link";

/**
 * A link when there is somewhere to go, and plain markup when there is not.
 *
 * `next/link` requires an `href`, so a screen whose destination is derived from a
 * possibly-absent id had two bad options: interpolate `undefined` into the path
 * and ship a link to a 404, or duplicate the subtree. This is the third.
 */
export default function OptionalLink({
  href,
  className,
  children,
}: {
  href: string | null | undefined;
  className?: string;
  children: React.ReactNode;
}) {
  if (!href) return <>{children}</>;

  return (
    <Link href={href} className={className}>
      {children}
    </Link>
  );
}
