import Script from "next/script";

type RybbitTrackingProps = {
  domain: string;
};

export function RybbitTracking({ domain }: RybbitTrackingProps) {
  const siteId = process.env.NEXT_PUBLIC_RYBBIT_SITE_ID?.trim();
  if (!siteId) {
    return null;
  }

  const apiUrl = process.env.RYBBIT_API_URL?.trim() || "https://app.rybbit.io";
  const src = `${apiUrl.replace(/\/$/, "")}/api/script.js`;

  return (
    <Script
      async
      data-site-id={siteId}
      data-domain={domain}
      defer
      id="rybbit-public-audit"
      src={src}
      strategy="afterInteractive"
    />
  );
}
