"use client"
import { type JSX, useEffect, useRef } from "react"

export function PHProvider({ children }: { children: React.ReactNode }): JSX.Element {
  const initRef = useRef(false)

  useEffect(() => {
    if (initRef.current || process.env.NODE_ENV !== "production") return
    initRef.current = true

    import("posthog-js").then(({ default: posthog }) => {
      posthog.init("phc_aUO790jHd7z1SXwsYCz8dRApxueplZlZWeDSpKc5hol", {
        api_host: "https://app.posthog.com",
        capture_pageview: false,
      })
    })
  }, [])

  return <>{children}</>
}
