import type { ReactNode } from "react";
import { useEffect } from "react";

export const TrustpilotProvider = ({ children }: { children: ReactNode }) => {
  useEffect(() => {
    // Required to load Trustpilot widgets
    const script = document.createElement("script");
    script.type = "text/javascript";
    script.className = "optanon-category-C0002";
    script.src =
      "//widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js";
    script.async = true;
    document.head.appendChild(script);

    return () => {
      document.head.removeChild(script);
    };
  }, []);

  return <div>{children}</div>;
};
