const FB_APP_ID = process.env.NEXT_PUBLIC_FACEBOOK_APP_ID;

export default function ShareButtons({
  message,
  link,
  redirectUri,
}: {
  message: string;
  link: string;
  redirectUri: string;
}) {
  const whatsappHref = `https://wa.me/?text=${encodeURIComponent(message)}`;
  const messengerHref = FB_APP_ID
    ? `https://www.facebook.com/dialog/send?link=${encodeURIComponent(link)}&app_id=${FB_APP_ID}&redirect_uri=${encodeURIComponent(redirectUri)}`
    : null;

  return (
    <div className="mt-6 flex flex-col gap-2">
      <a
        href={whatsappHref}
        target="_blank"
        rel="noopener noreferrer"
        className="border border-ink px-4 py-3 text-center text-sm hover:border-clay hover:bg-clay hover:text-paper"
      >
        Share via WhatsApp
      </a>

      {messengerHref ? (
        <a
          href={messengerHref}
          target="_blank"
          rel="noopener noreferrer"
          className="border border-ink px-4 py-3 text-center text-sm hover:border-clay hover:bg-clay hover:text-paper"
        >
          Share via Messenger
        </a>
      ) : (
        <p className="text-center text-xs text-muted">
          Messenger sharing needs a Facebook App ID — see the README&apos;s &quot;Sharing via
          Messenger&quot; section.
        </p>
      )}
    </div>
  );
}
